exercise.php 51 KB

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