Exemplo n.º 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;
}
Exemplo n.º 2
0
 // the two rows below are about the category headers
 if (!$ques->exclude_on_final_screen) {
     $result .= watupro_cat_header($exam, $qct, $ques, 'submit');
     if (!in_array($ques->cat_id, $question_catids)) {
         $question_catids[] = $ques->cat_id;
     }
 }
 $qct++;
 $question_content = $ques->question;
 // fill the gaps need to replace gaps
 if ($ques->answer_type == 'gaps') {
     $question_content = preg_replace("/{{{([^}}}])*}}}/", "_____", $question_content);
 }
 $ansArr = is_array(@$_POST["answer-" . $ques->ID]) ? $_POST["answer-" . $ques->ID] : array();
 // points and correct calculation
 list($points, $correct) = WTPQuestion::calc_answer($ques, $ansArr, $ques->q_answers, $user_grade_ids);
 $max_points += WTPQuestion::max_points($ques);
 // handle sorting personalities
 if ($exam->is_personality_quiz and $ques->answer_type == 'sort' and watupro_intel()) {
     WatuPROIQuestion::sort_question_personality($ques, $ansArr, $user_grade_ids);
 }
 // discard points?
 if ($points and !$correct and $ques->reward_only_correct) {
     $points = 0;
 }
 list($answer_text, $current_text, $unresolved_text) = $_question->process($_watu, $qct, $question_content, $ques, $ansArr, $correct, $points);
 $unresolved_questions .= str_replace('[[watupro-resolvedclass]]', '', $unresolved_text);
 // replace the resolved class
 if ($correct) {
     $current_text = str_replace('[[watupro-resolvedclass]]', 'watupro-resolved', $current_text);
 } else {
Exemplo n.º 3
0
function watupro_unserialize_answer($answer)
{
    global $wpdb;
    $answer_arr = unserialize(stripslashes($answer->answer));
    $question = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_QUESTIONS . " WHERE ID=%d", $answer->question_id));
    $answer_value = $answer_arr[0];
    list($points, $is_correct) = WTPQuestion::calc_answer($question, $answer_value);
    $answer->answer = $answer_value;
    $answer->is_correct = $is_correct;
    $answer->points = $points;
    return $answer;
}