exercice.php 60 KB

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