exercice.php 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  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. //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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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,__FILE__,__LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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) . "/%/%'", __FILE__, __LINE__);
  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'", __FILE__, __LINE__);
  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">' . 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('excel.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 '</form>';
  714. echo '<form id="form1b" name="form1b" method="post" action="' . api_get_self() . '?show=' . Security :: remove_XSS($_GET['show']) . '">';
  715. echo '<input type="hidden" name="export_report" value="export_report">';
  716. echo '<input type="hidden" name="export_format" value="xls">';
  717. echo '</form>';
  718. //echo '<form id="form1c" name="form1c" method="post" action="'.api_get_self().'?show='.Security::remove_XSS($_GET['show']).'">';
  719. //echo $extra_user_fields;
  720. //echo '</form>';
  721. }
  722. }
  723. } else {
  724. //the student view
  725. if ($show == 'result') {
  726. echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=test') . '">' . Display :: return_icon('quiz.gif', get_lang('BackToExercisesList')) . get_lang('BackToExercisesList') . '</a>';
  727. } else {
  728. 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>';
  729. }
  730. }
  731. echo '</div>'; // closing the actions div
  732. if ($show == 'test') {
  733. ?>
  734. <table class="data_table">
  735. <?php
  736. if (($is_allowedToEdit) and ($origin != 'learnpath')) {
  737. ?>
  738. <tr class="row_odd">
  739. <th colspan="3"><?php echo get_lang('ExerciseName');?></th>
  740. <th><?php echo get_lang('QuantityQuestions');?></th>
  741. <!--<th>--><?php
  742. ?>
  743. <!--</th>-->
  744. <th><?php echo get_lang('Modify');?></th>
  745. </tr>
  746. <?php
  747. } else {
  748. //student only
  749. ?> <tr>
  750. <th colspan="2"><?php echo get_lang('ExerciseName');?></th>
  751. <th><?php echo get_lang('QuantityQuestions');?></th>
  752. <th><?php echo get_lang('State');?></th>
  753. </tr>
  754. <?php
  755. }
  756. // show message if no HP test to show
  757. if (!($nbrExercises + $nbrHpTests)) {
  758. ?>
  759. <tr>
  760. <td <?php echo ($is_allowedToEdit?'colspan="6"':'colspan="5"'); ?>><?php echo get_lang("NoEx"); ?></td>
  761. </tr>
  762. <?php
  763. }
  764. $i = 1;
  765. // while list exercises
  766. if ($origin != 'learnpath') {
  767. //avoid sending empty parameters
  768. $myorigin = (empty ($origin) ? '' : '&origin=' . $origin);
  769. $mylpid = (empty ($learnpath_id) ? '' : '&learnpath_id=' . $learnpath_id);
  770. $mylpitemid = (empty ($learnpath_item_id) ? '' : '&learnpath_item_id=' . $learnpath_item_id);
  771. while ($row = Database :: fetch_array($result)) {
  772. //validacion when belongs to a session
  773. $session_img = api_get_session_image($row['session_id'], $_user['status']);
  774. if ($i % 2 == 0)
  775. $s_class = "row_odd";
  776. else
  777. $s_class = "row_even";
  778. // prof only
  779. if ($is_allowedToEdit) {
  780. echo '<tr class="' . $s_class . '">' . "\n";
  781. ?>
  782. <td width="30" align="left"><?php Display::display_icon('quiz.gif', get_lang('Exercice'))?></td>
  783. <td width="15" valign="left"><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
  784. <?php $row['title']=api_parse_tex($row['title']); ?>
  785. <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>
  786. <td align="center"> <?php
  787. $exid = $row['id'];
  788. //count number exercice - teacher
  789. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '" . Database :: escape_string($exid) . "'";
  790. $sqlresult = Database::query($sqlquery);
  791. $rowi = Database :: result($sqlresult, 0);
  792. //count number random exercice - teacher
  793. $sql_random_query = 'SELECT type,random,active,results_disabled,max_attempt FROM ' . $TBL_EXERCICES . ' WHERE id="' . Database :: escape_string($exid) . '" ';
  794. $rs_random = Database::query($sql_random_query, __FILE__, __LINE__);
  795. $row_random = Database :: fetch_array($rs_random);
  796. if ($row_random['random'] > 0) {
  797. echo $row_random['random'] . ' ' . api_strtolower(get_lang(($row_random['random'] > 1 ? 'Questions' : 'Question'))) . '</td>';
  798. } else {
  799. echo $rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question'))) . '</td>';
  800. }
  801. //echo '<td><a href="exercice.php?choice=exportqti2&exerciseId='.$row['id'].'"><img src="../img/export.png" border="0" title="IMS/QTI" /></a></td>';
  802. ?>
  803. <td>
  804. <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>
  805. <?php
  806. if ($row['results_disabled']) {
  807. //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>';
  808. } else {
  809. //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>';
  810. }
  811. ?>
  812. <!--<a href="exercise_admin.php?modifyExercise=yes&exerciseId=--><?php
  813. ?>
  814. <!--"> <img src="../img/edit.gif" border="0" title="--><?php
  815. ?>
  816. <!--" alt="--><?php
  817. ?>
  818. <!--" /></a>-->
  819. <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>
  820. <?php
  821. //if active
  822. if ($row['active']) {
  823. ?>
  824. <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>
  825. <?php
  826. } else {
  827. // else if not active
  828. ?>
  829. <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>
  830. <?php
  831. }
  832. echo "</td>";
  833. echo "</tr>\n";
  834. } else { // student only
  835. ?>
  836. <tr>
  837. <td><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
  838. <?php $row['title']=api_parse_tex($row['title']);?>
  839. <td><a href="exercice_submit.php?<?php echo api_get_cidreq().$myorigin.$mylpid.$myllpitemid; ?>&exerciseId=<?php echo $row['id']; ?>"><?php echo $row['title']; ?></a></td>
  840. <td align="center"> <?php
  841. $exid = $row['id'];
  842. //count number exercise questions
  843. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '" . Database :: escape_string($exid) . "'";
  844. $sqlresult = Database::query($sqlquery);
  845. $rowi = Database :: result($sqlresult, 0);
  846. //count number random exercice
  847. $sql_random_query = 'SELECT type,random,active,results_disabled,max_attempt FROM ' . $TBL_EXERCICES . ' WHERE id="' . Database :: escape_string($exid) . '" ';
  848. $rs_random = Database::query($sql_random_query, __FILE__, __LINE__);
  849. $row_random = Database :: fetch_array($rs_random);
  850. if ($row_random['random'] > 0) {
  851. echo $row_random['random'] . ' ' . api_strtolower(get_lang(($row_random['random'] > 1 ? 'Questions' : 'Question')));
  852. } else {
  853. //show results student
  854. echo $rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question')));
  855. }
  856. ?> </td>
  857. <td align="center"><?php
  858. $eid = $row['id'];
  859. $uid = api_get_user_id();
  860. //this query might be improved later on by ordering by the new "tms" field rather than by exe_id
  861. $qry = "SELECT * FROM $TBL_TRACK_EXERCICES
  862. WHERE exe_exo_id = '" . Database :: escape_string($eid) . "' and exe_user_id = '" . Database :: escape_string($uid) . "' AND exe_cours_id = '" . api_get_course_id() . "' AND status <>'incomplete' AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND session_id = '" . api_get_session_id() . "'
  863. ORDER BY exe_id DESC";
  864. $qryres = Database::query($qry);
  865. $num = Database :: num_rows($qryres);
  866. //hide the results
  867. $my_result_disabled = $row['results_disabled'];
  868. if ($my_result_disabled == 0) {
  869. if ($num > 0) {
  870. $row = Database :: fetch_array($qryres);
  871. $percentage = 0;
  872. if ($row['exe_weighting'] != 0) {
  873. $percentage = ($row['exe_result'] / $row['exe_weighting']) * 100;
  874. }
  875. echo get_lang('Attempted') . ' (' . get_lang('Score') . ': ';
  876. printf("%1.2f\n", $percentage);
  877. echo " %)";
  878. } else {
  879. echo get_lang('NotAttempted');
  880. }
  881. } else {
  882. echo get_lang('CantShowResults');
  883. }
  884. ?></td>
  885. </tr>
  886. <?php
  887. }
  888. // skips the last exercise, that is only used to know if we have or not to create a link "Next page"
  889. if ($i == $limitExPage) {
  890. break;
  891. }
  892. $i++;
  893. } // end while()
  894. $ind = $i;
  895. if (($from + $limitExPage -1) > $nbrexerc) {
  896. if ($from > $nbrexerc) {
  897. $from = $from - $nbrexerc;
  898. $to = $limitExPage;
  899. } else {
  900. $to = $limitExPage - ($nbrexerc - $from);
  901. $from = 0;
  902. }
  903. } else {
  904. $to = $limitExPage;
  905. }
  906. if ($is_allowedToEdit) {
  907. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  908. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  909. WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND
  910. (d.path LIKE '%htm%')
  911. AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' LIMIT " . (int) $from . "," . (int) $to; // only .htm or .html files listed
  912. } else {
  913. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  914. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  915. WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND
  916. (d.path LIKE '%htm%')
  917. AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' AND ip.visibility='1' LIMIT " . (int) $from . "," . (int) $to;
  918. }
  919. $result = Database::query($sql, __FILE__, __LINE__);
  920. while ($row = Database :: fetch_array($result, 'ASSOC')) {
  921. $attribute['path'][] = $row['path'];
  922. $attribute['visibility'][] = $row['visibility'];
  923. $attribute['comment'][] = $row['comment'];
  924. }
  925. $nbrActiveTests = 0;
  926. if (is_array($attribute['path'])) {
  927. while (list ($key, $path) = each($attribute['path'])) {
  928. list ($a, $vis) = each($attribute['visibility']);
  929. if (strcmp($vis, "1") == 0) {
  930. $active = 1;
  931. } else {
  932. $active = 0;
  933. }
  934. echo "<tr>\n";
  935. $title = GetQuizName($path, $documentPath);
  936. if ($title == '') {
  937. $title = basename($path);
  938. }
  939. // prof only
  940. if ($is_allowedToEdit) {
  941. /************/
  942. ?>
  943. <tr>
  944. <td><img src="../img/jqz.gif" alt="HotPotatoes" /></td>
  945. <td><?php echo ($ind+($page*$limitExPage)).'.'; ?></td>
  946. <td><a href="showinframes.php?file=<?php echo $path?>&cid=<?php echo $_course['official_code'];?>&uid=<?php echo $_user['user_id'];?>" <?php if(!$active) echo 'class="invisible"'; ?>><?php echo $title?></a></td>
  947. <td></td>
  948. <td><a href="adminhp.php?hotpotatoesName=<?php echo $path; ?>"> <img src="../img/edit.gif" border="0" alt="<?php echo api_htmlentities(get_lang('Modify'),ENT_QUOTES,$charset); ?>" /></a>
  949. <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); ?>" />
  950. <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>
  951. <?php
  952. // if active
  953. if ($active) {
  954. $nbrActiveTests = $nbrActiveTests +1;
  955. ?>
  956. <a href="<?php echo $exercicePath; ?>?hpchoice=disable&amp;page=<?php echo $page; ?>&amp;file=<?php echo $path; ?>"><img src="../img/visible.gif" border="0" alt="<?php echo api_htmlentities(get_lang('Deactivate'),ENT_QUOTES,$charset); ?>" /></a>
  957. <?php
  958. } else { // else if not active
  959. ?>
  960. <a href="<?php echo $exercicePath; ?>?hpchoice=enable&amp;page=<?php echo $page; ?>&amp;file=<?php echo $path; ?>"><img src="../img/invisible.gif" border="0" alt="<?php echo api_htmlentities(get_lang('Activate'),ENT_QUOTES,$charset); ?>" /></a>
  961. <?php
  962. }
  963. echo '<img src="../img/lp_quiz_na.gif" border="0" alt="" />';
  964. /****************/
  965. ?></td>
  966. <?php
  967. } else { // student only
  968. if ($active == 1) {
  969. $nbrActiveTests = $nbrActiveTests +1;
  970. ?>
  971. <tr>
  972. <td><?php echo ($ind+($page*$limitExPage)).'.'; ?><!--<img src="../img/jqz.jpg" alt="HotPotatoes" />--></td>
  973. <td>&nbsp;</td>
  974. <td><a href="showinframes.php?<?php echo api_get_cidreq()."&amp;file=".$path."&amp;cid=".$_course['official_code']."&amp;uid=".$_user['user_id'].'"'; if(!$active) echo 'class="invisible"'; ?>"><?php echo $title;?></a></td>
  975. <td>&nbsp;</td><td>&nbsp;</td>
  976. </tr>
  977. <?php
  978. }
  979. }
  980. ?>
  981. <?php
  982. if ($ind == $limitExPage) {
  983. break;
  984. }
  985. if ($is_allowedToEdit) {
  986. $ind++;
  987. } else {
  988. if ($active == 1) {
  989. $ind++;
  990. }
  991. }
  992. }
  993. }
  994. } //end if ($origin != 'learnpath') {
  995. ?>
  996. </table>
  997. <?php
  998. }
  999. /*****************************************/
  1000. /* Exercise Results (uses tracking tool) */
  1001. /*****************************************/
  1002. // if tracking is enabled
  1003. if ($_configuration['tracking_enabled'] && ($show == 'result')) {
  1004. ?>
  1005. <!--<table class="data_table">
  1006. <tr class="row_odd">
  1007. <?php if($is_allowedToEdit || $is_tutor): ?>
  1008. <th><?php echo get_lang('User'); ?></th><?php endif; ?>
  1009. <th><?php echo get_lang('Exercice'); ?></th>
  1010. <th><?php echo get_lang('Duration'); ?></th>
  1011. <th><?php echo get_lang('Date'); ?></th>
  1012. <th><?php echo get_lang('Result'); ?></th>
  1013. <th><?php echo (($is_allowedToEdit||$is_tutor)?get_lang("CorrectTest"):get_lang("ViewTest")); ?></th>
  1014. </tr>-->
  1015. <?php
  1016. $session_id_and = '';
  1017. if (api_get_session_id() != 0) {
  1018. $session_id_and = ' AND session_id = ' . api_get_session_id() . ' ';
  1019. }
  1020. if ($is_allowedToEdit || $is_tutor) {
  1021. $user_id_and = '';
  1022. if (!empty ($_POST['filter_by_user'])) {
  1023. if ($_POST['filter_by_user'] == 'all') {
  1024. $user_id_and = " AND user_id like '%'";
  1025. } else {
  1026. $user_id_and = " AND user_id = '" . Database :: escape_string((int) $_POST['filter_by_user']) . "' ";
  1027. }
  1028. }
  1029. if ($_GET['gradebook'] == 'view') {
  1030. $exercise_where_query = 'te.exe_exo_id =ce.id AND ';
  1031. }
  1032. $sql="SELECT ".(api_is_western_name_order() ? "CONCAT(firstname,' ',lastname)" : "CONCAT(lastname,' ',firstname)")." as users, ce.title, te.exe_result ,
  1033. te.exe_weighting, UNIX_TIMESTAMP(te.exe_date), te.exe_id, email, UNIX_TIMESTAMP(te.start_date), steps_counter,cuser.user_id,te.exe_duration
  1034. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  1035. WHERE user.user_id=cuser.user_id AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
  1036. AND cuser.status<>1 $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0
  1037. AND cuser.course_code=te.exe_cours_id ORDER BY users, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";
  1038. $hpsql="SELECT ".(api_is_western_name_order() ? "CONCAT(tu.firstname,' ',tu.lastname)" : "CONCAT(tu.lastname,' ',tu.firstname)").", tth.exe_name,
  1039. tth.exe_result , tth.exe_weighting, UNIX_TIMESTAMP(tth.exe_date)
  1040. FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
  1041. WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . Database :: escape_string($_cid) . " $user_id_and '
  1042. ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
  1043. } else {
  1044. // get only this user's results
  1045. $user_id_and = ' AND te.exe_user_id = ' . Database :: escape_string(api_get_user_id()) . ' ';
  1046. $sql="SELECT ".(api_is_western_name_order() ? "CONCAT(firstname,' ',lastname)" : "CONCAT(lastname,' ',firstname)")." as users,ce.title, te.exe_result ,
  1047. te.exe_weighting, UNIX_TIMESTAMP(te.exe_date), te.exe_id, email, UNIX_TIMESTAMP(te.start_date), steps_counter,cuser.user_id,te.exe_duration, ce.results_disabled
  1048. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  1049. WHERE user.user_id=cuser.user_id AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
  1050. AND cuser.status<>1 $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0
  1051. AND cuser.course_code=te.exe_cours_id ORDER BY users, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";
  1052. $hpsql = "SELECT '',exe_name, exe_result , exe_weighting, UNIX_TIMESTAMP(exe_date)
  1053. FROM $TBL_TRACK_HOTPOTATOES
  1054. WHERE exe_user_id = '" . $_user['user_id'] . "' AND exe_cours_id = '" . Database :: escape_string($_cid) . "'
  1055. ORDER BY exe_cours_id ASC, exe_date DESC";
  1056. }
  1057. $results = getManyResultsXCol($sql, 12);
  1058. $hpresults = getManyResultsXCol($hpsql, 5);
  1059. $NoTestRes = 0;
  1060. $NoHPTestRes = 0;
  1061. //Print the results of tests
  1062. $lang_nostartdate = get_lang('NoStartDate') . ' / ';
  1063. if (is_array($results)) {
  1064. $users_array_id = array ();
  1065. if ($_GET['gradebook'] == 'view') {
  1066. $filter_by_no_revised = true;
  1067. $from_gradebook = true;
  1068. }
  1069. $sizeof = sizeof($results);
  1070. $user_list_id = array ();
  1071. $user_list_name = '';
  1072. $quiz_name_list = '';
  1073. $duration_list = '';
  1074. $date_list = '';
  1075. $result_list = '';
  1076. $more_details_list = '';
  1077. $list_info = array();
  1078. for ($i = 0; $i < $sizeof; $i++) {
  1079. $revised = false;
  1080. $sql_exe = 'SELECT exe_id FROM ' . Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING) . '
  1081. WHERE author != ' . "''" . ' AND exe_id = ' . "'" . Database :: escape_string($results[$i][5]) . "'" . ' LIMIT 1';
  1082. $query = Database::query($sql_exe, __FILE__, __LINE__);
  1083. if (Database :: num_rows($query) > 0) {
  1084. $revised = true;
  1085. }
  1086. if ($filter_by_not_revised && $revised == true) {
  1087. continue;
  1088. }
  1089. if ($filter_by_revised && $revised == false) {
  1090. continue;
  1091. }
  1092. if ($from_gradebook && ($is_allowedToEdit || $is_tutor)) {
  1093. if (in_array($results[$i][1] . $results[$i][0], $users_array_id)) {
  1094. continue;
  1095. }
  1096. $users_array_id[] = $results[$i][1] . $results[$i][0];
  1097. }
  1098. $user_list_name = $results[$i][0];
  1099. $user_list_id[] = $results[$i][9];
  1100. $id = $results[$i][5];
  1101. $mailid = $results[$i][6];
  1102. $user = $results[$i][0];
  1103. $test = $results[$i][1];
  1104. $quiz_name_list = $test;
  1105. $dt = strftime($dateTimeFormatLong, $results[$i][4]);
  1106. $res = $results[$i][2];
  1107. $duration = intval($results[$i][10]);
  1108. // we filter the results if we have the permission to
  1109. if (isset ($results[$i][11]))
  1110. $result_disabled = intval($results[$i][11]);
  1111. else
  1112. $result_disabled = 0;
  1113. if ($result_disabled == 0) {
  1114. //echo '<tr';
  1115. //if ($i % 2 == 0) {
  1116. //echo 'class="row_odd"';
  1117. //} else {
  1118. //echo 'class="row_even"';
  1119. //}
  1120. //echo '>';
  1121. $add_start_date = $lang_nostartdate;
  1122. if ($is_allowedToEdit || $is_tutor) {
  1123. $user = $results[$i][0];
  1124. //echo '<td>' . $user . ' </td>';
  1125. }
  1126. //echo '<td>' . $test . '</td>';
  1127. //echo '<td>';
  1128. if ($results[$i][7] > 1) {
  1129. //echo ceil((($results[$i][4] - $results[$i][7]) / 60)) . ' ' . get_lang('MinMinutes');
  1130. $duration_list = ceil((($results[$i][4] - $results[$i][7]) / 60)) . ' ' . get_lang('MinMinutes');
  1131. if ($results[$i][8] > 1) {
  1132. //echo ' ( ' . $results[$i][8] . ' ' . get_lang('Steps') . ' )';
  1133. $duration_list = ' ( ' . $results[$i][8] . ' ' . get_lang('Steps') . ' )';
  1134. }
  1135. $add_start_date = format_locale_date('%b %d, %Y %H:%M', $results[$i][7]) . ' / ';
  1136. } else {
  1137. $duration_list = get_lang('NoLogOfDuration');
  1138. //echo get_lang('NoLogOfDuration');
  1139. }
  1140. //echo '</td>';
  1141. //echo '<td>' . $add_start_date . format_locale_date('%b %d, %Y %H:%M', $results[$i][4]) . '</td>'; //get_lang('dateTimeFormatLong')
  1142. $date_list = $add_start_date . format_locale_date('%b %d, %Y %H:%M', $results[$i][4]);
  1143. // there are already a duration test period calculated??
  1144. //echo '<td>'.sprintf(get_lang('DurationFormat'), $duration).'</td>';
  1145. // if the float look like 10.00 we show only 10
  1146. $my_res = float_format($results[$i][2],1);
  1147. $my_total = float_format($results[$i][3],1);
  1148. //echo '<td>' . round(($my_res / ($my_total != 0 ? $my_total : 1)) * 100, 2) . '% (' . $my_res . ' / ' . $my_total . ')</td>';
  1149. $result_list = round(($my_res / ($my_total != 0 ? $my_total : 1)) * 100, 2) . '% (' . $my_res . ' / ' . $my_total . ')';
  1150. // Is hard to read this!!
  1151. /*
  1152. echo '<td>'.(($is_allowedToEdit||$is_tutor)?
  1153. "<a href='exercise_show.php?user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".
  1154. (($revised)?get_lang('Edit'):get_lang('Qualify'))."</a>".
  1155. ((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>':'')
  1156. .(($is_allowedToEdit)?' - <a href="exercice_history.php?cidReq='.htmlentities($_GET['cidReq']).'&exe_id='.$id.'">'.get_lang('ViewHistoryChange').'</a>':'')
  1157. :(($revised)?"<a href='exercise_show.php?dt=$dt&res=$res&id=$id'>".get_lang('Show')."</a>":'')).'</td>';
  1158. */
  1159. //echo '<td>';
  1160. $html_link = '';
  1161. if ($is_allowedToEdit || $is_tutor) {
  1162. if ($revised) {
  1163. //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'));
  1164. //echo '&nbsp;';
  1165. $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'));
  1166. $html_link.= '&nbsp;';
  1167. } else {
  1168. //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'));
  1169. //echo '&nbsp;';
  1170. $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'));
  1171. $html_link.='&nbsp;';
  1172. }
  1173. //echo "</a>";
  1174. $html_link.="</a>";
  1175. if (api_is_platform_admin() || $is_tutor) {
  1176. //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>';
  1177. //echo '&nbsp;';
  1178. $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>';
  1179. $html_link.='&nbsp;';
  1180. }
  1181. if ($is_allowedToEdit) {
  1182. //echo ' <a href="exercice_history.php?cidReq=' . security::remove_XSS($_GET['cidReq']) . '&exe_id=' . $id . '">' .Display :: return_icon('history.gif', get_lang('ViewHistoryChange')).'</a>';
  1183. if ($filter==2){
  1184. $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>';
  1185. }
  1186. }
  1187. } else {
  1188. if ($revised) {
  1189. //echo "<a href='exercise_show.php?dt=$dt&res=$res&id=$id'>" . get_lang('Show') . "</a> ";
  1190. $html_link.="<a href='exercise_show.php?dt=$dt&res=$res&id=$id'>" . get_lang('Show') . "</a> ";
  1191. } else {
  1192. // echo '&nbsp;' . get_lang('NoResult');
  1193. $html_link.='&nbsp;' . get_lang('NoResult');
  1194. }
  1195. }
  1196. $more_details_list = $html_link;
  1197. if ($is_allowedToEdit || $is_tutor) {
  1198. $list_info [] = array($user_list_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
  1199. } else {
  1200. $list_info [] = array($quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
  1201. }
  1202. //$list_info [] = array($user_list_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
  1203. //echo '</td>';
  1204. //echo '</tr>';
  1205. }
  1206. }
  1207. ////////////////////////////////////////////////////////////////////////////////
  1208. //Code added by Isaac flores
  1209. $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']));
  1210. $table = new SortableTableFromArrayConfig($list_info, 1,20,'quiz_table');
  1211. $table->set_additional_parameters($parameters);
  1212. if ($is_allowedToEdit || $is_tutor) {
  1213. $table->set_header(0, get_lang('User'));
  1214. $secuence = 0;
  1215. } else {
  1216. $secuence = 1;
  1217. }
  1218. $table->set_header(-$secuence + 1, get_lang('Exercice'));
  1219. $table->set_header(-$secuence + 2, get_lang('Duration'),false);
  1220. $table->set_header(-$secuence + 3, get_lang('Date'));
  1221. $table->set_header(-$secuence + 4, get_lang('Result'),false);
  1222. $table->set_header(-$secuence + 5, (($is_allowedToEdit||$is_tutor) ? get_lang("CorrectTest") : get_lang("ViewTest")), false);
  1223. $table->display();
  1224. //////////////////////////////////////////////////////////////////////////////////
  1225. } else {
  1226. $NoTestRes = 1;
  1227. }
  1228. // Print the Result of Hotpotatoes Tests
  1229. if (is_array($hpresults)) {
  1230. for ($i = 0; $i < sizeof($hpresults); $i++) {
  1231. $title = GetQuizName($hpresults[$i][1], $documentPath);
  1232. if ($title == '') {
  1233. $title = basename($hpresults[$i][1]);
  1234. }
  1235. echo '<tr>';
  1236. if ($is_allowedToEdit) {
  1237. echo '<td class="content">' . $hpresults[$i][0] . '</td>';
  1238. }
  1239. echo '<td class="content">' . $title . '</td>';
  1240. echo '<td class="content">' . strftime($dateTimeFormatLong, $hpresults[$i][4]) . '</td>';
  1241. 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>';
  1242. echo '<td></td>'; //there is no possibility to edit the results of a Hotpotatoes test
  1243. echo '</tr>';
  1244. }
  1245. } else {
  1246. $NoHPTestRes = 1;
  1247. }
  1248. if ($NoTestRes == 1 && $NoHPTestRes == 1) {
  1249. ?>
  1250. <tr>
  1251. <td colspan="6"><?php echo get_lang("NoResult"); ?></td>
  1252. </tr>
  1253. <?php
  1254. }
  1255. ?>
  1256. </table>
  1257. <br />
  1258. <?php
  1259. }
  1260. if ($origin != 'learnpath') { //so we are not in learnpath tool
  1261. Display :: display_footer();
  1262. } else {
  1263. ?>
  1264. <link rel="stylesheet" type="text/css" href="<?php echo $clarolineRepositoryWeb ?>css/default.css" />
  1265. <?php
  1266. }
  1267. ?>