exercise.php 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Exercise list: This script shows the list of exercises for administrators and students.
  6. * @package chamilo.exercise
  7. * @author Olivier Brouckaert, original author
  8. * @author Denes Nagy, HotPotatoes integration
  9. * @author Wolfgang Schneider, code/html cleanup
  10. * @author Julio Montoya <gugli100@gmail.com>, lots of cleanup + several improvements
  11. * Modified by hubert.borderiou (question category)
  12. */
  13. // including the global library
  14. require_once __DIR__.'/../inc/global.inc.php';
  15. $current_course_tool = TOOL_QUIZ;
  16. // Setting the tabs
  17. $this_section = SECTION_COURSES;
  18. $htmlHeadXtra[] = api_get_asset('qtip2/jquery.qtip.min.js');
  19. $htmlHeadXtra[] = api_get_css_asset('qtip2/jquery.qtip.min.css');
  20. // Access control
  21. api_protect_course_script(true);
  22. require_once 'hotpotatoes.lib.php';
  23. /* Constants and variables */
  24. $is_allowedToEdit = api_is_allowed_to_edit(null, true);
  25. $is_tutor = api_is_allowed_to_edit(true);
  26. $is_tutor_course = api_is_course_tutor();
  27. $courseInfo = api_get_course_info();
  28. $courseId = $courseInfo['real_id'];
  29. $userInfo = api_get_user_info();
  30. $userId = $userInfo['id'];
  31. $sessionId = api_get_session_id();
  32. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  33. $userId,
  34. $courseInfo
  35. );
  36. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  37. $TBL_ITEM_PROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  38. $TBL_EXERCISE_QUESTION = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  39. $TBL_EXERCISES = Database :: get_course_table(TABLE_QUIZ_TEST);
  40. $TBL_TRACK_EXERCISES = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  41. // document path
  42. $documentPath = api_get_path(SYS_COURSE_PATH).$courseInfo['path']."/document";
  43. // picture path
  44. $picturePath = $documentPath.'/images';
  45. // audio path
  46. $audioPath = $documentPath.'/audio';
  47. // hot potatoes
  48. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  49. $exercisePath = api_get_self();
  50. $exfile = explode('/', $exercisePath);
  51. $exfile = strtolower($exfile[sizeof($exfile) - 1]);
  52. $exercisePath = substr($exercisePath, 0, strpos($exercisePath, $exfile));
  53. $exercisePath = $exercisePath."exercise.php";
  54. // Clear the exercise session
  55. Session::erase('objExercise');
  56. Session::erase('objQuestion');
  57. Session::erase('objAnswer');
  58. Session::erase('questionList');
  59. Session::erase('exerciseResult');
  60. Session::erase('firstTime');
  61. //General POST/GET/SESSION/COOKIES parameters recovery
  62. $origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : null;
  63. $choice = isset($_REQUEST['choice']) ? Security::remove_XSS($_REQUEST['choice']) : null;
  64. $hpchoice = isset($_REQUEST['hpchoice']) ? Security::remove_XSS($_REQUEST['hpchoice']) : null;
  65. $exerciseId = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : null;
  66. $file = isset($_REQUEST['file']) ? Database::escape_string($_REQUEST['file']) : null;
  67. $learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : null;
  68. $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : null;
  69. $page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : null;
  70. if ($page < 0) {
  71. $page = 1;
  72. }
  73. if (!empty($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  74. $_SESSION['gradebook'] = Security::remove_XSS($_GET['gradebook']);
  75. $gradebook = $_SESSION['gradebook'];
  76. } elseif (empty($_GET['gradebook'])) {
  77. unset($_SESSION['gradebook']);
  78. $gradebook = '';
  79. }
  80. if (!empty($gradebook) && $gradebook == 'view') {
  81. $interbreadcrumb[] = array(
  82. 'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
  83. 'name' => get_lang('ToolGradebook')
  84. );
  85. }
  86. $nameTools = get_lang('Exercises');
  87. $errorXmlExport = null;
  88. if ($is_allowedToEdit && !empty($choice) && $choice == 'exportqti2') {
  89. require_once api_get_path(SYS_CODE_PATH).'exercise/export/qti2/qti2_export.php';
  90. $export = export_exercise_to_qti($exerciseId, true);
  91. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  92. $temp_dir_short = api_get_unique_id();
  93. $temp_zip_dir = $archive_path.$temp_dir_short;
  94. if (!is_dir($temp_zip_dir)) {
  95. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  96. }
  97. $temp_zip_file = $temp_zip_dir."/".api_get_unique_id().".zip";
  98. $temp_xml_file = $temp_zip_dir."/qti2export_".$exerciseId.'.xml';
  99. file_put_contents($temp_xml_file, $export);
  100. $xmlReader = new XMLReader();
  101. $xmlReader->open($temp_xml_file);
  102. $xmlReader->setParserProperty(XMLReader::VALIDATE, true);
  103. $isValid = $xmlReader->isValid();
  104. if ($isValid) {
  105. $zip_folder = new PclZip($temp_zip_file);
  106. $zip_folder->add($temp_xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
  107. $name = 'qti2_export_'.$exerciseId.'.zip';
  108. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  109. unlink($temp_zip_file);
  110. unlink($temp_xml_file);
  111. rmdir($temp_zip_dir);
  112. exit; //otherwise following clicks may become buggy
  113. } else {
  114. $errorXmlExport = Display :: return_message(get_lang('ErrorWritingXMLFile'), 'error');
  115. }
  116. }
  117. if ($origin != 'learnpath') {
  118. //so we are not in learnpath tool
  119. Display :: display_header($nameTools, get_lang('Exercise'));
  120. if (isset($_GET['message'])) {
  121. if (in_array($_GET['message'], array('ExerciseEdited'))) {
  122. 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
  348. FROM $TBL_EXERCISES
  349. WHERE c_id = $courseId AND active<>'-1' $condition_session ";
  350. $sql = "SELECT * FROM $TBL_EXERCISES
  351. WHERE c_id = $courseId AND active<>'-1' $condition_session
  352. ORDER BY title
  353. LIMIT ".$from.",".$limit;
  354. } else {
  355. // Only for students
  356. $total_sql = "SELECT count(iid) as count
  357. FROM $TBL_EXERCISES
  358. WHERE c_id = $courseId AND active = '1' $condition_session ";
  359. $sql = "SELECT * FROM $TBL_EXERCISES
  360. WHERE c_id = $courseId AND
  361. active='1' $condition_session
  362. ORDER BY title LIMIT ".$from.",".$limit;
  363. }
  364. $result = Database::query($sql);
  365. $result_total = Database::query($total_sql);
  366. $total_exercises = 0;
  367. if (Database :: num_rows($result_total)) {
  368. $result_total = Database::fetch_array($result_total);
  369. $total_exercises = $result_total['count'];
  370. }
  371. //get HotPotatoes files (active and inactive)
  372. if ($is_allowedToEdit) {
  373. $sql = "SELECT * FROM $TBL_DOCUMENT
  374. WHERE
  375. c_id = $courseId AND
  376. path LIKE '".Database :: escape_string($uploadPath.'/%/%')."'";
  377. $res = Database::query($sql);
  378. $hp_count = Database :: num_rows($res);
  379. } else {
  380. $sql = "SELECT * FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  381. WHERE
  382. d.id = ip.ref AND
  383. ip.tool = '".TOOL_DOCUMENT."' AND
  384. d.path LIKE '".Database :: escape_string($uploadPath.'/%/%')."' AND
  385. ip.visibility ='1' AND
  386. d.c_id = ".$courseId." AND
  387. ip.c_id = ".$courseId;
  388. $res = Database::query($sql);
  389. $hp_count = Database :: num_rows($res);
  390. }
  391. $total = $total_exercises + $hp_count;
  392. $token = Security::get_token();
  393. if ($is_allowedToEdit && $origin != 'learnpath') {
  394. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/exercise_admin.php?'.api_get_cidreq().'">'.
  395. Display :: return_icon('new_exercice.png', get_lang('NewEx'), '', ICON_SIZE_MEDIUM).'</a>';
  396. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/question_create.php?'.api_get_cidreq().'">'.
  397. Display :: return_icon('new_question.png', get_lang('AddQ'), '', ICON_SIZE_MEDIUM).'</a>';
  398. // Question category
  399. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/tests_category.php?'.api_get_cidreq().'">';
  400. echo Display::return_icon('green_open.png', get_lang('QuestionCategory'), '', ICON_SIZE_MEDIUM);
  401. echo '</a>';
  402. echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/question_pool.php?'.api_get_cidreq().'">';
  403. echo Display::return_icon('database.png', get_lang('QuestionPool'), '', ICON_SIZE_MEDIUM);
  404. echo '</a>';
  405. //echo Display::url(Display::return_icon('looknfeel.png', get_lang('Media')), 'media.php?' . api_get_cidreq());
  406. // end question category
  407. 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>';
  408. // link to import qti2 ...
  409. 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>';
  410. 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>';
  411. 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>';
  412. echo Display::url(
  413. Display::return_icon(
  414. 'clean_all.png',
  415. get_lang('CleanAllStudentsResultsForAllTests'),
  416. '',
  417. ICON_SIZE_MEDIUM
  418. ),
  419. '',
  420. array(
  421. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToEmptyAllTestResults'), ENT_QUOTES, $charset))."')) return false;",
  422. 'href' => api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq().'&choice=clean_all_test&sec_token='.$token
  423. )
  424. );
  425. }
  426. if ($is_allowedToEdit) {
  427. echo '</div>'; // closing the actions div
  428. }
  429. if ($total > $limit) {
  430. echo '<div style="float:right;height:20px;">';
  431. //show pages navigation link for previous page
  432. if ($page) {
  433. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&page=".($page - 1)."\">".Display :: return_icon('action_prev.png', get_lang('PreviousPage'))."</a>";
  434. } elseif ($total_exercises + $hp_count > $limit) {
  435. echo Display :: return_icon('action_prev_na.png', get_lang('PreviousPage'));
  436. }
  437. //show pages navigation link for previous page
  438. if ($total_exercises > $from + $limit || $hp_count > $from + $limit) {
  439. echo ' '."<a href=\"".api_get_self()."?".api_get_cidreq()."&page=".($page + 1)."\">".Display::return_icon('action_next.png', get_lang('NextPage'))."</a>";
  440. } elseif ($page) {
  441. echo ' '.Display :: return_icon('action_next_na.png', get_lang('NextPage'));
  442. }
  443. echo '</div>';
  444. }
  445. $i = 1;
  446. $online_icon = Display::return_icon('online.png', get_lang('Visible'), array('width' => '12px'));
  447. $offline_icon = Display::return_icon('offline.png', get_lang('Invisible'), array('width' => '12px'));
  448. $exerciseList = array();
  449. $list_ordered = null;
  450. while ($row = Database :: fetch_array($result, 'ASSOC')) {
  451. $exerciseList[$row['iid']] = $row;
  452. }
  453. if (!empty($exerciseList) &&
  454. api_get_setting('exercise_invisible_in_session') === 'true'
  455. ) {
  456. if (!empty($sessionId)) {
  457. $changeDefaultVisibility = true;
  458. if (api_get_setting('configure_exercise_visibility_in_course') === 'true') {
  459. if (api_get_course_setting('exercise_invisible_in_session') == 1) {
  460. $changeDefaultVisibility = true;
  461. } else {
  462. $changeDefaultVisibility = false;
  463. }
  464. }
  465. if ($changeDefaultVisibility) {
  466. // Check exercise
  467. foreach ($exerciseList as $exercise) {
  468. if ($exercise['session_id'] == 0) {
  469. $visibilityInfo = api_get_item_property_info(
  470. $courseInfo,
  471. TOOL_QUIZ,
  472. $exercise['iid'],
  473. $sessionId
  474. );
  475. if (empty($visibilityInfo)) {
  476. // Create a record for this
  477. api_item_property_update(
  478. $courseInfo,
  479. TOOL_QUIZ,
  480. $exercise['iid'],
  481. 'invisible',
  482. api_get_user_id(),
  483. 0,
  484. null,
  485. '',
  486. '',
  487. $sessionId
  488. );
  489. }
  490. }
  491. }
  492. }
  493. }
  494. }
  495. if (isset($list_ordered) && !empty($list_ordered)) {
  496. $new_question_list = array();
  497. foreach ($list_ordered as $exercise_id) {
  498. if (isset($exerciseList[$exercise_id])) {
  499. $new_question_list[] = $exerciseList[$exercise_id];
  500. }
  501. }
  502. $exerciseList = $new_question_list;
  503. }
  504. $tableRows = [];
  505. /* Listing exercises */
  506. if (!empty($exerciseList)) {
  507. if ($origin != 'learnpath') {
  508. //avoid sending empty parameters
  509. $myorigin = (empty($origin) ? '' : '&origin='.$origin);
  510. $mylpid = (empty($learnpath_id) ? '' : '&learnpath_id='.$learnpath_id);
  511. $mylpitemid = (empty($learnpath_item_id) ? '' : '&learnpath_item_id='.$learnpath_item_id);
  512. $i = 1;
  513. foreach ($exerciseList as $row) {
  514. $my_exercise_id = $row['id'];
  515. $exercise = new Exercise();
  516. $exercise->read($my_exercise_id, false);
  517. if (empty($exercise->id)) {
  518. continue;
  519. }
  520. $locked = $exercise->is_gradebook_locked;
  521. $i++;
  522. //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->getCutTitle();
  570. $alt_title = '';
  571. if ($cut_title != $row['title']) {
  572. $alt_title = ' title = "'.$row['title'].'" ';
  573. }
  574. // Teacher only
  575. if ($is_allowedToEdit) {
  576. $lp_blocked = null;
  577. if ($exercise->exercise_was_added_in_lp == true) {
  578. $lp_blocked = Display::div(
  579. get_lang('AddedToLPCannotBeAccessed'),
  580. array('class' => 'lp_content_type_label')
  581. );
  582. }
  583. $visibility = api_get_item_visibility(
  584. $courseInfo,
  585. TOOL_QUIZ,
  586. $my_exercise_id,
  587. 0
  588. );
  589. if (!empty($sessionId)) {
  590. $setting = api_get_configuration_value('show_hidden_exercise_added_to_lp');
  591. if ($setting) {
  592. if ($exercise->exercise_was_added_in_lp == false) {
  593. if ($visibility == 0) {
  594. continue;
  595. }
  596. }
  597. } else {
  598. if ($visibility == 0) {
  599. continue;
  600. }
  601. }
  602. $visibility = api_get_item_visibility(
  603. $courseInfo,
  604. TOOL_QUIZ,
  605. $my_exercise_id,
  606. $sessionId
  607. );
  608. }
  609. if ($row['active'] == 0 || $visibility == 0) {
  610. $title = Display::tag('font', $cut_title, array('style' => 'color:grey'));
  611. } else {
  612. $title = $cut_title;
  613. }
  614. $count_exercise_not_validated = 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.png', $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.png', 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->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->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
  916. INNER JOIN $TBL_ITEM_PROPERTY ip
  917. ON (d.id = ip.ref AND d.c_id = ip.c_id)
  918. WHERE
  919. d.c_id = $courseId AND
  920. ip.c_id = $courseId AND
  921. ip.tool = '".TOOL_DOCUMENT."' AND
  922. (d.path LIKE '%htm%') AND
  923. d.path LIKE '".Database :: escape_string($uploadPath.'/%/%')."'
  924. LIMIT ".$from.",".$limit; // only .htm or .html files listed
  925. } else {
  926. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  927. FROM $TBL_DOCUMENT d
  928. INNER JOIN $TBL_ITEM_PROPERTY ip
  929. ON (d.id = ip.ref AND d.c_id = ip.c_id)
  930. WHERE
  931. d.c_id = $courseId AND
  932. ip.c_id = $courseId AND
  933. ip.tool = '".TOOL_DOCUMENT."' AND
  934. (d.path LIKE '%htm%') AND
  935. d.path LIKE '".Database :: escape_string($uploadPath.'/%/%')."' AND
  936. ip.visibility='1'
  937. LIMIT ".$from.",".$limit;
  938. }
  939. $result = Database::query($sql);
  940. while ($row = Database :: fetch_array($result, 'ASSOC')) {
  941. $attribute['path'][] = $row['path'];
  942. $attribute['visibility'][] = $row['visibility'];
  943. $attribute['comment'][] = $row['comment'];
  944. }
  945. $nbrActiveTests = 0;
  946. if (isset($attribute['path']) && is_array($attribute['path'])) {
  947. $hotpotatoes_exist = true;
  948. while (list($key, $path) = each($attribute['path'])) {
  949. $item = '';
  950. list ($a, $vis) = each($attribute['visibility']);
  951. $active = !empty($vis);
  952. $title = GetQuizName($path, $documentPath);
  953. if ($title == '') {
  954. $title = basename($path);
  955. }
  956. // prof only
  957. if ($is_allowedToEdit) {
  958. $item = Display::tag(
  959. 'td',
  960. implode(PHP_EOL, [
  961. Display::return_icon('hotpotatoes_s.png', "HotPotatoes"),
  962. Display::url(
  963. $title,
  964. 'showinframes.php?' . api_get_cidreq() . '&' . http_build_query([
  965. 'file' => $path,
  966. 'uid' => $userId
  967. ]),
  968. ['class' => !$active ? 'text-muted' : null]
  969. )
  970. ])
  971. );
  972. $item .= Display::tag('td', '-');
  973. $actions = Display::url(
  974. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL),
  975. 'adminhp.php?'.api_get_cidreq().'&hotpotatoesName='.$path
  976. );
  977. $actions .='<a href="hotpotatoes_exercise_report.php?'.api_get_cidreq().'&path='.$path.'">'.
  978. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  979. // if active
  980. if ($active) {
  981. $nbrActiveTests = $nbrActiveTests + 1;
  982. $actions .= ' <a href="'.$exercisePath.'?'.api_get_cidreq().'&hpchoice=disable&page='.$page.'&file='.$path.'">'.
  983. Display::return_icon('visible.png', get_lang('Deactivate'), '', ICON_SIZE_SMALL).'</a>';
  984. } else { // else if not active
  985. $actions .=' <a href="'.$exercisePath.'?'.api_get_cidreq().'&hpchoice=enable&page='.$page.'&file='.$path.'">'.
  986. Display::return_icon('invisible.png', get_lang('Activate'), '', ICON_SIZE_SMALL).'</a>';
  987. }
  988. $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;">'.
  989. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
  990. $item .= Display::tag('td', $actions);
  991. $tableRows[] = Display::tag('tr', $item);
  992. } else {
  993. // Student only
  994. if ($active) {
  995. $attempt = ExerciseLib::getLatestHotPotatoResult(
  996. $path,
  997. $userId,
  998. api_get_course_int_id(),
  999. api_get_session_id()
  1000. );
  1001. $nbrActiveTests = $nbrActiveTests + 1;
  1002. $item .= Display::tag(
  1003. 'td',
  1004. Display::url(
  1005. $title,
  1006. 'showinframes.php?' . api_get_cidreq() . '&' . http_build_query([
  1007. 'file' => $path,
  1008. 'cid' => api_get_course_id(),
  1009. 'uid' => $userId
  1010. ])
  1011. )
  1012. );
  1013. if (!empty($attempt)) {
  1014. $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>';
  1015. $attemptText = get_lang('LatestAttempt').' : ';
  1016. $attemptText .= ExerciseLib::show_score($attempt['exe_result'], $attempt['exe_weighting']).' ';
  1017. $attemptText .= $actions;
  1018. } else {
  1019. // No attempts.
  1020. $attemptText = get_lang('NotAttempted').' ';
  1021. }
  1022. $item .= Display::tag('td', $attemptText);
  1023. if ($isDrhOfCourse) {
  1024. $actions ='<a href="hotpotatoes_exercise_report.php?'.api_get_cidreq().'&path='.$path.'">'.
  1025. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  1026. $item .= Display::tag('td', $actions, array('class' => 'td_actions'));
  1027. }
  1028. $tableRows[] = Display::tag('tr', $item);
  1029. }
  1030. }
  1031. }
  1032. }
  1033. if (empty($exerciseList) && $hotpotatoes_exist == false) {
  1034. if ($is_allowedToEdit && $origin != 'learnpath') {
  1035. echo '<div id="no-data-view">';
  1036. echo '<h3>'.get_lang('Quiz').'</h3>';
  1037. echo Display::return_icon('quiz.png', '', array(), 64);
  1038. echo '<div class="controls">';
  1039. echo Display::url('<em class="fa fa-plus"></em> '.get_lang('NewEx'), 'exercise_admin.php?'.api_get_cidreq(), array('class' => 'btn btn-primary'));
  1040. echo '</div>';
  1041. echo '</div>';
  1042. }
  1043. } else {
  1044. if ($is_allowedToEdit) {
  1045. $headers = [
  1046. get_lang('ExerciseName'),
  1047. get_lang('QuantityQuestions'),
  1048. get_lang('Actions')
  1049. ];
  1050. } else {
  1051. $headers = [
  1052. get_lang('ExerciseName'),
  1053. get_lang('Status')
  1054. ];
  1055. if ($isDrhOfCourse) {
  1056. $headers[] = get_lang('Actions');
  1057. }
  1058. }
  1059. $headerList = '';
  1060. foreach ($headers as $header) {
  1061. $headerList .= Display::tag('th', $header);
  1062. }
  1063. echo '<div class="table-responsive">';
  1064. echo '<table class="table table-striped table-hover">';
  1065. echo Display::tag(
  1066. 'thead',
  1067. Display::tag('tr', $headerList)
  1068. );
  1069. echo '<tbody>';
  1070. foreach ($tableRows as $row) {
  1071. echo $row;
  1072. }
  1073. echo '</tbody>';
  1074. echo '</table>';
  1075. echo '</div>';
  1076. }
  1077. if ($origin != 'learnpath') { //so we are not in learnpath tool
  1078. Display :: display_footer();
  1079. }