exercice.php 49 KB

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