From 0737d389bb85092e88b5fc67423ae204c0bafe6a Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 28 Aug 2012 14:41:29 +0200 Subject: [PATCH] Fixing Scenario errors see #5375 --- main/css/academica/default.css | 31 +- main/css/baby_orange/default.css | 31 +- main/css/base_chamilo.css | 23 -- main/css/chamilo/default.css | 8 - main/exercice/admin.php | 7 +- main/exercice/answer.class.php | 26 +- main/exercice/exercise.class.php | 12 +- main/exercice/exercise_show.php | 2 +- main/exercice/exercise_submit.php | 2 +- main/exercice/exercise_submit_modal.php | 423 ++++++++++++------------ main/exercice/hotspot_admin.inc.php | 4 +- main/exercice/multiple_answer.class.php | 5 +- main/exercice/question_admin.inc.php | 12 +- main/exercice/testcategory.class.php | 4 +- main/exercice/unique_answer.class.php | 64 ++-- main/inc/lib/autoload.class.php | 1 + main/inc/lib/pear/HTML/QuickForm.php | 4 +- 17 files changed, 284 insertions(+), 375 deletions(-) diff --git a/main/css/academica/default.css b/main/css/academica/default.css index 1c1296ed5a..420bcb160d 100644 --- a/main/css/academica/default.css +++ b/main/css/academica/default.css @@ -699,21 +699,7 @@ div.lp_resource_elements { .exercice_form { width: 300px; } -#validationButton { - text-decoration: none; - margin: 5px; - border:1px solid #999999; - background:#F0F0F0; - padding: 3px; - padding-left:10px; - padding-right:10px; - font-weight:bold; - color:#666; -} -.exercise_scenario_label { -} -.exercise_scenario_element { -} + span.checkbox { width: 19px; height: 25px; @@ -1282,21 +1268,6 @@ ul#navigation .help a{ .exercice_form { width: 300px; } -#validationButton { - text-decoration: none; - margin: 5px; - /*border:1px solid #999999;*/ - /*background:#F0F0F0; */ - padding: 3px; - padding-left:10px; - padding-right:10px; - font-weight:bold; - color:#666; -} -.exercise_scenario_label { -} -.exercise_scenario_element { -} span.checkbox { width: 19px; height: 25px; diff --git a/main/css/baby_orange/default.css b/main/css/baby_orange/default.css index e9425d7160..aa7baf6189 100644 --- a/main/css/baby_orange/default.css +++ b/main/css/baby_orange/default.css @@ -687,21 +687,7 @@ div.lp_resource_elements { .exercice_form { width: 300px; } -#validationButton { - text-decoration: none; - margin: 5px; - border:1px solid #999999; - background:#F0F0F0; - padding: 3px; - padding-left:10px; - padding-right:10px; - font-weight:bold; - color:#666; -} -.exercise_scenario_label { -} -.exercise_scenario_element { -} + span.checkbox { width: 19px; height: 25px; @@ -1258,21 +1244,6 @@ ul#navigation .help a{ .exercice_form { width: 300px; } -#validationButton { - text-decoration: none; - margin: 5px; - /*border:1px solid #999999;*/ - /*background:#F0F0F0; */ - padding: 3px; - padding-left:10px; - padding-right:10px; - font-weight:bold; - color:#666; -} -.exercise_scenario_label { -} -.exercise_scenario_element { -} span.checkbox { width: 19px; height: 25px; diff --git a/main/css/base_chamilo.css b/main/css/base_chamilo.css index 312127f661..277c59611d 100755 --- a/main/css/base_chamilo.css +++ b/main/css/base_chamilo.css @@ -1256,22 +1256,7 @@ padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0p .exercice_form { width: 300px; } -#validationButton { - text-decoration: none; - margin: 5px; - /*border:1px solid #999999;*/ - /*background:#F0F0F0; */ - padding: 3px; - padding-left:10px; - padding-right:10px; - font-weight:bold; - color:#666; -} -.exercise_scenario_label { -} -.exercise_scenario_element { -} span.checkbox { width: 19px; height: 25px; @@ -1289,14 +1274,6 @@ span.radio { float: left; } - -#exercise_close_link { - padding-left: 20px; -} -#exercise_close_link:hover { - padding-left: 20px; -} - .icon_image_content { width:70px; cursor:hand; diff --git a/main/css/chamilo/default.css b/main/css/chamilo/default.css index 0c7a931816..a6e04b2190 100644 --- a/main/css/chamilo/default.css +++ b/main/css/chamilo/default.css @@ -118,14 +118,6 @@ footer { background:transparent url('images/textologo.jpg') no-repeat; } -#exercise_close_link { - background: url(images/close.gif) no-repeat; -} - -#exercise_close_link:hover { - background: url(images/close_highlight.gif) no-repeat; -} - /*including "login" image*/ button.login { background-image:url(images/bg-button.gif); diff --git a/main/exercice/admin.php b/main/exercice/admin.php index a5ca24bf9c..287d714cb3 100644 --- a/main/exercice/admin.php +++ b/main/exercice/admin.php @@ -135,7 +135,7 @@ $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; $picturePath = $documentPath.'/images'; // audio path -$audioPath=$documentPath.'/audio'; +$audioPath = $documentPath.'/audio'; // the 5 types of answers $aType = array(get_lang('UniqueSelect'),get_lang('MultipleSelect'),get_lang('FillBlanks'),get_lang('Matching'),get_lang('FreeAnswer')); @@ -151,8 +151,7 @@ $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); if ($_GET['action'] == 'exportqti2' && !empty($_GET['questionId'])) { require_once 'export/qti2/qti2_export.php'; $export = export_question($_GET['questionId'],true); - $qid = (int)$_GET['questionId']; - require_once(api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php'); + $qid = (int)$_GET['questionId']; $archive_path = api_get_path(SYS_ARCHIVE_PATH); $temp_dir_short = uniqid(); $temp_zip_dir = $archive_path."/".$temp_dir_short; @@ -217,8 +216,6 @@ if ($editQuestion || $newQuestion || $modifyQuestion || $modifyAnswers) { } } - - // if cancelling an exercise if ($cancelExercise) { // existing exercise diff --git a/main/exercice/answer.class.php b/main/exercice/answer.class.php index 740b0dce3c..db06b5bcad 100644 --- a/main/exercice/answer.class.php +++ b/main/exercice/answer.class.php @@ -420,7 +420,7 @@ class Answer { * @param coordinates Coordinates for hotspot exercises (optional) * @param integer Type for hotspot exercises (optional) */ - function createAnswer($answer,$correct,$comment,$weighting,$position,$new_hotspot_coordinates = NULL, $new_hotspot_type = NULL,$destination='') { + function createAnswer($answer,$correct,$comment,$weighting,$position,$new_hotspot_coordinates = null, $new_hotspot_type = null, $destination='') { $this->new_nbrAnswers++; $id=$this->new_nbrAnswers; $this->new_answer[$id]=$answer; @@ -430,7 +430,7 @@ class Answer { $this->new_position[$id]=$position; $this->new_hotspot_coordinates[$id]=$new_hotspot_coordinates; $this->new_hotspot_type[$id]=$new_hotspot_type; - $this->new_destination[$id]=$destination; + $this->new_destination[$id] = $destination; } /** @@ -446,14 +446,14 @@ class Answer { $TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER); $questionId=$this->questionId; - $sql = "UPDATE $TBL_REPONSES SET " . - "answer = '".Database::escape_string($answer)."', " . - "comment = '".Database::escape_string($comment)."', " . - "ponderation = '".Database::escape_string($weighting)."', " . - "position = '".Database::escape_string($position)."', " . - "destination = '".Database::escape_string($destination)."' " . - "WHERE c_id = {$this->course_id} AND id = '".Database::escape_string($position)."' " . - "AND question_id = '".Database::escape_string($questionId)."'"; + $sql = "UPDATE $TBL_REPONSES SET + answer = '".Database::escape_string($answer)."', + comment = '".Database::escape_string($comment)."', + ponderation = '".Database::escape_string($weighting)."', + position = '".Database::escape_string($position)."', + destination = '".Database::escape_string($destination)."' + WHERE c_id = {$this->course_id} AND id = '".Database::escape_string($position)."' + AND question_id = '".Database::escape_string($questionId)."'"; Database::query($sql); } @@ -469,9 +469,10 @@ class Answer { // removes old answers before inserting of new ones $sql = "DELETE FROM $TBL_REPONSES WHERE c_id = {$this->course_id} AND question_id = '".($questionId)."'"; Database::query($sql); + $c_id = $this->course['real_id']; // inserts new answers into data base - $sql = "INSERT INTO $TBL_REPONSES (c_id, id, question_id, answer,correct,comment, ponderation,position,hotspot_coordinates,hotspot_type,destination) VALUES "; + $sql = "INSERT INTO $TBL_REPONSES (c_id, id, question_id, answer, correct, comment, ponderation, position, hotspot_coordinates,hotspot_type, destination) VALUES "; for ($i=1;$i <= $this->new_nbrAnswers; $i++) { $answer = Database::escape_string($this->new_answer[$i]); $correct = Database::escape_string($this->new_correct[$i]); @@ -484,8 +485,7 @@ class Answer { $sql.="($c_id, '$i','$questionId','$answer','$correct','$comment','$weighting','$position','$hotspot_coordinates','$hotspot_type','$destination'),"; } - $sql = api_substr($sql,0,-1); - + $sql = api_substr($sql,0,-1); Database::query($sql); // moves $new_* arrays diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index d87d758ce6..9c999cc341 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -1587,10 +1587,14 @@ class Exercise { $hotspot_get = isset($_POST['hotspot']) ? Security::remove_XSS($_POST['hotspot']):null; $all_button = ''; - if ($this->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT && $this->type == ONE_PER_PAGE) { - $html .=''; - $html .= get_lang('EndTest').''; - $html .='
'; + if ($this->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT && $this->type == ONE_PER_PAGE) { + $html .=''; + if ($questionNum == count($this->questionList)) { + $html .= get_lang('EndTest').''; + } else { + $html .= get_lang('ContinueTest').''; + } + $html .='
'; } else { //User if (api_is_allowed_to_session_edit()) { diff --git a/main/exercice/exercise_show.php b/main/exercice/exercise_show.php index cf678e1b5a..b177453bd2 100644 --- a/main/exercice/exercise_show.php +++ b/main/exercice/exercise_show.php @@ -52,7 +52,7 @@ 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 ( $questionNum ) ) { $questionNum = $_REQUEST['num'];} if ( empty ( $nbrQuestions ) ) { $nbrQuestions = $_REQUEST['nbrQuestions'];} if ( empty ( $questionList ) ) { $questionList = $_SESSION['questionList'];} if ( empty ( $objExercise ) ) { $objExercise = $_SESSION['objExercise'];} diff --git a/main/exercice/exercise_submit.php b/main/exercice/exercise_submit.php index 85dc5adbe0..3d9b4db663 100644 --- a/main/exercice/exercise_submit.php +++ b/main/exercice/exercise_submit.php @@ -87,7 +87,7 @@ if (empty ($exerciseResultCoordinates)) { $choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null; $choice = empty($choice) ? $_REQUEST['choice2'] : null; -$questionNum = isset($_REQUEST['questionNum']) ? intval($_REQUEST['questionNum']) : null; +//From submit modal $current_question = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : null; //Error message diff --git a/main/exercice/exercise_submit_modal.php b/main/exercice/exercise_submit_modal.php index a501ecc3b0..37920a072c 100644 --- a/main/exercice/exercise_submit_modal.php +++ b/main/exercice/exercise_submit_modal.php @@ -10,14 +10,16 @@ use \ChamiloSession as Session; -$language_file=array('exercice'); +$language_file = array('exercice'); require_once '../inc/global.inc.php'; api_protect_course_script(false); + require_once api_get_path(LIBRARY_PATH).'geometry.lib.php'; Display::display_reduced_header(); $dbg_local = 0; + require_once 'exercise.class.php'; require_once 'question.class.php'; require_once 'answer.class.php'; @@ -47,9 +49,9 @@ $questionList = $_SESSION['questionList']; $exerciseId = intval($_GET['exerciseId']); $exerciseType = intval($_GET['exerciseType']); -$questionNum = intval($_GET['questionnum']); -$nbrQuestions = intval($_GET['nbrQuestions']); +$questionNum = intval($_GET['num']); +$nbrQuestions = intval($_GET['nbrQuestions']); //clean extra session variables Session::erase('objExerciseExtra'.$exerciseId); @@ -69,11 +71,13 @@ if (is_array($coords) && count($coords)>0){ $user_array = substr($user_array,0,-1); if (isset($_GET['choice'])){ - $choice_value = intval($_GET['choice']); + $choice_value = intval($_GET['choice']); } -// getting the options by js + +// Getting the options by js if (empty($choice_value)) { - echo ''; + echo 'window.location.href = "exercise_submit_modal.php?learnpath_id='.$learnpath_id.'&learnpath_item_id='.$learnpath_item_id.'&hotspotcoord="+ hotspotcoord + "&hotspot="+ hotspot + "&choice="+ choice_js + "&exerciseId='.$exerciseId.'&num='.$questionNum.'&exerciseType='.$exerciseType.'&origin='.$origin.'&gradebook='.$gradebook.'";'; } -$choice=array(); +$choice = array(); $questionid= $questionList[$questionNum]; // $choice_value => value of the user selection -$choice[$questionid]=$choice_value; +$choice[$questionid] = $choice_value; // initializing if(!is_array($exerciseResult)) { - $exerciseResult=array(); + $exerciseResult = array(); } - // if the user has answered at least one question -if(is_array($choice)) { - if($exerciseType == 1) { +if (is_array($choice)) { + if ($exerciseType == EXERCISE_FEEDBACK_TYPE_DIRECT) { // $exerciseResult receives the content of the form. // Each choice of the student is stored into the array $choice - $exerciseResult=$choice; + $exerciseResult = $choice; } else { // gets the question ID from $choice. It is the key of the array list($key)=array_keys($choice); @@ -146,8 +141,8 @@ if(is_array($choice)) { // the script "exercise_result.php" will take the variable $exerciseResult from the session -Session::write('exerciseResult',$exerciseResult); -Session::write('exerciseResultCoordinates',$exerciseResultCoordinates); +Session::write('exerciseResult', $exerciseResult); +Session::write('exerciseResultCoordinates', $exerciseResultCoordinates); /* // if it is the last question (only for a sequential exercise) @@ -162,6 +157,7 @@ if($questionNum >= $nbrQuestions) // gets the student choice for this question //print_r($choice); echo "
"; + // creates a temporary Question object if (in_array($questionid, $questionList)) { $objQuestionTmp = Question :: read($questionid); @@ -176,18 +172,21 @@ $objAnswerTmp=new Answer($questionid); $nbrAnswers=$objAnswerTmp->selectNbrAnswers(); //echo 'answe_type '.$answerType;echo '
'; -$choice=$exerciseResult[$questionid]; +$choice = $exerciseResult[$questionid]; $destination=array(); $comment=''; $next=1; -$_SESSION['hotspot_coord']=array(); -$_SESSION['hotspot_dest']=array(); -$overlap_color=$missing_color=$excess_color=false; -$organs_at_risk_hit=0; +$_SESSION['hotspot_coord'] = array(); +$_SESSION['hotspot_dest'] = array(); + +$overlap_color = $missing_color = $excess_color=false; +$organs_at_risk_hit = 0; $wrong_results = false; $hot_spot_load = false; + + if (!empty($choice_value)) { - for($answerId=1;$answerId <= $nbrAnswers;$answerId++) { + for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) { $answer = $objAnswerTmp->selectAnswer($answerId); $answerComment = $objAnswerTmp->selectComment($answerId); $answerDestination = $objAnswerTmp->selectDestination($answerId); @@ -204,8 +203,8 @@ if (!empty($choice_value)) { switch($answerType) { // for unique answer case UNIQUE_ANSWER : - $studentChoice=($choice_value == $numAnswer)?1:0; - if($studentChoice) { + $studentChoice = ($choice_value == $numAnswer)?1:0; + if ($studentChoice) { $questionScore +=$answerWeighting; $totalScore +=$answerWeighting; $newquestionList[]=$questionid; @@ -213,7 +212,7 @@ if (!empty($choice_value)) { break; case HOT_SPOT_DELINEATION : $studentChoice=$choice[$answerId]; - if($studentChoice) { + if ($studentChoice) { $newquestionList[]=$questionid; } if ($answerId===1) { @@ -226,158 +225,158 @@ if (!empty($choice_value)) { } - if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) { - //display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect); - //echo $questionScore; - if ($studentChoice) { - $destination=$answerDestination; - $comment=$answerComment; - } - } elseif($answerType == HOT_SPOT_DELINEATION) { - if ($next) { - if ($dbg_local>0) { error_log(__LINE__.' - next',0);} - $hot_spot_load = true; //apparently the script is called twice - $user_answer = $user_array; - $_SESSION['exerciseResultCoordinates'][$questionid]=$user_answer; //needed for exercise_result.php - - // we compare only the delineation not the other points - $answer_question = $_SESSION['hotspot_coord'][1]; - $answerDestination = $_SESSION['hotspot_dest'][1]; - - $poly_user = convert_coordinates($user_answer,'/'); - $poly_answer = convert_coordinates($answer_question,'|'); - $max_coord = poly_get_max($poly_user,$poly_answer); - - if (empty($_GET['hotspot'])) { //no user response - $overlap = -2; - } else { - $poly_user_compiled = poly_compile($poly_user,$max_coord); - $poly_answer_compiled = poly_compile($poly_answer,$max_coord); - $poly_results = poly_result($poly_answer_compiled,$poly_user_compiled,$max_coord); - - $overlap = $poly_results['both']; - $poly_answer_area = $poly_results['s1']; - $poly_user_area = $poly_results['s2']; - $missing = $poly_results['s1Only']; - $excess = $poly_results['s2Only']; - } - - //$overlap = round(polygons_overlap($poly_answer,$poly_user)); //this is an area in pixels - if ($dbg_local>0) { error_log(__LINE__.' - Polygons results are '.print_r($poly_results,1),0);} - if ($overlap < 1) { - //shortcut to avoid complicated calculations - $final_overlap = 0; - $final_missing = 100; - $final_excess = 100; + if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) { + //display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect); + //echo $questionScore; + if ($studentChoice) { + $destination = $answerDestination; + $comment = $answerComment; + } + } elseif($answerType == HOT_SPOT_DELINEATION) { + if ($next) { + if ($dbg_local>0) { error_log(__LINE__.' - next',0);} + $hot_spot_load = true; //apparently the script is called twice + $user_answer = $user_array; + $_SESSION['exerciseResultCoordinates'][$questionid]=$user_answer; //needed for exercise_result.php + + // we compare only the delineation not the other points + $answer_question = $_SESSION['hotspot_coord'][1]; + $answerDestination = $_SESSION['hotspot_dest'][1]; + + $poly_user = convert_coordinates($user_answer,'/'); + $poly_answer = convert_coordinates($answer_question,'|'); + $max_coord = poly_get_max($poly_user,$poly_answer); + + if (empty($_GET['hotspot'])) { //no user response + $overlap = -2; + } else { + $poly_user_compiled = poly_compile($poly_user,$max_coord); + $poly_answer_compiled = poly_compile($poly_answer,$max_coord); + $poly_results = poly_result($poly_answer_compiled,$poly_user_compiled,$max_coord); + + $overlap = $poly_results['both']; + $poly_answer_area = $poly_results['s1']; + $poly_user_area = $poly_results['s2']; + $missing = $poly_results['s1Only']; + $excess = $poly_results['s2Only']; + } + + //$overlap = round(polygons_overlap($poly_answer,$poly_user)); //this is an area in pixels + if ($dbg_local>0) { error_log(__LINE__.' - Polygons results are '.print_r($poly_results,1),0);} + if ($overlap < 1) { + //shortcut to avoid complicated calculations + $final_overlap = 0; + $final_missing = 100; + $final_excess = 100; + } else { + // the final overlap is the percentage of the initial polygon that is overlapped by the user's polygon + $final_overlap = round(((float)$overlap / (float)$poly_answer_area)*100); + if ($dbg_local>1) { error_log(__LINE__.' - Final overlap is '.$final_overlap,0);} + // the final missing area is the percentage of the initial polygon that is not overlapped by the user's polygon + $final_missing = 100 - $final_overlap; + if ($dbg_local>1) { error_log(__LINE__.' - Final missing is '.$final_missing,0);} + // the final excess area is the percentage of the initial polygon's size that is covered by the user's polygon outside of the initial polygon + $final_excess = round((((float)$poly_user_area-(float)$overlap)/(float)$poly_answer_area)*100); + if ($dbg_local>1) { error_log(__LINE__.' - Final excess is '.$final_excess,0);} + } + + $destination_items= explode('@@', $answerDestination); + $threadhold_total = $destination_items[0]; + $threadhold_items=explode(';',$threadhold_total); + $threadhold1 = $threadhold_items[0]; // overlap + $threadhold2 = $threadhold_items[1]; // excess + $threadhold3 = $threadhold_items[2]; //missing + + // echo $final_overlap.' '.$threadhold1 .' - '. $final_missing.' '. $threadhold2 .' - '. $final_excess.' '. $threadhold3; + + // if is delineation + if ($answerId===1) { + //setting colors + if ($final_overlap>=$threadhold1) { + $overlap_color=true; //echo 'a'; + } + //echo $excess.'-'.$threadhold2; + if ($final_excess<=$threadhold2) { + $excess_color=true; //echo 'b'; + } + //echo '--------'.$missing.'-'.$threadhold3; + if ($final_missing<=$threadhold3) { + $missing_color=true; //echo 'c'; + } + + // if pass + //if ($final_overlap>=$threadhold1 && $final_missing<=$threadhold2 && $final_excess<=$threadhold3) { + if ($final_overlap>=$threadhold1 && $final_missing<=$threadhold3 && $final_excess<=$threadhold2) { + $next=1; //go to the oars + $result_comment=get_lang('Acceptable'); + } else { + $next=1; //Go to the oars. If $next = 0 we will show this message: "One (or more) area at risk has been hit" instead of the table resume with the results + $wrong_results = true; + $result_comment=get_lang('Unacceptable'); + $special_comment = $comment=$answerDestination=$objAnswerTmp->selectComment(1); + $answerDestination=$objAnswerTmp->selectDestination(1); + $destination_items= explode('@@', $answerDestination); + $try_hotspot=$destination_items[1]; + $lp_hotspot=$destination_items[2]; + $select_question_hotspot=$destination_items[3]; + $url_hotspot=$destination_items[4]; + //echo 'show the feedback'; + } + } elseif($answerId>1) { + if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') { + if ($dbg_local>0) { error_log(__LINE__.' - answerId is of type noerror',0);} + //type no error shouldn't be treated + $next = 1; + continue; + } + if ($dbg_local>0) { error_log(__LINE__.' - answerId is >1 so we\'re probably in OAR',0);} + //check the intersection between the oar and the user + //echo 'user'; print_r($x_user_list); print_r($y_user_list); + //echo 'official';print_r($x_list);print_r($y_list); + //$result = get_intersection_data($x_list,$y_list,$x_user_list,$y_user_list); + + //$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); + $delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); //getting the oars coordinates + + $poly_answer = convert_coordinates($delineation_cord,'|'); + $max_coord = poly_get_max($poly_user,$poly_answer); //getting max coordinates + $test = false; + // if ($answerId == 2 ){$test = true;} for test oars + + if (empty($_GET['hotspot'])) { //no user response + $overlap = false; + } else { + // poly_compile really works tested with gnuplot + $poly_user_compiled = poly_compile($poly_user,$max_coord,$test);//$poly_user is already set when answerid = 1 + $poly_answer_compiled = poly_compile($poly_answer,$max_coord,$test); + $overlap = poly_touch($poly_user_compiled, $poly_answer_compiled,$max_coord); + } + + if ($overlap == false) { + //all good, no overlap + $next = 1; + continue; } else { - // the final overlap is the percentage of the initial polygon that is overlapped by the user's polygon - $final_overlap = round(((float)$overlap / (float)$poly_answer_area)*100); - if ($dbg_local>1) { error_log(__LINE__.' - Final overlap is '.$final_overlap,0);} - // the final missing area is the percentage of the initial polygon that is not overlapped by the user's polygon - $final_missing = 100 - $final_overlap; - if ($dbg_local>1) { error_log(__LINE__.' - Final missing is '.$final_missing,0);} - // the final excess area is the percentage of the initial polygon's size that is covered by the user's polygon outside of the initial polygon - $final_excess = round((((float)$poly_user_area-(float)$overlap)/(float)$poly_answer_area)*100); - if ($dbg_local>1) { error_log(__LINE__.' - Final excess is '.$final_excess,0);} + if ($dbg_local>0) { error_log(__LINE__.' - Overlap is '.$overlap.': OAR hit',0);} + + $organs_at_risk_hit++; + //show the feedback + $next=1; + $comment=$answerDestination=$objAnswerTmp->selectComment($answerId); + $answerDestination=$objAnswerTmp->selectDestination($answerId); + $destination_items= explode('@@', $answerDestination); + $try_hotspot=$destination_items[1]; + $lp_hotspot=$destination_items[2]; + $select_question_hotspot=$destination_items[3]; + $url_hotspot=$destination_items[4]; } - - $destination_items= explode('@@', $answerDestination); - $threadhold_total = $destination_items[0]; - $threadhold_items=explode(';',$threadhold_total); - $threadhold1 = $threadhold_items[0]; // overlap - $threadhold2 = $threadhold_items[1]; // excess - $threadhold3 = $threadhold_items[2]; //missing - - // echo $final_overlap.' '.$threadhold1 .' - '. $final_missing.' '. $threadhold2 .' - '. $final_excess.' '. $threadhold3; - - // if is delineation - if ($answerId===1) { - //setting colors - if ($final_overlap>=$threadhold1) { - $overlap_color=true; //echo 'a'; - } - //echo $excess.'-'.$threadhold2; - if ($final_excess<=$threadhold2) { - $excess_color=true; //echo 'b'; - } - //echo '--------'.$missing.'-'.$threadhold3; - if ($final_missing<=$threadhold3) { - $missing_color=true; //echo 'c'; - } - - // if pass - //if ($final_overlap>=$threadhold1 && $final_missing<=$threadhold2 && $final_excess<=$threadhold3) { - if ($final_overlap>=$threadhold1 && $final_missing<=$threadhold3 && $final_excess<=$threadhold2) { - $next=1; //go to the oars - $result_comment=get_lang('Acceptable'); - } else { - $next=1; //Go to the oars. If $next = 0 we will show this message: "One (or more) area at risk has been hit" instead of the table resume with the results - $wrong_results = true; - $result_comment=get_lang('Unacceptable'); - $sepecial_comment = $comment=$answerDestination=$objAnswerTmp->selectComment(1); - $answerDestination=$objAnswerTmp->selectDestination(1); - $destination_items= explode('@@', $answerDestination); - $try_hotspot=$destination_items[1]; - $lp_hotspot=$destination_items[2]; - $select_question_hotspot=$destination_items[3]; - $url_hotspot=$destination_items[4]; - //echo 'show the feedback'; - } - } elseif($answerId>1) { - if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') { - if ($dbg_local>0) { error_log(__LINE__.' - answerId is of type noerror',0);} - //type no error shouldn't be treated - $next = 1; - continue; - } - if ($dbg_local>0) { error_log(__LINE__.' - answerId is >1 so we\'re probably in OAR',0);} - //check the intersection between the oar and the user - //echo 'user'; print_r($x_user_list); print_r($y_user_list); - //echo 'official';print_r($x_list);print_r($y_list); - //$result = get_intersection_data($x_list,$y_list,$x_user_list,$y_user_list); - - //$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); - $delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); //getting the oars coordinates - - $poly_answer = convert_coordinates($delineation_cord,'|'); - $max_coord = poly_get_max($poly_user,$poly_answer); //getting max coordinates - $test = false; - // if ($answerId == 2 ){$test = true;} for test oars - - if (empty($_GET['hotspot'])) { //no user response - $overlap = false; - } else { - // poly_compile really works tested with gnuplot - $poly_user_compiled = poly_compile($poly_user,$max_coord,$test);//$poly_user is already set when answerid = 1 - $poly_answer_compiled = poly_compile($poly_answer,$max_coord,$test); - $overlap = poly_touch($poly_user_compiled, $poly_answer_compiled,$max_coord); - } - - if ($overlap == false) { - //all good, no overlap - $next = 1; - continue; - } else { - if ($dbg_local>0) { error_log(__LINE__.' - Overlap is '.$overlap.': OAR hit',0);} - - $organs_at_risk_hit++; - //show the feedback - $next=1; - $comment=$answerDestination=$objAnswerTmp->selectComment($answerId); - $answerDestination=$objAnswerTmp->selectDestination($answerId); - $destination_items= explode('@@', $answerDestination); - $try_hotspot=$destination_items[1]; - $lp_hotspot=$destination_items[2]; - $select_question_hotspot=$destination_items[3]; - $url_hotspot=$destination_items[4]; - } - } - } else { - // the first delineation feedback - if ($dbg_local>0) { error_log(__LINE__.' first',0);} - //we send the error - } - } + } + } else { + // the first delineation feedback + if ($dbg_local>0) { error_log(__LINE__.' first',0);} + //we send the error + } + } } if ($overlap_color) { @@ -412,7 +411,7 @@ if (!empty($choice_value)) { } - $table_resume=' + $table_resume = '
@@ -439,13 +438,19 @@ if (!empty($choice_value)) {
'.get_lang('Requirements').'
'; //var_dump($final_overlap, $threadhold1 , $final_missing, $threadhold2 , $final_excess, $threadhold3); } -$_SESSION['newquestionList']=$newquestionList; -if ($choice_value==-1) { - $links. ''.get_lang('ChooseAnAnswer').''; +$_SESSION['newquestionList'] = $newquestionList; + +$links=''; + +if ($choice_value == -1) { + if ($answerType != HOT_SPOT_DELINEATION) { + $links .= ''.get_lang('ChooseAnAnswer').'
'; + } } -if ($answerType!= HOT_SPOT_DELINEATION) { + +if ($answerType != HOT_SPOT_DELINEATION) { if (!empty($destination)) { - $item_list=explode('@@',$destination); + $item_list = explode('@@',$destination); //print_R($item_list); $try = $item_list[0]; $lp = $item_list[1]; @@ -477,7 +482,7 @@ if ($answerType!= HOT_SPOT_DELINEATION) { } } -$links=''; + // the link to retry the question if ($try==1) { $num_value_array= (array_keys($questionList, $questionid)); @@ -511,24 +516,28 @@ if ($destinationid==-1) { $links.= Display :: return_icon('quiz.gif', '', array ('style' => 'padding-left:0px;padding-right:5px;')).''.get_lang('GoToQuestion').' '.$num_value_array[0].'

'; } } + echo ''; + if ($links!='') { echo '
- '.api_ucfirst(get_lang('Close')).' + '.api_ucfirst(get_lang('Close')).'

'.get_lang('Feedback').'

'; if ($answerType == HOT_SPOT_DELINEATION) { - if ($organs_at_risk_hit>0) { + if ($organs_at_risk_hit > 0) { //$message='

'.get_lang('YourDelineation').'

'; //$message.=$table_resume; $message.='
'.get_lang('ResultIs').' '.get_lang('Unacceptable').'
'; @@ -546,8 +555,8 @@ if ($links!='') { echo '

'.$comment.'

'; } echo '

'.$links.'

'; - //echo ''.get_lang('Close').''; echo '
'; + $_SESSION['hot_spot_result']=$message; $_SESSION['hotspot_delineation_result'][$exerciseId][$questionid] = array($message, $exerciseResult[$questionid]); //reseting the exerciseResult variable @@ -560,7 +569,7 @@ if ($links!='') { } else { $questionNum++; echo ''; } diff --git a/main/exercice/hotspot_admin.inc.php b/main/exercice/hotspot_admin.inc.php index 57a086a63e..8b1ee6aa4d 100644 --- a/main/exercice/hotspot_admin.inc.php +++ b/main/exercice/hotspot_admin.inc.php @@ -583,8 +583,8 @@ $hotspot_admin_url = api_get_path(WEB_CODE_PATH) . 'exercice/admin.php?' . api_g } else { $option_lp = ''.$option_lp; } - //Feedback SELECT - + + //Feedback SELECT $question_list=$objExercise->selectQuestionList(); $option_feed=''; $option_feed.=''; diff --git a/main/exercice/multiple_answer.class.php b/main/exercice/multiple_answer.class.php index 441eead98a..61080e1ab4 100644 --- a/main/exercice/multiple_answer.class.php +++ b/main/exercice/multiple_answer.class.php @@ -28,7 +28,7 @@ class MultipleAnswer extends Question { /** * Constructor */ - function MultipleAnswer(){ + function MultipleAnswer() { parent::question(); $this -> type = MULTIPLE_ANSWER; $this -> isContent = $this-> getIsContent(); @@ -105,8 +105,7 @@ class MultipleAnswer extends Question { $defaults['weighting[2]'] = -5; } $renderer = & $form->defaultRenderer(); - - + $renderer->setElementTemplate('{error}
{element}', 'correct['.$i.']'); $renderer->setElementTemplate('{error}
{element}', 'counter['.$i.']'); $renderer->setElementTemplate('{error}
{element}', 'answer['.$i.']'); diff --git a/main/exercice/question_admin.inc.php b/main/exercice/question_admin.inc.php index 1e46f3c211..35740765b1 100644 --- a/main/exercice/question_admin.inc.php +++ b/main/exercice/question_admin.inc.php @@ -60,10 +60,10 @@ if (is_object($objQuestion)) { $form->addElement('header', $text.': '.$form_title_extra); // question form elements - $objQuestion->createForm ($form); + $objQuestion->createForm($form); // answer form elements - $objQuestion->createAnswersForm ($form); + $objQuestion->createAnswersForm($form); // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications if (!$show_quiz_edition) { @@ -77,13 +77,13 @@ if (is_object($objQuestion)) { //$renderer->setElementTemplate('
{label}
{element}
','submitQuestion'); // FORM VALIDATION - if (isset($_POST['submitQuestion']) && $form->validate()) { + if (isset($_POST['submitQuestion']) && $form->validate()) { // question - $objQuestion->processCreation($form,$objExercise); - // answers + $objQuestion->processCreation($form, $objExercise); - $objQuestion->processAnswersCreation($form,$nb_answers); + // answers + $objQuestion->processAnswersCreation($form, $nb_answers); // TODO: maybe here is the better place to index this tool, including answers text diff --git a/main/exercice/testcategory.class.php b/main/exercice/testcategory.class.php index 31898b8bc2..5b57501c7d 100644 --- a/main/exercice/testcategory.class.php +++ b/main/exercice/testcategory.class.php @@ -1,8 +1,8 @@ defaultRenderer(); + $renderer = $form->defaultRenderer(); $renderer->setElementTemplate('{error}
{element}', 'correct'); $renderer->setElementTemplate('{error}
{element}', 'counter['.$i.']'); @@ -203,23 +203,16 @@ class UniqueAnswer extends Question { } elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { $form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config); // Direct feedback - + //Adding extra feedback fields $group = array(); - $group['try'.$i] = $form->createElement('checkbox', 'try'.$i, get_lang('TryAgain').': ' , get_lang('TryAgain')); + $group['try'.$i] = $form->createElement('checkbox', 'try'.$i, null , get_lang('TryAgain')); $group['lp'.$i] = $form->createElement('select', 'lp'.$i, get_lang('SeeTheory').': ', $select_lp_id); $group['destination'.$i]= $form->createElement('select', 'destination'.$i, get_lang('GoToQuestion').': ' , $select_question); $group['url'.$i] = $form->createElement('text', 'url'.$i, get_lang('Other').': ', array('class'=>'span2', 'placeholder' => get_lang('Other'))); - - /*$renderer->setElementTemplate('{error}
{element}', 'url'.$i.''); - $renderer->setElementTemplate('{error}
{element}', 'lp'.$i.''); - $renderer->setElementTemplate('{error}
{element}', 'try'.$i.'');*/ - - $renderer->setGroupElementTemplate('
{label} {element}
', 'scenario'); - $group_result = $form->addGroup($group, 'scenario'); + $form->addGroup($group, 'scenario'); - $renderer->setGroupTemplate(''.$group_result->toHtml().'', 'scenario'); - //$renderer->setGroupElementTemplate('
{label}
{element}
', 'scenario'); + $renderer->setElementTemplate('{error}
{element}', 'scenario'); } $form->addElement('text', 'weighting['.$i.']', null, array('class' => "span1", 'value' => '0')); @@ -250,7 +243,7 @@ class UniqueAnswer extends Question { $renderer->setElementTemplate('{element} ','lessAnswers'); $renderer->setElementTemplate('{element} ','moreAnswers'); - $form -> addElement ('html', ''); + $form->addElement('html', ''); //We check the first radio button to be sure a radio button will be check if ($correct==0) { @@ -279,21 +272,20 @@ class UniqueAnswer extends Question { $questionWeighting = $nbrGoodAnswers = 0; $correct = $form -> getSubmitValue('correct'); $objAnswer = new Answer($this->id); - $nb_answers = $form -> getSubmitValue('nb_answers'); + $nb_answers = $form->getSubmitValue('nb_answers'); for ($i=1 ; $i <= $nb_answers ; $i++) { $answer = trim($form -> getSubmitValue('answer['.$i.']')); $comment = trim($form -> getSubmitValue('comment['.$i.']')); $weighting = trim($form -> getSubmitValue('weighting['.$i.']')); - $scenario= $form -> getSubmitValue('scenario'); - - echo '
';
+            $scenario = $form -> getSubmitValue('scenario');
+            
            	//$list_destination = $form -> getSubmitValue('destination'.$i);
            	//$destination_str = $form -> getSubmitValue('destination'.$i);
 
- 		    $try = $scenario['try'.$i];
-            $lp= $scenario['lp'.$i];
+ 		    $try = $scenario['try'.$i];            
+            $lp = $scenario['lp'.$i];
  			$destination = $scenario['destination'.$i];
  			$url = trim($scenario['url'.$i]);
 
@@ -301,7 +293,7 @@ class UniqueAnswer extends Question {
  			How we are going to parse the destination value
 
 			here we parse the destination value which is a string
-		 	1@@3@@2;4;4;@@http://www.dokeos.com
+		 	1@@3@@2;4;4;@@http://www.chamilo.org
 
 		 	where: try_again@@lp_id@@selected_questions@@url
 
@@ -309,31 +301,29 @@ class UniqueAnswer extends Question {
 			lp_id = id of a learning path (0 if dont select)
 			selected_questions= ids of questions
 			url= an url
-			*/
-			/*
+	
  			$destination_str='';
  			foreach ($list_destination as $destination_id)
  			{
  				$destination_str.=$destination_id.';';
  			}*/
 
-        	$goodAnswer= ($correct == $i) ? true : false;
+        	$goodAnswer = ($correct == $i) ? true : false;
 
-        	if($goodAnswer) {
+        	if ($goodAnswer) {
         		$nbrGoodAnswers++;
         		$weighting = abs($weighting);
-        		if($weighting > 0)
-                {
+        		if($weighting > 0) {
                     $questionWeighting += $weighting;
                 }
         	}
 
- 			if (empty($try))
- 				$try=0;
+ 			if (empty($try)) {
+ 				$try = 0;
+            }
 
- 			if (empty($lp))
- 			{
- 				$lp=0;
+ 			if (empty($lp)) {
+ 				$lp = 0;
  			}
 
  			if (empty($destination)) {
@@ -344,17 +334,17 @@ class UniqueAnswer extends Question {
  				$url=0;
  			}
 
- 			//1@@1;2;@@2;4;4;@@http://www.dokeos.com
-			$dest= $try.'@@'.$lp.'@@'.$destination.'@@'.$url;
-        	$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i,NULL,NULL,$dest);
+ 			//1@@1;2;@@2;4;4;@@http://www.chamilo.org
+			$dest = $try.'@@'.$lp.'@@'.$destination.'@@'.$url;            
+        	$objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting, $i, null, null, $dest);
         }
         
     	// saves the answers into the data base
-        $objAnswer -> save();
+        $objAnswer->save();
 
         // sets the total weighting of the question
-        $this -> updateWeighting($questionWeighting);
-        $this -> save();
+        $this->updateWeighting($questionWeighting);
+        $this->save();
 	}
 	
 	function return_header($feedback_type = null, $counter = null, $score = null) {
diff --git a/main/inc/lib/autoload.class.php b/main/inc/lib/autoload.class.php
index 00636cb8c1..6076e8ac55 100644
--- a/main/inc/lib/autoload.class.php
+++ b/main/inc/lib/autoload.class.php
@@ -584,6 +584,7 @@ class Autoload
         $result['EventsMail'] = '/main/inc/lib/events_email.class.php';
         $result['Exercise'] = '/main/exercice/exercise.class.php';
         $result['ExerciseLink'] = '/main/gradebook/lib/be/exerciselink.class.php';
+        $result['Testcategory'] = '/main/exercice/testcategory.class.php';        
         $result['ExerciseResult'] = '/main/exercice/exercise_result.class.php';
         $result['ExerciseShowFunctions'] = '/main/inc/lib/exercise_show_functions.lib.php';
         $result['FileManager'] = '/main/inc/lib/fileManage.lib.php';
diff --git a/main/inc/lib/pear/HTML/QuickForm.php b/main/inc/lib/pear/HTML/QuickForm.php
index e629015636..80f3e90d03 100644
--- a/main/inc/lib/pear/HTML/QuickForm.php
+++ b/main/inc/lib/pear/HTML/QuickForm.php
@@ -628,8 +628,6 @@ class HTML_QuickForm extends HTML_Common
                 $args[$i] = null;
             }
         }
-        
-        
         $err = $elementObject->onQuickFormEvent($event, $args, $this);
         if ($err !== true) {
             return $err;
@@ -784,7 +782,7 @@ class HTML_QuickForm extends HTML_Common
             $name       = 'qf_group_' . $anonGroups++;
             $appendName = false;
         }
-        $group =& $this->addElement('group', $name, $groupLabel, $elements, $separator, $appendName);
+        $group = & $this->addElement('group', $name, $groupLabel, $elements, $separator, $appendName);
         return $group;
     } // end func addGroup