exercise_result.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  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(api_sql_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 = Database::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. $exeId= create_event_exercice($objExercise->selectId());
  431. }
  432. $counter=0;
  433. // Loop over all question to show results for each of them, one by one
  434. foreach ($questionList as $questionId) {
  435. $counter++;
  436. // gets the student choice for this question
  437. $choice=$exerciseResult[$questionId];
  438. // creates a temporary Question object
  439. $objQuestionTmp = Question :: read($questionId);
  440. // initialize question information
  441. $questionName=$objQuestionTmp->selectTitle();
  442. $questionDescription=$objQuestionTmp->selectDescription();
  443. $questionWeighting=$objQuestionTmp->selectWeighting();
  444. $answerType=$objQuestionTmp->selectType();
  445. $quesId =$objQuestionTmp->selectId(); //added by priya saini
  446. // destruction of the Question object
  447. unset($objQuestionTmp);
  448. // decide how many columns we want to use to show the results of each type
  449. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
  450. $colspan=4;
  451. } elseif($answerType == MATCHING || $answerType == FREE_ANSWER) {
  452. $colspan=2;
  453. } elseif($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) {
  454. $colspan=4;
  455. $rowspan=$nbrAnswers+1;
  456. } else {
  457. $colspan=1;
  458. }
  459. // show titles
  460. if ($origin != 'learnpath') {?>
  461. <table width="100%" border="0" cellpadding="3" cellspacing="2">
  462. <tr bgcolor="#E6E6E6">
  463. <td colspan="<?php echo $colspan; ?>">
  464. <?php echo get_lang("Question").' '.($counter).' : '.$questionName; ?>
  465. </td>
  466. </tr>
  467. <tr>
  468. <td colspan="<?php echo $colspan; ?>">
  469. <i><?php echo $questionDescription; ?></i>
  470. </td>
  471. </tr>
  472. <?php
  473. if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
  474. ?>
  475. <tr>
  476. <td width="5%" valign="top" align="center" nowrap="nowrap">
  477. <i><?php echo get_lang("Choice"); ?></i>
  478. </td>
  479. <td width="5%" align="center" nowrap="nowrap">
  480. <i><?php echo get_lang("ExpectedChoice"); ?></i>
  481. </td>
  482. <td width="45%" valign="top">
  483. <i><?php echo get_lang("Answer"); ?></i>
  484. </td>
  485. <td width="45%" valign="top">
  486. <i><?php echo get_lang("Comment"); ?></i>
  487. </td>
  488. </tr>
  489. <?php
  490. } elseif ($answerType == FILL_IN_BLANKS) {
  491. ?>
  492. <tr>
  493. <td>
  494. <i><?php echo get_lang("Answer"); ?></i>
  495. </td>
  496. </tr>
  497. <?php
  498. } elseif ($answerType == FREE_ANSWER) {
  499. ?>
  500. <tr>
  501. <td width="55%">
  502. <i><?php echo get_lang("Answer"); ?></i>
  503. </td>
  504. <td width="45%" valign="top">
  505. <i><?php echo get_lang("Comment"); ?></i>
  506. </td>
  507. </tr>
  508. <?php
  509. } elseif ($answerType == HOT_SPOT) {
  510. ?>
  511. <tr>
  512. <td valign="top" colspan="2">
  513. <table width="552" border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;">
  514. <tr>
  515. <td width="152" valign="top">
  516. <i><?php echo get_lang("CorrectAnswer"); ?></i><br /><br />
  517. </td>
  518. <td width="100" valign="top">
  519. <i><?php echo get_lang('HotspotHit'); ?></i><br /><br />
  520. </td>
  521. <td width="300" valign="top">
  522. <i><?php echo get_lang("Comment"); ?></i><br /><br />
  523. </td>
  524. </tr>
  525. <?php
  526. } else { //matching type
  527. ?>
  528. <tr>
  529. <td width="50%">
  530. <i><?php echo get_lang("ElementList"); ?></i>
  531. </td>
  532. <td width="50%">
  533. <i><?php echo get_lang("CorrespondsTo"); ?></i>
  534. </td>
  535. </tr>
  536. <?php
  537. }
  538. }
  539. // construction of the Answer object
  540. $objAnswerTmp=new Answer($questionId);
  541. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  542. $questionScore=0;
  543. if ($answerType == FREE_ANSWER) {
  544. $nbrAnswers = 1;
  545. }
  546. // We're inside *one* question. Go through each possible answer for this question
  547. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  548. //select answer of *position*=$answerId
  549. $answer=$objAnswerTmp->selectAnswer($answerId);
  550. $answerComment=$objAnswerTmp->selectComment($answerId);
  551. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  552. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  553. switch ($answerType) {
  554. // for unique answer
  555. case UNIQUE_ANSWER :
  556. // if the student choice is equal to the answer ID
  557. // then give him the corresponding score
  558. // (maybe a negative score, positive score or 0)
  559. // Positive score should only be given when we are going over the right answer
  560. $studentChoice=($choice == $answerId)?1:0;
  561. if($studentChoice) {
  562. $questionScore+=$answerWeighting;
  563. $totalScore+=$answerWeighting;
  564. }
  565. break;
  566. // for multiple answers
  567. case MULTIPLE_ANSWER :
  568. $studentChoice=$choice[$answerId];
  569. if($studentChoice) {
  570. $questionScore+=$answerWeighting;
  571. $totalScore+=$answerWeighting;
  572. }
  573. break;
  574. // for fill in the blanks
  575. case FILL_IN_BLANKS :
  576. // the question is encoded like this
  577. // [A] B [C] D [E] F::10,10,10@1
  578. // number 1 before the "@" means that is a switchable fill in blank question
  579. // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
  580. // means that is a normal fill blank question
  581. // first we explode the "::"
  582. $pre_array = explode('::', $answer);
  583. // is switchable fill blank or not
  584. $last = count($pre_array)-1;
  585. $is_set_switchable = explode('@', $pre_array[$last]);
  586. $switchable_answer_set=false;
  587. if (isset($is_set_switchable[1]) && $is_set_switchable[1]==1)
  588. {
  589. $switchable_answer_set=true;
  590. }
  591. $answer = '';
  592. for ($k=0; $k<$last; $k++)
  593. {
  594. $answer .= $pre_array[$k];
  595. }
  596. // splits weightings that are joined with a comma
  597. $answerWeighting = explode(',',$is_set_switchable[0]);
  598. // we save the answer because it will be modified
  599. $temp=$answer;
  600. // TeX parsing
  601. // 1. find everything between the [tex] and [/tex] tags
  602. $startlocations=api_strpos($temp,'[tex]');
  603. $endlocations=api_strpos($temp,'[/tex]');
  604. if($startlocations !== false && $endlocations !== false)
  605. {
  606. $texstring=api_substr($temp,$startlocations,$endlocations-$startlocations+6);
  607. // 2. replace this by {texcode}
  608. $temp=str_replace($texstring,'{texcode}',$temp);
  609. }
  610. $answer='';
  611. $j=0;
  612. //initialise answer tags
  613. $user_tags=array();
  614. $correct_tags=array();
  615. $real_text=array();
  616. // the loop will stop at the end of the text
  617. while(1)
  618. {
  619. // quits the loop if there are no more blanks (detect '[')
  620. if(($pos = api_strpos($temp,'[')) === false)
  621. {
  622. // adds the end of the textsolution
  623. $answer=$temp;
  624. // TeX parsing - replacement of texcode tags
  625. $texstring = api_parse_tex($texstring);
  626. $answer=str_replace("{texcode}",$texstring,$answer);
  627. $real_text[] = $answer;
  628. break; //no more "blanks", quit the loop
  629. }
  630. // adds the piece of text that is before the blank
  631. //and ends with '[' into a general storage array
  632. $real_text[]=api_substr($temp,0,$pos+1);
  633. $answer.=api_substr($temp,0,$pos+1);
  634. //take the string remaining (after the last "[" we found)
  635. $temp=api_substr($temp,$pos+1);
  636. // quit the loop if there are no more blanks, and update $pos to the position of next ']'
  637. if(($pos = api_strpos($temp,']')) === false)
  638. {
  639. // adds the end of the text
  640. $answer.=$temp;
  641. break;
  642. }
  643. $choice[$j]=trim($choice[$j]);
  644. $user_tags[]=api_strtolower($choice[$j]);
  645. //put the contents of the [] answer tag into correct_tags[]
  646. $correct_tags[]=api_strtolower(api_substr($temp,0,$pos));
  647. $j++;
  648. $temp=api_substr($temp,$pos+1);
  649. //$answer .= ']';
  650. }
  651. $answer='';
  652. $real_correct_tags = $correct_tags;
  653. $chosen_list=array();
  654. for($i=0;$i<count($real_correct_tags);$i++) {
  655. if ($i==0)
  656. {
  657. $answer.=$real_text[0];
  658. }
  659. if (!$switchable_answer_set)
  660. {
  661. if ($correct_tags[$i]==$user_tags[$i])
  662. {
  663. // gives the related weighting to the student
  664. $questionScore+=$answerWeighting[$i];
  665. // increments total score
  666. $totalScore+=$answerWeighting[$i];
  667. // adds the word in green at the end of the string
  668. $answer.=$correct_tags[$i];
  669. }
  670. // else if the word entered by the student IS NOT the same as the one defined by the professor
  671. elseif(!empty($user_tags[$i]))
  672. {
  673. // adds the word in red at the end of the string, and strikes it
  674. $answer.='<font color="red"><s>'.$user_tags[$i].'</s></font>';
  675. }
  676. else
  677. {
  678. // adds a tabulation if no word has been typed by the student
  679. $answer.='&nbsp;&nbsp;&nbsp;';
  680. }
  681. } else {
  682. // switchable fill in the blanks
  683. if (in_array($user_tags[$i],$correct_tags)) {
  684. $chosen_list[]=$user_tags[$i];
  685. $correct_tags=array_diff($correct_tags,$chosen_list);
  686. // gives the related weighting to the student
  687. $questionScore+=$answerWeighting[$i];
  688. // increments total score
  689. $totalScore+=$answerWeighting[$i];
  690. // adds the word in green at the end of the string
  691. $answer.=$user_tags[$i];
  692. } // else if the word entered by the student IS NOT the same as the one defined by the professor
  693. elseif(!empty($user_tags[$i]))
  694. {
  695. // adds the word in red at the end of the string, and strikes it
  696. $answer.='<font color="red"><s>'.$user_tags[$i].'</s></font>';
  697. }
  698. else
  699. {
  700. // adds a tabulation if no word has been typed by the student
  701. $answer.='&nbsp;&nbsp;&nbsp;';
  702. }
  703. }
  704. // adds the correct word, followed by ] to close the blank
  705. $answer.=' / <font color="green"><b>'.$real_correct_tags[$i].'</b></font>]';
  706. if ( isset( $real_text[$i+1] ) ) {
  707. $answer.=$real_text[$i+1];
  708. }
  709. }
  710. break;
  711. // for free answer
  712. case FREE_ANSWER :
  713. $studentChoice=$choice;
  714. if($studentChoice)
  715. {
  716. //Score is at -1 because the question has'nt been corected
  717. $questionScore=-1;
  718. $totalScore+=0;
  719. }
  720. break;
  721. // for matching
  722. case MATCHING :
  723. if($answerCorrect)
  724. {
  725. if($answerCorrect == $choice[$answerId])
  726. {
  727. $questionScore+=$answerWeighting;
  728. $totalScore+=$answerWeighting;
  729. $choice[$answerId]=$matching[$choice[$answerId]];
  730. }
  731. elseif(!$choice[$answerId])
  732. {
  733. $choice[$answerId]='&nbsp;&nbsp;&nbsp;';
  734. }
  735. else
  736. {
  737. $choice[$answerId]='<font color="red"><s>'.$matching[$choice[$answerId]].'</s></font>';
  738. }
  739. }
  740. else
  741. {
  742. $matching[$answerId]=$answer;
  743. }
  744. break;
  745. // for hotspot with no order
  746. case HOT_SPOT :
  747. $studentChoice=$choice[$answerId];
  748. if ($studentChoice) { //the answer was right
  749. $questionScore+=$answerWeighting;
  750. $totalScore+=$answerWeighting;
  751. }
  752. break;
  753. // for hotspot with fixed order
  754. case HOT_SPOT_ORDER :
  755. $studentChoice=$choice['order'][$answerId];
  756. if($studentChoice == $answerId)
  757. {
  758. $questionScore+=$answerWeighting;
  759. $totalScore+=$answerWeighting;
  760. $studentChoice = true;
  761. }
  762. else
  763. {
  764. $studentChoice = false;
  765. }
  766. break;
  767. } // end switch Answertype
  768. //display answers (if not matching type, or if the answer is correct)
  769. if ($answerType != MATCHING || $answerCorrect) {
  770. if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
  771. if ($origin!='learnpath') {
  772. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect);
  773. }
  774. } elseif($answerType == FILL_IN_BLANKS) {
  775. if ($origin!='learnpath') {
  776. display_fill_in_blanks_answer($answer);
  777. }
  778. } elseif($answerType == FREE_ANSWER) {
  779. // to store the details of open questions in an array to be used in mail
  780. $arrques[] = $questionName;
  781. $arrans[] = $choice;
  782. $firstName = $_SESSION['_user']['firstName'];
  783. $lastName = $_SESSION['_user']['lastName'];
  784. $mail = $_SESSION['_user']['mail'];
  785. $coursecode = $_SESSION['_course']['id'];
  786. $to = '';
  787. $teachers = array();
  788. if(api_get_setting('use_session_mode')=='true' && !empty($_SESSION['id_session']))
  789. {
  790. $teachers = CourseManager::get_coach_list_from_course_code($coursecode,$_SESSION['id_session']);
  791. }
  792. else
  793. {
  794. $teachers = CourseManager::get_teacher_list_from_course_code($coursecode);
  795. }
  796. $num = count($teachers);
  797. if($num>1)
  798. {
  799. $to = array();
  800. foreach($teachers as $teacher)
  801. {
  802. $to[] = $teacher['email'];
  803. }
  804. }elseif($num>0){
  805. foreach($teachers as $teacher)
  806. {
  807. $to = $teacher['email'];
  808. }
  809. }else{
  810. //this is a problem (it means that there is no admin for this course)
  811. }
  812. if($origin != 'learnpath') {
  813. display_free_answer($choice);
  814. }
  815. }
  816. elseif($answerType == HOT_SPOT)
  817. {
  818. if ($origin != 'learnpath') {
  819. display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
  820. }
  821. }
  822. elseif($answerType == HOT_SPOT_ORDER)
  823. {
  824. display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment);
  825. }
  826. else
  827. {
  828. if ($origin != 'learnpath') {
  829. ?>
  830. <tr>
  831. <td width="50%">
  832. <?php
  833. $answer=api_parse_tex($answer);
  834. echo $answer; ?>
  835. </td>
  836. <td width="50%">
  837. <?php echo $choice[$answerId]; ?> / <font color="green"><b>
  838. <?php
  839. $matching[$answerCorrect]=api_parse_tex($matching[$answerCorrect]);
  840. echo $matching[$answerCorrect]; ?></b></font>
  841. </td>
  842. </tr>
  843. <?php
  844. }
  845. }
  846. }
  847. } // end for that loops over all answers of the current question
  848. // if answer is hotspot. To the difference of exercise_show.php, we use the results from the session (from_db=0)
  849. // TODO Change this, because it is wrong to show the user some results that haven't been stored in the database yet
  850. if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) {
  851. // We made an extra table for the answers
  852. if($origin != 'learnpath') {
  853. echo "</table></td></tr>"; //echo Security::remove_XSS($questionId);
  854. ?>
  855. <tr>
  856. <td colspan="2">
  857. <i><?php echo get_lang('Hotspot'); ?></i><br /><br />
  858. <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">
  859. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo Security::remove_XSS($questionId); ?>&exe_id=&from_db=0" />
  860. </object>
  861. </td>
  862. </tr>
  863. <?php
  864. }
  865. }
  866. ?>
  867. <?php if($origin != 'learnpath') { ?>
  868. <tr>
  869. <td colspan="<?php echo $colspan; ?>" align="left">
  870. <b>
  871. <?php
  872. if($questionScore==-1){
  873. echo get_lang('Score').": 0 /".float_format($questionWeighting);
  874. } else {
  875. echo get_lang('Score').": ".float_format($questionScore,1)."/".float_format($questionWeighting,1);
  876. }
  877. ?></b><br /><br />
  878. </td>
  879. </tr>
  880. </table>
  881. <?php } ?>
  882. <?php
  883. // destruction of Answer
  884. unset($objAnswerTmp);
  885. $i++;
  886. $totalWeighting+=$questionWeighting;
  887. //added by priya saini
  888. if($_configuration['tracking_enabled']) {
  889. if(empty($choice)){
  890. $choice = 0;
  891. }
  892. if ($answerType==MULTIPLE_ANSWER ) {
  893. if ($choice != 0) {
  894. $reply = array_keys($choice);
  895. for ($i=0;$i<sizeof($reply);$i++) {
  896. $ans = $reply[$i];
  897. exercise_attempt($questionScore,$ans,$quesId,$exeId,$i);
  898. }
  899. } else {
  900. exercise_attempt($questionScore, 0 ,$quesId,$exeId,0);
  901. }
  902. } elseif ($answerType==MATCHING) {
  903. $j=sizeof($matching)+1;
  904. for ($i=0;$i<sizeof($choice);$i++,$j++) {
  905. $val = $choice[$j];
  906. if (preg_match_all ('#<font color="red"><s>([0-9a-z ]*)</s></font>#', $val, $arr1))
  907. $val = $arr1[1][0];
  908. $val=strip_tags($val);
  909. $sql = "SELECT position from $table_ans where question_id='".Database::escape_string($questionId)."' and answer='".Database::escape_string($val)."' AND correct=0";
  910. $res = api_sql_query($sql, __FILE__, __LINE__);
  911. if (Database::num_rows($res)>0) {
  912. $answer = Database::result($res,0,"position");
  913. } else {
  914. $answer = 0;
  915. }
  916. exercise_attempt($questionScore,$answer,$quesId,$exeId,$j);
  917. }
  918. }
  919. elseif ($answerType==FREE_ANSWER) {
  920. $answer = $choice;
  921. exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  922. }
  923. elseif ($answerType==UNIQUE_ANSWER) {
  924. // exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  925. // In fact, we are not storing the results by answer ID, but by *position*, which is stored in $choice
  926. exercise_attempt($questionScore,$choice,$quesId,$exeId,0);
  927. } elseif ($answerType == HOT_SPOT) {
  928. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
  929. if (is_array($exerciseResultCoordinates[$quesId])) {
  930. foreach($exerciseResultCoordinates[$quesId] as $idx => $val) {
  931. exercise_attempt_hotspot($exeId,$quesId,$idx,$choice[$idx],$val);
  932. }
  933. }
  934. } else {
  935. exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  936. }
  937. }
  938. } // end huge foreach() block that loops over all questions
  939. ?>
  940. <?php if($origin != 'learnpath') { ?>
  941. <table width="100%" border="0" cellpadding="3" cellspacing="2">
  942. <tr>
  943. <td>
  944. <b>
  945. <?php echo get_lang('YourTotalScore')." ";
  946. if ($dsp_percent == true) {
  947. echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
  948. } else {
  949. echo float_format($totalScore,1)."/".float_format($totalWeighting,1);
  950. }
  951. ?>
  952. </b>
  953. </td>
  954. </tr>
  955. <tr>
  956. <td>
  957. <br />
  958. <button type="submit" class="save"><?php echo get_lang('Finish');?></button>
  959. </td>
  960. </tr>
  961. </table>
  962. <?php } ?>
  963. </form>
  964. <br /><br />
  965. <?php
  966. if ($origin == 'learnpath') {
  967. //Display::display_normal_message(get_lang('ExerciseFinished'));
  968. $lp_mode = $_SESSION['lp_mode'];
  969. $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;
  970. $href = ($lp_mode == 'fullscreen')?' window.opener.location.href="'.$url.'" ':' top.location.href="'.$url.'" ';
  971. echo '<script language="javascript" type="text/javascript">'.$href.'</script>'."\n";
  972. }
  973. /*
  974. ==============================================================================
  975. Tracking of results
  976. ==============================================================================
  977. */
  978. if ($_configuration['tracking_enabled']) {
  979. // Updates the empty exercise
  980. $safe_lp_id = $learnpath_id==''?0:(int)$learnpath_id;
  981. $safe_lp_item_id = $learnpath_item_id==''?0:(int)$learnpath_item_id;
  982. $quizDuration = (!empty($_SESSION['quizStartTime']) ? time() - $_SESSION['quizStartTime'] : 0);
  983. update_event_exercice($exeId, $objExercise->selectId(),$totalScore,$totalWeighting,api_get_session_id(),$safe_lp_id,$safe_lp_item_id,$quizDuration);
  984. }
  985. if($objExercise->results_disabled) {
  986. ob_end_clean();
  987. if ($origin != 'learnpath') {
  988. Display :: display_normal_message(get_lang('ExerciseFinished').'<br /><a href="exercice.php" />'.get_lang('Back').'</a>',false);
  989. } else {
  990. Display :: display_normal_message(get_lang('ExerciseFinished').'<br /><br />',false);
  991. }
  992. }
  993. if ($origin != 'learnpath') {
  994. //we are not in learnpath tool
  995. Display::display_footer();
  996. } else {
  997. //record the results in the learning path, using the SCORM interface (API)
  998. echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$totalScore.','.$totalWeighting.');</script>'."\n";
  999. echo '</body></html>';
  1000. }
  1001. if(count($arrques)>0) {
  1002. $mycharset = api_get_setting('platform_charset');
  1003. $msg = '<html><head>
  1004. <link rel="stylesheet" href="'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css" type="text/css">
  1005. <meta content="text/html; charset='.$mycharset.'" http-equiv="content-type">';
  1006. $msg .= '</head>
  1007. <body><br />
  1008. <p>'.get_lang('OpenQuestionsAttempted').' :
  1009. </p>
  1010. <p>'.get_lang('AttemptDetails').' : ><br />
  1011. </p>
  1012. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
  1013. <tr>
  1014. <td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
  1015. <td width="469" valign="top"><h2>#course#</h2></td>
  1016. </tr>
  1017. <tr>
  1018. <td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
  1019. <td width="469" valign="top" class="outerframe">#exercise#</td>
  1020. </tr>
  1021. <tr>
  1022. <td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
  1023. '.(api_is_western_name_order() ? '<td valign="top" >#firstName# #lastName#</td>' : '<td valign="top" >#lastName# #firstName#</td>').'
  1024. </tr>
  1025. <tr>
  1026. <td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
  1027. <td valign="top"> #mail#</td>
  1028. </tr></table>
  1029. <p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
  1030. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
  1031. for($i=0;$i<sizeof($arrques);$i++) {
  1032. $msg.='
  1033. <tr>
  1034. <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>
  1035. <td width="473" valign="top" bgcolor="#F3F3F3"><span class="style16"> #questionName#</span></td>
  1036. </tr>
  1037. <tr>
  1038. <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Answer').' </span></td>
  1039. <td valign="top" bgcolor="#F3F3F3"><span class="style16"> #answer#</span></td>
  1040. </tr>';
  1041. $msg1= str_replace("#exercise#",$exerciseTitle,$msg);
  1042. $msg= str_replace("#firstName#",$firstName,$msg1);
  1043. $msg1= str_replace("#lastName#",$lastName,$msg);
  1044. $msg= str_replace("#mail#",$mail,$msg1);
  1045. $msg1= str_replace("#questionName#",$arrques[$i],$msg);
  1046. $msg= str_replace("#answer#",$arrans[$i],$msg1);
  1047. $msg1= str_replace("#i#",$i,$msg);
  1048. $msg= str_replace("#course#",$courseName,$msg1);
  1049. }
  1050. $msg.='</table><br>
  1051. <span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
  1052. <a href="#url#">#url#</a></span></body></html>';
  1053. $msg1= str_replace("#url#",$url,$msg);
  1054. $mail_content = $msg1;
  1055. $student_name = api_get_person_name($_SESSION['_user']['firstName'], $_SESSION['_user']['lastName']);
  1056. $subject = get_lang('OpenQuestionsAttempted');
  1057. $from = api_get_setting('noreply_email_address');
  1058. if($from == '') {
  1059. if(isset($_SESSION['id_session']) && $_SESSION['id_session'] != ''){
  1060. $sql = 'SELECT user.email,user.lastname,user.firstname FROM '.TABLE_MAIN_SESSION.' as session, '.TABLE_MAIN_USER.' as user
  1061. WHERE session.id_coach = user.user_id
  1062. AND session.id = "'.Database::escape_string($_SESSION['id_session']).'"
  1063. ';
  1064. $result=api_sql_query($sql,__FILE__,__LINE__);
  1065. $from = Database::result($result,0,'email');
  1066. $from_name = api_get_person_name(Database::result($result,0,'firstname'), Database::result($result,0,'lastname'), null, PERSON_NAME_EMAIL_ADDRESS);
  1067. } else {
  1068. $array = explode(' ',$_SESSION['_course']['titular']);
  1069. $firstname = $array[1];
  1070. $lastname = $array[0];
  1071. $sql = 'SELECT email,lastname,firstname FROM '.TABLE_MAIN_USER.'
  1072. WHERE firstname = "'.Database::escape_string($firstname).'"
  1073. AND lastname = "'.Database::escape_string($lastname).'"
  1074. ';
  1075. $result=api_sql_query($sql,__FILE__,__LINE__);
  1076. $from = Database::result($result,0,'email');
  1077. $from_name = api_get_person_name(Database::result($result,0,'firstname'), Database::result($result,0,'lastname'), null, PERSON_NAME_EMAIL_ADDRESS);
  1078. }
  1079. }
  1080. api_mail_html($student_name, $to, $subject, $mail_content, $from_name, $from, array('encoding'=>$mycharset,'charset'=>$mycharset));
  1081. }
  1082. ?>