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