123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347 |
- <?php // $Id: exercice_submit.php 18002 2009-01-26 16:33:20Z juliomontoya $
- /*
- ==============================================================================
- Dokeos - elearning and course management software
- Copyright (c) 2004-2008 Dokeos SPRL
- Copyright (c) 2003 Ghent University (UGent)
- Copyright (c) 2001 Universite catholique de Louvain (UCL)
- Copyright (c) various contributors
- 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 submission
- * This script allows to run an exercise. According to the exercise type, questions
- * can be on an unique page, or one per page with a Next button.
- *
- * One exercise may contain different types of answers (unique or multiple selection,
- * matching, fill in blanks, free answer, hot-spot).
- *
- * Questions are selected randomly or not.
- *
- * When the user has answered all questions and clicks on the button "Ok",
- * it goes to exercise_result.php
- *
- * Notice : This script is also used to show a question before modifying it by
- * the administrator
- * @package dokeos.exercise
- * @author Olivier Brouckaert
- * @author Julio Montoya multiple fill in blank option added
- * @version $Id: exercice_submit.php 18002 2009-01-26 16:33:20Z juliomontoya $
- */
- include('exercise.class.php');
- include('question.class.php');
- include('answer.class.php');
- include('exercise.lib.php');
- // debug var. Set to 0 to hide all debug display. Set to 1 to display debug messages.
- $debug = 0;
- /*
- // 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);
- */
- // name of the language file that needs to be included
- $language_file='exercice';
- include_once('../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).'text.lib.php');
- $is_allowedToEdit=api_is_allowed_to_edit();
- $_configuration['live_exercise_tracking'] = true;
- $stat_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
- $exercice_attemp_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
- $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);
- // general parameters passed via POST/GET
- if ( empty ( $origin ) ) {
- $origin = $_REQUEST['origin'];
- }
- if ( empty ( $learnpath_id ) ) {
- $learnpath_id = Database::escape_string($_REQUEST['learnpath_id']);
- }
- if ( empty ( $learnpath_item_id ) ) {
- $learnpath_item_id = Database::escape_string($_REQUEST['learnpath_item_id']);
- }
- if ( empty ( $formSent ) ) {
- $formSent = $_REQUEST['formSent'];
- }
- if ( empty ( $exerciseResult ) ) {
- $exerciseResult = $_REQUEST['exerciseResult'];
- }
- if ( empty ( $exerciseResultCoordinates ) ) {
- $exerciseResultCoordinates = $_REQUEST['exerciseResultCoordinates'];
- }
- if ( empty ( $exerciseType ) ) {
- $exerciseType = $_REQUEST['exerciseType'];
- }
- if ( empty ( $exerciseId ) ) {
- $exerciseId = intval($_REQUEST['exerciseId']);
- }
- if ( empty ( $choice ) ) {
- $choice = $_REQUEST['choice'];
- }
- if ( empty ( $questionNum ) ) {
- $questionNum = Database::escape_string($_REQUEST['questionNum']);
- }
- if ( empty ( $nbrQuestions ) ) {
- $nbrQuestions = Database::escape_string($_REQUEST['nbrQuestions']);
- }
- if ( empty ($buttonCancel) ) {
- $buttonCancel = $_REQUEST['buttonCancel'];
- }
- $error = '';
- if (!isset($exerciseType)) {
- $exe_start_date= date('Y-m-d H:i:s');
- }
- // if the user has clicked on the "Cancel" button
- if($buttonCancel)
- {
- // returns to the exercise list
- header("Location: exercice.php?origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
- exit();
- }
- if ($origin=='builder') {
- /*******************************/
- /* Clears the exercise session */
- /*******************************/
- if(isset($_SESSION['objExercise'])) { api_session_unregister('objExercise'); unset($objExercise); }
- if(isset($_SESSION['objQuestion'])) { api_session_unregister('objQuestion'); unset($objQuestion); }
- if(isset($_SESSION['objAnswer'])) { api_session_unregister('objAnswer'); unset($objAnswer); }
- if(isset($_SESSION['questionList'])) { api_session_unregister('questionList'); unset($questionList); }
- if(isset($_SESSION['newquestionList'])) { api_session_unregister('newquestionList'); unset($newquestionList); }
- if(isset($_SESSION['exerciseResult'])) { api_session_unregister('exerciseResult'); unset($exerciseResult); }
- if(isset($_SESSION['exerciseResultCoordinates'])) { api_session_unregister('exerciseResultCoordinates'); unset($exerciseResultCoordinates); }
- }
- $safe_lp_id = ($learnpath_id=='')?0:(int)$learnpath_id;
- $safe_lp_item_id = ($learnpath_item_id=='')?0:(int)$learnpath_item_id;
- $condition = ' WHERE ' .
- 'exe_exo_id = '."'".$exerciseId."'".' AND ' .
- 'exe_user_id = '."'".api_get_user_id()."'".' AND ' .
- 'exe_cours_id = '."'".$_course['id']."'".' AND ' .
- 'status = '."'incomplete'".' AND '.
- 'orig_lp_id = '."'".$safe_lp_id."'".' AND '.
- 'orig_lp_item_id = '."'".$safe_lp_item_id."'".' AND '.
- 'session_id = '."'".(int)$_SESSION['id_session']."'";
- $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
- $result=api_sql_query("SELECT type,feedback_type FROM $TBL_EXERCICES WHERE id=$exerciseId",__FILE__,__LINE__);
- $exercise_row = Database::fetch_array($result);
- $exerciseType = $exercise_row['type'];
- $exerciseFeedbackType= $exercise_row['feedback_type'];
- if ($exerciseType == 1) {
- $_SESSION['exercice_start_date'] = $exe_start_date;
- }
- if ($_configuration['live_exercise_tracking'] == true && $exerciseType == 2 && $exerciseFeedbackType!=1) {
- $query = 'SELECT * FROM '.$stat_table.$condition;
- $result_select = api_sql_query($query,__FILE__,__LINE__);
- if(Database::num_rows($result_select) > 0 ){
- $getIncomplete = Database::fetch_array($result_select);
- $exe_id = $getIncomplete['exe_id'];
- if ($_SERVER['REQUEST_METHOD']!='POST') {
- define('QUESTION_LIST_ALREADY_LOGGED',1);
- $recorded['questionList'] = explode(',',$getIncomplete['data_tracking']);
- $query = 'SELECT * FROM '.$exercice_attemp_table.' WHERE exe_id = '.$getIncomplete['exe_id'].' ORDER BY tms ASC';
- $result = api_sql_query($query,__FILE__,__LINE__);
- while ($row = Database::fetch_array($result)) {
- $recorded['exerciseResult'][$row['question_id']] = 1;
- }
- $exerciseResult = $_SESSION['exerciseResult'] = $recorded['exerciseResult'];
- $exerciseType = 2;
- $questionNum = count($recorded['exerciseResult']);
- $questionNum++;
- $questionList = $_SESSION['questionList'] = $recorded['questionList'];
- }
- } else {
- $table_recorded_not_exist = true;
- }
- }
- // if the user has submitted the form
- if ($formSent) {
- if ($debug>0) {
- echo str_repeat(' ',0).'$formSent was set'."<br />\n";
- }
- // initializing
- if (!is_array($exerciseResult)) {
- $exerciseResult=array();
- $exerciseResultCoordinates=array();
- }
- // if the user has answered at least one question
- if (is_array($choice)) {
- if ($debug>0) {
- echo str_repeat(' ',0).'$choice is an array'."<br />\n";
- }
- if ($exerciseType == 1) {
- // $exerciseResult receives the content of the form.
- // Each choice of the student is stored into the array $choice
- $exerciseResult=$choice;
- if (isset($_POST['hotspot'])) {
- $exerciseResultCoordinates = $_POST['hotspot'];
- }
- } else {
- // gets the question ID from $choice. It is the key of the array
- list($key)=array_keys($choice);
- // if the user didn't already answer this question
- if (!isset($exerciseResult[$key])) {
- // stores the user answer into the array
- $exerciseResult[$key]=$choice[$key];
- //saving each question
- if ($_configuration['live_exercise_tracking'] == true && $exerciseType == 2 && $exerciseFeedbackType!=1) {
-
- $nro_question = $questionNum;// - 1;
- //START of saving and qualifying each question submitted
- //------------------------------------------------------------------------------------------
- //
- define('ENABLED_LIVE_EXERCISE_TRACKING',1);
- require_once 'question.class.php';
- require_once 'answer.class.php';
- require_once(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
- $counter=0;
- $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
- //foreach($questionList as $questionId)
- if (true) {
- $exeId = $exe_id;
- $questionId = $key;
- $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);
-
- // 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]);
- } elseif(!empty($user_tags[$i])) {
- // else if the word entered by the student IS NOT the same as the one defined by the professor
- // 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
- } // end for that loops over all answers of the current question
-
- // 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 = mysql_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__);
- $answer = mysql_result($res,0,"id");
- exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
- } else {
- exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
- }
- }
- } // end huge foreach() block th //START of saving and qualifying each question submitted
- //------------------------------------------------------------------------------------------
- //
- define('ENABLED_LIVE_EXERCISE_TRACKING',1);
- require_once 'question.class.php';
- require_once 'answer.class.php';
- require_once(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
- $counter=0;
- $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
- //foreach($questionList as $questionId)
- if (true) {
- $exeId = $exe_id;
- $questionId = $key;
- $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);
-
- // 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]);
- } elseif(!empty($user_tags[$i])) {
- // else if the word entered by the student IS NOT the same as the one defined by the professor
- // 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
- } // end for that loops over all answers of the current question
-
- // 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 = mysql_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__);
- $answer = mysql_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
- api_sql_query('UPDATE '.$stat_table.' SET exe_result = exe_result + '.(int)$totalScore.',exe_weighting = exe_weighting + '.(int)$totalWeighting.' WHERE exe_id = '.$exe_id,__FILE__,__LINE__);
- //END of saving and qualifying
- //------------------------------------------------------------------------------------------
- //at loops over all questions
- api_sql_query('UPDATE '.$stat_table.' SET exe_result = exe_result + '.(int)$totalScore.',exe_weighting = exe_weighting + '.(int)$totalWeighting.' WHERE exe_id = '.$exe_id,__FILE__,__LINE__);
- //END of saving and qualifying
- //------------------------------------------------------------------------------------------
- //
- }
- if (isset($_POST['hotspot'])) {
- $exerciseResultCoordinates[$key] = $_POST['hotspot'][$key];
- }
- }
- }
- if ($debug>0) {
- echo str_repeat(' ',0).'$choice is an array - end'."<br />\n";
- }
- }
- // the script "exercise_result.php" will take the variable $exerciseResult from the session
- api_session_register('exerciseResult');
- api_session_register('exerciseResultCoordinates');
- // if it is the last question (only for a sequential exercise)
- if($exerciseType == 1 || $questionNum >= $nbrQuestions) {
- if ($debug>0) {
- echo str_repeat(' ',0).'Redirecting to exercise_result.php - Remove debug option to let this happen'."<br />\n";
- }
- // goes to the script that will show the result of the exercise
- if ($exerciseType == 1) {
- header("Location: exercise_result.php?exerciseType=$exerciseType&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
- } else {
- //clean incomplete
- api_sql_query('UPDATE '.$stat_table.' SET '."status = '', data_tracking='', exe_date = '".date('Y-m-d H:i:s')."'".' WHERE exe_id = '.$exe_id,__FILE__,__LINE__);
- header("Location: exercise_show.php?id=$exeId&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
- }
- exit();
- }
- if ($debug>0) {
- echo str_repeat(' ',0).'$formSent was set - end'."<br />\n";
- }
- }
- // if the object is not in the session
- if (!isset($_SESSION['objExercise']) || $origin == 'learnpath' || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) {
-
- if ($debug>0) {
- echo str_repeat(' ',0).'$_SESSION[objExercise] was unset'."<br />\n";
- }
- // construction of Exercise
- $objExercise=new Exercise();
- unset($_SESSION['questionList']);
-
- // if the specified exercise doesn't exist or is disabled
- if (!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() && !$is_allowedToEdit && ($origin != 'learnpath') )) {
- unset($objExercise);
- $error = get_lang('ExerciseNotFound');
- //die(get_lang('ExerciseNotFound'));
- } else {
- // saves the object into the session
- api_session_register('objExercise');
- if ($debug>0) {
- echo str_repeat(' ',0).'$_SESSION[objExercise] was unset - set now - end'."<br />\n";
- }
- }
- }
- if (!isset($objExcercise) && isset($_SESSION['objExercise'])) {
- $objExercise = $_SESSION['objExercise'];
- }
- if (!is_object($objExercise)) {
- header('Location: exercice.php');
- exit();
- }
- $Exe_starttime = $objExercise->start_time;
- $Exe_endtime = $objExercise->end_time;
- $quizID = $objExercise->selectId();
- $exerciseAttempts=$objExercise->selectAttempts();
- $exerciseTitle=$objExercise->selectTitle();
- $exerciseDescription=$objExercise->selectDescription();
- $exerciseDescription=stripslashes($exerciseDescription);
- $exerciseSound=$objExercise->selectSound();
- $randomQuestions=$objExercise->isRandom();
- $exerciseType=$objExercise->selectType();
- if(!isset($_SESSION['questionList']) || $origin == 'learnpath')
- {
- if($debug>0){echo str_repeat(' ',0).'$_SESSION[questionList] was unset'."<br />\n";}
- // selects the list of question ID
- $questionList = ($randomQuestions?$objExercise->selectRandomList():$objExercise->selectQuestionList());
- // saves the question list into the session
- api_session_register('questionList');
- if($debug>0){echo str_repeat(' ',0).'$_SESSION[questionList] was unset - set now - end'."<br />\n";}
- }
- if(!isset($objExcercise) && isset($_SESSION['objExercise'])){
- $questionList = $_SESSION['questionList'];
- }
- $quizStartTime = time();
- api_session_register('quizStartTime');
- $nbrQuestions=sizeof($questionList);
- // if questionNum comes from POST and not from GET
- if(!$questionNum || $_POST['questionNum'])
- {
- // only used for sequential exercises (see $exerciseType)
- if(!$questionNum)
- {
- $questionNum=1;
- }
- else
- {
- $questionNum++;
- }
- }
- //$nameTools=get_lang('Exercice');
- $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
- $interbreadcrumb[]=array("url" => "#","name" => $exerciseTitle);
- if ($origin != 'learnpath') { //so we are not in learnpath tool
- $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>";
- $htmlHeadXtra[] = "<script type=\"text/javascript\" src=\"../inc/lib/javascript/custom-form-elements.js\"></script>";
- 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=<?php echo $charset; ?>" />
- </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
- }
- $exerciseTitle=api_parse_tex($exerciseTitle);
- echo "<h3>".$exerciseTitle."</h3>";
- if( $exerciseAttempts > 0){
- $user_id = api_get_user_id();
- $course_code = api_get_course_id();
- $sql = "SELECT count(*) FROM $stat_table WHERE exe_exo_id = '$quizID'
- AND exe_user_id = '$user_id'
- AND status != 'incomplete'
- AND orig_lp_id = $safe_lp_id
- AND orig_lp_item_id = $safe_lp_item_id
- AND exe_cours_id = '$course_code' AND session_id = '".(int)$_SESSION['id_session']."'";
- $aquery = api_sql_query($sql, __FILE__, __LINE__);
- $attempt = Database::fetch_array($aquery);
- if ( $attempt[0] >= $exerciseAttempts ) {
- if (!api_is_allowed_to_edit()) {
- Display::display_warning_message(sprintf(get_lang('ReachedMaxAttempts'),$exerciseTitle,$exerciseAttempts));
- Display::display_footer();
- exit;
- } else {
- Display::display_warning_message(sprintf(get_lang('ReachedMaxAttemptsAdmin'),$exerciseTitle,$exerciseAttempts));
- }
- }
- }
- if (!function_exists('convert_date_to_number')) {
- function convert_date_to_number($default){
- // 2008-10-12 00:00:00 ---to--> 12345672218 (timestamp)
- $parts = split(' ',$default);
- list($d_year,$d_month,$d_day) = split('-',$parts[0]);
- list($d_hour,$d_minute,$d_second) = split(':',$parts[1]);
- return mktime($d_hour, $d_minute, $d_second, $d_month, $d_day, $d_year);
- }
- }
- $limit_time_exists = (($Exe_starttime!='0000-00-00 00:00:00')||($Exe_endtime!='0000-00-00 00:00:00'))? true : false;
- if($limit_time_exists){
- $exercise_start_time = convert_date_to_number($Exe_starttime);
- $exercise_end_time = convert_date_to_number($Exe_endtime);
- $time_now = convert_date_to_number(date('Y-m-d H:i:s'));
- $permission_to_start = (($time_now - $exercise_start_time)>0)?true:false;
- if($_SERVER['REQUEST_METHOD']!='POST')$exercise_timeover = (($time_now - $exercise_end_time)>0)?true:false;
- if($permission_to_start == false || $exercise_timeover == true ){ //
- if(!api_is_allowed_to_edit()){
- $message_warning = ($permission_to_start == false)? get_lang('ExerciseNoStartedYet') : get_lang('ReachedTimeLimit') ;
- Display::display_warning_message(sprintf($message_warning,$exerciseTitle,$exerciseAttempts));
- Display::display_footer();
- exit;
- } else {
- $message_warning = ($permission_to_start == false)? get_lang('ExerciseNoStartedAdmin') : get_lang('ReachedTimeLimitAdmin') ;
- Display::display_warning_message(sprintf($message_warning,$exerciseTitle,$exerciseAttempts));
- }
- }
- }
- if(!empty($error))
- {
- Display::display_error_message($error,false);
- }
- else
- {
- if(!empty($exerciseSound)) {
- echo "<a href=\"../document/download.php?doc_url=%2Faudio%2F".$exerciseSound."\" target=\"_blank\">",
- "<img src=\"../img/sound.gif\" border=\"0\" align=\"absmiddle\" alt=",get_lang('Sound')."\" /></a>";
- }
- // Get number of hotspot questions for javascript validation
- $number_of_hotspot_questions = 0;
- $onsubmit = '';
- $i=0;
-
- foreach($questionList as $questionId)
- {
- $i++;
- $objQuestionTmp = Question :: read($questionId);
-
- // for sequential exercises
- if($exerciseType == 2) {
- // if it is not the right question, goes to the next loop iteration
- if($questionNum != $i)
- {
- continue;
- }
- else
- {
- if ($objQuestionTmp->selectType() == HOT_SPOT)
- {
- $number_of_hotspot_questions++;
- }
- break;
- }
- }
- else
- {
- if ($objQuestionTmp->selectType() == HOT_SPOT)
- {
- $number_of_hotspot_questions++;
- }
- }
- }
- if($number_of_hotspot_questions > 0)
- {
- $onsubmit = "onsubmit=\"return validateFlashVar('".$number_of_hotspot_questions."', '".get_lang('HotspotValidateError1')."', '".get_lang('HotspotValidateError2')."');\"";
- }
- $s="<p>$exerciseDescription</p>";
- if($exerciseType==2){
- $s2 = "&exerciseId=".$exerciseId;
- }
- $s.=" <form method='post' action='".api_get_self()."?autocomplete=off".$s2."' name='frm_exercise' $onsubmit>
- <input type='hidden' name='formSent' value='1' />
- <input type='hidden' name='exerciseType' value='".$exerciseType."' />
- <input type='hidden' name='exerciseId' value='".$exerciseId."' />
- <input type='hidden' name='questionNum' value='".$questionNum."' />
- <input type='hidden' name='nbrQuestions' value='".$nbrQuestions."' />
- <input type='hidden' name='origin' value='".$origin."' />
- <input type='hidden' name='learnpath_id' value='".$learnpath_id."' />
- <input type='hidden' name='learnpath_item_id' value='".$learnpath_item_id."' />
- <table width='100%' border='0' cellpadding='1' cellspacing='0'>
- <tr>
- <td>
- <table width='100%' cellpadding='3' cellspacing='0' border='0'>";
- echo $s;
- $i=0;
- foreach($questionList as $questionId) {
- $i++;
- // for sequential exercises
- if($exerciseType == 2) {
- // if it is not the right question, goes to the next loop iteration
- if($questionNum != $i){
- continue;
- } else {
- if ($exerciseFeedbackType!=1) {
- // if the user has already answered this question
- if(isset($exerciseResult[$questionId])) {
- // construction of the Question object
- $objQuestionTmp = Question::read($questionId);
- $questionName=$objQuestionTmp->selectTitle();
- // destruction of the Question object
- unset($objQuestionTmp);
- echo '<tr><td>'.get_lang('AlreadyAnswered').' "'.$questionName.'"</td></tr>';
- break;
- }
- }
- }
- }
- /*
- $s="<tr>
- <td width='3%' bgcolor='#e6e6e6'><img src=\"".api_get_path(WEB_IMG_PATH)."test.gif\" align=\"absmiddle\"></td>
- <td valign='middle' bgcolor='#e6e6e6'>
- ".get_lang('Question')." ";
- */
-
- // shows the question and its answers
- showQuestion($questionId, false, $origin,$i,$nbrQuestions);
- // for sequential exercises
- if($exerciseType == 2) {
- // quits the loop
- break;
- }
- }
- // end foreach()
-
- echo "
- <!-- <input type='submit' name='buttonCancel' value=".get_lang('Cancel')." />
- //--><br />";
- $submit_btn="<input type='submit' name='submit' value='";
- // $submit_btn.=get_lang('ValidateAnswer');
- if ($objExercise->selectFeedbackType()==1 && $_SESSION['objExercise']->selectType()==2) {
- $submit_btn='';
- echo '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.js" type="text/javascript"></script>';
- echo '<style type="text/css" media="all">@import "'.api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.css";</style>';
- $hotspot_get=$_POST['hotspot'];
- // Show a hidden div
- echo "<script>$(document).ready( function(){
- $('.rounded').corners();
- $('.rounded_inner').corners();
- });</script>";
- //echo '<br /><span class="rounded" style="width: 300px; margin-top: 10px; padding: 3px; background-color:#ccc;"><span style="width: 300px" class="rounded_inner" ><a href="exercise_submit_modal.php?hotspot='.$hotspot_get.'&nbrQuestions='.$nbrQuestions.'&questionnum='.$questionNum.'&exerciseType='.$exerciseType.'&exerciseId='.$exerciseId.'&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=480&width=640&modal=true" title="" class="thickbox" id="validationButton">'.get_lang('ValidateAnswer').'</a></span></span><br /><br /><br />';
- echo '<br /><div class="rounded" style="text-align: center;"><div class="rounded_inner"><a href="exercise_submit_modal.php?hotspot='.$hotspot_get.'&nbrQuestions='.$nbrQuestions.'&questionnum='.$questionNum.'&exerciseType='.$exerciseType.'&exerciseId='.$exerciseId.'&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=480&width=640&modal=true" title="" class="thickbox" id="validationButton">'.get_lang('ValidateAnswer').'</a></div></div><br /><br /><br />';
- } else {
- if ($exerciseType == 1 || $nbrQuestions == $questionNum)
- {
- $submit_btn.=get_lang('ValidateAnswer');
- }
- else
- {
- $submit_btn.=get_lang('Next').' >';
- }
- $submit_btn.= '\' />';
- }
- echo $submit_btn;
- echo "</form>";
- $b=2;
- }
- if($_configuration['live_exercise_tracking'] == true && $exerciseFeedbackType!=1) {
- //if($questionNum < 2){
- if($table_recorded_not_exist){
- if($exerciseType == 2){
- api_sql_query("INSERT INTO $stat_table(exe_exo_id,exe_user_id,exe_cours_id,status,session_id,data_tracking,start_date,orig_lp_id,orig_lp_item_id)
- VALUES('$exerciseId','".api_get_user_id()."','".$_course['id']."','incomplete','".api_get_session_id()."','".implode(',',$questionList)."','".date('Y-m-d H:i:s')."',$safe_lp_id,$safe_lp_item_id)",__FILE__,__LINE__);
- } else {
- api_sql_query("INSERT INTO $stat_table (exe_exo_id,exe_user_id,exe_cours_id,status,session_id,start_date,orig_lp_id,orig_lp_item_id)
- VALUES('$exerciseId','".api_get_user_id()."','".$_course['id']."','incomplete','".api_get_session_id()."','".date('Y-m-d H:i:s')."',$safe_lp_id,$safe_lp_item_id)",__FILE__,__LINE__);
- }
- }
- }
- if ($origin != 'learnpath') { //so we are not in learnpath tool
- Display::display_footer();
- }
|