';
}
}
break(2); //break the switch and the "for" condition
} else {
$numAnswer=$objAnswerTmp->selectAutoId($answerId);
if ($answerCorrect) {
if ($answerCorrect == $choice[$numAnswer]) {
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
$user_answer = ''.$answer_matching[$choice[$numAnswer]].'';
} else {
$user_answer = ''.$answer_matching[$choice[$numAnswer]].'';
}
$matching[$numAnswer] = $choice[$numAnswer];
}
break;
}
// for hotspot with no order
case HOT_SPOT :
if ($from_database) {
if ($show_result) {
$TBL_TRACK_HOTSPOT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
$query = "SELECT hotspot_correct FROM ".$TBL_TRACK_HOTSPOT." WHERE hotspot_exe_id = '".$exeId."' and hotspot_question_id= '".$questionId."' AND hotspot_answer_id='".Database::escape_string($answerId)."'";
$resq = Database::query($query);
$studentChoice = Database::result($resq,0,"hotspot_correct");
}
} else {
$studentChoice = $choice[$answerId];
if ($studentChoice) {
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
}
}
break;
// @todo never added to chamilo
//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;
// for hotspot with delineation
case HOT_SPOT_DELINEATION :
if ($from_database) {
// getting the user answer
$TBL_TRACK_HOTSPOT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
$query = "SELECT hotspot_correct, hotspot_coordinate from ".$TBL_TRACK_HOTSPOT." where hotspot_exe_id = '".$exeId."' and hotspot_question_id= '".$questionId."' AND hotspot_answer_id='1'"; //by default we take 1 because it's a delineation
$resq = Database::query($query);
$row = Database::fetch_array($resq,'ASSOC');
$choice = $row['hotspot_correct'];
$user_answer = $row['hotspot_coordinate'];
// THIS is very important otherwise the poly_compile will throw an error!!
// round-up the coordinates
$coords = explode('/',$user_answer);
$user_array = '';
foreach ($coords as $coord) {
list($x,$y) = explode(';',$coord);
$user_array .= round($x).';'.round($y).'/';
}
$user_array = substr($user_array,0,-1);
} else {
if ($studentChoice) {
$newquestionList[]=$questionId;
}
if ($answerId===1) {
$studentChoice =$choice[$answerId];
$questionScore +=$answerWeighting;
if ($hotspot_delineation_result[1]==1) {
$totalScore +=$answerWeighting; //adding the total
}
}
}
$_SESSION['hotspot_coord'][1] = $delineation_cord;
$_SESSION['hotspot_dest'][1] = $answer_delineation_destination;
break;
} // end switch Answertype
global $origin, $debug;
if ($show_result) {
if ($from == 'exercise_result') {
if ($debug) error_log('Showing questions $from '.$from);
//display answers (if not matching type, or if the answer is correct)
if ($answerType != MATCHING || $answerCorrect) {
if (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION, MULTIPLE_ANSWER, MULTIPLE_ANSWER_COMBINATION))) {
if ($origin != 'learnpath') {
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,0,0);
}
} elseif($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
if ($origin!='learnpath') {
ExerciseShowFunctions::display_multiple_answer_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,$questionId,0);
}
} elseif($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) {
if ($origin!='learnpath') {
ExerciseShowFunctions::display_multiple_answer_combination_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,0,0);
}
} elseif($answerType == FILL_IN_BLANKS) {
if ($origin!='learnpath') {
ExerciseShowFunctions::display_fill_in_blanks_answer($answer,0,0);
}
} elseif($answerType == FREE_ANSWER) {
// to store the details of open questions in an array to be used in mail
$arrques[] = $questionName;
$arrans[] = $choice;
if($origin != 'learnpath') {
ExerciseShowFunctions::display_free_answer($choice,0,0);
}
} elseif($answerType == ORAL_EXPRESSION) {
// to store the details of open questions in an array to be used in mail
$arrques[] = $questionName;
$arrans[] = $choice;
if($origin != 'learnpath') {
ExerciseShowFunctions::display_oral_expression_answer($choice, 0, 0, $nano);
}
} elseif($answerType == HOT_SPOT) {
if ($origin != 'learnpath') {
ExerciseShowFunctions::display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
}
} elseif($answerType == HOT_SPOT_ORDER) {
if ($origin != 'learnpath') {
ExerciseShowFunctions::display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment);
}
} elseif ($answerType == HOT_SPOT_DELINEATION) {
$user_answer = $_SESSION['exerciseResultCoordinates'][$questionId];
//$_SESSION['exerciseResultCoordinates']=str_replace('/','|',$user_answer);
//if (!$comes_from_popup) {
//round-up the coordinates
$coords = explode('/',$user_answer);
$user_array = '';
foreach ($coords as $coord) {
list($x,$y) = explode(';',$coord);
$user_array .= round($x).';'.round($y).'/';
}
$user_array = substr($user_array,0,-1);
if ($next) {
//$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($user_array)."')";
$result = api_sql_query($sql,__FILE__,__LINE__);*/
$user_answer = $user_array;
// we compare only the delineation not the other points
$answer_question = $_SESSION['hotspot_coord'][1];
$answerDestination = $_SESSION['hotspot_dest'][1];
//calculating the area
$poly_user = convert_coordinates($user_answer,'/');
$poly_answer = convert_coordinates($answer_question,'|');
$max_coord = poly_get_max($poly_user,$poly_answer);
$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 ($debug>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 ($debug>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 ($debug>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 ($debug>1) {
error_log(__LINE__.' - Final excess is '.$final_excess,0);
}
}
//checking the destination parameters parsing the "@@"
$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
// 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<=$threadhold3 && $final_excess<=$threadhold2) {
$next=1; //go to the oars
$result_comment=get_lang('Acceptable');
$final_answer = 1; // do not update with update_exercise_attempt
} else {
$next=0;
$result_comment=get_lang('Unacceptable');
$comment=$answerDestination=$objAnswerTmp->selectComment(1);
$answerDestination=$objAnswerTmp->selectDestination(1);
//checking the destination parameters parsing the "@@"
$destination_items= explode('@@', $answerDestination);
}
} elseif($answerId>1) {
if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') {
if ($debug>0) {
error_log(__LINE__.' - answerId is of type noerror',0);
}
//type no error shouldn't be treated
$next = 1;
continue;
}
if ($debug>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);
$inter= $result['success'];
//$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId);
$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId);
$poly_answer = convert_coordinates($delineation_cord,'|');
$max_coord = poly_get_max($poly_user,$poly_answer);
$poly_answer_compiled = poly_compile($poly_answer,$max_coord);
$overlap = poly_touch($poly_user_compiled, $poly_answer_compiled,$max_coord);
if ($overlap == false) {
//all good, no overlap
$next = 1;
continue;
} else {
if ($debug>0) {
error_log(__LINE__.' - Overlap is '.$overlap.': OAR hit',0);
}
$organs_at_risk_hit++;
//show the feedback
$next=0;
$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 ($debug>0) {
error_log(__LINE__.' first',0);
}
}
} elseif($answerType==MATCHING) {
if ($origin != 'learnpath') {
echo '
';
break;
case HOT_SPOT:
ExerciseShowFunctions::display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
break;
case HOT_SPOT_DELINEATION:
$user_answer = $user_array;
if ($next) {
//$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($user_array)."')";
$result = api_sql_query($sql,__FILE__,__LINE__);*/
$user_answer = $user_array;
// we compare only the delineation not the other points
$answer_question = $_SESSION['hotspot_coord'][1];
$answerDestination = $_SESSION['hotspot_dest'][1];
//calculating the area
$poly_user = convert_coordinates($user_answer,'/');
$poly_answer = convert_coordinates($answer_question,'|');
$max_coord = poly_get_max($poly_user,$poly_answer);
$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 ($debug>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 ($debug>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 ($debug>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 ($debug>1) {
error_log(__LINE__.' - Final excess is '.$final_excess,0);
}
}
//checking the destination parameters parsing the "@@"
$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
// 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<=$threadhold3 && $final_excess<=$threadhold2) {
$next=1; //go to the oars
$result_comment=get_lang('Acceptable');
$final_answer = 1; // do not update with update_exercise_attempt
} else {
$next=0;
$result_comment=get_lang('Unacceptable');
$comment=$answerDestination=$objAnswerTmp->selectComment(1);
$answerDestination=$objAnswerTmp->selectDestination(1);
//checking the destination parameters parsing the "@@"
$destination_items= explode('@@', $answerDestination);
}
} elseif($answerId>1) {
if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') {
if ($debug>0) {
error_log(__LINE__.' - answerId is of type noerror',0);
}
//type no error shouldn't be treated
$next = 1;
continue;
}
if ($debug>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);
$inter= $result['success'];
//$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId);
$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId);
$poly_answer = convert_coordinates($delineation_cord,'|');
$max_coord = poly_get_max($poly_user,$poly_answer);
$poly_answer_compiled = poly_compile($poly_answer,$max_coord);
$overlap = poly_touch($poly_user_compiled, $poly_answer_compiled,$max_coord);
if ($overlap == false) {
//all good, no overlap
$next = 1;
continue;
} else {
if ($debug>0) {
error_log(__LINE__.' - Overlap is '.$overlap.': OAR hit',0);
}
$organs_at_risk_hit++;
//show the feedback
$next=0;
$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 ($debug>0) {
error_log(__LINE__.' first',0);
}
}
break;
case HOT_SPOT_ORDER:
ExerciseShowFunctions::display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment);
break;
case MATCHING:
if ($origin != 'learnpath') {
echo '
';
}
break;
}
}
}
} // end for that loops over all answers of the current question
// destruction of Answer
if (!$saved_results && $answerType == HOT_SPOT) {
$queryfree = "SELECT marks FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($exeId)."' and question_id= '".Database::escape_string($questionId)."'";
$resfree = Database::query($queryfree);
$questionScore = Database::result($resfree,0,"marks");
}
$final_answer = true;
foreach($real_answers as $my_answer) {
if (!$my_answer) {
$final_answer = false;
}
}
//we add the total score after dealing with the answers
if ($answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) {
if ($final_answer) {
//getting only the first score where we save the weight of all the question
$answerWeighting = $objAnswerTmp->selectWeighting(1);
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
}
}
$extra_data = array('final_overlap' => $final_overlap, 'final_missing'=>$final_missing, 'final_excess'=> $final_excess,
'overlap_color' => $overlap_color, 'missing_color'=>$missing_color, 'excess_color'=> $excess_color,
'threadhold1' => $threadhold1, 'threadhold2'=>$threadhold2, 'threadhold3'=> $threadhold3,
);
if ($from == 'exercise_result') {
// if answer is hotspot. To the difference of exercise_show.php, we use the results from the session (from_db=0)
// TODO Change this, because it is wrong to show the user some results that haven't been stored in the database yet
if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER || $answerType == HOT_SPOT_DELINEATION ) {
if ($debug) error_log('$from AND this is a hotspot kind of question ');
$my_exe_id = 0;
$from_database = 0;
if ($answerType == HOT_SPOT_DELINEATION) {
if (0) {
if ($overlap_color) {
$overlap_color='green';
} else {
$overlap_color='red';
}
if ($missing_color) {
$missing_color='green';
} else {
$missing_color='red';
}
if ($excess_color) {
$excess_color='green';
} else {
$excess_color='red';
}
if (!is_numeric($final_overlap)) {
$final_overlap = 0;
}
if (!is_numeric($final_missing)) {
$final_missing = 0;
}
if (!is_numeric($final_excess)) {
$final_excess = 0;
}
if ($final_overlap>100) {
$final_overlap = 100;
}
$table_resume='