exercise.php 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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 ((!empty($row['start_time']) && $row['start_time'] != '0000-00-00 00:00:00') ||
  487. ($row['end_time'] != '0000-00-00 00:00:00' && !empty($row['end_time']))
  488. ) {
  489. $time_limits = true;
  490. }
  491. $is_actived_time = false;
  492. if ($time_limits) {
  493. // check if start time
  494. $start_time = false;
  495. if (!empty($row['start_time']) && $row['start_time'] != '0000-00-00 00:00:00') {
  496. $start_time = api_strtotime($row['start_time'], 'UTC');
  497. }
  498. $end_time = false;
  499. if (!empty($row['end_time']) && $row['end_time'] != '0000-00-00 00:00:00') {
  500. $end_time = api_strtotime($row['end_time'], 'UTC');
  501. }
  502. $now = time();
  503. //If both "clocks" are enable
  504. if ($start_time && $end_time) {
  505. if ($now > $start_time && $end_time > $now) {
  506. $is_actived_time = true;
  507. }
  508. } else {
  509. //we check the start and end
  510. if ($start_time) {
  511. if ($now > $start_time) {
  512. $is_actived_time = true;
  513. }
  514. }
  515. if ($end_time) {
  516. if ($end_time > $now) {
  517. $is_actived_time = true;
  518. }
  519. }
  520. }
  521. }
  522. // Blocking empty start times see BT#2800
  523. global $_custom;
  524. if (isset($_custom['exercises_hidden_when_no_start_date']) &&
  525. $_custom['exercises_hidden_when_no_start_date']
  526. ) {
  527. if (empty($row['start_time']) ||
  528. $row['start_time'] == '0000-00-00 00:00:00'
  529. ) {
  530. $time_limits = true;
  531. $is_actived_time = false;
  532. }
  533. }
  534. $cut_title = $exercise_obj->getCutTitle();
  535. $alt_title = '';
  536. if ($cut_title != $row['title']) {
  537. $alt_title = ' title = "'.$row['title'].'" ';
  538. }
  539. // Teacher only
  540. if ($is_allowedToEdit) {
  541. $lp_blocked = null;
  542. if ($exercise_obj->exercise_was_added_in_lp == true) {
  543. $lp_blocked = Display::div(
  544. get_lang('AddedToLPCannotBeAccessed'),
  545. array('class' => 'lp_content_type_label')
  546. );
  547. }
  548. $visibility = api_get_item_visibility(
  549. $courseInfo,
  550. TOOL_QUIZ,
  551. $my_exercise_id,
  552. 0
  553. );
  554. if (!empty($sessionId)) {
  555. $setting = api_get_configuration_value('show_hidden_exercise_added_to_lp');
  556. if ($setting) {
  557. if ($exercise_obj->exercise_was_added_in_lp == false) {
  558. if ($visibility == 0) {
  559. continue;
  560. }
  561. }
  562. } else {
  563. if ($visibility == 0) {
  564. continue;
  565. }
  566. }
  567. $visibility = api_get_item_visibility(
  568. $courseInfo,
  569. TOOL_QUIZ,
  570. $my_exercise_id,
  571. $sessionId
  572. );
  573. }
  574. if ($row['active'] == 0 || $visibility == 0) {
  575. $title = Display::tag('font', $cut_title, array('style' => 'color:grey'));
  576. } else {
  577. $title = $cut_title;
  578. }
  579. $count_exercise_not_validated = intval(
  580. Event::count_exercise_result_not_validated(
  581. $my_exercise_id,
  582. $courseId,
  583. $session_id
  584. )
  585. );
  586. $move = Display::return_icon(
  587. 'all_directions.png',
  588. get_lang('Move'),
  589. array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;')
  590. );
  591. $move = null;
  592. $class_tip = '';
  593. if (!empty($count_exercise_not_validated)) {
  594. $results_text = $count_exercise_not_validated == 1 ? get_lang('ResultNotRevised') : get_lang('ResultsNotRevised');
  595. $title .= '<span class="exercise_tooltip" style="display: none;">'.$count_exercise_not_validated.' '.$results_text.' </span>';
  596. $class_tip = 'link_tooltip';
  597. }
  598. //$class_tip = 'exercise_link';
  599. $url = $move.'<a '.$alt_title.' class="'.$class_tip.'" id="tooltip_'.$row['id'].'" href="overview.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id'].'">
  600. '.Display::return_icon('quiz.gif', $row['title']).'
  601. '.$title.' </a>';
  602. $item = Display::tag('td', $url.' '.$session_img.$lp_blocked);
  603. // Count number exercise - teacher
  604. $sql = "SELECT count(*) count FROM $TBL_EXERCISE_QUESTION
  605. WHERE c_id = $courseId AND exercice_id = $my_exercise_id";
  606. $sqlresult = Database::query($sql);
  607. $rowi = Database :: result($sqlresult, 0, 0);
  608. if ($session_id == $row['session_id']) {
  609. // Questions list
  610. $actions = Display::url(
  611. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL),
  612. 'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']
  613. );
  614. // Test settings
  615. $actions .= Display::url(
  616. Display::return_icon('settings.png', get_lang('Configure'), '', ICON_SIZE_SMALL),
  617. 'exercise_admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']
  618. );
  619. // Exercise results
  620. $actions .='<a href="exercise_report.php?'.api_get_cidreq().'&exerciseId='.$row['id'].'">'.
  621. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  622. // Export
  623. $actions .= Display::url(
  624. Display::return_icon('cd.gif', get_lang('CopyExercise')),
  625. '',
  626. array(
  627. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToCopy'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;",
  628. 'href' => 'exercise.php?'.api_get_cidreq().'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id']
  629. )
  630. );
  631. // Clean exercise
  632. if ($locked == false) {
  633. $actions .= Display::url(
  634. Display::return_icon('clean.png', get_lang('CleanStudentResults'), '', ICON_SIZE_SMALL),
  635. '',
  636. array(
  637. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDeleteResults'), ENT_QUOTES, $charset))." ".addslashes($row['title'])."?"."')) return false;",
  638. 'href' => 'exercise.php?'.api_get_cidreq().'&choice=clean_results&sec_token='.$token.'&exerciseId='.$row['id']
  639. )
  640. );
  641. } else {
  642. $actions .= Display::return_icon('clean_na.png', get_lang('ResourceLockedByGradebook'), '', ICON_SIZE_SMALL);
  643. }
  644. // Visible / invisible
  645. // Check if this exercise was added in a LP
  646. if ($exercise_obj->exercise_was_added_in_lp == true) {
  647. $actions .= Display::return_icon('invisible.png', get_lang('AddedToLPCannotBeAccessed'), '', ICON_SIZE_SMALL);
  648. } else {
  649. if ($row['active'] == 0 || $visibility == 0) {
  650. $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']);
  651. } else {
  652. // else if not active
  653. $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']);
  654. }
  655. }
  656. // Export qti ...
  657. $actions .= Display::url(Display::return_icon('export_qti2.png', 'IMS/QTI', '', ICON_SIZE_SMALL), 'exercise.php?choice=exportqti2&exerciseId='.$row['id'].'&'.api_get_cidreq());
  658. } else {
  659. // not session
  660. $actions = Display::return_icon('edit_na.png', get_lang('ExerciseEditionNotAvailableInSession'));
  661. // Check if this exercise was added in a LP
  662. if ($exercise_obj->exercise_was_added_in_lp == true) {
  663. $actions .= Display::return_icon('invisible.png', get_lang('AddedToLPCannotBeAccessed'), '', ICON_SIZE_SMALL);
  664. } else {
  665. if ($row['active'] == 0 || $visibility == 0) {
  666. $actions .= Display::url(
  667. Display::return_icon('invisible.png', get_lang('Activate'), '', ICON_SIZE_SMALL),
  668. 'exercise.php?'.api_get_cidreq().'&choice=enable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']
  669. );
  670. } else {
  671. // else if not active
  672. $actions .= Display::url(
  673. Display::return_icon('visible.png', get_lang('Deactivate'), '', ICON_SIZE_SMALL),
  674. 'exercise.php?'.api_get_cidreq().'&choice=disable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']
  675. );
  676. }
  677. }
  678. $actions .='<a href="exercise_report.php?'.api_get_cidreq().'&exerciseId='.$row['id'].'">'.
  679. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  680. $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']));
  681. }
  682. // Delete
  683. if ($session_id == $row['session_id']) {
  684. if ($locked == false) {
  685. $actions .= Display::url(
  686. Display::return_icon(
  687. 'delete.png',
  688. get_lang('Delete'),
  689. '',
  690. ICON_SIZE_SMALL
  691. ),
  692. '',
  693. 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'])
  694. );
  695. } else {
  696. $actions .= Display::return_icon('delete_na.png', get_lang('ResourceLockedByGradebook'), '', ICON_SIZE_SMALL);
  697. }
  698. }
  699. // Number of questions
  700. $random_label = null;
  701. if ($row['random'] > 0 || $row['random'] == -1) {
  702. // if random == -1 means use random questions with all questions
  703. $random_number_of_question = $row['random'];
  704. if ($random_number_of_question == -1) {
  705. $random_number_of_question = $rowi;
  706. }
  707. if ($row['random_by_category'] > 0) {
  708. $nbQuestionsTotal = TestCategory::getNumberOfQuestionRandomByCategory(
  709. $my_exercise_id,
  710. $random_number_of_question
  711. );
  712. $number_of_questions = $nbQuestionsTotal." ";
  713. $number_of_questions .= ($nbQuestionsTotal > 1) ? get_lang("QuestionsLowerCase") : get_lang("QuestionLowerCase");
  714. $number_of_questions .= " - ";
  715. $number_of_questions .= min(TestCategory::getNumberMaxQuestionByCat($my_exercise_id), $random_number_of_question).' '.get_lang('QuestionByCategory');
  716. } else {
  717. $random_label = ' ('.get_lang('Random').') ';
  718. $number_of_questions = $random_number_of_question.' '.$random_label;
  719. //Bug if we set a random value bigger than the real number of questions
  720. if ($random_number_of_question > $rowi) {
  721. $number_of_questions = $rowi.' '.$random_label;
  722. }
  723. }
  724. } else {
  725. $number_of_questions = $rowi;
  726. }
  727. //Attempts
  728. //$attempts = ExerciseLib::get_count_exam_results($row['id']).' '.get_lang('Attempts');
  729. //$item .= Display::tag('td',$attempts);
  730. $item .= Display::tag('td', $number_of_questions);
  731. } else {
  732. // Student only.
  733. $visibility = api_get_item_visibility(
  734. $courseInfo,
  735. TOOL_QUIZ,
  736. $my_exercise_id,
  737. $sessionId
  738. );
  739. if ($visibility == 0) {
  740. continue;
  741. }
  742. $url = '<a '.$alt_title.' href="overview.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id'].'">'.
  743. $cut_title.'</a>';
  744. // Link of the exercise.
  745. $item = Display::tag('td', $url.' '.$session_img);
  746. // Count number exercise questions.
  747. /*$sql = "SELECT count(*) FROM $TBL_EXERCISE_QUESTION
  748. WHERE c_id = $courseId AND exercice_id = ".$row['id'];
  749. $sqlresult = Database::query($sql);
  750. $rowi = Database::result($sqlresult, 0);
  751. if ($row['random'] > 0) {
  752. $row['random'].' '.api_strtolower(get_lang(($row['random'] > 1 ? 'Questions' : 'Question')));
  753. } else {
  754. //show results student
  755. $rowi.' '.api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question')));
  756. }*/
  757. // This query might be improved later on by ordering by the new "tms" field rather than by exe_id
  758. // Don't remove this marker: note-query-exe-results
  759. $sql = "SELECT * FROM $TBL_TRACK_EXERCISES
  760. WHERE
  761. exe_exo_id = ".$row['id']." AND
  762. exe_user_id = ".$userId." AND
  763. c_id = ".api_get_course_int_id()." AND
  764. status <> 'incomplete' AND
  765. orig_lp_id = 0 AND
  766. orig_lp_item_id = 0 AND
  767. session_id = '".api_get_session_id()."'
  768. ORDER BY exe_id DESC";
  769. $qryres = Database::query($sql);
  770. $num = Database :: num_rows($qryres);
  771. // Hide the results.
  772. $my_result_disabled = $row['results_disabled'];
  773. // Time limits are on
  774. if ($time_limits) {
  775. // Exam is ready to be taken
  776. if ($is_actived_time) {
  777. // Show results 697 $attempt_text = get_lang('LatestAttempt').' : ';
  778. if ($my_result_disabled == 0 || $my_result_disabled == 2) {
  779. //More than one attempt
  780. if ($num > 0) {
  781. $row_track = Database :: fetch_array($qryres);
  782. $attempt_text = get_lang('LatestAttempt').' : ';
  783. $attempt_text .= ExerciseLib::show_score($row_track['exe_result'], $row_track['exe_weighting']);
  784. } else {
  785. //No attempts
  786. $attempt_text = get_lang('NotAttempted');
  787. }
  788. } else {
  789. //$attempt_text = get_lang('CantShowResults');
  790. $attempt_text = '-';
  791. }
  792. } else {
  793. //Quiz not ready due to time limits 700 $attempt_text = get_lang('NotAttempted');
  794. //@todo use the is_visible function
  795. if (!empty($row['start_time']) && !empty($row['end_time']) &&
  796. $row['start_time'] != '0000-00-00 00:00:00' && $row['end_time'] != '0000-00-00 00:00:00'
  797. ) {
  798. $today = time();
  799. $start_time = api_strtotime($row['start_time'], 'UTC');
  800. $end_time = api_strtotime($row['end_time'], 'UTC');
  801. if ($today < $start_time) {
  802. $attempt_text = sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_convert_and_format_date($row['start_time']), api_convert_and_format_date($row['end_time']));
  803. } else {
  804. if ($today > $end_time) {
  805. $attempt_text = sprintf(get_lang('ExerciseWasActivatedFromXToY'), api_convert_and_format_date($row['start_time']), api_convert_and_format_date($row['end_time']));
  806. }
  807. }
  808. } else {
  809. //$attempt_text = get_lang('ExamNotAvailableAtThisTime');
  810. if ($row['start_time'] != '0000-00-00 00:00:00') {
  811. $attempt_text = sprintf(get_lang('ExerciseAvailableFromX'), api_convert_and_format_date($row['start_time']));
  812. }
  813. if ($row['end_time'] != '0000-00-00 00:00:00') {
  814. $attempt_text = sprintf(get_lang('ExerciseAvailableUntilX'), api_convert_and_format_date($row['end_time']));
  815. }
  816. }
  817. }
  818. } else {
  819. // Normal behaviour.
  820. // Show results.
  821. if ($my_result_disabled == 0 || $my_result_disabled == 2) {
  822. if ($num > 0) {
  823. $row_track = Database :: fetch_array($qryres);
  824. $attempt_text = get_lang('LatestAttempt').' : ';
  825. $attempt_text .= ExerciseLib::show_score($row_track['exe_result'], $row_track['exe_weighting']);
  826. } else {
  827. $attempt_text = get_lang('NotAttempted');
  828. }
  829. } else {
  830. //$attempt_text = get_lang('CantShowResults');
  831. $attempt_text = '-';
  832. }
  833. }
  834. $class_tip = '';
  835. if (empty($num)) {
  836. $num = '';
  837. } else {
  838. $class_tip = 'link_tooltip';
  839. //@todo use sprintf and show the results validated by the teacher
  840. if ($num == 1) {
  841. $num = $num.' '.get_lang('Result');
  842. } else {
  843. $num = $num.' '.get_lang('Results');
  844. }
  845. $num = '<span class="tooltip" style="display: none;">'.$num.'</span>';
  846. }
  847. $item .= Display::tag('td', $attempt_text);
  848. }
  849. if ($is_allowedToEdit) {
  850. $item .= Display::tag('td', $actions, array('class' => 'td_actions'));
  851. } else {
  852. if ($isDrhOfCourse) {
  853. $actions ='<a href="exercise_report.php?'.api_get_cidreq().'&exerciseId='.$row['id'].'">'.
  854. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  855. $item .= Display::tag('td', $actions, array('class' => 'td_actions'));
  856. }
  857. }
  858. $tableRows[] = Display::tag(
  859. 'tr',
  860. $item,
  861. array(
  862. 'id' => 'exercise_list_' . $my_exercise_id,
  863. )
  864. );
  865. } // end foreach()
  866. }
  867. }
  868. // end exercise list
  869. // Hotpotatoes results
  870. $hotpotatoes_exist = false;
  871. if ($is_allowedToEdit) {
  872. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  873. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  874. WHERE
  875. d.c_id = $courseId AND
  876. ip.c_id = $courseId AND
  877. d.id = ip.ref AND
  878. ip.tool = '".TOOL_DOCUMENT."' AND
  879. (d.path LIKE '%htm%') AND
  880. d.path LIKE '".Database :: escape_string($uploadPath.'/%/%')."'
  881. LIMIT ".$from.",".$limit; // only .htm or .html files listed
  882. } else {
  883. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  884. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  885. WHERE
  886. d.c_id = $courseId AND
  887. ip.c_id = $courseId AND
  888. d.id = ip.ref AND
  889. ip.tool = '".TOOL_DOCUMENT."' AND
  890. (d.path LIKE '%htm%') AND
  891. d.path LIKE '".Database :: escape_string($uploadPath.'/%/%')."' AND
  892. ip.visibility='1'
  893. LIMIT ".$from.",".$limit;
  894. }
  895. $result = Database::query($sql);
  896. while ($row = Database :: fetch_array($result, 'ASSOC')) {
  897. $attribute['path'][] = $row['path'];
  898. $attribute['visibility'][] = $row['visibility'];
  899. $attribute['comment'][] = $row['comment'];
  900. }
  901. $nbrActiveTests = 0;
  902. if (isset($attribute['path']) && is_array($attribute['path'])) {
  903. $hotpotatoes_exist = true;
  904. while (list($key, $path) = each($attribute['path'])) {
  905. $item = '';
  906. list ($a, $vis) = each($attribute['visibility']);
  907. if (strcmp($vis, "1") == 0) {
  908. $active = 1;
  909. } else {
  910. $active = 0;
  911. }
  912. $title = GetQuizName($path, $documentPath);
  913. if ($title == '') {
  914. $title = basename($path);
  915. }
  916. // prof only
  917. if ($is_allowedToEdit) {
  918. $item = Display::tag('td', Display::return_icon('hotpotatoes_s.png', "HotPotatoes").'<a href="showinframes.php?file='.$path.'&cid='.api_get_course_id().'&uid='.$userId.'" '.(!$active ? 'class="invisible"' : '').' >'.$title.'</a> ');
  919. $item .= Display::tag('td', '-');
  920. $actions = Display::url(
  921. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL),
  922. 'adminhp.php?'.api_get_cidreq().'&hotpotatoesName='.$path
  923. );
  924. $actions .='<a href="hotpotatoes_exercise_report.php?'.api_get_cidreq().'&path='.$path.'">'.
  925. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  926. // if active
  927. if ($active) {
  928. $nbrActiveTests = $nbrActiveTests + 1;
  929. $actions .= ' <a href="'.$exercisePath.'?'.api_get_cidreq().'&hpchoice=disable&page='.$page.'&file='.$path.'">'.
  930. Display::return_icon('visible.png', get_lang('Deactivate'), '', ICON_SIZE_SMALL).'</a>';
  931. } else { // else if not active
  932. $actions .=' <a href="'.$exercisePath.'?'.api_get_cidreq().'&hpchoice=enable&page='.$page.'&file='.$path.'">'.
  933. Display::return_icon('invisible.png', get_lang('Activate'), '', ICON_SIZE_SMALL).'</a>';
  934. }
  935. $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;">'.
  936. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
  937. $item .= Display::tag('td', $actions);
  938. $tableRows[] = Display::tag('tr', $item);
  939. } else {
  940. // Student only
  941. if ($active == 1) {
  942. $attempt = ExerciseLib::getLatestHotPotatoResult(
  943. $path,
  944. $userId,
  945. api_get_course_int_id(),
  946. api_get_session_id()
  947. );
  948. $nbrActiveTests = $nbrActiveTests + 1;
  949. $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>');
  950. if (!empty($attempt)) {
  951. $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>';
  952. $attemptText = get_lang('LatestAttempt').' : ';
  953. $attemptText .= ExerciseLib::show_score($attempt['exe_result'], $attempt['exe_weighting']).' ';
  954. $attemptText .= $actions;
  955. } else {
  956. // No attempts.
  957. $attemptText = get_lang('NotAttempted').' ';
  958. }
  959. $item .= Display::tag('td', $attemptText);
  960. if ($isDrhOfCourse) {
  961. $actions ='<a href="hotpotatoes_exercise_report.php?'.api_get_cidreq().'&path='.$path.'">'.
  962. Display :: return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
  963. $item .= Display::tag('td', $actions, array('class' => 'td_actions'));
  964. }
  965. $tableRows[] = Display::tag('tr', $item);
  966. }
  967. }
  968. }
  969. }
  970. if (empty($exercise_list) && $hotpotatoes_exist == false) {
  971. if ($is_allowedToEdit && $origin != 'learnpath') {
  972. echo '<div id="no-data-view">';
  973. echo '<h3>'.get_lang('Quiz').'</h3>';
  974. echo Display::return_icon('quiz.png', '', array(), 64);
  975. echo '<div class="controls">';
  976. echo Display::url('<em class="fa fa-plus"></em> '.get_lang('NewEx'), 'exercise_admin.php?'.api_get_cidreq(), array('class' => 'btn btn-primary'));
  977. echo '</div>';
  978. echo '</div>';
  979. }
  980. } else {
  981. if ($is_allowedToEdit) {
  982. $headers = [
  983. get_lang('ExerciseName'),
  984. get_lang('QuantityQuestions'),
  985. get_lang('Actions')
  986. ];
  987. } else {
  988. $headers = [
  989. get_lang('ExerciseName'),
  990. get_lang('Status')
  991. ];
  992. if ($isDrhOfCourse) {
  993. $headers[] = get_lang('Actions');
  994. }
  995. }
  996. $headerList = '';
  997. foreach ($headers as $header) {
  998. $headerList .= Display::tag('th', $header);
  999. }
  1000. echo '<div class="table-responsive">';
  1001. echo '<table class="table table-striped table-hover">';
  1002. echo Display::tag(
  1003. 'thead',
  1004. Display::tag('tr', $headerList)
  1005. );
  1006. echo '<tbody>';
  1007. foreach ($tableRows as $row) {
  1008. echo $row;
  1009. }
  1010. echo '</tbody>';
  1011. echo '</table>';
  1012. echo '</div>';
  1013. }
  1014. if ($origin != 'learnpath') { //so we are not in learnpath tool
  1015. Display :: display_footer();
  1016. }