exercice.php 30 KB

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