Пример #1
0
 static function mark_review()
 {
     global $wpdb;
     $_watu = new WatuPRO();
     // this will only happen for logged in users
     if (!is_user_logged_in()) {
         return false;
     }
     $taking_id = $_watu->add_taking($_POST['exam_id'], 1);
     // select current data if any
     $marked_for_review = $wpdb->get_var($wpdb->prepare("SELECT marked_for_review FROM " . WATUPRO_TAKEN_EXAMS . "\n\t\t\tWHERE ID=%d", $taking_id));
     if (empty($marked_for_review)) {
         $marked_for_review = array("question_ids" => array(), "question_nums" => array());
     } else {
         $marked_for_review = unserialize($marked_for_review);
     }
     if ($_POST['act'] == 'mark') {
         $marked_for_review['question_ids'][] = $_POST['question_id'];
         $marked_for_review['question_nums'][] = $_POST['question_num'];
     } else {
         // unmark
         foreach ($marked_for_review['question_ids'] as $cnt => $id) {
             if ($id == $_POST['question_id']) {
                 unset($marked_for_review['question_ids'][$cnt]);
             }
         }
         foreach ($marked_for_review['question_nums'] as $cnt => $num) {
             if ($num == $_POST['question_num']) {
                 unset($marked_for_review['question_nums'][$cnt]);
             }
         }
     }
     // now save
     $wpdb->query($wpdb->prepare("UPDATE " . WATUPRO_TAKEN_EXAMS . " SET marked_for_review=%s WHERE ID=%d", serialize($marked_for_review), $taking_id));
 }
Пример #2
0
/**
 * This will scan all the content pages that wordpress outputs for our special code. If the code is found, it will replace the requested quiz.
 */
function watupro_shortcode($attr)
{
    global $wpdb, $post;
    $exam_id = $attr[0];
    $contents = '';
    if (!is_numeric($exam_id)) {
        return $contents;
    }
    watupro_vc_scripts();
    ob_start();
    // select exam
    $exam = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_EXAMS . " WHERE id=%d", $exam_id));
    if (watupro_intel()) {
        WatuPROIntelligence::conditional_scripts($exam_id);
    }
    watupro_conditional_scripts($exam);
    // passed question ids?
    if (!empty($attr['question_ids'])) {
        $passed_question_ids = $attr['question_ids'];
    }
    // submitting without ajax?
    if (!empty($_POST['no_ajax']) and !empty($exam->no_ajax)) {
        require WATUPRO_PATH . "/show_exam.php";
        $contents = ob_get_clean();
        $contents = apply_filters('watupro_content', $contents);
        return $contents;
    }
    // other cases, show here
    if (empty($_GET['waturl']) or !$exam->shareable_final_screen) {
        // showing the exam
        if ($exam->mode == 'practice' and watupro_intel()) {
            WatuPracticeController::show($exam);
        } else {
            include WATUPRO_PATH . '/show_exam.php';
        }
        $contents = ob_get_contents();
    } else {
        // showing taking results
        $url = @base64_decode($_GET['waturl']);
        list($exam_id, $tid) = explode("|", $url);
        if (!is_numeric($exam_id) or !is_numeric($tid)) {
            return $contents;
        }
        // must check if public URL is allowed
        $taking = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_TAKEN_EXAMS . " WHERE ID=%d", $tid));
        $contents = WatuPRO::cleanup($taking->details, 'web');
        $post->ID = 0;
        $post->comment_status = 'closed';
    }
    ob_end_clean();
    $contents = apply_filters('watupro_content', $contents);
    return $contents;
}
Пример #3
0
 static function check_access($exam, $post)
 {
     WatuPRO::$output_sent = false;
     // change this var from class method to avoid outputting the generic message
     if (!WatuPRO::can_access($exam)) {
         // not logged in error
         if (!is_user_logged_in()) {
             echo "<p><b>" . sprintf(__('You need to be registered and logged in to take this %s.', 'watupro'), __('quiz', 'watupro')) . " <a href='" . wp_login_url(get_permalink($post->ID)) . "'>" . __('Log in', 'watupro') . "</a>";
             if (get_option("users_can_register")) {
                 echo " " . __('or', 'watupro') . " <a href='" . wp_registration_url() . "'>" . __('Register', 'watupro') . "</a></b>";
             }
             echo "</p>";
         } else {
             // logged in but no rights to access
             if (!WatuPRO::$output_sent) {
                 echo "<p>" . __('You are not allowed to access this exam at the moment.', 'watupro') . "</p><!-- logged in but no rights to access-->";
             }
         }
         return false;
         // can_access returned false
     }
     return true;
 }
Пример #4
0
 function display_unresolved($output)
 {
     $output = WatuPRO::cleanup($output, 'web');
     // now remove correct-answer style
     $output = str_replace('correct-answer', '', $output);
     $output = str_replace('user-answer-unrevealed', 'user-answer', $output);
     // do it back & forth to avoid nasty bug
     $output = str_replace('user-answer', 'user-answer-unrevealed', $output);
     // remove hardcoded correct/incorrect images if any
     // (for example we may have these in fill the gaps questions)
     $output = str_replace('<img src="' . WATUPRO_URL . '/correct.png" hspace="5">', '', $output);
     $output = str_replace('<img src="' . WATUPRO_URL . '/wrong.png" hspace="5">', '', $output);
     return $output;
 }
Пример #5
0
$output .= str_replace($replace_these, $with_these, wpautop(stripslashes($exam->final_screen), false));
$output = watupro_parse_answerto($output, $taking_id);
$email_output = str_replace($replace_these, $with_these, wpautop(stripslashes($exam->email_output), false));
$email_output = watupro_parse_answerto($email_output, $taking_id);
// store this taking
$_watu->update_taking($taking_id, $achieved, $grade, $output, $percent, $grade_obj, $catgrades);
// send API call
do_action('watupro_completed_exam', $taking_id);
if (watupro_intel() and !empty($exam->fee) and !empty($exam->pay_always)) {
    do_action('watupro_completed_paid_exam', $taking_id, $exam);
}
$output = apply_filters('watupro_content', $output);
$email_output = apply_filters('watupro_content', $email_output);
// show output on the screen
if (empty($do_redirect)) {
    print WatuPRO::cleanup($output, 'web');
} else {
    echo "WATUPRO_REDIRECT:::" . $do_redirect;
}
// update taking output with the filters
$wpdb->query($wpdb->prepare("UPDATE " . WATUPRO_TAKEN_EXAMS . " SET details=%s WHERE ID=%d", $output, $taking_id));
if (!empty($exam->email_output)) {
    $output = $email_output;
}
// here maybe replace output with email output
// clear any timer related info for this exam
delete_user_meta($user_ID, "start_exam_" . $exam->ID);
// email details if required
$_watu->email_results($exam, $output, @$grade_obj->ID);
if (empty($exam->no_ajax)) {
    exit;
Пример #6
0
if ($exam->is_scheduled == 1) {
    $now = current_time('timestamp');
    $schedule_from = strtotime($exam->schedule_from);
    $schedule_to = strtotime($exam->schedule_to);
    if ($now < $schedule_from or $now > $schedule_to) {
        printf(__('This test will be available between %s and %s.', 'watupro'), date(get_option('date_format') . ' ' . get_option('time_format'), $schedule_from), date(get_option('date_format') . ' ' . get_option('time_format'), $schedule_to));
        if (current_user_can(WATUPRO_MANAGE_CAPS)) {
            echo ' ' . __('You can still see it only because you are administrator or manager.', 'watupro') . ' ';
        } else {
            return false;
        }
        // students can't take this test
    }
}
// logged in or login not required here
$_watu = new WatuPRO();
// re-taking allowed?
$ok = $_watu->can_retake($exam);
// check time limits on submit
if ($ok and $exam->time_limit > 0 and !empty($_REQUEST['action'])) {
    $ok = $_watu->verify_time_limit($exam, @$in_progress);
    if (!$ok) {
        echo "<p><b>" . __("Time limit exceeded! We cannot accept your results.", 'watupro') . "</b></p>";
        if (!empty($in_progress->ID)) {
            $wpdb->query($wpdb->prepare("UPDATE " . WATUPRO_TAKEN_EXAMS . " \n\t\t\tSET in_progress=0 WHERE id=%d", $in_progress->ID));
            echo $wpdb->prepare("UPDATE " . WATUPRO_TAKEN_EXAMS . " SET in_progress=0 WHERE id=%d", $in_progress->ID);
        }
    }
    // $ok, so clear the time limit for the future takings
    update_user_meta($user_ID, "start_exam_" . $exam->ID, 0);
}
Пример #7
0
        ?>
</a></p>
		<?php 
    }
    // end if not $advanced_settings['show_only_snapshot']
}
// end if not export
?>
	
	
	<?php 
if (empty($_GET['export'])) {
    ?>
	<div id="detailsText" style="background:#EEE;padding:5px;">	
	<p><?php 
    echo WatuPRO::cleanup($taking->details, 'web');
    ?>
</p>
	</div>
	<?php 
}
?>
	
	<?php 
if (empty($advanced_settings['show_only_snapshot'])) {
    if (empty($_GET['export'])) {
        ?>
 <div id="detailsTable" style="display:none;"> <?php 
    }
    ?>
	
Пример #8
0
 static function can_access($exam)
 {
     // always access public exams
     if (!$exam->require_login) {
         return true;
     }
     if ($exam->require_login and !is_user_logged_in()) {
         return false;
     }
     // admin can always access
     if (current_user_can('manage_options') or current_user_can('watupro_manage_exams')) {
         if (empty($_POST['action']) and $exam->fee > 0) {
             echo "<b>" . __('Note: This quiz requires payment, but you are administrator and do not need to go through it.', 'watupro') . "</b>";
         }
         return true;
     }
     // USER GROUP CHECKS
     $allowed = WTPCategory::has_access($exam);
     if (!$allowed) {
         echo "<!-- not in allowed user group -->";
         return false;
     }
     // INTELLIGENCE MODULE RESTRICTIONS
     if (watupro_intel()) {
         if ($exam->fee > 0) {
             require_once WATUPRO_PATH . "/i/models/payment.php";
             if (!empty($_POST['stripe_pay'])) {
                 WatuPROPayment::Stripe();
             }
             // process Stripe payment if any
             if (!WatuPROPayment::valid_payment($exam)) {
                 self::$output_sent = WatuPROPayment::render($exam);
                 return false;
             }
         }
         require_once WATUPRO_PATH . "/i/models/dependency.php";
         if (!WatuPRODependency::check($exam)) {
             echo "<!-- WATUPROCOMMENT unsatisfied dependencies -->";
             return false;
         }
     }
     return true;
 }