exercise_result.php 42 KB

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