exercice.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. <?php // $Id: exercice.php 17605 2009-01-08 22:29:28Z cfasanando $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. * Exercise list: This script shows the list of exercises for administrators and students.
  22. * @package dokeos.exercise
  23. * @author Olivier Brouckaert, original author
  24. * @author Denes Nagy, HotPotatoes integration
  25. * @author Wolfgang Schneider, code/html cleanup
  26. * @version $Id:exercice.php 12269 2007-05-03 14:17:37Z elixir_julian $
  27. */
  28. // name of the language file that needs to be included
  29. $language_file='exercice';
  30. // including the global library
  31. require_once('../inc/global.inc.php');
  32. require_once ('../gradebook/lib/be.inc.php');
  33. // setting the tabs
  34. $this_section=SECTION_COURSES;
  35. // access control
  36. api_protect_course_script(true);
  37. $show=(isset($_GET['show']) && $_GET['show'] == 'result')?'result':'test'; // moved down to fix bug: http://www.dokeos.com/forum/viewtopic.php?p=18609#18609
  38. // including additional libraries
  39. require_once('exercise.class.php');
  40. require_once('question.class.php');
  41. require_once('answer.class.php');
  42. require_once(api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  43. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  44. require_once('hotpotatoes.lib.php');
  45. require_once(api_get_path(LIBRARY_PATH).'document.lib.php');
  46. include(api_get_path(LIBRARY_PATH).'mail.lib.inc.php');
  47. include(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  48. include_once(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  49. /*
  50. -----------------------------------------------------------
  51. Constants and variables
  52. -----------------------------------------------------------
  53. */
  54. $is_allowedToEdit = api_is_allowed_to_edit();
  55. $is_tutor = api_is_allowed_to_edit(true);
  56. $TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
  57. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  58. $TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  59. $TBL_EXERCICE_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
  60. $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  61. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  62. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  63. $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  64. $TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  65. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  66. $TBL_TRACK_ATTEMPT_RECORDING = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  67. $TBL_LP_ITEM_VIEW = Database::get_course_table (TABLE_LP_ITEM_VIEW);
  68. $TBL_LP_VIEW = Database::get_course_table (TABLE_LP_VIEW);
  69. // document path
  70. $documentPath= api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  71. // picture path
  72. $picturePath=$documentPath.'/images';
  73. // audio path
  74. $audioPath=$documentPath.'/audio';
  75. // hotpotatoes
  76. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  77. $exercicePath = api_get_self();
  78. $exfile = explode('/',$exercicePath);
  79. $exfile = strtolower($exfile[sizeof($exfile)-1]);
  80. $exercicePath = substr($exercicePath,0,strpos($exercicePath,$exfile));
  81. $exercicePath = $exercicePath."exercice.php";
  82. // maximum number of exercises on a same page
  83. $limitExPage=50;
  84. // Clear the exercise session
  85. if(isset($_SESSION['objExercise'])) { api_session_unregister('objExercise'); }
  86. if(isset($_SESSION['objQuestion'])) { api_session_unregister('objQuestion'); }
  87. if(isset($_SESSION['objAnswer'])) { api_session_unregister('objAnswer'); }
  88. if(isset($_SESSION['questionList'])) { api_session_unregister('questionList'); }
  89. if(isset($_SESSION['exerciseResult'])) { api_session_unregister('exerciseResult'); }
  90. //general POST/GET/SESSION/COOKIES parameters recovery
  91. if ( empty ( $origin ) ) {
  92. $origin = $_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 = Database::escape_string($_REQUEST['exerciseId']);
  102. }
  103. if ( empty ( $file ) ) {
  104. $file = Database::escape_string($_REQUEST['file']);
  105. }
  106. $learnpath_id = Database::escape_string($_REQUEST['learnpath_id']);
  107. $learnpath_item_id = Database::escape_string($_REQUEST['learnpath_item_id']);
  108. $page = Database::escape_string($_REQUEST['page']);
  109. if($origin == 'learnpath'){
  110. $show = 'result';
  111. }
  112. if($_GET['delete']=='delete' && ($is_allowedToEdit || api_is_coach()) && !empty($_GET['did'])){
  113. $sql='DELETE FROM '.Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES).' WHERE exe_id = '.(int)$_GET['did'];
  114. api_sql_query ($sql,__FILE__,__LINE__);
  115. header('Location: exercice.php?cidReq='.htmlentities($_GET['cidReq']).'&show=result');
  116. exit;
  117. }
  118. if ($show=='result' && $_REQUEST['comments']=='update' && ($is_allowedToEdit || $is_tutor))
  119. {
  120. $id = $_GET['exeid'];
  121. $emailid = $_GET['emailid'];
  122. $test = $_GET['test'];
  123. $from = $_SESSION['_user']['mail'];
  124. $from_name = $_SESSION['_user']['firstName']." ".$_SESSION['_user']['lastName'];
  125. $url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result';
  126. $TBL_RECORDING = Database::get_statistic_table('track_e_attempt_recording');
  127. foreach ($_POST as $key=>$v) {
  128. $keyexp = explode('_',$key);
  129. if ($keyexp[0] == "marks") {
  130. $sql = "select question from $TBL_QUESTIONS where id = '$keyexp[1]'";
  131. $result =api_sql_query($sql, __FILE__, __LINE__);
  132. $ques_name = Database::result($result,0,"question");
  133. $query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '".Database::escape_string($v)."'
  134. WHERE question_id = '".Database::escape_string($keyexp[1])."'
  135. AND exe_id='".Database::escape_string($id)."'";
  136. api_sql_query($query, __FILE__, __LINE__);
  137. $qry = 'SELECT sum(marks) as tot
  138. FROM '.$TBL_TRACK_ATTEMPT.' where exe_id = '.intval($id).'
  139. GROUP BY question_id';
  140. $res = api_sql_query($qry,__FILE__,__LINE__);
  141. $tot = Database::result($res,0,'tot');
  142. $totquery = "update $TBL_TRACK_EXERCICES set exe_result = '".Database::escape_string($tot)."' where exe_Id='".Database::escape_string($id)."'";
  143. api_sql_query($totquery, __FILE__, __LINE__);
  144. $recording_changes = 'INSERT INTO '.$TBL_RECORDING.' ' .
  145. '(exe_id,
  146. question_id,
  147. marks,
  148. insert_date,
  149. author)
  150. VALUES
  151. ('."'$id','".$keyexp[1]."','$v','".date('Y-m-d H:i:s')."','".api_get_user_id()."'".')';
  152. api_sql_query($recording_changes, __FILE__, __LINE__);
  153. } else {
  154. $query = "UPDATE $TBL_TRACK_ATTEMPT SET teacher_comment = '".Database::escape_string($v)."'
  155. WHERE question_id = '".Database::escape_string($keyexp[1])."'
  156. AND exe_id = '".Database::escape_string($id)."'";
  157. api_sql_query($query, __FILE__, __LINE__);
  158. $recording_changes = 'INSERT INTO '.$TBL_RECORDING.' ' .
  159. '(exe_id,
  160. question_id,
  161. teacher_comment,
  162. insert_date,
  163. author)
  164. VALUES
  165. ('."'$id','".$keyexp[1]."','$v','".date('Y-m-d H:i:s')."','".api_get_user_id()."'".')';
  166. api_sql_query($recording_changes, __FILE__, __LINE__);
  167. }
  168. }
  169. $qry = 'SELECT DISTINCT question_id, marks
  170. FROM '.$TBL_TRACK_ATTEMPT.' where exe_id = '.intval($id).'
  171. GROUP BY question_id';
  172. $res = api_sql_query($qry,__FILE__,__LINE__);
  173. $tot = 0;
  174. while($row = Database::fetch_array($res,'ASSOC')) {
  175. $tot += $row ['marks'];
  176. }
  177. $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".Database::escape_string($tot)."' WHERE exe_Id='".Database::escape_string($id)."'";
  178. api_sql_query($totquery, __FILE__, __LINE__);
  179. $subject = get_lang('ExamSheetVCC');
  180. $htmlmessage = '<html>'.
  181. '<head>' .
  182. '<style type="text/css">' .
  183. '<!--' .
  184. '.body{' .
  185. 'font-family: Verdana, Arial, Helvetica, sans-serif;' .
  186. 'font-weight: Normal;' .
  187. 'color: #000000;' .
  188. '}' .
  189. '.style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; color: #006699; }' .
  190. '.style10 {' .
  191. ' font-family: Verdana, Arial, Helvetica, sans-serif;' .
  192. ' font-size: 12px;' .
  193. ' font-weight: bold;' .
  194. '}' .
  195. '.style16 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }' .
  196. '-->' .
  197. '</style>' .
  198. '</head>' .
  199. '<body>' .
  200. '<div>' .
  201. ' <p>'.get_lang('DearStudentEmailIntroduction').'</p>' .
  202. ' <p class="style10"> '.get_lang('AttemptVCC').' </p>' .
  203. ' <table width="417">' .
  204. ' <tr>' .
  205. ' <td width="229" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>' .
  206. ' <td width="469" valign="top" bgcolor="#F3F3F3"><span class="style16">#ques_name#</span></td>' .
  207. ' </tr>' .
  208. ' <tr>' .
  209. ' <td width="229" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Exercice').'</span></td>' .
  210. ' <td width="469" valign="top" bgcolor="#F3F3F3"><span class="style16">#test#</span></td>' .
  211. ' </tr>' .
  212. ' </table>' .
  213. ' <p>'.get_lang('ClickLinkToViewComment').' <a href="#url#">#url#</a><br />' .
  214. ' <br />' .
  215. ' '.get_lang('Regards').' </p>' .
  216. ' </div>' .
  217. ' </body>' .
  218. ' </html>';
  219. $message = '<p>'.sprintf(get_lang('AttemptVCCLong'),$test).' <A href="#url#">#url#</A></p><br />';
  220. $mess= str_replace("#test#",$test,$message);
  221. //$message= str_replace("#ques_name#",$ques_name,$mess);
  222. $message = str_replace("#url#",$url,$mess);
  223. $mess = stripslashes($message);
  224. $headers = " MIME-Version: 1.0 \r\n";
  225. $headers .= "User-Agent: Dokeos/1.6";
  226. $headers .= "Content-Transfer-Encoding: 7bit";
  227. $headers .= 'From: '.$from_name.' <'.$from.'>' . "\r\n";
  228. $headers="From:$from_name\r\nReply-to: $to\r\nContent-type: text/html; charset=".($charset?$charset:'ISO-8859-15');
  229. //mail($emailid, $subject, $mess,$headers);
  230. api_mail_html($emailid, $emailid, $subject, $mess, $from_name, $from);
  231. if (in_array($origin, array('tracking_course','user_course'))){
  232. // update score when you qualify the exercises in Learning path detail
  233. if (isset($_REQUEST['lp_item_id']) && isset($_REQUEST['lp_item_view_id']) && isset($_REQUEST['student_id']) && isset($_REQUEST['total_score'])) {
  234. $lp_item_id = Security::remove_XSS($_REQUEST['lp_item_id']);
  235. $lp_item_view_id = Security::remove_XSS($_REQUEST['lp_item_view_id']);
  236. $student_id = Security::remove_XSS($_REQUEST['student_id']);
  237. $score = Security::remove_XSS($_REQUEST['total_score']);
  238. $sql = "UPDATE $TBL_LP_ITEM_VIEW SET score = '$score' WHERE lp_item_id = '$lp_item_id'
  239. AND lp_view_id = (SELECT id from $TBL_LP_VIEW WHERE user_id = '$student_id' and lp_id='$lp_item_view_id')";
  240. api_sql_query($sql,__FILE__,__LINE__);
  241. }
  242. //Redirect to the reporting
  243. header('location: ../mySpace/myStudents.php?origin='.$origin.'&student='.$_GET['student'].'&details=true&course='.$_GET['course']);
  244. }
  245. }
  246. if ($_GET['gradebook'] && $_GET['exerciseId']) {
  247. $interbreadcrumb[]= array (
  248. 'url' => '../gradebook/index.php',
  249. 'name' => get_lang('Gradebook')
  250. );
  251. }
  252. if ($show!='result') {
  253. $nameTools=get_lang('Exercices');
  254. } else {
  255. if($is_allowedToEdit || $is_tutor) {
  256. $nameTools=get_lang('StudentScore');
  257. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  258. } else {
  259. $nameTools=get_lang('YourScore');
  260. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  261. }
  262. }
  263. // need functions of statsutils lib to display previous exercices scores
  264. include_once(api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php');
  265. if ($is_allowedToEdit && !empty($choice) && $choice == 'exportqti2') {
  266. require_once('export/qti2/qti2_export.php');
  267. $export = export_exercise($exerciseId,true);
  268. require_once(api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php');
  269. $garbage_path = api_get_path(GARBAGE_PATH);
  270. $temp_dir_short = uniqid();
  271. $temp_zip_dir = $garbage_path."/".$temp_dir_short;
  272. if(!is_dir($temp_zip_dir)) mkdir($temp_zip_dir);
  273. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  274. $temp_xml_file = $temp_zip_dir."/qti2export_".$exerciseId.'.xml';
  275. file_put_contents($temp_xml_file,$export);
  276. $zip_folder=new PclZip($temp_zip_file);
  277. $zip_folder->add($temp_xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
  278. $name = 'qti2_export_'.$exerciseId.'.zip';
  279. //DocumentManager::string_send_for_download($export,true,'qti2export_'.$exerciseId.'.xml');
  280. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  281. unlink($temp_zip_file);
  282. unlink($temp_xml_file);
  283. rmdir($temp_zip_dir);
  284. exit(); //otherwise following clicks may become buggy
  285. }
  286. if (!empty($_POST['export_user_fields'])) {
  287. switch ($_POST['export_user_fields']) {
  288. case 'export_user_fields':
  289. $_SESSION['export_user_fields'] = true;
  290. break;
  291. case 'do_not_export_user_fields':
  292. default:
  293. $_SESSION['export_user_fields'] = false;
  294. break;
  295. }
  296. }
  297. if (!empty($_POST['export_report']) && $_POST['export_report'] == 'export_report') {
  298. if(api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
  299. $user_id = null;
  300. if(empty($_SESSION['export_user_fields'])) $_SESSION['export_user_fields'] = false;
  301. if(!$is_allowedToEdit and !$is_tutor) {
  302. $user_id = api_get_user_id();
  303. }
  304. require_once('exercise_result.class.php');
  305. switch($_POST['export_format']) {
  306. case 'xls':
  307. $export = new ExerciseResult();
  308. $export->exportCompleteReportXLS($documentPath, $user_id, $_SESSION['export_user_fields']);
  309. exit;
  310. break;
  311. case 'csv':
  312. default:
  313. $export = new ExerciseResult();
  314. $export->exportCompleteReportCSV($documentPath, $user_id, $_SESSION['export_user_fields']);
  315. exit;
  316. break;
  317. }
  318. } else {
  319. api_not_allowed(true);
  320. }
  321. }
  322. if ($origin != 'learnpath') {
  323. //so we are not in learnpath tool
  324. Display::display_header($nameTools,"Exercise");
  325. if(isset($_GET['message'])) {
  326. if (in_array($_GET['message'], array('ExerciseEdited'))) {
  327. Display::display_confirmation_message(get_lang($_GET['message']));
  328. }
  329. }
  330. } else {
  331. echo '<link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_CODE_PATH).'css/default.css"/>';
  332. }
  333. // used for stats
  334. include_once(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  335. event_access_tool(TOOL_QUIZ);
  336. Display::display_introduction_section(TOOL_QUIZ);
  337. // selects $limitExPage exercises at the same time
  338. $from=$page*$limitExPage;
  339. $sql="SELECT count(id) FROM $TBL_EXERCICES";
  340. $res = api_sql_query($sql,__FILE__,__LINE__);
  341. list($nbrexerc) = Database::fetch_array($res);
  342. HotPotGCt($documentPath,1,$_user['user_id']);
  343. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  344. // only for administrator
  345. if ($is_allowedToEdit) {
  346. if (!empty($choice)) {
  347. // construction of Exercise
  348. $objExerciseTmp=new Exercise();
  349. if ($objExerciseTmp->read($exerciseId)) {
  350. switch ($choice) {
  351. case 'delete': // deletes an exercise
  352. $objExerciseTmp->delete();
  353. //delete link of exercise of gradebook tool
  354. $sql='SELECT gl.id FROM '.$tbl_grade_link.' gl WHERE gl.type="1" AND gl.ref_id="'.$exerciseId.'";';
  355. $result=api_sql_query($sql,__FILE__,__LINE__);
  356. $row=Database::fetch_array($result,'ASSOC');
  357. $link= LinkFactory :: load($row['id']);
  358. if ($link[0] != null) {
  359. $link[0]->delete();
  360. }
  361. Display::display_confirmation_message(get_lang('ExerciseDeleted'));
  362. break;
  363. case 'enable': // enables an exercise
  364. $objExerciseTmp->enable();
  365. $objExerciseTmp->save();
  366. // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
  367. api_item_property_update($_course, TOOL_QUIZ, $exerciseId, "QuizAdded", $_user['user_id']);
  368. Display::display_confirmation_message(get_lang('VisibilityChanged'));
  369. break;
  370. case 'disable': // disables an exercise
  371. $objExerciseTmp->disable();
  372. $objExerciseTmp->save();
  373. Display::display_confirmation_message(get_lang('VisibilityChanged'));
  374. break;
  375. case 'disable_results' : //disable the results for the learners
  376. $objExerciseTmp->disable_results();
  377. $objExerciseTmp->save();
  378. Display::display_confirmation_message(get_lang('ResultsDisabled'));
  379. break;
  380. case 'enable_results' : //disable the results for the learners
  381. $objExerciseTmp->enable_results();
  382. $objExerciseTmp->save();
  383. Display::display_confirmation_message(get_lang('ResultsEnabled'));
  384. break;
  385. }
  386. }
  387. // destruction of Exercise
  388. unset($objExerciseTmp);
  389. }
  390. if (!empty($hpchoice)) {
  391. switch($hpchoice) {
  392. case 'delete': // deletes an exercise
  393. $imgparams = array();
  394. $imgcount = 0;
  395. GetImgParams($file,$documentPath,$imgparams,$imgcount);
  396. $fld = GetFolderName($file);
  397. for($i=0;$i < $imgcount;$i++)
  398. {
  399. my_delete($documentPath.$uploadPath."/".$fld."/".$imgparams[$i]);
  400. update_db_info("delete", $uploadPath."/".$fld."/".$imgparams[$i]);
  401. }
  402. if ( my_delete($documentPath.$file))
  403. {
  404. update_db_info("delete", $file);
  405. }
  406. my_delete($documentPath.$uploadPath."/".$fld."/");
  407. break;
  408. case 'enable': // enables an exercise
  409. $newVisibilityStatus = "1"; //"visible"
  410. $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='".Database::escape_string($file)."'";
  411. $res = api_sql_query($query,__FILE__,__LINE__);
  412. $row = Database::fetch_array($res, 'ASSOC');
  413. api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'visible', $_user['user_id']);
  414. //$dialogBox = get_lang('ViMod');
  415. break;
  416. case 'disable': // disables an exercise
  417. $newVisibilityStatus = "0"; //"invisible"
  418. $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='".Database::escape_string($file)."'";
  419. $res = api_sql_query($query,__FILE__,__LINE__);
  420. $row = Database::fetch_array($res, 'ASSOC');
  421. api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'invisible', $_user['user_id']);
  422. #$query = "UPDATE $TBL_DOCUMENT SET visibility='$newVisibilityStatus' WHERE path=\"".$file."\""; //added by Toon
  423. #api_sql_query($query,__FILE__,__LINE__);
  424. //$dialogBox = get_lang('ViMod');
  425. break;
  426. default:
  427. break;
  428. }
  429. }
  430. if ($show == 'test') {
  431. $sql="SELECT id,title,type,active,description, results_disabled FROM $TBL_EXERCICES WHERE active<>'-1' ORDER BY title LIMIT ".(int)$from.",".(int)($limitExPage+1);
  432. $result=api_sql_query($sql,__FILE__,__LINE__);
  433. }
  434. } elseif($show == 'test') {// only for students //fin
  435. $sql="SELECT id,title,type,description, results_disabled FROM $TBL_EXERCICES WHERE active='1' ORDER BY title LIMIT ".(int)$from.",".(int)($limitExPage+1);
  436. $result=api_sql_query($sql,__FILE__,__LINE__);
  437. }
  438. // the actions
  439. echo '<div class="actions">';
  440. // display the next and previous link if needed
  441. $from=$page*$limitExPage;
  442. $sql="SELECT count(id) FROM $TBL_EXERCICES";
  443. $res = api_sql_query($sql,__FILE__,__LINE__);
  444. list($nbrexerc) = Database::fetch_array($res);
  445. HotPotGCt($documentPath,1,$_user['user_id']);
  446. // only for administrator
  447. if($is_allowedToEdit) {
  448. if ($show == 'test') {
  449. $sql="SELECT id,title,type,active,description, results_disabled FROM $TBL_EXERCICES WHERE active<>'-1' ORDER BY title LIMIT ".(int)$from.",".(int)($limitExPage+1);
  450. $result=api_sql_query($sql,__FILE__,__LINE__);
  451. }
  452. } elseif($show == 'test') { // only for students
  453. $sql="SELECT id,title,type,description, results_disabled FROM $TBL_EXERCICES WHERE active='1' ORDER BY title LIMIT ".(int)$from.",".(int)($limitExPage+1);
  454. $result=api_sql_query($sql,__FILE__,__LINE__);
  455. }
  456. if($show == 'test')
  457. {
  458. $nbrExercises=Database::num_rows($result);
  459. //get HotPotatoes files (active and inactive)
  460. $res = api_sql_query ("SELECT *
  461. FROM $TBL_DOCUMENT
  462. WHERE
  463. path LIKE '".Database::escape_string($uploadPath)."/%/%'",__FILE__,__LINE__);
  464. $nbrTests = Database::num_rows($res);
  465. $res = api_sql_query ("SELECT *
  466. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  467. WHERE d.id = ip.ref
  468. AND ip.tool = '".TOOL_DOCUMENT."'
  469. AND d.path LIKE '".Database::escape_string($uploadPath)."/%/%'
  470. AND ip.visibility='1'", __FILE__,__LINE__);
  471. $nbrActiveTests = Database::num_rows($res);
  472. if($is_allowedToEdit)
  473. {//if user is allowed to edit, also show hidden HP tests
  474. $nbrHpTests = $nbrTests;
  475. }
  476. else
  477. {
  478. $nbrHpTests = $nbrActiveTests;
  479. }
  480. $nbrNextTests = $nbrexerc-$nbrHpTests-(($page*$limitExPage));
  481. echo '<span style="float:right">';
  482. //show pages navigation link for previous page
  483. if($page)
  484. {
  485. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;page=".($page-1)."\">".Display::return_icon('previous.gif').get_lang("PreviousPage")."</a> | ";
  486. }
  487. elseif($nbrExercises+$nbrNextTests > $limitExPage)
  488. {
  489. echo Display::return_icon('previous.gif').get_lang('PreviousPage')." | ";
  490. }
  491. //show pages navigation link for previous page
  492. if($nbrExercises+$nbrNextTests > $limitExPage)
  493. {
  494. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;page=".($page+1)."\">".get_lang("NextPage").Display::return_icon('next.gif')."</a>";
  495. }
  496. elseif($page)
  497. {
  498. echo get_lang("NextPage") . Display::return_icon('next.gif');
  499. }
  500. echo '</span>';
  501. }
  502. if (($is_allowedToEdit) and ($origin != 'learnpath'))
  503. {
  504. echo '<a href="exercise_admin.php?'.api_get_cidreq().'">'.Display::return_icon('new_test.gif',get_lang('NewEx')).get_lang('NewEx').'</a>';
  505. echo '<a href="hotpotatoes.php">'.Display::return_icon('jqz.jpg',get_lang('ImportHotPotatoesQuiz')).get_lang('ImportHotPotatoesQuiz').'</a>';
  506. echo '<a href="'.api_add_url_param($_SERVER['REQUEST_URI'],'show=result').'">'.Display::return_icon('show_test_results.gif',get_lang('ImportHotPotatoesQuiz')).get_lang("Results").'</a>';
  507. // the actions for the statistics
  508. if($show == 'result')
  509. {
  510. // the form
  511. if(api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach())
  512. {
  513. if($_SESSION['export_user_fields']==false)
  514. {
  515. $alt = get_lang('ExportWithUserFields');
  516. $extra_user_fields = '<input type="hidden" name="export_user_fields" value="export_user_fields">';
  517. }
  518. else
  519. {
  520. $alt = get_lang('ExportWithoutUserFields');
  521. $extra_user_fields = '<input type="hidden" name="export_user_fields" value="do_not_export_user_fields">';
  522. }
  523. echo '<a href="#" onclick="document.form1a.submit();">'.Display::return_icon('excel.gif',get_lang('ExportAsCSV')).get_lang('ExportAsCSV').'</a>';
  524. echo '<a href="#" onclick="document.form1b.submit();">'.Display::return_icon('excel.gif',get_lang('ExportAsXLS')).get_lang('ExportAsXLS').'</a>';
  525. echo '<a href="#" onclick="document.form1c.submit();">'.Display::return_icon('synthese_view.gif',$alt).$alt.'</a>';
  526. echo '<a href="'.api_add_url_param($_SERVER['REQUEST_URI'],'show=test').'">'.Display::return_icon('quiz.gif').get_lang('BackToExercisesList').'</a>';
  527. echo '<form id="form1a" name="form1a" method="post" action="'.api_get_self().'?show='.Security::remove_XSS($_GET['show']).'">';
  528. echo '<input type="hidden" name="export_report" value="export_report">';
  529. echo '<input type="hidden" name="export_format" value="csv">';
  530. echo '</form>';
  531. echo '<form id="form1b" name="form1b" method="post" action="'.api_get_self().'?show='.Security::remove_XSS($_GET['show']).'">';
  532. echo '<input type="hidden" name="export_report" value="export_report">';
  533. echo '<input type="hidden" name="export_format" value="xls">';
  534. echo '</form>';
  535. echo '<form id="form1c" name="form1c" method="post" action="'.api_get_self().'?show='.Security::remove_XSS($_GET['show']).'">';
  536. echo $extra_user_fields;
  537. echo '</form>';
  538. }
  539. }
  540. }
  541. if ($_configuration['tracking_enabled'])
  542. {
  543. if ($show == 'result')
  544. {
  545. if (!function_exists('make_select'))
  546. {
  547. function make_select($name,$values,$checked='')
  548. {
  549. $output .= '<select name="'.$name.'" >';
  550. foreach($values as $key => $value)
  551. {
  552. $output .= '<option value="'.$key.'" '.(($checked==$key)?'selected="selected"':'').'>'.$value.'</option>';
  553. }
  554. $output .= '</select>';
  555. return $output;
  556. }
  557. }
  558. if (!function_exists('make_select_users'))
  559. {
  560. function make_select_users($name,$values,$checked='')
  561. {
  562. $output .= '<select name="'.$name.'" >';
  563. $output .= '<option value="all">'.get_lang('EveryBody').'</option>';
  564. foreach($values as $key => $value)
  565. {
  566. $output .= '<option value="'.$key.'" '.(($checked==$key)?'selected="selected"':'').'>'.$value.'</option>';
  567. }
  568. $output .= '</select>';
  569. return $output;
  570. }
  571. }
  572. if (api_is_allowed_to_edit())
  573. {
  574. if (!$_REQUEST['filter'])
  575. {
  576. $filter_by_not_revised = true;
  577. $filter=1;
  578. }
  579. $filter = (int)$_REQUEST['filter'];
  580. switch($filter)
  581. {
  582. case 1:
  583. $filter_by_not_revised = true;
  584. break;
  585. case 2:
  586. $filter_by_revised = true;
  587. break;
  588. default:
  589. null;
  590. }
  591. $form_filter = '<form method="post" action="'.api_get_self().'?cidReq='.api_get_course_id().'&show=result">';
  592. $form_filter .= make_select('filter',array(1=>get_lang('FilterByNotRevised'),2=>get_lang('FilterByRevised')),$filter);
  593. $form_filter .= '<input type="submit" value="'.get_lang('FilterExercices').'"> </form>';
  594. echo $form_filter;
  595. }
  596. }
  597. if (api_is_allowed_to_edit())
  598. {
  599. $user_count = count($user_list_name);
  600. if ($user_count >0 ) {
  601. $form_filter = '<form method="post" action="'.api_get_self().'?cidReq='.api_get_course_id().'&show=result">';
  602. $user_list_for_select =array();
  603. for ($i=0;$i<$user_count;$i++) {
  604. $user_list_for_select[$user_list_id[$i]]=$user_list_name[$i];
  605. }
  606. $form_filter .= make_select_users('filter_by_user',$user_list_for_select,(int)$_REQUEST['filter_by_user']);
  607. $form_filter .= '<input type="hidden" name="filter" value="'.$filter.'">';
  608. $form_filter .= '<input type="submit" value="'.get_lang('FilterExercicesByUsers').'"></form>';
  609. echo $form_filter;
  610. }
  611. }
  612. }
  613. echo '</div>'; // closing the actions div
  614. if ($show == 'test') {
  615. ?>
  616. <table class="data_table">
  617. <?php
  618. if (($is_allowedToEdit) and ($origin != 'learnpath')) {
  619. ?>
  620. <tr class="row_odd">
  621. <th colspan="3"><?php echo get_lang('ExerciseName');?></th>
  622. <th><?php echo get_lang('QuantityQuestions');?></th>
  623. <th><?php echo get_lang('Export');?></th>
  624. <th><?php echo get_lang('Modify');?></th>
  625. </tr>
  626. <?php
  627. } else {
  628. ?> <tr>
  629. <th colspan="3"><?php echo get_lang('ExerciseName');?></th>
  630. <th><?php echo get_lang('QuantityQuestions');?></th>
  631. <th><?php echo get_lang('State');?></th>
  632. </tr>
  633. <?php
  634. }
  635. // show message if no HP test to show
  636. if (!($nbrExercises+$nbrHpTests) ) {
  637. ?>
  638. <tr>
  639. <td <?php echo ($is_allowedToEdit?'colspan="6"':'colspan="5"'); ?>><?php echo get_lang("NoEx"); ?></td>
  640. </tr>
  641. <?php
  642. }
  643. $i=1;
  644. // while list exercises
  645. if ($origin != 'learnpath') {
  646. //avoid sending empty parameters
  647. $myorigin = (empty($origin)?'':'&origin='.$origin);
  648. $mylpid = (empty($learnpath_id)?'':'&learnpath_id='.$learnpath_id);
  649. $mylpitemid = (empty($learnpath_item_id)?'':'&learnpath_item_id='.$learnpath_item_id);
  650. while($row=Database::fetch_array($result)) {
  651. if($i%2==0) $s_class="row_odd"; else $s_class="row_even";
  652. // prof only
  653. if ($is_allowedToEdit) {
  654. echo '<tr class="'.$s_class.'">'."\n";
  655. ?>
  656. <td width="30" align="left"><?php Display::display_icon('quiz.gif', get_lang('Exercice'))?></td>
  657. <td width="15" valign="left"><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
  658. <?php $row['title']=api_parse_tex($row['title']); ?>
  659. <td><a href="exercice_submit.php?<?php echo api_get_cidreq().$myorigin.$mylpid.$mylpitemid; ?>&amp;exerciseId=<?php echo $row['id']; ?>" <?php if(!$row['active']) echo 'class="invisible"'; ?>><?php echo $row['title']; ?></a></td>
  660. <td> <?php
  661. $exid = $row['id'];
  662. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '".Database::escape_string($exid)."'";
  663. $sqlresult =api_sql_query($sqlquery);
  664. $rowi = Database::result($sqlresult,0);
  665. echo $rowi.' '.strtolower(get_lang(($rowi>1?'Questions':'Question'))).'</td>';
  666. echo '<td><a href="exercice.php?choice=exportqti2&exerciseId='.$row['id'].'"><img src="../img/export.png" border="0" title="IMS/QTI" /></a></td>';
  667. ?>
  668. <td>
  669. <a href="exercise_admin.php?modifyExercise=yes&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/edit.gif" border="0" title="<?php echo htmlentities(get_lang('Modify'),ENT_QUOTES,$charset); ?>" alt="<?php echo htmlentities(get_lang('Modify'),ENT_QUOTES,$charset); ?>" /></a>
  670. <a href="admin.php?exerciseId=<?php echo $row['id']; ?>"><img src="../img/wizard_small.gif" border="0" title="<?php echo htmlentities(get_lang('Build'),ENT_QUOTES,$charset); ?>" alt="<?php echo htmlentities(get_lang('Build'),ENT_QUOTES,$charset); ?>" /></a>
  671. <a href="exercice.php?choice=delete&exerciseId=<?php echo $row['id']; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('AreYouSureToDelete'),ENT_QUOTES,$charset)); echo " ".$row['title']; echo "?"; ?>')) return false;"> <img src="../img/delete.gif" border="0" alt="<?php echo htmlentities(get_lang('Delete'),ENT_QUOTES,$charset); ?>" /></a>
  672. <?php
  673. // if active
  674. if ($row['active']) {
  675. ?>
  676. <a href="exercice.php?choice=disable&page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/visible.gif" border="0" alt="<?php echo htmlentities(get_lang('Deactivate'),ENT_QUOTES,$charset); ?>" /></a>
  677. <?php
  678. } else {// else if not active
  679. ?>
  680. <a href="exercice.php?choice=enable&page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/invisible.gif" border="0" alt="<?php echo htmlentities(get_lang('Activate'),ENT_QUOTES,$charset); ?>" /></a>
  681. <?php
  682. }
  683. if($row['results_disabled']) {
  684. echo '<a href="exercice.php?choice=enable_results&page='.$page.'&exerciseId='.$row['id'].'" title="'.get_lang('EnableResults').'" alt="'.get_lang('EnableResults').'"><img src="../img/lp_quiz_na.gif" border="0" alt="'.htmlentities(get_lang('EnableResults'),ENT_QUOTES,$charset).'" /></a>';
  685. } else {
  686. echo '<a href="exercice.php?choice=disable_results&page='.$page.'&exerciseId='.$row['id'].'" title="'.get_lang('DisableResults').'" alt="'.get_lang('DisableResults').'"><img src="../img/lp_quiz.gif" border="0" alt="'.htmlentities(get_lang('DisableResults'),ENT_QUOTES,$charset).'" /></a>';
  687. }
  688. echo "</td>";
  689. echo "</tr>\n";
  690. } else {// student only
  691. ?>
  692. <tr>
  693. <td><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
  694. <td>&nbsp;</td>
  695. <?php $row['title']=api_parse_tex($row['title']);?>
  696. <td><a href="exercice_submit.php?<?php echo api_get_cidreq().$myorigin.$mylpid.$myllpitemid; ?>&exerciseId=<?php echo $row['id']; ?>"><?php echo $row['title']; ?></a></td>
  697. <td align="center"> <?php
  698. $exid = $row['id'];
  699. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '".Database::escape_string($exid)."'";
  700. $sqlresult =api_sql_query($sqlquery);
  701. $rowi = Database::result($sqlresult,0);
  702. echo $rowi.' '.strtolower(get_lang(($rowi>1?'Questions':'Question'))); ?> </td>
  703. <td align="center"><?php
  704. $eid = $row['id'];
  705. $uid= api_get_user_id();
  706. //this query might be improved later on by ordering by the new "tms" field rather than by exe_id
  707. $qry = "SELECT * FROM $TBL_TRACK_EXERCICES " .
  708. "WHERE exe_exo_id = '".Database::escape_string($eid)."' and exe_user_id = '".Database::escape_string($uid)."' AND exe_cours_id = '".api_get_course_id()."' AND status <>'incomplete' AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND session_id = '".api_get_session_id()."' ORDER BY exe_id DESC";
  709. $qryres = api_sql_query($qry);
  710. $num = Database::num_rows($qryres);
  711. if ($num>0) {
  712. $row = Database::fetch_array($qryres);
  713. $percentage = 0;
  714. if($row['exe_weighting'] != 0) {
  715. $percentage = ($row['exe_result']/$row['exe_weighting'])*100;
  716. }
  717. echo get_lang('Attempted').' ('.get_lang('Score').':';
  718. printf("%1.2f\n",$percentage);
  719. echo " %)";
  720. } else {
  721. echo get_lang('NotAttempted');
  722. }
  723. ?></td>
  724. </tr>
  725. <?php
  726. }
  727. // skips the last exercise, that is only used to know if we have or not to create a link "Next page"
  728. if($i == $limitExPage) {
  729. break;
  730. }
  731. $i++;
  732. } // end while()
  733. $ind = $i;
  734. if (($from+$limitExPage-1)>$nbrexerc) {
  735. if ($from>$nbrexerc) {
  736. $from = $from - $nbrexerc;
  737. $to = $limitExPage;
  738. } else {
  739. $to = $limitExPage-($nbrexerc-$from);
  740. $from = 0;
  741. }
  742. } else {
  743. $to = $limitExPage;
  744. }
  745. if($is_allowedToEdit) {
  746. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  747. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  748. WHERE d.id = ip.ref AND ip.tool = '".TOOL_DOCUMENT."' AND
  749. (d.path LIKE '%htm%')
  750. AND d.path LIKE '".Database::escape_string($uploadPath)."/%/%' LIMIT ".(int)$from.",".(int)$to; // only .htm or .html files listed
  751. } else {
  752. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  753. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  754. WHERE d.id = ip.ref AND ip.tool = '".TOOL_DOCUMENT."' AND
  755. (d.path LIKE '%htm%')
  756. AND d.path LIKE '".Database::escape_string($uploadPath)."/%/%' AND ip.visibility='1' LIMIT ".(int)$from.",".(int)$to;
  757. }
  758. $result = api_sql_query ($sql,__FILE__,__LINE__);
  759. while ($row = Database::fetch_array($result, 'ASSOC')) {
  760. $attribute['path' ][] = $row['path' ];
  761. $attribute['visibility'][] = $row['visibility'];
  762. $attribute['comment' ][] = $row['comment' ];
  763. }
  764. $nbrActiveTests = 0;
  765. if (is_array($attribute['path'])) {
  766. while (list($key,$path) = each($attribute['path'])) {
  767. list($a,$vis)=each($attribute['visibility']);
  768. if (strcmp($vis,"1")==0) { $active=1;
  769. } else {
  770. $active=0;
  771. }
  772. echo "<tr>\n";
  773. $title = GetQuizName($path,$documentPath);
  774. if ($title =='') {
  775. $title = GetFileName($path);
  776. }
  777. // prof only
  778. if($is_allowedToEdit) {
  779. /************/
  780. ?>
  781. <tr>
  782. <td><img src="../img/jqz.jpg" alt="HotPotatoes" /></td>
  783. <td><?php echo ($ind+($page*$limitExPage)).'.'; ?></td>
  784. <td><a href="showinframes.php?file=<?php echo $path?>&cid=<?php echo $_course['official_code'];?>&uid=<?php echo $_user['user_id'];?>" <?php if(!$active) echo 'class="invisible"'; ?>><?php echo $title?></a></td>
  785. <td></td><td></td>
  786. <td><a href="adminhp.php?hotpotatoesName=<?php echo $path; ?>"> <img src="../img/edit.gif" border="0" alt="<?php echo htmlentities(get_lang('Modify'),ENT_QUOTES,$charset); ?>" /></a>
  787. <img src="../img/wizard_gray_small.gif" border="0" title="<?php echo htmlentities(get_lang('Build'),ENT_QUOTES,$charset); ?>" alt="<?php echo htmlentities(get_lang('Build'),ENT_QUOTES,$charset); ?>" />
  788. <a href="<?php echo $exercicePath; ?>?hpchoice=delete&amp;file=<?php echo $path; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('AreYouSure'),ENT_QUOTES,$charset).$title."?"); ?>')) return false;"><img src="../img/delete.gif" border="0" alt="<?php echo htmlentities(get_lang('Delete'),ENT_QUOTES,$charset); ?>" /></a>
  789. <?php
  790. // if active
  791. if($active){
  792. $nbrActiveTests = $nbrActiveTests + 1;
  793. ?>
  794. <a href="<?php echo $exercicePath; ?>?hpchoice=disable&amp;page=<?php echo $page; ?>&amp;file=<?php echo $path; ?>"><img src="../img/visible.gif" border="0" alt="<?php echo htmlentities(get_lang('Deactivate'),ENT_QUOTES,$charset); ?>" /></a>
  795. <?php
  796. } else {// else if not active
  797. ?>
  798. <a href="<?php echo $exercicePath; ?>?hpchoice=enable&amp;page=<?php echo $page; ?>&amp;file=<?php echo $path; ?>"><img src="../img/invisible.gif" border="0" alt="<?php echo htmlentities(get_lang('Activate'),ENT_QUOTES,$charset); ?>" /></a>
  799. <?php
  800. }
  801. echo '<img src="../img/lp_quiz_na.gif" border="0" alt="" />';
  802. /****************/
  803. ?></td>
  804. <?php } else {// student only
  805. if ($active==1) {
  806. $nbrActiveTests = $nbrActiveTests + 1;
  807. ?>
  808. <tr>
  809. <td><?php echo ($ind+($page*$limitExPage)).'.'; ?><!--<img src="../img/jqz.jpg" alt="HotPotatoes" />--></td>
  810. <td>&nbsp;</td>
  811. <td><a href="showinframes.php?<?php echo api_get_cidreq()."&amp;file=".$path."&amp;cid=".$_course['official_code']."&amp;uid=".$_user['user_id'].'"'; if(!$active) echo 'class="invisible"'; ?>"><?php echo $title;?></a></td>
  812. <td>&nbsp;</td><td>&nbsp;</td>
  813. </tr>
  814. <?php
  815. }
  816. }
  817. ?>
  818. <?php
  819. if ($ind == $limitExPage) {
  820. break;
  821. }
  822. if ($is_allowedToEdit) {
  823. $ind++;
  824. } else {
  825. if ($active==1) {
  826. $ind++;
  827. }
  828. }
  829. }
  830. }
  831. } //end if ($origin != 'learnpath') {
  832. ?>
  833. </table>
  834. <?php
  835. }
  836. /*****************************************/
  837. /* Exercise Results (uses tracking tool) */
  838. /*****************************************/
  839. // if tracking is enabled
  840. if ($_configuration['tracking_enabled'] AND ($show == 'result') )
  841. {
  842. ?>
  843. <table class="data_table">
  844. <tr class="row_odd">
  845. <?php if($is_allowedToEdit || $is_tutor): ?>
  846. <th><?php echo get_lang('User'); ?></th><?php endif; ?>
  847. <th><?php echo get_lang('Exercice'); ?></th>
  848. <th><?php echo get_lang('Duration'); ?></th>
  849. <th><?php echo get_lang('Date'); ?></th>
  850. <th><?php echo get_lang('Result'); ?></th>
  851. <th><?php echo (($is_allowedToEdit||$is_tutor)?get_lang("CorrectTest"):get_lang("ViewTest")); ?></th>
  852. </tr>
  853. <?php
  854. $session_id_and='';
  855. if (api_get_session_id()!=0) {
  856. $session_id_and = ' AND session_id = ' .api_get_session_id().' ';
  857. }
  858. if($is_allowedToEdit || $is_tutor) {
  859. $user_id_and='';
  860. if (!empty($_POST['filter_by_user'])) {
  861. if ($_POST['filter_by_user'] =='all') {
  862. $user_id_and = " AND user_id like '%'";
  863. } else {
  864. $user_id_and = " AND user_id = '" . Database::escape_string ( (int)$_POST['filter_by_user'] )."' ";
  865. }
  866. }
  867. if($_GET['gradebook']=='view') {
  868. $exercise_where_query = 'te.exe_exo_id =ce.id AND ';
  869. }
  870. $sql="SELECT CONCAT(lastname,' ',firstname) as users, ce.title, te.exe_result ,
  871. te.exe_weighting, UNIX_TIMESTAMP(te.exe_date), te.exe_id, email,UNIX_TIMESTAMP(te.start_date),steps_counter,user_id
  872. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user
  873. WHERE te.exe_exo_id = ce.id AND te.status != 'incomplete' AND user_id=te.exe_user_id AND te.exe_cours_id='".Database::escape_string($_cid)."'
  874. AND user.status<>1 $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0
  875. ORDER BY users, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";
  876. $hpsql="SELECT CONCAT(tu.lastname,' ',tu.firstname), tth.exe_name,
  877. tth.exe_result , tth.exe_weighting, UNIX_TIMESTAMP(tth.exe_date)
  878. FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
  879. WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '".Database::escape_string($_cid)." $user_id_and '
  880. ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
  881. } else {
  882. // get only this user's results
  883. $user_id_and = ' AND te.exe_user_id = ' . Database::escape_string ( api_get_user_id() ).' ';
  884. $sql="SELECT CONCAT(lastname,' ',firstname) as users,ce.title, te.exe_result ,
  885. te.exe_weighting, UNIX_TIMESTAMP(te.exe_date),te.exe_id,email,UNIX_TIMESTAMP(te.start_date),steps_counter,user_id
  886. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user
  887. WHERE te.exe_exo_id = ce.id AND te.status != 'incomplete' AND user_id=te.exe_user_id AND te.exe_cours_id='".Database::escape_string($_cid)."'
  888. AND user.status<>1 $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0
  889. ORDER BY users, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";
  890. $hpsql="SELECT '',exe_name, exe_result , exe_weighting, UNIX_TIMESTAMP(exe_date)
  891. FROM $TBL_TRACK_HOTPOTATOES
  892. WHERE exe_user_id = '".$_user['user_id']."' AND exe_cours_id = '".Database::escape_string($_cid)."'
  893. ORDER BY exe_cours_id ASC, exe_date DESC";
  894. //error_log($hpsql);
  895. }
  896. $results=getManyResultsXCol($sql,10);
  897. $hpresults=getManyResultsXCol($hpsql,5);
  898. $NoTestRes = 0;
  899. $NoHPTestRes = 0;
  900. //Print the results of tests
  901. $lang_nostartdate = get_lang('NoStartDate').' / ';
  902. if (is_array($results)) {
  903. $users_array_id = array();
  904. if ($_GET['gradebook']=='view') {
  905. $filter_by_no_revised = true;
  906. $from_gradebook = true;
  907. }
  908. $sizeof = sizeof($results);
  909. $user_list_name = $user_list_id = array();
  910. for ($i = 0; $i < $sizeof; $i++) {
  911. $revised = false;
  912. $sql_exe='SELECT exe_id FROM '.Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING).' WHERE author != '."''".' AND exe_id = '."'".$results[$i][5]."'".' LIMIT 1';
  913. $query = api_sql_query($sql_exe,__FILE__,__LINE__);
  914. if ( Database::num_rows($query) > 0) {
  915. $revised = true;
  916. }
  917. if ($filter_by_not_revised && $revised == true) {
  918. continue;
  919. }
  920. if($filter_by_revised && $revised == false) {
  921. continue;
  922. }
  923. if($from_gradebook && ($is_allowedToEdit || $is_tutor)) {
  924. if(in_array($results[$i][1].$results[$i][0],$users_array_id)) {
  925. continue;
  926. }
  927. $users_array_id[] = $results[$i][1].$results[$i][0];
  928. }
  929. $user_list_name[] = $results[$i][0];
  930. $user_list_id[] = $results[$i][9];
  931. $id = $results[$i][5];
  932. $mailid = $results[$i][6];
  933. $user = $results[$i][0];
  934. $test = $results[$i][1];
  935. $dt = strftime($dateTimeFormatLong,$results[$i][4]);
  936. $res = $results[$i][2];
  937. echo '<tr';
  938. if ($i%2==0) {
  939. echo 'class="row_odd"';
  940. } else {
  941. echo 'class="row_even"';
  942. }
  943. echo '>';
  944. $add_start_date = $lang_nostartdate;
  945. if ($is_allowedToEdit || $is_tutor) {
  946. $user = $results[$i][0];
  947. echo '<td>'.$user.' '.$duration.'</td>';
  948. }
  949. echo '<td>'.$test.'</td>';
  950. echo '<td>';
  951. if ($results[$i][7] > 1) {
  952. echo ceil((($results[$i][4] - $results[$i][7])/60)).' '.get_lang('Min');
  953. if($results[$i][8] > 1) {
  954. echo ' ( '.$results[$i][8].' '.get_lang('Steps').' )';
  955. }
  956. $add_start_date = format_locale_date('%b %d, %Y %H:%M',$results[$i][7]).' / ';
  957. } else {
  958. echo get_lang('NoLogOfDuration');
  959. }
  960. echo '</td>';
  961. echo '<td>'.$add_start_date.format_locale_date('%b %d, %Y %H:%M',$results[$i][4]).'</td>';//get_lang('dateTimeFormatLong')
  962. echo '<td>'.round(($res/($results[$i][3]!=0?$results[$i][3]:1))*100).'% ('.$res.' / '.$results[$i][3].')</td>';
  963. echo '<td>'.(($is_allowedToEdit||$is_tutor)?
  964. "<a href='exercise_show.php?user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".
  965. (($revised)?get_lang('Edit'):get_lang('Qualify'))."</a>".
  966. ((api_is_platform_admin() || $is_tutor)?' - <a href="exercice.php?cidReq='.htmlentities($_GET['cidReq']).'&show=result&filter='.$filter.'&delete=delete&did='.$id.'" onclick="javascript:if(!confirm(\''.sprintf(get_lang('DeleteAttempt'),$user,$dt).'\')) return false;">'.get_lang('Delete').'</a>':'')
  967. .(($is_allowedToEdit)?' - <a href="exercice_history.php?cidReq='.htmlentities($_GET['cidReq']).'&exe_id='.$id.'">'.get_lang('ViewHistory').'</a>':'')
  968. :(($revised)?"<a href='exercise_show.php?dt=$dt&res=$res&id=$id'>".get_lang('Show')."</a>":'')).'</td>';
  969. echo '</tr>';
  970. }
  971. } else {
  972. $NoTestRes = 1;
  973. }
  974. // Print the Result of Hotpotatoes Tests
  975. if (is_array($hpresults)) {
  976. for($i = 0; $i < sizeof($hpresults); $i++) {
  977. $title = GetQuizName($hpresults[$i][1],$documentPath);
  978. if ($title =='') {
  979. $title = GetFileName($hpresults[$i][1]);
  980. }
  981. echo '<tr>';
  982. if ($is_allowedToEdit) {
  983. echo '<td class="content">'.$hpresults[$i][0].'</td>';
  984. }
  985. echo '<td class="content">'.$title.'</td>';
  986. echo '<td class="content">'.strftime($dateTimeFormatLong,$hpresults[$i][4]).'</td>';
  987. echo '<td class="content">'.round(($hpresults[$i][2]/($hpresults[$i][3]!=0?$hpresults[$i][3]:1))*100).'% ('.$hpresults[$i][2].' / '.$hpresults[$i][3].')</td>';
  988. echo '<td></td>'; //there is no possibility to edit the results of a Hotpotatoes test
  989. echo '</tr>';
  990. }
  991. } else {
  992. $NoHPTestRes = 1;
  993. }
  994. if ($NoTestRes==1 && $NoHPTestRes==1) {
  995. ?>
  996. <tr>
  997. <td colspan="6"><?php echo get_lang("NoResult"); ?></td>
  998. </tr>
  999. <?php
  1000. }
  1001. ?>
  1002. </table>
  1003. <br />
  1004. <?php
  1005. }
  1006. if ($origin != 'learnpath') { //so we are not in learnpath tool
  1007. Display::display_footer();
  1008. } else {
  1009. ?>
  1010. <link rel="stylesheet" type="text/css" href="<?php echo $clarolineRepositoryWeb ?>css/default.css" />
  1011. <?php
  1012. }
  1013. ?>