exercise_result.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  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 result
  18. * This script gets informations from the script "exercise_submit.php",
  19. * through the session, and calculates the score of the student for
  20. * that exercise.
  21. * Then it shows the results on the screen.
  22. * @package dokeos.exercise
  23. * @author Olivier Brouckaert, main author
  24. * @author Roan Embrechts, some refactoring
  25. * @version $Id: exercise_result.php 14588 2008-03-13 11:17:02Z vanwayenbergh $
  26. *
  27. * @todo split more code up in functions, move functions to library?
  28. */
  29. /*
  30. ==============================================================================
  31. INIT SECTION
  32. ==============================================================================
  33. */
  34. include('exercise.class.php');
  35. include('question.class.php');
  36. include('answer.class.php');
  37. if($_GET['origin']=='learnpath')
  38. {
  39. require_once ('../newscorm/learnpath.class.php');
  40. require_once ('../newscorm/learnpathItem.class.php');
  41. require_once ('../newscorm/scorm.class.php');
  42. require_once ('../newscorm/scormItem.class.php');
  43. require_once ('../newscorm/aicc.class.php');
  44. require_once ('../newscorm/aiccItem.class.php');
  45. }
  46. // answer types
  47. define('UNIQUE_ANSWER', 1);
  48. define('MULTIPLE_ANSWER', 2);
  49. define('FILL_IN_BLANKS', 3);
  50. define('MATCHING', 4);
  51. define('FREE_ANSWER', 5);
  52. define('HOT_SPOT', 6);
  53. define('HOT_SPOT_ORDER', 7);
  54. global $_cid;
  55. // name of the language file that needs to be included
  56. $language_file='exercice';
  57. include('../inc/global.inc.php');
  58. $this_section=SECTION_COURSES;
  59. /* ------------ ACCESS RIGHTS ------------ */
  60. // notice for unauthorized people.
  61. api_protect_course_script(true);
  62. include_once(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  63. include_once(api_get_path(LIBRARY_PATH).'mail.lib.inc.php');
  64. include_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  65. // Database table definitions
  66. $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  67. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  68. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  69. $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
  70. $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  71. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  72. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  73. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  74. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  75. //temp values to move to AWACS
  76. $dsp_percent = false; //false to display total score as absolute values
  77. //debug param. 0: no display - 1: debug display
  78. $debug=0;
  79. if($debug>0){echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);}
  80. // general parameters passed via POST/GET
  81. if ( empty ( $origin ) ) {
  82. $origin = $_REQUEST['origin'];
  83. }
  84. if ( empty ( $learnpath_id ) ) {
  85. $learnpath_id = mysql_real_escape_string($_REQUEST['learnpath_id']);
  86. }
  87. if ( empty ( $learnpath_item_id ) ) {
  88. $learnpath_item_id = mysql_real_escape_string($_REQUEST['learnpath_item_id']);
  89. }
  90. if ( empty ( $formSent ) ) {
  91. $formSent = $_REQUEST['formSent'];
  92. }
  93. if ( empty ( $exerciseResult ) ) {
  94. $exerciseResult = $_SESSION['exerciseResult'];
  95. }
  96. if ( empty ( $questionId ) ) {
  97. $questionId = $_REQUEST['questionId'];
  98. }
  99. if ( empty ( $choice ) ) {
  100. $choice = $_REQUEST['choice'];
  101. }
  102. if ( empty ( $questionNum ) ) {
  103. $questionNum = mysql_real_escape_string($_REQUEST['questionNum']);
  104. }
  105. if ( empty ( $nbrQuestions ) ) {
  106. $nbrQuestions = mysql_real_escape_string($_REQUEST['nbrQuestions']);
  107. }
  108. if ( empty ( $questionList ) ) {
  109. $questionList = $_SESSION['questionList'];
  110. }
  111. if ( empty ( $objExercise ) ) {
  112. $objExercise = $_SESSION['objExercise'];
  113. }
  114. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  115. $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  116. $courseName = $_SESSION['_course']['name'];
  117. $query = "select user_id from $main_admin_table";
  118. $admin_id = mysql_result(api_sql_query($query),0,"user_id");
  119. $uinfo = api_get_user_info($admin_id);
  120. $from = $uinfo['mail'];
  121. $from_name = $uinfo['firstname'].' '.$uinfo['lastname'];
  122. $str = $_SERVER['REQUEST_URI'];
  123. $arr = explode('/',$str);
  124. $url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result';
  125. //$url = $_SERVER['SERVER_NAME'].'/'.$arr[1].'/';
  126. // if the above variables are empty or incorrect, stops the script
  127. if(!is_array($exerciseResult) || !is_array($questionList) || !is_object($objExercise))
  128. {
  129. header('Location: exercice.php');
  130. exit();
  131. }
  132. $exerciseTitle=$objExercise->selectTitle();
  133. $exerciseDescription=$objExercise->selectDescription();
  134. $exerciseDescription=stripslashes($exerciseDescription);
  135. $nameTools=get_lang('Exercice');
  136. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  137. if ($origin != 'learnpath')
  138. {
  139. //so we are not in learnpath tool
  140. Display::display_header($nameTools,"Exercise");
  141. }
  142. else
  143. {
  144. if(empty($charset))
  145. {
  146. $charset = 'ISO-8859-15';
  147. }
  148. header('Content-Type: text/html; charset='. $charset);
  149. @$document_language = Database::get_language_isocode($language_interface);
  150. if(empty($document_language))
  151. {
  152. //if there was no valid iso-code, use the english one
  153. $document_language = 'en';
  154. }
  155. /*
  156. * HTML HEADER
  157. */
  158. ?>
  159. <!DOCTYPE html
  160. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  161. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  162. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $document_language; ?>" lang="<?php echo $document_language; ?>">
  163. <head>
  164. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  165. </head>
  166. <body>
  167. <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/frames.css'; ?>" />
  168. <?php
  169. }
  170. /*
  171. ==============================================================================
  172. FUNCTIONS
  173. ==============================================================================
  174. */
  175. function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect)
  176. {
  177. ?>
  178. <tr>
  179. <td width="5%" align="center">
  180. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $studentChoice?'_on':'_off'; ?>.gif"
  181. border="0" alt="" />
  182. </td>
  183. <td width="5%" align="center">
  184. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif"
  185. border="0" alt=" " />
  186. </td>
  187. <td width="45%" style="border-bottom: 1px solid #4171B5;">
  188. <?php
  189. $answer=api_parse_tex($answer);
  190. echo $answer; ?>
  191. </td>
  192. <td width="45%" style="border-bottom: 1px solid #4171B5;">
  193. <?php
  194. $answerComment=api_parse_tex($answerComment);
  195. if($studentChoice) echo nl2br(make_clickable(stripslashes($answerComment))); else echo '&nbsp;'; ?>
  196. </td>
  197. </tr>
  198. <?php
  199. }
  200. function display_fill_in_blanks_answer($answer)
  201. {
  202. ?>
  203. <tr>
  204. <td>
  205. <?php echo nl2br($answer); ?>
  206. </td>
  207. </tr>
  208. <?php
  209. }
  210. function display_free_answer($answer)
  211. {
  212. ?>
  213. <tr>
  214. <td width="55%">
  215. <?php echo nl2br(stripslashes($answer)); ?>
  216. </td>
  217. <td width="45%">
  218. <?php echo get_lang('notCorrectedYet');?>
  219. </td>
  220. </tr>
  221. <?php
  222. }
  223. function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment)
  224. {
  225. //global $hotspot_colors;
  226. $hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
  227. "#4271B5",
  228. "#FE8E16",
  229. "#3B3B3B",
  230. "#BCD631",
  231. "#D63173",
  232. "#D7D7D7",
  233. "#90AFDD",
  234. "#AF8640",
  235. "#4F9242",
  236. "#F4EB24",
  237. "#ED2024",
  238. "#45C7F0",
  239. "#F7BDE2");
  240. ?>
  241. <tr>
  242. <td width="25%" valign="top">
  243. <div style="float:left; padding-left:5px;">
  244. <div style="display:inline; float:left; width:80px;"><?php echo $answer ?></div>
  245. <div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]; ?>; display:inline; float:left; margin-top:3px;"></div>
  246. </div>
  247. </td>
  248. <td width="25%" valign="top"><?php echo $answerId; ?></td>
  249. <td width="25%" valign="top">
  250. <?php $studentChoice = ($studentChoice)?get_lang('Correct'):get_lang('Fault'); echo $studentChoice; ?>
  251. </td>
  252. <td width="25%" valign="top">
  253. <?php echo stripslashes($answerComment); ?>
  254. </td>
  255. </tr>
  256. <?php
  257. }
  258. /*
  259. ==============================================================================
  260. MAIN CODE
  261. ==============================================================================
  262. */
  263. $exerciseTitle=api_parse_tex($exerciseTitle);
  264. ?>
  265. <h3><?php echo $exerciseTitle ?>: <?php echo get_lang("Result"); ?></h3>
  266. <?php echo $exerciseDescription; ?>
  267. <form method="get" action="exercice.php">
  268. <input type="hidden" name="origin" value="<?php echo $origin; ?>" />
  269. <input type="hidden" name="learnpath_id" value="<?php echo $learnpath_id; ?>" />
  270. <input type="hidden" name="learnpath_item_id" value="<?php echo $learnpath_item_id; ?>" />
  271. <?php
  272. $i=$totalScore=$totalWeighting=0;
  273. if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
  274. // added by Priya Saini
  275. $sql = "select max(exe_Id) as id from ".$TBL_TRACK_EXERCICES;
  276. $res = api_sql_query($sql, __FILE__, __LINE__);
  277. $exeId =mysql_result($res,0,"id");
  278. $exeId=$exeId+1;
  279. $counter=0;
  280. foreach($questionList as $questionId)
  281. {
  282. $counter++;
  283. // gets the student choice for this question
  284. $choice=$exerciseResult[$questionId];
  285. // creates a temporary Question object
  286. $objQuestionTmp = Question :: read($questionId);
  287. $questionName=$objQuestionTmp->selectTitle();
  288. $questionWeighting=$objQuestionTmp->selectWeighting();
  289. $answerType=$objQuestionTmp->selectType();
  290. $quesId =$objQuestionTmp->selectId(); //added by priya saini
  291. // destruction of the Question object
  292. unset($objQuestionTmp);
  293. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  294. {
  295. $colspan=4;
  296. }
  297. elseif($answerType == MATCHING || $answerType == FREE_ANSWER)
  298. {
  299. $colspan=2;
  300. }
  301. elseif($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER)
  302. {
  303. $colspan=4;
  304. $rowspan=$nbrAnswers+1;
  305. }
  306. else
  307. {
  308. $colspan=1;
  309. }
  310. ?>
  311. <table width="100%" border="0" cellpadding="3" cellspacing="2">
  312. <tr bgcolor="#E6E6E6">
  313. <td colspan="<?php echo $colspan; ?>">
  314. <?php echo get_lang("Question").' '.($counter); ?>
  315. </td>
  316. </tr>
  317. <tr>
  318. <td colspan="<?php echo $colspan; ?>">
  319. <?php echo $questionName; ?>
  320. </td>
  321. </tr>
  322. <?php
  323. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  324. {
  325. ?>
  326. <tr>
  327. <td width="5%" valign="top" align="center" nowrap="nowrap">
  328. <i><?php echo get_lang("Choice"); ?></i>
  329. </td>
  330. <td width="5%" valign="top" nowrap="nowrap">
  331. <i><?php echo get_lang("ExpectedChoice"); ?></i>
  332. </td>
  333. <td width="45%" valign="top">
  334. <i><?php echo get_lang("Answer"); ?></i>
  335. </td>
  336. <td width="45%" valign="top">
  337. <i><?php echo get_lang("Comment"); ?></i>
  338. </td>
  339. </tr>
  340. <?php
  341. }
  342. elseif($answerType == FILL_IN_BLANKS)
  343. {
  344. ?>
  345. <tr>
  346. <td>
  347. <i><?php echo get_lang("Answer"); ?></i>
  348. </td>
  349. </tr>
  350. <?php
  351. }
  352. elseif($answerType == FREE_ANSWER)
  353. {
  354. ?>
  355. <tr>
  356. <td width="55%">
  357. <i><?php echo get_lang("Answer"); ?></i>
  358. </td>
  359. <td width="45%" valign="top">
  360. <i><?php echo get_lang("Comment"); ?></i>
  361. </td>
  362. </tr>
  363. <?php
  364. }
  365. elseif($answerType == HOT_SPOT)
  366. {
  367. ?>
  368. <tr>
  369. <td valign="top" colspan="2">
  370. <table width="100%" border="0">
  371. <tr>
  372. <td width="25%" valign="top">
  373. <i><?php echo get_lang("CorrectAnswer"); ?></i><br /><br />
  374. </td>
  375. <td width="25%" valign="top">
  376. <i><?php echo get_lang("ClickNumber"); ?></i><br /><br />
  377. </td>
  378. <td width="25%" valign="top">
  379. <i><?php echo get_lang('HotspotHit'); ?></i><br /><br />
  380. </td>
  381. <td width="25%" valign="top">
  382. <i><?php echo get_lang("Comment"); ?></i><br /><br />
  383. </td>
  384. </tr>
  385. <?php
  386. }
  387. else
  388. {
  389. ?>
  390. <tr>
  391. <td width="50%">
  392. <i><?php echo get_lang("ElementList"); ?></i>
  393. </td>
  394. <td width="50%">
  395. <i><?php echo get_lang("CorrespondsTo"); ?></i>
  396. </td>
  397. </tr>
  398. <?php
  399. }
  400. // construction of the Answer object
  401. $objAnswerTmp=new Answer($questionId);
  402. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  403. $questionScore=0;
  404. if($answerType == FREE_ANSWER)
  405. $nbrAnswers = 1;
  406. for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
  407. {
  408. $answer=$objAnswerTmp->selectAnswer($answerId);
  409. $answerComment=$objAnswerTmp->selectComment($answerId);
  410. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  411. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  412. switch($answerType)
  413. {
  414. // for unique answer
  415. case UNIQUE_ANSWER :
  416. $studentChoice=($choice == $answerId)?1:0;
  417. if($studentChoice)
  418. {
  419. $questionScore+=$answerWeighting;
  420. $totalScore+=$answerWeighting;
  421. }
  422. break;
  423. // for multiple answers
  424. case MULTIPLE_ANSWER :
  425. $studentChoice=$choice[$answerId];
  426. if($studentChoice)
  427. {
  428. $questionScore+=$answerWeighting;
  429. $totalScore+=$answerWeighting;
  430. }
  431. break;
  432. // for fill in the blanks
  433. case FILL_IN_BLANKS : // splits text and weightings that are joined with the character '::'
  434. list($answer,$answerWeighting)=explode('::',$answer);
  435. // splits weightings that are joined with a comma
  436. $answerWeighting=explode(',',$answerWeighting);
  437. // we save the answer because it will be modified
  438. $temp=$answer;
  439. // TeX parsing
  440. // 1. find everything between the [tex] and [/tex] tags
  441. $startlocations=strpos($temp,'[tex]');
  442. $endlocations=strpos($temp,'[/tex]');
  443. if($startlocations !== false && $endlocations !== false)
  444. {
  445. $texstring=substr($temp,$startlocations,$endlocations-$startlocations+6);
  446. // 2. replace this by {texcode}
  447. $temp=str_replace($texstring,'{texcode}',$temp);
  448. }
  449. $answer='';
  450. $j=0;
  451. // the loop will stop at the end of the text
  452. while(1)
  453. {
  454. // quits the loop if there are no more blanks
  455. if(($pos = strpos($temp,'[')) === false)
  456. {
  457. // adds the end of the text
  458. $answer.=$temp;
  459. // TeX parsing
  460. $texstring = api_parse_tex($texstring);
  461. $answer=str_replace("{texcode}",$texstring,$answer);
  462. break;
  463. }
  464. // adds the piece of text that is before the blank and ended by [
  465. $answer.=substr($temp,0,$pos+1);
  466. $temp=substr($temp,$pos+1);
  467. // quits the loop if there are no more blanks
  468. if(($pos = strpos($temp,']')) === false)
  469. {
  470. // adds the end of the text
  471. $answer.=$temp;
  472. break;
  473. }
  474. $choice[$j]=trim($choice[$j]);
  475. // if the word entered by the student IS the same as the one defined by the professor
  476. if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j])))
  477. {
  478. // gives the related weighting to the student
  479. $questionScore+=$answerWeighting[$j];
  480. // increments total score
  481. $totalScore+=$answerWeighting[$j];
  482. // adds the word in green at the end of the string
  483. $answer.=stripslashes($choice[$j]);
  484. }
  485. // else if the word entered by the student IS NOT the same as the one defined by the professor
  486. elseif(!empty($choice[$j]))
  487. {
  488. // adds the word in red at the end of the string, and strikes it
  489. $answer.='<font color="red"><s>'.stripslashes($choice[$j]).'</s></font>';
  490. }
  491. else
  492. {
  493. // adds a tabulation if no word has been typed by the student
  494. $answer.='&nbsp;&nbsp;&nbsp;';
  495. }
  496. // adds the correct word, followed by ] to close the blank
  497. $answer.=' / <font color="green"><b>'.substr($temp,0,$pos).'</b></font>]';
  498. $j++;
  499. $temp=substr($temp,$pos+1);
  500. }
  501. break;
  502. // for free answer
  503. case FREE_ANSWER :
  504. $studentChoice=$choice;
  505. if($studentChoice)
  506. {
  507. //Score is at -1 because the question has'nt been corected
  508. $questionScore=-1;
  509. $totalScore+=0;
  510. }
  511. break;
  512. // for matching
  513. case MATCHING :
  514. if($answerCorrect)
  515. {
  516. if($answerCorrect == $choice[$answerId])
  517. {
  518. $questionScore+=$answerWeighting;
  519. $totalScore+=$answerWeighting;
  520. $choice[$answerId]=$matching[$choice[$answerId]];
  521. }
  522. elseif(!$choice[$answerId])
  523. {
  524. $choice[$answerId]='&nbsp;&nbsp;&nbsp;';
  525. }
  526. else
  527. {
  528. $choice[$answerId]='<font color="red"><s>'.$matching[$choice[$answerId]].'</s></font>';
  529. }
  530. }
  531. else
  532. {
  533. $matching[$answerId]=$answer;
  534. }
  535. break;
  536. // for hotspot with no order
  537. case HOT_SPOT : $studentChoice=$choice[$answerId];
  538. if($studentChoice)
  539. {
  540. $questionScore+=$answerWeighting;
  541. $totalScore+=$answerWeighting;
  542. }
  543. break;
  544. // for hotspot with fixed order
  545. case HOT_SPOT_ORDER : $studentChoice=$choice['order'][$answerId];
  546. if($studentChoice == $answerId)
  547. {
  548. $questionScore+=$answerWeighting;
  549. $totalScore+=$answerWeighting;
  550. $studentChoice = true;
  551. }
  552. else
  553. {
  554. $studentChoice = false;
  555. }
  556. break;
  557. } // end switch Answertype
  558. if($answerType != MATCHING || $answerCorrect)
  559. {
  560. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  561. {
  562. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect);
  563. }
  564. elseif($answerType == FILL_IN_BLANKS)
  565. {
  566. display_fill_in_blanks_answer($answer);
  567. }
  568. elseif($answerType == FREE_ANSWER)
  569. {
  570. // to store the details of open questions in an array to be used in mail
  571. $arrques[] = $questionName;
  572. $arrans[] = $choice;
  573. $firstName = $_SESSION['_user']['firstName'];
  574. $lastName = $_SESSION['_user']['lastName'];
  575. $mail = $_SESSION['_user']['mail'];
  576. $coursecode = $_SESSION['_course']['id'];
  577. $to = '';
  578. $teachers = array();
  579. if(api_get_setting('use_session_mode')=='true' && !empty($_SESSION['id_session']))
  580. {
  581. $teachers = CourseManager::get_coach_list_from_course_code($coursecode,$_SESSION['id_session']);
  582. }
  583. else
  584. {
  585. $teachers = CourseManager::get_teacher_list_from_course_code($coursecode);
  586. }
  587. $num = count($teachers);
  588. if($num>1)
  589. {
  590. $to = array();
  591. foreach($teachers as $teacher)
  592. {
  593. $to[] = $teacher['email'];
  594. }
  595. }elseif($num>0){
  596. foreach($teachers as $teacher)
  597. {
  598. $to = $teacher['email'];
  599. }
  600. }else{
  601. //this is a problem (it means that there is no admin for this course)
  602. }
  603. display_free_answer($choice);
  604. }
  605. elseif($answerType == HOT_SPOT)
  606. {
  607. $tbl_track_e_hotspot = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  608. // Save into db
  609. $sql = "INSERT INTO $tbl_track_e_hotspot (`hotspot_user_id` , `hotspot_course_code` , `hotspot_exe_id` , `hotspot_question_id` , `hotspot_answer_id` , `hotspot_correct` , `hotspot_coordinate` )
  610. VALUES ('".$_user['user_id']."', '".$_course['id']."', '$exeId', '$questionId', '$answerId', '$studentChoice', '".$_SESSION['exerciseResultCoordinates'][$questionId][$answerId]."')";
  611. $result = api_sql_query($sql,__FILE__,__LINE__);
  612. display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
  613. }
  614. elseif($answerType == HOT_SPOT_ORDER)
  615. {
  616. display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment);
  617. }
  618. else
  619. {
  620. ?>
  621. <tr>
  622. <td width="50%">
  623. <?php
  624. $answer=api_parse_tex($answer);
  625. echo $answer; ?>
  626. </td>
  627. <td width="50%">
  628. <?php echo $choice[$answerId]; ?> / <font color="green"><b>
  629. <?php
  630. $matching[$answerCorrect]=api_parse_tex($matching[$answerCorrect]);
  631. echo $matching[$answerCorrect]; ?></b></font>
  632. </td>
  633. </tr>
  634. <?php
  635. }
  636. }
  637. } // end for that loops over all answers of the current question
  638. if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER)
  639. {
  640. // We made an extra table for the answers
  641. echo "</table></td></tr>";
  642. ?>
  643. <tr>
  644. <td colspan="2">
  645. <i><?php echo get_lang('Hotspot'); ?></i><br /><br />
  646. <object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo $questionId ?>&exe_id=&from_db=0" width="730" height="750">
  647. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo $questionId ?>&exe_id=&from_db=0" />
  648. </object>
  649. </td>
  650. </tr>
  651. <?php
  652. }
  653. ?>
  654. <tr>
  655. <td colspan="<?php echo $colspan; ?>" align="right">
  656. <b>
  657. <?php
  658. if($questionScore==-1){
  659. echo get_lang('Score')." : 0/$questionWeighting";
  660. }
  661. else{
  662. echo get_lang('Score')." : $questionScore/$questionWeighting";
  663. }
  664. ?></b>
  665. </td>
  666. </tr>
  667. </table>
  668. <?php
  669. // destruction of Answer
  670. unset($objAnswerTmp);
  671. $i++;
  672. $totalWeighting+=$questionWeighting;
  673. //added by priya saini
  674. if($_configuration['tracking_enabled'])
  675. {
  676. if(empty($choice)){
  677. $choice = 0;
  678. }
  679. if ($answerType==MULTIPLE_ANSWER )
  680. {
  681. $reply = array_keys($choice);
  682. for ($i=0;$i<sizeof($reply);$i++)
  683. {
  684. $ans = $reply[$i];
  685. exercise_attempt($questionScore,$ans,$quesId,$exeId,$i);
  686. }
  687. }
  688. elseif ($answerType==MATCHING)
  689. {
  690. $j=sizeof($matching)+1;
  691. for ($i=0;$i<sizeof($choice);$i++,$j++)
  692. {
  693. $val = $choice[$j];
  694. if (preg_match_all ('#<font color="red"><s>([0-9a-z ]*)</s></font>#', $val, $arr1))
  695. $val = $arr1[1][0];
  696. $val=addslashes($val);
  697. $val=strip_tags($val);
  698. $sql = "select position from $table_ans where question_id=$questionId and answer='$val' AND correct=0";
  699. $res = api_sql_query($sql, __FILE__, __LINE__);
  700. $answer = mysql_result($res,0,"position");
  701. exercise_attempt($questionScore,$answer,$quesId,$exeId,$j);
  702. }
  703. }
  704. elseif ($answerType==FREE_ANSWER)
  705. {
  706. $answer = $choice;
  707. exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  708. }
  709. elseif ($answerType==UNIQUE_ANSWER)
  710. {
  711. $sql = "select id from $table_ans where question_id=$questionId and position=$choice";
  712. $res = api_sql_query($sql, __FILE__, __LINE__);
  713. $answer = mysql_result($res,0,"id");
  714. exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  715. }
  716. else
  717. {
  718. exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  719. }
  720. }
  721. } // end huge foreach() block that loops over all questions
  722. ?>
  723. <table width="100%" border="0" cellpadding="3" cellspacing="2">
  724. <tr>
  725. <td>
  726. <b><?php echo get_lang('YourTotalScore')." ";
  727. if($dsp_percent == true){
  728. echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
  729. }else{
  730. echo $totalScore."/".$totalWeighting;
  731. }
  732. ?></b>
  733. </td>
  734. </tr>
  735. <tr>
  736. <td>
  737. <br />
  738. <?php
  739. if ($origin != 'learnpath')
  740. {
  741. ?>
  742. <input type="submit" value="<?php echo get_lang('Ok'); ?>" />
  743. <?php
  744. }
  745. ?>
  746. </td>
  747. </tr>
  748. </table>
  749. </form>
  750. <br />
  751. <?php
  752. /*
  753. ==============================================================================
  754. Tracking of results
  755. ==============================================================================
  756. */
  757. if($_configuration['tracking_enabled'])
  758. {
  759. //include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  760. event_exercice($objExercise->selectId(),$totalScore,$totalWeighting,$answer,$question_id);
  761. }
  762. if ($origin != 'learnpath')
  763. {
  764. //we are not in learnpath tool
  765. Display::display_footer();
  766. }else{
  767. echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$totalScore.');</script>';
  768. echo '</body></html>';
  769. }
  770. $send_email = api_get_course_setting('email_alert_manager_on_new_quiz');
  771. $csspath = "http://portal.dokeos.com/demo/main/css/default.css";
  772. if ($send_email && count($arrques)>0)
  773. {
  774. $msg = '<html><head>
  775. <link rel="stylesheet" href="http://www.dokeos.com/styles.css" type="text/css">
  776. <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">';
  777. $msg .= '</head>
  778. <body><br />
  779. <p>'.get_lang('OpenQuestionsAttempted').' :
  780. </p>
  781. <p>'.get_lang('AttemptDetails').' : ><br />
  782. </p>
  783. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
  784. <tr>
  785. <td width="229" valign="top" class="mybody">&nbsp;&nbsp;'.get_lang('CourseName').'</td>
  786. <td width="469" valign="top" class="mybody">#course#</td>
  787. </tr>
  788. <tr>
  789. <td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
  790. <td width="469" valign="top" class="outerframe">#exercise#</td>
  791. </tr>
  792. <tr>
  793. <td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
  794. <td valign="top" >#firstName# #lastName#</td>
  795. </tr>
  796. <tr>
  797. <td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
  798. <td valign="top"> #mail#</td>
  799. </tr></table>
  800. <p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
  801. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
  802. for($i=0;$i<sizeof($arrques);$i++)
  803. {
  804. $msg.='
  805. <tr>
  806. <td width="220" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>
  807. <td width="473" valign="top" bgcolor="F3F3F3"><span class="style16"> #questionName#</span></td>
  808. </tr>
  809. <tr>
  810. <td width="220" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Answer').' </span></td>
  811. <td valign="top" bgcolor="F3F3F3"><span class="style16"> #answer#</span></td>
  812. </tr>';
  813. $msg1= str_replace("#exercise#",$exerciseTitle,$msg);
  814. $msg= str_replace("#firstName#",$firstName,$msg1);
  815. $msg1= str_replace("#lastName#",$lastName,$msg);
  816. $msg= str_replace("#mail#",$mail,$msg1);
  817. $msg1= str_replace("#questionName#",$arrques[$i],$msg);
  818. $msg= str_replace("#answer#",$arrans[$i],$msg1);
  819. $msg1= str_replace("#i#",$i,$msg);
  820. $msg= str_replace("#course#",$courseName,$msg1);
  821. }
  822. $msg.='</table><br>
  823. <span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
  824. <a href="#url#">#url#</a></span></body></html>';
  825. $msg1= str_replace("#url#",$url,$msg);
  826. $mail_content = stripslashes($msg1);
  827. $student_name = $_SESSION['_user']['firstName'].' '.$_SESSION['_user']['lastName'];
  828. $subject = get_lang('OpenQuestionsAttempted');
  829. api_mail_html($student_name, $to, $subject, $mail_content, $from_name, $from);
  830. }
  831. ?>