exercise.php 46 KB

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