return FALSE;
}
-function print_result($q_text, $q_answer, $q_num, $a_num, $correct) {
- if ($a_num == 1) {
- echo '<input type="checkbox" checked="checked" disabled="disabled" />';
- echo $q_text;
+// text - the text to display
+// checked - whether this option should be checked or not
+// correct_choice - FALSE: false/negative choice, TRUE: true/correct choice (from the test), or null for no correct/wrong choice (likert)
+function print_result($text, $checked, $correct_choice = null) {
+ global $_base_path;
+
+ static $right, $wrong, $empty, $check_empty, $check_check;
+
+ if (!isset($right)) {
+ $right = ' <img src="'.$_base_path.'images/checkmark.gif" alt="'._AT('correct_answer').'" title="'._AT('correct_answer').'" height="16" width="16" style="vertical-align: middle" />';
+ $wrong = ' <img src="'.$_base_path.'images/x.gif" alt="'._AT('wrong_answer').'" title="'._AT('wrong_answer').'" height="16" width="16" style="vertical-align: middle" />';
+ $empty = ' <img src="'.$_base_path.'images/clr.gif" alt="" title="" height="16" width="16" style="vertical-align: middle" />';
+ $check_empty = ' <img src="'.$_base_path.'images/checkbox_empty.gif" alt="" title="" height="13" width="13" style="vertical-align: middle" /> ';
+ $check_check = ' <img src="'.$_base_path.'images/checkbox_check.gif" alt="" title="" height="13" width="13" style="vertical-align: middle" /> ';
+ }
+
+ // mark this choice
+ if (isset($correct_choice)) {
+ if ($checked && $correct_choice) {
+ echo $right;
+ } else if ($checked && !$correct_choice) {
+ echo $wrong;
+ } else if (!$checked && $correct_choice) {
+ echo $wrong;
+ } else { // !$checked && !$correct_choice
+ echo $empty;
+ }
} else {
- echo '<input type="checkbox" disabled="disabled" />';
- echo $q_text;
+ echo $empty;
+ }
+
+ if ($checked) {
+ echo $check_check;
+ } else {
+ echo $check_empty;
+ }
+ echo $text;
+ if ($correct_choice == 1) {
+ echo ' - ' . $right;
}
}
if ($score != '') {
echo $score;
- /*} else if ($correct == $score){
- echo $weight;
- } else if ($correct!=$score){
- echo '0';*/
} else if ($correct) {
echo $weight;
} else if ($put_zero) {
echo '0';
}
- echo '" style="width: 30px; font-weight: bold;" maxlength="4" '.($disabled ? 'disabled="disabled" ' : '').'/><strong>/'.floatval($weight).'</strong>';
+ echo '" style="width: 30px; font-weight: bold; text-align: right;" maxlength="4" '.($disabled ? 'disabled="disabled" ' : '').'/><strong> / '.floatval($weight).'</strong>';
}
function print_question_cats($cat_id = 0) {
$answer_row['answer'] = explode('|', $answer_row['answer']);
}
- /* for each non-empty choice: */
/* for each non-empty choice: */
for ($i=0; ($i < 10) && ($row['choice_'.$i] != ''); $i++) {
if ($i > 0) {
echo '<br />';
}
+ $text = $row['choice_' . $i];
+ $correct_choice = ($row['answer_'.$i] == 1) ? TRUE : FALSE;
+
if (is_array($answer_row['answer'])) {
- print_result($row['choice_'.$i], $row['answer_'.$i], $i, (int) in_array($i, $answer_row['answer']), $row['answer_'.$answer_row['answer']]);
-
- if (is_array($answer_row['answer']) && ($row['answer_'.$i] == 1) && in_array($i, $answer_row['answer'])) {
- echo $mark_right;
- } else if (is_array($answer_row['answer']) && ($row['answer_'.$i] == 1) && !in_array($i, $answer_row['answer'])) {
- echo $mark_wrong;
- } else if (is_array($answer_row['answer']) && ($row['answer_'.$i] != 1) && in_array($i, $answer_row['answer'])) {
- echo $mark_wrong;
- }
+ $checked = in_array($i, $answer_row['answer']) ? TRUE : FALSE;
} else {
- $show_answer = 0;
- if ($answer_row['answer'] == $i) {
- $show_answer = 1;
- }
- print_result($row['choice_'.$i], $row['answer_'.$i], $i, $show_answer, $row['answer_'.$answer_row['answer']]);
- if (($row['answer_'.$i] == 1) && ($answer_row['answer'] == $i)) {
- echo $mark_right;
- } else if ($row['answer_'.$i] == 1) {
- echo $mark_wrong;
- }
+ $checked = ($answer_row['answer'] == $i) ? TRUE : FALSE;
}
+
+ print_result($text, $checked, $correct_choice);
}
echo '</p>';
echo AT_print($row['question'], 'tests_questions.question').'<br /><p>';
- print_result(_AT('true'), $row['answer_0'], 1, (int) ($answer_row['answer'] == 1), $correct);
- if (($answer_row['answer'] == 1) && ($row['answer_0'] == 1)){
- echo $mark_right;
- } else if ($row['answer_0'] == 1) {
- echo $mark_wrong;
- }
+ // true:
+ print_result(_AT('true'), ($answer_row['answer'] == 1) ? TRUE : FALSE, ($row['answer_0'] == 1) ? TRUE : FALSE);
+
echo '<br />';
- print_result(_AT('false'), $row['answer_0'], 2, (int) ($answer_row['answer'] == 2), $correct);
- if (($answer_row['answer'] == 2) && ($row['answer_0'] == 2)){
- echo $mark_right;
- } else if ($row['answer_0'] == 2) {
- echo $mark_wrong;
- }
- echo '<br />';
- print_result('<em>'._AT('left_blank').'</em>', -1, -1, (int) ($answer_row['answer'] == -1), false);
- if ($answer_row['answer'] == -1) {
- echo $mark_wrong;
- }
+ // false:
+ print_result(_AT('false'), ($answer_row['answer'] == 2) ? TRUE : FALSE, ($row['answer_0'] == 2) ? TRUE : FALSE);
+
+ // left empty:
echo '</p>';
break;
if ($i > 0) {
echo $spacer;
}
- print_result($row['choice_'.$i], $row['answer_'.$i], $i, $answer_row['answer'], 'none');
+ print_result($row['choice_'.$i], ($answer_row['answer'] == $i) ? TRUE : FALSE);
}
- echo $spacer;
-
- print_result('<em>'._AT('left_blank').'</em>', -1, -1, $answer_row['answer'], 'none');
echo '</p>';
break;
}
require(AT_INCLUDE_PATH.'vitals.inc.php');
require(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php');
-if (isset($_POST['back'])) {
- header('Location: my_tests.php');
- exit;
-}
-
if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
$content_base_href = 'get.php/';
} else {
$result = mysql_query($sql, $db);
$count = 1;
-echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
+echo '<form method="get" action="'.$_base_href.'tools/my_tests.php">';
if ($row = mysql_fetch_assoc($result)){
echo '<div class="input-form">';
if ($i > 0) {
echo '<br />';
}
+ $text = $row['choice_' . $i];
+ $correct_choice = ($row['answer_'.$i] == 1) ? TRUE : FALSE;
+
if (is_array($answer_row['answer'])) {
- print_result($row['choice_'.$i], $row['answer_'.$i], $i, (int) in_array($i, $answer_row['answer']), $row['answer_'.$answer_row['answer']]);
-
- if (is_array($answer_row['answer']) && ($row['answer_'.$i] == 1) && in_array($i, $answer_row['answer'])) {
- echo $mark_right;
- } else if (is_array($answer_row['answer']) && ($row['answer_'.$i] == 1) && !in_array($i, $answer_row['answer'])) {
- echo $mark_wrong;
- } else if (is_array($answer_row['answer']) && ($row['answer_'.$i] != 1) && in_array($i, $answer_row['answer'])) {
- echo $mark_wrong;
- }
+ $checked = in_array($i, $answer_row['answer']) ? TRUE : FALSE;
} else {
- $show_answer = 0;
- if ($answer_row['answer'] == $i) {
- $show_answer = 1;
- }
- print_result($row['choice_'.$i], $row['answer_'.$i], $i, $show_answer, $row['answer_'.$answer_row['answer']]);
- if (($row['answer_'.$i] == 1) && ($answer_row['answer'] == $i)) {
- echo $mark_right;
- } else if ($row['answer_'.$i] == 1) {
- echo $mark_wrong;
- }
+ $checked = ($answer_row['answer'] == $i) ? TRUE : FALSE;
}
+
+ print_result($text, $checked, $correct_choice);
}
echo '</p>';
case AT_TESTS_TF:
/* true or false question */
if ($row['weight']) {
- print_score($row['answer_'.$answer_row['answer']], $row['weight'], $row['question_id'], $answer_row['score'], false, true);
+ print_score($row['answer_'.$answer_row['answer']], $row['weight'], $row['question_id'], $answer_row['score'], FALSE, TRUE);
echo '<br />';
}
echo AT_print($row['question'], 'tests_questions.question').'<br /><p>';
- /* avman */
- if($answer_row['answer']== $row['answer_0']){
- $correct=1;
- } else {
- $correct='';
- }
-
- print_result(_AT('true'), $row['answer_0'], 1, (int) ($answer_row['answer'] == 1), $correct);
- if (($answer_row['answer'] == 1) && ($row['answer_0'] == 1)){
- echo $mark_right;
- } else if (($answer_row['answer'] == 1) && ($row['answer_0'] != 1)) {
- echo $mark_wrong;
- } else if ($row['answer_0'] == 1) {
- echo $mark_wrong;
- }
+ // true:
+ print_result(_AT('true'), ($answer_row['answer'] == 1) ? TRUE : FALSE, ($row['answer_0'] == 1) ? TRUE : FALSE);
+
echo '<br />';
- print_result(_AT('false'), $row['answer_0'], 2, (int) ($answer_row['answer'] == 2), $correct);
- if (($answer_row['answer'] == 2) && ($row['answer_0'] == 2)){
- echo $mark_right;
- } else if (($answer_row['answer'] == 2) && ($row['answer_0'] != 2)) {
- echo $mark_wrong;
- } else if ($row['answer_0'] == 2) {
- echo $mark_wrong;
- }
- echo '<br />';
- print_result('<em>'._AT('left_blank').'</em>', -1, -1, (int) ($answer_row['answer'] == -1), false);
- if ($answer_row['answer'] == -1) {
- echo $mark_wrong;
- }
+ // false:
+ print_result(_AT('false'), ($answer_row['answer'] == 2) ? TRUE : FALSE, ($row['answer_0'] == 2) ? TRUE : FALSE);
+
+ // left empty:
+
$my_score=($my_score+$answer_row['score']);
$this_total += $row['weight'];
echo '</p>';
if ($i > 0) {
echo '<br />';
}
- print_result($row['choice_'.$i], '' , $i, AT_print($answer_row['answer'], 'tests_answers.answer'), 'none');
+ print_result($row['choice_'.$i], ($answer_row['answer'] == $i) ? TRUE : FALSE);
}
echo '</p>';