exercice.php 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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,__FILE__,__LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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,__FILE__,__LINE__);
  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,__FILE__, __LINE__);
  245. }
  246. }
  247. Database::query($totquery, __FILE__, __LINE__);
  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\r\nContent-type: text/html; charset=" . ($charset ? $charset : 'ISO-8859-15');
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);*/
  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, __FILE__, __LINE__);
  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);
  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']);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  470. $row = Database :: fetch_array($result, 'ASSOC');
  471. $link = LinkFactory :: load($row['id']);
  472. if ($link[0] != null) {
  473. $link[0]->delete();
  474. }
  475. Display :: display_confirmation_message(get_lang('ExerciseDeleted'));
  476. break;
  477. case 'enable' : // enables an exercise
  478. $objExerciseTmp->enable();
  479. $objExerciseTmp->save();
  480. // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
  481. Display :: display_confirmation_message(get_lang('VisibilityChanged'));
  482. break;
  483. case 'disable' : // disables an exercise
  484. $objExerciseTmp->disable();
  485. $objExerciseTmp->save();
  486. Display :: display_confirmation_message(get_lang('VisibilityChanged'));
  487. break;
  488. case 'disable_results' : //disable the results for the learners
  489. $objExerciseTmp->disable_results();
  490. $objExerciseTmp->save();
  491. Display :: display_confirmation_message(get_lang('ResultsDisabled'));
  492. break;
  493. case 'enable_results' : //disable the results for the learners
  494. $objExerciseTmp->enable_results();
  495. $objExerciseTmp->save();
  496. Display :: display_confirmation_message(get_lang('ResultsEnabled'));
  497. break;
  498. }
  499. }
  500. // destruction of Exercise
  501. unset ($objExerciseTmp);
  502. }
  503. if (!empty ($hpchoice)) {
  504. switch ($hpchoice) {
  505. case 'delete' : // deletes an exercise
  506. $imgparams = array ();
  507. $imgcount = 0;
  508. GetImgParams($file, $documentPath, $imgparams, $imgcount);
  509. $fld = GetFolderName($file);
  510. for ($i = 0; $i < $imgcount; $i++) {
  511. my_delete($documentPath . $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
  512. update_db_info("delete", $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
  513. }
  514. if (my_delete($documentPath . $file)) {
  515. update_db_info("delete", $file);
  516. }
  517. my_delete($documentPath . $uploadPath . "/" . $fld . "/");
  518. break;
  519. case 'enable' : // enables an exercise
  520. $newVisibilityStatus = "1"; //"visible"
  521. $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='" . Database :: escape_string($file) . "'";
  522. $res = Database::query($query, __FILE__, __LINE__);
  523. $row = Database :: fetch_array($res, 'ASSOC');
  524. api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'visible', $_user['user_id']);
  525. //$dialogBox = get_lang('ViMod');
  526. break;
  527. case 'disable' : // disables an exercise
  528. $newVisibilityStatus = "0"; //"invisible"
  529. $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='" . Database :: escape_string($file) . "'";
  530. $res = Database::query($query, __FILE__, __LINE__);
  531. $row = Database :: fetch_array($res, 'ASSOC');
  532. api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'invisible', $_user['user_id']);
  533. #$query = "UPDATE $TBL_DOCUMENT SET visibility='$newVisibilityStatus' WHERE path=\"".$file."\""; //added by Toon
  534. #Database::query($query,__FILE__,__LINE__);
  535. //$dialogBox = get_lang('ViMod');
  536. break;
  537. default :
  538. break;
  539. }
  540. }
  541. if ($show == 'test') {
  542. $sql = "SELECT id,title,type,active,description, results_disabled FROM $TBL_EXERCICES WHERE active<>'-1' ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
  543. $result = Database::query($sql, __FILE__, __LINE__);
  544. }
  545. }
  546. elseif ($show == 'test') { // only for students //fin
  547. $sql = "SELECT id,title,type,description, results_disabled FROM $TBL_EXERCICES WHERE active='1' ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
  548. $result = Database::query($sql, __FILE__, __LINE__);
  549. }
  550. // the actions
  551. echo '<div class="actions">';
  552. // display the next and previous link if needed
  553. $from = $page * $limitExPage;
  554. $sql = "SELECT count(id) FROM $TBL_EXERCICES";
  555. $res = Database::query($sql, __FILE__, __LINE__);
  556. list ($nbrexerc) = Database :: fetch_array($res);
  557. HotPotGCt($documentPath, 1, $_user['user_id']);
  558. //condition for the session
  559. $session_id = api_get_session_id();
  560. $condition_session = api_get_session_condition($session_id);
  561. // only for administrator
  562. if ($is_allowedToEdit) {
  563. if ($show == 'test') {
  564. $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);
  565. $result = Database::query($sql, __FILE__, __LINE__);
  566. }
  567. }
  568. elseif ($show == 'test') { // only for students
  569. $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);
  570. $result = Database::query($sql, __FILE__, __LINE__);
  571. }
  572. if ($show == 'test') {
  573. $nbrExercises = Database :: num_rows($result);
  574. //get HotPotatoes files (active and inactive)
  575. $res = Database::query("SELECT *
  576. FROM $TBL_DOCUMENT
  577. WHERE
  578. path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'", __FILE__, __LINE__);
  579. $nbrTests = Database :: num_rows($res);
  580. $res = Database::query("SELECT *
  581. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  582. WHERE d.id = ip.ref
  583. AND ip.tool = '" . TOOL_DOCUMENT . "'
  584. AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'
  585. AND ip.visibility='1'", __FILE__, __LINE__);
  586. $nbrActiveTests = Database :: num_rows($res);
  587. if ($is_allowedToEdit) {
  588. //if user is allowed to edit, also show hidden HP tests
  589. $nbrHpTests = $nbrTests;
  590. } else {
  591. $nbrHpTests = $nbrActiveTests;
  592. }
  593. $nbrNextTests = $nbrexerc - $nbrHpTests - (($page * $limitExPage));
  594. echo '<span style="float:right">';
  595. //show pages navigation link for previous page
  596. if ($page) {
  597. echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&amp;page=" . ($page -1) . "\">" . Display :: return_icon('previous.gif') . get_lang("PreviousPage") . "</a> | ";
  598. }
  599. elseif ($nbrExercises + $nbrNextTests > $limitExPage) {
  600. echo Display :: return_icon('previous.gif') . get_lang('PreviousPage') . " | ";
  601. }
  602. //show pages navigation link for previous page
  603. if ($nbrExercises + $nbrNextTests > $limitExPage) {
  604. echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&amp;page=" . ($page +1) . "\">" . get_lang("NextPage") . Display :: return_icon('next.gif') . "</a>";
  605. }
  606. elseif ($page) {
  607. echo get_lang("NextPage") . Display :: return_icon('next.gif');
  608. }
  609. echo '</span>';
  610. }
  611. if ($_configuration['tracking_enabled']) {
  612. if ($show == 'result') {
  613. /*if (!function_exists('make_select'))
  614. {
  615. function make_select($name,$values,$checked='')
  616. {
  617. $output .= '<select name="'.$name.'" >';
  618. foreach($values as $key => $value)
  619. {
  620. //$output .= '<option value="'.$key.'" '.(($checked==$key)?'selected="selected"':'').'>'.$value.'</option>';
  621. }
  622. $output .= '</select>';
  623. return $output;
  624. }
  625. }*/
  626. /*if (!function_exists('make_select_users'))
  627. {
  628. function make_select_users($name,$values,$checked='')
  629. {
  630. $output .= '<select name="'.$name.'" >';
  631. $output .= '<option value="all">'.get_lang('EveryBody').'</option>';
  632. foreach($values as $key => $value)
  633. {
  634. $output .= '<option value="'.$key.'" '.(($checked==$key)?'selected="selected"':'').'>'.$value.'</option>';
  635. }
  636. $output .= '</select>';
  637. return $output;
  638. }
  639. }*/
  640. if (api_is_allowed_to_edit(null,true)) {
  641. if (!$_GET['filter']) {
  642. $filter_by_not_revised = true;
  643. $filter = 1;
  644. } else {
  645. $filter=Security::remove_XSS($_GET['filter']);
  646. }
  647. $filter = (int) $_GET['filter'];
  648. switch ($filter) {
  649. case 1 :
  650. $filter_by_not_revised = true;
  651. break;
  652. case 2 :
  653. $filter_by_revised = true;
  654. break;
  655. default :
  656. null;
  657. }
  658. if ($_GET['filter'] == '1' or !isset ($_GET['filter']) or $_GET['filter'] == 0 ) {
  659. $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>';
  660. } else {
  661. $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>';
  662. }
  663. //$form_filter = '<form method="post" action="'.api_get_self().'?cidReq='.api_get_course_id().'&show=result">';
  664. //$form_filter .= make_select('filter',array(1=>get_lang('FilterByNotRevised'),2=>get_lang('FilterByRevised')),$filter);
  665. //$form_filter .= '<button class="save" type="submit">'.get_lang('FilterExercices').'</button></form>';
  666. echo $view_result;
  667. }
  668. }
  669. /*if (api_is_allowed_to_edit())
  670. {
  671. $user_count = count($user_list_name);
  672. if ($user_count >0 ) {
  673. $form_filter = '<form method="post" action="'.api_get_self().'?cidReq='.api_get_course_id().'&show=result">';
  674. $user_list_for_select =array();
  675. for ($i=0;$i<$user_count;$i++) {
  676. $user_list_for_select[$user_list_id[$i]]=$user_list_name[$i];
  677. }
  678. $form_filter .= make_select_users('filter_by_user',$user_list_for_select,(int)$_REQUEST['filter_by_user']);
  679. $form_filter .= '<input type="hidden" name="filter" value="'.$filter.'">';
  680. $form_filter .= '<input type="submit" value="'.get_lang('FilterExercicesByUsers').'"></form>';
  681. echo $form_filter;
  682. }
  683. } */
  684. }
  685. if (($is_allowedToEdit) and ($origin != 'learnpath')) {
  686. if ($_GET['show'] != 'result') {
  687. echo '<a href="exercise_admin.php?' . api_get_cidreq() . '">' . Display :: return_icon('new_test.gif', get_lang('NewEx')) . get_lang('NewEx') . '</a>';
  688. echo '<a href="question_create.php?' . api_get_cidreq() . '">' . Display :: return_icon('question_add.gif', get_lang('AddQuestionToExercise')) . get_lang('AddQuestionToExercise') . '</a>';
  689. echo '<a href="hotpotatoes.php">' . Display :: return_icon('jqz.gif', get_lang('ImportHotPotatoesQuiz')) . get_lang('ImportHotPotatoesQuiz') . '</a>';
  690. 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>';
  691. }
  692. // the actions for the statistics
  693. if ($show == 'result') {
  694. // the form
  695. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
  696. if ($_SESSION['export_user_fields'] == true) {
  697. $alt = get_lang('ExportWithUserFields');
  698. $extra_user_fields = '<input type="hidden" name="export_user_fields" value="export_user_fields">';
  699. } else {
  700. $alt = get_lang('ExportWithoutUserFields');
  701. $extra_user_fields = '<input type="hidden" name="export_user_fields" value="do_not_export_user_fields">';
  702. }
  703. //echo '<a href="javascript: void(0);" onclick="javascript: document.form1a.submit();">'.Display::return_icon('excel.gif',get_lang('ExportAsCSV')).get_lang('ExportAsCSV').'</a>';
  704. echo '<a href="javascript: void(0);" onclick="javascript: document.form1b.submit();">' . Display :: return_icon('excel.gif', get_lang('ExportAsXLS')) . get_lang('ExportAsXLS') . '</a>';
  705. //echo '<a href="javascript: void(0);" onclick="javascript: document.form1c.submit();">'.Display::return_icon('synthese_view.gif',$alt).$alt.'</a>';
  706. echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=test') . '">' . Display :: return_icon('quiz.gif', get_lang('BackToExercisesList')) . get_lang('BackToExercisesList') . '</a>';
  707. echo '<form id="form1a" name="form1a" method="post" action="' . api_get_self() . '?show=' . Security :: remove_XSS($_GET['show']) . '">';
  708. echo '<input type="hidden" name="export_report" value="export_report">';
  709. echo '<input type="hidden" name="export_format" value="csv">';
  710. echo '</form>';
  711. echo '<form id="form1b" name="form1b" method="post" action="' . api_get_self() . '?show=' . Security :: remove_XSS($_GET['show']) . '">';
  712. echo '<input type="hidden" name="export_report" value="export_report">';
  713. echo '<input type="hidden" name="export_format" value="xls">';
  714. echo '</form>';
  715. //echo '<form id="form1c" name="form1c" method="post" action="'.api_get_self().'?show='.Security::remove_XSS($_GET['show']).'">';
  716. //echo $extra_user_fields;
  717. //echo '</form>';
  718. }
  719. }
  720. } else {
  721. //the student view
  722. if ($show == 'result') {
  723. echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=test') . '">' . Display :: return_icon('quiz.gif', get_lang('BackToExercisesList')) . get_lang('BackToExercisesList') . '</a>';
  724. } else {
  725. 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>';
  726. }
  727. }
  728. echo '</div>'; // closing the actions div
  729. if ($show == 'test') {
  730. ?>
  731. <table class="data_table">
  732. <?php
  733. if (($is_allowedToEdit) and ($origin != 'learnpath')) {
  734. ?>
  735. <tr class="row_odd">
  736. <th colspan="3"><?php echo get_lang('ExerciseName');?></th>
  737. <th><?php echo get_lang('QuantityQuestions');?></th>
  738. <!--<th>--><?php
  739. ?>
  740. <!--</th>-->
  741. <th><?php echo get_lang('Modify');?></th>
  742. </tr>
  743. <?php
  744. } else {
  745. //student only
  746. ?> <tr>
  747. <th colspan="2"><?php echo get_lang('ExerciseName');?></th>
  748. <th><?php echo get_lang('QuantityQuestions');?></th>
  749. <th><?php echo get_lang('State');?></th>
  750. </tr>
  751. <?php
  752. }
  753. // show message if no HP test to show
  754. if (!($nbrExercises + $nbrHpTests)) {
  755. ?>
  756. <tr>
  757. <td <?php echo ($is_allowedToEdit?'colspan="6"':'colspan="5"'); ?>><?php echo get_lang("NoEx"); ?></td>
  758. </tr>
  759. <?php
  760. }
  761. $i = 1;
  762. // while list exercises
  763. if ($origin != 'learnpath') {
  764. //avoid sending empty parameters
  765. $myorigin = (empty ($origin) ? '' : '&origin=' . $origin);
  766. $mylpid = (empty ($learnpath_id) ? '' : '&learnpath_id=' . $learnpath_id);
  767. $mylpitemid = (empty ($learnpath_item_id) ? '' : '&learnpath_item_id=' . $learnpath_item_id);
  768. while ($row = Database :: fetch_array($result)) {
  769. //validacion when belongs to a session
  770. $session_img = api_get_session_image($row['session_id'], $_user['status']);
  771. if ($i % 2 == 0)
  772. $s_class = "row_odd";
  773. else
  774. $s_class = "row_even";
  775. // prof only
  776. if ($is_allowedToEdit) {
  777. echo '<tr class="' . $s_class . '">' . "\n";
  778. ?>
  779. <td width="30" align="left"><?php Display::display_icon('quiz.gif', get_lang('Exercice'))?></td>
  780. <td width="15" valign="left"><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
  781. <?php $row['title']=api_parse_tex($row['title']); ?>
  782. <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>
  783. <td align="center"> <?php
  784. $exid = $row['id'];
  785. //count number exercice - teacher
  786. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '" . Database :: escape_string($exid) . "'";
  787. $sqlresult = Database::query($sqlquery);
  788. $rowi = Database :: result($sqlresult, 0);
  789. //count number random exercice - teacher
  790. $sql_random_query = 'SELECT type,random,active,results_disabled,max_attempt FROM ' . $TBL_EXERCICES . ' WHERE id="' . Database :: escape_string($exid) . '" ';
  791. $rs_random = Database::query($sql_random_query, __FILE__, __LINE__);
  792. $row_random = Database :: fetch_array($rs_random);
  793. if ($row_random['random'] > 0) {
  794. echo $row_random['random'] . ' ' . api_strtolower(get_lang(($row_random['random'] > 1 ? 'Questions' : 'Question'))) . '</td>';
  795. } else {
  796. echo $rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question'))) . '</td>';
  797. }
  798. //echo '<td><a href="exercice.php?choice=exportqti2&exerciseId='.$row['id'].'"><img src="../img/export.png" border="0" title="IMS/QTI" /></a></td>';
  799. ?>
  800. <td>
  801. <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>
  802. <?php
  803. if ($row['results_disabled']) {
  804. //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>';
  805. } else {
  806. //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>';
  807. }
  808. ?>
  809. <!--<a href="exercise_admin.php?modifyExercise=yes&exerciseId=--><?php
  810. ?>
  811. <!--"> <img src="../img/edit.gif" border="0" title="--><?php
  812. ?>
  813. <!--" alt="--><?php
  814. ?>
  815. <!--" /></a>-->
  816. <a href="exercice.php?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" alt="<?php echo api_htmlentities(get_lang('Delete'),ENT_QUOTES,$charset); ?>" /></a>
  817. <?php
  818. //if active
  819. if ($row['active']) {
  820. ?>
  821. <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>
  822. <?php
  823. } else {
  824. // else if not active
  825. ?>
  826. <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>
  827. <?php
  828. }
  829. echo "</td>";
  830. echo "</tr>\n";
  831. } else { // student only
  832. ?>
  833. <tr>
  834. <td><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
  835. <?php $row['title']=api_parse_tex($row['title']);?>
  836. <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>
  837. <td align="center"> <?php
  838. $exid = $row['id'];
  839. //count number exercise questions
  840. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '" . Database :: escape_string($exid) . "'";
  841. $sqlresult = Database::query($sqlquery);
  842. $rowi = Database :: result($sqlresult, 0);
  843. //count number random exercice
  844. $sql_random_query = 'SELECT type,random,active,results_disabled,max_attempt FROM ' . $TBL_EXERCICES . ' WHERE id="' . Database :: escape_string($exid) . '" ';
  845. $rs_random = Database::query($sql_random_query, __FILE__, __LINE__);
  846. $row_random = Database :: fetch_array($rs_random);
  847. if ($row_random['random'] > 0) {
  848. echo $row_random['random'] . ' ' . api_strtolower(get_lang(($row_random['random'] > 1 ? 'Questions' : 'Question')));
  849. } else {
  850. //show results student
  851. echo $rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question')));
  852. }
  853. ?> </td>
  854. <td align="center"><?php
  855. $eid = $row['id'];
  856. $uid = api_get_user_id();
  857. //this query might be improved later on by ordering by the new "tms" field rather than by exe_id
  858. $qry = "SELECT * FROM $TBL_TRACK_EXERCICES
  859. 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() . "'
  860. ORDER BY exe_id DESC";
  861. $qryres = Database::query($qry);
  862. $num = Database :: num_rows($qryres);
  863. //hide the results
  864. $my_result_disabled = $row['results_disabled'];
  865. if ($my_result_disabled == 0) {
  866. if ($num > 0) {
  867. $row = Database :: fetch_array($qryres);
  868. $percentage = 0;
  869. if ($row['exe_weighting'] != 0) {
  870. $percentage = ($row['exe_result'] / $row['exe_weighting']) * 100;
  871. }
  872. echo get_lang('Attempted') . ' (' . get_lang('Score') . ': ';
  873. printf("%1.2f\n", $percentage);
  874. echo " %)";
  875. } else {
  876. echo get_lang('NotAttempted');
  877. }
  878. } else {
  879. echo get_lang('CantShowResults');
  880. }
  881. ?></td>
  882. </tr>
  883. <?php
  884. }
  885. // skips the last exercise, that is only used to know if we have or not to create a link "Next page"
  886. if ($i == $limitExPage) {
  887. break;
  888. }
  889. $i++;
  890. } // end while()
  891. $ind = $i;
  892. if (($from + $limitExPage -1) > $nbrexerc) {
  893. if ($from > $nbrexerc) {
  894. $from = $from - $nbrexerc;
  895. $to = $limitExPage;
  896. } else {
  897. $to = $limitExPage - ($nbrexerc - $from);
  898. $from = 0;
  899. }
  900. } else {
  901. $to = $limitExPage;
  902. }
  903. if ($is_allowedToEdit) {
  904. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  905. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  906. WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND
  907. (d.path LIKE '%htm%')
  908. AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' LIMIT " . (int) $from . "," . (int) $to; // only .htm or .html files listed
  909. } else {
  910. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  911. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  912. WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND
  913. (d.path LIKE '%htm%')
  914. AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' AND ip.visibility='1' LIMIT " . (int) $from . "," . (int) $to;
  915. }
  916. $result = Database::query($sql, __FILE__, __LINE__);
  917. while ($row = Database :: fetch_array($result, 'ASSOC')) {
  918. $attribute['path'][] = $row['path'];
  919. $attribute['visibility'][] = $row['visibility'];
  920. $attribute['comment'][] = $row['comment'];
  921. }
  922. $nbrActiveTests = 0;
  923. if (is_array($attribute['path'])) {
  924. while (list ($key, $path) = each($attribute['path'])) {
  925. list ($a, $vis) = each($attribute['visibility']);
  926. if (strcmp($vis, "1") == 0) {
  927. $active = 1;
  928. } else {
  929. $active = 0;
  930. }
  931. echo "<tr>\n";
  932. $title = GetQuizName($path, $documentPath);
  933. if ($title == '') {
  934. $title = basename($path);
  935. }
  936. // prof only
  937. if ($is_allowedToEdit) {
  938. /************/
  939. ?>
  940. <tr>
  941. <td><img src="../img/jqz.gif" alt="HotPotatoes" /></td>
  942. <td><?php echo ($ind+($page*$limitExPage)).'.'; ?></td>
  943. <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>
  944. <td></td>
  945. <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>
  946. <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); ?>" />
  947. <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>
  948. <?php
  949. // if active
  950. if ($active) {
  951. $nbrActiveTests = $nbrActiveTests +1;
  952. ?>
  953. <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>
  954. <?php
  955. } else { // else if not active
  956. ?>
  957. <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>
  958. <?php
  959. }
  960. echo '<img src="../img/lp_quiz_na.gif" border="0" alt="" />';
  961. /****************/
  962. ?></td>
  963. <?php
  964. } else { // student only
  965. if ($active == 1) {
  966. $nbrActiveTests = $nbrActiveTests +1;
  967. ?>
  968. <tr>
  969. <td><?php echo ($ind+($page*$limitExPage)).'.'; ?><!--<img src="../img/jqz.jpg" alt="HotPotatoes" />--></td>
  970. <td>&nbsp;</td>
  971. <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>
  972. <td>&nbsp;</td><td>&nbsp;</td>
  973. </tr>
  974. <?php
  975. }
  976. }
  977. ?>
  978. <?php
  979. if ($ind == $limitExPage) {
  980. break;
  981. }
  982. if ($is_allowedToEdit) {
  983. $ind++;
  984. } else {
  985. if ($active == 1) {
  986. $ind++;
  987. }
  988. }
  989. }
  990. }
  991. } //end if ($origin != 'learnpath') {
  992. ?>
  993. </table>
  994. <?php
  995. }
  996. /*****************************************/
  997. /* Exercise Results (uses tracking tool) */
  998. /*****************************************/
  999. // if tracking is enabled
  1000. if ($_configuration['tracking_enabled'] && ($show == 'result')) {
  1001. ?>
  1002. <!--<table class="data_table">
  1003. <tr class="row_odd">
  1004. <?php if($is_allowedToEdit || $is_tutor): ?>
  1005. <th><?php echo get_lang('User'); ?></th><?php endif; ?>
  1006. <th><?php echo get_lang('Exercice'); ?></th>
  1007. <th><?php echo get_lang('Duration'); ?></th>
  1008. <th><?php echo get_lang('Date'); ?></th>
  1009. <th><?php echo get_lang('Result'); ?></th>
  1010. <th><?php echo (($is_allowedToEdit||$is_tutor)?get_lang("CorrectTest"):get_lang("ViewTest")); ?></th>
  1011. </tr>-->
  1012. <?php
  1013. $session_id_and = '';
  1014. if (api_get_session_id() != 0) {
  1015. $session_id_and = ' AND session_id = ' . api_get_session_id() . ' ';
  1016. }
  1017. if ($is_allowedToEdit || $is_tutor) {
  1018. $user_id_and = '';
  1019. if (!empty ($_POST['filter_by_user'])) {
  1020. if ($_POST['filter_by_user'] == 'all') {
  1021. $user_id_and = " AND user_id like '%'";
  1022. } else {
  1023. $user_id_and = " AND user_id = '" . Database :: escape_string((int) $_POST['filter_by_user']) . "' ";
  1024. }
  1025. }
  1026. if ($_GET['gradebook'] == 'view') {
  1027. $exercise_where_query = 'te.exe_exo_id =ce.id AND ';
  1028. }
  1029. $sql="SELECT ".(api_is_western_name_order() ? "CONCAT(firstname,' ',lastname)" : "CONCAT(lastname,' ',firstname)")." as users, ce.title, te.exe_result ,
  1030. 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
  1031. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  1032. 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) . "'
  1033. 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
  1034. AND cuser.course_code=te.exe_cours_id ORDER BY users, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";
  1035. $hpsql="SELECT ".(api_is_western_name_order() ? "CONCAT(tu.firstname,' ',tu.lastname)" : "CONCAT(tu.lastname,' ',tu.firstname)").", tth.exe_name,
  1036. tth.exe_result , tth.exe_weighting, UNIX_TIMESTAMP(tth.exe_date)
  1037. FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
  1038. WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . Database :: escape_string($_cid) . " $user_id_and '
  1039. ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
  1040. } else {
  1041. // get only this user's results
  1042. $user_id_and = ' AND te.exe_user_id = ' . Database :: escape_string(api_get_user_id()) . ' ';
  1043. $sql="SELECT ".(api_is_western_name_order() ? "CONCAT(firstname,' ',lastname)" : "CONCAT(lastname,' ',firstname)")." as users,ce.title, te.exe_result ,
  1044. 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
  1045. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  1046. 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) . "'
  1047. 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
  1048. AND cuser.course_code=te.exe_cours_id ORDER BY users, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";
  1049. $hpsql = "SELECT '',exe_name, exe_result , exe_weighting, UNIX_TIMESTAMP(exe_date)
  1050. FROM $TBL_TRACK_HOTPOTATOES
  1051. WHERE exe_user_id = '" . $_user['user_id'] . "' AND exe_cours_id = '" . Database :: escape_string($_cid) . "'
  1052. ORDER BY exe_cours_id ASC, exe_date DESC";
  1053. }
  1054. $results = getManyResultsXCol($sql, 12);
  1055. $hpresults = getManyResultsXCol($hpsql, 5);
  1056. $NoTestRes = 0;
  1057. $NoHPTestRes = 0;
  1058. //Print the results of tests
  1059. $lang_nostartdate = get_lang('NoStartDate') . ' / ';
  1060. if (is_array($results)) {
  1061. $users_array_id = array ();
  1062. if ($_GET['gradebook'] == 'view') {
  1063. $filter_by_no_revised = true;
  1064. $from_gradebook = true;
  1065. }
  1066. $sizeof = sizeof($results);
  1067. $user_list_id = array ();
  1068. $user_list_name = '';
  1069. $quiz_name_list = '';
  1070. $duration_list = '';
  1071. $date_list = '';
  1072. $result_list = '';
  1073. $more_details_list = '';
  1074. $list_info = array();
  1075. for ($i = 0; $i < $sizeof; $i++) {
  1076. $revised = false;
  1077. $sql_exe = 'SELECT exe_id FROM ' . Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING) . '
  1078. WHERE author != ' . "''" . ' AND exe_id = ' . "'" . Database :: escape_string($results[$i][5]) . "'" . ' LIMIT 1';
  1079. $query = Database::query($sql_exe, __FILE__, __LINE__);
  1080. if (Database :: num_rows($query) > 0) {
  1081. $revised = true;
  1082. }
  1083. if ($filter_by_not_revised && $revised == true) {
  1084. continue;
  1085. }
  1086. if ($filter_by_revised && $revised == false) {
  1087. continue;
  1088. }
  1089. if ($from_gradebook && ($is_allowedToEdit || $is_tutor)) {
  1090. if (in_array($results[$i][1] . $results[$i][0], $users_array_id)) {
  1091. continue;
  1092. }
  1093. $users_array_id[] = $results[$i][1] . $results[$i][0];
  1094. }
  1095. $user_list_name = $results[$i][0];
  1096. $user_list_id[] = $results[$i][9];
  1097. $id = $results[$i][5];
  1098. $mailid = $results[$i][6];
  1099. $user = $results[$i][0];
  1100. $test = $results[$i][1];
  1101. $quiz_name_list = $test;
  1102. $dt = strftime($dateTimeFormatLong, $results[$i][4]);
  1103. $res = $results[$i][2];
  1104. $duration = intval($results[$i][10]);
  1105. // we filter the results if we have the permission to
  1106. if (isset ($results[$i][11]))
  1107. $result_disabled = intval($results[$i][11]);
  1108. else
  1109. $result_disabled = 0;
  1110. if ($result_disabled == 0) {
  1111. //echo '<tr';
  1112. //if ($i % 2 == 0) {
  1113. //echo 'class="row_odd"';
  1114. //} else {
  1115. //echo 'class="row_even"';
  1116. //}
  1117. //echo '>';
  1118. $add_start_date = $lang_nostartdate;
  1119. if ($is_allowedToEdit || $is_tutor) {
  1120. $user = $results[$i][0];
  1121. //echo '<td>' . $user . ' </td>';
  1122. }
  1123. //echo '<td>' . $test . '</td>';
  1124. //echo '<td>';
  1125. if ($results[$i][7] > 1) {
  1126. //echo ceil((($results[$i][4] - $results[$i][7]) / 60)) . ' ' . get_lang('MinMinutes');
  1127. $duration_list = ceil((($results[$i][4] - $results[$i][7]) / 60)) . ' ' . get_lang('MinMinutes');
  1128. if ($results[$i][8] > 1) {
  1129. //echo ' ( ' . $results[$i][8] . ' ' . get_lang('Steps') . ' )';
  1130. $duration_list = ' ( ' . $results[$i][8] . ' ' . get_lang('Steps') . ' )';
  1131. }
  1132. $add_start_date = format_locale_date('%b %d, %Y %H:%M', $results[$i][7]) . ' / ';
  1133. } else {
  1134. $duration_list = get_lang('NoLogOfDuration');
  1135. //echo get_lang('NoLogOfDuration');
  1136. }
  1137. //echo '</td>';
  1138. //echo '<td>' . $add_start_date . format_locale_date('%b %d, %Y %H:%M', $results[$i][4]) . '</td>'; //get_lang('dateTimeFormatLong')
  1139. $date_list = $add_start_date . format_locale_date('%b %d, %Y %H:%M', $results[$i][4]);
  1140. // there are already a duration test period calculated??
  1141. //echo '<td>'.sprintf(get_lang('DurationFormat'), $duration).'</td>';
  1142. // if the float look like 10.00 we show only 10
  1143. $my_res = float_format($results[$i][2],1);
  1144. $my_total = float_format($results[$i][3],1);
  1145. //echo '<td>' . round(($my_res / ($my_total != 0 ? $my_total : 1)) * 100, 2) . '% (' . $my_res . ' / ' . $my_total . ')</td>';
  1146. $result_list = round(($my_res / ($my_total != 0 ? $my_total : 1)) * 100, 2) . '% (' . $my_res . ' / ' . $my_total . ')';
  1147. // Is hard to read this!!
  1148. /*
  1149. echo '<td>'.(($is_allowedToEdit||$is_tutor)?
  1150. "<a href='exercise_show.php?user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".
  1151. (($revised)?get_lang('Edit'):get_lang('Qualify'))."</a>".
  1152. ((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>':'')
  1153. .(($is_allowedToEdit)?' - <a href="exercice_history.php?cidReq='.htmlentities($_GET['cidReq']).'&exe_id='.$id.'">'.get_lang('ViewHistoryChange').'</a>':'')
  1154. :(($revised)?"<a href='exercise_show.php?dt=$dt&res=$res&id=$id'>".get_lang('Show')."</a>":'')).'</td>';
  1155. */
  1156. //echo '<td>';
  1157. $html_link = '';
  1158. if ($is_allowedToEdit || $is_tutor) {
  1159. if ($revised) {
  1160. //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'));
  1161. //echo '&nbsp;';
  1162. $html_link.= "<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. $html_link.= '&nbsp;';
  1164. } else {
  1165. //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'));
  1166. //echo '&nbsp;';
  1167. $html_link.="<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. $html_link.='&nbsp;';
  1169. }
  1170. //echo "</a>";
  1171. $html_link.="</a>";
  1172. if (api_is_platform_admin() || $is_tutor) {
  1173. //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>';
  1174. //echo '&nbsp;';
  1175. $html_link.=' <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. $html_link.='&nbsp;';
  1177. }
  1178. if ($is_allowedToEdit) {
  1179. //echo ' <a href="exercice_history.php?cidReq=' . security::remove_XSS($_GET['cidReq']) . '&exe_id=' . $id . '">' .Display :: return_icon('history.gif', get_lang('ViewHistoryChange')).'</a>';
  1180. $html_link.=' <a href="exercice_history.php?cidReq=' . security::remove_XSS($_GET['cidReq']) . '&exe_id=' . $id . '">' .Display :: return_icon('history.gif', get_lang('ViewHistoryChange')).'</a>';
  1181. }
  1182. } else {
  1183. if ($revised) {
  1184. //echo "<a href='exercise_show.php?dt=$dt&res=$res&id=$id'>" . get_lang('Show') . "</a> ";
  1185. $html_link.="<a href='exercise_show.php?dt=$dt&res=$res&id=$id'>" . get_lang('Show') . "</a> ";
  1186. } else {
  1187. // echo '&nbsp;' . get_lang('NoResult');
  1188. $html_link.='&nbsp;' . get_lang('NoResult');
  1189. }
  1190. }
  1191. $more_details_list = $html_link;
  1192. if ($is_allowedToEdit || $is_tutor) {
  1193. $list_info [] = array($user_list_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
  1194. } else {
  1195. $list_info [] = array($quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
  1196. }
  1197. //$list_info [] = array($user_list_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
  1198. //echo '</td>';
  1199. //echo '</tr>';
  1200. }
  1201. }
  1202. ////////////////////////////////////////////////////////////////////////////////
  1203. //Code added by Isaac flores
  1204. $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']));
  1205. $table = new SortableTableFromArrayConfig($list_info, 1,20,'quiz_table');
  1206. $table->set_additional_parameters($parameters);
  1207. if ($is_allowedToEdit || $is_tutor) {
  1208. $table->set_header(0, get_lang('User'));
  1209. $secuence = 0;
  1210. } else {
  1211. $secuence = 1;
  1212. }
  1213. $table->set_header(-$secuence + 1, get_lang('Exercice'));
  1214. $table->set_header(-$secuence + 2, get_lang('Duration'),false);
  1215. $table->set_header(-$secuence + 3, get_lang('Date'));
  1216. $table->set_header(-$secuence + 4, get_lang('Result'),false);
  1217. $table->set_header(-$secuence + 5, (($is_allowedToEdit||$is_tutor) ? get_lang("CorrectTest") : get_lang("ViewTest")), false);
  1218. $table->display();
  1219. //////////////////////////////////////////////////////////////////////////////////
  1220. } else {
  1221. $NoTestRes = 1;
  1222. }
  1223. // Print the Result of Hotpotatoes Tests
  1224. if (is_array($hpresults)) {
  1225. for ($i = 0; $i < sizeof($hpresults); $i++) {
  1226. $title = GetQuizName($hpresults[$i][1], $documentPath);
  1227. if ($title == '') {
  1228. $title = basename($hpresults[$i][1]);
  1229. }
  1230. echo '<tr>';
  1231. if ($is_allowedToEdit) {
  1232. echo '<td class="content">' . $hpresults[$i][0] . '</td>';
  1233. }
  1234. echo '<td class="content">' . $title . '</td>';
  1235. echo '<td class="content">' . strftime($dateTimeFormatLong, $hpresults[$i][4]) . '</td>';
  1236. 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>';
  1237. echo '<td></td>'; //there is no possibility to edit the results of a Hotpotatoes test
  1238. echo '</tr>';
  1239. }
  1240. } else {
  1241. $NoHPTestRes = 1;
  1242. }
  1243. if ($NoTestRes == 1 && $NoHPTestRes == 1) {
  1244. ?>
  1245. <tr>
  1246. <td colspan="6"><?php echo get_lang("NoResult"); ?></td>
  1247. </tr>
  1248. <?php
  1249. }
  1250. ?>
  1251. </table>
  1252. <br />
  1253. <?php
  1254. }
  1255. if ($origin != 'learnpath') { //so we are not in learnpath tool
  1256. Display :: display_footer();
  1257. } else {
  1258. ?>
  1259. <link rel="stylesheet" type="text/css" href="<?php echo $clarolineRepositoryWeb ?>css/default.css" />
  1260. <?php
  1261. }
  1262. ?>