exercise.php 50 KB

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