Esempio n. 1
0
function watupro_listcode($attr)
{
    $cat_id = @$attr[0];
    if (empty($cat_id)) {
        $cat_id = @$attr['cat_id'];
    }
    // define orderby
    $ob = @$attr['orderby'];
    if (empty($ob)) {
        $ob = @$attr[1];
    }
    switch ($ob) {
        case 'title':
            $orderby = "tE.name";
            break;
        case 'latest':
            $orderby = "tE.ID DESC";
            break;
        case 'created':
        default:
            $orderby = "tE.ID";
            break;
    }
    watupro_vc_scripts();
    $show_status = empty($attr['show_status']) ? false : true;
    $content = WTPExam::show_list($cat_id, $orderby, $show_status);
    return $content;
}
Esempio n. 2
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";
    }
}
Esempio n. 3
0
if ($exam->email_taker and !is_user_logged_in()) {
    watupro_ask_for_email($exam);
}
// the exam is shown below
$question_count = $cat_count = $page_count = $num_pages = 1;
$question_ids = '';
$total = sizeof($all_question);
if ($exam->single_page == WATUPRO_PAGINATE_CUSTOM_NUMBER) {
    if ($exam->custom_per_page == 0) {
        $exam->custom_per_page = 1;
    }
    // this should never be zero
    $num_pages = ceil($total / $exam->custom_per_page);
}
if ($exam->show_pagination) {
    echo WTPExam::paginator($total, @$in_progress);
}
$question_catids = array();
// used for category based pagination and category header
$qct = 0;
if (empty($exam->time_limit) or !empty($_POST['watupro_start_timer'])) {
    // on timed exams questions should not be shown before the timer starts
    foreach ($all_question as $ques) {
        echo watupro_cat_header($exam, $qct, $ques);
        if ($exam->single_page == WATUPRO_PAGINATE_CUSTOM_NUMBER) {
            echo watupro_paginate_header($exam, $qct, $num_pages);
        }
        $qct++;
        echo "<div class='watu-question' id='question-{$question_count}'>";
        if (!$single_page and $cnt_questions > 1) {
            echo "<p class='watupro-qnum-info alignRight'>" . sprintf(__("Question Compeleted: %d out of %d", 'watupro'), $qct, $total) . "</p>";
Esempio n. 4
0
 static function skills($report_user_id, $has_tabs = true)
 {
     global $wpdb;
     // select exam categories that I can access
     $cat_ids = WTPCategory::user_cats($report_user_id);
     $cat_id_sql = implode(",", $cat_ids);
     $exam_cats = $wpdb->get_results("SELECT * FROM " . WATUPRO_CATS . " WHERE ID IN ({$cat_id_sql}) ORDER BY name");
     // question categories
     $q_cats = $wpdb->get_results("SELECT * FROM " . WATUPRO_QCATS . " ORDER BY name");
     // add uncategorized
     $q_cats[] = (object) array("ID" => 0, "name" => __('Uncategorized', 'watupro'));
     // exam category filter?
     $exam_cat_sql = @$_POST['cat'] < 0 ? $cat_id_sql : @$_POST['cat'];
     // now select all exams I have access to
     list($my_exams) = WTPExam::my_exams($report_user_id, $exam_cat_sql);
     $skill_filter = empty($_POST['skill_filter']) ? "all" : $_POST['skill_filter'];
     // practiced only?
     if ($skill_filter == 'practiced') {
         $final_exams = array();
         foreach ($my_exams as $exam) {
             if (!empty($exam->taking->ID)) {
                 $final_exams[] = $exam;
             }
         }
         $my_exams = $final_exams;
     }
     // proficiency filter selected? If yes, we'll need to limit exams
     // to those that are taken with at least $_POST['proficiency_goal'] % correct answers
     if ($skill_filter == 'proficient') {
         $final_exams = array();
         foreach ($my_exams as $exam) {
             if (!empty($exam->taking->ID) and $exam->taking->percent_correct >= $_POST['proficiency_goal']) {
                 $final_exams[] = $exam;
             }
         }
         // end exams loop
         $my_exams = $final_exams;
     }
     // for each exam select match answers and fill % correct info by category
     $taking_ids = array(0);
     foreach ($my_exams as $my_exam) {
         if (!empty($my_exam->taking->ID)) {
             $taking_ids[] = $my_exam->taking->ID;
         }
     }
     $user_answers = $wpdb->get_results("SELECT tA.is_correct as is_correct, tA.taking_id as taking_id, tQ.cat_id as cat_id \n\t\t\tFROM " . WATUPRO_STUDENT_ANSWERS . " tA JOIN " . WATUPRO_QUESTIONS . " tQ ON tQ.ID = tA.question_id\n\t\t\tWHERE tA.taking_id IN (" . implode(',', $taking_ids) . ") ORDER BY tA.ID");
     foreach ($my_exams as $cnt => $my_exam) {
         if (empty($my_exam->taking->ID)) {
             continue;
         }
         $cats = array();
         foreach ($user_answers as $answer) {
             if ($answer->taking_id != $my_exam->taking->ID) {
                 continue;
             }
             $correct_key = $answer->is_correct ? 'num_correct' : 'num_incorrect';
             if (isset($cats[$answer->cat_id][$correct_key])) {
                 $cats[$answer->cat_id][$correct_key]++;
             } else {
                 $cats[$answer->cat_id][$correct_key] = 1;
             }
         }
         // now foreach cat calculate the correctness
         foreach ($cats as $cat_id => $cat) {
             $num_correct = isset($cat['num_correct']) ? $cat['num_correct'] : 0;
             $num_incorrect = isset($cat['num_incorrect']) ? $cat['num_incorrect'] : 0;
             $total = $num_correct + $num_incorrect;
             $percentage = $total ? round(100 * $num_correct / $total) : 0;
             $cats[$cat_id]['percentage'] = $percentage;
         }
         // finally add cats to exam
         $my_exams[$cnt]->cats = $cats;
     }
     // group exams by question category
     $skills = array();
     // skills equal question categories
     $num_proficient = 0;
     foreach ($q_cats as $q_cat) {
         // skill filter (question category) selected in the drop-down?
         if (@$_POST['q_cat'] > -1 and $q_cat->ID != @$_POST['q_cat']) {
             continue;
         }
         // now construct array of this category along with the exams in it
         // then add in $skills. $skills is the final array that we'll use in the view
         $exams = array();
         foreach ($my_exams as $exam) {
             $has_questions = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . WATUPRO_QUESTIONS . " \n\t\t\t\t \tWHERE exam_id=%d AND cat_id=%d AND is_inactive=0 AND is_survey=0", $exam->ID, $q_cat->ID));
             if (!$has_questions) {
                 continue;
             }
             $exams[] = $exam;
         }
         $skills[] = array("category" => $q_cat, "exams" => $exams, "id" => $q_cat->ID);
         if (sizeof($exams)) {
             $num_proficient++;
         }
         // proficient in X skills
     }
     // by default $skills is ordered by category (name). Do we have to reorder?
     // NOT SURE THIS MAKES SENSE, SO FOR NOW NYI
     if (!empty($_POST['sort_skills']) and $_POST['sort_skills'] == 'proficiency') {
         // Sort by sum of proficiency of latest taking of the exams in this category
         // let's create an array that'll contain only cat ID and cumulative proficiency
         // for easier sorting
         $cat_ids = array();
         foreach ($skills as $skill) {
             // NYI
         }
     }
     if (@file_exists(get_stylesheet_directory() . '/watupro/reports/skills.php')) {
         require get_stylesheet_directory() . '/watupro/reports/skills.php';
     } else {
         require WATUPRO_PATH . "/modules/reports/views/skills.php";
     }
 }
Esempio n. 5
0
 static function show_list($cat_id = 'ALL', $orderby = "tE.ID", $show_status = false)
 {
     global $wpdb, $user_ID;
     $cat_id_sql = $cat_id == 'ALL' ? "" : $cat_id;
     list($exams) = WTPExam::my_exams($user_ID, $cat_id_sql, $orderby);
     $eids = array(0);
     foreach ($exams as $exam) {
         $eids[] = $exam->ID;
     }
     // if show_status we need to take the latest taking of this user for each exam and figure out the status
     if ($show_status and !empty($user_ID)) {
         $takings = $wpdb->get_results($wpdb->prepare("SELECT ID, exam_id, in_progress FROM " . WATUPRO_TAKEN_EXAMS . "\n\t\t \t \tWHERE user_id=%d AND exam_id IN (" . implode(',', $eids) . ") AND ID IN (\n\t\t \t \t\tSELECT MAX(ID) FROM " . WATUPRO_TAKEN_EXAMS . " WHERE user_id=%d GROUP BY exam_id\n\t\t \t \t)\n\t\t\t\tORDER BY ID DESC", $user_ID, $user_ID));
     }
     $content = "";
     foreach ($exams as $exam) {
         $content .= "<p><a href=" . get_permalink($exam->post->ID) . " target='_blank'>" . stripslashes($exam->name) . "</a>";
         if ($show_status and !empty($user_ID) and sizeof($takings)) {
             $status = __('Not started', 'watupro');
             foreach ($takings as $taking) {
                 if ($taking->exam_id == $exam->ID) {
                     $status = $taking->in_progress ? __('In progress', 'watupro') : __('Completed', 'watupro');
                 }
             }
             $content .= "<br><i>" . $status . "</i>";
         }
         $content .= "</p>";
     }
     return $content;
 }
Esempio n. 6
0
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";
    }
}