exercise.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  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. require_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php';
  101. $export = export_exercise_to_qti($exerciseId, true);
  102. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  103. $temp_dir_short = api_get_unique_id();
  104. $temp_zip_dir = $archive_path.$temp_dir_short;
  105. if (!is_dir($temp_zip_dir)) {
  106. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  107. }
  108. $temp_zip_file = $temp_zip_dir."/".api_get_unique_id().".zip";
  109. $temp_xml_file = $temp_zip_dir."/qti2export_".$exerciseId.'.xml';
  110. file_put_contents($temp_xml_file, $export);
  111. $xmlReader = new XMLReader();
  112. $xmlReader->open($temp_xml_file);
  113. $xmlReader->setParserProperty(XMLReader::VALIDATE, true);
  114. $isValid = $xmlReader->isValid();
  115. if ($isValid) {
  116. $zip_folder = new PclZip($temp_zip_file);
  117. $zip_folder->add($temp_xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
  118. $name = 'qti2_export_'.$exerciseId.'.zip';
  119. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  120. unlink($temp_zip_file);
  121. unlink($temp_xml_file);
  122. rmdir($temp_zip_dir);
  123. exit; //otherwise following clicks may become buggy
  124. } else {
  125. $errorXmlExport = Display :: return_message(get_lang('ErrorWritingXMLFile'), 'error');
  126. }
  127. }
  128. if ($origin != 'learnpath') {
  129. //so we are not in learnpath tool
  130. Display :: display_header($nameTools, get_lang('Exercise'));
  131. if (isset($_GET['message'])) {
  132. if (in_array($_GET['message'], array('ExerciseEdited'))) {
  133. Display :: display_confirmation_message(get_lang($_GET['message']));
  134. }
  135. }
  136. } else {
  137. Display :: display_reduced_header();
  138. }
  139. Event::event_access_tool(TOOL_QUIZ);
  140. // Tool introduction
  141. Display :: display_introduction_section(TOOL_QUIZ);
  142. if (!empty($errorXmlExport)) {
  143. echo $errorXmlExport;
  144. }
  145. HotPotGCt($documentPath, 1, $userId);
  146. // Only for administrator
  147. if ($is_allowedToEdit) {
  148. if (!empty($choice)) {
  149. // All test choice, clean all test's results
  150. if ($choice == 'clean_all_test') {
  151. $check = Security::check_token('get');
  152. if ($check) {
  153. // list of exercises in a course/session
  154. // we got variable $courseId $courseInfo session api_get_session_id()
  155. $exerciseList = ExerciseLib::get_all_exercises_for_course_id(
  156. $courseInfo,
  157. api_get_session_id(),
  158. $courseId,
  159. false
  160. );
  161. $quantity_results_deleted = 0;
  162. foreach ($exerciseList as $exeItem) {
  163. // delete result for test, if not in a gradebook
  164. $exercise_action_locked = api_resource_is_locked_by_gradebook($exeItem['id'], LINK_EXERCISE);
  165. if ($exercise_action_locked == false) {
  166. $objExerciseTmp = new Exercise();
  167. if ($objExerciseTmp->read($exeItem['id'])) {
  168. $quantity_results_deleted += $objExerciseTmp->clean_results(true);
  169. }
  170. }
  171. }
  172. Display:: display_confirmation_message(
  173. sprintf(
  174. get_lang('XResultsCleaned'),
  175. $quantity_results_deleted
  176. )
  177. );
  178. }
  179. }
  180. // single exercise choice
  181. // construction of Exercise
  182. $objExerciseTmp = new Exercise();
  183. $check = Security::check_token('get');
  184. $exercise_action_locked = api_resource_is_locked_by_gradebook(
  185. $exerciseId,
  186. LINK_EXERCISE
  187. );
  188. if ($objExerciseTmp->read($exerciseId)) {
  189. if ($check) {
  190. switch ($choice) {
  191. case 'delete':
  192. // deletes an exercise
  193. if ($exercise_action_locked == false) {
  194. $objExerciseTmp->delete();
  195. $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 1, $exerciseId, api_get_session_id());
  196. if ($link_info !== false) {
  197. GradebookUtils::remove_resource_from_course_gradebook($link_info['id']);
  198. }
  199. Display :: display_confirmation_message(get_lang('ExerciseDeleted'));
  200. }
  201. break;
  202. case 'enable':
  203. // enables an exercise
  204. $objExerciseTmp->enable();
  205. $objExerciseTmp->save();
  206. api_item_property_update($courseInfo, TOOL_QUIZ, $objExerciseTmp->id, 'visible', $userId);
  207. // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
  208. Display :: display_confirmation_message(get_lang('VisibilityChanged'));
  209. break;
  210. case 'disable':
  211. // disables an exercise
  212. $objExerciseTmp->disable();
  213. $objExerciseTmp->save();
  214. api_item_property_update($courseInfo, TOOL_QUIZ, $objExerciseTmp->id, 'invisible', $userId);
  215. Display :: display_confirmation_message(get_lang('VisibilityChanged'));
  216. break;
  217. case 'disable_results':
  218. //disable the results for the learners
  219. $objExerciseTmp->disable_results();
  220. $objExerciseTmp->save();
  221. Display :: display_confirmation_message(get_lang('ResultsDisabled'));
  222. break;
  223. case 'enable_results':
  224. //disable the results for the learners
  225. $objExerciseTmp->enable_results();
  226. $objExerciseTmp->save();
  227. Display :: display_confirmation_message(get_lang('ResultsEnabled'));
  228. break;
  229. case 'clean_results':
  230. //clean student results
  231. if ($exercise_action_locked == false) {
  232. $quantity_results_deleted = $objExerciseTmp->clean_results(true);
  233. Display :: display_confirmation_message(sprintf(get_lang('XResultsCleaned'), $quantity_results_deleted));
  234. }
  235. break;
  236. case 'copy_exercise': //copy an exercise
  237. $objExerciseTmp->copy_exercise();
  238. Display :: display_confirmation_message(get_lang('ExerciseCopied'));
  239. break;
  240. }
  241. }
  242. }
  243. // destruction of Exercise
  244. unset($objExerciseTmp);
  245. Security::clear_token();
  246. }
  247. if (!empty($hpchoice)) {
  248. switch ($hpchoice) {
  249. case 'delete':
  250. // deletes an exercise
  251. $imgparams = array();
  252. $imgcount = 0;
  253. GetImgParams($file, $documentPath, $imgparams, $imgcount);
  254. $fld = GetFolderName($file);
  255. for ($i = 0; $i < $imgcount; $i++) {
  256. my_delete($documentPath.$uploadPath."/".$fld."/".$imgparams[$i]);
  257. update_db_info("delete", $uploadPath."/".$fld."/".$imgparams[$i]);
  258. }
  259. if (!is_dir($documentPath.$uploadPath."/".$fld."/")) {
  260. my_delete($documentPath.$file);
  261. update_db_info("delete", $file);
  262. } else {
  263. if (my_delete($documentPath.$file)) {
  264. update_db_info("delete", $file);
  265. }
  266. }
  267. /* hotpotatoes folder may contains several tests so
  268. don't delete folder if not empty :
  269. http://support.chamilo.org/issues/2165
  270. */
  271. if (!(strstr($uploadPath, DIR_HOTPOTATOES) && !folder_is_empty($documentPath.$uploadPath."/".$fld."/"))) {
  272. my_delete($documentPath.$uploadPath."/".$fld."/");
  273. }
  274. break;
  275. case 'enable': // enables an exercise
  276. $newVisibilityStatus = "1"; //"visible"
  277. $query = "SELECT id FROM $TBL_DOCUMENT
  278. WHERE c_id = $courseId AND path='".Database :: escape_string($file)."'";
  279. $res = Database::query($query);
  280. $row = Database :: fetch_array($res, 'ASSOC');
  281. api_item_property_update(
  282. $courseInfo,
  283. TOOL_DOCUMENT,
  284. $row['id'],
  285. 'visible',
  286. $userId
  287. );
  288. //$dialogBox = get_lang('ViMod');
  289. break;
  290. case 'disable': // disables an exercise
  291. $newVisibilityStatus = "0"; //"invisible"
  292. $query = "SELECT id FROM $TBL_DOCUMENT
  293. WHERE c_id = $courseId AND path='".Database :: escape_string($file)."'";
  294. $res = Database::query($query);
  295. $row = Database :: fetch_array($res, 'ASSOC');
  296. api_item_property_update(
  297. $courseInfo,
  298. TOOL_DOCUMENT,
  299. $row['id'],
  300. 'invisible',
  301. $userId
  302. );
  303. break;
  304. default:
  305. break;
  306. }
  307. }
  308. }
  309. // Actions div bar
  310. if ($is_allowedToEdit) {
  311. echo '<div class="actions">';
  312. }
  313. // Selects $limit exercises at the same time
  314. // maximum number of exercises on a same page
  315. $limit = 50;
  316. // Display the next and previous link if needed
  317. $from = $page * $limit;
  318. HotPotGCt($documentPath, 1, $userId);
  319. //condition for the session
  320. $course_code = api_get_course_id();
  321. $session_id = api_get_session_id();
  322. $condition_session = api_get_session_condition($session_id, true, true);
  323. // Only for administrators
  324. if ($is_allowedToEdit) {
  325. $total_sql = "SELECT count(iid) as count FROM $TBL_EXERCISES
  326. WHERE c_id = $courseId AND active<>'-1' $condition_session ";
  327. $sql = "SELECT * FROM $TBL_EXERCISES
  328. WHERE c_id = $courseId AND active<>'-1' $condition_session
  329. ORDER BY title
  330. LIMIT ".$from.",".$limit;
  331. } else {
  332. // Only for students
  333. $total_sql = "SELECT count(iid) as count FROM $TBL_EXERCISES
  334. WHERE c_id = $courseId AND active = '1' $condition_session ";
  335. $sql = "SELECT * FROM $TBL_EXERCISES
  336. WHERE c_id = $courseId AND
  337. active='1' $condition_session
  338. ORDER BY title LIMIT ".$from.",".$limit;
  339. }
  340. $result = Database::query($sql);
  341. $result_total = Database::query($total_sql);
  342. $total_exercises = 0;
  343. if (Database :: num_rows($result_total)) {
  344. $result_total = Database::fetch_array($result_total);
  345. $total_exercises = $result_total['count'];
  346. }
  347. //get HotPotatoes files (active and inactive)
  348. if ($is_allowedToEdit) {
  349. $sql = "SELECT * FROM $TBL_DOCUMENT
  350. WHERE
  351. c_id = $courseId AND
  352. path LIKE '".Database :: escape_string($uploadPath.'/%/%')."'";
  353. $res = Database::query($sql);
  354. $hp_count = Database :: num_rows($res);
  355. } else {
  356. $sql = "SELECT * FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  357. WHERE
  358. d.id = ip.ref AND
  359. ip.tool = '".TOOL_DOCUMENT."' AND
  360. d.path LIKE '".Database :: escape_string($uploadPath.'/%/%')."' AND
  361. ip.visibility ='1' AND
  362. d.c_id = ".$courseId." AND
  363. ip.c_id = ".$courseId;
  364. $res = Database::query($sql);
  365. $hp_count = Database :: num_rows($res);
  366. }
  367. $total = $total_exercises + $hp_count;
  368. $token = Security::get_token();
  369. if ($is_allowedToEdit && $origin != 'learnpath') {
  370. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercice/exercise_admin.php?'.api_get_cidreq().'">'.
  371. Display :: return_icon('new_exercice.png', get_lang('NewEx'), '', ICON_SIZE_MEDIUM).'</a>';
  372. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercice/question_create.php?'.api_get_cidreq().'">'.
  373. Display :: return_icon('new_question.png', get_lang('AddQ'), '', ICON_SIZE_MEDIUM).'</a>';
  374. // Question category
  375. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercice/tests_category.php?'.api_get_cidreq().'">';
  376. echo Display::return_icon('question_category_show.gif', get_lang('QuestionCategory'));
  377. echo '</a>';
  378. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercice/question_pool.php?'.api_get_cidreq().'">';
  379. echo Display::return_icon('database.png', get_lang('QuestionPool'), '', ICON_SIZE_MEDIUM);
  380. echo '</a>';
  381. //echo Display::url(Display::return_icon('looknfeel.png', get_lang('Media')), 'media.php?' . api_get_cidreq());
  382. // end question category
  383. 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>';
  384. // link to import qti2 ...
  385. 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>';
  386. 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>';
  387. 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>';
  388. echo Display::url(
  389. Display::return_icon(
  390. 'clean_all.png',
  391. get_lang('CleanAllStudentsResultsForAllTests'),
  392. '',
  393. ICON_SIZE_MEDIUM
  394. ),
  395. '',
  396. array(
  397. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToEmptyAllTestResults'), ENT_QUOTES, $charset))."')) return false;",
  398. 'href' => api_get_path(WEB_CODE_PATH).'exercice/exercise.php?'.api_get_cidreq().'&choice=clean_all_test&sec_token='.$token
  399. )
  400. );
  401. }
  402. if ($is_allowedToEdit) {
  403. echo '</div>'; // closing the actions div
  404. }
  405. if ($total > $limit) {
  406. echo '<div style="float:right;height:20px;">';
  407. //show pages navigation link for previous page
  408. if ($page) {
  409. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&page=".($page - 1)."\">".Display :: return_icon('action_prev.png', get_lang('PreviousPage'))."</a>";
  410. } elseif ($total_exercises + $hp_count > $limit) {
  411. echo Display :: return_icon('action_prev_na.png', get_lang('PreviousPage'));
  412. }
  413. //show pages navigation link for previous page
  414. if ($total_exercises > $from + $limit || $hp_count > $from + $limit) {
  415. echo ' '."<a href=\"".api_get_self()."?".api_get_cidreq()."&page=".($page + 1)."\">".Display::return_icon('action_next.png', get_lang('NextPage'))."</a>";
  416. } elseif ($page) {
  417. echo ' '.Display :: return_icon('action_next_na.png', get_lang('NextPage'));
  418. }
  419. echo '</div>';
  420. }
  421. $i = 1;
  422. $online_icon = Display::return_icon('online.png', get_lang('Visible'), array('width' => '12px'));
  423. $offline_icon = Display::return_icon('offline.png', get_lang('Invisible'), array('width' => '12px'));
  424. $exercise_list = array();
  425. $exercise_obj = new Exercise();
  426. $list_ordered = null;
  427. while ($row = Database :: fetch_array($result, 'ASSOC')) {
  428. $exercise_list[$row['iid']] = $row;
  429. }
  430. if (isset($list_ordered) && !empty($list_ordered)) {
  431. $new_question_list = array();
  432. foreach ($list_ordered as $exercise_id) {
  433. if (isset($exercise_list[$exercise_id])) {
  434. $new_question_list[] = $exercise_list[$exercise_id];
  435. }
  436. }
  437. $exercise_list = $new_question_list;
  438. }
  439. /* Listing exercises */
  440. if (!empty($exercise_list)) {
  441. if ($origin != 'learnpath') {
  442. //avoid sending empty parameters
  443. $myorigin = (empty($origin) ? '' : '&origin='.$origin);
  444. $mylpid = (empty($learnpath_id) ? '' : '&learnpath_id='.$learnpath_id);
  445. $mylpitemid = (empty($learnpath_item_id) ? '' : '&learnpath_item_id='.$learnpath_item_id);
  446. // $token = Security::get_token(); // has been moved above
  447. $i = 1;
  448. foreach ($exercise_list as $row) {
  449. $my_exercise_id = $row['id'];
  450. $exercise_obj = new Exercise();
  451. $exercise_obj->read($my_exercise_id);
  452. if (empty($exercise_obj->id)) {
  453. continue;
  454. }
  455. $locked = $exercise_obj->is_gradebook_locked;
  456. $i++;
  457. //validacion when belongs to a session
  458. $session_img = api_get_session_image($row['session_id'], $userInfo['status']);
  459. $time_limits = false;
  460. if ($row['start_time'] != '0000-00-00 00:00:00' || $row['end_time'] != '0000-00-00 00:00:00') {
  461. $time_limits = true;
  462. }
  463. if ($time_limits) {
  464. // check if start time
  465. $start_time = false;
  466. if ($row['start_time'] != '0000-00-00 00:00:00') {
  467. $start_time = api_strtotime($row['start_time'], 'UTC');
  468. }
  469. $end_time = false;
  470. if ($row['end_time'] != '0000-00-00 00:00:00') {
  471. $end_time = api_strtotime($row['end_time'], 'UTC');
  472. }
  473. $now = time();
  474. $is_actived_time = false;
  475. //If both "clocks" are enable
  476. if ($start_time && $end_time) {
  477. if ($now > $start_time && $end_time > $now) {
  478. $is_actived_time = true;
  479. }
  480. } else {
  481. //we check the start and end
  482. if ($start_time) {
  483. if ($now > $start_time) {
  484. $is_actived_time = true;
  485. }
  486. }
  487. if ($end_time) {
  488. if ($end_time > $now) {
  489. $is_actived_time = true;
  490. }
  491. }
  492. }
  493. }
  494. // Blocking empty start times see BT#2800
  495. global $_custom;
  496. if (isset($_custom['exercises_hidden_when_no_start_date']) &&
  497. $_custom['exercises_hidden_when_no_start_date']
  498. ) {
  499. if (empty($row['start_time']) ||
  500. $row['start_time'] == '0000-00-00 00:00:00'
  501. ) {
  502. $time_limits = true;
  503. $is_actived_time = false;
  504. }
  505. }
  506. $cut_title = $exercise_obj->getCutTitle();
  507. $alt_title = '';
  508. if ($cut_title != $row['title']) {
  509. $alt_title = ' title = "'.$row['title'].'" ';
  510. }
  511. // Teacher only
  512. if ($is_allowedToEdit) {
  513. $lp_blocked = null;
  514. if ($exercise_obj->exercise_was_added_in_lp == true) {
  515. $lp_blocked = Display::div(
  516. get_lang('AddedToLPCannotBeAccessed'),
  517. array('class' => 'lp_content_type_label')
  518. );
  519. }
  520. $visibility = api_get_item_visibility($courseInfo, TOOL_QUIZ, $my_exercise_id);
  521. if ($row['active'] == 0 || $visibility == 0) {
  522. $title = Display::tag('font', $cut_title, array('style' => 'color:grey'));
  523. } else {
  524. $title = $cut_title;
  525. }
  526. $count_exercise_not_validated = intval(
  527. Event::count_exercise_result_not_validated(
  528. $my_exercise_id,
  529. $courseId,
  530. $session_id
  531. )
  532. );
  533. $move = Display::return_icon(
  534. 'all_directions.png',
  535. get_lang('Move'),
  536. array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;')
  537. );
  538. $move = null;
  539. $class_tip = '';
  540. if (!empty($count_exercise_not_validated)) {
  541. $results_text = $count_exercise_not_validated == 1 ? get_lang('ResultNotRevised') : get_lang('ResultsNotRevised');
  542. $title .= '<span class="exercise_tooltip" style="display: none;">'.$count_exercise_not_validated.' '.$results_text.' </span>';
  543. $class_tip = 'link_tooltip';
  544. }
  545. //$class_tip = 'exercise_link';
  546. $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>';
  547. $item = Display::tag('td', $url.' '.$session_img.$lp_blocked);
  548. // Count number exercise - teacher
  549. $sql = "SELECT count(*) count FROM $TBL_EXERCISE_QUESTION
  550. WHERE c_id = $courseId AND exercice_id = $my_exercise_id";
  551. $sqlresult = Database::query($sql);
  552. $rowi = Database :: result($sqlresult, 0, 0);
  553. if ($session_id == $row['session_id']) {
  554. // Questions list
  555. $actions = Display::url(
  556. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL),
  557. 'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']
  558. );
  559. // Test settings
  560. $actions .= Display::url(
  561. Display::return_icon('settings.png', get_lang('Configure'), '', ICON_SIZE_SMALL),
  562. 'exercise_admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']
  563. );
  564. // Exercise results
  565. $actions .='<a href="exercise_report.php?'.api_get_cidreq().'&exerciseId='.$row['id'].'">'.
  566. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  567. // Export
  568. $actions .= Display::url(
  569. Display::return_icon('cd.gif', get_lang('CopyExercise')),
  570. '',
  571. array(
  572. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToCopy'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;",
  573. 'href' => 'exercise.php?'.api_get_cidreq().'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id']
  574. )
  575. );
  576. // Clean exercise
  577. if ($locked == false) {
  578. $actions .= Display::url(
  579. Display::return_icon('clean.png', get_lang('CleanStudentResults'), '', ICON_SIZE_SMALL),
  580. '',
  581. array(
  582. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDeleteResults'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;",
  583. 'href' => 'exercise.php?'.api_get_cidreq().'&choice=clean_results&sec_token='.$token.'&exerciseId='.$row['id']
  584. )
  585. );
  586. } else {
  587. $actions .= Display::return_icon('clean_na.png', get_lang('ResourceLockedByGradebook'), '', ICON_SIZE_SMALL);
  588. }
  589. // Visible / invisible
  590. // Check if this exercise was added in a LP
  591. if ($exercise_obj->exercise_was_added_in_lp == true) {
  592. $actions .= Display::return_icon('invisible.png', get_lang('AddedToLPCannotBeAccessed'), '', ICON_SIZE_SMALL);
  593. } else {
  594. if ($row['active'] == 0 || $visibility == 0) {
  595. $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']);
  596. } else {
  597. // else if not active
  598. $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']);
  599. }
  600. }
  601. // Export qti ...
  602. $actions .= Display::url(Display::return_icon('export_qti2.png', 'IMS/QTI', '', ICON_SIZE_SMALL), 'exercise.php?choice=exportqti2&exerciseId='.$row['id'].'&'.api_get_cidreq());
  603. } else {
  604. // not session
  605. $actions = Display::return_icon('edit_na.png', get_lang('ExerciseEditionNotAvailableInSession'));
  606. $actions .='<a href="exercise_report.php?'.api_get_cidreq().'&exerciseId='.$row['id'].'">'.
  607. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  608. $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']));
  609. }
  610. // Delete
  611. if ($session_id == $row['session_id']) {
  612. if ($locked == false) {
  613. $actions .= Display::url(
  614. Display::return_icon(
  615. 'delete.png',
  616. get_lang('Delete'),
  617. '',
  618. ICON_SIZE_SMALL
  619. ),
  620. '',
  621. 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'])
  622. );
  623. } else {
  624. $actions .= Display::return_icon('delete_na.png', get_lang('ResourceLockedByGradebook'), '', ICON_SIZE_SMALL);
  625. }
  626. }
  627. // Number of questions
  628. $random_label = null;
  629. if ($row['random'] > 0 || $row['random'] == -1) {
  630. // if random == -1 means use random questions with all questions
  631. $random_number_of_question = $row['random'];
  632. if ($random_number_of_question == -1) {
  633. $random_number_of_question = $rowi;
  634. }
  635. if ($row['random_by_category'] > 0) {
  636. $nbQuestionsTotal = TestCategory::getNumberOfQuestionRandomByCategory(
  637. $my_exercise_id,
  638. $random_number_of_question
  639. );
  640. $number_of_questions = $nbQuestionsTotal." ";
  641. $number_of_questions .= ($nbQuestionsTotal > 1) ? get_lang("QuestionsLowerCase") : get_lang("QuestionLowerCase");
  642. $number_of_questions .= " - ";
  643. $number_of_questions .= min(TestCategory::getNumberMaxQuestionByCat($my_exercise_id), $random_number_of_question).' '.get_lang('QuestionByCategory');
  644. } else {
  645. $random_label = ' ('.get_lang('Random').') ';
  646. $number_of_questions = $random_number_of_question.' '.$random_label;
  647. //Bug if we set a random value bigger than the real number of questions
  648. if ($random_number_of_question > $rowi) {
  649. $number_of_questions = $rowi.' '.$random_label;
  650. }
  651. }
  652. } else {
  653. $number_of_questions = $rowi;
  654. }
  655. //Attempts
  656. //$attempts = ExerciseLib::get_count_exam_results($row['id']).' '.get_lang('Attempts');
  657. //$item .= Display::tag('td',$attempts);
  658. $item .= Display::tag('td', $number_of_questions);
  659. } else {
  660. // Student only.
  661. $visibility = api_get_item_visibility($courseInfo, TOOL_QUIZ, $my_exercise_id);
  662. if ($visibility == 0) {
  663. continue;
  664. }
  665. $url = '<a '.$alt_title.' href="overview.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id'].'">'.
  666. $cut_title.'</a>';
  667. // Link of the exercise.
  668. $item = Display::tag('td', $url.' '.$session_img);
  669. // Count number exercise questions.
  670. /*$sql = "SELECT count(*) FROM $TBL_EXERCISE_QUESTION
  671. WHERE c_id = $courseId AND exercice_id = ".$row['id'];
  672. $sqlresult = Database::query($sql);
  673. $rowi = Database::result($sqlresult, 0);
  674. if ($row['random'] > 0) {
  675. $row['random'].' '.api_strtolower(get_lang(($row['random'] > 1 ? 'Questions' : 'Question')));
  676. } else {
  677. //show results student
  678. $rowi.' '.api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question')));
  679. }*/
  680. // This query might be improved later on by ordering by the new "tms" field rather than by exe_id
  681. // Don't remove this marker: note-query-exe-results
  682. $sql = "SELECT * FROM $TBL_TRACK_EXERCISES
  683. WHERE
  684. exe_exo_id = ".$row['id']." AND
  685. exe_user_id = ".$userId." AND
  686. c_id = ".api_get_course_int_id()." AND
  687. status <> 'incomplete' AND
  688. orig_lp_id = 0 AND
  689. orig_lp_item_id = 0 AND
  690. session_id = '".api_get_session_id()."'
  691. ORDER BY exe_id DESC";
  692. $qryres = Database::query($sql);
  693. $num = Database :: num_rows($qryres);
  694. // Hide the results.
  695. $my_result_disabled = $row['results_disabled'];
  696. // Time limits are on
  697. if ($time_limits) {
  698. // Exam is ready to be taken
  699. if ($is_actived_time) {
  700. // Show results 697 $attempt_text = get_lang('LatestAttempt').' : ';
  701. if ($my_result_disabled == 0 || $my_result_disabled == 2) {
  702. //More than one attempt
  703. if ($num > 0) {
  704. $row_track = Database :: fetch_array($qryres);
  705. $attempt_text = get_lang('LatestAttempt').' : ';
  706. $attempt_text .= ExerciseLib::show_score($row_track['exe_result'], $row_track['exe_weighting']);
  707. } else {
  708. //No attempts
  709. $attempt_text = get_lang('NotAttempted');
  710. }
  711. } else {
  712. $attempt_text = get_lang('CantShowResults');
  713. }
  714. } else {
  715. //Quiz not ready due to time limits 700 $attempt_text = get_lang('NotAttempted');
  716. //@todo use the is_visible function
  717. if ($row['start_time'] != '0000-00-00 00:00:00' && $row['end_time'] != '0000-00-00 00:00:00') {
  718. $today = time();
  719. $start_time = api_strtotime($row['start_time'], 'UTC');
  720. $end_time = api_strtotime($row['end_time'], 'UTC');
  721. if ($today < $start_time) {
  722. $attempt_text = sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_convert_and_format_date($row['start_time']), api_convert_and_format_date($row['end_time']));
  723. } else {
  724. if ($today > $end_time) {
  725. $attempt_text = sprintf(get_lang('ExerciseWasActivatedFromXToY'), api_convert_and_format_date($row['start_time']), api_convert_and_format_date($row['end_time']));
  726. }
  727. }
  728. } else {
  729. //$attempt_text = get_lang('ExamNotAvailableAtThisTime');
  730. if ($row['start_time'] != '0000-00-00 00:00:00') {
  731. $attempt_text = sprintf(get_lang('ExerciseAvailableFromX'), api_convert_and_format_date($row['start_time']));
  732. }
  733. if ($row['end_time'] != '0000-00-00 00:00:00') {
  734. $attempt_text = sprintf(get_lang('ExerciseAvailableUntilX'), api_convert_and_format_date($row['end_time']));
  735. }
  736. }
  737. }
  738. } else {
  739. // Normal behaviour.
  740. // Show results.
  741. if ($my_result_disabled == 0 || $my_result_disabled == 2) {
  742. if ($num > 0) {
  743. $row_track = Database :: fetch_array($qryres);
  744. $attempt_text = get_lang('LatestAttempt').' : ';
  745. $attempt_text .= ExerciseLib::show_score($row_track['exe_result'], $row_track['exe_weighting']);
  746. } else {
  747. $attempt_text = get_lang('NotAttempted');
  748. }
  749. } else {
  750. $attempt_text = get_lang('CantShowResults');
  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('AreYouSureToDelete'), 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('<i class="fa fa-plus"></i> '.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. }