exercice.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4. For a full list of contributors, see documentation/credits.html
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. See "documentation/licence.html" more details.
  10. Contact:
  11. Dokeos
  12. Rue des Palais 44 Paleizenstraat
  13. B-1030 Brussels - Belgium
  14. Tel. +32 (2) 211 34 56
  15. */
  16. /**
  17. * Exercise list: This script shows the list of exercises for administrators and students.
  18. * @package dokeos.exercise
  19. * @author Olivier Brouckaert, original author
  20. * @author Denes Nagy, HotPotatoes integration
  21. * @author Wolfgang Schneider, code/html cleanup
  22. * @version $Id:exercice.php 12269 2007-05-03 14:17:37Z elixir_julian $
  23. */
  24. // name of the language file that needs to be included
  25. $language_file='exercice';
  26. require_once('../inc/global.inc.php');
  27. $this_section=SECTION_COURSES;
  28. api_protect_course_script(true);
  29. $show=(isset($_GET['show']) && $_GET['show'] == 'result')?'result':'test'; // moved down to fix bug: http://www.dokeos.com/forum/viewtopic.php?p=18609#18609
  30. /*
  31. -----------------------------------------------------------
  32. Libraries
  33. -----------------------------------------------------------
  34. */
  35. require_once('exercise.class.php');
  36. require_once('question.class.php');
  37. require_once('answer.class.php');
  38. require_once(api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  39. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  40. require_once('hotpotatoes.lib.php');
  41. require_once(api_get_path(LIBRARY_PATH).'document.lib.php');
  42. include(api_get_path(LIBRARY_PATH).'mail.lib.inc.php');
  43. /*
  44. -----------------------------------------------------------
  45. Constants and variables
  46. -----------------------------------------------------------
  47. */
  48. $is_allowedToEdit = api_is_allowed_to_edit();
  49. $is_tutor = api_is_allowed_to_edit(true);
  50. $TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
  51. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  52. $TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  53. $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  54. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  55. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  56. $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  57. $TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  58. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  59. // document path
  60. $documentPath= api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  61. // picture path
  62. $picturePath=$documentPath.'/images';
  63. // audio path
  64. $audioPath=$documentPath.'/audio';
  65. // hotpotatoes
  66. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  67. $exercicePath = api_get_self();
  68. $exfile = explode('/',$exercicePath);
  69. $exfile = strtolower($exfile[sizeof($exfile)-1]);
  70. $exercicePath = substr($exercicePath,0,strpos($exercicePath,$exfile));
  71. $exercicePath = $exercicePath."exercice.php";
  72. // maximum number of exercises on a same page
  73. $limitExPage=50;
  74. // Clear the exercise session
  75. if(isset($_SESSION['objExercise'])) { api_session_unregister('objExercise'); }
  76. if(isset($_SESSION['objQuestion'])) { api_session_unregister('objQuestion'); }
  77. if(isset($_SESSION['objAnswer'])) { api_session_unregister('objAnswer'); }
  78. if(isset($_SESSION['questionList'])) { api_session_unregister('questionList'); }
  79. if(isset($_SESSION['exerciseResult'])) { api_session_unregister('exerciseResult'); }
  80. //general POST/GET/SESSION/COOKIES parameters recovery
  81. if ( empty ( $origin ) ) {
  82. $origin = $_REQUEST['origin'];
  83. }
  84. if ( empty ($choice ) ) {
  85. $choice = $_REQUEST['choice'];
  86. }
  87. if ( empty ( $hpchoice ) ) {
  88. $hpchoice = $_REQUEST['hpchoice'];
  89. }
  90. if ( empty ($exerciseId ) ) {
  91. $exerciseId = Database::escape_string($_REQUEST['exerciseId']);
  92. }
  93. if ( empty ( $file ) ) {
  94. $file = Database::escape_string($_REQUEST['file']);
  95. }
  96. $learnpath_id = Database::escape_string($_REQUEST['learnpath_id']);
  97. $learnpath_item_id = Database::escape_string($_REQUEST['learnpath_item_id']);
  98. $page = Database::escape_string($_REQUEST['page']);
  99. if($origin == 'learnpath'){
  100. $show = 'result';
  101. }
  102. $htmlHeadXtra[]='<style type="text/css">
  103. <!--
  104. a.invisible
  105. {
  106. color: #999999;
  107. }
  108. a.invisible:visited
  109. {
  110. color: #999999;
  111. }
  112. a.invisible:active
  113. {
  114. color: #999999;
  115. }
  116. a.invisible:hover
  117. {
  118. color: #999999;
  119. }
  120. -->
  121. </style>';
  122. if ($show=='result' && $_REQUEST['comments']=='update' && ($is_allowedToEdit || $is_tutor))
  123. {
  124. $id = $_GET['exeid'];
  125. $emailid = $_GET['emailid'];
  126. $test = $_GET['test'];
  127. $from = $_SESSION['_user']['mail'];
  128. $from_name = $_SESSION['_user']['firstName']." ".$_SESSION['_user']['lastName'];
  129. $url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result';
  130. foreach ($_POST as $key=>$v)
  131. {
  132. $keyexp = explode('_',$key);
  133. if ($keyexp[0] == "marks")
  134. {
  135. $sql = "select question from $TBL_QUESTIONS where id = '$keyexp[1]'";
  136. $result =api_sql_query($sql, __FILE__, __LINE__);
  137. $ques_name = mysql_result($result,0,"question");
  138. $query = "update $TBL_TRACK_ATTEMPT set marks = '$v' where question_id = $keyexp[1] and exe_id=$id";
  139. api_sql_query($query, __FILE__, __LINE__);
  140. $qry = 'SELECT sum(marks) as tot
  141. FROM '.$TBL_TRACK_ATTEMPT.' where exe_id = '.intval($id).'
  142. GROUP BY question_id';
  143. $res = api_sql_query($qry,__FILE__,__LINE__);
  144. $tot = mysql_result($res,0,'tot');
  145. $totquery = "update $TBL_TRACK_EXERCICES set exe_result = $tot where exe_Id=$id";
  146. api_sql_query($totquery, __FILE__, __LINE__);
  147. }
  148. else
  149. {
  150. $query = "update $TBL_TRACK_ATTEMPT set teacher_comment = '$v' where question_id = $keyexp[1] and exe_id = $id ";
  151. api_sql_query($query, __FILE__, __LINE__);
  152. }
  153. }
  154. $qry = 'SELECT DISTINCT question_id, marks
  155. FROM '.$TBL_TRACK_ATTEMPT.' where exe_id = '.intval($id).'
  156. GROUP BY question_id';
  157. $res = api_sql_query($qry,__FILE__,__LINE__);
  158. $tot = 0;
  159. while($row = Database::fetch_array($res,'ASSOC'))
  160. {
  161. $tot += $row ['marks'];
  162. }
  163. $totquery = "update $TBL_TRACK_EXERCICES set exe_result = $tot where exe_Id=$id";
  164. api_sql_query($totquery, __FILE__, __LINE__);
  165. $subject = get_lang('ExamSheetVCC');
  166. $htmlmessage = '<html>'.
  167. '<head>' .
  168. '<style type="text/css">' .
  169. '<!--' .
  170. '.body{' .
  171. 'font-family: Verdana, Arial, Helvetica, sans-serif;' .
  172. 'font-weight: Normal;' .
  173. 'color: #000000;' .
  174. '}' .
  175. '.style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; color: #006699; }' .
  176. '.style10 {' .
  177. ' font-family: Verdana, Arial, Helvetica, sans-serif;' .
  178. ' font-size: 12px;' .
  179. ' font-weight: bold;' .
  180. '}' .
  181. '.style16 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }' .
  182. '-->' .
  183. '</style>' .
  184. '</head>' .
  185. '<body>' .
  186. '<div>' .
  187. ' <p>'.get_lang('DearStudentEmailIntroduction').'</p>' .
  188. ' <p class="style10"> '.get_lang('AttemptVCC').' </p>' .
  189. ' <table width="417">' .
  190. ' <tr>' .
  191. ' <td width="229" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>' .
  192. ' <td width="469" valign="top" bgcolor="#F3F3F3"><span class="style16">#ques_name#</span></td>' .
  193. ' </tr>' .
  194. ' <tr>' .
  195. ' <td width="229" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Exercice').'</span></td>' .
  196. ' <td width="469" valign="top" bgcolor="#F3F3F3"><span class="style16">#test#</span></td>' .
  197. ' </tr>' .
  198. ' </table>' .
  199. ' <p>'.get_lang('ClickLinkToViewComment').' <a href="#url#">#url#</a><br />' .
  200. ' <br />' .
  201. ' '.get_lang('Regards').' </p>' .
  202. ' </div>' .
  203. ' </body>' .
  204. ' </html>';
  205. $message = '<p>'.sprintf(get_lang('AttemptVCCLong'),$test).' <A href="#url#">#url#</A></p><br />';
  206. $mess= str_replace("#test#",$test,$message);
  207. //$message= str_replace("#ques_name#",$ques_name,$mess);
  208. $message = str_replace("#url#",$url,$mess);
  209. $mess = stripslashes($message);
  210. $headers = " MIME-Version: 1.0 \r\n";
  211. $headers .= "User-Agent: Dokeos/1.6";
  212. $headers .= "Content-Transfer-Encoding: 7bit";
  213. $headers .= 'From: '.$from_name.' <'.$from.'>' . "\r\n";
  214. $headers="From:$from_name\r\nReply-to: $to\r\nContent-type: text/html; charset=".($charset?$charset:'ISO-8859-15');
  215. //mail($emailid, $subject, $mess,$headers);
  216. api_mail_html($emailid, $emailid, $subject, $mess, $from_name, $from);
  217. if(in_array($origin, array('tracking_course','user_course'))){
  218. //Redirect to the reporting
  219. header('location: ../mySpace/myStudents.php?origin='.$origin.'&student='.$_GET['student'].'&details=true&course='.$_GET['course']);
  220. }
  221. }
  222. if($show!='result')
  223. {
  224. $nameTools=get_lang('Exercices');
  225. }
  226. else
  227. {
  228. if($is_allowedToEdit || $is_tutor)
  229. {
  230. $nameTools=get_lang('StudentScore');
  231. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  232. }
  233. else
  234. {
  235. $nameTools=get_lang('YourScore');
  236. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  237. }
  238. }
  239. if($is_allowedToEdit && !empty($choice) && $choice == 'exportqti2')
  240. {
  241. require_once('export/qti2/qti2_export.php');
  242. $export = export_exercise($exerciseId,true);
  243. require_once(api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php');
  244. $garbage_path = api_get_path(GARBAGE_PATH);
  245. $temp_dir_short = uniqid();
  246. $temp_zip_dir = $garbage_path."/".$temp_dir_short;
  247. if(!is_dir($temp_zip_dir)) mkdir($temp_zip_dir);
  248. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  249. $temp_xml_file = $temp_zip_dir."/qti2export_".$exerciseId.'.xml';
  250. file_put_contents($temp_xml_file,$export);
  251. $zip_folder=new PclZip($temp_zip_file);
  252. $zip_folder->add($temp_zip_dir, PCLZIP_OPT_REMOVE_PATH, $temp_zip_dir);
  253. $name = 'qti2_export_'.$exerciseId.'.zip';
  254. //DocumentManager::string_send_for_download($export,true,'qti2export_'.$exerciseId.'.xml');
  255. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  256. unlink($temp_zip_file);
  257. unlink($temp_xml_file);
  258. rmdir($temp_zip_dir);
  259. exit(); //otherwise following clicks may become buggy
  260. }
  261. if ($origin != 'learnpath')
  262. {
  263. //so we are not in learnpath tool
  264. Display::display_header($nameTools,"Exercise");
  265. if(isset($_GET['message']))
  266. {
  267. if (in_array($_GET['message'], array('ExerciseEdited')))
  268. {
  269. Display::display_confirmation_message(get_lang($_GET['message']));
  270. }
  271. }
  272. }
  273. else
  274. {
  275. echo '<link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_CODE_PATH).'css/default.css"/>';
  276. }
  277. // used for stats
  278. include_once(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  279. event_access_tool(TOOL_QUIZ);
  280. // need functions of statsutils lib to display previous exercices scores
  281. include_once(api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php');
  282. Display::display_introduction_section(TOOL_QUIZ);
  283. // selects $limitExPage exercises at the same time
  284. $from=$page*$limitExPage;
  285. // $sql="SELECT id,title,type,active FROM $TBL_EXERCICES ORDER BY title LIMIT $from,".($limitExPage+1);
  286. // $result=api_sql_query($sql,__FILE__,__LINE__);
  287. $sql="SELECT count(id) FROM $TBL_EXERCICES";
  288. $res = api_sql_query($sql,__FILE__,__LINE__);
  289. list($nbrexerc) = Database::fetch_array($res);
  290. HotPotGCt($documentPath,1,$_user['user_id']);
  291. // only for administrator
  292. if($is_allowedToEdit)
  293. {
  294. if(!empty($choice))
  295. {
  296. // construction of Exercise
  297. $objExerciseTmp=new Exercise();
  298. if($objExerciseTmp->read($exerciseId))
  299. {
  300. switch($choice)
  301. {
  302. case 'delete': // deletes an exercise
  303. $objExerciseTmp->delete();
  304. Display::display_confirmation_message(get_lang('ExerciseDeleted'));
  305. break;
  306. case 'enable': // enables an exercise
  307. $objExerciseTmp->enable();
  308. $objExerciseTmp->save();
  309. // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
  310. api_item_property_update($_course, TOOL_QUIZ, $exerciseId, "QuizAdded", $_user['user_id']);
  311. Display::display_confirmation_message(get_lang('VisibilityChanged'));
  312. break;
  313. case 'disable': // disables an exercise
  314. $objExerciseTmp->disable();
  315. $objExerciseTmp->save();
  316. Display::display_confirmation_message(get_lang('VisibilityChanged'));
  317. break;
  318. }
  319. }
  320. // destruction of Exercise
  321. unset($objExerciseTmp);
  322. }
  323. //$sql="SELECT id,title,type,active FROM $TBL_EXERCICES ORDER BY title LIMIT $from,".($limitExPage+1);
  324. //$result=api_sql_query($sql,__FILE__,__LINE__);
  325. if(!empty($hpchoice))
  326. {
  327. switch($hpchoice)
  328. {
  329. case 'delete': // deletes an exercise
  330. $imgparams = array();
  331. $imgcount = 0;
  332. GetImgParams($file,$documentPath,$imgparams,$imgcount);
  333. $fld = GetFolderName($file);
  334. for($i=0;$i < $imgcount;$i++)
  335. {
  336. my_delete($documentPath.$uploadPath."/".$fld."/".$imgparams[$i]);
  337. update_db_info("delete", $uploadPath."/".$fld."/".$imgparams[$i]);
  338. }
  339. if ( my_delete($documentPath.$file))
  340. {
  341. update_db_info("delete", $file);
  342. }
  343. my_delete($documentPath.$uploadPath."/".$fld."/");
  344. break;
  345. case 'enable': // enables an exercise
  346. $newVisibilityStatus = "1"; //"visible"
  347. $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='$file'";
  348. $res = api_sql_query($query,__FILE__,__LINE__);
  349. $row = Database::fetch_array($res, 'ASSOC');
  350. api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'visible', $_user['user_id']);
  351. //$dialogBox = get_lang('ViMod');
  352. break;
  353. case 'disable': // disables an exercise
  354. $newVisibilityStatus = "0"; //"invisible"
  355. $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='$file'";
  356. $res = api_sql_query($query,__FILE__,__LINE__);
  357. $row = Database::fetch_array($res, 'ASSOC');
  358. api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'invisible', $_user['user_id']);
  359. #$query = "UPDATE $TBL_DOCUMENT SET visibility='$newVisibilityStatus' WHERE path=\"".$file."\""; //added by Toon
  360. #api_sql_query($query,__FILE__,__LINE__);
  361. //$dialogBox = get_lang('ViMod');
  362. break;
  363. default:
  364. break;
  365. }
  366. }
  367. if($show == 'test')
  368. {
  369. $sql="SELECT id,title,type,active,description FROM $TBL_EXERCICES WHERE active<>'-1' ORDER BY title LIMIT $from,".($limitExPage+1);
  370. $result=api_sql_query($sql,__FILE__,__LINE__);
  371. }
  372. }
  373. // only for students
  374. elseif($show == 'test')
  375. {
  376. $sql="SELECT id,title,type,description FROM $TBL_EXERCICES WHERE active='1' ORDER BY title LIMIT $from,".($limitExPage+1);
  377. $result=api_sql_query($sql,__FILE__,__LINE__);
  378. }
  379. if($show == 'test'){
  380. $nbrExercises=Database::num_rows($result);
  381. echo "<table border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">",
  382. "<tr>";
  383. if (($is_allowedToEdit) and ($origin != 'learnpath'))
  384. {
  385. echo "<td width=\"50%\" nowrap=\"nowrap\">",
  386. "<img src=\"../img/new_test.gif\" alt=\"new test\" align=\"absbottom\">&nbsp;<a href=\"exercise_admin.php?".api_get_cidreq()."\">".get_lang("NewEx")."</a>",
  387. " | <img src=\"../img/jqz.jpg\" alt=\"HotPotatoes\" valign=\"ABSMIDDLE\">&nbsp;<a href=\"hotpotatoes.php\">".get_lang("ImportHotPotatoesQuiz")."</a>",
  388. "</td>",
  389. "<td width=\"50%\" align=\"right\">";
  390. }
  391. else
  392. {
  393. echo "<td align=\"right\">";
  394. }
  395. //get HotPotatoes files (active and inactive)
  396. $res = api_sql_query ("SELECT *
  397. FROM $TBL_DOCUMENT
  398. WHERE
  399. path LIKE '".$uploadPath."/%/%'",__FILE__,__LINE__);
  400. $nbrTests = Database::num_rows($res);
  401. $res = api_sql_query ("SELECT *
  402. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  403. WHERE d.id = ip.ref
  404. AND ip.tool = '".TOOL_DOCUMENT."'
  405. AND d.path LIKE '".$uploadPath."/%/%'
  406. AND ip.visibility='1'", __FILE__,__LINE__);
  407. $nbrActiveTests = Database::num_rows($res);
  408. if($is_allowedToEdit)
  409. {//if user is allowed to edit, also show hidden HP tests
  410. $nbrHpTests = $nbrTests;
  411. }else
  412. {
  413. $nbrHpTests = $nbrActiveTests;
  414. }
  415. $nbrNextTests = $nbrexerc-$nbrHpTests-(($page*$limitExPage));
  416. //show pages navigation link for previous page
  417. if($page)
  418. {
  419. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&page=".($page-1)."\">&lt;&lt; ",get_lang("PreviousPage")."</a> | ";
  420. }
  421. elseif($nbrExercises+$nbrNextTests > $limitExPage)
  422. {
  423. echo "&lt;&lt; ",get_lang("PreviousPage")." | ";
  424. }
  425. //show pages navigation link for previous page
  426. if($nbrExercises+$nbrNextTests > $limitExPage)
  427. {
  428. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&page=".($page+1)."\">&gt;&gt; ",get_lang("NextPage")."</a>";
  429. }
  430. elseif($page)
  431. {
  432. echo get_lang("NextPage") . " &gt;&gt;";
  433. }
  434. echo "</td>",
  435. "</tr>",
  436. "</table>";
  437. ?>
  438. <table class="data_table">
  439. <?php
  440. if (($is_allowedToEdit) and ($origin != 'learnpath'))
  441. {
  442. ?>
  443. <tr class="row_odd">
  444. <th colspan="2"><?php echo get_lang("ExerciseName");?></th>
  445. <th><?php echo get_lang("Description");?></th>
  446. <th><?php echo get_lang('Export');?></th>
  447. <th><?php echo get_lang("Modify");?></th>
  448. </tr>
  449. <?php
  450. }
  451. else
  452. {
  453. ?> <tr bgcolor="#e6e6e6">
  454. <th><?php echo get_lang("ExerciseName");?></th>
  455. <th><?php echo get_lang("Description");?></th>
  456. <th><?php echo get_lang("State");?></th>
  457. </tr>
  458. <?php }
  459. // show message if no HP test to show
  460. if(!($nbrExercises+$nbrHpTests) )
  461. {
  462. ?>
  463. <tr>
  464. <td <?php echo ($is_allowedToEdit?'colspan="5"':'colspan="3"'); ?>><?php echo get_lang("NoEx"); ?></td>
  465. </tr>
  466. <?php
  467. }
  468. $i=1;
  469. // while list exercises
  470. if ($origin != 'learnpath')
  471. {
  472. //avoid sending empty parameters
  473. $myorigin = (empty($origin)?'':'&origin='.$origin);
  474. $mylpid = (empty($learnpath_id)?'':'&learnpath_id='.$learnpath_id);
  475. $mylpitemid = (empty($learnpath_item_id)?'':'&learnpath_item_id='.$learnpath_item_id);
  476. while($row=Database::fetch_array($result))
  477. {
  478. if($i%2==0) $s_class="row_odd"; else $s_class="row_even";
  479. echo "<tr class='$s_class'>\n";
  480. // prof only
  481. if($is_allowedToEdit)
  482. {
  483. ?>
  484. <td width="27%" colspan="2">
  485. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  486. <tr>
  487. <td width="30" align="left"><img src="../img/quiz.gif"></td>
  488. <td width="15" valign="left" align="center"><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
  489. <?php $row['title']=api_parse_tex($row['title']); ?>
  490. <td>
  491. <a href="exercice_submit.php?<?php echo api_get_cidreq().$myorigin.$mylpid.$mylpitemid; ?>&exerciseId=<?php echo $row['id']; ?>" <?php if(!$row['active']) echo 'class="invisible"'; ?>><?php echo $row['title']; ?></a>
  492. </td>
  493. </tr>
  494. </table>
  495. </td>
  496. <td width="8%" align="center"> <?php
  497. $exid = $row['id'];
  498. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE `exercice_id` = '$exid'";
  499. $sqlresult =api_sql_query($sqlquery);
  500. $rowi = mysql_result($sqlresult,0);
  501. echo $rowi.' '.strtolower(get_lang(($rowi>1?'Questions':'Question'))).'</td>';
  502. echo '<td width="5%" align="center"><a href="exercice.php?choice=exportqti2&exerciseId='.$row['id'].'"><img src="../img/export.png" border="0" title="IMS/QTI" /></a></td>';
  503. ?>
  504. <td width="12%" align="center">
  505. <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>
  506. <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>
  507. <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>
  508. <?php
  509. // if active
  510. if($row['active'])
  511. {
  512. ?>
  513. <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>
  514. <?php
  515. }
  516. // else if not active
  517. else
  518. {
  519. ?>
  520. <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>
  521. <?php
  522. }
  523. echo "</td>";
  524. echo "</tr>\n";
  525. }
  526. // student only
  527. else
  528. {
  529. ?>
  530. <td width="40%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
  531. <tr>
  532. <td width="20" valign="top" align="right"><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
  533. <td width="1">&nbsp;</td>
  534. <?php $row['title']=api_parse_tex($row['title']);?>
  535. <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>
  536. </tr>
  537. </table></td>
  538. <td align='center'> <?php
  539. $exid = $row['id'];
  540. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE `exercice_id` = '$exid'";
  541. $sqlresult =api_sql_query($sqlquery);
  542. $rowi = mysql_result($sqlresult,0);
  543. echo ($rowi>1?get_lang('Questions'):get_lang('Question')); ?> </td>
  544. <td align='center'><?php
  545. $eid = $row['id'];
  546. $uid= api_get_user_id();
  547. $qry = "select * from `".$TBL_TRACK_EXERCICES."` where exe_exo_id = $eid and exe_user_id = $uid and exe_cours_id = '".api_get_course_id()."'";
  548. $qryres = api_sql_query($qry);
  549. $num = Database::num_rows($qryres);
  550. $row = Database::fetch_array($qryres);
  551. $percentage = 0;
  552. if($row['exe_weighting'] != 0)
  553. {
  554. $percentage = ($row['exe_result']/$row['exe_weighting'])*100;
  555. }
  556. if ($num>0)
  557. {
  558. echo get_lang('Attempted').' ('.get_lang('Score').':';
  559. printf("%1.2f\n",$percentage);
  560. echo " %)";
  561. }
  562. else
  563. {
  564. echo get_lang('NotAttempted');
  565. }
  566. ?></td>
  567. </tr>
  568. <?php
  569. }
  570. // skips the last exercise, that is only used to know if we have or not to create a link "Next page"
  571. if($i == $limitExPage)
  572. {
  573. break;
  574. }
  575. $i++;
  576. } // end while()
  577. $ind = $i;
  578. if (($from+$limitExPage-1)>$nbrexerc)
  579. {
  580. if($from>$nbrexerc)
  581. {
  582. $from = $from - $nbrexerc;
  583. $to = $limitExPage;
  584. }
  585. else
  586. {
  587. $to = $limitExPage-($nbrexerc-$from);
  588. $from = 0;
  589. }
  590. }
  591. else{
  592. $to = $limitExPage;
  593. }
  594. if($is_allowedToEdit)
  595. {
  596. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  597. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  598. WHERE d.id = ip.ref AND ip.tool = '".TOOL_DOCUMENT."' AND
  599. (d.path LIKE '%htm%' OR d.path LIKE '%html%')
  600. AND d.path LIKE '".$uploadPath."/%/%' LIMIT $from,$to"; // only .htm or .html files listed
  601. }
  602. else
  603. {
  604. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  605. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  606. WHERE d.id = ip.ref AND ip.tool = '".TOOL_DOCUMENT."' AND
  607. (d.path LIKE '%htm%' OR d.path LIKE '%html%')
  608. AND d.path LIKE '".$uploadPath."/%/%' AND ip.visibility='1' LIMIT $from,$to";
  609. }
  610. $result = api_sql_query ($sql,__FILE__,__LINE__);
  611. while($row = Database::fetch_array($result, 'ASSOC'))
  612. {
  613. $attribute['path' ][] = $row['path' ];
  614. $attribute['visibility'][] = $row['visibility'];
  615. $attribute['comment' ][] = $row['comment' ];
  616. }
  617. $nbrActiveTests = 0;
  618. if(is_array($attribute['path']))
  619. {
  620. while(list($key,$path) = each($attribute['path']))
  621. {
  622. list($a,$vis)=each($attribute['visibility']);
  623. if (strcmp($vis,"1")==0)
  624. { $active=1;}
  625. else
  626. { $active=0;}
  627. echo "<tr>\n";
  628. $title = GetQuizName($path,$documentPath);
  629. if ($title =='')
  630. {
  631. $title = GetFileName($path);
  632. }
  633. // prof only
  634. if($is_allowedToEdit)
  635. {
  636. /************/
  637. ?>
  638. <td width="27%" colspan="2">
  639. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  640. <tr>
  641. <td width="30" align="left"><img src="../img/jqz.jpg" alt="HotPotatoes" /></td>
  642. <td width="15" align="center"><?php echo ($ind+($page*$limitExPage)).'.'; ?></td>
  643. <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>
  644. </tr>
  645. </table></td>
  646. <td></td><td></td>
  647. <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>
  648. <a href="<?php echo $exercicePath; ?>?hpchoice=delete&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>
  649. <?php
  650. // if active
  651. if($active)
  652. {
  653. $nbrActiveTests = $nbrActiveTests + 1;
  654. ?>
  655. <a href="<?php echo $exercicePath; ?>?hpchoice=disable&page=<?php echo $page; ?>&file=<?php echo $path; ?>"><img src="../img/visible.gif" border="0" alt="<?php echo htmlentities(get_lang('Deactivate'),ENT_QUOTES,$charset); ?>" /></a>
  656. <?php
  657. }
  658. // else if not active
  659. else
  660. {
  661. ?>
  662. <a href="<?php echo $exercicePath; ?>?hpchoice=enable&page=<?php echo $page; ?>&file=<?php echo $path; ?>"><img src="../img/invisible.gif" border="0" alt="<?php echo htmlentities(get_lang('Activate'),ENT_QUOTES,$charset); ?>" /></a>
  663. <?php
  664. }
  665. /****************/
  666. ?></td>
  667. <?php }
  668. // student only
  669. else
  670. {
  671. if ($active==1)
  672. {
  673. $nbrActiveTests = $nbrActiveTests + 1;
  674. ?>
  675. <td width="40%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
  676. <td width="20" align="right"><?php echo ($ind+($page*$limitExPage)).'.'; ?><!--<img src="../img/jqz.jpg" alt="HotPotatoes" />--></td>
  677. <td width="1">&nbsp;</td>
  678. <td><a href="showinframes.php?<?php echo api_get_cidreq()."&file=".$path."&cid=".$_course['official_code']."&uid=".$_user['user_id'].'"'; if(!$active) echo 'class="invisible"'; ?>"><?php echo $title;?></a></td>
  679. </tr>
  680. </table></td>
  681. </tr>
  682. <?php
  683. }
  684. }
  685. ?>
  686. <?php
  687. if($ind == $limitExPage)
  688. {
  689. break;
  690. }
  691. if($is_allowedToEdit)
  692. {
  693. $ind++;
  694. }
  695. else
  696. {
  697. if ($active==1)
  698. {
  699. $ind++;
  700. }
  701. }
  702. //echo '<tr><td colspan="5"><hr /></td></tr>';
  703. }
  704. }
  705. } //end if ($origin != 'learnpath') {
  706. ?>
  707. </table>
  708. <?php
  709. }else{
  710. if($origin != 'learnpath'){
  711. echo '<a href="'.api_add_url_param($_SERVER['REQUEST_URI'],'show=test').'">&lt;&lt; '.get_lang('Back').'</a>';
  712. }
  713. }// end if($show == 'test')
  714. /*****************************************/
  715. /* Exercise Results (uses tracking tool) */
  716. /*****************************************/
  717. // if tracking is enabled
  718. if($_configuration['tracking_enabled'])
  719. {
  720. if($show == 'result'){
  721. ?>
  722. <table class="data_table">
  723. <tr class="row_odd">
  724. <?php if($is_allowedToEdit || $is_tutor): ?>
  725. <th><?php echo get_lang("User"); ?></th><?php endif; ?>
  726. <th><?php echo get_lang("Exercice"); ?></th>
  727. <th><?php echo get_lang("Date"); ?></th>
  728. <th><?php echo get_lang("Result"); ?></th>
  729. <th><?php echo (($is_allowedToEdit||$is_tutor)?get_lang("CorrectTest"):get_lang("ViewTest")); ?></th>
  730. </tr>
  731. <?php
  732. if($is_allowedToEdit || $is_tutor)
  733. {
  734. //get all results (ourself and the others) as an admin should see them
  735. //AND exe_user_id <> $_user['user_id'] clause has been removed
  736. $sql="SELECT CONCAT(`lastname`,' ',`firstname`),`ce`.`title`, `te`.`exe_result` ,
  737. `te`.`exe_weighting`, UNIX_TIMESTAMP(`te`.`exe_date`),`te`.`exe_Id`,email
  738. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user
  739. WHERE `te`.`exe_exo_id` = `ce`.`id` AND `user_id`=`te`.`exe_user_id` AND `te`.`exe_cours_id`='$_cid'
  740. ORDER BY `te`.`exe_cours_id` ASC, `ce`.`title` ASC, `te`.`exe_date`ASC";
  741. $hpsql="SELECT CONCAT(tu.lastname,' ',tu.firstname), tth.exe_name,
  742. tth.exe_result , tth.exe_weighting, UNIX_TIMESTAMP(tth.exe_date)
  743. FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
  744. WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '".$_cid."'
  745. ORDER BY tth.exe_cours_id ASC, tth.exe_date ASC";
  746. }
  747. else
  748. { // get only this user's results
  749. $sql="SELECT '',`ce`.`title`, `te`.`exe_result` , `te`.`exe_weighting`, UNIX_TIMESTAMP(`te`.`exe_date`),`te`.`exe_Id`
  750. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te
  751. WHERE `te`.`exe_exo_id` = `ce`.`id` AND `te`.`exe_user_id`='".$_user['user_id']."' AND `te`.`exe_cours_id`='$_cid'
  752. ORDER BY `te`.`exe_cours_id` ASC, `ce`.`title` ASC, `te`.`exe_date`ASC";
  753. $hpsql="SELECT '',exe_name, exe_result , exe_weighting, UNIX_TIMESTAMP(exe_date)
  754. FROM $TBL_TRACK_HOTPOTATOES
  755. WHERE exe_user_id = '".$_user['user_id']."' AND exe_cours_id = '".$_cid."'
  756. ORDER BY exe_cours_id ASC, exe_date ASC";
  757. }
  758. $results=getManyResultsXCol($sql,7);
  759. $hpresults=getManyResultsXCol($hpsql,5);
  760. $NoTestRes = 0;
  761. $NoHPTestRes = 0;
  762. //Print the results of tests
  763. if(is_array($results))
  764. {
  765. for($i = 0; $i < sizeof($results); $i++)
  766. {
  767. $id = $results[$i][5];
  768. $mailid = $results[$i][6];
  769. $user = $results[$i][0];
  770. $test = $results[$i][1];
  771. $dt = strftime($dateTimeFormatLong,$results[$i][4]);
  772. $res = $results[$i][2];
  773. echo '<tr';
  774. if($i%2==0) echo 'class="row_odd"'; else echo 'class="row_even"';
  775. echo '>';
  776. if($is_allowedToEdit || $is_tutor)
  777. {
  778. $user = $results[$i][0];
  779. echo '<td>'.$user.'</td>';
  780. }
  781. echo '<td>'.$test.'</td>';
  782. echo '<td>'.format_locale_date(get_lang('dateTimeFormatLong'),$results[$i][4]).'</td>';
  783. echo '<td>'.round(($res/($results[$i][3]!=0?$results[$i][3]:1))*100).'% ('.$res.' / '.$results[$i][3].')</td>';
  784. echo '<td>'.(($is_allowedToEdit||$is_tutor)?"<a href='exercise_show.php?user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".get_lang("Edit")."</a>":"<a href='exercise_show.php?dt=$dt&res=$res&id=$id'>".get_lang('Show')."</a>").'</td>';
  785. echo '</tr>';
  786. }
  787. }
  788. else
  789. {
  790. $NoTestRes = 1;
  791. }
  792. // Print the Result of Hotpotatoes Tests
  793. if(is_array($hpresults))
  794. {
  795. for($i = 0; $i < sizeof($hpresults); $i++)
  796. {
  797. $title = GetQuizName($hpresults[$i][1],$documentPath);
  798. if ($title =='')
  799. {
  800. $title = GetFileName($hpresults[$i][1]);
  801. }
  802. echo '<tr>';
  803. if($is_allowedToEdit)
  804. {
  805. echo '<td class="content">'.$hpresults[$i][0].'</td>';
  806. }
  807. echo '<td class="content">'.$title.'</td>';
  808. echo '<td class="content">'.strftime($dateTimeFormatLong,$hpresults[$i][4]).'</td>';
  809. echo '<td class="content">'.round(($hpresults[$i][2]/($hpresults[$i][3]!=0?$hpresults[$i][3]:1))*100).'% ('.$hpresults[$i][2].' / '.$hpresults[$i][3].')</td>';
  810. echo '<td></td>'; //there is no possibility to edit the results of a Hotpotatoes test
  811. echo '</tr>';
  812. }
  813. }
  814. else
  815. {
  816. $NoHPTestRes = 1;
  817. }
  818. if ($NoTestRes==1 && $NoHPTestRes==1)
  819. {
  820. ?>
  821. <tr>
  822. <td colspan="5"><?php echo get_lang("NoResult"); ?></td>
  823. </tr>
  824. <?php
  825. }
  826. ?>
  827. </table>
  828. <?php
  829. }else{
  830. echo '<p><img src="'.api_get_path(WEB_IMG_PATH).'show_test_results.gif" align="absbottom">&nbsp;<a href="'.api_add_url_param($_SERVER['REQUEST_URI'],'show=result').'">'.get_lang("Results").' &gt;&gt;</a></p>';
  831. }// end if($show == 'result')
  832. }// end if tracking is enabled
  833. if ($origin != 'learnpath') { //so we are not in learnpath tool
  834. Display::display_footer();
  835. } else {
  836. ?>
  837. <link rel="stylesheet" type="text/css" href="<?php echo $clarolineRepositoryWeb ?>css/default.css" />
  838. <?php
  839. }
  840. ?>