} else { $current_text = str_replace('[[watupro-resolvedclass]]', 'watupro-unresolved', $current_text); } if (empty($ques->exclude_on_final_screen)) { $result .= $current_text; } // insert taking data $_watu->store_details($exam->ID, $taking_id, $ques->ID, $answer_text, $points, $ques->question, $correct, $current_text); if ($correct) { $score++; } $achieved += $points; } // uploaded files? if ($exam->no_ajax) { $result = WatuPROFileHandler::final_screen($result, $taking_id); } // calculate percentage if ($total == 0) { $percent = 0; } else { $percent = number_format($score / $total * 100, 2); } $percent = round($percent); // generic rating $rating = $_watu->calculate_rating($total, $score, $percent); // assign grade list($grade, $certificate_id, $do_redirect, $grade_obj) = WTPGrade::calculate($exam_id, $achieved, $percent, 0, $user_grade_ids); // assign certificate if any $certificate = ""; if (!empty($certificate_id) and is_user_logged_in()) {
function store_details($exam_id, $taking_id, $question_id, $answer, $points = 0, $question_text = "", $is_correct = 0, $snapshot = '') { global $wpdb, $user_ID; if (empty($points)) { $points = "0.00"; } // remove hardcoded correct/incorrect images if any // (for example we may have these in fill the gaps questions) $answer = str_replace('<img src="' . plugins_url("watupro") . '/correct.png" hspace="5">', '', $answer); $answer = str_replace('<img src="' . plugins_url("watupro") . '/wrong.png" hspace="5">', '', $answer); // if detail exists update $detail = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_STUDENT_ANSWERS . "\n WHERE taking_id=%d AND exam_id=%d AND question_id=%d", $taking_id, $exam_id, $question_id)); // question hits if any $hints = @$_POST['question_' . $question_id . '_hints']; $no_hints = sizeof(explode("watupro-hint", $hints)) - 1; $question_text = ''; // unset this, we'll no longer store it for performance reasons if (empty($detail->ID)) { $wpdb->insert(WATUPRO_STUDENT_ANSWERS, array("user_id" => $user_ID, "exam_id" => $exam_id, "taking_id" => $taking_id, "question_id" => $question_id, "answer" => $answer, "points" => $points, "question_text" => $question_text, "is_correct" => $is_correct, 'snapshot' => $snapshot, 'hints_used' => $hints, "num_hints_used" => $no_hints, "onpage_question_num" => @$_POST['current_question'], "feedback" => @$_POST['feedback-' . $question_id]), array("%d", "%d", "%d", "%d", "%s", "%f", "%s", "%d", "%s", "%s", "%d", "%d", "%s")); $detail_id = $wpdb->insert_id; } else { // don't remove the snapshot if (empty($snapshot) and !empty($detail->snapshot)) { $snapshot = stripslashes($detail->snapshot); } $wpdb->query($wpdb->prepare("UPDATE " . WATUPRO_STUDENT_ANSWERS . " SET\n answer=%s, points=%s, question_text=%s, is_correct=%d, snapshot=%s, hints_used = %s, \n num_hints_used=%d, onpage_question_num=%d, feedback=%s\n WHERE id=%d", $answer, $points, $question_text, $is_correct, $snapshot, $hints, $no_hints, @$_POST['current_question'], @$_POST['feedback-' . $question_id], $detail->ID)); $detail_id = $detail->ID; } // uploaded file? WatuPROFileHandler::upload_file($question_id, $detail_id, $taking_id); }