exercice.php 49 KB

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