0 ){ if($exerciseType == 2){ $getIncomplete = mysql_fetch_array($sql); $exe_id = $getIncomplete['exe_id']; if($_SERVER['REQUEST_METHOD']!='POST'){ define('QUESTION_LIST_ALREADY_LOGGED',1); api_sql_query('UPDATE '.$stat_table.' SET steps_counter = steps_counter + 1'.$condition,__FILE__,__LINE__); $recorded['questionList'] = explode(',',$getIncomplete['data_tracking']); //selecting all the answered question from database for //building the answers array, taking care of handling "multiple answers" behavior. $sql = api_sql_query('SELECT * FROM '.$exercice_attemp_table.' WHERE exe_id = '.$getIncomplete['exe_id'].' ORDER BY tms ASC',__FILE__,__LINE__); while($row = mysql_fetch_array($sql)){ if(array_key_exists($row['question_id'],$recorded['exerciseResult'])){ if(!is_array($recorded['exerciseResult'][$row['question_id']])){ $last_value = $recorded['exerciseResult'][$row['question_id']]; $recorded['exerciseResult'][$row['question_id']] = array(); $recorded['exerciseResult'][$row['question_id']][$last_value] = 1; } $recorded['exerciseResult'][$row['question_id']][$row['answer']] = 1; } else { $recorded['exerciseResult'][$row['question_id']] = $row['answer']; } } $_SESSION['exerciseResult'] = $recorded['exerciseResult']; $exerciseType = 2; $questionNum = count($recorded['exerciseResult']); //$questionNum = $questionList[$questionNum]; $questionList = $_SESSION['questionList'] = array_combine(range(1,count($recorded['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'."
\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'."
\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): $nro_question = $questionNum;// - 1; // for multiple answers if(is_array($choice[$key])){ foreach ($choice[$key] as $key_array => $value){ api_sql_query('INSERT INTO '.$exercice_attemp_table.' (exe_id,user_id,question_id,answer,marks,course_code,position,tms)'. ' VALUES '. '('."'".(int)$exe_id."','".api_get_user_id()."','".$questionList[$nro_question]."','".Database::escape_string($key_array)."','','".$_course['id']."','".$position."','".date('Y-m-d H:i:s')."'".')'); } } else { api_sql_query('INSERT INTO '.$exercice_attemp_table.' (exe_id,user_id,question_id,answer,marks,course_code,position,tms)'. ' VALUES '. '('."'".(int)$exe_id."','".api_get_user_id()."','".$questionList[$nro_question]."','".Database::escape_string($choice[$key])."','','".$_course['id']."','".$position."','".date('Y-m-d H:i:s')."'".')'); } endif; if (isset($_POST['hotspot'])) { $exerciseResultCoordinates[$key] = $_POST['hotspot'][$key]; } } } if($debug>0){echo str_repeat(' ',0).'$choice is an array - end'."
\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'."
\n";} // goes to the script that will show the result of the exercise header("Location: exercise_result.php?exerciseType=$exerciseType&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id"); exit(); } if($debug>0){echo str_repeat(' ',0).'$formSent was set - end'."
\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'."
\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'."
\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'."
\n";} // selects the list of question ID $questionList = $objExercise->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'."
\n";} } if(!isset($objExcercise) && isset($_SESSION['objExercise'])){ $questionList = $_SESSION['questionList']; } $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[] = " "; 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 */ ?> ".$exerciseTitle.""; if( $exerciseAttempts > 0){ $user_id = api_get_user_id(); $course_code = api_get_course_id(); $sql = 'SELECT count(*) FROM '.Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES).' WHERE exe_exo_id = '.$quizID.' '. "and status != 'incomplete' ". 'and exe_user_id = '.$user_id.' '. "and exe_cours_id = '$course_code'"; $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('ReachedMaxAttemptsAdmin'),$exerciseTitle,$exerciseAttempts)); } else { Display::display_warning_message(sprintf(get_lang('ReachedMaxAttempts'),$exerciseTitle,$exerciseAttempts)); Display::display_footer(); exit; } } } 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').' %s' : get_lang('ReachedTimeLimit') ; Display::display_warning_message(sprintf($message_warning,(($permission_to_start == false)?$Exe_starttime:$Exe_endttime))); 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 "", ",get_lang('Sound')."; } // 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="

$exerciseDescription

"; if($origin == 'learnpath' && $exerciseType==2){ $s2 = "&exerciseId=".$exerciseId; } $s.="
"; 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 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 ''; break; } } } $s="
'.get_lang('AlreadyAnswered').' "'.$questionName.'"
".get_lang('Question')." "; $s.=$i.' : '; if($exerciseType == 2) $s.=' / '.$nbrQuestions.' '; echo $s; // shows the question and its answers showQuestion($questionId, false, $origin); // for sequential exercises if($exerciseType == 2) { // quits the loop break; } } // end foreach() $s="
'; $s.="
"; $b=2; echo $s; } //creating empty exercise if incomplete not exist if($_configuration['live_exercise_tracking'] == true): //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) ' . 'VALUES ' . '('."'$exerciseId','".api_get_user_id()."','".$_course['id']."','incomplete','".api_get_session_id()."','".implode(',',$questionList)."','".date('Y-m-d H:i:s')."'".') ',__FILE__,__LINE__); } else { api_sql_query('INSERT INTO '.$stat_table.' ' . '(exe_exo_id,exe_user_id,exe_cours_id,status,session_id,start_date) ' . 'VALUES ' . '('."'$exerciseId','".api_get_user_id()."','".$_course['id']."','incomplete','".api_get_session_id()."','".date('Y-m-d H:i:s')."'".') ',__FILE__,__LINE__); } } endif; if ($origin != 'learnpath') { //so we are not in learnpath tool Display::display_footer(); } //var_dump($questionList); ?>