exercise_result.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. <?php // $Id: exercise_result.php 9774 2006-10-25 15:13:32Z yannoo $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Olivier Brouckaert
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * EXERCISE RESULT
  22. *
  23. * This script gets informations from the script "exercise_submit.php",
  24. * through the session, and calculates the score of the student for
  25. * that exercise.
  26. *
  27. * Then it shows the results on the screen.
  28. *
  29. * @author Olivier Brouckaert, main author
  30. * @author Roan Embrechts, some refactoring
  31. * @package dokeos.exercise
  32. * @todo split more code up in functions, move functions to library?
  33. ==============================================================================
  34. */
  35. /*
  36. ==============================================================================
  37. INIT SECTION
  38. ==============================================================================
  39. */
  40. include('exercise.class.php');
  41. include('question.class.php');
  42. include('answer.class.php');
  43. // answer types
  44. define('UNIQUE_ANSWER', 1);
  45. define('MULTIPLE_ANSWER', 2);
  46. define('FILL_IN_BLANKS', 3);
  47. define('MATCHING', 4);
  48. define('FREE_ANSWER', 5);
  49. define('HOT_SPOT', 6);
  50. global $_cid;
  51. $langFile='exercice';
  52. include('../inc/global.inc.php');
  53. $this_section=SECTION_COURSES;
  54. include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  55. include(api_get_path(LIBRARY_PATH).'mail.lib.inc.php');
  56. //include(api_get_path(LIBRARY_PATH).'text.lib.php');
  57. $TBL_EXERCICE_QUESTION = $_course['dbNameGlu'].'quiz_rel_question';
  58. $TBL_EXERCICES = $_course['dbNameGlu'].'quiz';
  59. $TBL_QUESTIONS = $_course['dbNameGlu'].'quiz_question';
  60. $TBL_REPONSES = $_course['dbNameGlu'].'quiz_answer';
  61. $TABLETRACK_EXERCICES = $statsDbName."`.`track_e_exercices";
  62. $TABLETRACK_ATTEMPT = $statsDbName."`.`track_e_attempt";
  63. $main_user_table = Database :: get_main_table(MAIN_USER_TABLE);
  64. $main_course_user_table = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
  65. $table_ans = Database :: get_course_table(QUIZ_ANSWER_TABLE);
  66. //temp values to move to AWACS
  67. $dsp_percent = false; //false to display total score as absolute values
  68. //debug param. 0: no display - 1: debug display
  69. $debug=0;
  70. if($debug>0){echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);}
  71. // general parameters passed via POST/GET
  72. if ( empty ( $origin ) ) {
  73. $origin = $_REQUEST['origin'];
  74. }
  75. if ( empty ( $learnpath_id ) ) {
  76. $learnpath_id = mysql_real_escape_string($_REQUEST['learnpath_id']);
  77. }
  78. if ( empty ( $learnpath_item_id ) ) {
  79. $learnpath_item_id = mysql_real_escape_string($_REQUEST['learnpath_item_id']);
  80. }
  81. if ( empty ( $formSent ) ) {
  82. $formSent = $_REQUEST['formSent'];
  83. }
  84. if ( empty ( $exerciseResult ) ) {
  85. $exerciseResult = $_SESSION['exerciseResult'];
  86. }
  87. if ( empty ( $questionId ) ) {
  88. $questionId = $_REQUEST['questionId'];
  89. }
  90. if ( empty ( $choice ) ) {
  91. $choice = $_REQUEST['choice'];
  92. }
  93. if ( empty ( $questionNum ) ) {
  94. $questionNum = mysql_real_escape_string($_REQUEST['questionNum']);
  95. }
  96. if ( empty ( $nbrQuestions ) ) {
  97. $nbrQuestions = mysql_real_escape_string($_REQUEST['nbrQuestions']);
  98. }
  99. if ( empty ( $questionList ) ) {
  100. $questionList = $_SESSION['questionList'];
  101. }
  102. if ( empty ( $objExercise ) ) {
  103. $objExercise = $_SESSION['objExercise'];
  104. }
  105. $main_user_table = Database :: get_main_table(MAIN_USER_TABLE);
  106. $main_admin_table = Database :: get_main_table(MAIN_ADMIN_TABLE);
  107. $courseName = $_SESSION[_course][name];
  108. $query = "select user_id from $main_admin_table";
  109. $admin_id = mysql_result(api_sql_query($query),0,"user_id");
  110. $query1 = "select email,firstname,lastname from $main_user_table where user_id = $admin_id";
  111. $rs = api_sql_query($query1);
  112. $row = mysql_fetch_array($rs);
  113. $from = $row['email'];
  114. $from_name = $row['firstname'].' '.$row['lastname'];
  115. $str = $_SERVER['REQUEST_URI'];
  116. $arr = explode('/',$str);
  117. $url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result';
  118. //$url = $_SERVER['SERVER_NAME'].'/'.$arr[1].'/';
  119. // if the above variables are empty or incorrect, stops the script
  120. if(!is_array($exerciseResult) || !is_array($questionList) || !is_object($objExercise))
  121. {
  122. header('Location: exercice.php');
  123. exit();
  124. }
  125. $exerciseTitle=$objExercise->selectTitle();
  126. $nameTools=get_lang('Exercice');
  127. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  128. if ($origin != 'learnpath')
  129. {
  130. //so we are not in learnpath tool
  131. Display::display_header($nameTools,"Exercise");
  132. }
  133. else
  134. {
  135. ?> <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH); ?>css/default.css"> <?php
  136. }
  137. /*
  138. ==============================================================================
  139. FUNCTIONS
  140. ==============================================================================
  141. */
  142. function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect)
  143. {
  144. ?>
  145. <tr>
  146. <td width="5%" align="center">
  147. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $studentChoice?'_on':'_off'; ?>.gif"
  148. border="0" alt="" />
  149. </td>
  150. <td width="5%" align="center">
  151. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif"
  152. border="0" alt=" " />
  153. </td>
  154. <td width="45%" style="border-bottom: 1px solid #4171B5;">
  155. <?php
  156. $answer=api_parse_tex($answer);
  157. echo $answer; ?>
  158. </td>
  159. <td width="45%" style="border-bottom: 1px solid #4171B5;">
  160. <?php
  161. $answerComment=api_parse_tex($answerComment);
  162. if($studentChoice) echo nl2br(make_clickable($answerComment)); else echo '&nbsp;'; ?>
  163. </td>
  164. </tr>
  165. <?php
  166. }
  167. function display_fill_in_blanks_answer($answer)
  168. {
  169. ?>
  170. <tr>
  171. <td>
  172. <?php echo nl2br($answer); ?>
  173. </td>
  174. </tr>
  175. <?php
  176. }
  177. function display_free_answer($answer)
  178. {
  179. ?>
  180. <tr>
  181. <td width="55%">
  182. <?php echo nl2br(stripslashes($answer)); ?>
  183. </td>
  184. <td width="45%">
  185. <?php echo get_lang('notCorrectedYet');?>
  186. </td>
  187. </tr>
  188. <?php
  189. }
  190. function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment)
  191. {
  192. global $hotspot_colors;
  193. ?>
  194. <tr>
  195. <td width="25%" valign="top">
  196. <div style="float:left; padding-left:5px;">
  197. <div style="display:inline; float:left; width:80px;"><?php echo $answer ?></div>
  198. <div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]; ?>; display:inline; float:left; margin-top:3px;"></div>
  199. </div>
  200. </td>
  201. <td width="25%" valign="top"><?php echo $answerId; ?></td>
  202. <td width="25%" valign="top">
  203. <?php $studentChoice = ($studentChoice)?get_lang('Correct'):get_lang('Fault'); echo $studentChoice; ?>
  204. </td>
  205. <td width="25%" valign="top">
  206. <?php echo $answerComment ?>
  207. </td>
  208. </tr>
  209. <?php
  210. }
  211. /*
  212. ==============================================================================
  213. MAIN CODE
  214. ==============================================================================
  215. */
  216. $exerciseTitle=api_parse_tex($exerciseTitle);
  217. ?>
  218. <h3><?php echo $exerciseTitle ?>: <?php echo get_lang("Result"); ?></h3>
  219. <form method="get" action="exercice.php">
  220. <input type="hidden" name="origin" value="<?php echo $origin; ?>" />
  221. <input type="hidden" name="learnpath_id" value="<?php echo $learnpath_id; ?>" />
  222. <input type="hidden" name="learnpath_item_id" value="<?php echo $learnpath_item_id; ?>" />
  223. <?php
  224. $i=$totalScore=$totalWeighting=0;
  225. if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
  226. // added by Priya Saini
  227. $sql = "select max(exe_Id) as id from `".$TABLETRACK_EXERCICES."`";
  228. $res = api_sql_query($sql, __FILE__, __LINE__);
  229. $exeId =mysql_result($res,0,"id");
  230. $exeId=$exeId+1;
  231. foreach($questionList as $questionId)
  232. {
  233. // gets the student choice for this question
  234. $choice=$exerciseResult[$questionId];
  235. // creates a temporary Question object
  236. $objQuestionTmp=new Question();
  237. $objQuestionTmp->read($questionId);
  238. $questionName=$objQuestionTmp->selectTitle();
  239. $questionWeighting=$objQuestionTmp->selectWeighting();
  240. $answerType=$objQuestionTmp->selectType();
  241. $quesId =$objQuestionTmp->selectId(); //added by priya saini
  242. // destruction of the Question object
  243. unset($objQuestionTmp);
  244. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  245. {
  246. $colspan=4;
  247. }
  248. elseif($answerType == MATCHING || $answerType == FREE_ANSWER)
  249. {
  250. $colspan=2;
  251. }
  252. else
  253. {
  254. $colspan=1;
  255. }
  256. ?>
  257. <table width="100%" border="0" cellpadding="3" cellspacing="2">
  258. <tr bgcolor="#E6E6E6">
  259. <td colspan="<?php echo $colspan; ?>">
  260. <?php echo get_lang("Question").' '.($i+1); ?>
  261. </td>
  262. </tr>
  263. <tr>
  264. <td colspan="<?php echo $colspan; ?>">
  265. <?php echo $questionName; ?>
  266. </td>
  267. </tr>
  268. <?php
  269. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  270. {
  271. ?>
  272. <tr>
  273. <td width="5%" valign="top" align="center" nowrap="nowrap">
  274. <i><?php echo get_lang("Choice"); ?></i>
  275. </td>
  276. <td width="5%" valign="top" nowrap="nowrap">
  277. <i><?php echo get_lang("ExpectedChoice"); ?></i>
  278. </td>
  279. <td width="45%" valign="top">
  280. <i><?php echo get_lang("Answer"); ?></i>
  281. </td>
  282. <td width="45%" valign="top">
  283. <i><?php echo get_lang("Comment"); ?></i>
  284. </td>
  285. </tr>
  286. <?php
  287. }
  288. elseif($answerType == FILL_IN_BLANKS)
  289. {
  290. ?>
  291. <tr>
  292. <td>
  293. <i><?php echo get_lang("Answer"); ?></i>
  294. </td>
  295. </tr>
  296. <?php
  297. }
  298. elseif($answerType == FREE_ANSWER)
  299. {
  300. ?>
  301. <tr>
  302. <td width="55%">
  303. <i><?php echo get_lang("Answer"); ?></i>
  304. </td>
  305. <td width="45%" valign="top">
  306. <i><?php echo get_lang("Comment"); ?></i>
  307. </td>
  308. </tr>
  309. <?php
  310. }
  311. elseif($answerType == HOT_SPOT)
  312. {
  313. ?>
  314. <tr>
  315. <td width="40%">
  316. <i><?php echo get_lang('Hotspot'); ?></i><br /><br />
  317. <object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo $questionId ?>" width="380" height="400">
  318. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo $questionId ?>" />
  319. </object>
  320. </td>
  321. <td width="60%" valign="top">
  322. <table width="100%" border="0">
  323. <tr>
  324. <td width="25%" valign="top">
  325. <i><?php echo get_lang("CorrectAnswer"); ?></i><br /><br />
  326. </td>
  327. <td width="25%" valign="top">
  328. <i><?php echo get_lang("ClickNumber"); ?></i><br /><br />
  329. </td>
  330. <td width="25%" valign="top">
  331. <i><?php echo get_lang('HotspotHit'); ?></i><br /><br />
  332. </td>
  333. <td width="25%" valign="top">
  334. <i><?php echo get_lang("Comment"); ?></i><br /><br />
  335. </td>
  336. </tr>
  337. <?php
  338. }
  339. else
  340. {
  341. ?>
  342. <tr>
  343. <td width="50%">
  344. <i><?php echo get_lang("ElementList"); ?></i>
  345. </td>
  346. <td width="50%">
  347. <i><?php echo get_lang("CorrespondsTo"); ?></i>
  348. </td>
  349. </tr>
  350. <?php
  351. }
  352. // construction of the Answer object
  353. $objAnswerTmp=new Answer($questionId);
  354. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  355. $questionScore=0;
  356. for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
  357. {
  358. $answer=$objAnswerTmp->selectAnswer($answerId);
  359. $answerComment=$objAnswerTmp->selectComment($answerId);
  360. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  361. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  362. switch($answerType)
  363. {
  364. // for unique answer
  365. case UNIQUE_ANSWER :
  366. $studentChoice=($choice == $answerId)?1:0;
  367. if($studentChoice)
  368. {
  369. $questionScore+=$answerWeighting;
  370. $totalScore+=$answerWeighting;
  371. }
  372. break;
  373. // for multiple answers
  374. case MULTIPLE_ANSWER :
  375. $studentChoice=$choice[$answerId];
  376. if($studentChoice)
  377. {
  378. $questionScore+=$answerWeighting;
  379. $totalScore+=$answerWeighting;
  380. }
  381. break;
  382. // for fill in the blanks
  383. case FILL_IN_BLANKS : // splits text and weightings that are joined with the character '::'
  384. list($answer,$answerWeighting)=explode('::',$answer);
  385. // splits weightings that are joined with a comma
  386. $answerWeighting=explode(',',$answerWeighting);
  387. // we save the answer because it will be modified
  388. $temp=$answer;
  389. // TeX parsing
  390. // 1. find everything between the [tex] and [/tex] tags
  391. $startlocations=strpos($temp,'[tex]');
  392. $endlocations=strpos($temp,'[/tex]');
  393. if($startlocations !== false && $endlocations !== false)
  394. {
  395. $texstring=substr($temp,$startlocations,$endlocations-$startlocations+6);
  396. // 2. replace this by {texcode}
  397. $temp=str_replace($texstring,'{texcode}',$temp);
  398. }
  399. $answer='';
  400. $j=0;
  401. // the loop will stop at the end of the text
  402. while(1)
  403. {
  404. // quits the loop if there are no more blanks
  405. if(($pos = strpos($temp,'[')) === false)
  406. {
  407. // adds the end of the text
  408. $answer.=$temp;
  409. // TeX parsing
  410. $texstring = api_parse_tex($texstring);
  411. $answer=str_replace("{texcode}",$texstring,$answer);
  412. break;
  413. }
  414. // adds the piece of text that is before the blank and ended by [
  415. $answer.=substr($temp,0,$pos+1);
  416. $temp=substr($temp,$pos+1);
  417. // quits the loop if there are no more blanks
  418. if(($pos = strpos($temp,']')) === false)
  419. {
  420. // adds the end of the text
  421. $answer.=$temp;
  422. break;
  423. }
  424. $choice[$j]=trim($choice[$j]);
  425. // if the word entered by the student IS the same as the one defined by the professor
  426. if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j])))
  427. {
  428. // gives the related weighting to the student
  429. $questionScore+=$answerWeighting[$j];
  430. // increments total score
  431. $totalScore+=$answerWeighting[$j];
  432. // adds the word in green at the end of the string
  433. $answer.=stripslashes($choice[$j]);
  434. }
  435. // else if the word entered by the student IS NOT the same as the one defined by the professor
  436. elseif(!empty($choice[$j]))
  437. {
  438. // adds the word in red at the end of the string, and strikes it
  439. $answer.='<font color="red"><s>'.stripslashes($choice[$j]).'</s></font>';
  440. }
  441. else
  442. {
  443. // adds a tabulation if no word has been typed by the student
  444. $answer.='&nbsp;&nbsp;&nbsp;';
  445. }
  446. // adds the correct word, followed by ] to close the blank
  447. $answer.=' / <font color="green"><b>'.substr($temp,0,$pos).'</b></font>]';
  448. $j++;
  449. $temp=substr($temp,$pos+1);
  450. }
  451. break;
  452. // for free answer
  453. case FREE_ANSWER :
  454. $studentChoice=$choice;
  455. if($studentChoice)
  456. {
  457. $questionScore=0;
  458. $totalScore+=0;
  459. }
  460. break;
  461. // for matching
  462. case MATCHING :
  463. if($answerCorrect)
  464. {
  465. if($answerCorrect == $choice[$answerId])
  466. {
  467. $questionScore+=$answerWeighting;
  468. $totalScore+=$answerWeighting;
  469. $choice[$answerId]=$matching[$choice[$answerId]];
  470. }
  471. elseif(!$choice[$answerId])
  472. {
  473. $choice[$answerId]='&nbsp;&nbsp;&nbsp;';
  474. }
  475. else
  476. {
  477. $choice[$answerId]='<font color="red"><s>'.$matching[$choice[$answerId]].'</s></font>';
  478. }
  479. }
  480. else
  481. {
  482. $matching[$answerId]=$answer;
  483. }
  484. break;
  485. } // end switch Answertype
  486. if($answerType != MATCHING || $answerCorrect)
  487. {
  488. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  489. {
  490. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect);
  491. }
  492. elseif($answerType == FILL_IN_BLANKS)
  493. {
  494. display_fill_in_blanks_answer($answer);
  495. }
  496. elseif($answerType == FREE_ANSWER)
  497. {
  498. // to store the details of open questions in an array to be used in mail
  499. $arrques[] = $questionName;
  500. $arrans[] = $choice;
  501. $firstName = $_SESSION['_user']['firstName'];
  502. $lastName = $_SESSION['_user']['lastName'];
  503. $mail = $_SESSION['_user']['mail'];
  504. $coursecode = $_SESSION['_course']['official_code'];
  505. $query1 = "SELECT user_id from $main_course_user_table where course_code= '$coursecode' and role = 'professor'";
  506. $result1 = api_sql_query($query1, __FILE__, __LINE__);
  507. $temp = mysql_result($result1,0,"user_id");
  508. $query = "select email from $main_user_table where user_id =".$temp ;
  509. $result = api_sql_query($query, __FILE__, __LINE__);
  510. $to = mysql_result($result,0,"email");
  511. display_free_answer($choice);
  512. }
  513. elseif($answerType == HOT_SPOT)
  514. {
  515. display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
  516. }
  517. else
  518. {
  519. ?>
  520. <tr>
  521. <td width="50%">
  522. <?php
  523. $answer=api_parse_tex($answer);
  524. echo $answer; ?>
  525. </td>
  526. <td width="50%">
  527. <?php echo $choice[$answerId]; ?> / <font color="green"><b>
  528. <?php
  529. $matching[$answerCorrect]=api_parse_tex($matching[$answerCorrect]);
  530. echo $matching[$answerCorrect]; ?></b></font>
  531. </td>
  532. </tr>
  533. <?php
  534. }
  535. }
  536. } // end for that loops over all answers of the current question
  537. ?>
  538. <tr>
  539. <td colspan="<?php echo $colspan; ?>" align="right">
  540. <b><?php echo get_lang('Score')." : $questionScore/$questionWeighting"; ?></b>
  541. </td>
  542. </tr>
  543. </table>
  544. <?php
  545. // destruction of Answer
  546. unset($objAnswerTmp);
  547. $i++;
  548. $totalWeighting+=$questionWeighting;
  549. //added by priya saini
  550. if($is_trackingEnabled)
  551. {
  552. if ($answerType==2 )
  553. {
  554. $reply = array_keys($choice);
  555. for ($i=0;$i<sizeof($reply);$i++)
  556. {
  557. $ans = $reply[$i];
  558. exercise_attempt($questionScore,$ans,$quesId,$exeId);
  559. }
  560. }
  561. else if ($answerType==4)
  562. { $j=3;
  563. for ($i=0;$i<sizeof($choice);$i++,$j++)
  564. {
  565. $val = $choice[$j];
  566. if (preg_match_all ('#<font color="red"><s>([0-9a-z ]*)</s></font>#', $val, $arr1))
  567. $val = $arr1[1][0];
  568. $sql = "select position from $table_ans where question_id=$questionId and answer='$val'";
  569. $res = api_sql_query($sql, __FILE__, __LINE__);
  570. $answer = mysql_result($res,0,"position");
  571. exercise_attempt($questionScore,$answer,$quesId,$exeId,$j);
  572. }
  573. }
  574. else if ($answerType==5)
  575. {
  576. $answer = $choice;
  577. exercise_attempt($questionScore,$answer,$quesId,$exeId);
  578. }
  579. else if ($answerType==1)
  580. {
  581. $sql = "select id from $table_ans where question_id=$questionId and position=$choice";
  582. $res = api_sql_query($sql, __FILE__, __LINE__);
  583. $answer = mysql_result($res,0,"id");
  584. exercise_attempt($questionScore,$answer,$quesId,$exeId);
  585. }
  586. else
  587. exercise_attempt($questionScore,$answer,$quesId,$exeId);
  588. }
  589. } // end huge foreach() block that loops over all questions
  590. ?>
  591. <table width="100%" border="0" cellpadding="3" cellspacing="2">
  592. <tr>
  593. <td>
  594. <b><?php echo get_lang('YourTotalScore')." ";
  595. if($dsp_percent == true){
  596. echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
  597. }else{
  598. echo $totalScore."/".$totalWeighting;
  599. }
  600. ?> !</b>
  601. </td>
  602. </tr>
  603. <tr>
  604. <td>
  605. <br />
  606. <input type="submit" value="<?php echo get_lang('Ok'); ?>" />
  607. </td>
  608. </tr>
  609. </table>
  610. </form>
  611. <br />
  612. <?php
  613. /*
  614. ==============================================================================
  615. Tracking of results
  616. ==============================================================================
  617. */
  618. if($is_trackingEnabled)
  619. {
  620. //include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  621. event_exercice($objExercise->selectId(),$totalScore,$totalWeighting,$answer,$question_id);
  622. }
  623. if ($origin != 'learnpath')
  624. {
  625. //we are not in learnpath tool
  626. Display::display_footer();
  627. }
  628. $csspath = "http://portal.dokeos.com/demo/main/css/default.css";
  629. if (!empty($arrques))
  630. {
  631. $msg = "<html><head>
  632. <link rel='stylesheet' href='http://www.dokeos.com/styles.css' type='text/css'>
  633. <meta content='text/html; charset=ISO-8859-1' http-equiv='content-type'>";
  634. /*<style type='text/css'>
  635. <!--
  636. .body{
  637. font-family: Verdana, Arial, Helvetica, sans-serif;
  638. font-weight: Normal;
  639. color: #000000;
  640. }
  641. .style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; color: #006699; }
  642. .style10 {
  643. font-family: Verdana, Arial, Helvetica, sans-serif;
  644. font-size: 12px;
  645. font-weight: bold;
  646. }
  647. .style16 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
  648. -->
  649. </style>*/
  650. /*$msg .= "</head>
  651. <body>
  652. <br>
  653. <p><span class='style8'>Open Question(s) Attempted
  654. </span></p>
  655. <p><span class='style8'>Attempt Details : </span><br>
  656. </p>
  657. <table width='730' height='136' border='0' cellpadding='3' cellspacing='3'>
  658. <tr>
  659. <td width='229' valign='top' bgcolor='E5EDF8'>&nbsp;&nbsp;<span class='style10'>Course Name</span></td>
  660. <td width='469' valign='top' bgcolor='#F3F3F3'><span class='style16'>#course#</span></td>
  661. </tr>
  662. <tr>
  663. <td width='229' valign='top' bgcolor='E5EDF8'>&nbsp;&nbsp;<span class='style10'>Test Attempted</span></td>
  664. <td width='469' valign='top' bgcolor='#F3F3F3'><span class='style16'> #exercise#</span></td>
  665. </tr>
  666. <tr>
  667. <td valign='top' bgcolor='E5EDF8'>&nbsp;&nbsp;<span class='style10'>Student's Name </span></td>
  668. <td valign='top' bgcolor='#F3F3F3'><span class='style16'> #firstName# #lastName#</span></td>
  669. </tr>
  670. <tr>
  671. <td valign='top' bgcolor='E5EDF8'>&nbsp;&nbsp;<span class='style10'>Student's Email ID </span></td>
  672. <td valign='top' bgcolor='#F3F3F3'><span class='style16'> #mail#</span></td>
  673. </tr></table>
  674. <p><br>
  675. <span class='style8'>Open Questions Attempted are :</span></p>
  676. <table width='730' height='136' border='0' cellpadding='3' cellspacing='3'>";
  677. for($i=0;$i<sizeof($arrques);$i++)
  678. {
  679. $msg.="
  680. <tr>
  681. <td width='220' valign='top' bgcolor='E5EDF8'>&nbsp;&nbsp;<span class='style10'>Question</span></td>
  682. <td width='473' valign='top' bgcolor='F3F3F3'><span class='style16'> #questionName#</span></td>
  683. </tr>
  684. <tr>
  685. <td width='220' valign='top' bgcolor='E5EDF8'>&nbsp;&nbsp;<span class='style10'>Answer </span></td>
  686. <td valign='top' bgcolor='F3F3F3'><span class='style16'> #answer#</span></td>
  687. </tr>";
  688. $msg1= str_replace("#exercise#",$exerciseTitle,$msg);
  689. $msg= str_replace("#firstName#",$firstName,$msg1);
  690. $msg1= str_replace("#lastName#",$lastName,$msg);
  691. $msg= str_replace("#mail#",$mail,$msg1);
  692. $msg1= str_replace("#questionName#",$arrques[$i],$msg);
  693. $msg= str_replace("#answer#",$arrans[$i],$msg1);
  694. $msg1= str_replace("#i#",$i,$msg);
  695. $msg= str_replace("#course#",$courseName,$msg1);
  696. }
  697. $msg.="</table><br>*/
  698. //
  699. $msg .= "</head>
  700. <body><br>
  701. <p>Open Question(s) Attempted
  702. </p>
  703. <p>Attempt Details : ><br>
  704. </p>
  705. <table width='730' height='136' border='0' cellpadding='3' cellspacing='3'>
  706. <tr>
  707. <td width='229' valign='top' class='mybody'>&nbsp;&nbsp;Course Name</td>
  708. <td width='469' valign='top' class='mybody'>#course#</td>
  709. </tr>
  710. <tr>
  711. <td width='229' valign='top' class='outerframe'>&nbsp;&nbsp;Test Attempted</span></td>
  712. <td width='469' valign='top' class='outerframe'>#exercise#</td>
  713. </tr>
  714. <tr>
  715. <td valign='top'>&nbsp;&nbsp;<span class='style10'>Student's Name </span></td>
  716. <td valign='top' >#firstName# #lastName#</td>
  717. </tr>
  718. <tr>
  719. <td valign='top' >&nbsp;&nbsp;Student's Email ID </td>
  720. <td valign='top'> #mail#</td>
  721. </tr></table>
  722. <p><br>
  723. Open Questions Attempted are :</p>
  724. <table width='730' height='136' border='0' cellpadding='3' cellspacing='3'>";
  725. for($i=0;$i<sizeof($arrques);$i++)
  726. {
  727. $msg.="
  728. <tr>
  729. <td width='220' valign='top' bgcolor='E5EDF8'>&nbsp;&nbsp;<span class='style10'>Question</span></td>
  730. <td width='473' valign='top' bgcolor='F3F3F3'><span class='style16'> #questionName#</span></td>
  731. </tr>
  732. <tr>
  733. <td width='220' valign='top' bgcolor='E5EDF8'>&nbsp;&nbsp;<span class='style10'>Answer </span></td>
  734. <td valign='top' bgcolor='F3F3F3'><span class='style16'> #answer#</span></td>
  735. </tr>";
  736. $msg1= str_replace("#exercise#",$exerciseTitle,$msg);
  737. $msg= str_replace("#firstName#",$firstName,$msg1);
  738. $msg1= str_replace("#lastName#",$lastName,$msg);
  739. $msg= str_replace("#mail#",$mail,$msg1);
  740. $msg1= str_replace("#questionName#",$arrques[$i],$msg);
  741. $msg= str_replace("#answer#",$arrans[$i],$msg1);
  742. $msg1= str_replace("#i#",$i,$msg);
  743. $msg= str_replace("#course#",$courseName,$msg1);
  744. }
  745. $msg.="</table><br>
  746. <span class='style16'>Click the following links tp check the answer and give feedbacks,<br>
  747. <a href='#url#'>#url#</a></span></body></html>";
  748. $msg1= str_replace("#url#",$url,$msg);
  749. $mail_content = stripslashes($msg1);
  750. $student_name = $_SESSION[_user][firstName].' '.$_SESSION[_user][lastName];
  751. $subject = "Open Questions Attempted.";
  752. $headers="From:$from_name\r\nReply-to: $to\r\nContent-type: text/html; charset=iso-8859-15";
  753. api_mail($student_name, $to, $subject, $mail_content, $from_name, $from, $headers);
  754. //mail($to,'Open questions attempted',$mail_content,$headers);
  755. }
  756. ?>