diff --git a/main/exercice/exercice_submit.php b/main/exercice/exercice_submit.php index c4ee747e89..a911bdca44 100644 --- a/main/exercice/exercice_submit.php +++ b/main/exercice/exercice_submit.php @@ -1,5 +1,5 @@ \n"; } - if ($exerciseType == 1) { + if ($exerciseType == 1) + { // $exerciseResult receives the content of the form. // Each choice of the student is stored into the array $choice $exerciseResult = $choice; @@ -251,6 +251,7 @@ if ($formSent) { 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); @@ -308,7 +309,7 @@ if ($formSent) { $answerComment = $objAnswerTmp->selectComment($answerId); $answerCorrect = $objAnswerTmp->isCorrect($answerId); $answerWeighting = $objAnswerTmp->selectWeighting($answerId); - + switch ($answerType) { // for unique answer case UNIQUE_ANSWER : @@ -505,13 +506,10 @@ if ($formSent) { $questionScore += $answerWeighting; $totalScore += $answerWeighting; } - $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__); + 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__); break; // for hotspot with fixed order case HOT_SPOT_ORDER : @@ -527,7 +525,6 @@ if ($formSent) { break; } // end switch Answertype } // end for that loops over all answers of the current question - // destruction of Answer unset ($objAnswerTmp); @@ -572,12 +569,10 @@ if ($formSent) { exercise_attempt($questionScore, $answer, $quesId, $exeId, $j); } - } - elseif ($answerType == FREE_ANSWER) { + } elseif ($answerType == FREE_ANSWER) { $answer = $choice; exercise_attempt($questionScore, $answer, $quesId, $exeId, 0); - } - elseif ($answerType == UNIQUE_ANSWER) { + } 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 = Database :: result($res, 0, "id"); @@ -612,22 +607,23 @@ if ($formSent) { // 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) { + define('ALL_ON_ONE_PAGE',1); + define('ONE_PER_PAGE',2); + // if all questions on one page OR if it is the last question (only for an exercise with one question per page) + if ($exerciseType == ALL_ON_ONE_PAGE || $questionNum >= $nbrQuestions) { if ($debug > 0) { echo str_repeat(' ', 0) . 'Redirecting to exercise_result.php - Remove debug option to let this happen' . "
\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"); + if ($exerciseType == ALL_ON_ONE_PAGE) { + header("Location: exercise_result.php?id=$exe_id&exerciseType=$exerciseType&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id"); } else { if ($exe_id != '') { //clean incomplete $update_query = 'UPDATE ' . $stat_table . ' SET ' . "status = '', data_tracking='', exe_date = '" . date('Y-m-d H:i:s') . "'" . ' WHERE exe_id = ' . $exe_id; api_sql_query($update_query, __FILE__, __LINE__); } - header("Location: exercise_show.php?id=$exeId&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id"); + header("Location: exercise_show.php?id=$exe_id&exerciseType=$exerciseType&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id"); } exit (); } @@ -1013,7 +1009,8 @@ if (!empty ($error)) { } $s = "

$exerciseDescription

"; - if ($exerciseType == 2) { + if ($exerciseType == 2) + { $s2 = "&exerciseId=" . $exerciseId; } diff --git a/main/exercice/exercise_result.php b/main/exercice/exercise_result.php index 0808a47917..6b0aef220d 100644 --- a/main/exercice/exercise_result.php +++ b/main/exercice/exercise_result.php @@ -29,7 +29,7 @@ * @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 20288 2009-05-04 17:48:40Z juliomontoya $ +* @version $Id: exercise_result.php 20351 2009-05-05 23:59:13Z cvargas1 $ * * @todo split more code up in functions, move functions to library? */ @@ -38,11 +38,10 @@ INIT SECTION ============================================================================== */ -include('exercise.class.php'); -include('question.class.php'); -include('answer.class.php'); -if($_GET['origin']=='learnpath') -{ +require_once('exercise.class.php'); +require_once('question.class.php'); +require_once('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'); @@ -50,30 +49,20 @@ if($_GET['origin']=='learnpath') 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'); +require('../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'); +require_once(api_get_path(LIBRARY_PATH).'events.lib.inc.php'); +require_once(api_get_path(LIBRARY_PATH).'mail.lib.inc.php'); +require_once(api_get_path(LIBRARY_PATH).'course.lib.php'); // Database table definitions $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); @@ -86,20 +75,20 @@ $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 +//temp values to move to admin settings $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'."
\n";var_dump($_POST);} // general parameters passed via POST/GET if ( empty ( $origin ) ) { - $origin = $_REQUEST['origin']; + $origin = Security::remove_XSS($_REQUEST['origin']); } if ( empty ( $learnpath_id ) ) { - $learnpath_id = $_REQUEST['learnpath_id']; + $learnpath_id = Security::remove_XSS($_REQUEST['learnpath_id']); } if ( empty ( $learnpath_item_id ) ) { - $learnpath_item_id = $_REQUEST['learnpath_item_id']; + $learnpath_item_id = Security::remove_XSS($_REQUEST['learnpath_item_id']); } if ( empty ( $formSent ) ) { $formSent = $_REQUEST['formSent']; @@ -135,30 +124,31 @@ if($_configuration['live_exercise_tracking'] == true && $exerciseType == 1){ $_configuration['live_exercise_tracking'] = false; } +// set admin name as person who sends the results e-mail (lacks policy about whom should really send the results) $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"; +$query = "SELECT user_id FROM $main_admin_table LIMIT 1"; //get all admins from 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 the above variables are empty or incorrect, we don't have any result to show, so stop the script if(!is_array($exerciseResult) || !is_array($questionList) || !is_object($objExercise)) { header('Location: exercice.php'); exit(); } +// define basic exercise info to print on screen $exerciseTitle=$objExercise->selectTitle(); $exerciseDescription=$objExercise->selectDescription(); $exerciseDescription=stripslashes($exerciseDescription); +$gradebook = ''; if (isset($_SESSION['gradebook'])){ $gradebook= $_SESSION['gradebook']; } @@ -286,16 +276,12 @@ $htmlHeadXtra[] = ""; -if ($origin != 'learnpath') -{ +if ($origin != 'learnpath') { //so we are not in learnpath tool Display::display_header($nameTools,"Exercise"); -} -else -{ +} else { - if(empty($charset)) - { + if (empty($charset)) { $charset = 'ISO-8859-15'; } header('Content-Type: text/html; charset='. $charset); @@ -317,29 +303,24 @@ else "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> - + - - - results_disabled) -{ +if ($objExercise->results_disabled) { ob_start(); } /* -============================================================================== - FUNCTIONS -============================================================================== +FUNCTIONS */ + function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect) { ?> @@ -452,12 +433,10 @@ function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComme } /* -============================================================================== - MAIN CODE -============================================================================== +DISPLAY AND MAIN PROCESS */ -// I'm in a preview mode +// I'm in a preview mode as course admin. Display the action menu. if (api_is_course_admin() && $origin != 'learnpath') { echo '
'; echo Display::return_icon('quiz.gif', get_lang('GoBackToEx')).''.get_lang('GoBackToEx').''; @@ -467,6 +446,7 @@ if (api_is_course_admin() && $origin != 'learnpath') { $exerciseTitle=api_parse_tex($exerciseTitle); +//show exercise title ?>

:

@@ -479,69 +459,59 @@ $exerciseTitle=api_parse_tex($exerciseTitle); 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]; - // 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; - } - ?> - - - - - - - - +$i=$totalScore=$totalWeighting=0; +if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);} + +if ($_configuration['tracking_enabled']) { + // Create an empty exercise + $exeId= create_event_exercice($objExercise->selectId()); +} +$counter=0; + +// Loop over all question to show results for each of them, one by one +foreach ($questionList as $questionId) { + $counter++; + // gets the student choice for this question + $choice=$exerciseResult[$questionId]; + // creates a temporary Question object + $objQuestionTmp = Question :: read($questionId); + // initialize question information + $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); + + // decide how many columns we want to use to show the results of each type + 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; + } + // show titles + if ($origin != 'learnpath') {?> +
- -
- -
+ + + + + + 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]); + } + + // 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; + // 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]'); + // 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); - } + 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) + $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) { - // 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 .= ']'; + // 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 } - - $answer=''; - $real_correct_tags = $correct_tags; - $chosen_list=array(); - - for($i=0;$i'; - } - 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.=''.stripslashes($user_tags[$i]).''; - } - 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.=' / '.$real_correct_tags[$i].']'; - if ( isset( $real_text[$i+1] ) ) { - $answer.=$real_text[$i+1]; - } - } - break; - // for free answer - case FREE_ANSWER : - $studentChoice=$choice; - - if($studentChoice) + // 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) { - //Score is at -1 because the question has'nt been corected - $questionScore=-1; - $totalScore+=0; + // adds the end of the text + $answer.=$temp; + break; } - - - break; - // for matching - case MATCHING : - if($answerCorrect) + $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'; } else { - $choice[$answerId]=''.$matching[$choice[$answerId]].''; + // 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.=''.stripslashes($user_tags[$i]).''; } + else + { + // adds a tabulation if no word has been typed by the student + $answer.='   '; + } } - else - { - $matching[$answerId]=$answer; - } - break; - // for hotspot with no order - case HOT_SPOT : - $studentChoice=$choice[$answerId]; - if($studentChoice) - { - $questionScore+=$answerWeighting; - $totalScore+=$answerWeighting; - } + // adds the correct word, followed by ] to close the blank + $answer.=' / '.$real_correct_tags[$i].']'; + if ( isset( $real_text[$i+1] ) ) { + $answer.=$real_text[$i+1]; + } + } + break; + // for free answer + case FREE_ANSWER : + $studentChoice=$choice; - break; - // for hotspot with fixed order - case HOT_SPOT_ORDER : - $studentChoice=$choice['order'][$answerId]; + if($studentChoice) + { + //Score is at -1 because the question has'nt been corected + $questionScore=-1; + $totalScore+=0; + } - if($studentChoice == $answerId) + + break; + // for matching + case MATCHING : + if($answerCorrect) + { + if($answerCorrect == $choice[$answerId]) { $questionScore+=$answerWeighting; $totalScore+=$answerWeighting; - $studentChoice = true; + $choice[$answerId]=$matching[$choice[$answerId]]; + } + elseif(!$choice[$answerId]) + { + $choice[$answerId]='   '; } else { - $studentChoice = false; + $choice[$answerId]=''.$matching[$choice[$answerId]].''; } - - break; - } // end switch Answertype - - if($answerType != MATCHING || $answerCorrect) - { - if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) - { - if ($origin!='learnpath') { - display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect); - } - } - elseif($answerType == FILL_IN_BLANKS) - { - if ($origin!='learnpath') { - 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); + $matching[$answerId]=$answer; + } + break; + // for hotspot with no order + case HOT_SPOT : + $studentChoice=$choice[$answerId]; + if ($studentChoice) { //the answer was right + $questionScore+=$answerWeighting; + $totalScore+=$answerWeighting; + } + $tbl_track_e_hotspot = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); + $sql_verified='SELECT COUNT(*) AS count FROM '.$tbl_track_e_hotspot.' WHERE hotspot_user_id="'.Database :: escape_string($_user['user_id']).'" AND hotspot_course_code="'.Database :: escape_string($_course['id']).'" + AND hotspot_question_id="'.Database :: escape_string($questionId).'" AND hotspot_answer_id="'.Database :: escape_string($answerId).'" AND hotspot_correct="'. Database :: escape_string($studentChoice).'" AND hotspot_coordinate="'.Database :: escape_string($_SESSION['exerciseResultCoordinates'][$questionId][$answerId]).'" ;'; + $res_verified=Database::query($sql_verified,__FILE__,__LINE__); + $my_count_result=Database::result($res_verified,0,0); + if ($my_count_result==0) { + $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__); } - $num = count($teachers); - if($num>1) + break; + // for hotspot with fixed order + case HOT_SPOT_ORDER : + $studentChoice=$choice['order'][$answerId]; + + if($studentChoice == $answerId) { - $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) + $questionScore+=$answerWeighting; + $totalScore+=$answerWeighting; + $studentChoice = true; } - if($origin != 'learnpath') { - display_free_answer($choice); + else + { + $studentChoice = false; } - + + break; + } // end switch Answertype + + //display answers (if not matching type, or if the answer is correct) + if ($answerType != MATCHING || $answerCorrect) { + if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) { + if ($origin!='learnpath') { + display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect); } - elseif($answerType == HOT_SPOT) - { - if ($origin != 'learnpath') { - display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment); - } + } elseif($answerType == FILL_IN_BLANKS) { + if ($origin!='learnpath') { + display_fill_in_blanks_answer($answer); } - elseif($answerType == HOT_SPOT_ORDER) + } 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'])) { - display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment); + $teachers = CourseManager::get_coach_list_from_course_code($coursecode,$_SESSION['id_session']); } else { - if ($origin != 'learnpath') { - ?> - - - - - 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) } - } - } // 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 if($origin != 'learnpath') { - echo "
+ +
+ +
@@ -558,7 +528,7 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
@@ -566,7 +536,7 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
@@ -577,7 +547,7 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
@@ -597,7 +567,7 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
@@ -609,463 +579,470 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
- - - / - -
"; - ?> - - - -

- - - - - - - - - - -

- - - - - ([0-9a-z ]*)#', $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__); - if (Database::num_rows($res)>0) { - $answer = Database::result($res,0,"position"); - } else { - $answer = 0; - } - exercise_attempt($questionScore,$answer,$quesId,$exeId,$j); + elseif($answerType == HOT_SPOT) + { + if ($origin != 'learnpath') { + display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment); } } - elseif ($answerType==FREE_ANSWER) { - $answer = $choice; - exercise_attempt($questionScore,$answer,$quesId,$exeId,0); + elseif($answerType == HOT_SPOT_ORDER) + { + display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment); } - 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,0 ,$quesId,$exeId,0); + else + { + if ($origin != 'learnpath') { + ?> + + + + + + / + + + + "; //echo Security::remove_XSS($questionId); + ?> + + + +

+ + + + + + - - - - -
+ - - -
-
- - - + ?>

- - + + ([0-9a-z ]*)#', $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__); + if (Database::num_rows($res)>0) { + $answer = Database::result($res,0,"position"); + } else { + $answer = 0; + } + 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,0 ,$quesId,$exeId,0); + } + } else { + exercise_attempt($questionScore,$answer,$quesId,$exeId,0); + } + } +} // end huge foreach() block that loops over all questions +?> + + + + + + + + +
+ + + +
+
+ + + +
+ + -

-
+'; } echo ''; - } else if($answerType == HOTSPOT) { + } else if($answerType == HOT_SPOT) { ?> @@ -888,7 +880,7 @@ function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComme ?> - - diff --git a/main/exercice/hotspot.class.php b/main/exercice/hotspot.class.php index 10f3b4d61d..269088a949 100644 --- a/main/exercice/hotspot.class.php +++ b/main/exercice/hotspot.class.php @@ -1,22 +1,6 @@ -
- +
selectAnswer($answerId); @@ -911,13 +903,12 @@ function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComme ?>
- - + + '. + // + ' +