exercise.php 52 KB

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