exercice.php 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  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. */
  11. // name of the language file that needs to be included
  12. $language_file = array('exercice','tracking');
  13. // including the global library
  14. require_once '../inc/global.inc.php';
  15. require_once api_get_path(LIBRARY_PATH).'sortabletable.class.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 'exercise.lib.php';
  25. require_once 'question.class.php';
  26. require_once 'answer.class.php';
  27. require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
  28. require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
  29. require_once 'hotpotatoes.lib.php';
  30. require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
  31. require_once api_get_path(LIBRARY_PATH) . 'mail.lib.inc.php';
  32. require_once api_get_path(LIBRARY_PATH) . 'usermanager.lib.php';
  33. /* Constants and variables */
  34. $is_allowedToEdit = api_is_allowed_to_edit(null,true);
  35. $is_tutor = api_is_allowed_to_edit(true);
  36. $is_tutor_course = api_is_course_tutor();
  37. $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  38. $TBL_USER = Database :: get_main_table(TABLE_MAIN_USER);
  39. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  40. $TBL_ITEM_PROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  41. $TBL_EXERCICE_ANSWER = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  42. $TBL_EXERCICE_QUESTION = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  43. $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST);
  44. $TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  45. $TBL_TRACK_EXERCICES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  46. $TBL_TRACK_HOTPOTATOES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  47. $TBL_TRACK_ATTEMPT = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  48. $TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  49. $TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  50. $TBL_LP_ITEM = Database :: get_course_table(TABLE_LP_ITEM);
  51. $TBL_LP_VIEW = Database :: get_course_table(TABLE_LP_VIEW);
  52. // document path
  53. $documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . "/document";
  54. // picture path
  55. $picturePath = $documentPath . '/images';
  56. // audio path
  57. $audioPath = $documentPath . '/audio';
  58. // hotpotatoes
  59. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  60. $exercicePath = api_get_self();
  61. $exfile = explode('/', $exercicePath);
  62. $exfile = strtolower($exfile[sizeof($exfile) - 1]);
  63. $exercicePath = substr($exercicePath, 0, strpos($exercicePath, $exfile));
  64. $exercicePath = $exercicePath . "exercice.php";
  65. if ($show == 'result') {
  66. if (empty($_GET['exerciseId']) && empty($_GET['path']) ) {
  67. //header('Location: exercice.php?' . api_get_cidreq());
  68. }
  69. }
  70. // maximum number of exercises on a same page
  71. $limitExPage = 50;
  72. // Clear the exercise session
  73. if (isset ($_SESSION['objExercise'])) {
  74. api_session_unregister('objExercise');
  75. }
  76. if (isset ($_SESSION['objQuestion'])) {
  77. api_session_unregister('objQuestion');
  78. }
  79. if (isset ($_SESSION['objAnswer'])) {
  80. api_session_unregister('objAnswer');
  81. }
  82. if (isset ($_SESSION['questionList'])) {
  83. api_session_unregister('questionList');
  84. }
  85. if (isset ($_SESSION['exerciseResult'])) {
  86. api_session_unregister('exerciseResult');
  87. }
  88. //General POST/GET/SESSION/COOKIES parameters recovery
  89. if (empty ($origin)) {
  90. $origin = Security::remove_XSS($_REQUEST['origin']);
  91. }
  92. if (empty ($choice)) {
  93. $choice = $_REQUEST['choice'];
  94. }
  95. if (empty ($hpchoice)) {
  96. $hpchoice = $_REQUEST['hpchoice'];
  97. }
  98. if (empty ($exerciseId)) {
  99. $exerciseId = intval($_REQUEST['exerciseId']);
  100. }
  101. if (empty ($file)) {
  102. $file = Database :: escape_string($_REQUEST['file']);
  103. }
  104. $learnpath_id = intval($_REQUEST['learnpath_id']);
  105. $learnpath_item_id = intval($_REQUEST['learnpath_item_id']);
  106. $page = intval($_REQUEST['page']);
  107. if ($origin == 'learnpath') {
  108. $show = 'result';
  109. }
  110. //Deleting an attempt
  111. if ($_GET['delete'] == 'delete' && ($is_allowedToEdit || api_is_coach()) && !empty ($_GET['did']) && $_GET['did'] == strval(intval($_GET['did']))) {
  112. $sql = 'DELETE FROM ' . Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES) . ' WHERE exe_id = ' . $_GET['did']; //_GET[did] filtered by entry condition
  113. Database::query($sql);
  114. $filter=Security::remove_XSS($_GET['filter']);
  115. header('Location: exercice.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&show=result&filter=' . $filter . '&exerciseId='.$exerciseId);
  116. exit;
  117. }
  118. //Send student email @todo move this code in a class, library
  119. if ($show == 'result' && $_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_GET['exeid']== strval(intval($_GET['exeid']))) {
  120. $id = intval($_GET['exeid']); //filtered by post-condition
  121. $track_exercise_info = get_exercise_track_exercise_info($id);
  122. if (empty($track_exercise_info)) {
  123. api_not_allowed();
  124. }
  125. $test = $track_exercise_info['title'];
  126. $student_id = $track_exercise_info['exe_user_id'];
  127. $course_id = $track_exercise_info['exe_cours_id'];
  128. $session_id = $track_exercise_info['session_id'];
  129. $lp_id = $track_exercise_info['orig_lp_id'];
  130. $lp_item_id = $track_exercise_info['orig_lp_item_id'];
  131. $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
  132. $user_info = api_get_user_info($student_id);
  133. $student_email = $user_info['mail'];
  134. //Teacher data?
  135. $from = $_SESSION['_user']['mail'];
  136. $from_name = api_get_person_name($_SESSION['_user']['firstName'], $_SESSION['_user']['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
  137. $url = api_get_path(WEB_CODE_PATH) . 'exercice/exercice.php?' . api_get_cidreq() . '&show=result';
  138. $total_weighting = $_REQUEST['totalWeighting'];
  139. $my_post_info = array();
  140. $post_content_id = array();
  141. $comments_exist = false;
  142. foreach ($_POST as $key_index=>$key_value) {
  143. $my_post_info = explode('_',$key_index);
  144. $post_content_id[]=$my_post_info[1];
  145. if ($my_post_info[0]=='comments') {
  146. $comments_exist=true;
  147. }
  148. }
  149. $loop_in_track=($comments_exist===true) ? (count($_POST)/2) : count($_POST);
  150. $array_content_id_exe=array();
  151. if ($comments_exist===true) {
  152. $array_content_id_exe=array_slice($post_content_id,$loop_in_track);
  153. } else {
  154. $array_content_id_exe=$post_content_id;
  155. }
  156. for ($i=0;$i<$loop_in_track;$i++) {
  157. $my_marks = Database::escape_string($_POST['marks_'.$array_content_id_exe[$i]]);
  158. $contain_comments = Database::escape_string($_POST['comments_'.$array_content_id_exe[$i]]);
  159. if (isset($contain_comments)) {
  160. $my_comments = Database::escape_string($_POST['comments_'.$array_content_id_exe[$i]]);
  161. } else {
  162. $my_comments = '';
  163. }
  164. $my_questionid=$array_content_id_exe[$i];
  165. $sql = "SELECT question from $TBL_QUESTIONS WHERE id = '$my_questionid'";
  166. $result =Database::query($sql);
  167. $ques_name = Database::result($result,0,"question");
  168. $query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '$my_marks',teacher_comment = '$my_comments' WHERE question_id = '".$my_questionid."' AND exe_id='".$id."'";
  169. Database::query($query);
  170. //Not necessary to update the weight
  171. /*
  172. $qry = 'SELECT sum(marks) as tot FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$id;
  173. $res = Database::query($qry);
  174. $tot = Database::result($res,0,'tot');
  175. //updating also the total weight
  176. $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".intval($tot)."', exe_weighting = '".Database::escape_string($total_weighting)."'
  177. WHERE exe_Id='".$id."'";
  178. Database::query($totquery);
  179. */
  180. //Saving results in the track recording table
  181. $recording_changes = 'INSERT INTO '.$TBL_TRACK_ATTEMPT_RECORDING.' (exe_id, question_id, marks, insert_date, author, teacher_comment) VALUES
  182. ('."'$id','".$my_questionid."','$my_marks','".api_get_utc_datetime()."','".api_get_user_id()."'".',"'.$my_comments.'")';
  183. Database::query($recording_changes);
  184. }
  185. $qry = 'SELECT DISTINCT question_id, marks FROM ' . $TBL_TRACK_ATTEMPT . ' where exe_id = ' . $id . ' GROUP BY question_id';
  186. $res = Database::query($qry);
  187. $tot = 0;
  188. while ($row = Database :: fetch_array($res, 'ASSOC')) {
  189. $tot += $row['marks'];
  190. }
  191. $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '" . floatval($tot) . "' WHERE exe_id='" . $id . "'";
  192. Database::query($totquery);
  193. $subject = get_lang('ExamSheetVCC');
  194. $htmlmessage = '<html>' .
  195. '<head>' .
  196. '<style type="text/css">' .
  197. '<!--' .
  198. '.body{' .
  199. 'font-family: Verdana, Arial, Helvetica, sans-serif;' .
  200. 'font-weight: Normal;' .
  201. 'color: #000000;' .
  202. '}' .
  203. '.style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; color: #006699; }' .
  204. '.style10 {' .
  205. ' font-family: Verdana, Arial, Helvetica, sans-serif;' .
  206. ' font-size: 12px;' .
  207. ' font-weight: bold;' .
  208. '}' .
  209. '.style16 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }' .
  210. '-->' .
  211. '</style>' .
  212. '</head>' .
  213. '<body>' .
  214. '<div>' .
  215. ' <p>' . get_lang('DearStudentEmailIntroduction') . '</p>' .
  216. ' <p class="style10"> ' . get_lang('AttemptVCC') . ' </p>' .
  217. ' <table width="417">' .
  218. ' <tr>' .
  219. ' <td width="229" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">' . get_lang('Question') . '</span></td>' .
  220. ' <td width="469" valign="top" bgcolor="#F3F3F3"><span class="style16">#ques_name#</span></td>' .
  221. ' </tr>' .
  222. ' <tr>' .
  223. ' <td width="229" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">' . get_lang('Exercice') . '</span></td>' .
  224. ' <td width="469" valign="top" bgcolor="#F3F3F3"><span class="style16">#test#</span></td>' .
  225. ' </tr>' .
  226. ' </table>' .
  227. ' <p>' . get_lang('ClickLinkToViewComment') . ' <a href="#url#">#url#</a><br />' .
  228. ' <br />' .
  229. ' ' . get_lang('Regards') . ' </p>' .
  230. ' </div>' .
  231. ' </body>' .
  232. ' </html>';
  233. $message = '<p>' . sprintf(get_lang('AttemptVCCLong'), Security::remove_XSS($test)) . ' <A href="#url#">#url#</A></p><br />';
  234. $mess = str_replace("#test#", Security::remove_XSS($test), $message);
  235. //$message= str_replace("#ques_name#",$ques_name,$mess);
  236. $message = str_replace("#url#", $url, $mess);
  237. $mess = $message;
  238. $headers = " MIME-Version: 1.0 \r\n";
  239. $headers .= "User-Agent: Chamilo/1.8";
  240. $headers .= "Content-Transfer-Encoding: 7bit";
  241. $headers .= 'From: ' . $from_name . ' <' . $from . '>' . "\r\n";
  242. $headers = "From:$from_name\r\nReply-to: $to";
  243. @api_mail_html($student_email, $student_email, $subject, $mess, $from_name, $from);
  244. //Updating LP score here
  245. if (in_array($origin, array ('tracking_course','user_course','correct_exercise_in_lp'))) {
  246. /*
  247. * We do not need this because lp_item_view_id comes to the rescue
  248. *
  249. //Checking if this is the lastest attempt
  250. $sql = "SELECT exe_id FROM $TBL_TRACK_EXERCICES
  251. WHERE exe_user_id = '" . Database :: escape_string($_POST['student_id']) . "' AND exe_cours_id = '" . api_get_course_id() . "' AND orig_lp_id = '$lp_item_id' AND orig_lp_item_id = '$lp_item_view_id' AND session_id = '" . api_get_session_id() . "' AND status = ''
  252. ORDER BY exe_id DESC LIMIT 1 ";
  253. $res_view_count = Database::query($sql);
  254. $res_view_count = Database :: fetch_row($res_view_count);
  255. $my_view_count = intval($res_view_count[0]);
  256. //Update lp_item_view if this attempts is the latest
  257. $sql = "SELECT MAX(view_count) FROM $TBL_LP_ITEM_VIEW
  258. WHERE lp_item_id = '" . (int) $lp_item_view_id . "' AND lp_view_id = (SELECT id from $TBL_LP_VIEW WHERE user_id = '" . (int) $student_id . "' and lp_id='" . (int) $lp_item_id . "')";
  259. $res_max_view_count = Database::query($sql);
  260. $row_max_view_count = Database :: fetch_row($res_max_view_count);
  261. $max_view_count = intval($row_max_view_count[0]);
  262. //Only update if is the last attempt
  263. if ($my_view_count == $_GET['exeid']) {
  264. // update score and total_time from last attempt when you qualify the exercise in Learning path detail
  265. $sql_update_score = "UPDATE $TBL_LP_ITEM_VIEW SET score = '" . intval($tot) . "' WHERE lp_item_id = '" . (int) $lp_item_view_id . "'
  266. 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'";
  267. Database::query($sql_update_score);
  268. }*/
  269. $sql_update_score = "UPDATE $TBL_LP_ITEM_VIEW SET score = '" . intval($tot) . "' WHERE id = " .$lp_item_view_id;
  270. Database::query($sql_update_score);
  271. if ($origin == 'tracking_course') {
  272. //Redirect to the course detail in lp
  273. header('location: exercise.php?course=' . Security :: remove_XSS($_GET['course']));
  274. //header('location: ../mySpace/lp_tracking.php?course=' . api_get_course_id() . '&origin=' . $origin . '&my_lp_id=' . $lp_item_id . '&lp_id=' . $lp_id . '&student_id=' . $student_id.'&extend_attempt=1&from='.Security::remove_XSS($_GET['from']));
  275. exit;
  276. } else {
  277. //Redirect to the reporting
  278. header('location: ../mySpace/myStudents.php?origin=' . $origin . '&student=' . $student_id . '&details=true&course=' . $course_id.'&session_id='.$session_id);
  279. exit;
  280. }
  281. }
  282. }
  283. if (!empty($_GET['gradebook']) && $_GET['gradebook']=='view' ) {
  284. $_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
  285. $gradebook= $_SESSION['gradebook'];
  286. } elseif (empty($_GET['gradebook'])) {
  287. unset($_SESSION['gradebook']);
  288. $gradebook= '';
  289. }
  290. if (!empty($gradebook) && $gradebook=='view') {
  291. $interbreadcrumb[] = array ('url' => '../gradebook/' . $_SESSION['gradebook_dest'],'name' => get_lang('ToolGradebook'));
  292. }
  293. if ($show != 'result') {
  294. $nameTools = get_lang('Exercices');
  295. } else {
  296. if ($is_allowedToEdit || $is_tutor) {
  297. $nameTools = get_lang('StudentScore');
  298. $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
  299. } else {
  300. $nameTools = get_lang('YourScore');
  301. $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
  302. }
  303. }
  304. // need functions of statsutils lib to display previous exercices scores
  305. require_once (api_get_path(LIBRARY_PATH) . 'statsUtils.lib.inc.php');
  306. if ($is_allowedToEdit && !empty ($choice) && $choice == 'exportqti2') {
  307. require_once 'export/qti2/qti2_export.php';
  308. $export = export_exercise($exerciseId, true);
  309. require_once api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php';
  310. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  311. $temp_dir_short = uniqid();
  312. $temp_zip_dir = $archive_path . "/" . $temp_dir_short;
  313. if (!is_dir($temp_zip_dir))
  314. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  315. $temp_zip_file = $temp_zip_dir . "/" . md5(time()) . ".zip";
  316. $temp_xml_file = $temp_zip_dir . "/qti2export_" . $exerciseId . '.xml';
  317. file_put_contents($temp_xml_file, $export);
  318. $zip_folder = new PclZip($temp_zip_file);
  319. $zip_folder->add($temp_xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
  320. $name = 'qti2_export_' . $exerciseId . '.zip';
  321. //DocumentManager::string_send_for_download($export,true,'qti2export_'.$exerciseId.'.xml');
  322. DocumentManager :: file_send_for_download($temp_zip_file, true, $name);
  323. unlink($temp_zip_file);
  324. unlink($temp_xml_file);
  325. rmdir($temp_zip_dir);
  326. exit (); //otherwise following clicks may become buggy
  327. }
  328. if (!empty ($_POST['export_user_fields'])) {
  329. switch ($_POST['export_user_fields']) {
  330. case 'export_user_fields' :
  331. $_SESSION['export_user_fields'] = true;
  332. break;
  333. case 'do_not_export_user_fields' :
  334. default :
  335. $_SESSION['export_user_fields'] = false;
  336. break;
  337. }
  338. }
  339. if (!empty ($_POST['export_report']) && $_POST['export_report'] == 'export_report') {
  340. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
  341. $user_id = null;
  342. if (empty ($_SESSION['export_user_fields']))
  343. $_SESSION['export_user_fields'] = false;
  344. if (!$is_allowedToEdit and !$is_tutor) {
  345. $user_id = api_get_user_id();
  346. }
  347. require_once ('exercise_result.class.php');
  348. switch ($_POST['export_format']) {
  349. case 'xls' :
  350. $export = new ExerciseResult();
  351. $export->exportCompleteReportXLS($documentPath, $user_id, $_SESSION['export_user_fields'], $_POST['export_filter'],$_POST['exerciseId'], $_POST['hotpotato_name']);
  352. exit;
  353. break;
  354. case 'csv' :
  355. default :
  356. $export = new ExerciseResult();
  357. $export->exportCompleteReportCSV($documentPath, $user_id, $_SESSION['export_user_fields'], $_POST['export_filter'],$_POST['exerciseId'], $_POST['hotpotato_name']);
  358. exit;
  359. break;
  360. }
  361. } else {
  362. api_not_allowed(true);
  363. }
  364. }
  365. if ($origin != 'learnpath') {
  366. //so we are not in learnpath tool
  367. Display :: display_header($nameTools, get_lang('Exercise'));
  368. if (isset ($_GET['message'])) {
  369. if (in_array($_GET['message'], array ('ExerciseEdited'))) {
  370. Display :: display_confirmation_message(get_lang($_GET['message']));
  371. }
  372. }
  373. } else {
  374. echo '<link rel="stylesheet" type="text/css" href="' . api_get_path(WEB_CODE_PATH) . 'css/default.css"/>';
  375. }
  376. event_access_tool(TOOL_QUIZ);
  377. // Tool introduction
  378. Display :: display_introduction_section(TOOL_QUIZ);
  379. HotPotGCt($documentPath, 1, $_user['user_id']);
  380. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  381. // only for administrator
  382. if ($is_allowedToEdit) {
  383. if (!empty ($choice)) {
  384. // construction of Exercise
  385. $objExerciseTmp = new Exercise();
  386. $check = Security::check_token('get');
  387. if ($objExerciseTmp->read($exerciseId)) {
  388. if ($check) {
  389. switch ($choice) {
  390. case 'delete' : // deletes an exercise
  391. $objExerciseTmp->delete();
  392. //delete link of exercise of gradebook tool
  393. $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="1" AND gl.ref_id="' . $exerciseId . '";';
  394. $result = Database::query($sql);
  395. $row = Database :: fetch_array($result, 'ASSOC');
  396. //see
  397. if (!empty($row['id'])) {
  398. $link = LinkFactory :: load($row['id']);
  399. if ($link[0] != null) {
  400. $link[0]->delete();
  401. }
  402. }
  403. Display :: display_confirmation_message(get_lang('ExerciseDeleted'));
  404. break;
  405. case 'enable' : // enables an exercise
  406. $objExerciseTmp->enable();
  407. $objExerciseTmp->save();
  408. // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
  409. Display :: display_confirmation_message(get_lang('VisibilityChanged'));
  410. break;
  411. case 'disable' : // disables an exercise
  412. $objExerciseTmp->disable();
  413. $objExerciseTmp->save();
  414. Display :: display_confirmation_message(get_lang('VisibilityChanged'));
  415. break;
  416. case 'disable_results' : //disable the results for the learners
  417. $objExerciseTmp->disable_results();
  418. $objExerciseTmp->save();
  419. Display :: display_confirmation_message(get_lang('ResultsDisabled'));
  420. break;
  421. case 'enable_results' : //disable the results for the learners
  422. $objExerciseTmp->enable_results();
  423. $objExerciseTmp->save();
  424. Display :: display_confirmation_message(get_lang('ResultsEnabled'));
  425. break;
  426. case 'clean_results' : //clean student results
  427. $quantity_results_deleted= $objExerciseTmp->clean_results();
  428. Display :: display_confirmation_message(sprintf(get_lang('XResultsCleaned'),$quantity_results_deleted));
  429. break;
  430. case 'copy_exercise' : //copy an exercise
  431. $objExerciseTmp->copy_exercise();
  432. Display :: display_confirmation_message(get_lang('ExerciseCopied'));
  433. break;
  434. }
  435. }
  436. }
  437. // destruction of Exercise
  438. unset ($objExerciseTmp);
  439. Security::clear_token();
  440. }
  441. if (!empty ($hpchoice)) {
  442. switch ($hpchoice) {
  443. case 'delete' : // deletes an exercise
  444. $imgparams = array ();
  445. $imgcount = 0;
  446. GetImgParams($file, $documentPath, $imgparams, $imgcount);
  447. $fld = GetFolderName($file);
  448. for ($i = 0; $i < $imgcount; $i++) {
  449. my_delete($documentPath . $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
  450. update_db_info("delete", $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
  451. }
  452. if (my_delete($documentPath . $file)) {
  453. update_db_info("delete", $file);
  454. }
  455. my_delete($documentPath . $uploadPath . "/" . $fld . "/");
  456. break;
  457. case 'enable' : // enables an exercise
  458. $newVisibilityStatus = "1"; //"visible"
  459. $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='" . Database :: escape_string($file) . "'";
  460. $res = Database::query($query);
  461. $row = Database :: fetch_array($res, 'ASSOC');
  462. api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'visible', $_user['user_id']);
  463. //$dialogBox = get_lang('ViMod');
  464. break;
  465. case 'disable' : // disables an exercise
  466. $newVisibilityStatus = "0"; //"invisible"
  467. $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='" . Database :: escape_string($file) . "'";
  468. $res = Database::query($query);
  469. $row = Database :: fetch_array($res, 'ASSOC');
  470. api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'invisible', $_user['user_id']);
  471. break;
  472. default :
  473. break;
  474. }
  475. }
  476. }
  477. // Actions div bar
  478. echo '<div class="actions">';
  479. // Display the next and previous link if needed
  480. // Selects $limitExPage exercises at the same time
  481. $from = $page * $limitExPage;
  482. $sql = "SELECT count(id) FROM $TBL_EXERCICES";
  483. $res = Database::query($sql);
  484. list ($nbrexerc) = Database :: fetch_array($res);
  485. HotPotGCt($documentPath, 1, api_get_user_id());
  486. //condition for the session
  487. $session_id = api_get_session_id();
  488. $condition_session = api_get_session_condition($session_id,true,true);
  489. if ($show == 'test') {
  490. // Only for administrators
  491. if ($is_allowedToEdit) {
  492. $sql = "SELECT id, title, type, active, description, results_disabled, session_id, start_time, end_time, random, max_attempt FROM $TBL_EXERCICES WHERE active<>'-1' $condition_session ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
  493. $result = Database::query($sql);
  494. } else {
  495. // Only for students
  496. $sql = "SELECT id, title, type, description, results_disabled, session_id, start_time, end_time , max_attempt FROM $TBL_EXERCICES WHERE active='1' $condition_session ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
  497. $result = Database::query($sql);
  498. }
  499. $nbrExercises = Database :: num_rows($result);
  500. //get HotPotatoes files (active and inactive)
  501. $res = Database::query("SELECT * FROM $TBL_DOCUMENT WHERE path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'");
  502. $nbrTests = Database :: num_rows($res);
  503. $res = Database::query("SELECT * FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  504. WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "'
  505. AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'
  506. AND ip.visibility='1'");
  507. $nbrActiveTests = Database :: num_rows($res);
  508. if ($is_allowedToEdit) {
  509. //if user is allowed to edit, also show hidden HP tests
  510. $nbrHpTests = $nbrTests;
  511. } else {
  512. $nbrHpTests = $nbrActiveTests;
  513. }
  514. $nbrNextTests = $nbrexerc - $nbrHpTests - (($page * $limitExPage));
  515. echo '<span style="float:right">';
  516. //show pages navigation link for previous page
  517. if ($page) {
  518. echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&amp;page=" . ($page -1) . "\">" . Display :: return_icon('previous.gif') . get_lang('PreviousPage') . "</a> | ";
  519. } elseif ($nbrExercises + $nbrNextTests > $limitExPage) {
  520. echo Display :: return_icon('previous.gif') . get_lang('PreviousPage') . " | ";
  521. }
  522. //show pages navigation link for previous page
  523. if ($nbrExercises + $nbrNextTests > $limitExPage) {
  524. echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&amp;page=" . ($page +1) . "\">" . get_lang("NextPage") . Display :: return_icon('next.gif') . "</a>";
  525. } elseif ($page) {
  526. echo get_lang('NextPage') . Display :: return_icon('next.gif');
  527. }
  528. echo '</span>';
  529. }
  530. if ($is_allowedToEdit && $origin != 'learnpath') {
  531. if ($_GET['show'] != 'result') {
  532. echo '<a href="exercise_admin.php?' . api_get_cidreq() . '">' . Display :: return_icon('new_exercice.png', get_lang('NewEx'),'','32').'</a>';
  533. echo '<a href="question_create.php?' . api_get_cidreq() . '">' . Display :: return_icon('new_question.png', get_lang('AddQ'),'','32').'</a>';
  534. echo '<a href="hotpotatoes.php?' . api_get_cidreq() . '">' . Display :: return_icon('import_hotpotatoes.png', get_lang('ImportHotPotatoesQuiz'),'','32').'</a>';
  535. // link to import qti2 ...
  536. echo '<a href="qti2.php?' . api_get_cidreq() . '">' . Display :: return_icon('import_qti2.png', get_lang('ImportQtiQuiz'),'','32') .'</a>';
  537. echo '<a href="upload_exercise.php?' . api_get_cidreq() . '">' . Display :: return_icon('import_excel.png', get_lang('ImportExcelQuiz'),'','32') .'</a>';
  538. }
  539. // the actions for the statistics
  540. if ($show == 'result') {
  541. // the form
  542. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
  543. if ($_SESSION['export_user_fields']) {
  544. $alt = get_lang('ExportWithUserFields');
  545. $extra_user_fields = '<input type="hidden" name="export_user_fields" value="export_user_fields">';
  546. } else {
  547. $alt = get_lang('ExportWithoutUserFields');
  548. $extra_user_fields = '<input type="hidden" name="export_user_fields" value="do_not_export_user_fields">';
  549. }
  550. echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=test') . '">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'','32').'</a>';
  551. echo '<a href="javascript: void(0);" onclick="javascript: document.form1a.submit();">'.Display::return_icon('export_csv.png',get_lang('ExportAsCSV'),'','32').'</a>';
  552. echo '<a href="javascript: void(0);" onclick="javascript: document.form1b.submit();">' . Display :: return_icon('export_excel.png', get_lang('ExportAsXLS'),'','32').'</a>';
  553. echo '<form id="form1a" name="form1a" method="post" action="' . api_get_self() . '?show=' . Security :: remove_XSS($_GET['show']) . '" style="display:inline">';
  554. echo '<input type="hidden" name="export_report" value="export_report">';
  555. echo '<input type="hidden" name="export_format" value="csv">';
  556. echo '<input type="hidden" name="exerciseId" value="'.intval($_GET['exerciseId']).'">';
  557. echo '<input type="hidden" name="hotpotato_name" value="'.Security::remove_XSS($_GET['path']).'">';
  558. if ($_GET['filter'] == '1' or !isset ($_GET['filter']) or $_GET['filter'] == 0 ) {
  559. $filter = 1;
  560. } else {
  561. $filter = 2;
  562. }
  563. echo '<input type="hidden" name="export_filter" value="'.(empty($filter)?1:intval($filter)).'">';
  564. echo '</form>';
  565. echo '<form id="form1b" name="form1b" method="post" action="' . api_get_self() . '?show=' . Security :: remove_XSS($_GET['show']) . '" style="display:inline">';
  566. echo '<input type="hidden" name="export_report" value="export_report">';
  567. echo '<input type="hidden" name="export_filter" value="'.(empty($filter)?1:intval($filter)).'">';
  568. echo '<input type="hidden" name="hotpotato_name" value="'.Security::remove_XSS($_GET['path']).'">';
  569. echo '<input type="hidden" name="export_format" value="xls">';
  570. echo '<input type="hidden" name="exerciseId" value="'.intval($_GET['exerciseId']).'">';
  571. echo '</form>';
  572. }
  573. }
  574. } else {
  575. //Student view
  576. if ($show == 'result') {
  577. echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=test') . '">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'','32').'</a>';
  578. } else {
  579. //echo '<a href="' . api_get_self() .'?'.api_get_cidreq().'&show=result'.'">' . Display :: return_icon('show_test_results.gif', get_lang('Results')) . get_lang('Results') . '</a>';
  580. }
  581. }
  582. if ($show == 'result') {
  583. if (api_is_allowed_to_edit(null,true)) {
  584. if (!$_GET['filter']) {
  585. $filter_by_not_revised = true;
  586. $filter = 1;
  587. } else {
  588. $filter=Security::remove_XSS($_GET['filter']);
  589. }
  590. $filter = (int)$_GET['filter'];
  591. switch ($filter) {
  592. case 1 :
  593. $filter_by_not_revised = true;
  594. break;
  595. case 2 :
  596. $filter_by_revised = true;
  597. break;
  598. default :
  599. null;
  600. }
  601. if (!empty($_GET['exerciseId'])) {
  602. if ($_GET['filter'] == '1' or !isset ($_GET['filter']) or $_GET['filter'] == 0 ) {
  603. $view_result = '<a href="' . api_get_self() . '?cidReq=' . api_get_course_id() . '&show=result&filter=2&id_session='.intval($_GET['id_session']).'&exerciseId='.intval($_GET['exerciseId']).'&gradebook='.$gradebook.'" >'.Display :: return_icon('exercice_check.png', get_lang('ShowCorrectedOnly'),'','32').'</a>';
  604. } else {
  605. $view_result = '<a href="' .api_get_self() . '?cidReq=' . api_get_course_id() . '&show=result&filter=1&id_session='.intval($_GET['id_session']).'&exerciseId='.intval($_GET['exerciseId']).'&gradebook='.$gradebook.'" >'.Display :: return_icon('exercice_uncheck.png', get_lang('ShowUnCorrectedOnly'),'','32').'</a>';
  606. }
  607. echo $view_result;
  608. }
  609. }
  610. }
  611. echo '</div>'; // closing the actions div
  612. if ($show == 'test') {
  613. ?>
  614. <script>
  615. $(function() {
  616. /*
  617. $( "a", ".operations" ).button();
  618. $(".tabs-left").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
  619. $(".tabs-left li").removeClass('ui-corner-top').addClass('ui-corner-left');
  620. */
  621. });
  622. </script>
  623. <style>
  624. /*
  625. New interface not yet ready for 1.8.8
  626. Vertical Tabs
  627. .ui-tabs-vertical { width: 99%; }
  628. .ui-tabs-vertical .ui-tabs-nav { padding: .2em .1em .2em .2em; float: left; width: 20%; }
  629. .ui-tabs-vertical .ui-tabs-nav li { clear: left; width: 100%; border-bottom-width: 1px !important; border-right-width: 0 !important; margin: 0 -1px .2em 0; white-space:normal;}
  630. .ui-tabs-vertical .ui-tabs-nav li a { display:block; width:100%; }
  631. .ui-tabs-vertical .ui-tabs-nav li.ui-tabs-selected { padding-bottom: 0; padding-right: .1em; border-right-width: 1px; border-right-width: 1px; }
  632. .ui-tabs-vertical .ui-tabs-panel { padding: 1em; float: left; width: 40em;}
  633. */
  634. </style>
  635. <?php
  636. $i =1;
  637. $lis = '';
  638. $exercise_list = array();
  639. $online_icon = Display::return_icon('online.png', get_lang('Visible'),array('width'=>'12px'));
  640. $offline_icon = Display::return_icon('offline.png',get_lang('Invisible'),array('width'=>'12px'));
  641. while ($row = Database :: fetch_array($result,'ASSOC')) {
  642. /*$status = $online_icon;
  643. if (empty($row['active'])) {
  644. $status = $offline_icon;
  645. }
  646. if (!(api_is_platform_admin() || api_is_allowed_to_edit()) ) {
  647. $status = '';
  648. }
  649. $lis.= Display::tag('li','<a href="#tabs-'.$i.'">'.$status.' '.$row['title'].'</a>');
  650. $i++;*/
  651. $exercise_list[] = $row;
  652. }
  653. if (!empty($exercise_list)) {
  654. //echo '<div id="exercise_tabs" class="tabs-left">';
  655. echo '<div>';
  656. //echo Display::tag('ul', $lis);
  657. /* Listing exercises */
  658. if ($origin != 'learnpath') {
  659. //avoid sending empty parameters
  660. $myorigin = (empty ($origin) ? '' : '&origin=' . $origin);
  661. $mylpid = (empty ($learnpath_id) ? '' : '&learnpath_id=' . $learnpath_id);
  662. $mylpitemid = (empty ($learnpath_item_id) ? '' : '&learnpath_item_id=' . $learnpath_item_id);
  663. $token = Security::get_token();
  664. $i=1;
  665. echo '<table class="data_table">';
  666. if ($is_allowedToEdit) {
  667. $headers = array(get_lang('ExerciseName'),get_lang('QuantityQuestions'), get_lang('Actions'));
  668. } else {
  669. $headers = array(get_lang('ExerciseName'), get_lang('Attempts'), get_lang('Status'), get_lang('Actions'));
  670. }
  671. $header_list = '';
  672. foreach($headers as $header) {
  673. $header_list .= Display::tag('th',$header);
  674. }
  675. echo Display::tag('tr',$header_list);
  676. if (!empty($exercise_list))
  677. foreach ($exercise_list as $row) {
  678. //echo '<div id="tabs-'.$i.'">';
  679. $i++;
  680. //validacion when belongs to a session
  681. $session_img = api_get_session_image($row['session_id'], $_user['status']);
  682. $time_limits = false;
  683. if ($row['start_time'] != '0000-00-00 00:00:00' && $row['end_time'] != '0000-00-00 00:00:00') {
  684. $time_limits = true;
  685. }
  686. if ($time_limits) {
  687. // check if start time
  688. $start_time = api_strtotime($row['start_time'],'UTC');
  689. $end_time = api_strtotime($row['end_time'],'UTC');
  690. $now = time();
  691. $is_actived_time = false;
  692. if ($now > $start_time && $end_time > $now ) {
  693. $is_actived_time = true;
  694. }
  695. }
  696. // Teacher only
  697. if ($is_allowedToEdit) {
  698. //Showing exercise title
  699. $row['title']=text_filter($row['title']);
  700. //echo Display::tag('h1',$row['title']);
  701. if ($session_id == $row['session_id']) {
  702. //Settings
  703. //echo Display::url(Display::return_icon('settings.png',get_lang('Edit'), array('width'=>'22px'))." ".get_lang('Edit'), 'exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$row['id']);
  704. }
  705. //echo '<p>';
  706. //echo $session_img;
  707. $url = '<a href="exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$myllpitemid.'&exerciseId='.$row['id'].'"><img src="../img/quiz.gif" alt="HotPotatoes" /> '.$row['title'].'</a>';
  708. $item = Display::tag('td',$url.' '.$session_img);
  709. $exid = $row['id'];
  710. //count number exercice - teacher
  711. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '" . $exid . "'";
  712. $sqlresult = Database::query($sqlquery);
  713. $rowi = Database :: result($sqlresult, 0);
  714. if ($session_id == $row['session_id']) {
  715. //Settings
  716. //$actions = Display::url(Display::return_icon('edit.gif',get_lang('Edit'), array('width'=>'20px')), 'exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$row['id']);
  717. $actions = Display::url(Display::return_icon('edit.png',get_lang('Edit'),array('width' =>'22px')), 'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']);
  718. $actions .='<a href="exercice.php?' . api_get_cidreq() . '&show=result&exerciseId='.$row['id'].'">' . Display :: return_icon('show_test_results.gif', get_lang('Results')).'</a>';
  719. //Export
  720. $actions .= Display::url(Display::return_icon('cd.gif', get_lang('CopyExercise')), '', array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToCopy'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id']));
  721. //Clean exercise
  722. $actions .= Display::url(Display::return_icon('clean_group.png', get_lang('CleanStudentResults')),'', array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDeleteResults'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=clean_results&sec_token='.$token.'&exerciseId='.$row['id']));
  723. //Visible / invisible
  724. if ($row['active']) {
  725. $actions .= Display::url(Display::return_icon('visible.gif', get_lang('Deactivate')) , 'exercice.php?'.api_get_cidreq().'&choice=disable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']);
  726. } else { // else if not active
  727. $actions .= Display::url(Display::return_icon('invisible.gif', get_lang('Activate')) , 'exercice.php?'.api_get_cidreq().'&choice=enable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']);
  728. }
  729. // Export qti ...
  730. $actions .= Display::url(Display::return_icon('export_qti2.png','IMS/QTI','','22'), 'exercice.php?choice=exportqti2&exerciseId='.$row['id']);
  731. } else { // not session resource
  732. $actions = Display::return_icon('edit_na.png', get_lang('ExerciseEditionNotAvailableInSession'));
  733. $actions .='<a href="exercice.php?' . api_get_cidreq() . '&show=result&exerciseId='.$row['id'].'">' . Display :: return_icon('show_test_results.gif', get_lang('Results')).'</a>';
  734. $actions .= Display::url(Display::return_icon('cd.gif', get_lang('CopyExercise')), '', array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToCopy'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id']));
  735. }
  736. //Delete
  737. if ($session_id == $row['session_id']) {
  738. $actions .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), '', array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDelete'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=delete&sec_token='.$token.'&exerciseId='.$row['id']));
  739. }
  740. //$actions .= '<br />';
  741. $random_label = '';
  742. if ($row['random'] > 0) {
  743. $random_label = ' ('.get_lang('Random').') ';
  744. $number_of_questions = $row['random'] . ' ' . api_strtolower(get_lang(($row['random'] > 1 ? 'Questions' : 'Question'))) .$random_label;
  745. } else {
  746. $number_of_questions = $rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question')));
  747. }
  748. //Attempts
  749. //$attempts = get_count_exam_results($row['id']).' '.get_lang('Attempts');
  750. //$item .= Display::tag('td',$attempts);
  751. $item .= Display::tag('td',$number_of_questions);
  752. $item .= Display::tag('td',$actions);
  753. //Special buttons
  754. /*
  755. echo '<div class="operations">';
  756. echo Display::url(Display::return_icon('quiz.gif',get_lang('Questions'), array('width'=>'22px'))." ".get_lang('Questions'),'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']);
  757. echo ' ';
  758. echo Display::url(Display::return_icon('preview.gif',get_lang('Preview'), array('width'=>'22px'))." ".get_lang('Preview'), 'exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id']);
  759. echo ' ';
  760. echo Display::url(Display::return_icon('show_test_results.gif',get_lang('Results'), array('width'=>'22px'))." ".get_lang('Results'), 'exercice.php?'.api_get_cidreq().'&show=result&exerciseId='.$row['id']);
  761. echo '</div>';*/
  762. echo Display::tag('tr',$item);
  763. } else {
  764. // Student only
  765. $row['title'] = text_filter($row['title']);
  766. // if time is actived show link to exercise
  767. if ($time_limits) {
  768. if ($is_actived_time) {
  769. $url = '<a href="exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$myllpitemid.'&exerciseId='.$row['id'].'">'.$row['title'].'</a>';
  770. } else {
  771. $url = $row['title'];
  772. }
  773. } else {
  774. $url = '<a href="exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$myllpitemid.'&exerciseId='.$row['id'].'">'.$row['title'].'</a>';
  775. }
  776. //Link of the exercise
  777. $item = Display::tag('td',$url.' '.$session_img);
  778. //count number exercise questions
  779. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '" . $row['id'] . "'";
  780. $sqlresult = Database::query($sqlquery);
  781. $rowi = Database::result($sqlresult, 0);
  782. if ($row['random'] > 0) {
  783. $row['random'] . ' ' . api_strtolower(get_lang(($row['random'] > 1 ? 'Questions' : 'Question')));
  784. } else {
  785. //show results student
  786. $rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question')));
  787. }
  788. //This query might be improved later on by ordering by the new "tms" field rather than by exe_id
  789. $qry = "SELECT * FROM $TBL_TRACK_EXERCICES
  790. WHERE exe_exo_id = '" . $row['id'] . "' and exe_user_id = '" . api_get_user_id() . "' 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() . "'
  791. ORDER BY exe_id DESC";
  792. $qryres = Database::query($qry);
  793. $num = Database :: num_rows($qryres);
  794. //Hide the results
  795. $my_result_disabled = $row['results_disabled'];
  796. //Time limits are on
  797. if ($time_limits) {
  798. // Examn is ready to be taken
  799. if ($is_actived_time) {
  800. if ($my_result_disabled == 0) {
  801. if ($num > 0) {
  802. $row_track = Database :: fetch_array($qryres);
  803. $attempt_text = get_lang('LatestAttempt') . ' : ';
  804. $attempt_text .= show_score($row_track['exe_result'], $row_track['exe_weighting']);
  805. } else {
  806. //$attempt_text = get_lang('NotAttempted');
  807. $attempt_text = sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_convert_and_format_date($row['start_time']), api_convert_and_format_date($row['end_time']));
  808. }
  809. } else {
  810. $attempt_text = get_lang('CantShowResults');
  811. }
  812. } else {
  813. //Examn not ready
  814. //$attempt_text = get_lang('ExamNotAvailableAtThisTime');
  815. $attempt_text = sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_convert_and_format_date($row['start_time']), api_convert_and_format_date($row['end_time']));
  816. }
  817. } else {
  818. //Normal behaviour
  819. //Show results
  820. if ($my_result_disabled == 0) {
  821. if ($num > 0) {
  822. $row_track = Database :: fetch_array($qryres);
  823. $attempt_text = get_lang('LatestAttempt') . ' : ';
  824. $attempt_text .= show_score($row_track['exe_result'], $row_track['exe_weighting']);
  825. } else {
  826. $attempt_text = get_lang('NotAttempted');
  827. }
  828. } else {
  829. $attempt_text = get_lang('CantShowResults');
  830. }
  831. }
  832. //User Attempts
  833. if (empty($row['max_attempt'])) {
  834. $item .= Display::tag('td',$num);
  835. } else {
  836. if (empty($num)) {
  837. $num = 0;
  838. }
  839. $item .= Display::tag('td',$num.' / '.$row['max_attempt']);
  840. }
  841. $item .= Display::tag('td', $attempt_text);
  842. //See results
  843. $actions ='<a href="exercice.php?' . api_get_cidreq() . '&show=result&exerciseId='.$row['id'].'">' . Display :: return_icon('show_test_results.gif', get_lang('Results')).'</a>';
  844. $item .= Display::tag('td', $actions);
  845. echo Display::tag('tr',$item);
  846. }
  847. /*echo '</p>';
  848. echo '</div>';*/
  849. } // end foreach()
  850. //Hotpotatoes results
  851. if ($is_allowedToEdit) {
  852. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  853. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  854. WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND (d.path LIKE '%htm%')
  855. AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' LIMIT " . (int) $from . "," . (int) ($limitExPage +1); // only .htm or .html files listed
  856. } else {
  857. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  858. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  859. WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND (d.path LIKE '%htm%')
  860. AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' AND ip.visibility='1' LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
  861. }
  862. $result = Database::query($sql);
  863. while ($row = Database :: fetch_array($result, 'ASSOC')) {
  864. $attribute['path'][] = $row['path'];
  865. $attribute['visibility'][] = $row['visibility'];
  866. $attribute['comment'][] = $row['comment'];
  867. }
  868. $nbrActiveTests = 0;
  869. if (is_array($attribute['path'])) {
  870. while (list ($key, $path) = each($attribute['path'])) {
  871. $item = '';
  872. list ($a, $vis) = each($attribute['visibility']);
  873. if (strcmp($vis, "1") == 0) {
  874. $active = 1;
  875. } else {
  876. $active = 0;
  877. }
  878. $title = GetQuizName($path, $documentPath);
  879. if ($title == '') {
  880. $title = basename($path);
  881. }
  882. // prof only
  883. if ($is_allowedToEdit) {
  884. $item = Display::tag('td','<img src="../img/hotpotatoes_s.png" alt="HotPotatoes" /> <a href="showinframes.php?file='.$path.'&cid='.api_get_course_id().'&uid='.api_get_user_id().'"'.(!$active?'class="invisible"':'').'>'.$title.'</a> ');
  885. $item .= Display::tag('td','-');
  886. $actions = Display::url(Display::return_icon('edit.png',get_lang('Edit'),array('width' =>'22px')), 'adminhp.php?'.api_get_cidreq().'&hotpotatoesName='.$path);
  887. $actions .='<a href="exercice.php?' . api_get_cidreq() . '&show=result&path='.$path.'">' . Display :: return_icon('show_test_results.gif', get_lang('Results')).'</a>';
  888. // if active
  889. if ($active) {
  890. $nbrActiveTests = $nbrActiveTests +1;
  891. $actions .= ' <a href="'.$exercicePath.'?'.api_get_cidreq().'&hpchoice=disable&amp;page='.$page.'&amp;file='.$path.'"><img src="../img/visible.gif" border="0" title="'.get_lang('Deactivate').'" alt="'.api_htmlentities(get_lang('Deactivate'),ENT_QUOTES,$charset).'" /></a>';
  892. } else { // else if not active
  893. $actions .=' <a href="'.$exercicePath.'?'.api_get_cidreq().'&hpchoice=enable&amp;page='.$page.'&amp;file='.$path.'"><img src="../img/invisible.gif" border="0" title="'.get_lang('Activate').'" alt="'.api_htmlentities(get_lang('Activate'),ENT_QUOTES,$charset).'" /></a>';
  894. }
  895. $actions .= '<a href="'.$exercicePath.'?'.api_get_cidreq().'&amp;hpchoice=delete&amp;file='.$path.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('AreYouSureToDelete'),ENT_QUOTES,$charset).' '.$title."?").'\')) return false;"><img src="../img/delete.png" border="0" title="'.get_lang('Delete').'" alt="'.api_htmlentities(get_lang('Delete'),ENT_QUOTES,$charset).'" /></a>';
  896. //$actions .='<img src="../img/lp_quiz_na.gif" border="0" title="'.get_lang('NotMarkActivity').'" alt="" />';
  897. $item .= Display::tag('td', $actions);
  898. echo Display::tag('tr',$item);
  899. } else { // student only
  900. if ($active == 1) {
  901. $nbrActiveTests = $nbrActiveTests +1;
  902. $item .= Display::tag('td', '<a href="showinframes.php?'.api_get_cidreq().'&file='.$path.'&cid='.api_get_course_id().'&uid='.api_get_user_id().'"'.(!$active?'class="invisible"':'').'">'.$title.'</a>');
  903. $item .= Display::tag('td', '');
  904. $item .= Display::tag('td', '');
  905. $actions ='<a href="exercice.php?' . api_get_cidreq() . '&show=result&path='.$path.'">' . Display :: return_icon('show_test_results.gif', get_lang('Results')).'</a>';
  906. $item .= Display::tag('td', $actions);
  907. echo Display::tag('tr',$item);
  908. }
  909. }
  910. }
  911. }
  912. echo '</table>';
  913. echo '</div>';
  914. }
  915. } else {
  916. echo Display::display_warning_message(get_lang('NoExercises'));
  917. }
  918. Display :: display_footer();
  919. exit;
  920. }
  921. /* Exercise Results (uses tracking tool) */
  922. // if tracking is enabled
  923. if ($show == 'result') {
  924. $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']));
  925. $exercise_id = intval($_GET['exerciseId']);
  926. if (!empty($exercise_id))
  927. $parameters['exerciseId'] = $exercise_id;
  928. if (!empty($_GET['path'])) {
  929. $parameters['path'] = Security::remove_XSS($_GET['path']);
  930. }
  931. $table = new SortableTable('quiz_results', 'get_count_exam_results', 'get_exam_results_data');
  932. $table->set_additional_parameters($parameters);
  933. if ($is_allowedToEdit || $is_tutor) {
  934. if (api_is_western_name_order()) {
  935. $table->set_header(0, get_lang('FirstName'));
  936. $table->set_header(1, get_lang('LastName'));
  937. } else {
  938. $table->set_header(0, get_lang('LastName'));
  939. $table->set_header(1, get_lang('FirstName'));
  940. }
  941. $table->set_header(2, get_lang('Exercice'));
  942. $table->set_header(3, get_lang('Duration'),false);
  943. $table->set_header(4, get_lang('Date'));
  944. $table->set_header(5, get_lang('Score'),false);
  945. $table->set_header(6, get_lang('CorrectTest'), false);
  946. } else {
  947. $table->set_header(0, get_lang('Exercice'));
  948. $table->set_header(1, get_lang('Duration'),false);
  949. $table->set_header(2, get_lang('Date'));
  950. $table->set_header(3, get_lang('Score'),false);
  951. $table->set_header(4, get_lang('Result'), false);
  952. }
  953. $table->display();
  954. }
  955. if ($origin != 'learnpath') { //so we are not in learnpath tool
  956. Display :: display_footer();
  957. }