exercice.php 39 KB

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