exercise.php 52 KB

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