Пример #1
0
function watupro_my_exams($passed_cat_ids = "", $orderby = "tE.ID")
{
    global $wpdb, $user_ID;
    // admin can see this for every student
    if (!empty($_GET['user_id']) and current_user_can(WATUPRO_MANAGE_CAPS)) {
        $user_id = $_GET['user_id'];
    } else {
        $user_id = $user_ID;
    }
    $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE ID=%d", $user_id));
    // select what categories I have access to
    get_currentuserinfo();
    $cat_ids = WTPCategory::user_cats($user_id);
    if (!empty($passed_cat_ids)) {
        $passed_cat_ids = explode(",", $passed_cat_ids);
        $cat_ids = array_intersect($cat_ids, $passed_cat_ids);
    }
    $cat_id_sql = implode(",", $cat_ids);
    list($my_exams, $takings, $num_taken) = WTPExam::my_exams($user_id, $cat_id_sql, $orderby);
    // intelligence dependencies
    if (watupro_intel()) {
        require_once WATUPRO_PATH . "/i/models/dependency.php";
        $my_exams = WatuPRODependency::mark($my_exams, $takings);
    }
    $num_to_take = sizeof($my_exams) - $num_taken;
    $dateformat = get_option('date_format');
    wp_enqueue_script('thickbox', null, array('jquery'));
    wp_enqueue_style('thickbox.css', '/' . WPINC . '/js/thickbox/thickbox.css', null, '1.0');
    wp_enqueue_style('style.css', plugins_url() . '/watupro/style.css', null, '1.0');
    if (@file_exists(get_stylesheet_directory() . '/watupro/my_exams.php')) {
        require get_stylesheet_directory() . '/watupro/my_exams.php';
    } else {
        require WATUPRO_PATH . "/views/my_exams.php";
    }
}
Пример #2
0
 static function edit($vars, $exam_id)
 {
     global $wpdb;
     // normally each quiz is active unless deactivated
     $is_active = 1;
     if (!empty($vars['is_inactive'])) {
         $is_active = 0;
     }
     // normalize params
     if (empty($vars['fee'])) {
         $vars['fee'] = "0.00";
     }
     if (empty($vars['random_per_category'])) {
         $vars['random_per_category'] = "0";
     }
     $vars['schedule_from'] = "{$vars['schedule_from']} {$vars['schedule_from_hour']}:{$vars['schedule_from_minute']}:00";
     $vars['schedule_to'] = "{$vars['schedule_to']} {$vars['schedule_to_hour']}:{$vars['schedule_to_minute']}:00";
     $retake_grades = empty($vars['retake_grades']) ? "" : "|" . @implode("|", $vars['retake_grades']) . "|";
     $wpdb->query($wpdb->prepare("UPDATE " . WATUPRO_EXAMS . " \n\t\t\tSET name=%s, description=%s, final_screen=%s,require_login=%d, take_again=%d, \n\t\t\temail_taker=%d, email_admin=%d, randomize_questions=%d, \n\t\t\tlogin_mode=%s, time_limit=%d, pull_random=%d, show_answers=%s, \n\t\t\tgroup_by_cat=%d, num_answers=%d, single_page=%d, cat_id=%d, times_to_take=%d,\n\t\t\tmode=%s, fee=%s, require_captcha=%d, grades_by_percent=%d, admin_email=%s,\n\t\t\tdisallow_previous_button=%d, random_per_category=%d, email_output=%s, live_result=%d,\n\t\t\tis_scheduled=%d, schedule_from=%s, schedule_to=%s, submit_always_visible=%d,\n\t\t\tretake_grades=%s, show_pagination=%d, enable_save_button=%d, shareable_final_screen=%d,\n\t\t\tredirect_final_screen=%d, takings_by_ip=%d, store_progress=%d, \n\t\t\tcustom_per_page=%d, is_active=%d, advanced_settings=%s, randomize_cats=%d, email_subject=%s,\n\t\t\tpay_always=%d, published_odd = %d, published_odd_url = %s\n\t\t\tWHERE ID=%d", $vars['name'], $vars['description'], $vars['content'], @$vars['require_login'], @$vars['take_again'], @$vars['email_taker'], @$vars['email_admin'], $vars['randomize_questions'], @$vars['login_mode'], $vars['time_limit'], $vars['pull_random'], $vars['show_answers'], @$vars['group_by_cat'], $vars['num_answers'], $vars['single_page'], $vars['cat_id'], $vars['times_to_take'], @$vars['mode'], $vars['fee'], @$vars['require_captcha'], @$vars['grades_by_percent'], $vars['admin_email'], @$vars['disallow_previous_button'], $vars['random_per_category'], $vars['email_output'], @$vars['live_result'], @$vars['is_scheduled'], $vars['schedule_from'], $vars['schedule_to'], @$vars['submit_always_visible'], $retake_grades, @$vars['show_pagination'], @$vars['enable_save_button'], @$vars['shareable_final_screen'], @$vars['redirect_final_screen'], $vars['takings_by_ip'], @$vars['store_progress'], $vars['custom_per_page'], $is_active, @$vars['advanced_settings'], @$vars['randomize_cats'], $vars['email_subject'], intval(@$vars['pay_always']), @$vars['published_odd'], $vars['published_odd_url'], $exam_id));
     if (watupro_intel()) {
         require_once WATUPRO_PATH . "/i/models/dependency.php";
         require_once WATUPRO_PATH . "/i/models/exam_intel.php";
         WatuPRODependency::store($exam_id);
         WatuPROIExam::extra_fields($exam_id, $vars);
     }
     return true;
 }
Пример #3
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;
 }
Пример #4
0
function watupro_exam()
{
    global $wpdb, $user_ID;
    $multiuser_access = 'all';
    if (watupro_intel()) {
        $multiuser_access = WatuPROIMultiUser::check_access('exams_access');
    }
    if (isset($_REQUEST['submit'])) {
        // prepare advanced settings - email grades and contact info fields
        $advanced_settings = $wpdb->get_var($wpdb->prepare("SELECT advanced_settings FROM " . WATUPRO_EXAMS . "\n\t\t\tWHERE id=%d", @$_REQUEST['quiz']));
        if (!empty($advanced_settings)) {
            $advanced_settings = unserialize(stripslashes($advanced_settings));
        } else {
            $advanced_settings = array();
        }
        // email grades
        $advanced_settings['email_grades'] = @$_POST['email_grades'];
        // flag for review
        $advanced_settings['flag_for_review'] = @$_POST['flag_for_review'];
        // dont display question numbers
        $advanced_settings['dont_display_question_numbers'] = @$_POST['dont_display_question_numbers'];
        // contact fields
        $advanced_settings['contact_fields'] = array();
        $advanced_settings['contact_fields']['email'] = $_POST['ask_for_email'];
        $advanced_settings['contact_fields']['email_label'] = $_POST['ask_for_email_label'];
        $advanced_settings['contact_fields']['name'] = $_POST['ask_for_name'];
        $advanced_settings['contact_fields']['name_label'] = $_POST['ask_for_name_label'];
        $advanced_settings['contact_fields']['phone'] = $_POST['ask_for_phone'];
        $advanced_settings['contact_fields']['phone_label'] = $_POST['ask_for_phone_label'];
        $advanced_settings['contact_fields']['company'] = $_POST['ask_for_company'];
        $advanced_settings['contact_fields']['company_label'] = $_POST['ask_for_company_label'];
        $advanced_settings['ask_for_contact_details'] = $_POST['ask_for_contact_details'];
        $_POST['advanced_settings'] = serialize($advanced_settings);
        if ($_REQUEST['action'] == 'edit') {
            //Update goes here
            $exam_id = $_REQUEST['quiz'];
            if ($multiuser_access == 'own') {
                $editor_id = $wpdb->get_var($wpdb->prepare("SELECT editor_id FROM " . WATUPRO_EXAMS . " WHERE ID=%d", $exam_id));
                if ($editor_id != $user_ID) {
                    wp_die('You can edit only your own exams', 'watupro');
                }
            }
            if (empty($_POST['use_different_email_output'])) {
                $_POST['email_output'] = '';
            }
            WTPExam::edit($_POST, $exam_id);
            if (!empty($_POST['auto_publish'])) {
                watupro_auto_publish($exam_id);
            }
            $wp_redirect = admin_url('admin.php?page=watupro_exams&message=updated');
            // save advanced settings
            if ($exam_id and watupro_intel()) {
                $_GET['exam_id'] = $exam_id;
                $_POST['ok'] = true;
                watupro_advanced_exam_settings();
            }
        } else {
            // add new exam
            $exam_id = WTPExam::add($_POST);
            if ($exam_id == 0) {
                $wp_redirect = admin_url('admin.php?page=watupro_exams&message=fail');
            }
            if ($exam_id and !empty($_POST['auto_publish'])) {
                watupro_auto_publish($exam_id);
            }
            $wp_redirect = admin_url('admin.php?page=watupro_questions&message=new_quiz&quiz=' . $exam_id);
        }
        echo "<meta http-equiv='refresh' content='0;url={$wp_redirect}' />";
        exit;
    }
    $action = 'new';
    if ($_REQUEST['action'] == 'edit') {
        $action = 'edit';
    }
    // global answer_display
    $answer_display = get_option('watupro_show_answers');
    // global single page display
    $single_page = get_option('watupro_single_page');
    $dquiz = array();
    $grades = array();
    if ($action == 'edit') {
        $dquiz = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_EXAMS . " WHERE ID=%d", $_GET['quiz']));
        $single_page = $dquiz->single_page;
        if ($multiuser_access == 'own' and $dquiz->editor_id != $user_ID) {
            wp_die('You can edit only your own exams', 'watupro');
        }
        $grades = WTPGrade::get_grades($dquiz);
        $final_screen = stripslashes($dquiz->final_screen);
        $schedule_from = $dquiz->schedule_from;
        list($schedule_from) = explode(" ", $schedule_from);
        $schedule_to = $dquiz->schedule_to;
        list($schedule_to) = explode(" ", $schedule_to);
        $advanced_settings = unserialize(stripslashes($dquiz->advanced_settings));
    } else {
        $final_screen = __("<p>You have completed %%QUIZ_NAME%%.</p>\n\n<p>You scored %%SCORE%% correct out of %%TOTAL%% questions.</p>\n\n<p>You have collected %%POINTS%% points.</p>\n\n<p>Your obtained grade is <b>%%GRADE%%</b></p>\n\n<p>Your answers are shown below:</p>\n\n%%ANSWERS%%", 'watupro');
        $schedule_from = date("Y-m-d");
        $schedule_to = date("Y-m-d");
    }
    // select certificates if any
    $certificates = $wpdb->get_results("SELECT * FROM " . WATUPRO_CERTIFICATES . " ORDER BY title");
    $cnt_certificates = sizeof($certificates);
    // categories if any
    $cats = $wpdb->get_results("SELECT * FROM " . WATUPRO_CATS . " ORDER BY name");
    // select other exams
    $other_exams = $wpdb->get_results("SELECT * FROM " . WATUPRO_EXAMS . " WHERE ID!='" . @$dquiz->ID . "' ORDER BY name");
    if (watupro_intel()) {
        require_once WATUPRO_PATH . "/i/models/dependency.php";
        $dependencies = WatuPRODependency::select(@$dquiz->ID);
    }
    // check if recaptcha keys are in place
    $recaptcha_public = get_option('watupro_recaptcha_public');
    $recaptcha_private = get_option('watupro_recaptcha_private');
    // is this quiz currently published?
    if (!empty($_GET['quiz'])) {
        $quiz_id = intval($_GET['quiz']);
        $is_published = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%[watupro " . $quiz_id . "]%' \n\t\t\t\tAND post_status='publish' AND post_title!=''");
    } else {
        $is_published = false;
    }
    wp_enqueue_script('jquery-ui-datepicker');
    wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
    if (@file_exists(get_stylesheet_directory() . '/watupro/exam_form.php')) {
        require get_stylesheet_directory() . '/watupro/exam_form.php';
    } else {
        require WATUPRO_PATH . "/views/exam_form.php";
    }
}