コード例 #1
0
ファイル: watupro.php プロジェクト: alvarpoon/anbig
 function can_retake($exam)
 {
     global $wpdb, $user_ID;
     // no login required but have a restriction by IP
     if (!empty($exam->takings_by_ip)) {
         // select number of takings by this IP address
         $num_taken = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM " . WATUPRO_TAKEN_EXAMS . "\n\t\t\t\tWHERE exam_id=%d AND ip=%s AND in_progress=0", $exam->ID, $_SERVER['REMOTE_ADDR']));
         if ($exam->takings_by_ip <= $num_taken) {
             echo "<p><b>";
             printf(__("Sorry, you can take this quiz only %d times.", 'watupro'), $exam->takings_by_ip);
             echo "</b></p>";
             return false;
         }
     }
     // end IP based check
     // no limits if login is not required
     if (!$exam->require_login) {
         return true;
     }
     if ($exam->take_again) {
         // Intelligence limitations
         if (watupro_intel()) {
             require_once WATUPRO_PATH . "/i/models/exam_intel.php";
             if (!WatuPROIExam::can_retake($exam)) {
                 return false;
             }
         }
         if (empty($exam->times_to_take) and (empty($exam->retake_grades) or strlen($exam->retake_grades) <= 2)) {
             return true;
         }
         // 0 = unlimited
         // now select number of takings
         if (!is_user_logged_in()) {
             echo __("Sorry, you are not allowed to submit this quiz.", 'watupro');
             return false;
         }
         $cnt_takings = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM " . WATUPRO_TAKEN_EXAMS . "\n\t\t\t\tWHERE exam_id=%d AND user_id=%d AND in_progress=0", $exam->ID, $user_ID));
         if (!$cnt_takings) {
             return true;
         }
         // if there are no takings no need to check further
         if (!empty($exam->times_to_take) and $cnt_takings >= $exam->times_to_take) {
             echo "<p><b>";
             printf(__("Sorry, you can take this quiz only %d times.", 'watupro'), $exam->times_to_take);
             echo "</b></p>";
             return false;
         }
         // all OK so far? Let's see if we have grade-based limitation and there are previous takings
         if (!empty($exam->retake_grades) and strlen($exam->retake_grades) > 2 and $cnt_takings) {
             $grids = explode("|", $exam->retake_grades);
             $grids = array_filter($grids);
             if (sizeof($grids)) {
                 // get latest taking
                 $latest_taking = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_TAKEN_EXAMS . " \n\t\t\t\t\t\tWHERE exam_id=%d AND user_id=%d AND in_progress=0 ORDER BY ID DESC LIMIT 1", $exam->ID, $user_ID));
                 if (!in_array($latest_taking->grade_id, $grids)) {
                     echo "<p><b>";
                     _e("You can't take this quiz again because of the latest grade you achieved on it.", 'watupro');
                     echo "</b></p>";
                     return false;
                 }
             }
         }
         // end grade-related limitation check
     } else {
         // Only 1 taking allowed: see if exam is already taken by this user
         $taking = $this->get_taking($exam);
         if (!empty($taking->ID) and !$taking->in_progress) {
             echo "<p><b>";
             printf(__("Sorry, you can take this %s only once!", 'watupro'), __('quiz', 'watupro'));
             echo "</b></p>";
             return false;
         }
     }
     // just in case
     return true;
 }
コード例 #2
0
ファイル: exam.php プロジェクト: alvarpoon/anbig
 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;
 }