exercise.php 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Exercise list: This script shows the list of exercises for administrators and students.
  6. * @package chamilo.exercise
  7. * @author Olivier Brouckaert, original author
  8. * @author Denes Nagy, HotPotatoes integration
  9. * @author Wolfgang Schneider, code/html cleanup
  10. * @author Julio Montoya <gugli100@gmail.com>, lots of cleanup + several improvements
  11. * Modified by hubert.borderiou (question category)
  12. */
  13. // including the global library
  14. require_once __DIR__.'/../inc/global.inc.php';
  15. $current_course_tool = TOOL_QUIZ;
  16. // Setting the tabs
  17. $this_section = SECTION_COURSES;
  18. $htmlHeadXtra[] = api_get_asset('qtip2/jquery.qtip.min.js');
  19. $htmlHeadXtra[] = api_get_css_asset('qtip2/jquery.qtip.min.css');
  20. // Access control
  21. api_protect_course_script(true);
  22. require_once 'hotpotatoes.lib.php';
  23. /* Constants and variables */
  24. $is_allowedToEdit = api_is_allowed_to_edit(null, true);
  25. $is_tutor = api_is_allowed_to_edit(true);
  26. $is_tutor_course = api_is_course_tutor();
  27. $courseInfo = api_get_course_info();
  28. $courseId = $courseInfo['real_id'];
  29. $userInfo = api_get_user_info();
  30. $userId = $userInfo['id'];
  31. $sessionId = api_get_session_id();
  32. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  33. $userId,
  34. $courseInfo
  35. );
  36. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  37. $TBL_ITEM_PROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  38. $TBL_EXERCISE_QUESTION = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  39. $TBL_EXERCISES = Database :: get_course_table(TABLE_QUIZ_TEST);
  40. $TBL_TRACK_EXERCISES = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  41. // document path
  42. $documentPath = api_get_path(SYS_COURSE_PATH).$courseInfo['path']."/document";
  43. // picture path
  44. $picturePath = $documentPath.'/images';
  45. // audio path
  46. $audioPath = $documentPath.'/audio';
  47. // hot potatoes
  48. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  49. $exercisePath = api_get_self();
  50. $exfile = explode('/', $exercisePath);
  51. $exfile = strtolower($exfile[sizeof($exfile) - 1]);
  52. $exercisePath = substr($exercisePath, 0, strpos($exercisePath, $exfile));
  53. $exercisePath = $exercisePath."exercise.php";
  54. // Clear the exercise session
  55. Session::erase('objExercise');
  56. Session::erase('objQuestion');
  57. Session::erase('objAnswer');
  58. Session::erase('questionList');
  59. Session::erase('exerciseResult');
  60. //General POST/GET/SESSION/COOKIES parameters recovery
  61. $origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : null;
  62. $choice = isset($_REQUEST['choice']) ? Security::remove_XSS($_REQUEST['choice']) : null;
  63. $hpchoice = isset($_REQUEST['hpchoice']) ? Security::remove_XSS($_REQUEST['hpchoice']) : null;
  64. $exerciseId = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : null;
  65. $file = isset($_REQUEST['file']) ? Database::escape_string($_REQUEST['file']) : null;
  66. $learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : null;
  67. $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : null;
  68. $page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : null;
  69. if ($page < 0) {
  70. $page = 1;
  71. }
  72. if (!empty($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  73. $_SESSION['gradebook'] = Security::remove_XSS($_GET['gradebook']);
  74. $gradebook = $_SESSION['gradebook'];
  75. } elseif (empty($_GET['gradebook'])) {
  76. unset($_SESSION['gradebook']);
  77. $gradebook = '';
  78. }
  79. if (!empty($gradebook) && $gradebook == 'view') {
  80. $interbreadcrumb[] = array(
  81. 'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
  82. 'name' => get_lang('ToolGradebook')
  83. );
  84. }
  85. $nameTools = get_lang('Exercises');
  86. $errorXmlExport = null;
  87. if ($is_allowedToEdit && !empty($choice) && $choice == 'exportqti2') {
  88. require_once api_get_path(SYS_CODE_PATH).'exercise/export/qti2/qti2_export.php';
  89. $export = export_exercise_to_qti($exerciseId, true);
  90. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  91. $temp_dir_short = api_get_unique_id();
  92. $temp_zip_dir = $archive_path.$temp_dir_short;
  93. if (!is_dir($temp_zip_dir)) {
  94. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  95. }
  96. $temp_zip_file = $temp_zip_dir."/".api_get_unique_id().".zip";
  97. $temp_xml_file = $temp_zip_dir."/qti2export_".$exerciseId.'.xml';
  98. file_put_contents($temp_xml_file, $export);
  99. $xmlReader = new XMLReader();
  100. $xmlReader->open($temp_xml_file);
  101. $xmlReader->setParserProperty(XMLReader::VALIDATE, true);
  102. $isValid = $xmlReader->isValid();
  103. if ($isValid) {
  104. $zip_folder = new PclZip($temp_zip_file);
  105. $zip_folder->add($temp_xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
  106. $name = 'qti2_export_'.$exerciseId.'.zip';
  107. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  108. unlink($temp_zip_file);
  109. unlink($temp_xml_file);
  110. rmdir($temp_zip_dir);
  111. exit; //otherwise following clicks may become buggy
  112. } else {
  113. $errorXmlExport = Display :: return_message(get_lang('ErrorWritingXMLFile'), 'error');
  114. }
  115. }
  116. if ($origin != 'learnpath') {
  117. //so we are not in learnpath tool
  118. Display :: display_header($nameTools, get_lang('Exercise'));
  119. if (isset($_GET['message'])) {
  120. if (in_array($_GET['message'], array('ExerciseEdited'))) {
  121. Display :: display_confirmation_message(get_lang($_GET['message']));
  122. }
  123. }
  124. } else {
  125. Display :: display_reduced_header();
  126. }
  127. Event::event_access_tool(TOOL_QUIZ);
  128. // Tool introduction
  129. Display :: display_introduction_section(TOOL_QUIZ);
  130. if (!empty($errorXmlExport)) {
  131. echo $errorXmlExport;
  132. }
  133. HotPotGCt($documentPath, 1, $userId);
  134. // Only for administrator
  135. if ($is_allowedToEdit) {
  136. if (!empty($choice)) {
  137. // All test choice, clean all test's results
  138. if ($choice === 'clean_all_test') {
  139. $check = Security::check_token('get');
  140. if ($check) {
  141. // list of exercises in a course/session
  142. // we got variable $courseId $courseInfo session api_get_session_id()
  143. $exerciseList = ExerciseLib::get_all_exercises_for_course_id(
  144. $courseInfo,
  145. $sessionId,
  146. $courseId,
  147. false
  148. );
  149. $quantity_results_deleted = 0;
  150. foreach ($exerciseList as $exeItem) {
  151. // delete result for test, if not in a gradebook
  152. $exercise_action_locked = api_resource_is_locked_by_gradebook($exeItem['id'], LINK_EXERCISE);
  153. if ($exercise_action_locked == false) {
  154. $objExerciseTmp = new Exercise();
  155. if ($objExerciseTmp->read($exeItem['id'])) {
  156. $quantity_results_deleted += $objExerciseTmp->clean_results(true);
  157. }
  158. }
  159. }
  160. Display:: display_confirmation_message(
  161. sprintf(
  162. get_lang('XResultsCleaned'),
  163. $quantity_results_deleted
  164. )
  165. );
  166. }
  167. }
  168. // single exercise choice
  169. // construction of Exercise
  170. $objExerciseTmp = new Exercise();
  171. $check = Security::check_token('get');
  172. $exercise_action_locked = api_resource_is_locked_by_gradebook(
  173. $exerciseId,
  174. LINK_EXERCISE
  175. );
  176. if ($objExerciseTmp->read($exerciseId)) {
  177. if ($check) {
  178. switch ($choice) {
  179. case 'delete':
  180. // deletes an exercise
  181. if ($exercise_action_locked == false) {
  182. $objExerciseTmp->delete();
  183. $link_info = GradebookUtils::isResourceInCourseGradebook(
  184. api_get_course_id(),
  185. 1,
  186. $exerciseId,
  187. api_get_session_id()
  188. );
  189. if ($link_info !== false) {
  190. GradebookUtils::remove_resource_from_course_gradebook($link_info['id']);
  191. }
  192. Display :: display_confirmation_message(get_lang('ExerciseDeleted'));
  193. }
  194. break;
  195. case 'enable':
  196. // enables an exercise
  197. if (empty($sessionId)) {
  198. $objExerciseTmp->enable();
  199. $objExerciseTmp->save();
  200. } else {
  201. if (!empty($objExerciseTmp->sessionId)) {
  202. $objExerciseTmp->enable();
  203. $objExerciseTmp->save();
  204. }
  205. }
  206. api_item_property_update(
  207. $courseInfo,
  208. TOOL_QUIZ,
  209. $objExerciseTmp->id,
  210. 'visible',
  211. $userId
  212. );
  213. // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
  214. Display :: display_confirmation_message(get_lang('VisibilityChanged'));
  215. break;
  216. case 'disable':
  217. // disables an exercise
  218. if (empty($sessionId)) {
  219. $objExerciseTmp->disable();
  220. $objExerciseTmp->save();
  221. } else {
  222. // Only change active if it belongs to a session
  223. if (!empty($objExerciseTmp->sessionId)) {
  224. $objExerciseTmp->disable();
  225. $objExerciseTmp->save();
  226. }
  227. }
  228. api_item_property_update(
  229. $courseInfo,
  230. TOOL_QUIZ,
  231. $objExerciseTmp->id,
  232. 'invisible',
  233. $userId
  234. );
  235. Display :: display_confirmation_message(get_lang('VisibilityChanged'));
  236. break;
  237. case 'disable_results':
  238. //disable the results for the learners
  239. $objExerciseTmp->disable_results();
  240. $objExerciseTmp->save();
  241. Display :: display_confirmation_message(get_lang('ResultsDisabled'));
  242. break;
  243. case 'enable_results':
  244. //disable the results for the learners
  245. $objExerciseTmp->enable_results();
  246. $objExerciseTmp->save();
  247. Display :: display_confirmation_message(get_lang('ResultsEnabled'));
  248. break;
  249. case 'clean_results':
  250. //clean student results
  251. if ($exercise_action_locked == false) {
  252. $quantity_results_deleted = $objExerciseTmp->clean_results(true);
  253. $title = $objExerciseTmp->selectTitle();
  254. Display :: display_confirmation_message($title.': '.sprintf(get_lang('XResultsCleaned'), $quantity_results_deleted));
  255. }
  256. break;
  257. case 'copy_exercise': //copy an exercise
  258. $objExerciseTmp->copy_exercise();
  259. Display :: display_confirmation_message(get_lang('ExerciseCopied'));
  260. break;
  261. }
  262. }
  263. }
  264. // destruction of Exercise
  265. unset($objExerciseTmp);
  266. Security::clear_token();
  267. }
  268. if (!empty($hpchoice)) {
  269. switch ($hpchoice) {
  270. case 'delete':
  271. // deletes an exercise
  272. $imgparams = array();
  273. $imgcount = 0;
  274. GetImgParams($file, $documentPath, $imgparams, $imgcount);
  275. $fld = GetFolderName($file);
  276. for ($i = 0; $i < $imgcount; $i++) {
  277. my_delete($documentPath.$uploadPath."/".$fld."/".$imgparams[$i]);
  278. DocumentManager::updateDbInfo("delete", $uploadPath."/".$fld."/".$imgparams[$i]);
  279. }
  280. if (!is_dir($documentPath.$uploadPath."/".$fld."/")) {
  281. my_delete($documentPath.$file);
  282. DocumentManager::updateDbInfo("delete", $file);
  283. } else {
  284. if (my_delete($documentPath.$file)) {
  285. DocumentManager::updateDbInfo("delete", $file);
  286. }
  287. }
  288. /* hotpotatoes folder may contains several tests so
  289. don't delete folder if not empty :
  290. http://support.chamilo.org/issues/2165
  291. */
  292. if (!(strstr($uploadPath, DIR_HOTPOTATOES) && !folder_is_empty($documentPath.$uploadPath."/".$fld."/"))) {
  293. my_delete($documentPath.$uploadPath."/".$fld."/");
  294. }
  295. break;
  296. case 'enable': // enables an exercise
  297. $newVisibilityStatus = "1"; //"visible"
  298. $query = "SELECT id FROM $TBL_DOCUMENT
  299. WHERE c_id = $courseId AND path='".Database :: escape_string($file)."'";
  300. $res = Database::query($query);
  301. $row = Database :: fetch_array($res, 'ASSOC');
  302. api_item_property_update(
  303. $courseInfo,
  304. TOOL_DOCUMENT,
  305. $row['id'],
  306. 'visible',
  307. $userId
  308. );
  309. //$dialogBox = get_lang('ViMod');
  310. break;
  311. case 'disable': // disables an exercise
  312. $newVisibilityStatus = "0"; //"invisible"
  313. $query = "SELECT id FROM $TBL_DOCUMENT
  314. WHERE c_id = $courseId AND path='".Database :: escape_string($file)."'";
  315. $res = Database::query($query);
  316. $row = Database :: fetch_array($res, 'ASSOC');
  317. api_item_property_update(
  318. $courseInfo,
  319. TOOL_DOCUMENT,
  320. $row['id'],
  321. 'invisible',
  322. $userId
  323. );
  324. break;
  325. default:
  326. break;
  327. }
  328. }
  329. }
  330. // Actions div bar
  331. if ($is_allowedToEdit) {
  332. echo '<div class="actions">';
  333. }
  334. // Selects $limit exercises at the same time
  335. // maximum number of exercises on a same page
  336. $limit = 50;
  337. // Display the next and previous link if needed
  338. $from = $page * $limit;
  339. HotPotGCt($documentPath, 1, $userId);
  340. //condition for the session
  341. $course_code = api_get_course_id();
  342. $session_id = api_get_session_id();
  343. $condition_session = api_get_session_condition($session_id, true, true);
  344. // Only for administrators
  345. if ($is_allowedToEdit) {
  346. $total_sql = "SELECT count(iid) as count
  347. FROM $TBL_EXERCISES
  348. WHERE c_id = $courseId AND active<>'-1' $condition_session ";
  349. $sql = "SELECT * FROM $TBL_EXERCISES
  350. WHERE c_id = $courseId AND active<>'-1' $condition_session
  351. ORDER BY title
  352. LIMIT ".$from.",".$limit;
  353. } else {
  354. // Only for students
  355. $total_sql = "SELECT count(iid) as count
  356. FROM $TBL_EXERCISES
  357. WHERE c_id = $courseId AND active = '1' $condition_session ";
  358. $sql = "SELECT * FROM $TBL_EXERCISES
  359. WHERE c_id = $courseId AND
  360. active='1' $condition_session
  361. ORDER BY title LIMIT ".$from.",".$limit;
  362. }
  363. $result = Database::query($sql);
  364. $result_total = Database::query($total_sql);
  365. $total_exercises = 0;
  366. if (Database :: num_rows($result_total)) {
  367. $result_total = Database::fetch_array($result_total);
  368. $total_exercises = $result_total['count'];
  369. }
  370. //get HotPotatoes files (active and inactive)
  371. if ($is_allowedToEdit) {
  372. $sql = "SELECT * FROM $TBL_DOCUMENT
  373. WHERE
  374. c_id = $courseId AND
  375. path LIKE '".Database :: escape_string($uploadPath.'/%/%')."'";
  376. $res = Database::query($sql);
  377. $hp_count = Database :: num_rows($res);
  378. } else {
  379. $sql = "SELECT * FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  380. WHERE
  381. d.id = ip.ref AND
  382. ip.tool = '".TOOL_DOCUMENT."' AND
  383. d.path LIKE '".Database :: escape_string($uploadPath.'/%/%')."' AND
  384. ip.visibility ='1' AND
  385. d.c_id = ".$courseId." AND
  386. ip.c_id = ".$courseId;
  387. $res = Database::query($sql);
  388. $hp_count = Database :: num_rows($res);
  389. }
  390. $total = $total_exercises + $hp_count;
  391. $token = Security::get_token();
  392. if ($is_allowedToEdit && $origin != 'learnpath') {
  393. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/exercise_admin.php?'.api_get_cidreq().'">'.
  394. Display :: return_icon('new_exercice.png', get_lang('NewEx'), '', ICON_SIZE_MEDIUM).'</a>';
  395. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/question_create.php?'.api_get_cidreq().'">'.
  396. Display :: return_icon('new_question.png', get_lang('AddQ'), '', ICON_SIZE_MEDIUM).'</a>';
  397. // Question category
  398. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/tests_category.php?'.api_get_cidreq().'">';
  399. echo Display::return_icon('green_open.png', get_lang('QuestionCategory'), '', ICON_SIZE_MEDIUM);
  400. echo '</a>';
  401. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/question_pool.php?'.api_get_cidreq().'">';
  402. echo Display::return_icon('database.png', get_lang('QuestionPool'), '', ICON_SIZE_MEDIUM);
  403. echo '</a>';
  404. //echo Display::url(Display::return_icon('looknfeel.png', get_lang('Media')), 'media.php?' . api_get_cidreq());
  405. // end question category
  406. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/hotpotatoes.php?'.api_get_cidreq().'">'.Display :: return_icon('import_hotpotatoes.png', get_lang('ImportHotPotatoesQuiz'), '', ICON_SIZE_MEDIUM).'</a>';
  407. // link to import qti2 ...
  408. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/qti2.php?'.api_get_cidreq().'">'.Display :: return_icon('import_qti2.png', get_lang('ImportQtiQuiz'), '', ICON_SIZE_MEDIUM).'</a>';
  409. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/aiken.php?'.api_get_cidreq().'">'.Display :: return_icon('import_aiken.png', get_lang('ImportAikenQuiz'), '', ICON_SIZE_MEDIUM).'</a>';
  410. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/upload_exercise.php?'.api_get_cidreq().'">'.Display :: return_icon('import_excel.png', get_lang('ImportExcelQuiz'), '', ICON_SIZE_MEDIUM).'</a>';
  411. echo Display::url(
  412. Display::return_icon(
  413. 'clean_all.png',
  414. get_lang('CleanAllStudentsResultsForAllTests'),
  415. '',
  416. ICON_SIZE_MEDIUM
  417. ),
  418. '',
  419. array(
  420. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToEmptyAllTestResults'), ENT_QUOTES, $charset))."')) return false;",
  421. 'href' => api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq().'&choice=clean_all_test&sec_token='.$token
  422. )
  423. );
  424. }
  425. if ($is_allowedToEdit) {
  426. echo '</div>'; // closing the actions div
  427. }
  428. if ($total > $limit) {
  429. echo '<div style="float:right;height:20px;">';
  430. //show pages navigation link for previous page
  431. if ($page) {
  432. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&page=".($page - 1)."\">".Display :: return_icon('action_prev.png', get_lang('PreviousPage'))."</a>";
  433. } elseif ($total_exercises + $hp_count > $limit) {
  434. echo Display :: return_icon('action_prev_na.png', get_lang('PreviousPage'));
  435. }
  436. //show pages navigation link for previous page
  437. if ($total_exercises > $from + $limit || $hp_count > $from + $limit) {
  438. echo ' '."<a href=\"".api_get_self()."?".api_get_cidreq()."&page=".($page + 1)."\">".Display::return_icon('action_next.png', get_lang('NextPage'))."</a>";
  439. } elseif ($page) {
  440. echo ' '.Display :: return_icon('action_next_na.png', get_lang('NextPage'));
  441. }
  442. echo '</div>';
  443. }
  444. $i = 1;
  445. $online_icon = Display::return_icon('online.png', get_lang('Visible'), array('width' => '12px'));
  446. $offline_icon = Display::return_icon('offline.png', get_lang('Invisible'), array('width' => '12px'));
  447. $exerciseList = array();
  448. $list_ordered = null;
  449. while ($row = Database :: fetch_array($result, 'ASSOC')) {
  450. $exerciseList[$row['iid']] = $row;
  451. }
  452. if (!empty($exerciseList) &&
  453. api_get_setting('exercise_invisible_in_session') === 'true'
  454. ) {
  455. if (!empty($sessionId)) {
  456. $changeDefaultVisibility = true;
  457. if (api_get_setting('configure_exercise_visibility_in_course') === 'true') {
  458. if (api_get_course_setting('exercise_invisible_in_session') == 1) {
  459. $changeDefaultVisibility = true;
  460. } else {
  461. $changeDefaultVisibility = false;
  462. }
  463. }
  464. if ($changeDefaultVisibility) {
  465. // Check exercise
  466. foreach ($exerciseList as $exercise) {
  467. if ($exercise['session_id'] == 0) {
  468. $visibilityInfo = api_get_item_property_info(
  469. $courseInfo,
  470. TOOL_QUIZ,
  471. $exercise['iid'],
  472. $sessionId
  473. );
  474. if (empty($visibilityInfo)) {
  475. // Create a record for this
  476. api_item_property_update(
  477. $courseInfo,
  478. TOOL_QUIZ,
  479. $exercise['iid'],
  480. 'invisible',
  481. api_get_user_id(),
  482. 0,
  483. null,
  484. '',
  485. '',
  486. $sessionId
  487. );
  488. }
  489. }
  490. }
  491. }
  492. }
  493. }
  494. if (isset($list_ordered) && !empty($list_ordered)) {
  495. $new_question_list = array();
  496. foreach ($list_ordered as $exercise_id) {
  497. if (isset($exerciseList[$exercise_id])) {
  498. $new_question_list[] = $exerciseList[$exercise_id];
  499. }
  500. }
  501. $exerciseList = $new_question_list;
  502. }
  503. $tableRows = [];
  504. /* Listing exercises */
  505. if (!empty($exerciseList)) {
  506. if ($origin != 'learnpath') {
  507. //avoid sending empty parameters
  508. $myorigin = (empty($origin) ? '' : '&origin='.$origin);
  509. $mylpid = (empty($learnpath_id) ? '' : '&learnpath_id='.$learnpath_id);
  510. $mylpitemid = (empty($learnpath_item_id) ? '' : '&learnpath_item_id='.$learnpath_item_id);
  511. $i = 1;
  512. foreach ($exerciseList as $row) {
  513. $my_exercise_id = $row['id'];
  514. $exercise = new Exercise();
  515. $exercise->read($my_exercise_id, false);
  516. if (empty($exercise->id)) {
  517. continue;
  518. }
  519. $locked = $exercise->is_gradebook_locked;
  520. $i++;
  521. //validacion when belongs to a session
  522. $session_img = api_get_session_image($row['session_id'], $userInfo['status']);
  523. $time_limits = false;
  524. if (!empty($row['start_time']) || !empty($row['end_time'])) {
  525. $time_limits = true;
  526. }
  527. $is_actived_time = false;
  528. if ($time_limits) {
  529. // check if start time
  530. $start_time = false;
  531. if (!empty($row['start_time'])) {
  532. $start_time = api_strtotime($row['start_time'], 'UTC');
  533. }
  534. $end_time = false;
  535. if (!empty($row['end_time'])) {
  536. $end_time = api_strtotime($row['end_time'], 'UTC');
  537. }
  538. $now = time();
  539. //If both "clocks" are enable
  540. if ($start_time && $end_time) {
  541. if ($now > $start_time && $end_time > $now) {
  542. $is_actived_time = true;
  543. }
  544. } else {
  545. //we check the start and end
  546. if ($start_time) {
  547. if ($now > $start_time) {
  548. $is_actived_time = true;
  549. }
  550. }
  551. if ($end_time) {
  552. if ($end_time > $now) {
  553. $is_actived_time = true;
  554. }
  555. }
  556. }
  557. }
  558. // Blocking empty start times see BT#2800
  559. global $_custom;
  560. if (isset($_custom['exercises_hidden_when_no_start_date']) &&
  561. $_custom['exercises_hidden_when_no_start_date']
  562. ) {
  563. if (empty($row['start_time'])) {
  564. $time_limits = true;
  565. $is_actived_time = false;
  566. }
  567. }
  568. $cut_title = $exercise->getCutTitle();
  569. $alt_title = '';
  570. if ($cut_title != $row['title']) {
  571. $alt_title = ' title = "'.$row['title'].'" ';
  572. }
  573. // Teacher only
  574. if ($is_allowedToEdit) {
  575. $lp_blocked = null;
  576. if ($exercise->exercise_was_added_in_lp == true) {
  577. $lp_blocked = Display::div(
  578. get_lang('AddedToLPCannotBeAccessed'),
  579. array('class' => 'lp_content_type_label')
  580. );
  581. }
  582. $visibility = api_get_item_visibility(
  583. $courseInfo,
  584. TOOL_QUIZ,
  585. $my_exercise_id,
  586. 0
  587. );
  588. if (!empty($sessionId)) {
  589. $setting = api_get_configuration_value('show_hidden_exercise_added_to_lp');
  590. if ($setting) {
  591. if ($exercise->exercise_was_added_in_lp == false) {
  592. if ($visibility == 0) {
  593. continue;
  594. }
  595. }
  596. } else {
  597. if ($visibility == 0) {
  598. continue;
  599. }
  600. }
  601. $visibility = api_get_item_visibility(
  602. $courseInfo,
  603. TOOL_QUIZ,
  604. $my_exercise_id,
  605. $sessionId
  606. );
  607. }
  608. if ($row['active'] == 0 || $visibility == 0) {
  609. $title = Display::tag('font', $cut_title, array('style' => 'color:grey'));
  610. } else {
  611. $title = $cut_title;
  612. }
  613. $count_exercise_not_validated = intval(
  614. Event::count_exercise_result_not_validated(
  615. $my_exercise_id,
  616. $courseId,
  617. $session_id
  618. )
  619. );
  620. $move = Display::return_icon(
  621. 'all_directions.png',
  622. get_lang('Move'),
  623. array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;')
  624. );
  625. $move = null;
  626. $class_tip = '';
  627. if (!empty($count_exercise_not_validated)) {
  628. $results_text = $count_exercise_not_validated == 1 ? get_lang('ResultNotRevised') : get_lang('ResultsNotRevised');
  629. $title .= '<span class="exercise_tooltip" style="display: none;">'.$count_exercise_not_validated.' '.$results_text.' </span>';
  630. $class_tip = 'link_tooltip';
  631. }
  632. //$class_tip = 'exercise_link';
  633. $url = $move.'<a '.$alt_title.' class="'.$class_tip.'" id="tooltip_'.$row['id'].'" href="overview.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id'].'">
  634. '.Display::return_icon('quiz.png', $row['title']).'
  635. '.$title.' </a>';
  636. $item = Display::tag('td', $url.' '.$session_img.$lp_blocked);
  637. // Count number exercise - teacher
  638. $sql = "SELECT count(*) count FROM $TBL_EXERCISE_QUESTION
  639. WHERE c_id = $courseId AND exercice_id = $my_exercise_id";
  640. $sqlresult = Database::query($sql);
  641. $rowi = Database :: result($sqlresult, 0, 0);
  642. if ($session_id == $row['session_id']) {
  643. // Questions list
  644. $actions = Display::url(
  645. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL),
  646. 'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']
  647. );
  648. // Test settings
  649. $actions .= Display::url(
  650. Display::return_icon('settings.png', get_lang('Configure'), '', ICON_SIZE_SMALL),
  651. 'exercise_admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']
  652. );
  653. // Exercise results
  654. $actions .='<a href="exercise_report.php?'.api_get_cidreq().'&exerciseId='.$row['id'].'">'.
  655. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  656. // Export
  657. $actions .= Display::url(
  658. Display::return_icon('cd.gif', get_lang('CopyExercise')),
  659. '',
  660. array(
  661. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToCopy'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;",
  662. 'href' => 'exercise.php?'.api_get_cidreq().'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id']
  663. )
  664. );
  665. // Clean exercise
  666. if ($locked == false) {
  667. $actions .= Display::url(
  668. Display::return_icon('clean.png', get_lang('CleanStudentResults'), '', ICON_SIZE_SMALL),
  669. '',
  670. array(
  671. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDeleteResults'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;",
  672. 'href' => 'exercise.php?'.api_get_cidreq().'&choice=clean_results&sec_token='.$token.'&exerciseId='.$row['id']
  673. )
  674. );
  675. } else {
  676. $actions .= Display::return_icon('clean_na.png', get_lang('ResourceLockedByGradebook'), '', ICON_SIZE_SMALL);
  677. }
  678. // Visible / invisible
  679. // Check if this exercise was added in a LP
  680. if ($exercise->exercise_was_added_in_lp == true) {
  681. $actions .= Display::return_icon('invisible.png', get_lang('AddedToLPCannotBeAccessed'), '', ICON_SIZE_SMALL);
  682. } else {
  683. if ($row['active'] == 0 || $visibility == 0) {
  684. $actions .= Display::url(Display::return_icon('invisible.png', get_lang('Activate'), '', ICON_SIZE_SMALL), 'exercise.php?'.api_get_cidreq().'&choice=enable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']);
  685. } else {
  686. // else if not active
  687. $actions .= Display::url(Display::return_icon('visible.png', get_lang('Deactivate'), '', ICON_SIZE_SMALL), 'exercise.php?'.api_get_cidreq().'&choice=disable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']);
  688. }
  689. }
  690. // Export qti ...
  691. $actions .= Display::url(Display::return_icon('export_qti2.png', 'IMS/QTI', '', ICON_SIZE_SMALL), 'exercise.php?choice=exportqti2&exerciseId='.$row['id'].'&'.api_get_cidreq());
  692. } else {
  693. // not session
  694. $actions = Display::return_icon('edit_na.png', get_lang('ExerciseEditionNotAvailableInSession'));
  695. // Check if this exercise was added in a LP
  696. if ($exercise->exercise_was_added_in_lp == true) {
  697. $actions .= Display::return_icon('invisible.png', get_lang('AddedToLPCannotBeAccessed'), '', ICON_SIZE_SMALL);
  698. } else {
  699. if ($row['active'] == 0 || $visibility == 0) {
  700. $actions .= Display::url(
  701. Display::return_icon('invisible.png', get_lang('Activate'), '', ICON_SIZE_SMALL),
  702. 'exercise.php?'.api_get_cidreq().'&choice=enable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']
  703. );
  704. } else {
  705. // else if not active
  706. $actions .= Display::url(
  707. Display::return_icon('visible.png', get_lang('Deactivate'), '', ICON_SIZE_SMALL),
  708. 'exercise.php?'.api_get_cidreq().'&choice=disable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']
  709. );
  710. }
  711. }
  712. $actions .='<a href="exercise_report.php?'.api_get_cidreq().'&exerciseId='.$row['id'].'">'.
  713. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  714. $actions .= Display::url(Display::return_icon('cd.gif', get_lang('CopyExercise')), '', array('onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToCopy'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;", 'href' => 'exercise.php?'.api_get_cidreq().'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id']));
  715. }
  716. // Delete
  717. if ($session_id == $row['session_id']) {
  718. if ($locked == false) {
  719. $actions .= Display::url(
  720. Display::return_icon(
  721. 'delete.png',
  722. get_lang('Delete'),
  723. '',
  724. ICON_SIZE_SMALL
  725. ),
  726. '',
  727. array('onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDeleteJS'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;", 'href' => 'exercise.php?'.api_get_cidreq().'&choice=delete&sec_token='.$token.'&exerciseId='.$row['id'])
  728. );
  729. } else {
  730. $actions .= Display::return_icon('delete_na.png', get_lang('ResourceLockedByGradebook'), '', ICON_SIZE_SMALL);
  731. }
  732. }
  733. // Number of questions
  734. $random_label = null;
  735. if ($row['random'] > 0 || $row['random'] == -1) {
  736. // if random == -1 means use random questions with all questions
  737. $random_number_of_question = $row['random'];
  738. if ($random_number_of_question == -1) {
  739. $random_number_of_question = $rowi;
  740. }
  741. if ($row['random_by_category'] > 0) {
  742. $nbQuestionsTotal = TestCategory::getNumberOfQuestionRandomByCategory(
  743. $my_exercise_id,
  744. $random_number_of_question
  745. );
  746. $number_of_questions = $nbQuestionsTotal." ";
  747. $number_of_questions .= ($nbQuestionsTotal > 1) ? get_lang("QuestionsLowerCase") : get_lang("QuestionLowerCase");
  748. $number_of_questions .= " - ";
  749. $number_of_questions .= min(TestCategory::getNumberMaxQuestionByCat($my_exercise_id), $random_number_of_question).' '.get_lang('QuestionByCategory');
  750. } else {
  751. $random_label = ' ('.get_lang('Random').') ';
  752. $number_of_questions = $random_number_of_question.' '.$random_label;
  753. //Bug if we set a random value bigger than the real number of questions
  754. if ($random_number_of_question > $rowi) {
  755. $number_of_questions = $rowi.' '.$random_label;
  756. }
  757. }
  758. } else {
  759. $number_of_questions = $rowi;
  760. }
  761. //Attempts
  762. //$attempts = ExerciseLib::get_count_exam_results($row['id']).' '.get_lang('Attempts');
  763. //$item .= Display::tag('td',$attempts);
  764. $item .= Display::tag('td', $number_of_questions);
  765. } else {
  766. // Student only.
  767. $visibility = api_get_item_visibility(
  768. $courseInfo,
  769. TOOL_QUIZ,
  770. $my_exercise_id,
  771. $sessionId
  772. );
  773. if ($visibility == 0) {
  774. continue;
  775. }
  776. $url = '<a '.$alt_title.' href="overview.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id'].'">'.
  777. $cut_title.'</a>';
  778. // Link of the exercise.
  779. $item = Display::tag('td', $url.' '.$session_img);
  780. // Count number exercise questions.
  781. /*$sql = "SELECT count(*) FROM $TBL_EXERCISE_QUESTION
  782. WHERE c_id = $courseId AND exercice_id = ".$row['id'];
  783. $sqlresult = Database::query($sql);
  784. $rowi = Database::result($sqlresult, 0);
  785. if ($row['random'] > 0) {
  786. $row['random'].' '.api_strtolower(get_lang(($row['random'] > 1 ? 'Questions' : 'Question')));
  787. } else {
  788. //show results student
  789. $rowi.' '.api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question')));
  790. }*/
  791. // This query might be improved later on by ordering by the new "tms" field rather than by exe_id
  792. // Don't remove this marker: note-query-exe-results
  793. $sql = "SELECT * FROM $TBL_TRACK_EXERCISES
  794. WHERE
  795. exe_exo_id = ".$row['id']." AND
  796. exe_user_id = $userId AND
  797. c_id = ".api_get_course_int_id()." AND
  798. status <> 'incomplete' AND
  799. orig_lp_id = 0 AND
  800. orig_lp_item_id = 0 AND
  801. session_id = '".api_get_session_id()."'
  802. ORDER BY exe_id DESC";
  803. $qryres = Database::query($sql);
  804. $num = Database :: num_rows($qryres);
  805. // Hide the results.
  806. $my_result_disabled = $row['results_disabled'];
  807. // Time limits are on
  808. if ($time_limits) {
  809. // Exam is ready to be taken
  810. if ($is_actived_time) {
  811. // Show results 697 $attempt_text = get_lang('LatestAttempt').' : ';
  812. if ($my_result_disabled == 0 || $my_result_disabled == 2) {
  813. //More than one attempt
  814. if ($num > 0) {
  815. $row_track = Database :: fetch_array($qryres);
  816. $attempt_text = get_lang('LatestAttempt').' : ';
  817. $attempt_text .= ExerciseLib::show_score($row_track['exe_result'], $row_track['exe_weighting']);
  818. } else {
  819. //No attempts
  820. $attempt_text = get_lang('NotAttempted');
  821. }
  822. } else {
  823. //$attempt_text = get_lang('CantShowResults');
  824. $attempt_text = '-';
  825. }
  826. } else {
  827. //Quiz not ready due to time limits 700 $attempt_text = get_lang('NotAttempted');
  828. //@todo use the is_visible function
  829. if (!empty($row['start_time']) && !empty($row['end_time'])) {
  830. $today = time();
  831. $start_time = api_strtotime($row['start_time'], 'UTC');
  832. $end_time = api_strtotime($row['end_time'], 'UTC');
  833. if ($today < $start_time) {
  834. $attempt_text = sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_convert_and_format_date($row['start_time']), api_convert_and_format_date($row['end_time']));
  835. } else {
  836. if ($today > $end_time) {
  837. $attempt_text = sprintf(get_lang('ExerciseWasActivatedFromXToY'), api_convert_and_format_date($row['start_time']), api_convert_and_format_date($row['end_time']));
  838. }
  839. }
  840. } else {
  841. //$attempt_text = get_lang('ExamNotAvailableAtThisTime');
  842. if (!empty($row['start_time'])) {
  843. $attempt_text = sprintf(
  844. get_lang('ExerciseAvailableFromX'),
  845. api_convert_and_format_date($row['start_time'])
  846. );
  847. }
  848. if (!empty($row['end_time'])) {
  849. $attempt_text = sprintf(
  850. get_lang('ExerciseAvailableUntilX'),
  851. api_convert_and_format_date($row['end_time'])
  852. );
  853. }
  854. }
  855. }
  856. } else {
  857. // Normal behaviour.
  858. // Show results.
  859. if ($my_result_disabled == 0 || $my_result_disabled == 2) {
  860. if ($num > 0) {
  861. $row_track = Database :: fetch_array($qryres);
  862. $attempt_text = get_lang('LatestAttempt').' : ';
  863. $attempt_text .= ExerciseLib::show_score(
  864. $row_track['exe_result'],
  865. $row_track['exe_weighting']
  866. );
  867. } else {
  868. $attempt_text = get_lang('NotAttempted');
  869. }
  870. } else {
  871. //$attempt_text = get_lang('CantShowResults');
  872. $attempt_text = '-';
  873. }
  874. }
  875. $class_tip = '';
  876. if (empty($num)) {
  877. $num = '';
  878. } else {
  879. $class_tip = 'link_tooltip';
  880. //@todo use sprintf and show the results validated by the teacher
  881. if ($num == 1) {
  882. $num = $num.' '.get_lang('Result');
  883. } else {
  884. $num = $num.' '.get_lang('Results');
  885. }
  886. $num = '<span class="tooltip" style="display: none;">'.$num.'</span>';
  887. }
  888. $item .= Display::tag('td', $attempt_text);
  889. }
  890. if ($is_allowedToEdit) {
  891. $item .= Display::tag('td', $actions, array('class' => 'td_actions'));
  892. } else {
  893. if ($isDrhOfCourse) {
  894. $actions ='<a href="exercise_report.php?'.api_get_cidreq().'&exerciseId='.$row['id'].'">'.
  895. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  896. $item .= Display::tag('td', $actions, array('class' => 'td_actions'));
  897. }
  898. }
  899. $tableRows[] = Display::tag(
  900. 'tr',
  901. $item,
  902. array(
  903. 'id' => 'exercise_list_' . $my_exercise_id,
  904. )
  905. );
  906. }
  907. }
  908. }
  909. // end exercise list
  910. // Hotpotatoes results
  911. $hotpotatoes_exist = false;
  912. if ($is_allowedToEdit) {
  913. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  914. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  915. WHERE
  916. d.c_id = $courseId AND
  917. ip.c_id = $courseId AND
  918. d.id = ip.ref AND
  919. ip.tool = '".TOOL_DOCUMENT."' AND
  920. (d.path LIKE '%htm%') AND
  921. d.path LIKE '".Database :: escape_string($uploadPath.'/%/%')."'
  922. LIMIT ".$from.",".$limit; // only .htm or .html files listed
  923. } else {
  924. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  925. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  926. WHERE
  927. d.c_id = $courseId AND
  928. ip.c_id = $courseId AND
  929. d.id = ip.ref AND
  930. ip.tool = '".TOOL_DOCUMENT."' AND
  931. (d.path LIKE '%htm%') AND
  932. d.path LIKE '".Database :: escape_string($uploadPath.'/%/%')."' AND
  933. ip.visibility='1'
  934. LIMIT ".$from.",".$limit;
  935. }
  936. $result = Database::query($sql);
  937. while ($row = Database :: fetch_array($result, 'ASSOC')) {
  938. $attribute['path'][] = $row['path'];
  939. $attribute['visibility'][] = $row['visibility'];
  940. $attribute['comment'][] = $row['comment'];
  941. }
  942. $nbrActiveTests = 0;
  943. if (isset($attribute['path']) && is_array($attribute['path'])) {
  944. $hotpotatoes_exist = true;
  945. while (list($key, $path) = each($attribute['path'])) {
  946. $item = '';
  947. list ($a, $vis) = each($attribute['visibility']);
  948. $active = !empty($vis);
  949. $title = GetQuizName($path, $documentPath);
  950. if ($title == '') {
  951. $title = basename($path);
  952. }
  953. // prof only
  954. if ($is_allowedToEdit) {
  955. $item = Display::tag(
  956. 'td',
  957. implode(PHP_EOL, [
  958. Display::return_icon('hotpotatoes_s.png', "HotPotatoes"),
  959. Display::url(
  960. $title,
  961. 'showinframes.php?' . api_get_cidreq() . '&' . http_build_query([
  962. 'file' => $path,
  963. 'uid' => $userId
  964. ]),
  965. ['class' => !$active ? 'text-muted' : null]
  966. )
  967. ])
  968. );
  969. $item .= Display::tag('td', '-');
  970. $actions = Display::url(
  971. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL),
  972. 'adminhp.php?'.api_get_cidreq().'&hotpotatoesName='.$path
  973. );
  974. $actions .='<a href="hotpotatoes_exercise_report.php?'.api_get_cidreq().'&path='.$path.'">'.
  975. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  976. // if active
  977. if ($active) {
  978. $nbrActiveTests = $nbrActiveTests + 1;
  979. $actions .= ' <a href="'.$exercisePath.'?'.api_get_cidreq().'&hpchoice=disable&page='.$page.'&file='.$path.'">'.
  980. Display::return_icon('visible.png', get_lang('Deactivate'), '', ICON_SIZE_SMALL).'</a>';
  981. } else { // else if not active
  982. $actions .=' <a href="'.$exercisePath.'?'.api_get_cidreq().'&hpchoice=enable&page='.$page.'&file='.$path.'">'.
  983. Display::return_icon('invisible.png', get_lang('Activate'), '', ICON_SIZE_SMALL).'</a>';
  984. }
  985. $actions .= '<a href="'.$exercisePath.'?'.api_get_cidreq().'&hpchoice=delete&file='.$path.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('AreYouSureToDeleteJS'), ENT_QUOTES, $charset).' '.$title."?").'\')) return false;">'.
  986. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
  987. $item .= Display::tag('td', $actions);
  988. $tableRows[] = Display::tag('tr', $item);
  989. } else {
  990. // Student only
  991. if ($active) {
  992. $attempt = ExerciseLib::getLatestHotPotatoResult(
  993. $path,
  994. $userId,
  995. api_get_course_int_id(),
  996. api_get_session_id()
  997. );
  998. $nbrActiveTests = $nbrActiveTests + 1;
  999. $item .= Display::tag(
  1000. 'td',
  1001. Display::url(
  1002. $title,
  1003. 'showinframes.php?' . api_get_cidreq() . '&' . http_build_query([
  1004. 'file' => $path,
  1005. 'cid' => api_get_course_id(),
  1006. 'uid' => $userId
  1007. ])
  1008. )
  1009. );
  1010. if (!empty($attempt)) {
  1011. $actions = '<a href="hotpotatoes_exercise_report.php?'.api_get_cidreq().'&path='.$path.'&filter_by_user='.$userId.'">'.Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  1012. $attemptText = get_lang('LatestAttempt').' : ';
  1013. $attemptText .= ExerciseLib::show_score($attempt['exe_result'], $attempt['exe_weighting']).' ';
  1014. $attemptText .= $actions;
  1015. } else {
  1016. // No attempts.
  1017. $attemptText = get_lang('NotAttempted').' ';
  1018. }
  1019. $item .= Display::tag('td', $attemptText);
  1020. if ($isDrhOfCourse) {
  1021. $actions ='<a href="hotpotatoes_exercise_report.php?'.api_get_cidreq().'&path='.$path.'">'.
  1022. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  1023. $item .= Display::tag('td', $actions, array('class' => 'td_actions'));
  1024. }
  1025. $tableRows[] = Display::tag('tr', $item);
  1026. }
  1027. }
  1028. }
  1029. }
  1030. if (empty($exerciseList) && $hotpotatoes_exist == false) {
  1031. if ($is_allowedToEdit && $origin != 'learnpath') {
  1032. echo '<div id="no-data-view">';
  1033. echo '<h3>'.get_lang('Quiz').'</h3>';
  1034. echo Display::return_icon('quiz.png', '', array(), 64);
  1035. echo '<div class="controls">';
  1036. echo Display::url('<em class="fa fa-plus"></em> '.get_lang('NewEx'), 'exercise_admin.php?'.api_get_cidreq(), array('class' => 'btn btn-primary'));
  1037. echo '</div>';
  1038. echo '</div>';
  1039. }
  1040. } else {
  1041. if ($is_allowedToEdit) {
  1042. $headers = [
  1043. get_lang('ExerciseName'),
  1044. get_lang('QuantityQuestions'),
  1045. get_lang('Actions')
  1046. ];
  1047. } else {
  1048. $headers = [
  1049. get_lang('ExerciseName'),
  1050. get_lang('Status')
  1051. ];
  1052. if ($isDrhOfCourse) {
  1053. $headers[] = get_lang('Actions');
  1054. }
  1055. }
  1056. $headerList = '';
  1057. foreach ($headers as $header) {
  1058. $headerList .= Display::tag('th', $header);
  1059. }
  1060. echo '<div class="table-responsive">';
  1061. echo '<table class="table table-striped table-hover">';
  1062. echo Display::tag(
  1063. 'thead',
  1064. Display::tag('tr', $headerList)
  1065. );
  1066. echo '<tbody>';
  1067. foreach ($tableRows as $row) {
  1068. echo $row;
  1069. }
  1070. echo '</tbody>';
  1071. echo '</table>';
  1072. echo '</div>';
  1073. }
  1074. if ($origin != 'learnpath') { //so we are not in learnpath tool
  1075. Display :: display_footer();
  1076. }