exercise_result.php 29 KB

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