exercise_result.php 39 KB

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