exercice.php 62 KB

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