exercice.php 55 KB

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