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']; } if ( empty ( $learnpath_id ) ) { $learnpath_id = $_REQUEST['learnpath_id']; } if ( empty ( $learnpath_item_id ) ) { $learnpath_item_id = $_REQUEST['learnpath_item_id']; } if ( empty ( $formSent ) ) { $formSent = $_REQUEST['formSent']; } if ( empty ( $exerciseResult ) ) { $exerciseResult = $_SESSION['exerciseResult']; } if ( empty ( $questionId ) ) { $questionId = $_REQUEST['questionId']; } if ( empty ( $choice ) ) { $choice = $_REQUEST['choice']; } if ( empty ( $questionNum ) ) { $questionNum = $_REQUEST['questionNum']; } if ( empty ( $nbrQuestions ) ) { $nbrQuestions = $_REQUEST['nbrQuestions']; } if ( empty ( $questionList ) ) { $questionList = $_SESSION['questionList']; } if ( empty ( $objExercise ) ) { $objExercise = $_SESSION['objExercise']; } $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN); $courseName = $_SESSION['_course']['name']; $query = "select user_id from $main_admin_table"; $admin_id = mysql_result(api_sql_query($query),0,"user_id"); $uinfo = api_get_user_info($admin_id); $from = $uinfo['mail']; $from_name = $uinfo['firstname'].' '.$uinfo['lastname']; $str = $_SERVER['REQUEST_URI']; $arr = explode('/',$str); $url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result'; //$url = $_SERVER['SERVER_NAME'].'/'.$arr[1].'/'; // if the above variables are empty or incorrect, stops the script if(!is_array($exerciseResult) || !is_array($questionList) || !is_object($objExercise)) { header('Location: exercice.php'); exit(); } $exerciseTitle=$objExercise->selectTitle(); $exerciseDescription=$objExercise->selectDescription(); $exerciseDescription=stripslashes($exerciseDescription); $nameTools=get_lang('Exercice'); $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices')); $htmlHeadXtra[] = " "; if ($origin != 'learnpath') { //so we are not in learnpath tool Display::display_header($nameTools,"Exercise"); } else { if(empty($charset)) { $charset = 'ISO-8859-15'; } header('Content-Type: text/html; charset='. $charset); @$document_language = Database::get_language_isocode($language_interface); if(empty($document_language)) { //if there was no valid iso-code, use the english one $document_language = 'en'; } /* * HTML HEADER */ ?> results_disabled) { ob_start(); } /* ============================================================================== FUNCTIONS ============================================================================== */ function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect) { ?>

:

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(); } $counter=0; foreach($questionList as $questionId) { $counter++; // gets the student choice for this question $choice=$exerciseResult[$questionId]; //print_r($choice); echo "
"; // 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; } ?>
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]); } // 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) { //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 if($answerType != MATCHING || $answerCorrect) { if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) { display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect); } elseif($answerType == FILL_IN_BLANKS) { display_fill_in_blanks_answer($answer); } elseif($answerType == FREE_ANSWER) { // to store the details of open questions in an array to be used in mail $arrques[] = $questionName; $arrans[] = $choice; $firstName = $_SESSION['_user']['firstName']; $lastName = $_SESSION['_user']['lastName']; $mail = $_SESSION['_user']['mail']; $coursecode = $_SESSION['_course']['id']; $to = ''; $teachers = array(); if(api_get_setting('use_session_mode')=='true' && !empty($_SESSION['id_session'])) { $teachers = CourseManager::get_coach_list_from_course_code($coursecode,$_SESSION['id_session']); } else { $teachers = CourseManager::get_teacher_list_from_course_code($coursecode); } $num = count($teachers); if($num>1) { $to = array(); foreach($teachers as $teacher) { $to[] = $teacher['email']; } }elseif($num>0){ foreach($teachers as $teacher) { $to = $teacher['email']; } }else{ //this is a problem (it means that there is no admin for this course) } display_free_answer($choice); } elseif($answerType == HOT_SPOT) { $tbl_track_e_hotspot = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); // Save into db $sql = "INSERT INTO $tbl_track_e_hotspot (`hotspot_user_id` , `hotspot_course_code` , `hotspot_exe_id` , `hotspot_question_id` , `hotspot_answer_id` , `hotspot_correct` , `hotspot_coordinate` ) VALUES ('".Database::escape_string($_user['user_id'])."', '".Database::escape_string($_course['id'])."', '".Database::escape_string($exeId)."', '".Database::escape_string($questionId)."', '".Database::escape_string($answerId)."', '".Database::escape_string($studentChoice)."', '".Database::escape_string($_SESSION['exerciseResultCoordinates'][$questionId][$answerId])."')"; $result = api_sql_query($sql,__FILE__,__LINE__); display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment); } elseif($answerType == HOT_SPOT_ORDER) { display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment); } else { ?> "; ?>








/




([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__); $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 ?>


selectId(),$totalScore,$totalWeighting,$answer,$question_id); } if($objExercise->results_disabled) { ob_end_clean(); Display :: display_normal_message(get_lang('ExerciseFinished').'
'.get_lang('Back').'',false); } if ($origin != 'learnpath') { //we are not in learnpath tool Display::display_footer(); }else{ //record the results in the learning path, using the SCORM interface (API) echo ''."\n"; echo ''; } if(count($arrques)>0) { $mycharset = api_get_setting('platform_charset'); $msg = ' '; $msg .= '

'.get_lang('OpenQuestionsAttempted').' :

'.get_lang('AttemptDetails').' : >

  '.get_lang('CourseName').'

#course#

  '.get_lang('TestAttempted').' #exercise#
  '.get_lang('StudentName').' #firstName# #lastName#
  '.get_lang('StudentEmail').' #mail#


'.get_lang('OpenQuestionsAttemptedAre').' :

'; for($i=0;$i '; $msg1= str_replace("#exercise#",$exerciseTitle,$msg); $msg= str_replace("#firstName#",$firstName,$msg1); $msg1= str_replace("#lastName#",$lastName,$msg); $msg= str_replace("#mail#",$mail,$msg1); $msg1= str_replace("#questionName#",$arrques[$i],$msg); $msg= str_replace("#answer#",$arrans[$i],$msg1); $msg1= str_replace("#i#",$i,$msg); $msg= str_replace("#course#",$courseName,$msg1); } $msg.='
#questionName#
  '.get_lang('Answer').' #answer#

'.get_lang('ClickToCommentAndGiveFeedback').',
#url#
'; $msg1= str_replace("#url#",$url,$msg); $mail_content = stripslashes($msg1); $student_name = $_SESSION['_user']['firstName'].' '.$_SESSION['_user']['lastName']; $subject = get_lang('OpenQuestionsAttempted'); $from = api_get_setting('noreply_email_address'); if($from == ''){ if(isset($_SESSION['id_session']) && $_SESSION['id_session'] != ''){ $sql = 'SELECT user.email,user.lastname,user.firstname FROM '.TABLE_MAIN_SESSION.' as session, '.TABLE_MAIN_USER.' as user WHERE session.id_coach = user.user_id AND session.id = "'.Database::escape_string($_SESSION['id_session']).'" '; $result=api_sql_query($sql,__FILE__,__LINE__); $from = mysql_result($result,0,'email'); $from_name = mysql_result($result,0,'firstname').' '.mysql_result($result,0,'lastname'); } else{ $array = explode(' ',$_SESSION['_course']['titular']); $firstname = $array[1]; $lastname = $array[0]; $sql = 'SELECT email,lastname,firstname FROM '.TABLE_MAIN_USER.' WHERE firstname = "'.Database::escape_string($firstname).'" AND lastname = "'.Database::escape_string($lastname).'" '; $result=api_sql_query($sql,__FILE__,__LINE__); $from = mysql_result($result,0,'email'); $from_name = mysql_result($result,0,'firstname').' '.mysql_result($result,0,'lastname'); } } api_mail_html($student_name, $to, $subject, $mail_content, $from_name, $from, array('encoding'=>$mycharset,'charset'=>$mycharset)); } ?>