Example #1
0
function watupro_liveresult()
{
    global $wpdb, $user_ID;
    $_watu = new WatuPRO();
    $_question = new WTPQuestion();
    // select exam
    $exam = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_EXAMS . " WHERE ID=%d", $_POST['quiz_id']));
    $_watu->this_quiz = $exam;
    $advanced_settings = unserialize(stripslashes($exam->advanced_settings));
    if (watupro_intel()) {
        WatuPROIQuestion::$advanced_settings = $advanced_settings;
        WTPQuestion::$advanced_settings = $advanced_settings;
    }
    $questions = watupro_unserialize_questions($_POST['watupro_questions']);
    // find current question
    $ques = null;
    foreach ($questions as $question) {
        if ($question->ID == $_POST['question_id']) {
            $ques = $question;
        }
    }
    if (!is_object($ques)) {
        die(__("Sorry, we couldn't retrieve the answer", 'watupro'));
    }
    $ansArr = is_array($_POST["answer-" . $ques->ID]) ? $_POST["answer-" . $ques->ID] : array();
    list($points, $correct) = WTPQuestion::calc_answer($ques, $ansArr, $ques->q_answers);
    list($answer_text, $current_text, $unresolved_text) = $_question->process($_watu, $_POST['question_num'], $ques->question, $ques, $ansArr, $correct, $points);
    $current_text = apply_filters('watupro_content', $current_text);
    echo $current_text;
    // now save it in the user answers details if user is logged in
    if (is_user_logged_in()) {
        $taking_id = $_watu->add_taking($exam->ID, 1);
        $answer = serialize($_POST['answer-' . $_POST['question_id']]);
        // we need to store the serialized answer here
        $_watu->store_details($exam->ID, $taking_id, $ques->ID, $answer, $points, $ques->question, $correct, $current_text);
    }
    exit;
}
Example #2
0
    update_user_meta($user_ID, "start_exam_" . $exam->ID, 0);
}
if (!$ok) {
    return false;
}
if (!is_singular() and !empty($GLOBALS['watupro_client_includes_loaded'])) {
    #If this is in the listing page - and a quiz is already shown, don't show another.
    printf(__("Please go to <a href='%s'>%s</a> to view this test", 'watupro'), get_permalink(), get_the_title());
    return false;
}
// now select and display questions
$answer_display = $exam->show_answers == "" ? get_option('watupro_show_answers') : $exam->show_answers;
// loading serialized questions or questions coming by POST
if (!empty($_POST['action']) or !empty($in_progress->serialized_questions)) {
    $serialized_questions = empty($_REQUEST['watupro_questions']) ? @$in_progress->serialized_questions : $_REQUEST['watupro_questions'];
    $all_question = watupro_unserialize_questions($serialized_questions);
}
// this happens either at the beginning or if for some reason $all_question is empty on submitting
if (empty($all_question)) {
    $all_question = WTPQuestion::select_all($exam);
    // regroup by cats?
    if (empty($passed_question_ids)) {
        $all_question = $_watu->group_by_cat($all_question, $exam);
    }
    // now match answers to non-textarea questions
    $_watu->match_answers($all_question, $exam);
}
$cnt_questions = sizeof($all_question);
// get required question ids as string
$rids = array(0);
foreach ($all_question as $q) {