exercice.php 55 KB

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