static function calculate($exam_id, $achieved, $percent, $cat_id = 0, $user_grade_ids = null) { global $wpdb; $exam = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_EXAMS . " WHERE ID=%d", $exam_id)); $grade = __('None', 'watupro'); $grade_obj = (object) array("title" => __('None', 'watupro'), "description" => ""); $do_redirect = false; $certificate_id = 0; $grades = self::get_grades($exam, $cat_id); // for the sake of grade calculation, $achieved won't be below zero // if($achieved < 0 ) $achieved = 0; if (count($grades)) { // calculate by percentage in Intelligence if (watupro_intel()) { if (!empty($exam->is_personality_quiz)) { return WTPIGrade::calculate($user_grade_ids); } } foreach ($grades as $grow) { $match_criteria = $achieved; // from Intelligence - calculate by % if (!empty($exam->grades_by_percent)) { $match_criteria = $percent; } if ($grow->gfrom <= $match_criteria and $match_criteria <= $grow->gto) { list($grade, $grade_obj, $certificate_id, $do_redirect) = self::match_grade($grow); break; } } } return array($grade, $certificate_id, $do_redirect, $grade_obj); }
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"; } }
/** * 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; }
static function download() { global $wpdb, $user_ID; // only do this when the URL contains watupro_download_file=$file_id if (empty($_GET['watupro_download_file']) or empty($_GET['id']) or !is_numeric($_GET['id'])) { return true; } if (!is_user_logged_in()) { wp_die(__('Only logged in users can download uploaded files.', 'watupro')); } // select the uploaded file $file = $wpdb->get_row($wpdb->prepare("SELECT ID, user_id, user_answer_id, filename, filesize, filetype \n\t\t\tFROM " . WATUPRO_USER_FILES . " WHERE ID=%d", $_GET['id'])); if (empty($file->ID)) { wp_die(__('The file has been deleted.', 'watupro')); } // check access if ($file->user_id != $user_ID) { if (!current_user_can(WATUPRO_MANAGE_CAPS)) { wp_die(__('You can only download your own files.', 'watupro')); } // manager. Let's see if he's allowed to see this file $multiuser_access = 'all'; if (watupro_intel()) { $multiuser_access = WatuPROIMultiUser::check_access('exams_access'); } if ($multiuser_access == 'own') { $exam_id = $wpdb->get_var($wpdb->prepare("SELECT exam_id FROM " . WATUPRO_STUDENT_ANSWERS . " WHERE\n\t\t\t\t\tID=%d", $file->user_answer_id)); $editor_id = $wpdb->get_var($wpdb->prepare("SELECT editor_id FROM \n\t\t\t\t\t" . WATUPRO_EXAMS . " WHERE ID=%d", $exam_id)); if ($editor_id != $user_ID) { wp_die(__('You can download only files of your own students.', 'watupro')); } } } // all good, let's download $content = $wpdb->get_var($wpdb->prepare("SELECT BINARY filecontents \n\t\t\tFROM " . WATUPRO_USER_FILES . " WHERE ID=%d", $file->ID)); header("Content-Length: " . strlen($content)); header("Content-Description: File Transfer"); header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"" . $file->filename . "\""); header("Content-Transfer-Encoding: binary"); echo $content; exit; }
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; }
function watupro_user_certificates() { global $wpdb, $user_ID; $certificate = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_CERTIFICATES . " WHERE ID=%d", $_GET['id'])); // check access $multiuser_access = 'all'; if (watupro_intel()) { $multiuser_access = WatuPROIMultiUser::check_access('certificates_access'); } if ($multiuser_access == 'own') { if ($certificate->editor_id != $user_ID) { wp_die(__('You can manage only your own certificates', 'watupro')); } } if (!empty($_GET['approve'])) { $wpdb->query($wpdb->prepare("UPDATE " . WATUPRO_USER_CERTIFICATES . " SET pending_approval = 0 WHERE ID=%d", $_GET['user_certificate_id'])); // send email to user? if ($certificate->approval_notify_user) { WatuPROCertificate::approval_notify($certificate, $_GET['user_certificate_id']); } watupro_redirect("admin.php?page=watupro_user_certificates&id=" . $_GET['id']); } if (!empty($_GET['delete'])) { $wpdb->query($wpdb->prepare("DELETE FROM " . WATUPRO_USER_CERTIFICATES . " WHERE ID=%d", $_GET['user_certificate_id'])); } // select users $users = $wpdb->get_results($wpdb->prepare("SELECT tUC.ID as user_certificate_id, tU.user_nicename as user_nicename, tU.user_email as user_email, \n\ttE.name as exam_name, tUC.pending_approval as pending_approval, tT.ID as taking_id, tT.date as taking_date, tT.result as taking_result,\n\ttE.ID as exam_id\n\tFROM " . WATUPRO_USER_CERTIFICATES . " tUC \n\tJOIN {$wpdb->users} tU ON tUC.user_id = tU.ID \n\tJOIN " . WATUPRO_TAKEN_EXAMS . " tT ON tT.user_id = tU.ID AND tT.ID = tUC.taking_id\n\tJOIN " . WATUPRO_EXAMS . " tE ON tE.ID = tT.exam_id AND tE.ID = tUC.exam_id\n\tWHERE tUC.certificate_id=%d\n\tORDER BY tT.ID DESC", $certificate->ID)); $dateformat = get_option('date_format'); $is_admin = true; wp_enqueue_script('thickbox', null, array('jquery')); wp_enqueue_style('thickbox.css', '/' . WPINC . '/js/thickbox/thickbox.css', null, '1.0'); if (@file_exists(get_stylesheet_directory() . '/watupro/users-earned-certificate.html.php')) { require get_stylesheet_directory() . '/watupro/users-earned-certificate.html.php'; } else { require WATUPRO_PATH . "/views/users-earned-certificate.html.php"; } }
function process($_watu, $qct, $question_content, $ques, $ansArr, $correct, $points) { $original_answer = ""; // this var is used only for textareas $answer_text = ""; // answers as text $unresolved_text = ""; $compact_class = $ques->compact_format ? ' watupro-compact ' : ''; $question_number = empty(self::$advanced_settings['dont_display_question_numbers']) ? "<span class='watupro_num'>Question {$qct} </span>" : ''; $enumerator = self::define_enumerator(); if ($ques->answer_type == 'gaps') { // gaps are displayed in different way to avoid repeating the question $current_text = "<div class='show-question [[watupro-resolvedclass]]'><div class='show-question-content'>" . $question_number; } else { $current_text = "<div class='show-question [[watupro-resolvedclass]]" . $compact_class . "'><div class='show-question-content'>" . $question_number . stripslashes($question_content) . "</div>\n"; $current_text .= "<div class='show-question-choices'>"; $current_text .= "<ul>"; } // replace the {{{ID}}} mask $current_text = str_replace('{{{ID}}}', $ques->ID, $current_text); $class = 'answer'; $any_answers = false; // this is for textareas -is there any answer provided at all? foreach ($ques->q_answers as $ans) { if ($ques->answer_type == 'matrix') { continue; } $user_answer_class = ($ques->is_survey or $_watu->this_quiz->is_personality_quiz) ? 'user-answer-unrevealed' : 'user-answer'; $class = 'answer'; if (in_array($ans->ID, $ansArr)) { $class .= ' ' . $user_answer_class; } if ($ans->correct == 1 and $ques->answer_type != 'textarea' and !$ques->is_survey) { $class .= ' correct-answer'; } if ($enumerator) { $enumerator_visible = $enumerator . '. '; $enumerator++; } else { $enumerator_visible = ''; } if ($ques->answer_type == 'textarea') { // textarea answers have only 1 element. Make comparison case insensitive $original_answer = @$ansArr[0]; $ansArr[0] = strtolower(strip_tags(trim($ansArr[0]))); $compare = strtolower($ans->answer); if (!empty($compare)) { $any_answers = true; } } else { $compare = $ans->ID; $current_text .= "<li class='{$class}'><span class='answer'><!--WATUEMAIL" . $class . "WATUEMAIL-->" . stripslashes($enumerator_visible . $ans->answer) . "</span></li>\n"; } } // end foreach choice; // open end will be displayed here if ($ques->answer_type == 'textarea') { $user_answer_class = $ques->is_survey ? 'user-answer-unrevealed' : 'user-answer'; // repeat this line in case there were no answers to compare $answer_text = empty($original_answer) ? $ansArr[0] : $original_answer; $ansArr[0] = strtolower($ansArr[0]); $class .= ' ' . $user_answer_class; if ($correct) { $class .= ' correct-answer'; } $current_text .= "<li class='{$class}'><span class='answer'>" . nl2br(stripslashes($answer_text)) . "</span></li>\n"; // uploaded file? if (!empty($_FILES['file-answer-' . $ques->ID]['tmp_name'])) { $current_text .= '<!--watupro-uploaded-file-' . $ques->ID . '-->'; } } if (($ques->answer_type == 'gaps' or $ques->answer_type == 'sort' or $ques->answer_type == 'matrix') and watupro_intel()) { list($points, $answer_text) = WatuPROIQuestion::process($ques, $ansArr); $current_text .= $answer_text; } if (empty($answer_text)) { $answer_text = $_watu->answer_text($ques->q_answers, $ansArr); } if ($ques->answer_type != 'gaps') { $current_text .= "</ul>"; } // close the ul for answers if (empty($_POST["answer-" . $ques->ID])) { $current_text .= "<p class='unanswered'>" . __('Question was not answered', 'watupro') . "</p>"; } if (!$correct) { $unresolved_text = $this->display_unresolved($current_text) . "</div>"; } // close question-choices $current_text .= "</div>"; $unresolved_text .= "</div>"; // if there is user's feedback, display it too if ($ques->accept_feedback and !empty($_POST['feedback-' . $ques->ID])) { $current_text .= "<p><b>" . stripslashes($ques->feedback_label) . "</b><br>" . stripslashes($_POST['feedback-' . $ques->ID]) . "</p>"; } // if explain_answer, display it $current_text .= $this->answer_feedback($ques, $correct, $ansArr, $points); $current_text .= "</div>"; $current_text = wpautop($current_text); // apply filter to allow 3rd party changes. $current_text = apply_filters('watu_filter_current_question_text', $current_text, $qct, $question_content, $correct); // if question is survey, unresolved should be empty if ($ques->is_survey) { $unresolved_text = ''; } return array($answer_text, $current_text, $unresolved_text); }
</p> <?php } ?> <h2><?php _e("Currently available modules", 'watupro'); ?> </h2> <ul> <li><strong><?php _e('Intelligence module -', 'watupro'); ?> </strong> <?php echo watupro_intel() ? __("Installed", 'watupro') : __("Not installed", 'watupro'); ?> </li> <li><strong><?php _e('Reporting module -', 'watupro'); ?> </strong> <?php echo watupro_module('reports') ? __("Installed", 'watupro') : __("Not installed", 'watupro'); ?> </li> </ul> <p><a href="http://calendarscripts.info/watupro/modules.html" target="_blank"><?php _e('For more info about the additional modules please click here.', 'watupro'); ?> </a></p>
$exam->final_screen = str_replace(array('%%GRADE%%', '%%GDESC%%'), array(wpautop($grade, false), wpautop(stripslashes(@$grade_obj->gdescription), false)), $exam->final_screen); $exam->email_output = str_replace(array('%%GRADE%%', '%%GDESC%%'), array(wpautop($grade, false), wpautop(stripslashes(@$grade_obj->gdescription), false)), $exam->email_output); // prepare output $replace_these = array('%%CORRECT%%', '%%TOTAL%%', '%%PERCENTAGE%%', '%%RATING%%', '%%CORRECT_ANSWERS%%', '%%QUIZ_NAME%%', '%%DESCRIPTION%%', '%%POINTS%%', '%%CERTIFICATE%%', '%%GTITLE%%', '%%UNRESOLVED%%', '%%ANSWERS%%', '%%CATGRADES%%', '%%DATE%%', '%%EMAIL%%', '%%MAX-POINTS%%', '%%watupro-share-url%%', '%%TIME-SPENT%%', '%%USER-NAME%%', '%%AVG-POINTS%%', '%%AVG-PERCENT%%'); $with_these = array($score, $total, $percent, $rating, $score, stripslashes($exam->name), wpautop(stripslashes($exam->description)), $achieved, $certificate, stripslashes(@$grade_obj->gtitle), $unresolved_questions, $result, $catgrades, date(get_option('date_format'), current_time('timestamp')), $user_email, $max_points, $share_url, $time_spent, $user_name, $avg_points, $avg_percent); // Show the results $output = "<div id='startOutput'> </div>"; $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; }
function watupro_options() { global $wpdb, $wp_roles; $roles = $wp_roles->roles; if (isset($_REQUEST['submit']) and $_REQUEST['submit']) { if (empty($_POST['currency'])) { $_POST['currency'] = $_POST['custom_currency']; } $options = array('single_page', 'answer_type', 'delete_db', 'paypal', 'other_payments', 'currency', 'recaptcha_public', 'recaptcha_private', 'accept_stripe', 'stripe_public', 'stripe_secret', 'really_delete_db', 'accept_paypoints', 'paypoints_price', 'paypoints_button', 'debug_mode', 'nodisplay_myquizzes', 'nodisplay_mycertificates', 'nodisplay_reports_tests', 'nodisplay_reports_skills', 'nodisplay_reports_history', 'nodisplay_paid_quizzes', 'nodisplay_mysettings', 'always_load_scripts'); foreach ($options as $opt) { if (!empty($_POST[$opt])) { update_option('watupro_' . $opt, $_POST[$opt]); } else { update_option('watupro_' . $opt, 0); } } update_option('watupro_admin_email', $_POST['watupro_admin_email']); // add/remove capabilities if (current_user_can('manage_options')) { foreach ($roles as $key => $role) { $r = get_role($key); if (@in_array($key, $_POST['manage_roles'])) { if (empty($r->capabilities['watupro_manage_exams'])) { $r->add_cap('watupro_manage_exams'); } } else { $r->remove_cap('watupro_manage_exams'); } } } // end if administrator } if (watupro_intel()) { $currency = get_option('watupro_currency'); $currencies = array('USD' => '$', "EUR" => "€", "GBP" => "£", "JPY" => "¥", "AUD" => "AUD", "CAD" => "CAD", "CHF" => "CHF", "CZK" => "CZK", "DKK" => "DKK", "HKD" => "HKD", "HUF" => "HUF", "ILS" => "ILS", "MXN" => "MXN", "NOK" => "NOK", "NZD" => "NZD", "PLN" => "PLN", "SEK" => "SEK", "SGD" => "SGD", "ZAR" => "ZAR"); $currency_keys = array_keys($currencies); $accept_stripe = get_option('watupro_accept_stripe'); $payment_errors = get_option("watupro_errorlog"); $payment_errors = substr($payment_errors, 0, 10000); $other_payments = get_option('watupro_other_payments'); $other_payments = empty($other_payments) ? "" : $other_payments; } // exams in watu light? if ($wpdb->get_var("SHOW TABLES LIKE '" . $wpdb->prefix . "watu_master" . "'") == $wpdb->prefix . "watu_master") { $watu_exams = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "watu_master ORDER BY ID"); if (!empty($_POST['copy_exams'])) { $num_copied = 0; foreach ($watu_exams as $exam) { // transfer the answer display settings in the best possible way $exam->live_result = 0; if ($exam->show_answers == 1) { $exam->final_screen .= "\n\n<p>%%ANSWERS%%</p>"; } if ($exam->show_answers == 2) { $exam->live_result = 1; } // randomize questions and/or answers? $randomize_questions = 0; if ($exam->randomize and $exam->randomize_answers) { $randomize_questions = 1; } if ($exam->randomize and !$exam->randomize_answers) { $randomize_questions = 2; } if (!$exam->randomize and $exam->randomize_answers) { $randomize_questions = 3; } $wpdb->query($wpdb->prepare("INSERT INTO " . WATUPRO_EXAMS . " SET \n\t\t\t\t\t\tname=%s, description=%s, final_screen=%s, added_on=%s, is_active=1,\n\t\t\t\t\t\tshow_answers=0, email_output='', live_result=%d, randomize_questions=%d,\n\t\t\t\t\t\trequire_login=%d, email_admin=%d", stripslashes($exam->name), stripslashes($exam->description), stripslashes($exam->final_screen), date("Y-m-d"), $exam->live_result, $randomize_questions, $exam->require_login, $exam->notify_admin)); $id = $wpdb->insert_id; // echo $id.'a'; if ($id) { $num_copied++; // copy questions and choices $questions = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "watu_question \n\t\t\t\t\t\t\tWHERE exam_id=%d ORDER BY ID", $exam->ID)); foreach ($questions as $question) { $wpdb->query($wpdb->prepare("INSERT INTO " . $wpdb->prefix . "watupro_question SET\n\t\t\t\t\t\t\t\texam_id=%d, question=%s, answer_type=%s, sort_order=%d", $id, stripslashes($question->question), stripslashes($question->answer_type), $question->sort_order)); $qid = $wpdb->insert_id; if ($qid) { $choices = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}watu_answer \n\t\t\t\t\t\t\t\t\tWHERE question_id=%d ORDER BY ID", $question->ID)); foreach ($choices as $choice) { $wpdb->query($wpdb->prepare("INSERT INTO {$wpdb->prefix}watupro_answer SET\n\t\t\t\t\t\t\t\t\t\tquestion_id=%d, answer=%s, correct=%s, point=%d, sort_order=%d", $qid, stripslashes($choice->answer), $choice->correct, $choice->point, $choice->sort_order)); } } } // copy grades $grades = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}watu_grading WHERE exam_id=%d ORDER BY ID", $exam->ID)); foreach ($grades as $gct => $grade) { $wpdb->query($wpdb->prepare("INSERT INTO {$wpdb->prefix}watupro_grading SET\n\t\t\t\t\t\t\t\texam_id=%d, gtitle=%s, gdescription=%s, gfrom=%d, gto=%d", $id, stripslashes($grade->gtitle), stripslashes($grade->gdescription), $grade->gfrom, $grade->gto)); $grade_id = $wpdb->insert_id; $grades[$gct]->new_grade_id = $grade_id; } // end foreach grade // replace shortcodes? if (!empty($_POST['replace_watu_shortcodes'])) { $wpdb->query("UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, '[WATU " . $exam->ID . "]', '[watupro " . $id . "]')"); } // copy takings? if (!empty($_POST['copy_takings'])) { $takings = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}watu_takings \n\t\t\t\t\t\t\t\tWHERE exam_id=%d ORDER BY ID", $exam->ID)); foreach ($takings as $taking) { // figure out the taking grade ID $taking_grade_id = 0; foreach ($grades as $grade) { if ($taking->grade_id == $grade->ID) { $taking_grade_id = $grade->new_grade_id; } } $wpdb->query($wpdb->prepare("INSERT INTO " . WATUPRO_TAKEN_EXAMS . " SET\n\t\t\t\t\t\t\t\t\tuser_id=%d, exam_id=%d, date=%s, points=%s, details=%s, result=%s, ip=%s, grade_id=%d", $taking->user_id, $id, $taking->date, $taking->points, stripslashes($taking->snapshot), stripslashes($taking->result), $taking->ip, $taking_grade_id)); } } } // end if exam $id } // end foreach exam $copy_message = sprintf(__("%d %s successfully copied.", 'watupro'), $num_copied, __('quizzes', 'watupro')); } // end if copy exams } // end if there is watu table $delete_db = get_option('watupro_delete_db'); // save no_ajax if (!empty($_POST['save_ajax_settings'])) { $ids = empty($_POST['no_ajax']) ? array(0) : $_POST['no_ajax']; $wpdb->query("UPDATE " . WATUPRO_EXAMS . " SET no_ajax=1 WHERE id IN (" . implode(', ', $ids) . ")"); $wpdb->query("UPDATE " . WATUPRO_EXAMS . " SET no_ajax=0 WHERE id NOT IN (" . implode(', ', $ids) . ")"); update_option('watupro_max_upload', intval($_POST['max_upload'])); update_option('watupro_upload_file_types', $_POST['upload_file_types']); } // select all quizzes for No Ajax option $quizzes = $wpdb->get_results("SELECT ID, name, no_ajax FROM " . WATUPRO_EXAMS . " ORDER BY name"); if (@file_exists(get_stylesheet_directory() . '/watupro/options.php')) { require get_stylesheet_directory() . '/watupro/options.php'; } else { require WATUPRO_PATH . "/views/options.php"; } }
if (watupro_intel()) { ?> jQuery('#fillTheGapsText').hide(); jQuery('#sortingText').hide(); jQuery('#sortAnswerArea').hide(); jQuery('#matrixAnswerArea').hide(); <?php } ?> switch(ansType) { case 'radio': jQuery('#answersArea').show(); jQuery('#trueFalseArea').show(); wtpSetTrueFalse(jQuery('#wtpTrueFalse').attr('checked')); break; case 'checkbox': jQuery('#answersArea').show(); jQuery('#questionCorrectCondition').show(); jQuery('#maxSelections').show(); break; case 'textarea': jQuery('#answersArea').show(); jQuery('#questionCorrectCondition').show(); jQuery('#openEndText').show(); break; <?php if (watupro_intel()) { ?> case 'gaps': jQuery('#fillTheGapsText').show(); jQuery('#questionCorrectCondition').show(); break; case 'sort': jQuery('#sortingText').show(); jQuery('#sortAnswerArea').show(); jQuery('#questionCorrectCondition').show(); break; case 'matrix': jQuery('#sortingText').show(); jQuery('#questionCorrectCondition').show(); jQuery('#matrixAnswerArea').show(); break; <?php } ?> } } // go to rich text mode function WatuProGoRichText(answerID) { jQuery('#wtpQuestionForm input[name=goto_rich_text]').val('' + answerID); document.getElementById('wtpQuestionForm').submit(); }
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; }
static function my_exams($uid, $cat_id_sql, $orderby = "tE.ID") { global $wpdb; $cat_id_sql = strlen($cat_id_sql) ? "AND tE.cat_id IN ({$cat_id_sql})" : ""; $paid_ids_sql = ''; if (watupro_intel() and !current_user_can(WATUPRO_MANAGE_CAPS) and get_option('watupro_nodisplay_paid_quizzes')) { // don't display quizzes that require payment but are not paid for $pids = array(0); $paid_ids = $wpdb->get_results($wpdb->prepare("SELECT tE.ID as ID FROM " . WATUPRO_EXAMS . " tE\n\t\t\t\tWHERE tE.fee > 0 AND tE.ID NOT IN \n\t\t\t\t(SELECT tP.exam_id FROM " . WATUPRO_PAYMENTS . " tP WHERE tP.user_id=%d AND tP.status = 'completed' )", $uid)); foreach ($paid_ids as $pid) { $pids[] = $pid->ID; } $paid_ids_sql = " AND tE.ID NOT IN (" . implode(",", $pids) . ") "; } // select all exams along with posts they have been embedded in $exams = $wpdb->get_results("SELECT tE.*, tC.name as cat \n\t\t\tFROM " . WATUPRO_EXAMS . " tE LEFT JOIN " . WATUPRO_CATS . " tC\n\t\t\tON tC.ID=tE.cat_id\n\t\t\tWHERE tE.is_active=1 {$cat_id_sql} {$paid_ids_sql} ORDER BY {$orderby}"); // now select all posts that have watupro shortcode in them $posts = $wpdb->get_results("SELECT * FROM {$wpdb->posts} \n\t\t\tWHERE post_content LIKE '%[watupro %]%' \n\t\t\tAND post_status='publish' AND post_title!=''\n\t\t\tORDER BY post_date DESC"); // select all exams that I have taken # $wpdb->show_errors=true; $takings = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . WATUPRO_TAKEN_EXAMS . "\n\t\t\tWHERE user_id=%d AND in_progress=0 ORDER BY ID DESC", $uid)); $tids = array(); foreach ($takings as $taking) { $tids[] = $taking->exam_id; } // final exams array - should contain only one post per exam, and we should know which one // is taken and which one is not $my_exams = array(); $num_taken = 0; foreach ($exams as $cnt => $exam) { $my_exam = $exam; if (in_array($exam->ID, $tids)) { $my_exam->is_taken = 1; } else { $my_exam->is_taken = 0; } $post_found = false; foreach ($posts as $post) { if (stristr($post->post_content, "[WATUPRO " . $exam->ID . "]")) { $my_exam->post = $post; $post_found = true; break; } } // maybe post wasn't found but the quiz is published innon-standard way? if ($exam->published_odd) { $post_found = true; } if ($post_found) { // match latest taking and fill all takings $my_exam->takings = array(); foreach ($takings as $taking) { if ($taking->exam_id != $exam->ID) { continue; } if (empty($my_exam->taking)) { $my_exam->taking = $taking; $num_taken++; } $my_exam->takings[] = $taking; } // add to the final array $my_exams[] = $my_exam; } // end if $post_found } // end foreach exam // primary returns $my_exams, but $takings may also be used as it's retrieved anyway return array($my_exams, $takings, $num_taken); }
function watupro_copy_exam() { global $wpdb, $user_ID; $multiuser_access = 'all'; if (watupro_intel()) { $multiuser_access = WatuPROIMultiUser::check_access('exams_access'); } $own_sql = $multiuser_access == 'own' ? $wpdb->prepare(" AND editor_id=%d ", $user_ID) : ""; $exam = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_EXAMS . " WHERE ID=%d", $_GET['id'])); $grades = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . WATUPRO_GRADES . " WHERE exam_id=%d order by ID ", $exam->ID)); $questions = $wpdb->get_results($wpdb->prepare("SELECT cat_id, question, ID FROM " . WATUPRO_QUESTIONS . " WHERE exam_id=%d ORDER BY sort_order, ID", $exam->ID)); $cids = array(0); foreach ($questions as $question) { if (!in_array($question->cat_id, $cids)) { $cids[] = $question->cat_id; } } $cidsql = implode(", ", $cids); // select question categories to group questions by cats $qcats = $wpdb->get_results("SELECT * FROM " . WATUPRO_QCATS . " WHERE ID IN ({$cidsql}) ORDER BY name"); // add Uncategorized $qcats[] = (object) array("ID" => 0, "name" => __('Uncategorized', 'watupro')); $other_exams = $wpdb->get_results("SELECT * FROM " . WATUPRO_EXAMS . " WHERE ID!='" . $exam->ID . "' {$own_sql} ORDER BY name"); if (!empty($_POST['copy_exam'])) { try { $copy_to = $_POST['copy_option'] == 'new' ? 0 : $_POST['copy_to']; WTPExam::copy($exam->ID, $copy_to); $_SESSION['flash'] = __("The exam was successfully copied!", 'watupro'); watupro_redirect("admin.php?page=watupro_exams"); } catch (Exception $e) { $error = $e->getMessage(); } } if (@file_exists(get_stylesheet_directory() . '/watupro/copy-exam-form.html.php')) { require get_stylesheet_directory() . '/watupro/copy-exam-form.html.php'; } else { require WATUPRO_PATH . "/views/copy-exam-form.html.php"; } }
function watupro_cats() { global $wpdb, $wp_roles, $user_ID; $groups_table = WATUPRO_GROUPS; $multiuser_access = 'all'; if (watupro_intel()) { $multiuser_access = WatuPROIMultiUser::check_access('cats_access'); } // are we using WP Roles or Watupro groups $use_wp_roles = get_option('watupro_use_wp_roles'); // select all groups if (!$use_wp_roles) { $groups = $wpdb->get_results("SELECT * FROM " . WATUPRO_GROUPS . " ORDER BY name"); } else { $roles = $wp_roles->roles; } switch (@$_GET['do']) { case 'add': if (!empty($_POST['ok'])) { $wpdb->query($wpdb->prepare("INSERT INTO " . WATUPRO_CATS . " (name, ugroups, editor_id)\n\t\t\t\t\tVALUES (%s, %s, %d)", $_POST['name'], "|" . @implode("|", $_POST['ugroups']) . "|", $user_ID)); echo "<meta http-equiv='refresh' content='0;url=admin.php?page=watupro_cats' />"; exit; } if (@file_exists(get_stylesheet_directory() . '/watupro/cat.php')) { require get_stylesheet_directory() . '/watupro/cat.php'; } else { require WATUPRO_PATH . "/views/cat.php"; } break; case 'edit': if ($multiuser_access == 'own') { $cat = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_CATS . " WHERE ID=%d", $_GET['id'])); if ($cat->editor_id != $user_ID) { wp_die(__('You can manage only your own categories', 'watupro')); } } if (!empty($_POST['del'])) { $wpdb->query($wpdb->prepare("DELETE FROM " . WATUPRO_CATS . " WHERE ID=%d", $_GET['id'])); // set cat_id=0 to all exams that were in this cat $wpdb->query($wpdb->prepare("UPDATE " . WATUPRO_EXAMS . " SET cat_id=0 WHERE cat_id=%d", $_GET['id'])); echo "<meta http-equiv='refresh' content='0;url=admin.php?page=watupro_cats' />"; exit; } if (!empty($_POST['ok'])) { $wpdb->query($wpdb->prepare("UPDATE " . WATUPRO_CATS . " SET\n\t\t\t\t\tname=%s, ugroups=%s WHERE ID=%d", $_POST['name'], "|" . @implode("|", $_POST['ugroups']) . "|", $_GET['id'])); echo "<meta http-equiv='refresh' content='0;url=admin.php?page=watupro_cats' />"; exit; } $cat = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_CATS . " WHERE ID=%d", $_GET['id'])); if (@file_exists(get_stylesheet_directory() . '/watupro/cat.php')) { require get_stylesheet_directory() . '/watupro/cat.php'; } else { require WATUPRO_PATH . "/views/cat.php"; } break; default: // select my cats $own_sql = $multiuser_access == 'own' ? $wpdb->prepare(" WHERE editor_id = %d ", $user_ID) : ""; $cats = $wpdb->get_results("SELECT * FROM " . WATUPRO_CATS . " {$own_sql} ORDER BY name"); if (@file_exists(get_stylesheet_directory() . '/watupro/cats.php')) { require get_stylesheet_directory() . '/watupro/cats.php'; } else { require WATUPRO_PATH . "/views/cats.php"; } break; } }
function watupro_takings() { global $wpdb, $wp_roles, $user_ID; $roles = $wp_roles->roles; $multiuser_access = 'all'; if (watupro_intel()) { $multiuser_access = WatuPROIMultiUser::check_access('exams_access'); } // select user groups $groups = $wpdb->get_results("SELECT * FROM " . WATUPRO_GROUPS . " ORDER BY name"); // shows data for a taken exam $ob = empty($_GET['ob']) ? "id" : $_GET['ob']; $dir = !empty($_GET['dir']) ? $_GET['dir'] : "DESC"; $odir = $dir == 'ASC' ? 'DESC' : 'ASC'; $offset = empty($_GET['offset']) ? 0 : $_GET['offset']; // select exam $exam = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_EXAMS . " WHERE ID=%d", $_GET['exam_id'])); if (!empty($_POST['cleanup']) or !empty($_POST['blankout'])) { if ($multiuser_access == 'own' and $exam->editor_id != $user_ID) { wp_die(__('You can manage only the results on exams created by you.', 'watupro')); } if (!empty($_POST['cleanup'])) { // now cleanup $wpdb->query($wpdb->prepare("DELETE FROM " . WATUPRO_TAKEN_EXAMS . " WHERE exam_id=%d", $exam->ID)); $wpdb->query($wpdb->prepare("DELETE FROM " . WATUPRO_STUDENT_ANSWERS . " WHERE exam_id=%d", $exam->ID)); } if (!empty($_POST['blankout'])) { $wpdb->query($wpdb->prepare("UPDATE " . WATUPRO_TAKEN_EXAMS . " \n\t\t\t\tSET details='data removed', catgrades='data removed' WHERE exam_id=%d", $exam->ID)); $wpdb->query($wpdb->prepare("UPDATE " . WATUPRO_STUDENT_ANSWERS . " \n\t\t\t\tSET question_text='data removed', snapshot='data removed' WHERE exam_id=%d", $exam->ID)); } } // check access if ($multiuser_access == 'own') { if ($exam->editor_id != $user_ID) { wp_die(__('You can only view results on your own quizzes.', 'watupro')); } } // search/filter $filters = array(); $joins = array(); $filter_sql = $left_join_sql = $role_join_sql = $group_join_sql = $left_join = ""; $join_sql = "LEFT JOIN {$wpdb->users} tU ON tU.ID=tT.user_id"; // add filters and joins // display name if (!empty($_GET['dn'])) { switch ($_GET['dnf']) { case 'contains': $like = "%{$_GET['dn']}%"; break; case 'starts': $like = "{$_GET['dn']}%"; break; case 'ends': $like = "%{$_GET['dn']}"; break; case 'equals': default: $like = $_GET['dn']; break; } $joins[] = $wpdb->prepare(" display_name LIKE %s ", $like); } // email if (!empty($_GET['email'])) { switch ($_GET['emailf']) { case 'contains': $like = "%{$_GET['email']}%"; break; case 'starts': $like = "{$_GET['email']}%"; break; case 'ends': $like = "%{$_GET['email']}"; break; case 'equals': default: $like = $_GET['email']; break; } $joins[] = $wpdb->prepare(" user_email LIKE %s ", $like); $filters[] = $wpdb->prepare(" ((user_id=0 AND email LIKE %s) OR (user_id!=0 AND user_email LIKE %s)) ", $like, $like); $left_join = 'LEFT'; // when email is selected, do left join because it might be without logged user } // WP user role - when selected role the join always becomes right join if (!empty($_GET['role'])) { $left_join = ''; $blog_prefix = $wpdb->get_blog_prefix(); $role_join_sql = "JOIN {$wpdb->usermeta} tUM ON tUM.user_id = tU.id \n\t\t\tAND tUM.meta_key = '{$blog_prefix}capabilities' AND tUM.meta_value LIKE '%:" . '"' . $_GET['role'] . '"' . ";%'"; } // Watupro user group if (!empty($_GET['ugroup'])) { $left_join = ''; $group_join_sql = "JOIN {$wpdb->usermeta} tUM2 ON tUM2.user_id = tU.id \n\t\t\tAND tUM2.meta_key = 'watupro_groups' AND tUM2.meta_value LIKE '%:" . '"' . $_GET['ugroup'] . '"' . ";%'"; } else { $group_join_sql = "LEFT JOIN {$wpdb->usermeta} tUM2 ON tUM2.user_id = tU.id \n\t\t\tAND tUM2.meta_key = 'watupro_groups' "; } // IP if (!empty($_GET['ip'])) { switch ($_GET['ipf']) { case 'contains': $like = "%{$_GET['ip']}%"; break; case 'starts': $like = "{$_GET['ip']}%"; break; case 'ends': $like = "%{$_GET['ip']}"; break; case 'equals': default: $like = $_GET['ip']; break; } $filters[] = $wpdb->prepare(" ip LIKE %s ", $like); } // Date if (!empty($_GET['date'])) { switch ($_GET['datef']) { case 'after': $filters[] = $wpdb->prepare(" date>%s ", $_GET['date']); break; case 'before': $filters[] = $wpdb->prepare(" date<%s ", $_GET['date']); break; case 'equals': default: $filters[] = $wpdb->prepare(" date=%s ", $_GET['date']); break; } } // Points if (!empty($_GET['points'])) { switch ($_GET['pointsf']) { case 'less': $filters[] = $wpdb->prepare(" points<%d ", $_GET['points']); break; case 'more': $filters[] = $wpdb->prepare(" points>%d ", $_GET['points']); break; case 'equals': default: $filters[] = $wpdb->prepare(" points=%d ", $_GET['points']); break; } } // % correct if (!empty($_GET['percent_correct'])) { switch ($_GET['percentf']) { case 'less': $filters[] = $wpdb->prepare(" percent_correct < %d ", $_GET['percent_correct']); break; case 'more': $filters[] = $wpdb->prepare(" percent_correct > %d ", $_GET['percent_correct']); break; case 'equals': default: $filters[] = $wpdb->prepare(" percent_correct = %d ", $_GET['percent_correct']); break; } } // passed taking ID from the manage user-certificates page if (!empty($_GET['taking_id'])) { $filters[] = $wpdb->prepare(" tT.ID=%d ", $_GET['taking_id']); } // Grade if (!empty($_GET['grade'])) { $filters[] = $wpdb->prepare(" grade_id=%d ", $_GET['grade']); } // construct filter & join SQLs if (sizeof($filters)) { $filter_sql = " AND " . implode(" AND ", $filters); } if (sizeof($joins)) { $join_sql = " {$left_join} JOIN {$wpdb->users} tU ON tU.ID=tT.user_id AND " . implode(" AND ", $joins); } $limit_sql = "LIMIT {$offset},10"; if (!empty($_GET['export'])) { $limit_sql = ""; } // select takings $in_progress = empty($_GET['in_progress']) ? 0 : 1; // completed or "in progress" takings $q = "SELECT SQL_CALC_FOUND_ROWS tT.*, tU.display_name as display_name, tU.user_email as user_email,\n\ttUM2.meta_value as user_groups\n\tFROM " . WATUPRO_TAKEN_EXAMS . " tT \n\t{$join_sql} {$role_join_sql} {$group_join_sql}\n\tWHERE tT.exam_id={$exam->ID} AND tT.in_progress={$in_progress} {$filter_sql}\n\tORDER BY {$ob} {$dir} {$limit_sql}"; // echo $q; $takings = $wpdb->get_results($q); $count = $wpdb->get_var("SELECT FOUND_ROWS()"); // fill user groups foreach ($takings as $cnt => $taking) { if (empty($taking->user_groups)) { continue; } $ugroups = unserialize($taking->user_groups); $ugroup_names = array(); foreach ($groups as $group) { if (in_array($group->ID, $ugroups)) { $ugroup_names[] = $group->name; } } $takings[$cnt]->user_groups = implode(', ', $ugroup_names); } // end filling user groups info // select number of in_progress takings unless we are showing them now if (!$in_progress) { $num_unfinished = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM " . WATUPRO_TAKEN_EXAMS . "\n\t\t\tWHERE exam_id = %d AND in_progress=1", $exam->ID)); } if (!empty($_GET['export'])) { $_record = new WTPRecord(); $_record->export($takings, $exam); } // grades for the dropdown $grades = WTPGrade::get_grades($exam); // this var will be added to links at the view $filters_url = "dn=" . @$_GET['dn'] . "&dnf=" . @$_GET['dnf'] . "&email=" . @$_GET['email'] . "&emailf=" . @$_GET['emailf'] . "&ip=" . @$_GET['ip'] . "&ipf=" . @$_GET['ipf'] . "&date=" . @$_GET['date'] . "&datef=" . @$_GET['datef'] . "&points=" . @$_GET['points'] . "&pointsf=" . @$_GET['pointsf'] . "&grade=" . @$_GET['grade'] . "&role=" . @$_GET['role'] . "&ugroup=" . @$_GET['ugroup'] . "&percent_correct=" . @$_GET['percent_correct'] . "&percentf=" . @$_GET['percentf']; $display_filters = (!sizeof($filters) and !sizeof($joins) and empty($role_join_sql) and empty($_GET['ugroup'])) ? false : true; wp_enqueue_script('thickbox', null, array('jquery')); wp_enqueue_style('thickbox.css', '/' . WPINC . '/js/thickbox/thickbox.css', null, '1.0'); if (@file_exists(get_stylesheet_directory() . '/watupro/takings.php')) { require get_stylesheet_directory() . '/watupro/takings.php'; } else { require WATUPRO_PATH . "/views/takings.php"; } }
function watupro_default_grades() { global $wpdb, $user_ID; $in_default_grades = true; $percentage_based = intval(@$_GET['percentage_based']); $exam = (object) array("ID" => 0, "name" => "", "grades_by_percent" => $percentage_based); // check access $multiuser_access = 'all'; $userid_sql = ''; if (watupro_intel()) { $multiuser_access = WatuPROIMultiUser::check_access('exams_access'); } // change the common gradecat design if (!empty($_POST['save_design']) and $multiuser_access == 'all') { update_option('watupro_gradecat_design', $_POST['gradecat_design']); } // prepare the default gradecat design $gradecat_design = get_option('watupro_gradecat_design'); if (empty($gradecat_design)) { $gradecat_design = "<p>" . __('For category <strong>%%CATEGORY%%</strong> you got grade <strong>%%GTITLE%%</strong>.', 'watupro') . "</p>\n\t\t\t<p>%%GDESC%%</p><hr>"; update_option('watupro_gradecat_design', $gradecat_design); } // select question categories $cats = $wpdb->get_results("SELECT * FROM " . WATUPRO_QCATS . " WHERE name!='' ORDER BY name"); if (!empty($_POST['add'])) { $wpdb->query($wpdb->prepare("INSERT INTO " . WATUPRO_GRADES . " SET\n\t\t\texam_id=0, gtitle=%s, gdescription=%s, gfrom=%s, gto=%s, certificate_id=%d, \n\t\t\tcat_id=%d, editor_id=%d, percentage_based=%d", $_POST['gtitle'], $_POST['gdescription'], $_POST['gfrom'], $_POST['gto'], @$_POST['certificate_id'], $_POST['cat_id'], $user_ID, $percentage_based)); } if (!empty($_POST['del'])) { if ($multiuser_access == 'own') { $userid_sql = $wpdb->prepare(" AND editor_id=%d ", $user_ID); } $wpdb->query($wpdb->prepare("DELETE FROM " . WATUPRO_GRADES . " WHERE ID=%d {$userid_sql}", $_POST['id'])); } if (!empty($_POST['save'])) { if ($multiuser_access == 'own') { $userid_sql = $wpdb->prepare(" AND editor_id=%d ", $user_ID); } $wpdb->query($wpdb->prepare("UPDATE " . WATUPRO_GRADES . " SET\n\t\t\tgtitle=%s, gdescription=%s, gfrom=%s, gto=%s, certificate_id=%d\n\t\t\tWHERE ID=%d {$userid_sql}", $_POST['gtitle'], $_POST['gdescription' . $_POST['id']], $_POST['gfrom'], $_POST['gto'], @$_POST['certificate_id'], $_POST['id'])); } $cat_id = empty($_POST['cat_id']) ? 0 : $_POST['cat_id']; // select all grades of the selected category $grades = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . WATUPRO_GRADES . " \n\t\tWHERE exam_id=0 AND cat_id=%d AND percentage_based=%d", $cat_id, $percentage_based)); // for the moment certificates will be used only on non-category grades if (!$cat_id) { // select certificates if any $certificates = $wpdb->get_results("SELECT * FROM " . WATUPRO_CERTIFICATES . " ORDER BY title"); $cnt_certificates = sizeof($certificates); } if (@file_exists(get_stylesheet_directory() . '/watupro/grades.php')) { require get_stylesheet_directory() . '/watupro/grades.php'; } else { require WATUPRO_PATH . "/views/grades.php"; } }
function watupro_add_menu_links() { global $wp_version, $_registered_pages; $page = 'tools.php'; $student_caps = current_user_can(WATUPRO_MANAGE_CAPS) ? WATUPRO_MANAGE_CAPS : 'read'; // used to be watupro_exams // multiuser settings - let's first default all to WATUPRO_MANAGE_CAPS in case of no Intelligence module $exam_caps = $certificate_caps = $cat_caps = $ugroup_caps = $qcat_caps = $setting_caps = WATUPRO_MANAGE_CAPS; if (watupro_intel() and !current_user_can('administrator')) { if (!WatuPROIMultiUser::check_access('exams_access', true)) { $exam_caps = 'administrator'; } if (!WatuPROIMultiUser::check_access('certificates_access', true)) { $certificate_caps = 'administrator'; } if (!WatuPROIMultiUser::check_access('cats_access', true)) { $cat_caps = 'administrator'; } if (!WatuPROIMultiUser::check_access('usergroups_access', true)) { $ugroup_caps = 'administrator'; } if (!WatuPROIMultiUser::check_access('qcats_access', true)) { $qcat_caps = 'administrator'; } if (!WatuPROIMultiUser::check_access('settings_access', true)) { $setting_caps = 'administrator'; } } // students part if (!get_option('watupro_nodisplay_myquizzes')) { add_menu_page(sprintf(__('My %s', 'watupro'), __('Quizzes', 'watupro')), sprintf(__('My %s', 'watupro'), __('Quizzes', 'watupro')), $student_caps, "my_watupro_exams", 'watupro_my_exams'); } else { add_submenu_page(null, sprintf(__('My %s', 'watupro'), __('Quizzes', 'watupro')), sprintf(__('My %s', 'watupro'), __('Quizzes', 'watupro')), $exam_caps, "my_watupro_exams", 'watupro_my_exams'); } if (!get_option('watupro_nodisplay_mycertificates')) { add_submenu_page('my_watupro_exams', __("My Certificates", 'watupro'), __("My Certificates", 'watupro'), $student_caps, 'watupro_my_certificates', 'watupro_my_certificates'); } else { add_submenu_page(null, __("My Certificates", 'watupro'), __("My Certificates", 'watupro'), $exam_caps, 'watupro_my_certificates', 'watupro_my_certificates'); } do_action('watupro_user_menu'); if (!get_option('watupro_nodisplay_mysettings')) { add_submenu_page('my_watupro_exams', sprintf(__("%s Settings", 'watupro'), __('Quiz', 'watupro')), sprintf(__("%s Settings", 'watupro'), __('Quiz', 'watupro')), $student_caps, 'watupro_my_options', 'watupro_my_options'); } // admin menus // "watupro_exams" menu is always accessible to WATUPRO_MANAGE_CAPS because it's the main menu item add_menu_page(__('Watu PRO', 'watupro'), __('Watu PRO', 'watupro'), WATUPRO_MANAGE_CAPS, "watupro_exams", 'watupro_exams'); add_submenu_page('watupro_exams', __('Quizzes', 'watupro'), __('Quizzes', 'watupro'), WATUPRO_MANAGE_CAPS, "watupro_exams", 'watupro_exams'); add_submenu_page('watupro_exams', __("Watu PRO Certificates", 'watupro'), __("Certificates", 'watupro'), $certificate_caps, 'watupro_certificates', 'watupro_certificates'); add_submenu_page('watupro_exams', __('Quiz Categories', 'watupro'), __('Quiz Categories', 'watupro'), $cat_caps, "watupro_cats", "watupro_cats"); add_submenu_page('watupro_exams', __('User Groups', 'watupro'), __('User Groups', 'watupro'), $ugroup_caps, "watupro_groups", "watupro_groups"); add_submenu_page('watupro_exams', __('Question Categories', 'watupro'), __('Question Categories', 'watupro'), $qcat_caps, "watupro_question_cats", "watupro_question_cats"); add_submenu_page('watupro_exams', __('Default Grades', 'watupro'), __('Default Grades', 'watupro'), $exam_caps, "watupro_default_grades", "watupro_default_grades"); // accessible only to superadmin add_submenu_page('watupro_exams', __('Modules', 'watupro'), __('Modules', 'watupro'), 'manage_options', "watupro_modules", "watupro_modules"); add_submenu_page('watupro_exams', __('Settings', 'watupro'), __('Settings', 'watupro'), $setting_caps, "watupro_options", "watupro_options"); do_action('watupro_admin_menu'); // always accessible to WATUPRO_MANAGE_CAPS add_submenu_page('watupro_exams', __('Help', 'watupro'), __('Help', 'watupro'), WATUPRO_MANAGE_CAPS, "watupro_help", "watupro_help"); // not visible in menu - add/edit exam add_submenu_page(NULL, __('Add/Edit Exam', 'watupro'), __('Add/Edit Exam', 'watupro'), $exam_caps, "watupro_exam", "watupro_exam"); add_submenu_page(NULL, __('Add/Edit Question', 'watupro'), __('Add/Edit Question', 'watupro'), $exam_caps, "watupro_question", "watupro_question"); // add/edit question add_submenu_page(NULL, __('Manage Questions', 'watupro'), __('Manage Questions', 'watupro'), $exam_caps, "watupro_questions", "watupro_questions"); // manage questions add_submenu_page(NULL, __('Taken Exam Data', 'watupro'), __('Taken Exam Data', 'watupro'), $exam_caps, "watupro_takings", "watupro_takings"); // view takings add_submenu_page(NULL, __('Manage Grades', 'watupro'), __('Manage Grades', 'watupro'), $exam_caps, "watupro_grades", "watupro_grades"); // manage grades add_submenu_page(NULL, __('Copy Exam', 'watupro'), __('Copy Exam', 'watupro'), $exam_caps, "watupro_copy_exam", "watupro_copy_exam"); // copy exam add_submenu_page(NULL, __('Users Who Earned Certificate', 'watupro'), __('Users Who Earned Certificate', 'watupro'), $certificate_caps, "watupro_user_certificates", "watupro_user_certificates"); // view/approve user certificates add_submenu_page(NULL, __('Editing an answer to question', 'watupro'), __('Editing an answer to question', 'watupro'), $exam_caps, "watupro_edit_choice", "watupro_edit_choice"); add_submenu_page(NULL, __('Advanced questions import', 'watupro'), __('Advanced questions import', 'watupro'), $exam_caps, "watupro_advanced_import", array('WatuPROImport', 'dispatch')); }
function watupro_edit_choice() { global $wpdb; // select choice $choice = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_ANSWERS . " WHERE ID=%d", $_GET['id'])); // select question $question = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_QUESTIONS . " WHERE ID=%d", $choice->question_id)); if (!empty($_POST['ok'])) { $wpdb->query($wpdb->prepare("UPDATE " . WATUPRO_ANSWERS . " SET answer=%s WHERE ID=%d", $_POST['answer'], $choice->ID)); // redirect to questions page watupro_redirect("admin.php?page=watupro_question&question=" . $question->ID . "&action=edit&quiz=" . $question->exam_id); } // select quiz $quiz = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_EXAMS . " WHERE ID=%d", $question->exam_id)); if (watupro_intel() and $quiz->is_personality_quiz) { $exam = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_EXAMS . " WHERE ID=%d", $question->exam_id)); $grades = WTPGrade::get_grades($exam); } if (@file_exists(get_stylesheet_directory() . '/watupro/edit-choice.html.php')) { require get_stylesheet_directory() . '/watupro/edit-choice.html.php'; } else { require WATUPRO_PATH . "/views/edit-choice.html.php"; } }
static function all_answers($in_shortcode = false) { global $wpdb; $ob = empty($_GET['ob']) ? "tA.ID" : $_GET['ob']; $dir = empty($_GET['dir']) ? "DESC" : $_GET['dir']; if (!in_array($dir, array("ASC", "DESC"))) { $dir = "DESC"; } $odir = $dir == 'ASC' ? 'DESC' : 'ASC'; $offset = empty($_GET['offset']) ? 0 : intval($_GET['offset']); $date_format = get_option('date_format'); $page_limit = 20; $limit_sql = empty($_GET['export']) ? "LIMIT {$offset}, {$page_limit}" : ""; // select exam $exam = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_EXAMS . " WHERE ID=%d", $_GET['exam_id'])); // select question $question = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_QUESTIONS . " WHERE ID=%d", $_GET['id'])); // select all user answers joined, ordered and paginated $answers = $wpdb->get_results($wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS tA.*, tT.date as date, tT.ip as ip, \n\t\tCONCAT(tT.email, tU.user_email) as email, tU.display_name as display_name\n\t\tFROM " . WATUPRO_STUDENT_ANSWERS . " tA JOIN " . WATUPRO_TAKEN_EXAMS . " tT ON tA.taking_id = tT.ID\n\t\tLEFT JOIN {$wpdb->users} tU ON tU.ID = tA.user_id\n\t\tWHERE tA.exam_id = %d AND tA.question_id = %d AND tT.in_progress = 0\n\t\tORDER BY {$ob} {$dir} {$limit_sql}", $exam->ID, $question->ID)); $count = $wpdb->get_var("SELECT FOUND_ROWS()"); if (!empty($_GET['export'])) { $newline = watupro_define_newline(); $rows = array(); $titlerow = __('User name', 'watupro') . "\t" . __('Email', 'watupro') . "\t" . __('IP', 'watupro') . "\t" . __('Date', 'watupro') . "\t" . __('Answer', 'watupro') . "\t" . __('Points', 'watupro') . "\t" . __('Is Correct?', 'watupro'); if (watupro_intel()) { $titlerow .= "\t" . __('Teacher comments', 'watupro'); } if (!empty($exam->question_hints) and !empty($question->hints)) { $titlerow .= "\t" . __('Hints used', 'watupro'); } $rows[] = $titlerow; foreach ($answers as $answer) { // cleanup $answer->answer = str_replace("\t", " ", $answer->answer); $answer->answer = str_replace('"', "'", $answer->answer); $answer->teacher_comments = str_replace("\t", " ", $answer->teacher_comments); $answer->teacher_comments = str_replace('"', "'", $answer->teacher_comments); $answer->hints_used = str_replace("\t", " ", $answer->hints_used); $answer->hints_used = str_replace('"', "'", $answer->hints_used); $answer->hints_used = str_replace("</div>", "; ", $answer->hints_used); $answer->hints_used = strip_tags($answer->hints_used); $row = ""; $row .= $answer->user_id ? $answer->display_name : __("N/A", 'watupro'); $row .= "\t" . ($answer->email ? $answer->email : __("N/A", 'watupro')); $row .= "\t" . $answer->ip; $row .= "\t" . date($date_format, strtotime($answer->date)); $row .= "\t" . $answer->answer; $row .= "\t" . $answer->points; $row .= "\t" . ($answer->is_correct ? __('Yes', 'watupro') : __('No', 'watupro')); if (watupro_intel()) { $row .= "\t" . $answer->teacher_comments; } if (!empty($exam->question_hints) and !empty($question->hints)) { $row .= "\t" . ($answer->num_hints_used ? sprintf(__('%d hints used:', 'watupro'), $answer->num_hints_used) . " " . trim($answer->hints_used) : __('No hints used', 'watupro')); } // remove new lines $row = str_replace("\n", " ", $row); $row = str_replace("\r", " ", $row); $row = stripslashes($row); $rows[] = $row; } $csv = implode($newline, $rows); $now = gmdate('D, d M Y H:i:s') . ' GMT'; header('Content-Type: ' . watupro_get_mime_type()); header('Expires: ' . $now); header('Content-Disposition: attachment; filename="exam-' . $exam->ID . '-question-' . $question->ID . '.csv"'); header('Pragma: no-cache'); echo $csv; exit; } if (@file_exists(get_stylesheet_directory() . '/watupro/reports/all-question-answers.html.php')) { require get_stylesheet_directory() . '/watupro/reports/all-question-answers.html.php'; } else { require WATUPRO_PATH . "/modules/reports/views/all-question-answers.html.php"; } }