Exemplo n.º 1
0
}
$order_sql = $exam->randomize ? "ORDER BY RAND()" : "ORDER BY ID";
$questions = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . WATU_QUESTIONS . " \n\t\tWHERE exam_id=%d {$order_sql}", $exam_id));
$num_questions = sizeof($questions);
if ($questions) {
    if (!isset($GLOBALS['watu_client_includes_loaded']) and !isset($_REQUEST['do'])) {
        $GLOBALS['watu_client_includes_loaded'] = true;
        // Make sure that this code is not loaded more than once.
    }
    if (isset($_REQUEST['do']) and $_REQUEST['do']) {
        // Quiz Reuslts.
        $achieved = $max_points = $num_correct = 0;
        $result = '';
        $result .= "<p>" . __('All the questions in the exam along with their answers are shown below. Your answers are bolded. The correct answers have a green background while the incorrect ones have a red background.', 'watu') . "</p>";
        // we should reorder the questions in the same way they came from POST because exam might be randomized
        $_exam = new WatuExam();
        $questions = $_exam->reorder_questions($questions, $_POST['question_id']);
        foreach ($questions as $qct => $ques) {
            $result .= "<div class='show-question'>";
            $result .= "<div class='show-question-content'>" . wpautop(stripslashes($ques->question), false) . "</div>";
            $all_answers = $ques->answers;
            $correct = false;
            $class = $textarea_class = 'answer';
            $result .= "<ul>";
            $ansArr = is_array(@$_REQUEST["answer-" . $ques->ID]) ? $_POST["answer-" . $ques->ID] : array();
            foreach ($all_answers as $ans) {
                $class = 'answer';
                list($points, $correct, $class) = WatuQuestion::calculate($ques, $ans, $ansArr, $correct, $class);
                if (strstr($class, 'correct-answer')) {
                    $textarea_class = $class;
                }
Exemplo n.º 2
0
Arquivo: watu.php Projeto: leeci/watu
function watu_activate($update = false)
{
    global $wpdb;
    $wpdb->show_errors();
    $version = get_option('watu_version');
    if (!$update) {
        watu_init();
    }
    // Initial options.
    update_option('watu_show_answers', 1);
    update_option('watu_single_page', 0);
    update_option('watu_answer_type', 'radio');
    if ($wpdb->get_var("SHOW TABLES LIKE '" . WATU_EXAMS . "'") != WATU_EXAMS) {
        $sql = "CREATE TABLE `" . WATU_EXAMS . "`(\r\n\t\t\t\t\tID int(11) unsigned NOT NULL auto_increment,\r\n\t\t\t\t\tname varchar(50) NOT NULL DEFAULT '',\r\n\t\t\t\t\tdescription mediumtext NOT NULL,\r\n\t\t\t\t\tfinal_screen mediumtext NOT NULL,\r\n\t\t\t\t\tadded_on datetime NOT NULL DEFAULT '1900-01-01',\r\n\t\t\t\t\tPRIMARY KEY  (ID)\r\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 ";
        $wpdb->query($sql);
    }
    if ($wpdb->get_var("SHOW TABLES LIKE '" . WATU_QUESTIONS . "'") != WATU_QUESTIONS) {
        $sql = "CREATE TABLE " . WATU_QUESTIONS . " (\r\n\t\t\t\t\tID int(11) unsigned NOT NULL auto_increment,\r\n\t\t\t\t\texam_id int(11) unsigned NOT NULL DEFAULT 0,\r\n\t\t\t\t\tquestion mediumtext NOT NULL,\r\n\t\t\t\t\tanswer_type char(15)  NOT NULL DEFAULT '',\r\n\t\t\t\t\tsort_order int(3) NOT NULL default 0,\r\n\t\t\t\t\tPRIMARY KEY  (ID),\r\n\t\t\t\t\tKEY quiz_id (exam_id)\r\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8";
        $wpdb->query($sql);
    }
    if ($wpdb->get_var("SHOW TABLES LIKE '" . WATU_ANSWERS . "'") != WATU_ANSWERS) {
        $sql = "CREATE TABLE " . WATU_ANSWERS . " (\r\n\t\t\t\t\tID int(11) unsigned NOT NULL auto_increment,\r\n\t\t\t\t\tquestion_id int(11) unsigned NOT NULL,\r\n\t\t\t\t\tanswer TEXT,\r\n\t\t\t\t\tcorrect enum('0','1') NOT NULL default '0',\r\n\t\t\t\t\tpoint int(11) NOT NULL,\r\n\t\t\t\t\tsort_order int(3) NOT NULL default 0,\r\n\t\t\t\t\tPRIMARY KEY  (ID)\r\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8";
        $wpdb->query($sql);
    }
    if ($wpdb->get_var("SHOW TABLES LIKE '" . WATU_GRADES . "'") != WATU_GRADES) {
        $sql = "CREATE TABLE `" . WATU_GRADES . "` (\r\n\t\t\t\t `ID` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t `exam_id` int(11) NOT NULL DEFAULT 0,\r\n\t\t\t\t `gtitle` varchar (255) NOT NULL DEFAULT '',\r\n\t\t\t\t `gdescription` mediumtext NOT NULL,\r\n\t\t\t\t `gfrom` int(11) NOT NULL DEFAULT 0,\r\n\t\t\t\t `gto` int(11) NOT NULL DEFAULT 0,\r\n\t\t\t\t PRIMARY KEY (`ID`)\r\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8";
        $wpdb->query($sql);
    }
    if ($wpdb->get_var("SHOW TABLES LIKE '" . WATU_TAKINGS . "'") != WATU_TAKINGS) {
        $sql = "CREATE TABLE `" . WATU_TAKINGS . "` (\r\n\t\t\t\t `ID` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t `exam_id` int(11) NOT NULL DEFAULT 0,\r\n\t\t\t\t `user_id` int(11) NOT NULL DEFAULT 0,\r\n\t\t\t\t `ip` varchar(20) NOT NULL DEFAULT '',\r\n\t\t\t\t `date` DATE NOT NULL DEFAULT '1900-01-01',\r\n\t\t\t\t `points` INT NOT NULL DEFAULT 0,\r\n\t\t\t\t `grade_id` INT UNSIGNED NOT NULL DEFAULT 0,\r\n\t\t\t\t PRIMARY KEY (`ID`)\r\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8";
        $wpdb->query($sql);
    }
    watu_add_db_fields(array(array("name" => "randomize", "type" => "TINYINT NOT NULL DEFAULT 0"), array("name" => "single_page", "type" => "TINYINT NOT NULL DEFAULT 0"), array("name" => "show_answers", "type" => "TINYINT NOT NULL DEFAULT 100"), array("name" => "require_login", "type" => "TINYINT NOT NULL DEFAULT 0"), array("name" => "notify_admin", "type" => "TINYINT NOT NULL DEFAULT 0"), array("name" => "randomize_answers", "type" => "TINYINT NOT NULL DEFAULT 0")), WATU_EXAMS);
    // db updates in 1.8
    if (empty($version) or $version < 1.8) {
        // let all existing exams follow the default option
        $sql = "UPDATE " . WATU_EXAMS . " SET single_page = '" . get_option('watu_single_page') . "'";
        $wpdb->query($sql);
    }
    watu_add_db_fields(array(array("name" => "is_required", "type" => "TINYINT UNSIGNED NOT NULL DEFAULT 0")), WATU_QUESTIONS);
    watu_add_db_fields(array(array("name" => "result", "type" => "TEXT"), array("name" => "snapshot", "type" => "MEDIUMTEXT")), WATU_TAKINGS);
    // let's change choice and answer fields to TEXT instead of VARCHAR - 2.1.3
    if (empty($version) or $version < 2.1) {
        // let all existing exams follow the default option
        $sql = "ALTER TABLE " . WATU_ANSWERS . " CHANGE answer answer TEXT";
        $wpdb->query($sql);
    }
    $demo_quiz_created = get_option('watu_demo_quiz_created');
    if ($demo_quiz_created != '1') {
        WatuExam::create_demo();
    }
    update_option("watu_delete_db", '');
    update_option("watu_version", '2.4');
    update_option('watu_admin_notice', __('<h2>Thank you for activating Watu!</h2> <p>Please go to your <a href="tools.php?page=watu_exams">Quizzes page</a> to get started! If this is the first time you have activated the plugin there will be a small demo quiz automatically created for you. Feel free to explore it to get better idea how things work.</p>', 'watu'));
}