exercise.php 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Exercise list: This script shows the list of exercises for administrators and students.
  6. * @package chamilo.exercise
  7. * @author Olivier Brouckaert, original author
  8. * @author Denes Nagy, HotPotatoes integration
  9. * @author Wolfgang Schneider, code/html cleanup
  10. * @author Julio Montoya <gugli100@gmail.com>, lots of cleanup + several improvements
  11. * Modified by hubert.borderiou (question category)
  12. */
  13. // including the global library
  14. require_once __DIR__.'/../inc/global.inc.php';
  15. $current_course_tool = TOOL_QUIZ;
  16. // Setting the tabs
  17. $this_section = SECTION_COURSES;
  18. $htmlHeadXtra[] = api_get_asset('qtip2/jquery.qtip.min.js');
  19. $htmlHeadXtra[] = api_get_css_asset('qtip2/jquery.qtip.min.css');
  20. // Access control
  21. api_protect_course_script(true);
  22. require_once 'hotpotatoes.lib.php';
  23. /* Constants and variables */
  24. $is_allowedToEdit = api_is_allowed_to_edit(null, true);
  25. $is_tutor = api_is_allowed_to_edit(true);
  26. $is_tutor_course = api_is_course_tutor();
  27. $courseInfo = api_get_course_info();
  28. $courseId = $courseInfo['real_id'];
  29. $userInfo = api_get_user_info();
  30. $userId = $userInfo['id'];
  31. $sessionId = api_get_session_id();
  32. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  33. $userId,
  34. $courseInfo
  35. );
  36. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  37. $TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  38. $TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  39. $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
  40. $TBL_TRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  41. // document path
  42. $documentPath = api_get_path(SYS_COURSE_PATH).$courseInfo['path']."/document";
  43. // picture path
  44. $picturePath = $documentPath.'/images';
  45. // audio path
  46. $audioPath = $documentPath.'/audio';
  47. // hot potatoes
  48. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  49. $exercisePath = api_get_self();
  50. $exfile = explode('/', $exercisePath);
  51. $exfile = strtolower($exfile[sizeof($exfile) - 1]);
  52. $exercisePath = substr($exercisePath, 0, strpos($exercisePath, $exfile));
  53. $exercisePath = $exercisePath."exercise.php";
  54. // Clear the exercise session
  55. Session::erase('objExercise');
  56. Session::erase('objQuestion');
  57. Session::erase('objAnswer');
  58. Session::erase('questionList');
  59. Session::erase('exerciseResult');
  60. Session::erase('firstTime');
  61. //General POST/GET/SESSION/COOKIES parameters recovery
  62. $origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : null;
  63. $choice = isset($_REQUEST['choice']) ? Security::remove_XSS($_REQUEST['choice']) : null;
  64. $hpchoice = isset($_REQUEST['hpchoice']) ? Security::remove_XSS($_REQUEST['hpchoice']) : null;
  65. $exerciseId = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : null;
  66. $file = isset($_REQUEST['file']) ? Database::escape_string($_REQUEST['file']) : null;
  67. $learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : null;
  68. $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : null;
  69. $page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : null;
  70. if ($page < 0) {
  71. $page = 1;
  72. }
  73. if (!empty($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  74. $_SESSION['gradebook'] = Security::remove_XSS($_GET['gradebook']);
  75. $gradebook = $_SESSION['gradebook'];
  76. } elseif (empty($_GET['gradebook'])) {
  77. unset($_SESSION['gradebook']);
  78. $gradebook = '';
  79. }
  80. if (!empty($gradebook) && $gradebook == 'view') {
  81. $interbreadcrumb[] = array(
  82. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  83. 'name' => get_lang('ToolGradebook')
  84. );
  85. }
  86. $nameTools = get_lang('Exercises');
  87. $errorXmlExport = null;
  88. if ($is_allowedToEdit && !empty($choice) && $choice == 'exportqti2') {
  89. require_once api_get_path(SYS_CODE_PATH).'exercise/export/qti2/qti2_export.php';
  90. $export = export_exercise_to_qti($exerciseId, true);
  91. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  92. $temp_dir_short = api_get_unique_id();
  93. $temp_zip_dir = $archive_path.$temp_dir_short;
  94. if (!is_dir($temp_zip_dir)) {
  95. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  96. }
  97. $temp_zip_file = $temp_zip_dir."/".api_get_unique_id().".zip";
  98. $temp_xml_file = $temp_zip_dir."/qti2export_".$exerciseId.'.xml';
  99. file_put_contents($temp_xml_file, $export);
  100. $xmlReader = new XMLReader();
  101. $xmlReader->open($temp_xml_file);
  102. $xmlReader->setParserProperty(XMLReader::VALIDATE, true);
  103. $isValid = $xmlReader->isValid();
  104. if ($isValid) {
  105. $zip_folder = new PclZip($temp_zip_file);
  106. $zip_folder->add($temp_xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
  107. $name = 'qti2_export_'.$exerciseId.'.zip';
  108. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  109. unlink($temp_zip_file);
  110. unlink($temp_xml_file);
  111. rmdir($temp_zip_dir);
  112. exit; //otherwise following clicks may become buggy
  113. } else {
  114. $errorXmlExport = Display :: return_message(get_lang('ErrorWritingXMLFile'), 'error');
  115. }
  116. }
  117. if ($origin != 'learnpath') {
  118. //so we are not in learnpath tool
  119. Display :: display_header($nameTools, get_lang('Exercise'));
  120. if (isset($_GET['message'])) {
  121. if (in_array($_GET['message'], array('ExerciseEdited'))) {
  122. echo Display::return_message(get_lang($_GET['message']), 'confirmation');
  123. }
  124. }
  125. } else {
  126. Display :: display_reduced_header();
  127. }
  128. Event::event_access_tool(TOOL_QUIZ);
  129. // Tool introduction
  130. Display :: display_introduction_section(TOOL_QUIZ);
  131. if (!empty($errorXmlExport)) {
  132. echo $errorXmlExport;
  133. }
  134. HotPotGCt($documentPath, 1, $userId);
  135. // Only for administrator
  136. if ($is_allowedToEdit) {
  137. if (!empty($choice)) {
  138. // All test choice, clean all test's results
  139. if ($choice === 'clean_all_test') {
  140. $check = Security::check_token('get');
  141. if ($check) {
  142. // list of exercises in a course/session
  143. // we got variable $courseId $courseInfo session api_get_session_id()
  144. $exerciseList = ExerciseLib::get_all_exercises_for_course_id(
  145. $courseInfo,
  146. $sessionId,
  147. $courseId,
  148. false
  149. );
  150. $quantity_results_deleted = 0;
  151. foreach ($exerciseList as $exeItem) {
  152. // delete result for test, if not in a gradebook
  153. $exercise_action_locked = api_resource_is_locked_by_gradebook($exeItem['id'], LINK_EXERCISE);
  154. if ($exercise_action_locked == false) {
  155. $objExerciseTmp = new Exercise();
  156. if ($objExerciseTmp->read($exeItem['id'])) {
  157. $quantity_results_deleted += $objExerciseTmp->clean_results(true);
  158. }
  159. }
  160. }
  161. 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. echo Display::return_message(get_lang('ExerciseDeleted'), 'confirmation');
  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. echo Display::return_message(get_lang('VisibilityChanged'), 'confirmation');
  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. echo Display::return_message(get_lang('VisibilityChanged'), 'confirmation');
  237. break;
  238. case 'disable_results':
  239. //disable the results for the learners
  240. $objExerciseTmp->disable_results();
  241. $objExerciseTmp->save();
  242. echo Display::return_message(get_lang('ResultsDisabled'), 'confirmation');
  243. break;
  244. case 'enable_results':
  245. //disable the results for the learners
  246. $objExerciseTmp->enable_results();
  247. $objExerciseTmp->save();
  248. echo Display::return_message(get_lang('ResultsEnabled'), 'confirmation');
  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. echo Display::return_message($title.': '.sprintf(get_lang('XResultsCleaned'), $quantity_results_deleted), 'confirmation');
  256. }
  257. break;
  258. case 'copy_exercise': //copy an exercise
  259. $objExerciseTmp->copy_exercise();
  260. echo Display::return_message(get_lang('ExerciseCopied'), 'confirmation');
  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. $changeDefaultVisibility = false;
  460. if (api_get_course_setting('exercise_invisible_in_session') == 1) {
  461. $changeDefaultVisibility = true;
  462. }
  463. }
  464. if ($changeDefaultVisibility) {
  465. // Check exercise
  466. foreach ($exerciseList as $exercise) {
  467. if ($exercise['session_id'] == 0) {
  468. $visibilityInfo = api_get_item_property_info(
  469. $courseId,
  470. TOOL_QUIZ,
  471. $exercise['iid'],
  472. $sessionId
  473. );
  474. if (empty($visibilityInfo)) {
  475. // Create a record for this
  476. api_item_property_update(
  477. $courseInfo,
  478. TOOL_QUIZ,
  479. $exercise['iid'],
  480. 'invisible',
  481. api_get_user_id(),
  482. 0,
  483. null,
  484. '',
  485. '',
  486. $sessionId
  487. );
  488. }
  489. }
  490. }
  491. }
  492. }
  493. }
  494. if (isset($list_ordered) && !empty($list_ordered)) {
  495. $new_question_list = array();
  496. foreach ($list_ordered as $exercise_id) {
  497. if (isset($exerciseList[$exercise_id])) {
  498. $new_question_list[] = $exerciseList[$exercise_id];
  499. }
  500. }
  501. $exerciseList = $new_question_list;
  502. }
  503. $tableRows = [];
  504. /* Listing exercises */
  505. if (!empty($exerciseList)) {
  506. if ($origin != 'learnpath') {
  507. //avoid sending empty parameters
  508. $myorigin = (empty($origin) ? '' : '&origin='.$origin);
  509. $mylpid = (empty($learnpath_id) ? '' : '&learnpath_id='.$learnpath_id);
  510. $mylpitemid = (empty($learnpath_item_id) ? '' : '&learnpath_item_id='.$learnpath_item_id);
  511. $i = 1;
  512. foreach ($exerciseList as $row) {
  513. $my_exercise_id = $row['id'];
  514. $exercise = new Exercise();
  515. $exercise->read($my_exercise_id, false);
  516. if (empty($exercise->id)) {
  517. continue;
  518. }
  519. $locked = $exercise->is_gradebook_locked;
  520. $i++;
  521. // Validation when belongs to a session
  522. $session_img = api_get_session_image($row['session_id'], $userInfo['status']);
  523. $time_limits = false;
  524. if (!empty($row['start_time']) || !empty($row['end_time'])) {
  525. $time_limits = true;
  526. }
  527. $is_actived_time = false;
  528. if ($time_limits) {
  529. // check if start time
  530. $start_time = false;
  531. if (!empty($row['start_time'])) {
  532. $start_time = api_strtotime($row['start_time'], 'UTC');
  533. }
  534. $end_time = false;
  535. if (!empty($row['end_time'])) {
  536. $end_time = api_strtotime($row['end_time'], 'UTC');
  537. }
  538. $now = time();
  539. //If both "clocks" are enable
  540. if ($start_time && $end_time) {
  541. if ($now > $start_time && $end_time > $now) {
  542. $is_actived_time = true;
  543. }
  544. } else {
  545. //we check the start and end
  546. if ($start_time) {
  547. if ($now > $start_time) {
  548. $is_actived_time = true;
  549. }
  550. }
  551. if ($end_time) {
  552. if ($end_time > $now) {
  553. $is_actived_time = true;
  554. }
  555. }
  556. }
  557. }
  558. // Blocking empty start times see BT#2800
  559. global $_custom;
  560. if (isset($_custom['exercises_hidden_when_no_start_date']) &&
  561. $_custom['exercises_hidden_when_no_start_date']
  562. ) {
  563. if (empty($row['start_time'])) {
  564. $time_limits = true;
  565. $is_actived_time = false;
  566. }
  567. }
  568. $cut_title = $exercise->getCutTitle();
  569. $alt_title = '';
  570. if ($cut_title != $row['title']) {
  571. $alt_title = ' title = "'.$row['title'].'" ';
  572. }
  573. // Teacher only
  574. if ($is_allowedToEdit) {
  575. $lp_blocked = null;
  576. if ($exercise->exercise_was_added_in_lp == true) {
  577. $lp_blocked = Display::div(
  578. get_lang('AddedToLPCannotBeAccessed'),
  579. array('class' => 'lp_content_type_label')
  580. );
  581. }
  582. $visibility = api_get_item_visibility(
  583. $courseInfo,
  584. TOOL_QUIZ,
  585. $my_exercise_id,
  586. 0
  587. );
  588. if (!empty($sessionId)) {
  589. $setting = api_get_configuration_value('show_hidden_exercise_added_to_lp');
  590. if ($setting) {
  591. if ($exercise->exercise_was_added_in_lp == false) {
  592. if ($visibility == 0) {
  593. continue;
  594. }
  595. }
  596. } else {
  597. if ($visibility == 0) {
  598. continue;
  599. }
  600. }
  601. $visibility = api_get_item_visibility(
  602. $courseInfo,
  603. TOOL_QUIZ,
  604. $my_exercise_id,
  605. $sessionId
  606. );
  607. }
  608. if ($row['active'] == 0 || $visibility == 0) {
  609. $title = Display::tag('font', $cut_title, array('style' => 'color:grey'));
  610. } else {
  611. $title = $cut_title;
  612. }
  613. $count_exercise_not_validated = (int) Event::count_exercise_result_not_validated(
  614. $my_exercise_id,
  615. $courseId,
  616. $session_id
  617. );
  618. $move = Display::return_icon(
  619. 'all_directions.png',
  620. get_lang('Move'),
  621. array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;')
  622. );
  623. $move = null;
  624. $class_tip = '';
  625. if (!empty($count_exercise_not_validated)) {
  626. $results_text = $count_exercise_not_validated == 1 ? get_lang('ResultNotRevised') : get_lang('ResultsNotRevised');
  627. $title .= '<span class="exercise_tooltip" style="display: none;">'.$count_exercise_not_validated.' '.$results_text.' </span>';
  628. $class_tip = 'link_tooltip';
  629. }
  630. $url = $move.'<a '.$alt_title.' class="'.$class_tip.'" id="tooltip_'.$row['id'].'" href="overview.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id'].'">
  631. '.Display::return_icon('quiz.png', $row['title']).'
  632. '.$title.' </a>';
  633. $item = Display::tag('td', $url.' '.$session_img.$lp_blocked);
  634. // Count number exercise - teacher
  635. $sql = "SELECT count(*) count FROM $TBL_EXERCISE_QUESTION
  636. WHERE c_id = $courseId AND exercice_id = $my_exercise_id";
  637. $sqlresult = Database::query($sql);
  638. $rowi = Database :: result($sqlresult, 0, 0);
  639. if ($session_id == $row['session_id']) {
  640. // Questions list
  641. $actions = Display::url(
  642. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL),
  643. 'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']
  644. );
  645. // Test settings
  646. $actions .= Display::url(
  647. Display::return_icon('settings.png', get_lang('Configure'), '', ICON_SIZE_SMALL),
  648. 'exercise_admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']
  649. );
  650. // Exercise results
  651. $actions .= '<a href="exercise_report.php?'.api_get_cidreq().'&exerciseId='.$row['id'].'">'.
  652. Display::return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  653. // Export
  654. $actions .= Display::url(
  655. Display::return_icon('cd.png', get_lang('CopyExercise')),
  656. '',
  657. array(
  658. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToCopy'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;",
  659. 'href' => 'exercise.php?'.api_get_cidreq().'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id']
  660. )
  661. );
  662. // Clean exercise
  663. if ($locked == false) {
  664. $actions .= Display::url(
  665. Display::return_icon('clean.png', get_lang('CleanStudentResults'), '', ICON_SIZE_SMALL),
  666. '',
  667. array(
  668. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDeleteResults'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;",
  669. 'href' => 'exercise.php?'.api_get_cidreq().'&choice=clean_results&sec_token='.$token.'&exerciseId='.$row['id']
  670. )
  671. );
  672. } else {
  673. $actions .= Display::return_icon('clean_na.png', get_lang('ResourceLockedByGradebook'), '', ICON_SIZE_SMALL);
  674. }
  675. // Visible / invisible
  676. // Check if this exercise was added in a LP
  677. if ($exercise->exercise_was_added_in_lp == true) {
  678. $actions .= Display::return_icon('invisible.png', get_lang('AddedToLPCannotBeAccessed'), '', ICON_SIZE_SMALL);
  679. } else {
  680. if ($row['active'] == 0 || $visibility == 0) {
  681. $actions .= Display::url(
  682. Display::return_icon(
  683. 'invisible.png',
  684. get_lang('Activate'),
  685. '',
  686. ICON_SIZE_SMALL
  687. ),
  688. 'exercise.php?'.api_get_cidreq(
  689. ).'&choice=enable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']
  690. );
  691. } else {
  692. // else if not active
  693. $actions .= Display::url(
  694. Display::return_icon(
  695. 'visible.png',
  696. get_lang('Deactivate'),
  697. '',
  698. ICON_SIZE_SMALL
  699. ),
  700. 'exercise.php?'.api_get_cidreq(
  701. ).'&choice=disable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']
  702. );
  703. }
  704. }
  705. // Export qti ...
  706. $actions .= Display::url(Display::return_icon('export_qti2.png', 'IMS/QTI', '', ICON_SIZE_SMALL), 'exercise.php?choice=exportqti2&exerciseId='.$row['id'].'&'.api_get_cidreq());
  707. } else {
  708. // not session
  709. $actions = Display::return_icon('edit_na.png', get_lang('ExerciseEditionNotAvailableInSession'));
  710. // Check if this exercise was added in a LP
  711. if ($exercise->exercise_was_added_in_lp == true) {
  712. $actions .= Display::return_icon('invisible.png', get_lang('AddedToLPCannotBeAccessed'), '', ICON_SIZE_SMALL);
  713. } else {
  714. if ($row['active'] == 0 || $visibility == 0) {
  715. $actions .= Display::url(
  716. Display::return_icon('invisible.png', get_lang('Activate'), '', ICON_SIZE_SMALL),
  717. 'exercise.php?'.api_get_cidreq().'&choice=enable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']
  718. );
  719. } else {
  720. // else if not active
  721. $actions .= Display::url(
  722. Display::return_icon('visible.png', get_lang('Deactivate'), '', ICON_SIZE_SMALL),
  723. 'exercise.php?'.api_get_cidreq().'&choice=disable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']
  724. );
  725. }
  726. }
  727. $actions .= '<a href="exercise_report.php?'.api_get_cidreq().'&exerciseId='.$row['id'].'">'.
  728. Display::return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  729. $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']));
  730. }
  731. // Delete
  732. if ($session_id == $row['session_id']) {
  733. if ($locked == false) {
  734. $actions .= Display::url(
  735. Display::return_icon(
  736. 'delete.png',
  737. get_lang('Delete'),
  738. '',
  739. ICON_SIZE_SMALL
  740. ),
  741. '',
  742. 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'])
  743. );
  744. } else {
  745. $actions .= Display::return_icon('delete_na.png', get_lang('ResourceLockedByGradebook'), '', ICON_SIZE_SMALL);
  746. }
  747. }
  748. // Number of questions
  749. $random_label = null;
  750. if ($row['random'] > 0 || $row['random'] == -1) {
  751. // if random == -1 means use random questions with all questions
  752. $random_number_of_question = $row['random'];
  753. if ($random_number_of_question == -1) {
  754. $random_number_of_question = $rowi;
  755. }
  756. if ($row['random_by_category'] > 0) {
  757. $nbQuestionsTotal = TestCategory::getNumberOfQuestionRandomByCategory(
  758. $my_exercise_id,
  759. $random_number_of_question
  760. );
  761. $number_of_questions = $nbQuestionsTotal." ";
  762. $number_of_questions .= ($nbQuestionsTotal > 1) ? get_lang("QuestionsLowerCase") : get_lang("QuestionLowerCase");
  763. $number_of_questions .= " - ";
  764. $number_of_questions .= min(TestCategory::getNumberMaxQuestionByCat($my_exercise_id), $random_number_of_question).' '.get_lang('QuestionByCategory');
  765. } else {
  766. $random_label = ' ('.get_lang('Random').') ';
  767. $number_of_questions = $random_number_of_question.' '.$random_label;
  768. //Bug if we set a random value bigger than the real number of questions
  769. if ($random_number_of_question > $rowi) {
  770. $number_of_questions = $rowi.' '.$random_label;
  771. }
  772. }
  773. } else {
  774. $number_of_questions = $rowi;
  775. }
  776. //Attempts
  777. //$attempts = ExerciseLib::get_count_exam_results($row['id']).' '.get_lang('Attempts');
  778. //$item .= Display::tag('td',$attempts);
  779. $item .= Display::tag('td', $number_of_questions);
  780. } else {
  781. // Student only.
  782. $visibility = api_get_item_visibility(
  783. $courseInfo,
  784. TOOL_QUIZ,
  785. $my_exercise_id,
  786. $sessionId
  787. );
  788. if ($visibility == 0) {
  789. continue;
  790. }
  791. $url = '<a '.$alt_title.' href="overview.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id'].'">'.
  792. $cut_title.'</a>';
  793. // Link of the exercise.
  794. $item = Display::tag('td', $url.' '.$session_img);
  795. // Count number exercise questions.
  796. /*$sql = "SELECT count(*) FROM $TBL_EXERCISE_QUESTION
  797. WHERE c_id = $courseId AND exercice_id = ".$row['id'];
  798. $sqlresult = Database::query($sql);
  799. $rowi = Database::result($sqlresult, 0);
  800. if ($row['random'] > 0) {
  801. $row['random'].' '.api_strtolower(get_lang(($row['random'] > 1 ? 'Questions' : 'Question')));
  802. } else {
  803. //show results student
  804. $rowi.' '.api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question')));
  805. }*/
  806. // This query might be improved later on by ordering by the new "tms" field rather than by exe_id
  807. // Don't remove this marker: note-query-exe-results
  808. $sql = "SELECT * FROM $TBL_TRACK_EXERCISES
  809. WHERE
  810. exe_exo_id = ".$row['id']." AND
  811. exe_user_id = $userId AND
  812. c_id = ".api_get_course_int_id()." AND
  813. status <> 'incomplete' AND
  814. orig_lp_id = 0 AND
  815. orig_lp_item_id = 0 AND
  816. session_id = '".api_get_session_id()."'
  817. ORDER BY exe_id DESC";
  818. $qryres = Database::query($sql);
  819. $num = Database :: num_rows($qryres);
  820. // Hide the results.
  821. $my_result_disabled = $row['results_disabled'];
  822. // Time limits are on
  823. if ($time_limits) {
  824. // Exam is ready to be taken
  825. if ($is_actived_time) {
  826. // Show results 697 $attempt_text = get_lang('LatestAttempt').' : ';
  827. if ($my_result_disabled == 0 || $my_result_disabled == 2) {
  828. //More than one attempt
  829. if ($num > 0) {
  830. $row_track = Database :: fetch_array($qryres);
  831. $attempt_text = get_lang('LatestAttempt').' : ';
  832. $attempt_text .= ExerciseLib::show_score($row_track['exe_result'], $row_track['exe_weighting']);
  833. } else {
  834. //No attempts
  835. $attempt_text = get_lang('NotAttempted');
  836. }
  837. } else {
  838. //$attempt_text = get_lang('CantShowResults');
  839. $attempt_text = '-';
  840. }
  841. } else {
  842. //Quiz not ready due to time limits 700 $attempt_text = get_lang('NotAttempted');
  843. //@todo use the is_visible function
  844. if (!empty($row['start_time']) && !empty($row['end_time'])) {
  845. $today = time();
  846. $start_time = api_strtotime($row['start_time'], 'UTC');
  847. $end_time = api_strtotime($row['end_time'], 'UTC');
  848. if ($today < $start_time) {
  849. $attempt_text = sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_convert_and_format_date($row['start_time']), api_convert_and_format_date($row['end_time']));
  850. } else {
  851. if ($today > $end_time) {
  852. $attempt_text = sprintf(get_lang('ExerciseWasActivatedFromXToY'), api_convert_and_format_date($row['start_time']), api_convert_and_format_date($row['end_time']));
  853. }
  854. }
  855. } else {
  856. //$attempt_text = get_lang('ExamNotAvailableAtThisTime');
  857. if (!empty($row['start_time'])) {
  858. $attempt_text = sprintf(
  859. get_lang('ExerciseAvailableFromX'),
  860. api_convert_and_format_date($row['start_time'])
  861. );
  862. }
  863. if (!empty($row['end_time'])) {
  864. $attempt_text = sprintf(
  865. get_lang('ExerciseAvailableUntilX'),
  866. api_convert_and_format_date($row['end_time'])
  867. );
  868. }
  869. }
  870. }
  871. } else {
  872. // Normal behaviour.
  873. // Show results.
  874. if ($my_result_disabled == 0 || $my_result_disabled == 2) {
  875. if ($num > 0) {
  876. $row_track = Database :: fetch_array($qryres);
  877. $attempt_text = get_lang('LatestAttempt').' : ';
  878. $attempt_text .= ExerciseLib::show_score(
  879. $row_track['exe_result'],
  880. $row_track['exe_weighting']
  881. );
  882. } else {
  883. $attempt_text = get_lang('NotAttempted');
  884. }
  885. } else {
  886. //$attempt_text = get_lang('CantShowResults');
  887. $attempt_text = '-';
  888. }
  889. }
  890. $class_tip = '';
  891. if (empty($num)) {
  892. $num = '';
  893. } else {
  894. $class_tip = 'link_tooltip';
  895. //@todo use sprintf and show the results validated by the teacher
  896. if ($num == 1) {
  897. $num = $num.' '.get_lang('Result');
  898. } else {
  899. $num = $num.' '.get_lang('Results');
  900. }
  901. $num = '<span class="tooltip" style="display: none;">'.$num.'</span>';
  902. }
  903. $item .= Display::tag('td', $attempt_text);
  904. }
  905. if ($is_allowedToEdit) {
  906. $item .= Display::tag('td', $actions, array('class' => 'td_actions'));
  907. } else {
  908. if ($isDrhOfCourse) {
  909. $actions = '<a href="exercise_report.php?'.api_get_cidreq().'&exerciseId='.$row['id'].'">'.
  910. Display::return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  911. $item .= Display::tag('td', $actions, array('class' => 'td_actions'));
  912. }
  913. }
  914. $tableRows[] = Display::tag(
  915. 'tr',
  916. $item,
  917. array(
  918. 'id' => 'exercise_list_'.$my_exercise_id,
  919. )
  920. );
  921. }
  922. }
  923. }
  924. // end exercise list
  925. // Hotpotatoes results
  926. $hotpotatoes_exist = false;
  927. if ($is_allowedToEdit) {
  928. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  929. FROM $TBL_DOCUMENT d
  930. INNER JOIN $TBL_ITEM_PROPERTY ip
  931. ON (d.id = ip.ref AND d.c_id = ip.c_id)
  932. WHERE
  933. d.c_id = $courseId AND
  934. ip.c_id = $courseId AND
  935. ip.tool = '".TOOL_DOCUMENT."' AND
  936. (d.path LIKE '%htm%') AND
  937. d.path LIKE '".Database :: escape_string($uploadPath.'/%/%')."'
  938. LIMIT ".$from.",".$limit; // only .htm or .html files listed
  939. } else {
  940. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  941. FROM $TBL_DOCUMENT d
  942. INNER JOIN $TBL_ITEM_PROPERTY ip
  943. ON (d.id = ip.ref AND d.c_id = ip.c_id)
  944. WHERE
  945. d.c_id = $courseId AND
  946. ip.c_id = $courseId AND
  947. ip.tool = '".TOOL_DOCUMENT."' AND
  948. (d.path LIKE '%htm%') AND
  949. d.path LIKE '".Database :: escape_string($uploadPath.'/%/%')."' AND
  950. ip.visibility='1'
  951. LIMIT ".$from.",".$limit;
  952. }
  953. $result = Database::query($sql);
  954. while ($row = Database :: fetch_array($result, 'ASSOC')) {
  955. $attribute['path'][] = $row['path'];
  956. $attribute['visibility'][] = $row['visibility'];
  957. $attribute['comment'][] = $row['comment'];
  958. }
  959. $nbrActiveTests = 0;
  960. if (isset($attribute['path']) && is_array($attribute['path'])) {
  961. $hotpotatoes_exist = true;
  962. while (list($key, $path) = each($attribute['path'])) {
  963. $item = '';
  964. list ($a, $vis) = each($attribute['visibility']);
  965. $active = !empty($vis);
  966. $title = GetQuizName($path, $documentPath);
  967. if ($title == '') {
  968. $title = basename($path);
  969. }
  970. // prof only
  971. if ($is_allowedToEdit) {
  972. $item = Display::tag(
  973. 'td',
  974. implode(PHP_EOL, [
  975. Display::return_icon('hotpotatoes_s.png', "HotPotatoes"),
  976. Display::url(
  977. $title,
  978. 'showinframes.php?'.api_get_cidreq().'&'.http_build_query([
  979. 'file' => $path,
  980. 'uid' => $userId
  981. ]),
  982. ['class' => !$active ? 'text-muted' : null]
  983. )
  984. ])
  985. );
  986. $item .= Display::tag('td', '-');
  987. $actions = Display::url(
  988. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL),
  989. 'adminhp.php?'.api_get_cidreq().'&hotpotatoesName='.$path
  990. );
  991. $actions .= '<a href="hotpotatoes_exercise_report.php?'.api_get_cidreq().'&path='.$path.'">'.
  992. Display::return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  993. // if active
  994. if ($active) {
  995. $nbrActiveTests = $nbrActiveTests + 1;
  996. $actions .= ' <a href="'.$exercisePath.'?'.api_get_cidreq().'&hpchoice=disable&page='.$page.'&file='.$path.'">'.
  997. Display::return_icon('visible.png', get_lang('Deactivate'), '', ICON_SIZE_SMALL).'</a>';
  998. } else { // else if not active
  999. $actions .= ' <a href="'.$exercisePath.'?'.api_get_cidreq().'&hpchoice=enable&page='.$page.'&file='.$path.'">'.
  1000. Display::return_icon('invisible.png', get_lang('Activate'), '', ICON_SIZE_SMALL).'</a>';
  1001. }
  1002. $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;">'.
  1003. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
  1004. $item .= Display::tag('td', $actions);
  1005. $tableRows[] = Display::tag('tr', $item);
  1006. } else {
  1007. // Student only
  1008. if ($active) {
  1009. $attempt = ExerciseLib::getLatestHotPotatoResult(
  1010. $path,
  1011. $userId,
  1012. api_get_course_int_id(),
  1013. api_get_session_id()
  1014. );
  1015. $nbrActiveTests = $nbrActiveTests + 1;
  1016. $item .= Display::tag(
  1017. 'td',
  1018. Display::url(
  1019. $title,
  1020. 'showinframes.php?'.api_get_cidreq().'&'.http_build_query([
  1021. 'file' => $path,
  1022. 'cid' => api_get_course_id(),
  1023. 'uid' => $userId
  1024. ])
  1025. )
  1026. );
  1027. if (!empty($attempt)) {
  1028. $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>';
  1029. $attemptText = get_lang('LatestAttempt').' : ';
  1030. $attemptText .= ExerciseLib::show_score($attempt['exe_result'], $attempt['exe_weighting']).' ';
  1031. $attemptText .= $actions;
  1032. } else {
  1033. // No attempts.
  1034. $attemptText = get_lang('NotAttempted').' ';
  1035. }
  1036. $item .= Display::tag('td', $attemptText);
  1037. if ($isDrhOfCourse) {
  1038. $actions = '<a href="hotpotatoes_exercise_report.php?'.api_get_cidreq().'&path='.$path.'">'.
  1039. Display::return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  1040. $item .= Display::tag('td', $actions, array('class' => 'td_actions'));
  1041. }
  1042. $tableRows[] = Display::tag('tr', $item);
  1043. }
  1044. }
  1045. }
  1046. }
  1047. if (empty($exerciseList) && $hotpotatoes_exist == false) {
  1048. if ($is_allowedToEdit && $origin != 'learnpath') {
  1049. echo '<div id="no-data-view">';
  1050. echo '<h3>'.get_lang('Quiz').'</h3>';
  1051. echo Display::return_icon('quiz.png', '', array(), 64);
  1052. echo '<div class="controls">';
  1053. echo Display::url('<em class="fa fa-plus"></em> '.get_lang('NewEx'), 'exercise_admin.php?'.api_get_cidreq(), array('class' => 'btn btn-primary'));
  1054. echo '</div>';
  1055. echo '</div>';
  1056. }
  1057. } else {
  1058. if ($is_allowedToEdit) {
  1059. $headers = [
  1060. get_lang('ExerciseName'),
  1061. get_lang('QuantityQuestions'),
  1062. get_lang('Actions')
  1063. ];
  1064. } else {
  1065. $headers = [
  1066. get_lang('ExerciseName'),
  1067. get_lang('Status')
  1068. ];
  1069. if ($isDrhOfCourse) {
  1070. $headers[] = get_lang('Actions');
  1071. }
  1072. }
  1073. $headerList = '';
  1074. foreach ($headers as $header) {
  1075. $headerList .= Display::tag('th', $header);
  1076. }
  1077. echo '<div class="table-responsive">';
  1078. echo '<table class="table table-striped table-hover">';
  1079. echo Display::tag(
  1080. 'thead',
  1081. Display::tag('tr', $headerList)
  1082. );
  1083. echo '<tbody>';
  1084. foreach ($tableRows as $row) {
  1085. echo $row;
  1086. }
  1087. echo '</tbody>';
  1088. echo '</table>';
  1089. echo '</div>';
  1090. }
  1091. if ($origin != 'learnpath') { //so we are not in learnpath tool
  1092. Display :: display_footer();
  1093. }