exercise_result.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  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 du Corbeau, 108
  13. B-1030 Brussels - Belgium
  14. info@dokeos.com
  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 14840 2008-04-11 06:21:45Z yannoo $
  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. if($objExercise->results_disabled)
  171. {
  172. ob_start();
  173. }
  174. /*
  175. ==============================================================================
  176. FUNCTIONS
  177. ==============================================================================
  178. */
  179. function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect)
  180. {
  181. ?>
  182. <tr>
  183. <td width="5%" align="center">
  184. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $studentChoice?'_on':'_off'; ?>.gif"
  185. border="0" alt="" />
  186. </td>
  187. <td width="5%" align="center">
  188. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif"
  189. border="0" alt=" " />
  190. </td>
  191. <td width="45%" style="border-bottom: 1px solid #4171B5;">
  192. <?php
  193. $answer=api_parse_tex($answer);
  194. echo $answer; ?>
  195. </td>
  196. <td width="45%" style="border-bottom: 1px solid #4171B5;">
  197. <?php
  198. $answerComment=api_parse_tex($answerComment);
  199. if($studentChoice) echo nl2br(make_clickable(stripslashes($answerComment))); else echo '&nbsp;'; ?>
  200. </td>
  201. </tr>
  202. <?php
  203. }
  204. function display_fill_in_blanks_answer($answer)
  205. {
  206. ?>
  207. <tr>
  208. <td>
  209. <?php echo nl2br($answer); ?>
  210. </td>
  211. </tr>
  212. <?php
  213. }
  214. function display_free_answer($answer)
  215. {
  216. ?>
  217. <tr>
  218. <td width="55%">
  219. <?php echo nl2br(stripslashes($answer)); ?>
  220. </td>
  221. <td width="45%">
  222. <?php echo get_lang('notCorrectedYet');?>
  223. </td>
  224. </tr>
  225. <?php
  226. }
  227. function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment)
  228. {
  229. //global $hotspot_colors;
  230. $hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
  231. "#4271B5",
  232. "#FE8E16",
  233. "#3B3B3B",
  234. "#BCD631",
  235. "#D63173",
  236. "#D7D7D7",
  237. "#90AFDD",
  238. "#AF8640",
  239. "#4F9242",
  240. "#F4EB24",
  241. "#ED2024",
  242. "#45C7F0",
  243. "#F7BDE2");
  244. ?>
  245. <tr>
  246. <td width="25%" valign="top">
  247. <div style="float:left; padding-left:5px;">
  248. <div style="display:inline; float:left; width:80px;"><?php echo $answer ?></div>
  249. <div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]; ?>; display:inline; float:left; margin-top:3px;"></div>
  250. </div>
  251. </td>
  252. <td width="25%" valign="top"><?php echo $answerId; ?></td>
  253. <td width="25%" valign="top">
  254. <?php $studentChoice = ($studentChoice)?get_lang('Correct'):get_lang('Fault'); echo $studentChoice; ?>
  255. </td>
  256. <td width="25%" valign="top">
  257. <?php echo stripslashes($answerComment); ?>
  258. </td>
  259. </tr>
  260. <?php
  261. }
  262. /*
  263. ==============================================================================
  264. MAIN CODE
  265. ==============================================================================
  266. */
  267. $exerciseTitle=api_parse_tex($exerciseTitle);
  268. ?>
  269. <h3><?php echo $exerciseTitle ?>: <?php echo get_lang("Result"); ?></h3>
  270. <?php echo $exerciseDescription; ?>
  271. <form method="get" action="exercice.php">
  272. <input type="hidden" name="origin" value="<?php echo $origin; ?>" />
  273. <input type="hidden" name="learnpath_id" value="<?php echo $learnpath_id; ?>" />
  274. <input type="hidden" name="learnpath_item_id" value="<?php echo $learnpath_item_id; ?>" />
  275. <?php
  276. $i=$totalScore=$totalWeighting=0;
  277. if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
  278. // added by Priya Saini
  279. $sql = "select max(exe_Id) as id from ".$TBL_TRACK_EXERCICES;
  280. $res = api_sql_query($sql, __FILE__, __LINE__);
  281. $exeId =mysql_result($res,0,"id");
  282. $exeId=$exeId+1;
  283. $counter=0;
  284. foreach($questionList as $questionId)
  285. {
  286. $counter++;
  287. // gets the student choice for this question
  288. $choice=$exerciseResult[$questionId];
  289. // creates a temporary Question object
  290. $objQuestionTmp = Question :: read($questionId);
  291. $questionName=$objQuestionTmp->selectTitle();
  292. $questionWeighting=$objQuestionTmp->selectWeighting();
  293. $answerType=$objQuestionTmp->selectType();
  294. $quesId =$objQuestionTmp->selectId(); //added by priya saini
  295. // destruction of the Question object
  296. unset($objQuestionTmp);
  297. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  298. {
  299. $colspan=4;
  300. }
  301. elseif($answerType == MATCHING || $answerType == FREE_ANSWER)
  302. {
  303. $colspan=2;
  304. }
  305. elseif($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER)
  306. {
  307. $colspan=4;
  308. $rowspan=$nbrAnswers+1;
  309. }
  310. else
  311. {
  312. $colspan=1;
  313. }
  314. ?>
  315. <table width="100%" border="0" cellpadding="3" cellspacing="2">
  316. <tr bgcolor="#E6E6E6">
  317. <td colspan="<?php echo $colspan; ?>">
  318. <?php echo get_lang("Question").' '.($counter); ?>
  319. </td>
  320. </tr>
  321. <tr>
  322. <td colspan="<?php echo $colspan; ?>">
  323. <?php echo $questionName; ?>
  324. </td>
  325. </tr>
  326. <?php
  327. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  328. {
  329. ?>
  330. <tr>
  331. <td width="5%" valign="top" align="center" nowrap="nowrap">
  332. <i><?php echo get_lang("Choice"); ?></i>
  333. </td>
  334. <td width="5%" valign="top" nowrap="nowrap">
  335. <i><?php echo get_lang("ExpectedChoice"); ?></i>
  336. </td>
  337. <td width="45%" valign="top">
  338. <i><?php echo get_lang("Answer"); ?></i>
  339. </td>
  340. <td width="45%" valign="top">
  341. <i><?php echo get_lang("Comment"); ?></i>
  342. </td>
  343. </tr>
  344. <?php
  345. }
  346. elseif($answerType == FILL_IN_BLANKS)
  347. {
  348. ?>
  349. <tr>
  350. <td>
  351. <i><?php echo get_lang("Answer"); ?></i>
  352. </td>
  353. </tr>
  354. <?php
  355. }
  356. elseif($answerType == FREE_ANSWER)
  357. {
  358. ?>
  359. <tr>
  360. <td width="55%">
  361. <i><?php echo get_lang("Answer"); ?></i>
  362. </td>
  363. <td width="45%" valign="top">
  364. <i><?php echo get_lang("Comment"); ?></i>
  365. </td>
  366. </tr>
  367. <?php
  368. }
  369. elseif($answerType == HOT_SPOT)
  370. {
  371. ?>
  372. <tr>
  373. <td valign="top" colspan="2">
  374. <table width="100%" border="0">
  375. <tr>
  376. <td width="25%" valign="top">
  377. <i><?php echo get_lang("CorrectAnswer"); ?></i><br /><br />
  378. </td>
  379. <td width="25%" valign="top">
  380. <i><?php echo get_lang("ClickNumber"); ?></i><br /><br />
  381. </td>
  382. <td width="25%" valign="top">
  383. <i><?php echo get_lang('HotspotHit'); ?></i><br /><br />
  384. </td>
  385. <td width="25%" valign="top">
  386. <i><?php echo get_lang("Comment"); ?></i><br /><br />
  387. </td>
  388. </tr>
  389. <?php
  390. }
  391. else
  392. {
  393. ?>
  394. <tr>
  395. <td width="50%">
  396. <i><?php echo get_lang("ElementList"); ?></i>
  397. </td>
  398. <td width="50%">
  399. <i><?php echo get_lang("CorrespondsTo"); ?></i>
  400. </td>
  401. </tr>
  402. <?php
  403. }
  404. // construction of the Answer object
  405. $objAnswerTmp=new Answer($questionId);
  406. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  407. $questionScore=0;
  408. if($answerType == FREE_ANSWER)
  409. $nbrAnswers = 1;
  410. for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
  411. {
  412. $answer=$objAnswerTmp->selectAnswer($answerId);
  413. $answerComment=$objAnswerTmp->selectComment($answerId);
  414. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  415. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  416. switch($answerType)
  417. {
  418. // for unique answer
  419. case UNIQUE_ANSWER :
  420. $studentChoice=($choice == $answerId)?1:0;
  421. if($studentChoice)
  422. {
  423. $questionScore+=$answerWeighting;
  424. $totalScore+=$answerWeighting;
  425. }
  426. break;
  427. // for multiple answers
  428. case MULTIPLE_ANSWER :
  429. $studentChoice=$choice[$answerId];
  430. if($studentChoice)
  431. {
  432. $questionScore+=$answerWeighting;
  433. $totalScore+=$answerWeighting;
  434. }
  435. break;
  436. // for fill in the blanks
  437. case FILL_IN_BLANKS : // splits text and weightings that are joined with the character '::'
  438. list($answer,$answerWeighting)=explode('::',$answer);
  439. // splits weightings that are joined with a comma
  440. $answerWeighting=explode(',',$answerWeighting);
  441. // we save the answer because it will be modified
  442. $temp=$answer;
  443. // TeX parsing
  444. // 1. find everything between the [tex] and [/tex] tags
  445. $startlocations=strpos($temp,'[tex]');
  446. $endlocations=strpos($temp,'[/tex]');
  447. if($startlocations !== false && $endlocations !== false)
  448. {
  449. $texstring=substr($temp,$startlocations,$endlocations-$startlocations+6);
  450. // 2. replace this by {texcode}
  451. $temp=str_replace($texstring,'{texcode}',$temp);
  452. }
  453. $answer='';
  454. $j=0;
  455. // the loop will stop at the end of the text
  456. while(1)
  457. {
  458. // quits the loop if there are no more blanks
  459. if(($pos = strpos($temp,'[')) === false)
  460. {
  461. // adds the end of the text
  462. $answer.=$temp;
  463. // TeX parsing
  464. $texstring = api_parse_tex($texstring);
  465. $answer=str_replace("{texcode}",$texstring,$answer);
  466. break;
  467. }
  468. // adds the piece of text that is before the blank and ended by [
  469. $answer.=substr($temp,0,$pos+1);
  470. $temp=substr($temp,$pos+1);
  471. // quits the loop if there are no more blanks
  472. if(($pos = strpos($temp,']')) === false)
  473. {
  474. // adds the end of the text
  475. $answer.=$temp;
  476. break;
  477. }
  478. $choice[$j]=trim($choice[$j]);
  479. // if the word entered by the student IS the same as the one defined by the professor
  480. if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j])))
  481. {
  482. // gives the related weighting to the student
  483. $questionScore+=$answerWeighting[$j];
  484. // increments total score
  485. $totalScore+=$answerWeighting[$j];
  486. // adds the word in green at the end of the string
  487. $answer.=stripslashes($choice[$j]);
  488. }
  489. // else if the word entered by the student IS NOT the same as the one defined by the professor
  490. elseif(!empty($choice[$j]))
  491. {
  492. // adds the word in red at the end of the string, and strikes it
  493. $answer.='<font color="red"><s>'.stripslashes($choice[$j]).'</s></font>';
  494. }
  495. else
  496. {
  497. // adds a tabulation if no word has been typed by the student
  498. $answer.='&nbsp;&nbsp;&nbsp;';
  499. }
  500. // adds the correct word, followed by ] to close the blank
  501. $answer.=' / <font color="green"><b>'.substr($temp,0,$pos).'</b></font>]';
  502. $j++;
  503. $temp=substr($temp,$pos+1);
  504. }
  505. break;
  506. // for free answer
  507. case FREE_ANSWER :
  508. $studentChoice=$choice;
  509. if($studentChoice)
  510. {
  511. //Score is at -1 because the question has'nt been corected
  512. $questionScore=-1;
  513. $totalScore+=0;
  514. }
  515. break;
  516. // for matching
  517. case MATCHING :
  518. if($answerCorrect)
  519. {
  520. if($answerCorrect == $choice[$answerId])
  521. {
  522. $questionScore+=$answerWeighting;
  523. $totalScore+=$answerWeighting;
  524. $choice[$answerId]=$matching[$choice[$answerId]];
  525. }
  526. elseif(!$choice[$answerId])
  527. {
  528. $choice[$answerId]='&nbsp;&nbsp;&nbsp;';
  529. }
  530. else
  531. {
  532. $choice[$answerId]='<font color="red"><s>'.$matching[$choice[$answerId]].'</s></font>';
  533. }
  534. }
  535. else
  536. {
  537. $matching[$answerId]=$answer;
  538. }
  539. break;
  540. // for hotspot with no order
  541. case HOT_SPOT : $studentChoice=$choice[$answerId];
  542. if($studentChoice)
  543. {
  544. $questionScore+=$answerWeighting;
  545. $totalScore+=$answerWeighting;
  546. }
  547. break;
  548. // for hotspot with fixed order
  549. case HOT_SPOT_ORDER : $studentChoice=$choice['order'][$answerId];
  550. if($studentChoice == $answerId)
  551. {
  552. $questionScore+=$answerWeighting;
  553. $totalScore+=$answerWeighting;
  554. $studentChoice = true;
  555. }
  556. else
  557. {
  558. $studentChoice = false;
  559. }
  560. break;
  561. } // end switch Answertype
  562. if($answerType != MATCHING || $answerCorrect)
  563. {
  564. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  565. {
  566. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect);
  567. }
  568. elseif($answerType == FILL_IN_BLANKS)
  569. {
  570. display_fill_in_blanks_answer($answer);
  571. }
  572. elseif($answerType == FREE_ANSWER)
  573. {
  574. // to store the details of open questions in an array to be used in mail
  575. $arrques[] = $questionName;
  576. $arrans[] = $choice;
  577. $firstName = $_SESSION['_user']['firstName'];
  578. $lastName = $_SESSION['_user']['lastName'];
  579. $mail = $_SESSION['_user']['mail'];
  580. $coursecode = $_SESSION['_course']['id'];
  581. $to = '';
  582. $teachers = array();
  583. if(api_get_setting('use_session_mode')=='true' && !empty($_SESSION['id_session']))
  584. {
  585. $teachers = CourseManager::get_coach_list_from_course_code($coursecode,$_SESSION['id_session']);
  586. }
  587. else
  588. {
  589. $teachers = CourseManager::get_teacher_list_from_course_code($coursecode);
  590. }
  591. $num = count($teachers);
  592. if($num>1)
  593. {
  594. $to = array();
  595. foreach($teachers as $teacher)
  596. {
  597. $to[] = $teacher['email'];
  598. }
  599. }elseif($num>0){
  600. foreach($teachers as $teacher)
  601. {
  602. $to = $teacher['email'];
  603. }
  604. }else{
  605. //this is a problem (it means that there is no admin for this course)
  606. }
  607. display_free_answer($choice);
  608. }
  609. elseif($answerType == HOT_SPOT)
  610. {
  611. $tbl_track_e_hotspot = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  612. // Save into db
  613. $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` )
  614. VALUES ('".$_user['user_id']."', '".$_course['id']."', '$exeId', '$questionId', '$answerId', '$studentChoice', '".$_SESSION['exerciseResultCoordinates'][$questionId][$answerId]."')";
  615. $result = api_sql_query($sql,__FILE__,__LINE__);
  616. display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
  617. }
  618. elseif($answerType == HOT_SPOT_ORDER)
  619. {
  620. display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment);
  621. }
  622. else
  623. {
  624. ?>
  625. <tr>
  626. <td width="50%">
  627. <?php
  628. $answer=api_parse_tex($answer);
  629. echo $answer; ?>
  630. </td>
  631. <td width="50%">
  632. <?php echo $choice[$answerId]; ?> / <font color="green"><b>
  633. <?php
  634. $matching[$answerCorrect]=api_parse_tex($matching[$answerCorrect]);
  635. echo $matching[$answerCorrect]; ?></b></font>
  636. </td>
  637. </tr>
  638. <?php
  639. }
  640. }
  641. } // end for that loops over all answers of the current question
  642. if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER)
  643. {
  644. // We made an extra table for the answers
  645. echo "</table></td></tr>";
  646. ?>
  647. <tr>
  648. <td colspan="2">
  649. <i><?php echo get_lang('Hotspot'); ?></i><br /><br />
  650. <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">
  651. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo $questionId ?>&exe_id=&from_db=0" />
  652. </object>
  653. </td>
  654. </tr>
  655. <?php
  656. }
  657. ?>
  658. <tr>
  659. <td colspan="<?php echo $colspan; ?>" align="right">
  660. <b>
  661. <?php
  662. if($questionScore==-1){
  663. echo get_lang('Score')." : 0/$questionWeighting";
  664. }
  665. else{
  666. echo get_lang('Score')." : $questionScore/$questionWeighting";
  667. }
  668. ?></b>
  669. </td>
  670. </tr>
  671. </table>
  672. <?php
  673. // destruction of Answer
  674. unset($objAnswerTmp);
  675. $i++;
  676. $totalWeighting+=$questionWeighting;
  677. //added by priya saini
  678. if($_configuration['tracking_enabled'])
  679. {
  680. if(empty($choice)){
  681. $choice = 0;
  682. }
  683. if ($answerType==MULTIPLE_ANSWER )
  684. {
  685. $reply = array_keys($choice);
  686. for ($i=0;$i<sizeof($reply);$i++)
  687. {
  688. $ans = $reply[$i];
  689. exercise_attempt($questionScore,$ans,$quesId,$exeId,$i);
  690. }
  691. }
  692. elseif ($answerType==MATCHING)
  693. {
  694. $j=sizeof($matching)+1;
  695. for ($i=0;$i<sizeof($choice);$i++,$j++)
  696. {
  697. $val = $choice[$j];
  698. if (preg_match_all ('#<font color="red"><s>([0-9a-z ]*)</s></font>#', $val, $arr1))
  699. $val = $arr1[1][0];
  700. $val=addslashes($val);
  701. $val=strip_tags($val);
  702. $sql = "select position from $table_ans where question_id=$questionId and answer='$val' AND correct=0";
  703. $res = api_sql_query($sql, __FILE__, __LINE__);
  704. $answer = mysql_result($res,0,"position");
  705. exercise_attempt($questionScore,$answer,$quesId,$exeId,$j);
  706. }
  707. }
  708. elseif ($answerType==FREE_ANSWER)
  709. {
  710. $answer = $choice;
  711. exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  712. }
  713. elseif ($answerType==UNIQUE_ANSWER)
  714. {
  715. $sql = "select id from $table_ans where question_id=$questionId and position=$choice";
  716. $res = api_sql_query($sql, __FILE__, __LINE__);
  717. $answer = mysql_result($res,0,"id");
  718. exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  719. }
  720. else
  721. {
  722. exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  723. }
  724. }
  725. } // end huge foreach() block that loops over all questions
  726. ?>
  727. <table width="100%" border="0" cellpadding="3" cellspacing="2">
  728. <tr>
  729. <td>
  730. <b><?php echo get_lang('YourTotalScore')." ";
  731. if($dsp_percent == true){
  732. echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
  733. }else{
  734. echo $totalScore."/".$totalWeighting;
  735. }
  736. ?></b>
  737. </td>
  738. </tr>
  739. <tr>
  740. <td>
  741. <br />
  742. <?php
  743. if ($origin != 'learnpath')
  744. {
  745. ?>
  746. <input type="submit" value="<?php echo get_lang('Ok'); ?>" />
  747. <?php
  748. }
  749. ?>
  750. </td>
  751. </tr>
  752. </table>
  753. </form>
  754. <br />
  755. <?php
  756. /*
  757. ==============================================================================
  758. Tracking of results
  759. ==============================================================================
  760. */
  761. if($_configuration['tracking_enabled'])
  762. {
  763. //include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  764. event_exercice($objExercise->selectId(),$totalScore,$totalWeighting,$answer,$question_id);
  765. }
  766. if($objExercise->results_disabled)
  767. {
  768. ob_end_clean();
  769. Display :: display_normal_message(get_lang('ExerciseFinished').'<br /><a href="exercice.php" />'.get_lang('Back').'</a>',false);
  770. }
  771. if ($origin != 'learnpath')
  772. {
  773. //we are not in learnpath tool
  774. Display::display_footer();
  775. }else{
  776. echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$totalScore.');</script>';
  777. echo '</body></html>';
  778. }
  779. $send_email = api_get_course_setting('email_alert_manager_on_new_quiz');
  780. $csspath = "http://portal.dokeos.com/demo/main/css/default.css";
  781. if ($send_email && count($arrques)>0)
  782. {
  783. $msg = '<html><head>
  784. <link rel="stylesheet" href="http://www.dokeos.com/styles.css" type="text/css">
  785. <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">';
  786. $msg .= '</head>
  787. <body><br />
  788. <p>'.get_lang('OpenQuestionsAttempted').' :
  789. </p>
  790. <p>'.get_lang('AttemptDetails').' : ><br />
  791. </p>
  792. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
  793. <tr>
  794. <td width="229" valign="top" class="mybody">&nbsp;&nbsp;'.get_lang('CourseName').'</td>
  795. <td width="469" valign="top" class="mybody">#course#</td>
  796. </tr>
  797. <tr>
  798. <td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
  799. <td width="469" valign="top" class="outerframe">#exercise#</td>
  800. </tr>
  801. <tr>
  802. <td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
  803. <td valign="top" >#firstName# #lastName#</td>
  804. </tr>
  805. <tr>
  806. <td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
  807. <td valign="top"> #mail#</td>
  808. </tr></table>
  809. <p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
  810. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
  811. for($i=0;$i<sizeof($arrques);$i++)
  812. {
  813. $msg.='
  814. <tr>
  815. <td width="220" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>
  816. <td width="473" valign="top" bgcolor="F3F3F3"><span class="style16"> #questionName#</span></td>
  817. </tr>
  818. <tr>
  819. <td width="220" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Answer').' </span></td>
  820. <td valign="top" bgcolor="F3F3F3"><span class="style16"> #answer#</span></td>
  821. </tr>';
  822. $msg1= str_replace("#exercise#",$exerciseTitle,$msg);
  823. $msg= str_replace("#firstName#",$firstName,$msg1);
  824. $msg1= str_replace("#lastName#",$lastName,$msg);
  825. $msg= str_replace("#mail#",$mail,$msg1);
  826. $msg1= str_replace("#questionName#",$arrques[$i],$msg);
  827. $msg= str_replace("#answer#",$arrans[$i],$msg1);
  828. $msg1= str_replace("#i#",$i,$msg);
  829. $msg= str_replace("#course#",$courseName,$msg1);
  830. }
  831. $msg.='</table><br>
  832. <span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
  833. <a href="#url#">#url#</a></span></body></html>';
  834. $msg1= str_replace("#url#",$url,$msg);
  835. $mail_content = stripslashes($msg1);
  836. $student_name = $_SESSION['_user']['firstName'].' '.$_SESSION['_user']['lastName'];
  837. $subject = get_lang('OpenQuestionsAttempted');
  838. api_mail_html($student_name, $to, $subject, $mail_content, $from_name, $from);
  839. }
  840. ?>