1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186 |
- <?php
- /*
- ==============================================================================
- Dokeos - elearning and course management software
- Copyright (c) 2008 Dokeos SPRL
- For a full list of contributors, see "credits.txt".
- The full license can be read in "license.txt".
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- See the GNU General Public License for more details.
- Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
- Mail: info@dokeos.com
- ==============================================================================
- */
- /**
- * Exercise result
- * This script gets informations from the script "exercise_submit.php",
- * through the session, and calculates the score of the student for
- * that exercise.
- * Then it shows the results on the screen.
- * @package dokeos.exercise
- * @author Olivier Brouckaert, main author
- * @author Roan Embrechts, some refactoring
- * @author Julio Montoya Armas switchable fill in blank option added
- * @version $Id: exercise_result.php 17972 2009-01-23 20:11:22Z juliomontoya $
- *
- * @todo split more code up in functions, move functions to library?
- */
- /*
- ==============================================================================
- INIT SECTION
- ==============================================================================
- */
- include('exercise.class.php');
- include('question.class.php');
- include('answer.class.php');
- if($_GET['origin']=='learnpath')
- {
- require_once ('../newscorm/learnpath.class.php');
- require_once ('../newscorm/learnpathItem.class.php');
- require_once ('../newscorm/scorm.class.php');
- require_once ('../newscorm/scormItem.class.php');
- require_once ('../newscorm/aicc.class.php');
- require_once ('../newscorm/aiccItem.class.php');
- }
- /*
- // answer types
- define('UNIQUE_ANSWER', 1);
- define('MULTIPLE_ANSWER', 2);
- define('FILL_IN_BLANKS', 3);
- define('MATCHING', 4);
- define('FREE_ANSWER', 5);
- define('HOT_SPOT', 6);
- define('HOT_SPOT_ORDER', 7);
- */
- global $_cid;
- // name of the language file that needs to be included
- $language_file='exercice';
- include('../inc/global.inc.php');
- $this_section=SECTION_COURSES;
- /* ------------ ACCESS RIGHTS ------------ */
- // notice for unauthorized people.
- api_protect_course_script(true);
- include_once(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
- include_once(api_get_path(LIBRARY_PATH).'mail.lib.inc.php');
- include_once(api_get_path(LIBRARY_PATH).'course.lib.php');
- // Database table definitions
- $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
- $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
- $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
- $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
- $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
- $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
- $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
- $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
- //temp values to move to AWACS
- $dsp_percent = false; //false to display total score as absolute values
- //debug param. 0: no display - 1: debug display
- $debug=0;
- if($debug>0){echo str_repeat(' ',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);}
- // general parameters passed via POST/GET
- if ( empty ( $origin ) ) {
- $origin = $_REQUEST['origin'];
- }
- if ( empty ( $learnpath_id ) ) {
- $learnpath_id = $_REQUEST['learnpath_id'];
- }
- if ( empty ( $learnpath_item_id ) ) {
- $learnpath_item_id = $_REQUEST['learnpath_item_id'];
- }
- if ( empty ( $formSent ) ) {
- $formSent = $_REQUEST['formSent'];
- }
- if ( empty ( $exerciseResult ) ) {
- $exerciseResult = $_SESSION['exerciseResult'];
- }
- if ( empty ( $questionId ) ) {
- $questionId = $_REQUEST['questionId'];
- }
- if ( empty ( $choice ) ) {
- $choice = $_REQUEST['choice'];
- }
- if ( empty ( $questionNum ) ) {
- $questionNum = $_REQUEST['questionNum'];
- }
- if ( empty ( $nbrQuestions ) ) {
- $nbrQuestions = $_REQUEST['nbrQuestions'];
- }
- if ( empty ( $questionList ) ) {
- $questionList = $_SESSION['questionList'];
- }
- if ( empty ( $objExercise ) ) {
- $objExercise = $_SESSION['objExercise'];
- }
- if ( empty ( $exerciseType ) ) {
- $exerciseType = $_REQUEST['exerciseType'];
- }
- $_configuration['live_exercise_tracking'] = false;
- if($_configuration['live_exercise_tracking']) define('ENABLED_LIVE_EXERCISE_TRACKING',1);
- if($_configuration['live_exercise_tracking'] == true && $exerciseType == 1){
- $_configuration['live_exercise_tracking'] = false;
- }
- $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
- $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
- $courseName = $_SESSION['_course']['name'];
- $query = "SELECT user_id FROM $main_admin_table";
- $admin_id = Database::result(api_sql_query($query),0,"user_id");
- $uinfo = api_get_user_info($admin_id);
- $from = $uinfo['mail'];
- $from_name = $uinfo['firstname'].' '.$uinfo['lastname'];
- $str = $_SERVER['REQUEST_URI'];
- $arr = explode('/',$str);
- $url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result';
- //$url = $_SERVER['SERVER_NAME'].'/'.$arr[1].'/';
- // if the above variables are empty or incorrect, stops the script
- if(!is_array($exerciseResult) || !is_array($questionList) || !is_object($objExercise))
- {
- header('Location: exercice.php');
- exit();
- }
- $exerciseTitle=$objExercise->selectTitle();
- $exerciseDescription=$objExercise->selectDescription();
- $exerciseDescription=stripslashes($exerciseDescription);
- $nameTools=get_lang('Exercice');
- $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
- $htmlHeadXtra[] = "<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
- <script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
- <script language=\"JavaScript\" type=\"text/javascript\">
- <!--
- // -----------------------------------------------------------------------------
- // Globals
- // Major version of Flash required
- var requiredMajorVersion = 7;
- // Minor version of Flash required
- var requiredMinorVersion = 0;
- // Minor version of Flash required
- var requiredRevision = 0;
- // the version of javascript supported
- var jsVersion = 1.0;
- // -----------------------------------------------------------------------------
- // -->
- </script>
- <script language=\"VBScript\" type=\"text/vbscript\">
- <!-- // Visual basic helper required to detect Flash Player ActiveX control version information
- Function VBGetSwfVer(i)
- on error resume next
- Dim swControl, swVersion
- swVersion = 0
- set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i))
- if (IsObject(swControl)) then
- swVersion = swControl.GetVariable(\"\$version\")
- end if
- VBGetSwfVer = swVersion
- End Function
- // -->
- </script>
- <script language=\"JavaScript1.1\" type=\"text/javascript\">
- <!-- // Detect Client Browser type
- var isIE = (navigator.appVersion.indexOf(\"MSIE\") != -1) ? true : false;
- var isWin = (navigator.appVersion.toLowerCase().indexOf(\"win\") != -1) ? true : false;
- var isOpera = (navigator.userAgent.indexOf(\"Opera\") != -1) ? true : false;
- jsVersion = 1.1;
- // JavaScript helper required to detect Flash Player PlugIn version information
- function JSGetSwfVer(i){
- // NS/Opera version >= 3 check for Flash plugin in plugin array
- if (navigator.plugins != null && navigator.plugins.length > 0) {
- if (navigator.plugins[\"Shockwave Flash 2.0\"] || navigator.plugins[\"Shockwave Flash\"]) {
- var swVer2 = navigator.plugins[\"Shockwave Flash 2.0\"] ? \" 2.0\" : \"\";
- var flashDescription = navigator.plugins[\"Shockwave Flash\" + swVer2].description;
- descArray = flashDescription.split(\" \");
- tempArrayMajor = descArray[2].split(\".\");
- versionMajor = tempArrayMajor[0];
- versionMinor = tempArrayMajor[1];
- if ( descArray[3] != \"\" ) {
- tempArrayMinor = descArray[3].split(\"r\");
- } else {
- tempArrayMinor = descArray[4].split(\"r\");
- }
- versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
- flashVer = versionMajor + \".\" + versionMinor + \".\" + versionRevision;
- } else {
- flashVer = -1;
- }
- }
- // MSN/WebTV 2.6 supports Flash 4
- else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.6\") != -1) flashVer = 4;
- // WebTV 2.5 supports Flash 3
- else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.5\") != -1) flashVer = 3;
- // older WebTV supports Flash 2
- else if (navigator.userAgent.toLowerCase().indexOf(\"webtv\") != -1) flashVer = 2;
- // Can't detect in all other cases
- else {
- flashVer = -1;
- }
- return flashVer;
- }
- // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
- function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
- {
- reqVer = parseFloat(reqMajorVer + \".\" + reqRevision);
- // loop backwards through the versions until we find the newest version
- for (i=25;i>0;i--) {
- if (isIE && isWin && !isOpera) {
- versionStr = VBGetSwfVer(i);
- } else {
- versionStr = JSGetSwfVer(i);
- }
- if (versionStr == -1 ) {
- return false;
- } else if (versionStr != 0) {
- if(isIE && isWin && !isOpera) {
- tempArray = versionStr.split(\" \");
- tempString = tempArray[1];
- versionArray = tempString .split(\",\");
- } else {
- versionArray = versionStr.split(\".\");
- }
- versionMajor = versionArray[0];
- versionMinor = versionArray[1];
- versionRevision = versionArray[2];
- versionString = versionMajor + \".\" + versionRevision; // 7.0r24 == 7.24
- versionNum = parseFloat(versionString);
- // is the major.revision >= requested major.revision AND the minor version >= requested minor
- if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
- return true;
- } else {
- return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
- }
- }
- }
- }
- // -->
- </script>";
- if ($origin != 'learnpath')
- {
- //so we are not in learnpath tool
- Display::display_header($nameTools,"Exercise");
- }
- else
- {
- if(empty($charset))
- {
- $charset = 'ISO-8859-15';
- }
- header('Content-Type: text/html; charset='. $charset);
- @$document_language = Database::get_language_isocode($language_interface);
- if(empty($document_language))
- {
- //if there was no valid iso-code, use the english one
- $document_language = 'en';
- }
- /*
- * HTML HEADER
- */
- ?>
- <!DOCTYPE html
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $document_language; ?>" lang="<?php echo $document_language; ?>">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
- </head>
- <body>
- <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/frames.css'; ?>" />
- <?php
- }
- if($objExercise->results_disabled)
- {
- ob_start();
- }
- /*
- ==============================================================================
- FUNCTIONS
- ==============================================================================
- */
- function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect)
- {
- ?>
- <tr>
- <td width="5%" align="center">
- <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $studentChoice?'_on':'_off'; ?>.gif"
- border="0" alt="" />
- </td>
- <td width="5%" align="center">
- <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif"
- border="0" alt=" " />
- </td>
- <td width="45%" style="border-bottom: 1px solid #4171B5;">
- <?php
- $answer=api_parse_tex($answer);
- echo $answer; ?>
- </td>
- <td width="45%" style="border-bottom: 1px solid #4171B5;">
- <?php
- $answerComment=api_parse_tex($answerComment);
- if($studentChoice)
- {
- if(!$answerCorrect)
- {
- echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable(stripslashes($answerComment))).'</span>';
- }
- else{
- echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable(stripslashes($answerComment))).'</span>';
- }
- }
- else
- {
- echo ' ';
- }
- ?>
- </td>
- </tr>
- <?php
- }
- function display_fill_in_blanks_answer($answer)
- {
- ?>
- <tr>
- <td>
- <?php echo nl2br($answer); ?>
- </td>
- </tr>
- <?php
- }
- function display_free_answer($answer)
- {
- ?>
- <tr>
- <td width="55%">
- <?php echo nl2br(stripslashes($answer)); ?>
- </td>
- <td width="45%">
- <?php echo get_lang('notCorrectedYet');?>
- </td>
- </tr>
- <?php
- }
- function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment)
- {
- //global $hotspot_colors;
- $hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
- "#4271B5",
- "#FE8E16",
- "#3B3B3B",
- "#BCD631",
- "#D63173",
- "#D7D7D7",
- "#90AFDD",
- "#AF8640",
- "#4F9242",
- "#F4EB24",
- "#ED2024",
- "#45C7F0",
- "#F7BDE2");
- ?>
- <tr>
- <td valign="top">
- <div style="float:left; padding-left:5px;">
- <div style="display:inline; float:left; width:80px;"><?php echo $answer ?></div>
- <div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]; ?>; display:inline; float:left; margin-top:3px;"></div>
- </div>
- </td>
- <td valign="top"><?php echo $answerId; ?></td>
- <td valign="top">
- <?php $studentChoice = ($studentChoice)?get_lang('Correct'):get_lang('Fault'); echo $studentChoice; ?>
- </td>
- <td valign="top">
- <?php echo stripslashes($answerComment); ?>
- </td>
- </tr>
- <?php
- }
- /*
- ==============================================================================
- MAIN CODE
- ==============================================================================
- */
- $exerciseTitle=api_parse_tex($exerciseTitle);
- ?>
- <h3><?php echo $exerciseTitle ?>: <?php echo get_lang("Result"); ?></h3>
- <?php echo $exerciseDescription; ?>
- <form method="get" action="exercice.php">
- <input type="hidden" name="origin" value="<?php echo $origin; ?>" />
- <input type="hidden" name="learnpath_id" value="<?php echo $learnpath_id; ?>" />
- <input type="hidden" name="learnpath_item_id" value="<?php echo $learnpath_item_id; ?>" />
- <?php
- $i=$totalScore=$totalWeighting=0;
- if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
- // added by Priya Saini
- //$sql = "select max(exe_Id) as id from ".$TBL_TRACK_EXERCICES;
-
- /*
- $sql = "select max(exe_Id) as id from ".$TBL_TRACK_ATTEMPT;
- $res = api_sql_query($sql, __FILE__, __LINE__);
- $exeId =mysql_result($res,0,"id");
- $exeId=$exeId+1;
- */
-
- if($_configuration['tracking_enabled'])
- {
- // Create an empty exercise
- $exeId= create_event_exercice($objExercise->selectId());
- }
-
- $counter=0;
- foreach($questionList as $questionId)
- {
- $counter++;
- // gets the student choice for this question
- $choice=$exerciseResult[$questionId];
-
- //print_r($choice); echo "<br>";
-
- // creates a temporary Question object
- $objQuestionTmp = Question :: read($questionId);
- $questionName=$objQuestionTmp->selectTitle();
- $questionDescription=$objQuestionTmp->selectDescription();
- $questionWeighting=$objQuestionTmp->selectWeighting();
- $answerType=$objQuestionTmp->selectType();
- $quesId =$objQuestionTmp->selectId(); //added by priya saini
- // destruction of the Question object
- unset($objQuestionTmp);
- if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
- {
- $colspan=4;
- }
- elseif($answerType == MATCHING || $answerType == FREE_ANSWER)
- {
- $colspan=2;
- }
- elseif($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER)
- {
- $colspan=4;
- $rowspan=$nbrAnswers+1;
- }
- else
- {
- $colspan=1;
- }
- ?>
- <table width="100%" border="0" cellpadding="3" cellspacing="2">
- <tr bgcolor="#E6E6E6">
- <td colspan="<?php echo $colspan; ?>">
- <?php echo get_lang("Question").' '.($counter).' : '.$questionName; ?>
- </td>
- </tr>
- <tr>
- <td colspan="<?php echo $colspan; ?>">
- <i>
- <?php echo $questionDescription; ?>
- </i>
- </td>
- </tr>
- <?php
- if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
- {
- ?>
- <tr>
- <td width="5%" valign="top" align="center" nowrap="nowrap">
- <i><?php echo get_lang("Choice"); ?></i>
- </td>
- <td width="5%" valign="top" nowrap="nowrap">
- <i><?php echo get_lang("ExpectedChoice"); ?></i>
- </td>
- <td width="45%" valign="top">
- <i><?php echo get_lang("Answer"); ?></i>
- </td>
- <td width="45%" valign="top">
- <i><?php echo get_lang("Comment"); ?></i>
- </td>
- </tr>
- <?php
- }
- elseif($answerType == FILL_IN_BLANKS)
- {
- ?>
- <tr>
- <td>
- <i><?php echo get_lang("Answer"); ?></i>
- </td>
- </tr>
- <?php
- }
- elseif($answerType == FREE_ANSWER)
- {
- ?>
- <tr>
- <td width="55%">
- <i><?php echo get_lang("Answer"); ?></i>
- </td>
- <td width="45%" valign="top">
- <i><?php echo get_lang("Comment"); ?></i>
- </td>
- </tr>
- <?php
- }
- elseif($answerType == HOT_SPOT)
- {
- ?>
- <tr>
- <td valign="top" colspan="2">
- <table width="556" border="0">
- <tr>
- <td width="40%" valign="top">
- <i><?php echo get_lang("CorrectAnswer"); ?></i><br /><br />
- </td>
- <td width="15%" valign="top">
- <i><?php echo get_lang("ClickNumber"); ?></i><br /><br />
- </td>
- <td width="20%" valign="top">
- <i><?php echo get_lang('HotspotHit'); ?></i><br /><br />
- </td>
- <td width="25%" valign="top">
- <i><?php echo get_lang("Comment"); ?></i><br /><br />
- </td>
- </tr>
- <?php
- }
- else
- {
- ?>
- <tr>
- <td width="50%">
- <i><?php echo get_lang("ElementList"); ?></i>
- </td>
- <td width="50%">
- <i><?php echo get_lang("CorrespondsTo"); ?></i>
- </td>
- </tr>
- <?php
- }
- // construction of the Answer object
- $objAnswerTmp=new Answer($questionId);
- $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
- $questionScore=0;
- if($answerType == FREE_ANSWER)
- $nbrAnswers = 1;
- for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
- {
- $answer=$objAnswerTmp->selectAnswer($answerId);
- $answerComment=$objAnswerTmp->selectComment($answerId);
- $answerCorrect=$objAnswerTmp->isCorrect($answerId);
- $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
- switch($answerType)
- {
- // for unique answer
- case UNIQUE_ANSWER :
- $studentChoice=($choice == $answerId)?1:0;
- if($studentChoice)
- {
- $questionScore+=$answerWeighting;
- $totalScore+=$answerWeighting;
- }
- break;
- // for multiple answers
- case MULTIPLE_ANSWER :
- $studentChoice=$choice[$answerId];
- if($studentChoice)
- {
- $questionScore+=$answerWeighting;
- $totalScore+=$answerWeighting;
- }
- break;
- // for fill in the blanks
- case FILL_IN_BLANKS :
-
- // the question is encoded like this
- // [A] B [C] D [E] F::10,10,10@1
- // number 1 before the "@" means that is a switchable fill in blank question
- // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
- // means that is a normal fill blank question
- // first we explode the "::"
- $pre_array = explode('::', $answer);
-
- // is switchable fill blank or not
- $last = count($pre_array)-1;
- $is_set_switchable = explode('@', $pre_array[$last]);
-
- $switchable_answer_set=false;
- if (isset($is_set_switchable[1]) && $is_set_switchable[1]==1)
- {
- $switchable_answer_set=true;
- }
-
- $answer = '';
- for ($k=0; $k<$last; $k++)
- {
- $answer .= $pre_array[$k];
- }
-
- // splits weightings that are joined with a comma
- $answerWeighting = explode(',',$is_set_switchable[0]);
- // we save the answer because it will be modified
- $temp=$answer;
- // TeX parsing
- // 1. find everything between the [tex] and [/tex] tags
- $startlocations=strpos($temp,'[tex]');
- $endlocations=strpos($temp,'[/tex]');
- if($startlocations !== false && $endlocations !== false)
- {
- $texstring=substr($temp,$startlocations,$endlocations-$startlocations+6);
- // 2. replace this by {texcode}
- $temp=str_replace($texstring,'{texcode}',$temp);
- }
- $answer='';
- $j=0;
-
- //initialise answer tags
- $user_tags=array();
- $correct_tags=array();
- $real_text=array();
- // the loop will stop at the end of the text
- while(1)
- {
- // quits the loop if there are no more blanks (detect '[')
- if(($pos = strpos($temp,'[')) === false)
- {
- // adds the end of the text
- $answer=$temp;
- // TeX parsing - replacement of texcode tags
- $texstring = api_parse_tex($texstring);
- $answer=str_replace("{texcode}",$texstring,$answer);
- $real_text[] = $answer;
- break; //no more "blanks", quit the loop
- }
- // adds the piece of text that is before the blank
- //and ends with '[' into a general storage array
- $real_text[]=substr($temp,0,$pos+1);
- $answer.=substr($temp,0,$pos+1);
- //take the string remaining (after the last "[" we found)
- $temp=substr($temp,$pos+1);
- // quit the loop if there are no more blanks, and update $pos to the position of next ']'
- if(($pos = strpos($temp,']')) === false)
- {
- // adds the end of the text
- $answer.=$temp;
- break;
- }
- $choice[$j]=trim($choice[$j]);
- $user_tags[]=stripslashes(strtolower($choice[$j]));
- //put the contents of the [] answer tag into correct_tags[]
- $correct_tags[]=strtolower(substr($temp,0,$pos));
- $j++;
- $temp=substr($temp,$pos+1);
- //$answer .= ']';
- }
-
- $answer='';
- $real_correct_tags = $correct_tags;
- $chosen_list=array();
-
- for($i=0;$i<count($real_correct_tags);$i++)
- {
- if ($i==0)
- {
- $answer.=$real_text[0];
- }
-
- if (!$switchable_answer_set)
- {
- if ($correct_tags[$i]==$user_tags[$i])
- {
- // gives the related weighting to the student
- $questionScore+=$answerWeighting[$i];
- // increments total score
- $totalScore+=$answerWeighting[$i];
- // adds the word in green at the end of the string
- $answer.=stripslashes($correct_tags[$i]);
- }
- // else if the word entered by the student IS NOT the same as the one defined by the professor
- elseif(!empty($user_tags[$i]))
- {
- // adds the word in red at the end of the string, and strikes it
- $answer.='<font color="red"><s>'.stripslashes($user_tags[$i]).'</s></font>';
- }
- else
- {
- // adds a tabulation if no word has been typed by the student
- $answer.=' ';
- }
- }
- else
- { // switchable fill in the blanks
- if (in_array($user_tags[$i],$correct_tags))
- {
- $chosen_list[]=$user_tags[$i];
- $correct_tags=array_diff($correct_tags,$chosen_list);
-
- // gives the related weighting to the student
- $questionScore+=$answerWeighting[$i];
- // increments total score
- $totalScore+=$answerWeighting[$i];
- // adds the word in green at the end of the string
- $answer.=stripslashes($user_tags[$i]);
- } // else if the word entered by the student IS NOT the same as the one defined by the professor
- elseif(!empty($user_tags[$i]))
- {
- // adds the word in red at the end of the string, and strikes it
- $answer.='<font color="red"><s>'.stripslashes($user_tags[$i]).'</s></font>';
- }
- else
- {
- // adds a tabulation if no word has been typed by the student
- $answer.=' ';
- }
- }
- // adds the correct word, followed by ] to close the blank
- $answer.=' / <font color="green"><b>'.$real_correct_tags[$i].'</b></font>]';
- if ( isset( $real_text[$i+1] ) ) {
- $answer.=$real_text[$i+1];
- }
- }
- break;
- // for free answer
- case FREE_ANSWER :
- $studentChoice=$choice;
- if($studentChoice)
- {
- //Score is at -1 because the question has'nt been corected
- $questionScore=-1;
- $totalScore+=0;
- }
- break;
- // for matching
- case MATCHING :
- if($answerCorrect)
- {
- if($answerCorrect == $choice[$answerId])
- {
- $questionScore+=$answerWeighting;
- $totalScore+=$answerWeighting;
- $choice[$answerId]=$matching[$choice[$answerId]];
- }
- elseif(!$choice[$answerId])
- {
- $choice[$answerId]=' ';
- }
- else
- {
- $choice[$answerId]='<font color="red"><s>'.$matching[$choice[$answerId]].'</s></font>';
- }
- }
- else
- {
- $matching[$answerId]=$answer;
- }
- break;
- // for hotspot with no order
- case HOT_SPOT : $studentChoice=$choice[$answerId];
- if($studentChoice)
- {
- $questionScore+=$answerWeighting;
- $totalScore+=$answerWeighting;
- }
- break;
- // for hotspot with fixed order
- case HOT_SPOT_ORDER : $studentChoice=$choice['order'][$answerId];
- if($studentChoice == $answerId)
- {
- $questionScore+=$answerWeighting;
- $totalScore+=$answerWeighting;
- $studentChoice = true;
- }
- else
- {
- $studentChoice = false;
- }
- break;
- } // end switch Answertype
-
- if($answerType != MATCHING || $answerCorrect)
- {
- if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
- {
- display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect);
- }
- elseif($answerType == FILL_IN_BLANKS)
- {
- display_fill_in_blanks_answer($answer);
- }
- elseif($answerType == FREE_ANSWER)
- {
- // to store the details of open questions in an array to be used in mail
- $arrques[] = $questionName;
- $arrans[] = $choice;
- $firstName = $_SESSION['_user']['firstName'];
- $lastName = $_SESSION['_user']['lastName'];
- $mail = $_SESSION['_user']['mail'];
- $coursecode = $_SESSION['_course']['id'];
- $to = '';
- $teachers = array();
- if(api_get_setting('use_session_mode')=='true' && !empty($_SESSION['id_session']))
- {
- $teachers = CourseManager::get_coach_list_from_course_code($coursecode,$_SESSION['id_session']);
- }
- else
- {
- $teachers = CourseManager::get_teacher_list_from_course_code($coursecode);
- }
- $num = count($teachers);
- if($num>1)
- {
- $to = array();
- foreach($teachers as $teacher)
- {
- $to[] = $teacher['email'];
- }
- }elseif($num>0){
- foreach($teachers as $teacher)
- {
- $to = $teacher['email'];
- }
- }else{
- //this is a problem (it means that there is no admin for this course)
- }
- display_free_answer($choice);
- }
- elseif($answerType == HOT_SPOT)
- {
-
- $tbl_track_e_hotspot = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
- // Save into db
- $sql = "INSERT INTO $tbl_track_e_hotspot (`hotspot_user_id` , `hotspot_course_code` , `hotspot_exe_id` , `hotspot_question_id` , `hotspot_answer_id` , `hotspot_correct` , `hotspot_coordinate` )
- VALUES ('".Database::escape_string($_user['user_id'])."', '".Database::escape_string($_course['id'])."', '".Database::escape_string($exeId)."', '".Database::escape_string($questionId)."', '".Database::escape_string($answerId)."', '".Database::escape_string($studentChoice)."', '".Database::escape_string($_SESSION['exerciseResultCoordinates'][$questionId][$answerId])."')";
-
- $result = api_sql_query($sql,__FILE__,__LINE__);
-
- display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
- }
- elseif($answerType == HOT_SPOT_ORDER)
- {
- display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment);
- }
- else
- {
- ?>
- <tr>
- <td width="50%">
- <?php
- $answer=api_parse_tex($answer);
- echo $answer; ?>
- </td>
- <td width="50%">
- <?php echo $choice[$answerId]; ?> / <font color="green"><b>
- <?php
- $matching[$answerCorrect]=api_parse_tex($matching[$answerCorrect]);
- echo $matching[$answerCorrect]; ?></b></font>
- </td>
- </tr>
- <?php
- }
- }
- } // end for that loops over all answers of the current question
- if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER)
- {
- // We made an extra table for the answers
- echo "</table></td></tr>";
- ?>
-
- <tr>
- <td colspan="2">
- <i><?php echo get_lang('Hotspot'); ?></i><br /><br />
- <object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo $questionId ?>&exe_id=&from_db=0" width="556" height="421">
- <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo $questionId ?>&exe_id=&from_db=0" />
- </object>
- </td>
- </tr>
- <?php
- }
- ?>
- <tr>
- <td colspan="<?php echo $colspan; ?>" align="left">
- <b>
- <?php
- if($questionScore==-1){
- echo get_lang('Score')." : 0/$questionWeighting";
- }
- else{
- echo get_lang('Score')." : $questionScore/$questionWeighting";
- }
- ?></b><br /><br />
- </td>
- </tr>
- </table>
- <?php
- // destruction of Answer
- unset($objAnswerTmp);
- $i++;
- $totalWeighting+=$questionWeighting;
- //added by priya saini
- if($_configuration['tracking_enabled'])
- {
- if(empty($choice)){
- $choice = 0;
- }
- if ($answerType==MULTIPLE_ANSWER )
- {
- if ($choice != 0)
- {
- $reply = array_keys($choice);
-
- for ($i=0;$i<sizeof($reply);$i++)
- {
- $ans = $reply[$i];
- exercise_attempt($questionScore,$ans,$quesId,$exeId,$i);
- }
- }
- else
- {
- exercise_attempt($questionScore, 0 ,$quesId,$exeId,0);
- }
- }
- elseif ($answerType==MATCHING)
- {
- $j=sizeof($matching)+1;
- for ($i=0;$i<sizeof($choice);$i++,$j++)
- {
- $val = $choice[$j];
- if (preg_match_all ('#<font color="red"><s>([0-9a-z ]*)</s></font>#', $val, $arr1))
- $val = $arr1[1][0];
- $val=addslashes($val);
- $val=strip_tags($val);
- $sql = "select position from $table_ans where question_id='".Database::escape_string($questionId)."' and answer='".Database::escape_string($val)."' AND correct=0";
- $res = api_sql_query($sql, __FILE__, __LINE__);
- $answer = Database::result($res,0,"position");
-
- exercise_attempt($questionScore,$answer,$quesId,$exeId,$j);
- }
- }
- elseif ($answerType==FREE_ANSWER) {
- $answer = $choice;
- exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
- }
- elseif ($answerType==UNIQUE_ANSWER) {
- $sql = "SELECT id FROM $table_ans WHERE question_id='".Database::escape_string($questionId)."' and position='".Database::escape_string($choice)."'";
- $res = api_sql_query($sql, __FILE__, __LINE__);
- if (Database::num_rows($res)>0) {
- $answer = Database::result($res,0,"id");
- exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
- }
- } else {
- exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
- }
- }
- } // end huge foreach() block that loops over all questions
- ?>
- <table width="100%" border="0" cellpadding="3" cellspacing="2">
- <tr>
- <td>
- <b><?php echo get_lang('YourTotalScore')." ";
- if($dsp_percent == true){
- echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
- }else{
- echo $totalScore."/".$totalWeighting;
- }
- ?></b>
- </td>
- </tr>
- <tr>
- <td>
- <br />
- <?php
- if ($origin != 'learnpath') {
- ?>
- <input type="submit" value="<?php echo get_lang('Finish'); ?>" />
- <?php
- } else {
- ?>
- <input type="button" onclick="top.location.href='../newscorm/lp_controller.php?cidReq=<?php echo api_get_course_id()?>&action=view&lp_id=<?php echo $learnpath_id ?>&lp_item_id=<?php echo $learnpath_item_id ?>'" value="<?php echo get_lang('Finish'); ?>" />
- <?php }?>
- </td>
- </tr>
- </table>
- </form>
- <br />
- <?php
- /*
- ==============================================================================
- Tracking of results
- ==============================================================================
- */
- if($_configuration['tracking_enabled']) {
- // Updates the empty exercise
- $safe_lp_id = $learnpath_id==''?0:(int)$learnpath_id;
- $safe_lp_item_id = $learnpath_item_id==''?0:(int)$learnpath_item_id;
- $quizDuration = (!empty($_SESSION['quizStartTime']) ? time() - $_SESSION['quizStartTime'] : 0);
- update_event_exercice($exeId, $objExercise->selectId(),$totalScore,$totalWeighting,api_get_session_id(),$safe_lp_id,$safe_lp_item_id,$quizDuration);
- }
- if($objExercise->results_disabled) {
- ob_end_clean();
- Display :: display_normal_message(get_lang('ExerciseFinished').'<br /><a href="exercice.php" />'.get_lang('Back').'</a>',false);
- }
- if ($origin != 'learnpath') {
- //we are not in learnpath tool
- Display::display_footer();
- } else {
- //record the results in the learning path, using the SCORM interface (API)
- echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$totalScore.','.$totalWeighting.');</script>'."\n";
- echo '</body></html>';
- }
- if(count($arrques)>0) {
- $mycharset = api_get_setting('platform_charset');
- $msg = '<html><head>
- <link rel="stylesheet" href="'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css" type="text/css">
- <meta content="text/html; charset='.$mycharset.'" http-equiv="content-type">';
- $msg .= '</head>
- <body><br />
- <p>'.get_lang('OpenQuestionsAttempted').' :
- </p>
- <p>'.get_lang('AttemptDetails').' : ><br />
- </p>
- <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
- <tr>
- <td width="229" valign="top"><h2> '.get_lang('CourseName').'</h2></td>
- <td width="469" valign="top"><h2>#course#</h2></td>
- </tr>
- <tr>
- <td width="229" valign="top" class="outerframe"> '.get_lang('TestAttempted').'</span></td>
- <td width="469" valign="top" class="outerframe">#exercise#</td>
- </tr>
- <tr>
- <td valign="top"> <span class="style10">'.get_lang('StudentName').'</span></td>
- <td valign="top" >#firstName# #lastName#</td>
- </tr>
- <tr>
- <td valign="top" > '.get_lang('StudentEmail').' </td>
- <td valign="top"> #mail#</td>
- </tr></table>
- <p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
- <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
- for($i=0;$i<sizeof($arrques);$i++) {
- $msg.='
- <tr>
- <td width="220" valign="top" bgcolor="#E5EDF8"> <span class="style10">'.get_lang('Question').'</span></td>
- <td width="473" valign="top" bgcolor="#F3F3F3"><span class="style16"> #questionName#</span></td>
- </tr>
- <tr>
- <td width="220" valign="top" bgcolor="#E5EDF8"> <span class="style10">'.get_lang('Answer').' </span></td>
- <td valign="top" bgcolor="#F3F3F3"><span class="style16"> #answer#</span></td>
- </tr>';
-
- $msg1= str_replace("#exercise#",$exerciseTitle,$msg);
- $msg= str_replace("#firstName#",$firstName,$msg1);
- $msg1= str_replace("#lastName#",$lastName,$msg);
- $msg= str_replace("#mail#",$mail,$msg1);
- $msg1= str_replace("#questionName#",$arrques[$i],$msg);
- $msg= str_replace("#answer#",$arrans[$i],$msg1);
- $msg1= str_replace("#i#",$i,$msg);
- $msg= str_replace("#course#",$courseName,$msg1);
- }
- $msg.='</table><br>
- <span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
- <a href="#url#">#url#</a></span></body></html>';
-
- $msg1= str_replace("#url#",$url,$msg);
- $mail_content = stripslashes($msg1);
- $student_name = $_SESSION['_user']['firstName'].' '.$_SESSION['_user']['lastName'];
- $subject = get_lang('OpenQuestionsAttempted');
-
- $from = api_get_setting('noreply_email_address');
- if($from == '') {
- if(isset($_SESSION['id_session']) && $_SESSION['id_session'] != ''){
- $sql = 'SELECT user.email,user.lastname,user.firstname FROM '.TABLE_MAIN_SESSION.' as session, '.TABLE_MAIN_USER.' as user
- WHERE session.id_coach = user.user_id
- AND session.id = "'.Database::escape_string($_SESSION['id_session']).'"
- ';
- $result=api_sql_query($sql,__FILE__,__LINE__);
- $from = Database::result($result,0,'email');
- $from_name = Database::result($result,0,'firstname').' '.Database::result($result,0,'lastname');
- } else {
- $array = explode(' ',$_SESSION['_course']['titular']);
- $firstname = $array[1];
- $lastname = $array[0];
- $sql = 'SELECT email,lastname,firstname FROM '.TABLE_MAIN_USER.'
- WHERE firstname = "'.Database::escape_string($firstname).'"
- AND lastname = "'.Database::escape_string($lastname).'"
- ';
- $result=api_sql_query($sql,__FILE__,__LINE__);
- $from = Database::result($result,0,'email');
- $from_name = Database::result($result,0,'firstname').' '.Database::result($result,0,'lastname');
- }
- }
- api_mail_html($student_name, $to, $subject, $mail_content, $from_name, $from, array('encoding'=>$mycharset,'charset'=>$mycharset));
- }
- ?>
|