|
|
|
|
|
|
|
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 : // splits text and weightings that are joined with the character '::'
list($answer,$answerWeighting)=explode('::',$answer);
// splits weightings that are joined with a comma
$answerWeighting=explode(',',$answerWeighting);
// 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;
// the loop will stop at the end of the text
while(1)
{
// quits the loop if there are no more blanks
if(($pos = strpos($temp,'[')) === false)
{
// adds the end of the text
$answer.=$temp;
// TeX parsing
$texstring = api_parse_tex($texstring);
$answer=str_replace("{texcode}",$texstring,$answer);
break;
}
// adds the piece of text that is before the blank and ended by [
$answer.=substr($temp,0,$pos+1);
$temp=substr($temp,$pos+1);
// quits the loop if there are no more blanks
if(($pos = strpos($temp,']')) === false)
{
// adds the end of the text
$answer.=$temp;
break;
}
$choice[$j]=trim($choice[$j]);
// if the word entered by the student IS the same as the one defined by the professor
if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j])))
{
// gives the related weighting to the student
$questionScore+=$answerWeighting[$j];
// increments total score
$totalScore+=$answerWeighting[$j];
// adds the word in green at the end of the string
$answer.=stripslashes($choice[$j]);
}
// else if the word entered by the student IS NOT the same as the one defined by the professor
elseif(!empty($choice[$j]))
{
// adds the word in red at the end of the string, and strikes it
$answer.=''.stripslashes($choice[$j]).'';
}
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.=' / '.substr($temp,0,$pos).']';
$j++;
$temp=substr($temp,$pos+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 ('".$_user['user_id']."', '".$_course['id']."', '$exeId', '$questionId', '$answerId', '$studentChoice', '".$_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=$questionId and answer='$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=$questionId and position=$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{
echo '';
echo '';
}
$send_email = api_get_course_setting('email_alert_manager_on_new_quiz');
$csspath = "http://portal.dokeos.com/demo/main/css/default.css";
if ($send_email && count($arrques)>0)
{
$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
| '.get_lang('Question').' |
#questionName# |
| '.get_lang('Answer').' |
#answer# |
';
$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.='
'.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');
api_mail_html($student_name, $to, $subject, $mail_content, $from_name, $from);
}
?> |