exercice.php 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  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. * @version $Id:exercice.php 12269 2007-05-03 14:17:37Z elixir_julian $
  11. */
  12. // name of the language file that needs to be included
  13. $language_file = 'exercice';
  14. // including the global library
  15. require_once '../inc/global.inc.php';
  16. require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
  17. require_once '../gradebook/lib/be.inc.php';
  18. // setting the tabs
  19. $this_section = SECTION_COURSES;
  20. // access control
  21. api_protect_course_script(true);
  22. $show = (isset ($_GET['show']) && $_GET['show'] == 'result') ? 'result' : 'test'; // moved down to fix bug: http://www.dokeos.com/forum/viewtopic.php?p=18609#18609
  23. // including additional libraries
  24. require_once 'exercise.class.php';
  25. require_once 'exercise.lib.php';
  26. require_once 'question.class.php';
  27. require_once 'answer.class.php';
  28. require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
  29. require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
  30. require_once 'hotpotatoes.lib.php';
  31. require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
  32. require_once api_get_path(LIBRARY_PATH) . 'mail.lib.inc.php';
  33. require_once api_get_path(LIBRARY_PATH) . 'usermanager.lib.php';
  34. /*
  35. Constants and variables
  36. */
  37. $is_allowedToEdit = api_is_allowed_to_edit(null,true);
  38. $is_tutor = api_is_allowed_to_edit(true);
  39. $is_tutor_course = api_is_course_tutor();
  40. $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  41. $TBL_USER = Database :: get_main_table(TABLE_MAIN_USER);
  42. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  43. $TBL_ITEM_PROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  44. $TBL_EXERCICE_ANSWER = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  45. $TBL_EXERCICE_QUESTION = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  46. $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST);
  47. $TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  48. $TBL_TRACK_EXERCICES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  49. $TBL_TRACK_HOTPOTATOES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  50. $TBL_TRACK_ATTEMPT = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  51. $TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  52. $TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  53. $TBL_LP_ITEM = Database :: get_course_table(TABLE_LP_ITEM);
  54. $TBL_LP_VIEW = Database :: get_course_table(TABLE_LP_VIEW);
  55. // document path
  56. $documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . "/document";
  57. // picture path
  58. $picturePath = $documentPath . '/images';
  59. // audio path
  60. $audioPath = $documentPath . '/audio';
  61. // hotpotatoes
  62. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  63. $exercicePath = api_get_self();
  64. $exfile = explode('/', $exercicePath);
  65. $exfile = strtolower($exfile[sizeof($exfile) - 1]);
  66. $exercicePath = substr($exercicePath, 0, strpos($exercicePath, $exfile));
  67. $exercicePath = $exercicePath . "exercice.php";
  68. // maximum number of exercises on a same page
  69. $limitExPage = 50;
  70. // Clear the exercise session
  71. if (isset ($_SESSION['objExercise'])) {
  72. api_session_unregister('objExercise');
  73. }
  74. if (isset ($_SESSION['objQuestion'])) {
  75. api_session_unregister('objQuestion');
  76. }
  77. if (isset ($_SESSION['objAnswer'])) {
  78. api_session_unregister('objAnswer');
  79. }
  80. if (isset ($_SESSION['questionList'])) {
  81. api_session_unregister('questionList');
  82. }
  83. if (isset ($_SESSION['exerciseResult'])) {
  84. api_session_unregister('exerciseResult');
  85. }
  86. //general POST/GET/SESSION/COOKIES parameters recovery
  87. if (empty ($origin)) {
  88. $origin = Security::remove_XSS($_REQUEST['origin']);
  89. }
  90. if (empty ($choice)) {
  91. $choice = $_REQUEST['choice'];
  92. }
  93. if (empty ($hpchoice)) {
  94. $hpchoice = $_REQUEST['hpchoice'];
  95. }
  96. if (empty ($exerciseId)) {
  97. $exerciseId = Database :: escape_string($_REQUEST['exerciseId']);
  98. }
  99. if (empty ($file)) {
  100. $file = Database :: escape_string($_REQUEST['file']);
  101. }
  102. $learnpath_id = intval($_REQUEST['learnpath_id']);
  103. $learnpath_item_id = intval($_REQUEST['learnpath_item_id']);
  104. $page = Database :: escape_string($_REQUEST['page']);
  105. if ($origin == 'learnpath') {
  106. $show = 'result';
  107. }
  108. if ($_GET['delete'] == 'delete' && ($is_allowedToEdit || api_is_coach()) && !empty ($_GET['did']) && $_GET['did'] == strval(intval($_GET['did']))) {
  109. $sql = 'DELETE FROM ' . Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES) . ' WHERE exe_id = ' . $_GET['did']; //_GET[did] filtered by entry condition
  110. Database::query($sql);
  111. $filter=Security::remove_XSS($_GET['filter']);
  112. header('Location: exercice.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&show=result&filter=' . $filter . '');
  113. exit;
  114. }
  115. if ($show == 'result' && $_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_GET['exeid']== strval(intval($_GET['exeid']))) {
  116. $id = intval($_GET['exeid']); //filtered by post-condition
  117. $track_exercise_info = get_exercise_track_exercise_info($id);
  118. if (empty($track_exercise_info)) {
  119. api_not_allowed();
  120. }
  121. $test = $track_exercise_info['title'];
  122. $student_id = $track_exercise_info['exe_user_id'];
  123. $course_id = $track_exercise_info['exe_cours_id'];
  124. $session_id = $track_exercise_info['session_id'];
  125. $lp_id = $track_exercise_info['orig_lp_id'];
  126. $lp_item_id = $track_exercise_info['orig_lp_item_id'];
  127. $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
  128. $user_info = api_get_user_info($student_id);
  129. $emailid = $user_info['mail'];
  130. $from = $_SESSION['_user']['mail'];
  131. $from_name = api_get_person_name($_SESSION['_user']['firstName'], $_SESSION['_user']['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
  132. $url = api_get_path(WEB_CODE_PATH) . 'exercice/exercice.php?' . api_get_cidreq() . '&show=result';
  133. $total_weighting = $_REQUEST['totalWeighting'];
  134. $my_post_info=array();
  135. $post_content_id=array();
  136. $comments_exist=false;
  137. foreach ($_POST as $key_index=>$key_value) {
  138. $my_post_info=explode('_',$key_index);
  139. $post_content_id[]=$my_post_info[1];
  140. if ($my_post_info[0]=='comments') {
  141. $comments_exist=true;
  142. }
  143. }
  144. $loop_in_track=($comments_exist===true) ? (count($_POST)/2) : count($_POST);
  145. $array_content_id_exe=array();
  146. if ($comments_exist===true) {
  147. $array_content_id_exe=array_slice($post_content_id,$loop_in_track);
  148. } else {
  149. $array_content_id_exe=$post_content_id;
  150. }
  151. for ($i=0;$i<$loop_in_track;$i++) {
  152. $my_marks = Database::escape_string($_POST['marks_'.$array_content_id_exe[$i]]);
  153. $contain_comments = Database::escape_string($_POST['comments_'.$array_content_id_exe[$i]]);
  154. if (isset($contain_comments)) {
  155. $my_comments = Database::escape_string($_POST['comments_'.$array_content_id_exe[$i]]);
  156. } else {
  157. $my_comments = '';
  158. }
  159. $my_questionid=$array_content_id_exe[$i];
  160. $sql = "SELECT question from $TBL_QUESTIONS WHERE id = '$my_questionid'";
  161. $result =Database::query($sql);
  162. $ques_name = Database::result($result,0,"question");
  163. $query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '$my_marks',teacher_comment = '$my_comments' WHERE question_id = '".$my_questionid."' AND exe_id='".$id."'";
  164. Database::query($query);
  165. //Not necessary to update the weight
  166. /*
  167. $qry = 'SELECT sum(marks) as tot FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$id;
  168. $res = Database::query($qry);
  169. $tot = Database::result($res,0,'tot');
  170. //updating also the total weight
  171. $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".intval($tot)."', exe_weighting = '".Database::escape_string($total_weighting)."'
  172. WHERE exe_Id='".$id."'";
  173. Database::query($totquery);
  174. */
  175. //@todo Why we insert this?
  176. $recording_changes = 'INSERT INTO '.$TBL_TRACK_ATTEMPT_RECORDING.' (exe_id, question_id, marks, insert_date, author, teacher_comment) VALUES
  177. ('."'$id','".$my_questionid."','$my_marks','".api_get_utc_datetime()."','".api_get_user_id()."'".',"'.$my_comments.'")';
  178. Database::query($recording_changes);
  179. }
  180. $qry = 'SELECT DISTINCT question_id, marks FROM ' . $TBL_TRACK_ATTEMPT . ' where exe_id = ' . $id . ' GROUP BY question_id';
  181. $res = Database::query($qry);
  182. $tot = 0;
  183. while ($row = Database :: fetch_array($res, 'ASSOC')) {
  184. $tot += $row['marks'];
  185. }
  186. $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '" . intval($tot) . "' WHERE exe_id='" . $id . "'";
  187. Database::query($totquery);
  188. //search items
  189. /*
  190. if (isset($_POST['my_exe_exo_id']) && isset($_POST['student_id'])) {
  191. $sql_lp='SELECT li.id as lp_item_id,li.lp_id,li.item_type,li.path,liv.id AS lp_view_id,liv.user_id,max(liv.view_count) AS view_count FROM '.$TBL_LP_ITEM.' li
  192. INNER JOIN '.$TBL_LP_VIEW.' liv ON li.lp_id=liv.lp_id WHERE li.path="'.Database::escape_string($_POST['my_exe_exo_id']).'" AND li.item_type="quiz" AND user_id="'.Database::escape_string($_POST['student_id']).'" ';
  193. $rs_lp=Database::query($sql_lp);
  194. if (!($rs_lp===false)) {
  195. $row_lp=Database::fetch_array($rs_lp);
  196. //update score in learnig path
  197. $sql_lp_view='UPDATE '.$TBL_LP_ITEM_VIEW.' liv SET score ="'.$tot.'" WHERE liv.lp_item_id="'.(int)$row_lp['lp_item_id'].'" AND liv.lp_view_id="'.(int)$row_lp['lp_view_id'].'" AND liv.view_count="'.(int)$row_lp['view_count'].'" ;';
  198. $rs_lp_view=Database::query($sql_lp_view);
  199. }
  200. }
  201. Database::query($totquery);*/
  202. $subject = get_lang('ExamSheetVCC');
  203. $htmlmessage = '<html>' .
  204. '<head>' .
  205. '<style type="text/css">' .
  206. '<!--' .
  207. '.body{' .
  208. 'font-family: Verdana, Arial, Helvetica, sans-serif;' .
  209. 'font-weight: Normal;' .
  210. 'color: #000000;' .
  211. '}' .
  212. '.style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; color: #006699; }' .
  213. '.style10 {' .
  214. ' font-family: Verdana, Arial, Helvetica, sans-serif;' .
  215. ' font-size: 12px;' .
  216. ' font-weight: bold;' .
  217. '}' .
  218. '.style16 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }' .
  219. '-->' .
  220. '</style>' .
  221. '</head>' .
  222. '<body>' .
  223. '<div>' .
  224. ' <p>' . get_lang('DearStudentEmailIntroduction') . '</p>' .
  225. ' <p class="style10"> ' . get_lang('AttemptVCC') . ' </p>' .
  226. ' <table width="417">' .
  227. ' <tr>' .
  228. ' <td width="229" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">' . get_lang('Question') . '</span></td>' .
  229. ' <td width="469" valign="top" bgcolor="#F3F3F3"><span class="style16">#ques_name#</span></td>' .
  230. ' </tr>' .
  231. ' <tr>' .
  232. ' <td width="229" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">' . get_lang('Exercice') . '</span></td>' .
  233. ' <td width="469" valign="top" bgcolor="#F3F3F3"><span class="style16">#test#</span></td>' .
  234. ' </tr>' .
  235. ' </table>' .
  236. ' <p>' . get_lang('ClickLinkToViewComment') . ' <a href="#url#">#url#</a><br />' .
  237. ' <br />' .
  238. ' ' . get_lang('Regards') . ' </p>' .
  239. ' </div>' .
  240. ' </body>' .
  241. ' </html>';
  242. $message = '<p>' . sprintf(get_lang('AttemptVCCLong'), Security::remove_XSS($test)) . ' <A href="#url#">#url#</A></p><br />';
  243. $mess = str_replace("#test#", Security::remove_XSS($test), $message);
  244. //$message= str_replace("#ques_name#",$ques_name,$mess);
  245. $message = str_replace("#url#", $url, $mess);
  246. $mess = $message;
  247. $headers = " MIME-Version: 1.0 \r\n";
  248. $headers .= "User-Agent: Dokeos/1.6";
  249. $headers .= "Content-Transfer-Encoding: 7bit";
  250. $headers .= 'From: ' . $from_name . ' <' . $from . '>' . "\r\n";
  251. $headers = "From:$from_name\r\nReply-to: $to";
  252. //mail($emailid, $subject, $mess,$headers);
  253. @api_mail_html($emailid, $emailid, $subject, $mess, $from_name, $from);
  254. //Updating LP score here
  255. if (in_array($origin, array ('tracking_course','user_course','correct_exercise_in_lp'))) {
  256. /*
  257. * We do not need this because lp_item_view_id comes to the rescue
  258. *
  259. //Checking if this is the lastest attempt
  260. $sql = "SELECT exe_id FROM $TBL_TRACK_EXERCICES
  261. WHERE exe_user_id = '" . Database :: escape_string($_POST['student_id']) . "' AND exe_cours_id = '" . api_get_course_id() . "' AND orig_lp_id = '$lp_item_id' AND orig_lp_item_id = '$lp_item_view_id' AND session_id = '" . api_get_session_id() . "' AND status = ''
  262. ORDER BY exe_id DESC LIMIT 1 ";
  263. $res_view_count = Database::query($sql);
  264. $res_view_count = Database :: fetch_row($res_view_count);
  265. $my_view_count = intval($res_view_count[0]);
  266. //Update lp_item_view if this attempts is the latest
  267. $sql = "SELECT MAX(view_count) FROM $TBL_LP_ITEM_VIEW
  268. WHERE lp_item_id = '" . (int) $lp_item_view_id . "' AND lp_view_id = (SELECT id from $TBL_LP_VIEW WHERE user_id = '" . (int) $student_id . "' and lp_id='" . (int) $lp_item_id . "')";
  269. $res_max_view_count = Database::query($sql);
  270. $row_max_view_count = Database :: fetch_row($res_max_view_count);
  271. $max_view_count = intval($row_max_view_count[0]);
  272. //Only update if is the last attempt
  273. if ($my_view_count == $_GET['exeid']) {
  274. // update score and total_time from last attempt when you qualify the exercise in Learning path detail
  275. $sql_update_score = "UPDATE $TBL_LP_ITEM_VIEW SET score = '" . intval($tot) . "' WHERE lp_item_id = '" . (int) $lp_item_view_id . "'
  276. AND lp_view_id = (SELECT id from $TBL_LP_VIEW WHERE user_id = '" . (int) $student_id . "' and lp_id='" . (int) $lp_item_id . "') AND view_count = '$max_view_count'";
  277. Database::query($sql_update_score);
  278. }*/
  279. $sql_update_score = "UPDATE $TBL_LP_ITEM_VIEW SET score = '" . intval($tot) . "' WHERE id = " .$lp_item_view_id;
  280. Database::query($sql_update_score);
  281. if ($origin == 'tracking_course') {
  282. //Redirect to the course detail in lp
  283. header('location: exercise.php?course=' . Security :: remove_XSS($_GET['course']));
  284. //header('location: ../mySpace/lp_tracking.php?course=' . api_get_course_id() . '&origin=' . $origin . '&my_lp_id=' . $lp_item_id . '&lp_id=' . $lp_id . '&student_id=' . $student_id.'&extend_attempt=1&from='.Security::remove_XSS($_GET['from']));
  285. exit;
  286. } else {
  287. //Redirect to the reporting
  288. header('location: ../mySpace/myStudents.php?origin=' . $origin . '&student=' . $student_id . '&details=true&course=' . $course_id.'&session_id='.$session_id);
  289. exit;
  290. }
  291. }
  292. }
  293. if (!empty($_GET['gradebook']) && $_GET['gradebook']=='view' ) {
  294. $_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
  295. $gradebook= $_SESSION['gradebook'];
  296. } elseif (empty($_GET['gradebook'])) {
  297. unset($_SESSION['gradebook']);
  298. $gradebook= '';
  299. }
  300. if (!empty($gradebook) && $gradebook=='view') {
  301. $interbreadcrumb[] = array (
  302. 'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
  303. 'name' => get_lang('ToolGradebook')
  304. );
  305. }
  306. if ($show != 'result') {
  307. $nameTools = get_lang('Exercices');
  308. } else {
  309. if ($is_allowedToEdit || $is_tutor) {
  310. $nameTools = get_lang('StudentScore');
  311. $interbreadcrumb[] = array (
  312. "url" => "exercice.php?gradebook=$gradebook",
  313. "name" => get_lang('Exercices')
  314. );
  315. } else {
  316. $nameTools = get_lang('YourScore');
  317. $interbreadcrumb[] = array (
  318. "url" => "exercice.php?gradebook=$gradebook",
  319. "name" => get_lang('Exercices')
  320. );
  321. }
  322. }
  323. // need functions of statsutils lib to display previous exercices scores
  324. require_once (api_get_path(LIBRARY_PATH) . 'statsUtils.lib.inc.php');
  325. if ($is_allowedToEdit && !empty ($choice) && $choice == 'exportqti2') {
  326. require_once 'export/qti2/qti2_export.php';
  327. $export = export_exercise($exerciseId, true);
  328. require_once api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php';
  329. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  330. $temp_dir_short = uniqid();
  331. $temp_zip_dir = $archive_path . "/" . $temp_dir_short;
  332. if (!is_dir($temp_zip_dir))
  333. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  334. $temp_zip_file = $temp_zip_dir . "/" . md5(time()) . ".zip";
  335. $temp_xml_file = $temp_zip_dir . "/qti2export_" . $exerciseId . '.xml';
  336. file_put_contents($temp_xml_file, $export);
  337. $zip_folder = new PclZip($temp_zip_file);
  338. $zip_folder->add($temp_xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
  339. $name = 'qti2_export_' . $exerciseId . '.zip';
  340. //DocumentManager::string_send_for_download($export,true,'qti2export_'.$exerciseId.'.xml');
  341. DocumentManager :: file_send_for_download($temp_zip_file, true, $name);
  342. unlink($temp_zip_file);
  343. unlink($temp_xml_file);
  344. rmdir($temp_zip_dir);
  345. exit (); //otherwise following clicks may become buggy
  346. }
  347. if (!empty ($_POST['export_user_fields'])) {
  348. switch ($_POST['export_user_fields']) {
  349. case 'export_user_fields' :
  350. $_SESSION['export_user_fields'] = true;
  351. break;
  352. case 'do_not_export_user_fields' :
  353. default :
  354. $_SESSION['export_user_fields'] = false;
  355. break;
  356. }
  357. }
  358. if (!empty ($_POST['export_report']) && $_POST['export_report'] == 'export_report') {
  359. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
  360. $user_id = null;
  361. if (empty ($_SESSION['export_user_fields']))
  362. $_SESSION['export_user_fields'] = false;
  363. if (!$is_allowedToEdit and !$is_tutor) {
  364. $user_id = api_get_user_id();
  365. }
  366. require_once ('exercise_result.class.php');
  367. switch ($_POST['export_format']) {
  368. case 'xls' :
  369. $export = new ExerciseResult();
  370. $export->exportCompleteReportXLS($documentPath, $user_id, $_SESSION['export_user_fields'], $_POST['export_filter']);
  371. exit;
  372. break;
  373. case 'csv' :
  374. default :
  375. $export = new ExerciseResult();
  376. $export->exportCompleteReportCSV($documentPath, $user_id, $_SESSION['export_user_fields'], $_POST['export_filter']);
  377. exit;
  378. break;
  379. }
  380. } else {
  381. api_not_allowed(true);
  382. }
  383. }
  384. if ($origin != 'learnpath') {
  385. //so we are not in learnpath tool
  386. Display :: display_header($nameTools, "Exercise");
  387. if (isset ($_GET['message'])) {
  388. if (in_array($_GET['message'], array (
  389. 'ExerciseEdited'
  390. ))) {
  391. Display :: display_confirmation_message(get_lang($_GET['message']));
  392. }
  393. }
  394. } else {
  395. echo '<link rel="stylesheet" type="text/css" href="' . api_get_path(WEB_CODE_PATH) . 'css/default.css"/>';
  396. }
  397. event_access_tool(TOOL_QUIZ);
  398. // Tool introduction
  399. Display :: display_introduction_section(TOOL_QUIZ);
  400. // selects $limitExPage exercises at the same time
  401. $from = $page * $limitExPage;
  402. $sql = "SELECT count(id) FROM $TBL_EXERCICES";
  403. $res = Database::query($sql);
  404. list ($nbrexerc) = Database :: fetch_array($res);
  405. HotPotGCt($documentPath, 1, $_user['user_id']);
  406. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  407. // only for administrator
  408. if ($is_allowedToEdit) {
  409. if (!empty ($choice)) {
  410. // construction of Exercise
  411. $objExerciseTmp = new Exercise();
  412. $check = Security::check_token('get');
  413. if ($objExerciseTmp->read($exerciseId)) {
  414. if ($check) {
  415. switch ($choice) {
  416. case 'delete' : // deletes an exercise
  417. $objExerciseTmp->delete();
  418. //delete link of exercise of gradebook tool
  419. $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="1" AND gl.ref_id="' . $exerciseId . '";';
  420. $result = Database::query($sql);
  421. $row = Database :: fetch_array($result, 'ASSOC');
  422. //see
  423. if (!empty($row['id'])) {
  424. $link = LinkFactory :: load($row['id']);
  425. if ($link[0] != null) {
  426. $link[0]->delete();
  427. }
  428. }
  429. Display :: display_confirmation_message(get_lang('ExerciseDeleted'));
  430. break;
  431. case 'enable' : // enables an exercise
  432. $objExerciseTmp->enable();
  433. $objExerciseTmp->save();
  434. // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
  435. Display :: display_confirmation_message(get_lang('VisibilityChanged'));
  436. break;
  437. case 'disable' : // disables an exercise
  438. $objExerciseTmp->disable();
  439. $objExerciseTmp->save();
  440. Display :: display_confirmation_message(get_lang('VisibilityChanged'));
  441. break;
  442. case 'disable_results' : //disable the results for the learners
  443. $objExerciseTmp->disable_results();
  444. $objExerciseTmp->save();
  445. Display :: display_confirmation_message(get_lang('ResultsDisabled'));
  446. break;
  447. case 'enable_results' : //disable the results for the learners
  448. $objExerciseTmp->enable_results();
  449. $objExerciseTmp->save();
  450. Display :: display_confirmation_message(get_lang('ResultsEnabled'));
  451. break;
  452. case 'clean_results' : //clean student results
  453. $quantity_results_deleted= $objExerciseTmp->clean_results();
  454. Display :: display_confirmation_message(sprintf(get_lang('XResultsCleaned'),$quantity_results_deleted));
  455. break;
  456. case 'copy_exercise' : //copy an exercise
  457. $objExerciseTmp->copy_exercise();
  458. Display :: display_confirmation_message(get_lang('ExerciseCopied'));
  459. break;
  460. }
  461. }
  462. }
  463. // destruction of Exercise
  464. unset ($objExerciseTmp);
  465. Security::clear_token();
  466. }
  467. if (!empty ($hpchoice)) {
  468. switch ($hpchoice) {
  469. case 'delete' : // deletes an exercise
  470. $imgparams = array ();
  471. $imgcount = 0;
  472. GetImgParams($file, $documentPath, $imgparams, $imgcount);
  473. $fld = GetFolderName($file);
  474. for ($i = 0; $i < $imgcount; $i++) {
  475. my_delete($documentPath . $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
  476. update_db_info("delete", $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
  477. }
  478. if (my_delete($documentPath . $file)) {
  479. update_db_info("delete", $file);
  480. }
  481. my_delete($documentPath . $uploadPath . "/" . $fld . "/");
  482. break;
  483. case 'enable' : // enables an exercise
  484. $newVisibilityStatus = "1"; //"visible"
  485. $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='" . Database :: escape_string($file) . "'";
  486. $res = Database::query($query);
  487. $row = Database :: fetch_array($res, 'ASSOC');
  488. api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'visible', $_user['user_id']);
  489. //$dialogBox = get_lang('ViMod');
  490. break;
  491. case 'disable' : // disables an exercise
  492. $newVisibilityStatus = "0"; //"invisible"
  493. $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='" . Database :: escape_string($file) . "'";
  494. $res = Database::query($query);
  495. $row = Database :: fetch_array($res, 'ASSOC');
  496. api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'invisible', $_user['user_id']);
  497. break;
  498. default :
  499. break;
  500. }
  501. }
  502. if ($show == 'test') {
  503. $sql = "SELECT id,title,type,active,description, results_disabled FROM $TBL_EXERCICES WHERE active<>'-1' ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
  504. $result = Database::query($sql);
  505. }
  506. } elseif ($show == 'test') { // only for students
  507. $sql = "SELECT id,title,type,description, results_disabled FROM $TBL_EXERCICES WHERE active='1' ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
  508. $result = Database::query($sql);
  509. }
  510. // the actions
  511. echo '<div class="actions">';
  512. // display the next and previous link if needed
  513. $from = $page * $limitExPage;
  514. $sql = "SELECT count(id) FROM $TBL_EXERCICES";
  515. $res = Database::query($sql);
  516. list ($nbrexerc) = Database :: fetch_array($res);
  517. HotPotGCt($documentPath, 1, $_user['user_id']);
  518. //condition for the session
  519. $session_id = api_get_session_id();
  520. $condition_session = api_get_session_condition($session_id,true,true);
  521. // only for administrator
  522. if ($is_allowedToEdit) {
  523. if ($show == 'test') {
  524. $sql = "SELECT id, title, type, active, description, results_disabled, session_id, start_time, end_time, random,max_attempt FROM $TBL_EXERCICES WHERE active<>'-1' $condition_session ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
  525. $result = Database::query($sql);
  526. }
  527. } elseif ($show == 'test') { // only for students
  528. $sql = "SELECT id, title, type, description, results_disabled, session_id, start_time, end_time FROM $TBL_EXERCICES WHERE active='1' $condition_session ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
  529. $result = Database::query($sql);
  530. }
  531. if ($show == 'test') {
  532. $nbrExercises = Database :: num_rows($result);
  533. //get HotPotatoes files (active and inactive)
  534. $res = Database::query("SELECT * FROM $TBL_DOCUMENT WHERE path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'");
  535. $nbrTests = Database :: num_rows($res);
  536. $res = Database::query("SELECT * FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  537. WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "'
  538. AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'
  539. AND ip.visibility='1'");
  540. $nbrActiveTests = Database :: num_rows($res);
  541. if ($is_allowedToEdit) {
  542. //if user is allowed to edit, also show hidden HP tests
  543. $nbrHpTests = $nbrTests;
  544. } else {
  545. $nbrHpTests = $nbrActiveTests;
  546. }
  547. $nbrNextTests = $nbrexerc - $nbrHpTests - (($page * $limitExPage));
  548. echo '<span style="float:right">';
  549. //show pages navigation link for previous page
  550. if ($page) {
  551. echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&amp;page=" . ($page -1) . "\">" . Display :: return_icon('previous.gif') . get_lang("PreviousPage") . "</a> | ";
  552. }
  553. elseif ($nbrExercises + $nbrNextTests > $limitExPage) {
  554. echo Display :: return_icon('previous.gif') . get_lang('PreviousPage') . " | ";
  555. }
  556. //show pages navigation link for previous page
  557. if ($nbrExercises + $nbrNextTests > $limitExPage) {
  558. echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&amp;page=" . ($page +1) . "\">" . get_lang("NextPage") . Display :: return_icon('next.gif') . "</a>";
  559. }
  560. elseif ($page) {
  561. echo get_lang("NextPage") . Display :: return_icon('next.gif');
  562. }
  563. echo '</span>';
  564. }
  565. if (($is_allowedToEdit) and ($origin != 'learnpath')) {
  566. if ($_GET['show'] != 'result') {
  567. echo '<a href="exercise_admin.php?' . api_get_cidreq() . '">' . Display :: return_icon('new_test.gif', get_lang('NewEx')) . get_lang('NewEx') . '</a>';
  568. echo '<a href="question_create.php?' . api_get_cidreq() . '">' . Display :: return_icon('question_add.gif', get_lang('AddQuestionToExercise')) . get_lang('AddQuestionToExercise') . '</a>';
  569. echo '<a href="hotpotatoes.php?' . api_get_cidreq() . '">' . Display :: return_icon('hotpotatoes_s.png', get_lang('ImportHotPotatoesQuiz')) . get_lang('ImportHotPotatoesQuiz') . '</a>';
  570. // link to import qti2 ...
  571. echo '<a href="qti2.php?' . api_get_cidreq() . '">' . Display :: return_icon('import_db.png', get_lang('ImportQtiQuiz')) . get_lang('ImportQtiQuiz') . '</a>';
  572. echo '<a href="exercice.php?' . api_get_cidreq() . '&show=result">' . Display :: return_icon('show_test_results.gif', get_lang('Results')) . get_lang('Results') . '</a>';
  573. }
  574. // the actions for the statistics
  575. if ($show == 'result') {
  576. // the form
  577. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
  578. if ($_SESSION['export_user_fields']) {
  579. $alt = get_lang('ExportWithUserFields');
  580. $extra_user_fields = '<input type="hidden" name="export_user_fields" value="export_user_fields">';
  581. } else {
  582. $alt = get_lang('ExportWithoutUserFields');
  583. $extra_user_fields = '<input type="hidden" name="export_user_fields" value="do_not_export_user_fields">';
  584. }
  585. echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=test') . '">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList')) . get_lang('GoBackToQuestionList') . '</a>';
  586. echo '<a href="javascript: void(0);" onclick="javascript: document.form1a.submit();">'.Display::return_icon('csv.gif',get_lang('ExportAsCSV')).get_lang('ExportAsCSV').'</a>';
  587. echo '<a href="javascript: void(0);" onclick="javascript: document.form1b.submit();">' . Display :: return_icon('excel.gif', get_lang('ExportAsXLS')) . get_lang('ExportAsXLS') . '</a>';
  588. echo '<form id="form1a" name="form1a" method="post" action="' . api_get_self() . '?show=' . Security :: remove_XSS($_GET['show']) . '" style="display:inline">';
  589. echo '<input type="hidden" name="export_report" value="export_report">';
  590. echo '<input type="hidden" name="export_format" value="csv">';
  591. if ($_GET['filter'] == '1' or !isset ($_GET['filter']) or $_GET['filter'] == 0 ) {
  592. $filter = 1;
  593. } else {
  594. $filter = 2;
  595. }
  596. echo '<input type="hidden" name="export_filter" value="'.(empty($filter)?1:intval($filter)).'">';
  597. echo '</form>';
  598. echo '<form id="form1b" name="form1b" method="post" action="' . api_get_self() . '?show=' . Security :: remove_XSS($_GET['show']) . '" style="display:inline">';
  599. echo '<input type="hidden" name="export_report" value="export_report">';
  600. echo '<input type="hidden" name="export_filter" value="'.(empty($filter)?1:intval($filter)).'">';
  601. echo '<input type="hidden" name="export_format" value="xls">';
  602. echo '</form>';
  603. }
  604. }
  605. } else {
  606. //the student view
  607. if ($show == 'result') {
  608. echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=test') . '">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList')) . get_lang('GoBackToQuestionList') . '</a>';
  609. } else {
  610. echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=result') . '">' . Display :: return_icon('show_test_results.gif', get_lang('Results')) . get_lang('Results') . '</a>';
  611. }
  612. }
  613. if ($_configuration['tracking_enabled']) {
  614. if ($show == 'result') {
  615. if (api_is_allowed_to_edit(null,true)) {
  616. if (!$_GET['filter']) {
  617. $filter_by_not_revised = true;
  618. $filter = 1;
  619. } else {
  620. $filter=Security::remove_XSS($_GET['filter']);
  621. }
  622. $filter = (int) $_GET['filter'];
  623. switch ($filter) {
  624. case 1 :
  625. $filter_by_not_revised = true;
  626. break;
  627. case 2 :
  628. $filter_by_revised = true;
  629. break;
  630. default :
  631. null;
  632. }
  633. if ($_GET['filter'] == '1' or !isset ($_GET['filter']) or $_GET['filter'] == 0 ) {
  634. $view_result = '<a href="' . api_get_self() . '?cidReq=' . api_get_course_id() . '&show=result&filter=2&gradebook='.$gradebook.'" >'.Display :: return_icon('check.gif', get_lang('ShowCorrectedOnly')).get_lang('ShowCorrectedOnly').'</a>';
  635. } else {
  636. $view_result = '<a href="' .api_get_self() . '?cidReq=' . api_get_course_id() . '&show=result&filter=1&gradebook='.$gradebook.'" >'.Display :: return_icon('un_check.gif', get_lang('ShowUnCorrectedOnly')).get_lang('ShowUnCorrectedOnly').'</a>';
  637. }
  638. echo $view_result;
  639. }
  640. }
  641. }
  642. echo '</div>'; // closing the actions div
  643. if ($show == 'test') {
  644. ?>
  645. <table class="data_table">
  646. <?php
  647. if (($is_allowedToEdit) and ($origin != 'learnpath')) {
  648. ?>
  649. <tr class="row_odd">
  650. <th colspan="3"><?php echo get_lang('ExerciseName');?></th>
  651. <th><?php echo get_lang('QuantityQuestions');?></th>
  652. <th><?php echo get_lang('Modify');?></th>
  653. </tr>
  654. <?php
  655. } else {
  656. //student only
  657. ?> <tr>
  658. <th colspan="2"><?php echo get_lang('ExerciseName');?></th>
  659. <th><?php echo get_lang('QuantityQuestions');?></th>
  660. <th><?php echo get_lang('State');?></th>
  661. </tr>
  662. <?php
  663. }
  664. // show message if no HP test to show
  665. if (!($nbrExercises + $nbrHpTests)) {
  666. ?>
  667. <tr>
  668. <td <?php echo ($is_allowedToEdit?'colspan="6"':'colspan="5"'); ?>><?php echo get_lang("NoEx"); ?></td>
  669. </tr>
  670. <?php
  671. }
  672. $i = 1;
  673. /*
  674. * Listing exercises
  675. */
  676. if ($origin != 'learnpath') {
  677. //avoid sending empty parameters
  678. $myorigin = (empty ($origin) ? '' : '&origin=' . $origin);
  679. $mylpid = (empty ($learnpath_id) ? '' : '&learnpath_id=' . $learnpath_id);
  680. $mylpitemid = (empty ($learnpath_item_id) ? '' : '&learnpath_item_id=' . $learnpath_item_id);
  681. $token = Security::get_token();
  682. while ($row = Database :: fetch_array($result,'ASSOC')) {
  683. //validacion when belongs to a session
  684. $session_img = api_get_session_image($row['session_id'], $_user['status']);
  685. $time_limits = false;
  686. if ($row['start_time'] != '0000-00-00 00:00:00' && $row['end_time'] != '0000-00-00 00:00:00') {
  687. $time_limits = true;
  688. }
  689. if ($time_limits) {
  690. // check if start time
  691. $start_time = api_strtotime($row['start_time'],'UTC');
  692. $end_time = api_strtotime($row['end_time'], 'UTC');
  693. $now = time();
  694. $is_actived_time = false;
  695. if ($now > $start_time && $end_time > $now ) {
  696. $is_actived_time = true;
  697. }
  698. }
  699. if ($i % 2 == 0)
  700. $s_class = "row_odd";
  701. else
  702. $s_class = "row_even";
  703. // prof only
  704. if ($is_allowedToEdit) {
  705. echo '<tr class="' . $s_class . '">';
  706. echo '<td width="30" align="left">'.Display::return_icon('quiz.gif', get_lang('Exercice')) .'</td>';
  707. echo '<td width="15" valign="left">'.($i+($page*$limitExPage)).'.'.'</td>';
  708. //Showing exercise title
  709. $row['title']=text_filter($row['title']);
  710. echo '<td>';
  711. $class_invisible = '';
  712. if (!$row['active']) {
  713. $class_invisible = 'class="invisible"';
  714. }
  715. echo '<a href="exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&amp;exerciseId='.$row['id'].'" '.$class_invisible.'>';
  716. echo Security::remove_XSS($row['title']);
  717. echo '</a>';
  718. echo $session_img;
  719. echo '</td>';
  720. echo '<td align="center">';
  721. $exid = $row['id'];
  722. //count number exercice - teacher
  723. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '" . Database :: escape_string($exid) . "'";
  724. $sqlresult = Database::query($sqlquery);
  725. $rowi = Database :: result($sqlresult, 0);
  726. //useless query
  727. /*$sql_random_query = 'SELECT type,random,active,results_disabled,max_attempt FROM ' . $TBL_EXERCICES . ' WHERE id="' . Database :: escape_string($exid) . '" ';
  728. $rs_random = Database::query($sql_random_query);
  729. $row_random = Database :: fetch_array($rs_random);*/
  730. $random_label = '';
  731. if ($row['random'] > 0) {
  732. $random_label = ' ('.get_lang('Random').') ';
  733. echo $row['random'] . ' ' . api_strtolower(get_lang(($row['random'] > 1 ? 'Questions' : 'Question'))) .$random_label. '</td>';
  734. } else {
  735. echo $rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question'))) . '</td>';
  736. }
  737. echo '<td align="center">';
  738. if ($session_id == $row['session_id']) {
  739. ?>
  740. <a href="admin.php?<?php echo api_get_cidreq()?>&amp;exerciseId=<?php echo $row['id']; ?>"><img src="../img/wizard_small.gif" border="0" title="<?php echo api_htmlentities(get_lang('Edit'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('Edit'),ENT_QUOTES,$charset); ?>" /></a>
  741. <a href="exercice.php?<?php echo api_get_cidreq()?>&amp;choice=copy_exercise&amp;sec_token=<?php echo $token; ?>&amp;exerciseId=<?php echo $row['id']; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToCopy'),ENT_QUOTES,$charset)); echo " ".addslashes($row['title']); echo "?"; ?>')) return false;"><img width="16" src="../img/cd.gif" border="0" title="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" /></a>
  742. <a href="exercice.php?<?php echo api_get_cidreq()?>&amp;choice=clean_results&amp;sec_token=<?php echo $token; ?>&amp;exerciseId=<?php echo $row['id']; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToDeleteResults'),ENT_QUOTES,$charset)); echo " ".addslashes($row['title']); echo "?"; ?>')) return false;" ><img width="16" src="../img/clean_group.gif" border="0" title="<?php echo api_htmlentities(get_lang('CleanStudentResults'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('CleanStudentResults'),ENT_QUOTES,$charset); ?>" /></a>
  743. <a href="exercice.php?<?php echo api_get_cidreq() ?>&choice=delete&sec_token=<?php echo$token; ?>&amp;exerciseId=<?php echo $row['id']; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToDelete'),ENT_QUOTES,$charset)); echo " ".addslashes($row['title']); echo "?"; ?>')) return false;"> <img src="../img/delete.gif" border="0" title="<?php echo get_lang('Delete'); ?>" alt="<?php echo api_htmlentities(get_lang('Delete'),ENT_QUOTES,$charset); ?>" /></a>
  744. <?php
  745. //if active
  746. if ($row['active']) {
  747. ?>
  748. <a href="exercice.php?<?php echo api_get_cidreq() ?>&choice=disable&sec_token=<?php echo$token; ?>&amp;page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/visible.gif" border="0" title="<?php echo get_lang('Deactivate'); ?>" alt="<?php echo api_htmlentities(get_lang('Deactivate'),ENT_QUOTES,$charset); ?>" /></a>
  749. <?php
  750. } else { // else if not active
  751. ?>
  752. <a href="exercice.php?<?php echo api_get_cidreq() ?>&choice=enable&sec_token=<?php echo$token; ?>&amp;page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/invisible.gif" border="0" title="<?php echo get_lang('Activate'); ?>" alt="<?php echo api_htmlentities(get_lang('Activate'),ENT_QUOTES,$charset); ?>" /></a>
  753. <?php
  754. }
  755. // Export qti ...
  756. echo '<a href="exercice.php?choice=exportqti2&exerciseId='.$row['id'].'"><img src="../img/export_db.png" border="0" title="IMS/QTI" /></a>';
  757. } else { // not session resource
  758. echo Display::return_icon('wizard_gray_small.gif', get_lang('ExerciseEditionNotAvailableInSession'), array('title'=>get_lang('ExerciseEditionNotAvailableInSession')));
  759. ?>
  760. <a href="exercice.php?<?php echo api_get_cidreq()?>&amp;choice=copy_exercise&amp;sec_token=<?php echo $token; ?>&amp;exerciseId=<?php echo $row['id']; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToCopy'),ENT_QUOTES,$charset)); echo " ".addslashes($row['title']); echo "?"; ?>')) return false;"><img width="16" src="../img/cd.gif" border="0" title="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" /></a>
  761. <?php
  762. }
  763. echo "</td>";
  764. echo "</tr>";
  765. } else { // student only
  766. ?>
  767. <tr>
  768. <td><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
  769. <?php $row['title']=text_filter($row['title']);?>
  770. <td>
  771. <?php
  772. // if time is actived show link to exercise
  773. if ($time_limits) {
  774. if ($is_actived_time) {
  775. echo '<a href="exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$myllpitemid.'&exerciseId='.$row['id'].'">'.$row['title'].'</a>';
  776. } else {
  777. echo $row['title'];
  778. }
  779. } else {
  780. echo '<a href="exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$myllpitemid.'&exerciseId='.$row['id'].'">'.$row['title'].'</a>';
  781. }
  782. echo '</td><td align="center">';
  783. $exid = $row['id'];
  784. //count number exercise questions
  785. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '" . Database :: escape_string($exid) . "'";
  786. $sqlresult = Database::query($sqlquery);
  787. $rowi = Database :: result($sqlresult, 0);
  788. //count number random exercice
  789. $sql_random_query = 'SELECT type,random,active,results_disabled,max_attempt FROM ' . $TBL_EXERCICES . ' WHERE id="' . Database :: escape_string($exid) . '" ';
  790. $rs_random = Database::query($sql_random_query);
  791. $row_random = Database :: fetch_array($rs_random);
  792. if ($row_random['random'] > 0) {
  793. echo $row_random['random'] . ' ' . api_strtolower(get_lang(($row_random['random'] > 1 ? 'Questions' : 'Question')));
  794. } else {
  795. //show results student
  796. echo $rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question')));
  797. }
  798. echo '</td>';
  799. echo '<td align="center">';
  800. $eid = $row['id'];
  801. $uid = api_get_user_id();
  802. //this query might be improved later on by ordering by the new "tms" field rather than by exe_id
  803. $qry = "SELECT * FROM $TBL_TRACK_EXERCICES
  804. WHERE exe_exo_id = '" . Database :: escape_string($eid) . "' and exe_user_id = '" . Database :: escape_string($uid) . "' AND exe_cours_id = '" . api_get_course_id() . "' AND status <>'incomplete' AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND session_id = '" . api_get_session_id() . "'
  805. ORDER BY exe_id DESC";
  806. $qryres = Database::query($qry);
  807. $num = Database :: num_rows($qryres);
  808. //hide the results
  809. $my_result_disabled = $row['results_disabled'];
  810. if ($time_limits) {
  811. if ($my_result_disabled == 0) {
  812. if ($num > 0) {
  813. echo sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_get_local_time($row['start_time']), api_get_local_time($row['end_time']));
  814. } else {
  815. echo get_lang('NotAttempted');
  816. }
  817. } else {
  818. echo get_lang('CantShowResults');
  819. }
  820. } else {
  821. if ($my_result_disabled == 0) {
  822. if ($num > 0) {
  823. $row = Database :: fetch_array($qryres);
  824. $percentage = 0;
  825. if ($row['exe_weighting'] != 0) {
  826. $percentage = ($row['exe_result'] / $row['exe_weighting']) * 100;
  827. }
  828. echo get_lang('Attempted') . ' (' . get_lang('Score') . ': ';
  829. printf("%1.2f\n", $percentage);
  830. echo " %)";
  831. } else {
  832. //echo get_lang('WillBeActivated' .' '. $row['start_time']);
  833. echo get_lang('NotAttempted');
  834. }
  835. } else {
  836. echo get_lang('CantShowResults');
  837. }
  838. }
  839. echo '</td></tr>';
  840. /*} else {
  841. echo get_lang('NotAttempted');
  842. }*/
  843. }
  844. // skips the last exercise, that is only used to know if we have or not to create a link "Next page"
  845. if ($i == $limitExPage) {
  846. break;
  847. }
  848. $i++;
  849. } // end while()
  850. $ind = $i;
  851. if (($from + $limitExPage -1) > $nbrexerc) {
  852. if ($from > $nbrexerc) {
  853. $from = $from - $nbrexerc;
  854. $to = $limitExPage;
  855. } else {
  856. $to = $limitExPage - ($nbrexerc - $from);
  857. $from = 0;
  858. }
  859. } else {
  860. $to = $limitExPage;
  861. }
  862. if ($is_allowedToEdit) {
  863. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  864. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  865. WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND (d.path LIKE '%htm%')
  866. AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' LIMIT " . (int) $from . "," . (int) $to; // only .htm or .html files listed
  867. } else {
  868. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  869. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  870. WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND (d.path LIKE '%htm%')
  871. AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' AND ip.visibility='1' LIMIT " . (int) $from . "," . (int) $to;
  872. }
  873. $result = Database::query($sql);
  874. while ($row = Database :: fetch_array($result, 'ASSOC')) {
  875. $attribute['path'][] = $row['path'];
  876. $attribute['visibility'][] = $row['visibility'];
  877. $attribute['comment'][] = $row['comment'];
  878. }
  879. $nbrActiveTests = 0;
  880. if (is_array($attribute['path'])) {
  881. while (list ($key, $path) = each($attribute['path'])) {
  882. list ($a, $vis) = each($attribute['visibility']);
  883. if (strcmp($vis, "1") == 0) {
  884. $active = 1;
  885. } else {
  886. $active = 0;
  887. }
  888. echo "<tr>\n";
  889. $title = GetQuizName($path, $documentPath);
  890. if ($title == '') {
  891. $title = basename($path);
  892. }
  893. // prof only
  894. if ($is_allowedToEdit) {
  895. echo ' <tr>'.
  896. ' <td><img src="../img/hotpotatoes_s.png" alt="HotPotatoes" /></td>'.
  897. ' <td>'.($ind+($page*$limitExPage)).'.</td>'.
  898. ' <td><a href="showinframes.php?file='.$path.'&cid='.$_course['official_code'].'&uid='.$_user['user_id'].'"'.(!$active?'class="invisible"':'').'>'.$title.'</a></td>'.
  899. ' <td align="center">-</td>'.
  900. ' <td align="center">' .
  901. ' <a href="adminhp.php?'.api_get_cidreq().'&hotpotatoesName='.$path.'">'.
  902. ' <img src="../img/edit.gif" border="0" title="'.get_lang('Modify').'" alt="'.api_htmlentities(get_lang('Modify'),ENT_QUOTES,$charset).'" />' .
  903. ' </a>'.
  904. ' <a href="'.$exercicePath.'?'.api_get_cidreq().'&amp;hpchoice=delete&amp;file='.$path.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('AreYouSure'),ENT_QUOTES,$charset).$title."?").'\')) return false;"><img src="../img/delete.gif" border="0" title="'.get_lang('Delete').'" alt="'.api_htmlentities(get_lang('Delete'),ENT_QUOTES,$charset).'" /></a>';
  905. // if active
  906. if ($active) {
  907. $nbrActiveTests = $nbrActiveTests +1;
  908. echo ' <a href="'.$exercicePath.'?'.api_get_cidreq().'&hpchoice=disable&amp;page='.$page.'&amp;file='.$path.'"><img src="../img/visible.gif" border="0" title="'.get_lang('Deactivate').'" alt="'.api_htmlentities(get_lang('Deactivate'),ENT_QUOTES,$charset).'" /></a>';
  909. } else { // else if not active
  910. echo ' <a href="'.$exercicePath.'?'.api_get_cidreq().'&hpchoice=enable&amp;page='.$page.'&amp;file='.$path.'"><img src="../img/invisible.gif" border="0" title="'.get_lang('Activate').'" alt="'.api_htmlentities(get_lang('Activate'),ENT_QUOTES,$charset).'" /></a>';
  911. }
  912. echo '<img src="../img/lp_quiz_na.gif" border="0" title="'.get_lang('NotMarkActivity').'" alt="" />';
  913. echo '</td>';
  914. } else { // student only
  915. if ($active == 1) {
  916. $nbrActiveTests = $nbrActiveTests +1;
  917. echo ' <tr>'.
  918. ' <td>'.($ind+($page*$limitExPage)).'.<!--<img src="../img/jqz.jpg" alt="HotPotatoes" />--></td>' .
  919. ' <td><a href="showinframes.php?'.api_get_cidreq().'&amp;file='.$path.'&amp;cid='.$_course['official_code'].'&amp;uid='.$_user['user_id'].'"'.(!$active?'class="invisible"':'').'">'.$title.'</a></td>'.
  920. ' <td style="text-align: center;">-</td><td style="text-align: center;">-</td>'.
  921. ' </tr>';
  922. }
  923. }
  924. if ($ind == $limitExPage) {
  925. break;
  926. }
  927. if ($is_allowedToEdit) {
  928. $ind++;
  929. } else {
  930. if ($active == 1) {
  931. $ind++;
  932. }
  933. }
  934. }
  935. }
  936. } //end if ($origin != 'learnpath') {
  937. echo '</table>';
  938. }
  939. /* Exercise Results (uses tracking tool) */
  940. // if tracking is enabled
  941. if ($_configuration['tracking_enabled'] && ($show == 'result')) {
  942. $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
  943. if ($is_allowedToEdit || $is_tutor) {
  944. $user_id_and = '';
  945. if (!empty ($_POST['filter_by_user'])) {
  946. if ($_POST['filter_by_user'] == 'all') {
  947. $user_id_and = " AND user_id like '%'";
  948. } else {
  949. $user_id_and = " AND user_id = '" . Database :: escape_string((int) $_POST['filter_by_user']) . "' ";
  950. }
  951. }
  952. if ($_GET['gradebook'] == 'view') {
  953. $exercise_where_query = 'te.exe_exo_id =ce.id AND ';
  954. }
  955. //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
  956. /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", ce.title as extitle, te.exe_result as exresult ,
  957. te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as exstart, steps_counter as exstep,cuser.user_id as excruid,te.exe_duration as exduration
  958. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  959. WHERE user.user_id=cuser.user_id AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
  960. $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0
  961. AND cuser.course_code=te.exe_cours_id ORDER BY userpart2, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/
  962. $sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", ce.title as extitle, te.exe_result as exresult , te.exe_weighting as exweight,
  963. te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as exstart, steps_counter as exstep, exe_user_id as excruid,te.exe_duration as exduration
  964. FROM $TBL_EXERCICES AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id)
  965. WHERE te.status != 'incomplete' AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0";
  966. $hpsql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", tth.exe_name, tth.exe_result , tth.exe_weighting, tth.exe_date
  967. FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
  968. WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . Database :: escape_string($_cid) . " $user_id_and '
  969. ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
  970. } else {
  971. // get only this user's results
  972. $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';
  973. /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", ce.title as extitle, te.exe_result as exresult, " .
  974. "te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " .
  975. "te.start_date as exstart, steps_counter as exstep, cuser.user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled
  976. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  977. WHERE user.user_id=cuser.user_id AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id
  978. AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
  979. AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." $user_id_and $session_id_and AND ce.active <>-1 AND" .
  980. " orig_lp_id = 0 AND orig_lp_item_id = 0 AND cuser.course_code=te.exe_cours_id ORDER BY userpart2, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/
  981. $sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", ce.title as extitle, te.exe_result as exresult, " .
  982. "te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " .
  983. "te.start_date as exstart, steps_counter as exstep, exe_user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled
  984. FROM $TBL_EXERCICES AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id)
  985. WHERE te.status != 'incomplete' AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' $user_id_and $session_id_and AND ce.active <>-1 AND" .
  986. " orig_lp_id = 0 AND orig_lp_item_id = 0 ORDER BY userpart2, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";
  987. $hpsql = "SELECT '',exe_name, exe_result , exe_weighting, exe_date
  988. FROM $TBL_TRACK_HOTPOTATOES
  989. WHERE exe_user_id = '" . $_user['user_id'] . "' AND exe_cours_id = '" . Database :: escape_string($_cid) . "'
  990. ORDER BY exe_cours_id ASC, exe_date DESC";
  991. }
  992. $results = array();
  993. $resx = Database::query($sql);
  994. while ($rowx = Database::fetch_array($resx,'ASSOC')) {
  995. $results[] = $rowx;
  996. }
  997. $hpresults = getManyResultsXCol($hpsql, 5);
  998. $has_test_results = false;
  999. $list_info = array();
  1000. // Print test results.
  1001. $lang_nostartdate = get_lang('NoStartDate') . ' / ';
  1002. if (is_array($results)) {
  1003. $has_test_results = true;
  1004. $users_array_id = array ();
  1005. if ($_GET['gradebook'] == 'view') {
  1006. $filter_by_no_revised = true;
  1007. $from_gradebook = true;
  1008. }
  1009. $sizeof = sizeof($results);
  1010. $user_list_id = array ();
  1011. $user_last_name = '';
  1012. $user_first_name = '';
  1013. $quiz_name_list = '';
  1014. $duration_list = '';
  1015. $date_list = '';
  1016. $result_list = '';
  1017. $more_details_list = '';
  1018. for ($i = 0; $i < $sizeof; $i++) {
  1019. $revised = false;
  1020. $sql_exe = 'SELECT exe_id FROM ' . $TBL_TRACK_ATTEMPT_RECORDING . '
  1021. WHERE author != ' . "''" . ' AND exe_id = ' . "'" . Database :: escape_string($results[$i]['exid']) . "'" . ' LIMIT 1';
  1022. $query = Database::query($sql_exe);
  1023. if (Database :: num_rows($query) > 0) {
  1024. $revised = true;
  1025. }
  1026. if ($filter_by_not_revised && $revised) {
  1027. continue;
  1028. }
  1029. if ($filter_by_revised && !$revised) {
  1030. continue;
  1031. }
  1032. if ($from_gradebook && ($is_allowedToEdit || $is_tutor)) {
  1033. if (in_array($results[$i]['extitle'] . $results[$i]['userpart1'] . $results[$i]['userpart2'], $users_array_id)) {
  1034. continue;
  1035. }
  1036. $users_array_id[] = $results[$i]['extitle'] . $results[$i]['userpart1'] . $results[$i]['userpart2'];
  1037. }
  1038. $user_first_name = $results[$i]['userpart1'];
  1039. $user_last_name = $results[$i]['userpart2'];
  1040. $user_list_id[] = $results[$i]['excruid'];
  1041. $id = $results[$i]['exid'];
  1042. $user = $results[$i]['userpart1'] . $results[$i]['userpart2'];;
  1043. $test = $results[$i]['extitle'];
  1044. $quiz_name_list = $test;
  1045. $dt = api_convert_and_format_date($results[$i]['exweight'], null, date_default_timezone_get());
  1046. $res = $results[$i]['exresult'];
  1047. $duration = intval($results[$i]['exduration']);
  1048. // we filter the results if we have the permission to
  1049. if (isset ($results[$i]['exdisabled']))
  1050. $result_disabled = intval($results[$i]['exdisabled']);
  1051. else
  1052. $result_disabled = 0;
  1053. if ($result_disabled == 0) {
  1054. $add_start_date = $lang_nostartdate;
  1055. if ($is_allowedToEdit || $is_tutor) {
  1056. $user = $results[$i]['userpart1'] . $results[$i]['userpart2'];
  1057. }
  1058. if ($results[$i]['exstart'] != "0000-00-00 00:00:00") {
  1059. //echo ceil((($results[$i][4] - $results[$i][7]) / 60)) . ' ' . get_lang('MinMinutes');
  1060. $exe_date_timestamp = api_strtotime($results[$i]['exdate'], date_default_timezone_get());
  1061. $start_date_timestamp = api_strtotime($results[$i]['exstart'], date_default_timezone_get());
  1062. $my_duration = ceil((($exe_date_timestamp - $start_date_timestamp) / 60));
  1063. if ($my_duration == 1 ) {
  1064. $duration_list = $my_duration . ' ' . get_lang('MinMinute');
  1065. } else {
  1066. $duration_list = $my_duration. ' ' . get_lang('MinMinutes');
  1067. }
  1068. if ($results[$i]['exstep'] > 1) {
  1069. //echo ' ( ' . $results[$i][8] . ' ' . get_lang('Steps') . ' )';
  1070. $duration_list = ' ( ' . $results[$i]['exstep'] . ' ' . get_lang('Steps') . ' )';
  1071. }
  1072. $add_start_date = api_convert_and_format_date($results[$i]['exstart'], null, date_default_timezone_get()) . ' / ';
  1073. } else {
  1074. $duration_list = get_lang('NoLogOfDuration');
  1075. //echo get_lang('NoLogOfDuration');
  1076. }
  1077. // Date conversion
  1078. $date_list = api_get_local_time($results[$i]['exstart']). ' / ' . api_get_local_time($results[$i]['exdate']);
  1079. // there are already a duration test period calculated??
  1080. //echo '<td>'.sprintf(get_lang('DurationFormat'), $duration).'</td>';
  1081. // if the float look like 10.00 we show only 10
  1082. $my_res = float_format($results[$i]['exresult'],1);
  1083. $my_total = float_format($results[$i]['exweight'],1);
  1084. $result_list = round(($my_res / ($my_total != 0 ? $my_total : 1)) * 100, 2) . '% (' . $my_res . ' / ' . $my_total . ')';
  1085. $html_link = '';
  1086. if ($is_allowedToEdit || $is_tutor) {
  1087. if ($revised) {
  1088. $html_link.= "<a href='exercise_show.php?".api_get_cidreq()."&action=edit&id=$id'>".Display :: return_icon('edit.gif', get_lang('Edit'));
  1089. $html_link.= '&nbsp;';
  1090. } else {
  1091. $html_link.="<a href='exercise_show.php?".api_get_cidreq()."&action=qualify&id=$id'>".Display :: return_icon('quizz_small.gif', get_lang('Qualify'));
  1092. $html_link.='&nbsp;';
  1093. }
  1094. $html_link.="</a>";
  1095. if (api_is_platform_admin() || $is_tutor) {
  1096. $html_link.=' <a href="exercice.php?'.api_get_cidreq().'&show=result&filter=' . $filter . '&delete=delete&did=' . $id . '" onclick="javascript:if(!confirm(\'' . sprintf(get_lang('DeleteAttempt'), $user, $dt) . '\')) return false;">'.Display :: return_icon('delete.gif', get_lang('Delete')).'</a>';
  1097. $html_link.='&nbsp;';
  1098. }
  1099. if ($is_allowedToEdit) {
  1100. if ($filter==2){
  1101. $html_link.=' <a href="exercice_history.php?'.api_get_cidreq().'&exe_id=' . $id . '">' .Display :: return_icon('history.gif', get_lang('ViewHistoryChange')).'</a>';
  1102. }
  1103. }
  1104. } else {
  1105. if ($revised) {
  1106. $html_link.="<a href='exercise_show.php?".api_get_cidreq()."&id=$id'>" . get_lang('Show') . "</a> ";
  1107. } else {
  1108. $html_link.='&nbsp;' . get_lang('NoResult');
  1109. }
  1110. }
  1111. $more_details_list = $html_link;
  1112. if ($is_allowedToEdit || $is_tutor) {
  1113. $list_info [] = array($user_first_name,$user_last_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
  1114. } else {
  1115. $list_info [] = array($quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
  1116. }
  1117. }
  1118. }
  1119. }
  1120. // Print HotPotatoes test results.
  1121. if (is_array($hpresults)) {
  1122. $has_test_results = true;
  1123. for ($i = 0; $i < sizeof($hpresults); $i++) {
  1124. $hp_title = GetQuizName($hpresults[$i][1], $documentPath);
  1125. if ($hp_title == '') {
  1126. $hp_title = basename($hpresults[$i][1]);
  1127. }
  1128. //$hp_date = api_convert_and_format_date($hpresults[$i][4], null, date_default_timezone_get());
  1129. $hp_date = api_get_local_time($hpresults[$i][4], null, date_default_timezone_get());
  1130. $hp_result = round(($hpresults[$i][2] / ($hpresults[$i][3] != 0 ? $hpresults[$i][3] : 1)) * 100, 2).'% ('.$hpresults[$i][2].' / '.$hpresults[$i][3].')';
  1131. if ($is_allowedToEdit) {
  1132. $list_info[] = array($hpresults[$i][0], $hp_title, '-', $hp_date , $hp_result , '-');
  1133. } else {
  1134. $list_info[] = array($hp_title, '-', $hp_date , $hp_result , '-');
  1135. }
  1136. }
  1137. }
  1138. if ($has_test_results) {
  1139. $parameters=array('cidReq'=>Security::remove_XSS($_GET['cidReq']),'show'=>Security::remove_XSS($_GET['show']),'filter' => Security::remove_XSS($_GET['filter']),'gradebook' =>Security::remove_XSS($_GET['gradebook']));
  1140. $table = new SortableTableFromArrayConfig($list_info, 1,20,'quiz_table');
  1141. $table->set_additional_parameters($parameters);
  1142. $secuence = 2;
  1143. if ($is_allowedToEdit || $is_tutor) {
  1144. $secuence = 0;
  1145. if (api_is_western_name_order()) {
  1146. $table->set_header(0, get_lang('FirstName'));
  1147. $table->set_header(1, get_lang('LastName'));
  1148. } else {
  1149. $table->set_header(0, get_lang('LastName'));
  1150. $table->set_header(1, get_lang('FirstName'));
  1151. }
  1152. }
  1153. $table->set_header(-$secuence + 2, get_lang('Exercice'));
  1154. $table->set_header(-$secuence + 3, get_lang('Duration'),false);
  1155. $table->set_header(-$secuence + 4, get_lang('Date'));
  1156. $table->set_header(-$secuence + 5, get_lang('Result'),false);
  1157. $table->set_header(-$secuence + 6, (($is_allowedToEdit||$is_tutor) ? get_lang('CorrectTest') : get_lang('ViewTest')), false);
  1158. $table->display();
  1159. } else {
  1160. echo get_lang('NoResult');
  1161. }
  1162. }
  1163. if ($origin != 'learnpath') { //so we are not in learnpath tool
  1164. Display :: display_footer();
  1165. } else {
  1166. ?>
  1167. <link rel="stylesheet" type="text/css" href="<?php echo $clarolineRepositoryWeb ?>css/default.css" />
  1168. <?php
  1169. }
  1170. ?>