exercise_result.php 41 KB

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