exercice.php 31 KB

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