exercise_result.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos SPRL
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  14. Mail: info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. * Exercise result
  19. * This script gets informations from the script "exercise_submit.php",
  20. * through the session, and calculates the score of the student for
  21. * that exercise.
  22. * Then it shows the results on the screen.
  23. * @package dokeos.exercise
  24. * @author Olivier Brouckaert, main author
  25. * @author Roan Embrechts, some refactoring
  26. * @author Julio Montoya Armas switchable fill in blank option added
  27. * @version $Id: exercise_result.php 22201 2009-07-17 19:57:03Z cfasanando $
  28. *
  29. * @todo split more code up in functions, move functions to library?
  30. */
  31. /*
  32. ==============================================================================
  33. INIT SECTION
  34. ==============================================================================
  35. */
  36. require_once('exercise.class.php');
  37. require_once('question.class.php');
  38. require_once('answer.class.php');
  39. if ($_GET['origin']=='learnpath') {
  40. require_once ('../newscorm/learnpath.class.php');
  41. require_once ('../newscorm/learnpathItem.class.php');
  42. require_once ('../newscorm/scorm.class.php');
  43. require_once ('../newscorm/scormItem.class.php');
  44. require_once ('../newscorm/aicc.class.php');
  45. require_once ('../newscorm/aiccItem.class.php');
  46. }
  47. global $_cid;
  48. // name of the language file that needs to be included
  49. $language_file='exercice';
  50. require('../inc/global.inc.php');
  51. $this_section=SECTION_COURSES;
  52. /* ------------ ACCESS RIGHTS ------------ */
  53. // notice for unauthorized people.
  54. api_protect_course_script(true);
  55. require_once(api_get_path(LIBRARY_PATH).'mail.lib.inc.php');
  56. require_once(api_get_path(LIBRARY_PATH).'course.lib.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. $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  63. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_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 admin settings
  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 = Security::remove_XSS($_REQUEST['origin']);
  75. }
  76. if ( empty ( $learnpath_id ) ) {
  77. $learnpath_id = Security::remove_XSS($_REQUEST['learnpath_id']);
  78. }
  79. if ( empty ( $learnpath_item_id ) ) {
  80. $learnpath_item_id = Security::remove_XSS($_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 ( $exerciseResultCoordinates ) ) {
  89. $exerciseResultCoordinates = $_SESSION['exerciseResultCoordinates'];
  90. }
  91. if ( empty ( $questionId ) ) {
  92. $questionId = $_REQUEST['questionId'];
  93. }
  94. if ( empty ( $choice ) ) {
  95. $choice = $_REQUEST['choice'];
  96. }
  97. if ( empty ( $questionNum ) ) {
  98. $questionNum = $_REQUEST['questionNum'];
  99. }
  100. if ( empty ( $nbrQuestions ) ) {
  101. $nbrQuestions = $_REQUEST['nbrQuestions'];
  102. }
  103. if ( empty ( $questionList ) ) {
  104. $questionList = $_SESSION['questionList'];
  105. }
  106. if ( empty ( $objExercise ) ) {
  107. $objExercise = $_SESSION['objExercise'];
  108. }
  109. if ( empty ( $exerciseType ) ) {
  110. $exerciseType = $_REQUEST['exerciseType'];
  111. }
  112. $_configuration['live_exercise_tracking'] = false;
  113. if($_configuration['live_exercise_tracking']) define('ENABLED_LIVE_EXERCISE_TRACKING',1);
  114. if($_configuration['live_exercise_tracking'] == true && $exerciseType == 1){
  115. $_configuration['live_exercise_tracking'] = false;
  116. }
  117. // set admin name as person who sends the results e-mail (lacks policy about whom should really send the results)
  118. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  119. $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  120. $courseName = $_SESSION['_course']['name'];
  121. $query = "SELECT user_id FROM $main_admin_table LIMIT 1"; //get all admins from admin table
  122. $admin_id = Database::result(Database::query($query),0,"user_id");
  123. $uinfo = api_get_user_info($admin_id);
  124. $from = $uinfo['mail'];
  125. $from_name = api_get_person_name($uinfo['firstname'], $uinfo['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
  126. $str = $_SERVER['REQUEST_URI'];
  127. $url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result';
  128. $sql_fb_type='SELECT feedback_type FROM '.$TBL_EXERCICES.' WHERE id ="'.Database::escape_string($objExercise->selectId()).'"';
  129. $res_fb_type=Database::query($sql_fb_type,__FILE__,__LINE__);
  130. $row_fb_type=Database::fetch_row($res_fb_type);
  131. $feedback_type = $row_fb_type[0];
  132. // if the above variables are empty or incorrect, we don't have any result to show, so stop the script
  133. if(!is_array($exerciseResult) || !is_array($questionList) || !is_object($objExercise))
  134. {
  135. header('Location: exercice.php');
  136. exit();
  137. }
  138. // define basic exercise info to print on screen
  139. $exerciseTitle=$objExercise->selectTitle();
  140. $exerciseDescription=$objExercise->selectDescription();
  141. $gradebook = '';
  142. if (isset($_SESSION['gradebook'])){
  143. $gradebook= $_SESSION['gradebook'];
  144. }
  145. if (!empty($gradebook) && $gradebook=='view') {
  146. $interbreadcrumb[]= array (
  147. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  148. 'name' => get_lang('Gradebook')
  149. );
  150. }
  151. $nameTools=get_lang('Exercice');
  152. $interbreadcrumb[]=array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
  153. $htmlHeadXtra[] = "<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
  154. <script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
  155. <script language=\"JavaScript\" type=\"text/javascript\">
  156. <!--
  157. // -----------------------------------------------------------------------------
  158. // Globals
  159. // Major version of Flash required
  160. var requiredMajorVersion = 7;
  161. // Minor version of Flash required
  162. var requiredMinorVersion = 0;
  163. // Minor version of Flash required
  164. var requiredRevision = 0;
  165. // the version of javascript supported
  166. var jsVersion = 1.0;
  167. // -----------------------------------------------------------------------------
  168. // -->
  169. </script>
  170. <script language=\"VBScript\" type=\"text/vbscript\">
  171. <!-- // Visual basic helper required to detect Flash Player ActiveX control version information
  172. Function VBGetSwfVer(i)
  173. on error resume next
  174. Dim swControl, swVersion
  175. swVersion = 0
  176. set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i))
  177. if (IsObject(swControl)) then
  178. swVersion = swControl.GetVariable(\"\$version\")
  179. end if
  180. VBGetSwfVer = swVersion
  181. End Function
  182. // -->
  183. </script>
  184. <script language=\"JavaScript1.1\" type=\"text/javascript\">
  185. <!-- // Detect Client Browser type
  186. var isIE = (navigator.appVersion.indexOf(\"MSIE\") != -1) ? true : false;
  187. var isWin = (navigator.appVersion.toLowerCase().indexOf(\"win\") != -1) ? true : false;
  188. var isOpera = (navigator.userAgent.indexOf(\"Opera\") != -1) ? true : false;
  189. jsVersion = 1.1;
  190. // JavaScript helper required to detect Flash Player PlugIn version information
  191. function JSGetSwfVer(i){
  192. // NS/Opera version >= 3 check for Flash plugin in plugin array
  193. if (navigator.plugins != null && navigator.plugins.length > 0) {
  194. if (navigator.plugins[\"Shockwave Flash 2.0\"] || navigator.plugins[\"Shockwave Flash\"]) {
  195. var swVer2 = navigator.plugins[\"Shockwave Flash 2.0\"] ? \" 2.0\" : \"\";
  196. var flashDescription = navigator.plugins[\"Shockwave Flash\" + swVer2].description;
  197. descArray = flashDescription.split(\" \");
  198. tempArrayMajor = descArray[2].split(\".\");
  199. versionMajor = tempArrayMajor[0];
  200. versionMinor = tempArrayMajor[1];
  201. if ( descArray[3] != \"\" ) {
  202. tempArrayMinor = descArray[3].split(\"r\");
  203. } else {
  204. tempArrayMinor = descArray[4].split(\"r\");
  205. }
  206. versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
  207. flashVer = versionMajor + \".\" + versionMinor + \".\" + versionRevision;
  208. } else {
  209. flashVer = -1;
  210. }
  211. }
  212. // MSN/WebTV 2.6 supports Flash 4
  213. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.6\") != -1) flashVer = 4;
  214. // WebTV 2.5 supports Flash 3
  215. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.5\") != -1) flashVer = 3;
  216. // older WebTV supports Flash 2
  217. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv\") != -1) flashVer = 2;
  218. // Can't detect in all other cases
  219. else {
  220. flashVer = -1;
  221. }
  222. return flashVer;
  223. }
  224. // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
  225. function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
  226. {
  227. reqVer = parseFloat(reqMajorVer + \".\" + reqRevision);
  228. // loop backwards through the versions until we find the newest version
  229. for (i=25;i>0;i--) {
  230. if (isIE && isWin && !isOpera) {
  231. versionStr = VBGetSwfVer(i);
  232. } else {
  233. versionStr = JSGetSwfVer(i);
  234. }
  235. if (versionStr == -1 ) {
  236. return false;
  237. } else if (versionStr != 0) {
  238. if(isIE && isWin && !isOpera) {
  239. tempArray = versionStr.split(\" \");
  240. tempString = tempArray[1];
  241. versionArray = tempString .split(\",\");
  242. } else {
  243. versionArray = versionStr.split(\".\");
  244. }
  245. versionMajor = versionArray[0];
  246. versionMinor = versionArray[1];
  247. versionRevision = versionArray[2];
  248. versionString = versionMajor + \".\" + versionRevision; // 7.0r24 == 7.24
  249. versionNum = parseFloat(versionString);
  250. // is the major.revision >= requested major.revision AND the minor version >= requested minor
  251. if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
  252. return true;
  253. } else {
  254. return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
  255. }
  256. }
  257. }
  258. }
  259. // -->
  260. </script>";
  261. if ($origin != 'learnpath') {
  262. //so we are not in learnpath tool
  263. Display::display_header($nameTools,"Exercise");
  264. } else {
  265. if (empty($charset)) {
  266. $charset = 'ISO-8859-15';
  267. }
  268. header('Content-Type: text/html; charset='. $charset);
  269. @$document_language = api_get_language_isocode($language_interface);
  270. if(empty($document_language))
  271. {
  272. //if there was no valid iso-code, use the english one
  273. $document_language = 'en';
  274. }
  275. /*
  276. * HTML HEADER
  277. */
  278. ?>
  279. <!DOCTYPE html
  280. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  281. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  282. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $document_language; ?>" lang="<?php echo $document_language; ?>">
  283. <head>
  284. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" />
  285. </head>
  286. <body>
  287. <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css'; ?>" />
  288. <?php
  289. }
  290. if ($objExercise->results_disabled) {
  291. ob_start();
  292. }
  293. /*
  294. FUNCTIONS
  295. */
  296. function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect)
  297. {
  298. ?>
  299. <tr>
  300. <td width="5%" align="center">
  301. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $studentChoice?'_on':'_off'; ?>.gif"
  302. border="0" alt="" />
  303. </td>
  304. <td width="5%" align="center">
  305. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif"
  306. border="0" alt=" " />
  307. </td>
  308. <td width="45%" style="border-bottom: 1px solid #4171B5;">
  309. <?php
  310. $answer=api_parse_tex($answer);
  311. echo $answer;
  312. ?>
  313. </td>
  314. <td width="45%" style="border-bottom: 1px solid #4171B5;">
  315. <?php
  316. $answerComment=api_parse_tex($answerComment);
  317. if($studentChoice)
  318. {
  319. if(!$answerCorrect)
  320. {
  321. echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
  322. }
  323. else{
  324. echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
  325. }
  326. }
  327. else
  328. {
  329. echo '&nbsp;';
  330. }
  331. ?>
  332. </td>
  333. </tr>
  334. <?php
  335. }
  336. function display_fill_in_blanks_answer($answer)
  337. {
  338. ?>
  339. <tr>
  340. <td>
  341. <?php echo Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY); ?>
  342. </td>
  343. </tr>
  344. <?php
  345. }
  346. function display_free_answer($answer)
  347. {
  348. ?>
  349. <tr>
  350. <td width="55%">
  351. <?php echo nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY)); ?>
  352. </td>
  353. <td width="45%">
  354. <?php echo get_lang('notCorrectedYet');?>
  355. </td>
  356. </tr>
  357. <?php
  358. }
  359. function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment)
  360. {
  361. //global $hotspot_colors;
  362. $hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
  363. "#4271B5",
  364. "#FE8E16",
  365. "#3B3B3B",
  366. "#BCD631",
  367. "#D63173",
  368. "#D7D7D7",
  369. "#90AFDD",
  370. "#AF8640",
  371. "#4F9242",
  372. "#F4EB24",
  373. "#ED2024",
  374. "#45C7F0",
  375. "#F7BDE2");
  376. ?>
  377. <tr>
  378. <td valign="top">
  379. <div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]; ?>; display:inline; float:left; margin-top:3px;"></div>
  380. <div style="float:left; padding-left:5px;">
  381. <?php echo $answerId; ?>
  382. </div>
  383. <div style="float:left; padding-left:5px;">
  384. <div style="display:inline; float:left; width:80px;"><?php echo $answer ?></div>
  385. </div>
  386. </td>
  387. <td valign="top">
  388. <?php $my_choice = ($studentChoice)?get_lang('Correct'):get_lang('Fault'); echo $my_choice; ?>
  389. </td>
  390. <td valign="top">
  391. <?php
  392. if ($studentChoice) {
  393. echo '<span style="font-weight: bold; color: #008000;">';
  394. } else {
  395. echo '<span style="font-weight: bold; color: #FF0000;">';
  396. }
  397. echo $answerComment;
  398. echo '</span>';
  399. ?>
  400. </td>
  401. </tr>
  402. <?php
  403. }
  404. /*
  405. DISPLAY AND MAIN PROCESS
  406. */
  407. // I'm in a preview mode as course admin. Display the action menu.
  408. if (api_is_course_admin() && $origin != 'learnpath') {
  409. echo '<div class="actions">';
  410. echo Display::return_icon('quiz.gif', get_lang('GoBackToEx')).'<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.get_lang('GoBackToEx').'</a>';
  411. echo Display::return_icon('edit.gif', get_lang('ModifyExercise')).'<a href="exercise_admin.php?modifyExercise=yes&exerciseId='.$objExercise->id.'">'.get_lang('ModifyExercise').'</a>';
  412. echo '</div>';
  413. }
  414. $exerciseTitle=api_parse_tex($exerciseTitle);
  415. //show exercise title
  416. ?>
  417. <?php if($origin != 'learnpath') {?>
  418. <h3><?php echo $exerciseTitle ?>: <?php echo get_lang("Result"); ?></h3>
  419. <?php echo $exerciseDescription; ?>
  420. <?php } ?>
  421. <form method="get" action="exercice.php">
  422. <input type="hidden" name="origin" value="<?php echo $origin; ?>" />
  423. <input type="hidden" name="learnpath_id" value="<?php echo $learnpath_id; ?>" />
  424. <input type="hidden" name="learnpath_item_id" value="<?php echo $learnpath_item_id; ?>" />
  425. <?php
  426. $i=$totalScore=$totalWeighting=0;
  427. if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
  428. if ($_configuration['tracking_enabled']) {
  429. // Create an empty exercise
  430. if (api_is_allowed_to_session_edit() )
  431. $exeId= create_event_exercice($objExercise->selectId());
  432. }
  433. $counter=0;
  434. // Loop over all question to show results for each of them, one by one
  435. foreach ($questionList as $questionId) {
  436. $counter++;
  437. // gets the student choice for this question
  438. $choice=$exerciseResult[$questionId];
  439. // creates a temporary Question object
  440. $objQuestionTmp = Question :: read($questionId);
  441. // initialize question information
  442. $questionName=$objQuestionTmp->selectTitle();
  443. $questionDescription=$objQuestionTmp->selectDescription();
  444. $questionWeighting=$objQuestionTmp->selectWeighting();
  445. $answerType=$objQuestionTmp->selectType();
  446. $quesId =$objQuestionTmp->selectId(); //added by priya saini
  447. // destruction of the Question object
  448. unset($objQuestionTmp);
  449. // decide how many columns we want to use to show the results of each type
  450. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
  451. $colspan=4;
  452. } elseif($answerType == MATCHING || $answerType == FREE_ANSWER) {
  453. $colspan=2;
  454. } elseif($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) {
  455. $colspan=4;
  456. $rowspan=$nbrAnswers+1;
  457. } else {
  458. $colspan=1;
  459. }
  460. // show titles
  461. if ($origin != 'learnpath') {?>
  462. <table width="100%" border="0" cellpadding="3" cellspacing="2">
  463. <tr bgcolor="#E6E6E6">
  464. <td colspan="<?php echo $colspan; ?>">
  465. <?php echo get_lang("Question").' '.($counter).' : '.$questionName; ?>
  466. </td>
  467. </tr>
  468. <tr>
  469. <td colspan="<?php echo $colspan; ?>">
  470. <i><?php echo $questionDescription; ?></i>
  471. </td>
  472. </tr>
  473. <?php
  474. if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
  475. ?>
  476. <tr>
  477. <td width="5%" valign="top" align="center" nowrap="nowrap">
  478. <i><?php echo get_lang("Choice"); ?></i>
  479. </td>
  480. <td width="5%" align="center" nowrap="nowrap">
  481. <i><?php echo get_lang("ExpectedChoice"); ?></i>
  482. </td>
  483. <td width="45%" valign="top">
  484. <i><?php echo get_lang("Answer"); ?></i>
  485. </td>
  486. <td width="45%" valign="top">
  487. <i><?php echo get_lang("Comment"); ?></i>
  488. </td>
  489. </tr>
  490. <?php
  491. } elseif ($answerType == FILL_IN_BLANKS) {
  492. ?>
  493. <tr>
  494. <td>
  495. <i><?php echo get_lang("Answer"); ?></i>
  496. </td>
  497. </tr>
  498. <?php
  499. } elseif ($answerType == FREE_ANSWER) {
  500. ?>
  501. <tr>
  502. <td width="55%">
  503. <i><?php echo get_lang("Answer"); ?></i>
  504. </td>
  505. <td width="45%" valign="top">
  506. <i><?php echo get_lang("Comment"); ?></i>
  507. </td>
  508. </tr>
  509. <?php
  510. } elseif ($answerType == HOT_SPOT) {
  511. ?>
  512. <tr>
  513. <td valign="top" colspan="2">
  514. <table width="552" border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;">
  515. <tr>
  516. <td width="152" valign="top">
  517. <i><?php echo get_lang("CorrectAnswer"); ?></i><br /><br />
  518. </td>
  519. <td width="100" valign="top">
  520. <i><?php echo get_lang('HotspotHit'); ?></i><br /><br />
  521. </td>
  522. <td width="300" valign="top">
  523. <i><?php echo get_lang("Comment"); ?></i><br /><br />
  524. </td>
  525. </tr>
  526. <?php
  527. } else { //matching type
  528. ?>
  529. <tr>
  530. <td width="50%">
  531. <i><?php echo get_lang("ElementList"); ?></i>
  532. </td>
  533. <td width="50%">
  534. <i><?php echo get_lang("CorrespondsTo"); ?></i>
  535. </td>
  536. </tr>
  537. <?php
  538. }
  539. }
  540. // construction of the Answer object
  541. $objAnswerTmp=new Answer($questionId);
  542. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  543. $questionScore=0;
  544. if ($answerType == FREE_ANSWER) {
  545. $nbrAnswers = 1;
  546. }
  547. // We're inside *one* question. Go through each possible answer for this question
  548. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  549. //select answer of *position*=$answerId
  550. $answer=$objAnswerTmp->selectAnswer($answerId);
  551. $answerComment=$objAnswerTmp->selectComment($answerId);
  552. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  553. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  554. switch ($answerType) {
  555. // for unique answer
  556. case UNIQUE_ANSWER :
  557. // if the student choice is equal to the answer ID
  558. // then give him the corresponding score
  559. // (maybe a negative score, positive score or 0)
  560. // Positive score should only be given when we are going over the right answer
  561. $studentChoice=($choice == $answerId)?1:0;
  562. if($studentChoice) {
  563. $questionScore+=$answerWeighting;
  564. $totalScore+=$answerWeighting;
  565. }
  566. break;
  567. // for multiple answers
  568. case MULTIPLE_ANSWER :
  569. $studentChoice=$choice[$answerId];
  570. if($studentChoice) {
  571. $questionScore+=$answerWeighting;
  572. $totalScore+=$answerWeighting;
  573. }
  574. break;
  575. // for fill in the blanks
  576. case FILL_IN_BLANKS :
  577. // the question is encoded like this
  578. // [A] B [C] D [E] F::10,10,10@1
  579. // number 1 before the "@" means that is a switchable fill in blank question
  580. // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
  581. // means that is a normal fill blank question
  582. // first we explode the "::"
  583. $pre_array = explode('::', $answer);
  584. // is switchable fill blank or not
  585. $last = count($pre_array)-1;
  586. $is_set_switchable = explode('@', $pre_array[$last]);
  587. $switchable_answer_set=false;
  588. if (isset($is_set_switchable[1]) && $is_set_switchable[1]==1)
  589. {
  590. $switchable_answer_set=true;
  591. }
  592. $answer = '';
  593. for ($k=0; $k<$last; $k++)
  594. {
  595. $answer .= $pre_array[$k];
  596. }
  597. // splits weightings that are joined with a comma
  598. $answerWeighting = explode(',',$is_set_switchable[0]);
  599. // we save the answer because it will be modified
  600. $temp=$answer;
  601. // TeX parsing
  602. // 1. find everything between the [tex] and [/tex] tags
  603. $startlocations=api_strpos($temp,'[tex]');
  604. $endlocations=api_strpos($temp,'[/tex]');
  605. if($startlocations !== false && $endlocations !== false)
  606. {
  607. $texstring=api_substr($temp,$startlocations,$endlocations-$startlocations+6);
  608. // 2. replace this by {texcode}
  609. $temp=str_replace($texstring,'{texcode}',$temp);
  610. }
  611. $answer='';
  612. $j=0;
  613. //initialise answer tags
  614. $user_tags=array();
  615. $correct_tags=array();
  616. $real_text=array();
  617. // the loop will stop at the end of the text
  618. while(1)
  619. {
  620. // quits the loop if there are no more blanks (detect '[')
  621. if(($pos = api_strpos($temp,'[')) === false)
  622. {
  623. // adds the end of the textsolution
  624. $answer=$temp;
  625. // TeX parsing - replacement of texcode tags
  626. $texstring = api_parse_tex($texstring);
  627. $answer=str_replace("{texcode}",$texstring,$answer);
  628. $real_text[] = $answer;
  629. break; //no more "blanks", quit the loop
  630. }
  631. // adds the piece of text that is before the blank
  632. //and ends with '[' into a general storage array
  633. $real_text[]=api_substr($temp,0,$pos+1);
  634. $answer.=api_substr($temp,0,$pos+1);
  635. //take the string remaining (after the last "[" we found)
  636. $temp=api_substr($temp,$pos+1);
  637. // quit the loop if there are no more blanks, and update $pos to the position of next ']'
  638. if(($pos = api_strpos($temp,']')) === false)
  639. {
  640. // adds the end of the text
  641. $answer.=$temp;
  642. break;
  643. }
  644. $choice[$j]=trim($choice[$j]);
  645. $user_tags[]=api_strtolower($choice[$j]);
  646. //put the contents of the [] answer tag into correct_tags[]
  647. $correct_tags[]=api_strtolower(api_substr($temp,0,$pos));
  648. $j++;
  649. $temp=api_substr($temp,$pos+1);
  650. //$answer .= ']';
  651. }
  652. $answer='';
  653. $real_correct_tags = $correct_tags;
  654. $chosen_list=array();
  655. for($i=0;$i<count($real_correct_tags);$i++) {
  656. if ($i==0)
  657. {
  658. $answer.=$real_text[0];
  659. }
  660. if (!$switchable_answer_set)
  661. {
  662. if ($correct_tags[$i]==$user_tags[$i])
  663. {
  664. // gives the related weighting to the student
  665. $questionScore+=$answerWeighting[$i];
  666. // increments total score
  667. $totalScore+=$answerWeighting[$i];
  668. // adds the word in green at the end of the string
  669. $answer.=$correct_tags[$i];
  670. }
  671. // else if the word entered by the student IS NOT the same as the one defined by the professor
  672. elseif(!empty($user_tags[$i]))
  673. {
  674. // adds the word in red at the end of the string, and strikes it
  675. $answer.='<font color="red"><s>'.$user_tags[$i].'</s></font>';
  676. }
  677. else
  678. {
  679. // adds a tabulation if no word has been typed by the student
  680. $answer.='&nbsp;&nbsp;&nbsp;';
  681. }
  682. } else {
  683. // switchable fill in the blanks
  684. if (in_array($user_tags[$i],$correct_tags)) {
  685. $chosen_list[]=$user_tags[$i];
  686. $correct_tags=array_diff($correct_tags,$chosen_list);
  687. // gives the related weighting to the student
  688. $questionScore+=$answerWeighting[$i];
  689. // increments total score
  690. $totalScore+=$answerWeighting[$i];
  691. // adds the word in green at the end of the string
  692. $answer.=$user_tags[$i];
  693. } // else if the word entered by the student IS NOT the same as the one defined by the professor
  694. elseif(!empty($user_tags[$i]))
  695. {
  696. // adds the word in red at the end of the string, and strikes it
  697. $answer.='<font color="red"><s>'.$user_tags[$i].'</s></font>';
  698. }
  699. else
  700. {
  701. // adds a tabulation if no word has been typed by the student
  702. $answer.='&nbsp;&nbsp;&nbsp;';
  703. }
  704. }
  705. // adds the correct word, followed by ] to close the blank
  706. $answer.=' / <font color="green"><b>'.$real_correct_tags[$i].'</b></font>]';
  707. if ( isset( $real_text[$i+1] ) ) {
  708. $answer.=$real_text[$i+1];
  709. }
  710. }
  711. break;
  712. // for free answer
  713. case FREE_ANSWER :
  714. $studentChoice=$choice;
  715. if($studentChoice)
  716. {
  717. //Score is at -1 because the question has'nt been corected
  718. $questionScore=-1;
  719. $totalScore+=0;
  720. }
  721. break;
  722. // for matching
  723. case MATCHING :
  724. if($answerCorrect)
  725. {
  726. if($answerCorrect == $choice[$answerId])
  727. {
  728. $questionScore+=$answerWeighting;
  729. $totalScore+=$answerWeighting;
  730. $choice[$answerId]=$matching[$choice[$answerId]];
  731. }
  732. elseif(!$choice[$answerId])
  733. {
  734. $choice[$answerId]='&nbsp;&nbsp;&nbsp;';
  735. }
  736. else
  737. {
  738. $choice[$answerId]='<font color="red"><s>'.$matching[$choice[$answerId]].'</s></font>';
  739. }
  740. }
  741. else
  742. {
  743. $matching[$answerId]=$answer;
  744. }
  745. break;
  746. // for hotspot with no order
  747. case HOT_SPOT :
  748. $studentChoice=$choice[$answerId];
  749. if ($studentChoice) { //the answer was right
  750. $questionScore+=$answerWeighting;
  751. $totalScore+=$answerWeighting;
  752. }
  753. break;
  754. // for hotspot with fixed order
  755. case HOT_SPOT_ORDER :
  756. $studentChoice=$choice['order'][$answerId];
  757. if($studentChoice == $answerId)
  758. {
  759. $questionScore+=$answerWeighting;
  760. $totalScore+=$answerWeighting;
  761. $studentChoice = true;
  762. }
  763. else
  764. {
  765. $studentChoice = false;
  766. }
  767. break;
  768. } // end switch Answertype
  769. //display answers (if not matching type, or if the answer is correct)
  770. if ($answerType != MATCHING || $answerCorrect) {
  771. if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
  772. if ($origin!='learnpath') {
  773. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect);
  774. }
  775. } elseif($answerType == FILL_IN_BLANKS) {
  776. if ($origin!='learnpath') {
  777. display_fill_in_blanks_answer($answer);
  778. }
  779. } elseif($answerType == FREE_ANSWER) {
  780. // to store the details of open questions in an array to be used in mail
  781. $arrques[] = $questionName;
  782. $arrans[] = $choice;
  783. $firstName = $_SESSION['_user']['firstName'];
  784. $lastName = $_SESSION['_user']['lastName'];
  785. $mail = $_SESSION['_user']['mail'];
  786. $coursecode = $_SESSION['_course']['id'];
  787. $to = '';
  788. $teachers = array();
  789. if(api_get_setting('use_session_mode')=='true' && !empty($_SESSION['id_session']))
  790. {
  791. $teachers = CourseManager::get_coach_list_from_course_code($coursecode,$_SESSION['id_session']);
  792. }
  793. else
  794. {
  795. $teachers = CourseManager::get_teacher_list_from_course_code($coursecode);
  796. }
  797. $num = count($teachers);
  798. if($num>1)
  799. {
  800. $to = array();
  801. foreach($teachers as $teacher)
  802. {
  803. $to[] = $teacher['email'];
  804. }
  805. }elseif($num>0){
  806. foreach($teachers as $teacher)
  807. {
  808. $to = $teacher['email'];
  809. }
  810. }else{
  811. //this is a problem (it means that there is no admin for this course)
  812. }
  813. if($origin != 'learnpath') {
  814. display_free_answer($choice);
  815. }
  816. }
  817. elseif($answerType == HOT_SPOT)
  818. {
  819. if ($origin != 'learnpath') {
  820. display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
  821. }
  822. }
  823. elseif($answerType == HOT_SPOT_ORDER)
  824. {
  825. display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment);
  826. }
  827. else
  828. {
  829. if ($origin != 'learnpath') {
  830. ?>
  831. <tr>
  832. <td width="50%">
  833. <?php
  834. $answer=api_parse_tex($answer);
  835. echo $answer; ?>
  836. </td>
  837. <td width="50%">
  838. <?php echo $choice[$answerId]; ?> / <font color="green"><b>
  839. <?php
  840. $matching[$answerCorrect]=api_parse_tex($matching[$answerCorrect]);
  841. echo $matching[$answerCorrect]; ?></b></font>
  842. </td>
  843. </tr>
  844. <?php
  845. }
  846. }
  847. }
  848. } // end for that loops over all answers of the current question
  849. // if answer is hotspot. To the difference of exercise_show.php, we use the results from the session (from_db=0)
  850. // TODO Change this, because it is wrong to show the user some results that haven't been stored in the database yet
  851. if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) {
  852. // We made an extra table for the answers
  853. if($origin != 'learnpath') {
  854. echo "</table></td></tr>"; //echo Security::remove_XSS($questionId);
  855. ?>
  856. <tr>
  857. <td colspan="2">
  858. <i><?php echo get_lang('Hotspot'); ?></i><br /><br />
  859. <object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo Security::remove_XSS($questionId); ?>&exe_id=&from_db=0" width="552" height="352">
  860. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo Security::remove_XSS($questionId); ?>&exe_id=&from_db=0" />
  861. </object>
  862. </td>
  863. </tr>
  864. <?php
  865. }
  866. }
  867. ?>
  868. <?php if($origin != 'learnpath') { ?>
  869. <tr>
  870. <td colspan="<?php echo $colspan; ?>" align="left">
  871. <b>
  872. <?php
  873. if($questionScore==-1){
  874. echo get_lang('Score').": 0 /".float_format($questionWeighting);
  875. } else {
  876. echo get_lang('Score').": ".float_format($questionScore,1)."/".float_format($questionWeighting,1);
  877. }
  878. ?></b><br /><br />
  879. </td>
  880. </tr>
  881. </table>
  882. <?php } ?>
  883. <?php
  884. // destruction of Answer
  885. unset($objAnswerTmp);
  886. $i++;
  887. $totalWeighting+=$questionWeighting;
  888. //added by priya saini
  889. if($_configuration['tracking_enabled']) {
  890. if(empty($choice)){
  891. $choice = 0;
  892. }
  893. if ($answerType==MULTIPLE_ANSWER ) {
  894. if ($choice != 0) {
  895. $reply = array_keys($choice);
  896. for ($i=0;$i<sizeof($reply);$i++) {
  897. $ans = $reply[$i];
  898. exercise_attempt($questionScore,$ans,$quesId,$exeId,$i);
  899. }
  900. } else {
  901. exercise_attempt($questionScore, 0 ,$quesId,$exeId,0);
  902. }
  903. } elseif ($answerType==MATCHING) {
  904. $j=sizeof($matching)+1;
  905. for ($i=0;$i<sizeof($choice);$i++,$j++) {
  906. $val = $choice[$j];
  907. if (preg_match_all ('#<font color="red"><s>([0-9a-z ]*)</s></font>#', $val, $arr1))
  908. $val = $arr1[1][0];
  909. $val=strip_tags($val);
  910. $sql = "SELECT position from $table_ans where question_id='".Database::escape_string($questionId)."' and answer='".Database::escape_string($val)."' AND correct=0";
  911. $res = Database::query($sql, __FILE__, __LINE__);
  912. if (Database::num_rows($res)>0) {
  913. $answer = Database::result($res,0,"position");
  914. } else {
  915. $answer = 0;
  916. }
  917. exercise_attempt($questionScore,$answer,$quesId,$exeId,$j);
  918. }
  919. }
  920. elseif ($answerType==FREE_ANSWER) {
  921. $answer = $choice;
  922. exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  923. }
  924. elseif ($answerType==UNIQUE_ANSWER) {
  925. // exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  926. // In fact, we are not storing the results by answer ID, but by *position*, which is stored in $choice
  927. exercise_attempt($questionScore,$choice,$quesId,$exeId,0);
  928. } elseif ($answerType == HOT_SPOT) {
  929. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
  930. if (is_array($exerciseResultCoordinates[$quesId])) {
  931. foreach($exerciseResultCoordinates[$quesId] as $idx => $val) {
  932. exercise_attempt_hotspot($exeId,$quesId,$idx,$choice[$idx],$val);
  933. }
  934. }
  935. } else {
  936. exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  937. }
  938. }
  939. } // end huge foreach() block that loops over all questions
  940. ?>
  941. <?php if($origin != 'learnpath') { ?>
  942. <table width="100%" border="0" cellpadding="3" cellspacing="2">
  943. <tr>
  944. <td>
  945. <b>
  946. <?php echo get_lang('YourTotalScore')." ";
  947. if ($dsp_percent == true) {
  948. echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
  949. } else {
  950. echo float_format($totalScore,1)."/".float_format($totalWeighting,1);
  951. }
  952. ?>
  953. </b>
  954. </td>
  955. </tr>
  956. <tr>
  957. <td>
  958. <br />
  959. <button type="submit" class="save"><?php echo get_lang('Finish');?></button>
  960. </td>
  961. </tr>
  962. </table>
  963. <?php } ?>
  964. </form>
  965. <br /><br />
  966. <?php
  967. if ($origin == 'learnpath') {
  968. //Display::display_normal_message(get_lang('ExerciseFinished'));
  969. $lp_mode = $_SESSION['lp_mode'];
  970. $url = '../newscorm/lp_controller.php?cidReq='.api_get_course_id().'&action=view&lp_id='.$learnpath_id.'&lp_item_id='.$learnpath_item_id.'&exeId='.$exeId.'&fb_type='.$feedback_type;
  971. $href = ($lp_mode == 'fullscreen')?' window.opener.location.href="'.$url.'" ':' top.location.href="'.$url.'" ';
  972. echo '<script language="javascript" type="text/javascript">'.$href.'</script>'."\n";
  973. }
  974. /*
  975. ==============================================================================
  976. Tracking of results
  977. ==============================================================================
  978. */
  979. if ($_configuration['tracking_enabled']) {
  980. // Updates the empty exercise
  981. $safe_lp_id = $learnpath_id==''?0:(int)$learnpath_id;
  982. $safe_lp_item_id = $learnpath_item_id==''?0:(int)$learnpath_item_id;
  983. $quizDuration = (!empty($_SESSION['quizStartTime']) ? time() - $_SESSION['quizStartTime'] : 0);
  984. if (api_is_allowed_to_session_edit() )
  985. update_event_exercice($exeId, $objExercise->selectId(),$totalScore,$totalWeighting,api_get_session_id(),$safe_lp_id,$safe_lp_item_id,$quizDuration);
  986. }
  987. if($objExercise->results_disabled) {
  988. ob_end_clean();
  989. if ($origin != 'learnpath') {
  990. Display :: display_normal_message(get_lang('ExerciseFinished').'<br /><a href="exercice.php" />'.get_lang('Back').'</a>',false);
  991. } else {
  992. Display :: display_normal_message(get_lang('ExerciseFinished').'<br /><br />',false);
  993. }
  994. }
  995. if ($origin != 'learnpath') {
  996. //we are not in learnpath tool
  997. Display::display_footer();
  998. } else {
  999. //record the results in the learning path, using the SCORM interface (API)
  1000. echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$totalScore.','.$totalWeighting.');</script>'."\n";
  1001. echo '</body></html>';
  1002. }
  1003. if(count($arrques)>0) {
  1004. $mycharset = api_get_setting('platform_charset');
  1005. $msg = '<html><head>
  1006. <link rel="stylesheet" href="'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css" type="text/css">
  1007. <meta content="text/html; charset='.$mycharset.'" http-equiv="content-type">';
  1008. $msg .= '</head>
  1009. <body><br />
  1010. <p>'.get_lang('OpenQuestionsAttempted').' :
  1011. </p>
  1012. <p>'.get_lang('AttemptDetails').' : ><br />
  1013. </p>
  1014. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
  1015. <tr>
  1016. <td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
  1017. <td width="469" valign="top"><h2>#course#</h2></td>
  1018. </tr>
  1019. <tr>
  1020. <td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
  1021. <td width="469" valign="top" class="outerframe">#exercise#</td>
  1022. </tr>
  1023. <tr>
  1024. <td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
  1025. '.(api_is_western_name_order() ? '<td valign="top" >#firstName# #lastName#</td>' : '<td valign="top" >#lastName# #firstName#</td>').'
  1026. </tr>
  1027. <tr>
  1028. <td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
  1029. <td valign="top"> #mail#</td>
  1030. </tr></table>
  1031. <p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
  1032. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
  1033. for($i=0;$i<sizeof($arrques);$i++) {
  1034. $msg.='
  1035. <tr>
  1036. <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>
  1037. <td width="473" valign="top" bgcolor="#F3F3F3"><span class="style16"> #questionName#</span></td>
  1038. </tr>
  1039. <tr>
  1040. <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Answer').' </span></td>
  1041. <td valign="top" bgcolor="#F3F3F3"><span class="style16"> #answer#</span></td>
  1042. </tr>';
  1043. $msg1= str_replace("#exercise#",$exerciseTitle,$msg);
  1044. $msg= str_replace("#firstName#",$firstName,$msg1);
  1045. $msg1= str_replace("#lastName#",$lastName,$msg);
  1046. $msg= str_replace("#mail#",$mail,$msg1);
  1047. $msg1= str_replace("#questionName#",$arrques[$i],$msg);
  1048. $msg= str_replace("#answer#",$arrans[$i],$msg1);
  1049. $msg1= str_replace("#i#",$i,$msg);
  1050. $msg= str_replace("#course#",$courseName,$msg1);
  1051. }
  1052. $msg.='</table><br>
  1053. <span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
  1054. <a href="#url#">#url#</a></span></body></html>';
  1055. $msg1= str_replace("#url#",$url,$msg);
  1056. $mail_content = $msg1;
  1057. $student_name = api_get_person_name($_SESSION['_user']['firstName'], $_SESSION['_user']['lastName']);
  1058. $subject = get_lang('OpenQuestionsAttempted');
  1059. $from = api_get_setting('noreply_email_address');
  1060. if($from == '') {
  1061. if(isset($_SESSION['id_session']) && $_SESSION['id_session'] != ''){
  1062. $sql = 'SELECT user.email,user.lastname,user.firstname FROM '.TABLE_MAIN_SESSION.' as session, '.TABLE_MAIN_USER.' as user
  1063. WHERE session.id_coach = user.user_id
  1064. AND session.id = "'.Database::escape_string($_SESSION['id_session']).'"
  1065. ';
  1066. $result=Database::query($sql,__FILE__,__LINE__);
  1067. $from = Database::result($result,0,'email');
  1068. $from_name = api_get_person_name(Database::result($result,0,'firstname'), Database::result($result,0,'lastname'), null, PERSON_NAME_EMAIL_ADDRESS);
  1069. } else {
  1070. $array = explode(' ',$_SESSION['_course']['titular']);
  1071. $firstname = $array[1];
  1072. $lastname = $array[0];
  1073. $sql = 'SELECT email,lastname,firstname FROM '.TABLE_MAIN_USER.'
  1074. WHERE firstname = "'.Database::escape_string($firstname).'"
  1075. AND lastname = "'.Database::escape_string($lastname).'"
  1076. ';
  1077. $result=Database::query($sql,__FILE__,__LINE__);
  1078. $from = Database::result($result,0,'email');
  1079. $from_name = api_get_person_name(Database::result($result,0,'firstname'), Database::result($result,0,'lastname'), null, PERSON_NAME_EMAIL_ADDRESS);
  1080. }
  1081. }
  1082. api_mail_html($student_name, $to, $subject, $mail_content, $from_name, $from, array('encoding'=>$mycharset,'charset'=>$mycharset));
  1083. }
  1084. ?>