From 65b7169eec4974c09aa661d4a9dbd77d7b5a65d2 Mon Sep 17 00:00:00 2001 From: Cristian Fasanando Date: Mon, 16 Feb 2009 23:09:02 +0100 Subject: [PATCH] [svn r18530] Fixing big typo FS#3510 --- main/exercice/exercice_submit.php | 322 +----------------------------- 1 file changed, 8 insertions(+), 314 deletions(-) diff --git a/main/exercice/exercice_submit.php b/main/exercice/exercice_submit.php index 22fb3fd68e..02c8451822 100644 --- a/main/exercice/exercice_submit.php +++ b/main/exercice/exercice_submit.php @@ -1,4 +1,4 @@ -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'; - } 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.=''.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) { - //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]=''.$matching[$choice[$answerId]].''; - } - } 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([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 = ''; - } - 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 + //START of saving and qualifying each question submitted //------------------------------------------------------------------------------------------ // define('ENABLED_LIVE_EXERCISE_TRACKING',1); @@ -852,12 +546,12 @@ if ($formSent) { 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 - //------------------------------------------------------------------------------------------ + } + // end huge foreach() block that loops over all questions + //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__); + $sql_update = 'UPDATE '.$stat_table.' SET exe_result = exe_result + '.(int)$totalScore.',exe_weighting = exe_weighting + '.(int)$totalWeighting.' WHERE exe_id = '.$exe_id; + api_sql_query($sql_update ,__FILE__,__LINE__); //END of saving and qualifying //------------------------------------------------------------------------------------------ //