exercise.php 54 KB

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