Removed the functions and moved to the file exercise_show_funtions.lib.php to /main/inc/lib/ CT#191

skala
Arthur Portugal 16 years ago
parent 2a19775772
commit 694a8d3e9b
  1. 339
      main/exercice/exercise_show.php

@ -21,8 +21,9 @@ require_once '../inc/lib/course.lib.php';
require_once 'exercise.class.php';
require_once 'question.class.php'; //also defines answer type constants
require_once 'answer.class.php';
require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
require_once(api_get_path(LIBRARY_PATH).'mail.lib.inc.php');
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
require_once api_get_path(LIBRARY_PATH).'exercise_show_functions.lib.php';
if ( empty ( $origin ) ) {
$origin = $_REQUEST['origin'];
@ -227,200 +228,12 @@ function getFCK(vals,marksid)
</script>
<?php
/**
* This function gets the comments of an exercise
*
* @param int $id
* @param int $question_id
* @return str the comment
*/
function get_comments($id,$question_id)
{
global $TBL_TRACK_ATTEMPT;
$sql = "SELECT teacher_comment FROM ".$TBL_TRACK_ATTEMPT." where exe_id='".Database::escape_string($id)."' and question_id = '".Database::escape_string($question_id)."' ORDER by question_id";
$sqlres = Database::query($sql, __FILE__, __LINE__);
$comm = Database::result($sqlres,0,"teacher_comment");
return $comm;
}
/**
* Display the answers to a multiple choice question
*
* @param integer Answer type
* @param integer Student choice
* @param string Textual answer
* @param string Comment on answer
* @param string Correct answer comment
* @param integer Exercise ID
* @param integer Question ID
* @param boolean Whether to show the answer comment or not
* @return void
*/
function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans)
{
global $feedback_type;
?>
<tr>
<td width="5%" align="center">
<img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $studentChoice?'_on':'_off'; ?>.gif"
border="0" alt="" />
</td>
<td width="5%" align="center">
<img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif"
border="0" alt=" " />
</td>
<td width="40%" style="border-bottom: 1px solid #4171B5;">
<?php
$answer=api_parse_tex($answer);
echo $answer;
?>
</td>
<?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
<td width="20%" style="border-bottom: 1px solid #4171B5;">
<?php
$answerComment=api_parse_tex($answerComment);
if($studentChoice)
{
if(!$answerCorrect)
{
echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
}
else{
echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
}
}
else
{
echo '&nbsp;';
}
?>
</td>
<?php
if ($ans==1) {
$comm = get_comments($id,$questionId);
}
?>
<?php } else { ?>
<td>&nbsp;</td>
<?php } ?>
</tr>
<?php
}
/**
* Shows the answer to a fill-in-the-blanks question, as HTML
* @param string Answer text
* @param int Exercise ID
* @param int Question ID
* @return void
*/
function display_fill_in_blanks_answer($answer,$id,$questionId)
{ global $feedback_type;
?>
<tr>
<td>
<?php echo nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY)); ?>
</td>
<?php
if(!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {?>
<td>
<?php
$comm = get_comments($id,$questionId);
?>
</td>
<?php } ?>
</tr>
<?php
}
/**
* Shows the answer to a free-answer question, as HTML
* @param string Answer text
* @param int Exercise ID
* @param int Question ID
* @return void
*/
function display_free_answer($answer,$id,$questionId) {
global $feedback_type;
?>
<tr>
<td>
<?php if (!empty($answer)) {echo nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY));} ?>
</td>
<?php if(!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {?>
<td>
<?php
$comm = get_comments($id,$questionId);
?>
</td>
<?php }?>
</tr>
<?php
}
/**
* Displays the answer to a hotspot question
*
* @param int $answerId
* @param string $answer
* @param string $studentChoice
* @param string $answerComment
*/
function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment) {
global $feedback_type;
$hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
"#4271B5",
"#FE8E16",
"#3B3B3B",
"#BCD631",
"#D63173",
"#D7D7D7",
"#90AFDD",
"#AF8640",
"#4F9242",
"#F4EB24",
"#ED2024",
"#45C7F0",
"#F7BDE2");
?>
<tr>
<td width="100px" valign="top" align="left">
<div style="width:100%;">
<div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]; ?>; display:inline; float:left; margin-top:3px;"></div>
<div style="float:left; padding-left:5px;">
<?php echo $answerId; ?>
</div>
<div><?php echo '&nbsp;'.$answer ?></div>
</div>
</td>
<td width="50px" style="padding-right:15px" valign="top" align="left">
<?php
$my_choice = ($studentChoice)?get_lang('Correct'):get_lang('Fault'); echo $my_choice; ?>
</td>
<?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
<td valign="top" align="left" >
<?php
$answerComment=api_parse_tex($answerComment);
if($studentChoice) {
echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
} else {
echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
}
?>
</td>
<?php } else { ?>
<td>&nbsp;</td>
<?php } ?>
</tr>
<?php
}
/*
==============================================================================
MAIN CODE
@ -649,9 +462,9 @@ if ($show_results) {
}
echo '<tr><td>';
if ($answerId==1) {
display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
} else {
display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
}
echo '</td></tr>';
$i++;
@ -711,9 +524,9 @@ if ($show_results) {
echo '<tr><td>';
if ($answerId==1) {
display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
} else {
display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
}
echo '</td></tr>';
$i++;
@ -775,9 +588,9 @@ if ($show_results) {
}
echo '<tr><td>';
if ($answerId==1) {
display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
} else {
display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
}
echo '</td></tr>';
$i++;
@ -941,7 +754,7 @@ if ($show_results) {
}
//echo $questionScore."-".$totalScore;
echo '<tr><td>';
display_fill_in_blanks_answer($answer,$id,$questionId);
ExerciseShowFunctions::display_fill_in_blanks_answer($answer,$id,$questionId);
echo '</td></tr>';
$i++;
}
@ -980,7 +793,7 @@ if ($show_results) {
$arrans[] = $choice;
echo '<tr>
<td valign="top">'.display_free_answer($choice, $id, $questionId).'</td>
<td valign="top">'.ExerciseShowFunctions::display_free_answer($choice, $id, $questionId).'</td>
</tr>
</table>';
@ -1068,7 +881,7 @@ if ($show_results) {
$query = "select hotspot_correct from ".$TBL_TRACK_HOTSPOT." where hotspot_exe_id = '".Database::escape_string($id)."' and hotspot_question_id= '".Database::escape_string($questionId)."' AND hotspot_answer_id='".Database::escape_string($answerId)."'";
$resq=Database::query($query);
$choice = Database::result($resq,0,"hotspot_correct");
display_hotspot_answer($answerId,$answer,$choice,$answerComment);
ExerciseShowFunctions::display_hotspot_answer($answerId,$answer,$choice,$answerComment);
$i++;
}
@ -1108,7 +921,7 @@ if ($show_results) {
}
}
echo '</a><br /><div id="feedback_'.$name.'" style="width:100%">';
$comnt = trim(get_comments($id,$questionId));
$comnt = trim(ExerciseShowFunctions::get_comments($id,$questionId));
if (empty($comnt)) {
echo '<br />';
} else {
@ -1122,7 +935,7 @@ if ($show_results) {
$renderer =& $feedback_form->defaultRenderer();
$renderer->setFormTemplate('<form{attributes}><div align="left">{content}</div></form>');
$renderer->setElementTemplate('<div align="left">{element}</div>');
$comnt = get_comments($id,$questionId);
$comnt = ExerciseShowFunctions::get_comments($id,$questionId);
${user.$questionId}['comments_'.$questionId] = $comnt;
$feedback_form->addElement('html_editor', 'comments_'.$questionId, null, null, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', 'Height' => '120'));
$feedback_form->addElement('html','<br>');
@ -1131,7 +944,7 @@ if ($show_results) {
$feedback_form->display();
echo '</div>';
} else {
$comnt = get_comments($id,$questionId);
$comnt = ExerciseShowFunctions::get_comments($id,$questionId);
echo '<tr><td><br />';
if (!empty($comnt)) {
echo '<b>'.get_lang('Feedback').'</b>';
@ -1266,7 +1079,7 @@ if ($origin != 'learnpath') {
echo '</body></html>';
} else {
if (!$is_allowedToEdit) {
send_notification($arrques, $arrans, $to);
ExerciseShowFunctions::send_notification($arrques, $arrans, $to);
}
Display::display_normal_message(get_lang('ExerciseFinished').' '.get_lang('ToContinueUseMenu'));
}
@ -1274,7 +1087,7 @@ if ($origin != 'learnpath') {
if (!$is_allowedToEdit) {
if ($origin != 'learnpath') {
send_notification($arrques, $arrans, $to);
ExerciseShowFunctions::send_notification($arrques, $arrans, $to);
}
}
@ -1283,120 +1096,4 @@ api_session_unregister('questionList');
unset ($questionList);
api_session_unregister('exerciseResult');
unset ($exerciseResult);
function send_notification($arrques, $arrans, $to) {
global $courseName, $exerciseTitle, $url_email;
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
$user_info = UserManager::get_user_info_by_id(api_get_user_id());
if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1 ) {
return '';
}
$mycharset = api_get_system_encoding();
$msg = '<html><head>
<link rel="stylesheet" href="'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css" type="text/css">
<meta content="text/html; charset='.$mycharset.'" http-equiv="content-type"></head>';
if(count($arrques)>0) {
$msg .= '<body>
<p>'.get_lang('OpenQuestionsAttempted').' :
</p>
<p>'.get_lang('AttemptDetails').' : <br />
</p>
<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
<tr>
<td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
<td width="469" valign="top"><h2>#course#</h2></td>
</tr>
<tr>
<td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
<td width="469" valign="top" class="outerframe">#exercise#</td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
<td valign="top" >#firstName# #lastName#</td>
</tr>
<tr>
<td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
<td valign="top"> #mail#</td>
</tr></table>
<p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
for($i=0;$i<sizeof($arrques);$i++) {
$msg.='
<tr>
<td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>
<td width="473" valign="top" bgcolor="#F3F3F3"><span class="style16"> #questionName#</span></td>
</tr>
<tr>
<td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Answer').' </span></td>
<td valign="top" bgcolor="#F3F3F3"><span class="style16"> #answer#</span></td>
</tr>';
$msg1= str_replace("#exercise#",$exerciseTitle,$msg);
$msg= str_replace("#firstName#",$user_info['firstname'],$msg1);
$msg1= str_replace("#lastName#",$user_info['lastname'],$msg);
$msg= str_replace("#mail#",$user_info['email'],$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.='</table><br>
<span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
<a href="#url#">#url#</a></span></body></html>';
$msg1= str_replace("#url#",$url_email,$msg);
$mail_content = $msg1;
$subject = get_lang('OpenQuestionsAttempted');
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
$result = @api_mail_html('', $to, $subject, $mail_content, $sender_name, $email_admin, array('charset'=>$mycharset));
} else {
$msg .= '<body>
<p>'.get_lang('ExerciseAttempted').' <br />
</p>
<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
<tr>
<td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
<td width="469" valign="top"><h2>#course#</h2></td>
</tr>
<tr>
<td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
<td width="469" valign="top" class="outerframe">#exercise#</td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
'.(api_is_western_name_order() ? '<td valign="top" >#firstName# #lastName#</td>' : '<td valign="top" >#lastName# #firstName#</td>').'
</tr>
<tr>
<td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
<td valign="top"> #mail#</td>
</tr></table>';
$msg= str_replace("#exercise#",$exerciseTitle,$msg);
$msg= str_replace("#firstName#",$user_info['firstname'],$msg);
$msg= str_replace("#lastName#",$user_info['lastname'],$msg);
$msg= str_replace("#mail#",$user_info['email'],$msg);
$msg= str_replace("#course#",$courseName,$msg);
$msg.='<br />
<span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
<a href="#url#">#url#</a></span></body></html>';
$msg= str_replace("#url#",$url_email,$msg);
$mail_content = $msg;
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
$subject = get_lang('ExerciseAttempted');
$result = @api_mail_html('', $to, $subject, $mail_content, $sender_name, $email_admin, array('charset'=>$mycharset));
}
}
unset ($exerciseResult);
Loading…
Cancel
Save