exercise.php 50 KB

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