exercice.php 56 KB

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