exercise_result.php 27 KB

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