public function process() { global $wpdb; if (!isset($_GET['id'])) { // do some redirection here. // TODO add redirect function in code. } if (isset($_GET['marked']) && $_GET['marked'] == "true") { $this->_pageVars['message'] = "Result successfully marked!"; } if (isset($_GET['deleted']) && $_GET['deleted'] == "true") { $this->_pageVars['message'] = "Result successfully deleted!"; } $unviewed = $wpdb->get_results($wpdb->prepare("SELECT * \n\t\t\t\t\t\t FROM `" . WPSQT_TABLE_RESULTS . "` \n\t\t\t\t\t\t WHERE item_id = %d \n\t\t\t\t\t\t AND LCASE(status) = 'unviewed'\n\t\t\t\t\t\t ORDER BY ID DESC", array($_GET['id'])), ARRAY_A); $accepted = $wpdb->get_results($wpdb->prepare("SELECT * \n\t\t\t\t\t\t FROM `" . WPSQT_TABLE_RESULTS . "` \n\t\t\t\t\t\t WHERE item_id = %d \n\t\t\t\t\t\t AND LCASE(status) = 'accepted'\n\t\t\t\t\t\t ORDER BY ID DESC", array($_GET['id'])), ARRAY_A); $rejected = $wpdb->get_results($wpdb->prepare("SELECT * \n\t\t\t\t\t\t FROM `" . WPSQT_TABLE_RESULTS . "` \n\t\t\t\t\t\t WHERE item_id = %d \n\t\t\t\t\t\t AND LCASE(status) = 'rejected'\n\t\t\t\t\t\t ORDER BY ID DESC", array($_GET['id'])), ARRAY_A); if (!isset($_GET['status']) || !isset(${$_GET['status']})) { $rawResults = array_merge($unviewed, $accepted, $rejected); } else { $rawResults = ${$_GET['status']}; } $itemsPerPage = get_option('wpsqt_number_of_items'); $currentPage = Wpsqt_Core::getCurrentPageNumber(); $startNumber = ($currentPage - 1) * $itemsPerPage; $this->_pageVars['results'] = array_slice($rawResults, $startNumber, $itemsPerPage); $this->_pageVars['counts'] = array('unviewed_count' => sizeof($unviewed), 'accepted_count' => sizeof($accepted), 'rejected_count' => sizeof($rejected)); $this->_pageVars['numberOfPages'] = Wpsqt_Core::getPaginationCount(sizeof($rawResults), $itemsPerPage); $this->_pageVars['currentPage'] = Wpsqt_Core::getCurrentPageNumber(); return false; }
/** * (non-PHPdoc) * @see Wpsqt_Page::process() */ public function process() { global $wpdb; if (isset($_GET['order'])) { $this->_updateQuestionOrder($_GET['order'], $_GET['id']); } $questions = Wpsqt_System::getQuizQuestionTypes(); // Builds the query for the question counts. $sql = "SELECT count(id) as `all_count`,"; $questionCounts = array(); $questionTypes = array('all'); $itemId = $wpdb->prepare("%d", array($_GET['id'])); foreach ($questions as $questionType => $description) { // Part of the query which fetches the query count for the singl $sqlFriendlyType = str_replace(' ', '', $questionType); $questionCounts[] = " (SELECT count(id) FROM " . WPSQT_TABLE_QUESTIONS . " WHERE item_id = " . $itemId . " and type = '" . $questionType . "') as `" . $sqlFriendlyType . "_count` "; $questionTypes[] = $questionType; } // Finishes off the query for the question counts. $sql .= implode(',', $questionCounts); $sql .= "FROM " . WPSQT_TABLE_QUESTIONS . " WHERE item_id = " . $itemId; $itemsPerPage = get_option('wpsqt_number_of_items'); $questions = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSQT_TABLE_QUESTIONS . "` WHERE item_id = %d ORDER BY `order` ASC", array($_GET['id'])), ARRAY_A); $questions = apply_filters("wpsqt_list_questions", $questions); $currentPage = Wpsqt_Core::getCurrentPageNumber(); $startNumber = ($currentPage - 1) * $itemsPerPage; $pageQuestions = array_slice($questions, $startNumber, $itemsPerPage); $this->_pageVars['questions'] = $pageQuestions; $this->_pageVars['currentPage'] = $currentPage; $this->_pageVars['numberOfPages'] = Wpsqt_Core::getPaginationCount(sizeof($questions), $itemsPerPage); $this->_pageVars['question_counts'] = $wpdb->get_row($sql, ARRAY_A); $this->_pageVars['question_types'] = $questionTypes; $this->_pageView = "admin/questions/index.php"; }
/** * Adds the hooks for the admin dashboard actions * @since 2.0 */ public function __construct() { parent::__construct(); add_action('plugins_loaded', array($this, 'wpsqt_init_menus')); add_action('wpsqt_page_files', array($this, "enqueue_files_admin")); add_action('admin_init', array($this, "adminFilter")); add_action('admin_head-media-upload.php', array($this, 'print_scripts_media_up'), 11); add_action('admin_notices', array($this, 'admin_notices')); }
/** * Adds the hooks for the admin dashboard actions * @since 2.0 */ public function __construct() { parent::__construct(); add_action('plugins_loaded', array($this, 'wpsqt_init_menus')); // Scripts cannot be enqueued when the wpsqt_page_files hook is run on // pre 3.2.2, so fallback to standard enqueuing procedure global $wp_version; if (version_compare($wp_version, '3.2.1', '>')) { add_action('wpsqt_page_files', array($this, "enqueue_files_admin")); } else { add_action('admin_init', array($this, "enqueue_files_admin")); } add_action('admin_init', array($this, "adminFilter")); add_action('admin_head-media-upload.php', array($this, 'print_scripts_media_up'), 11); add_action('admin_notices', array($this, 'admin_notices')); add_action('admin_init', array($this, 'download_csv')); }
/** * (non-PHPdoc) * @see Wpsqt_Page::process() */ public function process() { $itemsPerPage = get_option("wpsqt_number_of_items"); $quizResults = Wpsqt_System::getAllItemDetails('quiz'); $surveyResults = Wpsqt_System::getAllItemDetails('survey'); $pollResults = Wpsqt_System::getAllItemDetails('poll'); $type = isset($_GET['type']) ? $_GET['type'] : ''; $currentPage = isset($_GET['pageno']) ? $_GET['pageno'] : 1; $startNumber = ($currentPage - 1) * $itemsPerPage; $quizNo = sizeof($quizResults); $surveyNo = sizeof($surveyResults); $pollNo = sizeof($pollResults); $totalNo = $quizNo + $surveyNo + $pollNo; switch ($type) { case 'quiz': $results = $quizResults; break; case 'survey': $results = $surveyResults; break; case 'poll': $results = $pollResults; break; default: $results = array_merge($quizResults, $surveyResults, $pollResults); break; } $results = array_slice($results, $startNumber, $itemsPerPage); foreach ($results as &$result) { //$result = } $numberOfPages = Wpsqt_Core::getPaginationCount($totalNo, $itemsPerPage); $this->_pageVars = array('results' => $results, 'numberOfPages' => $numberOfPages, 'startNumber' => $startNumber, 'currentPage' => $currentPage, 'quizNo' => $quizNo, 'surveyNo' => $surveyNo, 'pollNo' => $pollNo, 'totalNo' => $totalNo, 'type' => $type); if (empty($results) && $type == 'all') { $this->_pageView = 'admin/main/empty.php'; } else { $this->_pageView = 'admin/main/list.php'; } }
/** * Builds the form and returns the content in * HTML. * * @return string $content The html for the form. * @since 2.0 */ public final function getForm() { $options = $this->_options; ob_start(); include Wpsqt_Core::pageView('admin/misc/form.php'); $content = ob_get_clean(); return $content; }
} else { if (isset($_SESSION['wpsqt'][$quizName]['details']['finish_message']) && !empty($_SESSION['wpsqt'][$quizName]['details']['finish_message'])) { // PARSE TOKENS $string = $objTokens->doReplacement($_SESSION['wpsqt'][$quizName]['details']['finish_message']); echo nl2br($string); } else { _e('Thank you for your time.', 'wp-survey-and-quiz-tool'); } } } ?> <?php } if ($_SESSION['wpsqt'][$quizName]['details']['finish_display'] == 'Quiz Review' || $_SESSION['wpsqt'][$quizName]['details']['finish_display'] == 'Both') { require_once Wpsqt_Core::pageView('site/quiz/review.php'); } if ($_SESSION['wpsqt'][$quizName]['details']['use_pdf'] == "yes") { ?> <a href="<?php echo plugins_url('pdf.php?quizid=' . $_SESSION['wpsqt'][$quizName]['details']['id'] . '&id=' . $_SESSION['wpsqt']['result_id'], WPSQT_FILE); ?> "><?php _e('Download certification', 'wp-survey-and-quiz-tool'); ?> </a> <?php } ?>
?> &type=poll" <?php if ($type == "poll") { ?> class="current"<?php } ?> id="survey_link">Polls <span class="count">(<?php echo $pollNo; ?> )</span></a> </li> </ul> <div class="tablenav-pages"> <?php echo Wpsqt_Core::getPaginationLinks($currentPage, $numberOfPages); ?> </div> </div> <table class="widefat post fixed" cellspacing="0"> <thead> <tr> <th class="manage-column" scope="col" width="40">ID</th> <th class="manage-column column-title" scope="col">Title</th> <th scope="col" width="75">Status</th> <th scope="col" width="75">Results</th> </tr> </thead> <tfoot> <tr>
/** * Handles the end of the quiz/survey. * * @since 2.0 */ public function finishQuiz() { global $wpdb; $quizName = $_SESSION['wpsqt']['current_id']; if (isset($_SESSION['wpsqt'][$quizName]['details']['timer']) && $_SESSION['wpsqt'][$quizName]['details']['timer'] != '0' && $_SESSION['wpsqt'][$quizName]['details']['timer'] != "") { ?> <script type="text/javascript"> jQuery(document).ready( function(){ jQuery(".timer").hide(); }); </script> <?php $time_allowed = $_SESSION['wpsqt'][$quizName]['details']['timer'] * 60; $start_time = $_SESSION['wpsqt'][$quizName]['start_time']; // Allow an extra 5 seconds per section for loading $loading_allowance = count($_SESSION['wpsqt'][$quizName]['sections']) * 5; if ($start_time + $time_allowed + $loading_allowance < time()) { _e('You have taken longer than the allowed time.', 'wp-survey-and-quiz-tool'); return; } } if (isset($_SESSION['wpsqt'][$quizName]['details']['use_wp']) && $_SESSION['wpsqt'][$quizName]['details']['use_wp'] == 'yes') { $objUser = wp_get_current_user(); if ($objUser->data != NULL) { $_SESSION['wpsqt'][$quizName]['person']['name'] = $objUser->user_login; $_SESSION['wpsqt'][$quizName]['person']['fname'] = $objUser->first_name; $_SESSION['wpsqt'][$quizName]['person']['lname'] = $objUser->last_name; $_SESSION['wpsqt'][$quizName]['person']['email'] = $objUser->user_email; } else { $_SESSION['wpsqt'][$quizName]['person']['name'] = 'Anonymous'; } } $personName = isset($_SESSION['wpsqt'][$quizName]['person']['name']) ? $_SESSION['wpsqt'][$quizName]['person']['name'] : 'Anonymous'; $timeTaken = microtime(true) - $_SESSION['wpsqt'][$quizName]['start_time']; $totalPoints = 0; $correctAnswers = 0; $canAutoMark = true; if ($_SESSION['wpsqt'][$quizName]['details']['type'] == 'quiz') { $passMark = (int) $_SESSION['wpsqt'][$quizName]['details']['pass_mark']; // Set $AutoMarkWhenFreetext if (isset($_SESSION['wpsqt'][$quizName]['details']['automark_whenfreetxt'])) { $AutoMarkWhenFreetxt = $_SESSION['wpsqt'][$quizName]['details']['automark_whenfreetxt']; } else { $AutoMarkWhenFreetxt = "no"; } } else { $AutoMarkWhenFreetxt = false; } foreach ($_SESSION['wpsqt'][$quizName]['sections'] as $quizSection) { if ($this->_type != "quiz" || isset($quizSection['can_automark']) && $quizSection['can_automark'] == false) { // Only if AutoMarkWhenFreetext is set to 'yes' will $canAutoMark be ignored if (preg_match("/yes/", $AutoMarkWhenFreetxt) !== 1) { $canAutoMark = false; break; } } foreach ($quizSection['questions'] as $key => $question) { // AutoMarkWhenFreetext: 'no' and 'include' will mark freetext questions as 'incorrect', // 'exclude will ignore the freetext questions' and not add them to the $totalPoints if (!(preg_match("/exclude/", $AutoMarkWhenFreetxt) == 1 && $question['type'] == "Free Text")) { $totalPoints += $question['points']; } } if (!isset($quizSection['stats'])) { continue; } if (isset($quizSection['stats']['correct'])) { $correctAnswers += $quizSection['stats']['correct']; } } if ($canAutoMark === true) { $_SESSION['wpsqt']['current_score'] = sprintf(__("%d correct out of %d", 'wp-survey-and-quiz-tool'), $correctAnswers, $totalPoints); $_SESSION['wpsqt']['correct_answers'] = $correctAnswers; $_SESSION['wpsqt']['total_points'] = $totalPoints; } else { $_SESSION['wpsqt']['current_score'] = __('Quiz can\'t be auto marked', 'wp-survey-and-quiz-tool'); } if ($correctAnswers !== 0) { $percentRight = $correctAnswers / $totalPoints * 100; } else { $percentRight = 0; } $status = 'unviewed'; $pass = '******'; if ($_SESSION['wpsqt'][$quizName]['details']['type'] == 'quiz') { // Check if pass if ($percentRight >= $passMark) { $pass = '******'; } if ($pass == '1') { $status = 'Accepted'; } else { $status = 'unviewed'; } } if (!isset($_SESSION['wpsqt'][$quizName]['details']['store_results']) || $_SESSION['wpsqt'][$quizName]['details']['store_results'] !== "no") { $wpdb->query($wpdb->prepare("INSERT INTO `" . WPSQT_TABLE_RESULTS . "` (datetaken,timetaken,person,sections,item_id,person_name,ipaddress,score,total,percentage,status,pass)\n\t\t\t\t\t\t\t\tVALUES (%s,%d,%s,%s,%d,%s,%s,%d,%d,%d,%s,%d)", array($_SESSION['wpsqt'][$quizName]['start_time'], $timeTaken, serialize($_SESSION['wpsqt'][$quizName]['person']), serialize($_SESSION['wpsqt'][$quizName]['sections']), $_SESSION['wpsqt'][$quizName]['details']['id'], $personName, $_SERVER['REMOTE_ADDR'], $correctAnswers, $totalPoints, $percentRight, $status, $pass))); $_SESSION['wpsqt']['result_id'] = $wpdb->insert_id; } else { $_SESSION['wpsqt']['result_id'] = null; } $emailAddress = get_option('wpsqt_contact_email'); if (isset($_SESSION['wpsqt'][$quizName]['details']['notificaton_type']) && $_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant') { $emailTrue = true; } elseif (isset($_SESSION['wpsqt'][$quizName]['details']['notificaton_type']) && $_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant-100' && $percentRight == 100) { $emailTrue = true; } elseif (isset($_SESSION['wpsqt'][$quizName]['details']['notificaton_type']) && $_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant-75' && $percentRight > 75) { $emailTrue = true; } elseif (isset($_SESSION['wpsqt'][$quizName]['details']['notificaton_type']) && $_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant-50' && $percentRight > 50) { $emailTrue = true; } elseif (isset($_SESSION['wpsqt'][$quizName]['details']['notificaton_type']) && isset($_SESSION['wpsqt'][$quizName]['details']['send_user']) && $_SESSION['wpsqt'][$quizName]['details']['send_user'] == 'yes') { $emailTrue = true; } if (isset($emailTrue)) { Wpsqt_Mail::sendMail(); } if ($this->_type == "survey" || $this->_type == "poll") { $this->_cacheSurveys(); } if (isset($_SESSION['wpsqt'][$quizName]['details']['limit_one_cookie']) && $_SESSION['wpsqt'][$quizName]['details']['limit_one_cookie'] == 'yes') { // Create the cookie ?> <script type="text/javascript"> var c_name = "wpsqt_<?php echo $quizName; ?> _taken"; var value = "yes" var exdays = 365; var exdate = new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; </script> <?php } require_once Wpsqt_Core::pageView('site/' . $this->_type . '/finished.php'); unset($_SESSION['wpsqt']['result_id']); }
/** * Returns the question object. * * @todo look into my possible over use of the factory pattern. * @param string $type * @since 2.0 */ public static function getObject($type) { return Wpsqt_Core::getObject("Wpsqt_Question_" . ucfirst(str_replace(" ", "", strtolower($type)))); }
/** * The factory method that returns the upgrade object with all * the queries and objects ready to roll. * * @param string $verison */ public static function getUpdate($version) { global $wpdb; $objUpgrade = new Wpsqt_Upgrade(); $oldQuizTable = $wpdb->get_blog_prefix() . 'wpsqt_quiz'; $oldQuizSectionTable = $wpdb->get_blog_prefix() . 'wpsqt_quiz_sections'; $oldFormsTable = $wpdb->get_blog_prefix() . 'wpsqt_forms'; $oldQuizQuestionTable = $wpdb->get_blog_prefix() . 'wpsqt_questions'; $oldQuizAnswersTable = $wpdb->get_blog_prefix() . 'wpsqt_answer'; $oldQuizResultsTable = $wpdb->get_blog_prefix() . 'wpsqt_results'; $oldSurveyTable = $wpdb->get_blog_prefix() . 'wpsqt_survey'; $oldSurveyQuestionsTable = $wpdb->get_blog_prefix() . 'wpsqt_questions'; $oldSurveyAnswersTable = $wpdb->get_blog_prefix() . 'wpsqt_questions_answers'; $oldSurveyResultsTable = $wpdb->get_blog_prefix() . 'wpsqt_survey_results'; $oldSurveySingleResultsTable = $wpdb->get_blog_prefix() . 'wpsqt_survey_single_results'; $oldSurveySectionsTable = $wpdb->get_blog_prefix() . 'wpsqt_survey_sections'; if (version_compare($version, "1.3") < 0) { $objUpgrade->addQuery("ALTER TABLE `" . $oldQuizTable . "` ADD `use_wp_user` VARCHAR( 3 ) NOT NULL DEFAULT 'no'"); $objUpgrade->addQuery("ALTER TABLE `" . $oldQuizSectionTable . "` ADD `orderby` VARCHAR( 255 ) NOT NULL DEFAULT 'random'"); $objUpgrade->addQuery("ALTER TABLE `" . $oldSurveySectionsTable . "` ADD `orderby` VARCHAR( 255 ) NOT NULL DEFAULT 'random'"); $objUpgrade->addQuery("ALTER TABLE `" . $oldQuizTable . "` DROP `type` "); // 1.3 $objUpgrade->addQuery("ALTER TABLE `" . $oldSurveyTable . "` ADD `send_email` VARCHAR( 3 ) NOT NULL DEFAULT 'no'"); $objUpgrade->addQuery("ALTER TABLE `" . $oldQuizTable . "` ADD `email_template` TEXT NULL DEFAULT NULL"); $objUpgrade->addQuery("ALTER TABLE `" . $oldSurveyTable . "` ADD `email_template` TEXT NULL DEFAULT NULL"); } if (version_compare($version, "1.3.1") < 0) { // 1.3.1 $objUpgrade->addQuery("ALTER TABLE `" . $oldSurveyQuestionsTable . "` ADD `include_other` VARCHAR( 3 ) NOT NULL DEFAULT 'no'"); } if (version_compare($version, "1.3.2") < 0) { // 1.3.2 $objUpgrade->addQuery("ALTER TABLE `" . $oldQuizTable . "` ADD `display_review` VARCHAR( 3 ) NOT NULL DEFAULT 'no'"); } if (version_compare($version, "1.3.16") < 0) { // 1.3.16 $objUpgrade->addQuery("CREATE TABLE IF NOT EXISTS `" . $oldSurveySingleResultsTable . "` (\n\t\t\t\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t\t `surveyid` int(11) NOT NULL,\n\t\t\t\t\t\t `person` text NOT NULL,\n\t\t\t\t\t\t `name` varchar(255) NOT NULL,\n\t\t\t\t\t\t `results` text NOT NULL,\n\t\t\t\t\t\t `ipaddress` varchar(255) NOT NULL,\n\t\t\t\t\t\t `user_agent` varchar(255) NOT NULL,\n\t\t\t\t\t\t PRIMARY KEY (`id`)\n\t\t\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=latin1;"); } if (version_compare($version, "1.3.21") < 0) { // 1.3.21 foreach (array($oldQuizTable, $oldQuizSectionTable, $oldQuizQuestionTable, $oldQuizAnswersTable, $oldFormsTable, $oldQuizResultsTable, $oldSurveyTable, $oldSurveySectionsTable, $oldSurveyQuestionsTable, $oldSurveyAnswersTable, $oldSurveyResultsTable, $oldSurveySingleResultsTable) as $tableName) { $wpdb->query("ALTER TABLE `" . $tableName . "` CHARACTER SET utf8 COLLATE utf8_general_ci"); } $objUpgrade->addQuery("ALTER TABLE `" . $oldQuizQuestionTable . "` \n\t\t\t\t\t\t CHANGE `hint` `hint` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `difficulty` `difficulty` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `type` `type` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `text` `text` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `section_type` `section_type` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'multiple'"); $objUpgrade->addQuery("ALTER TABLE `" . $oldQuizAnswersTable . "` \n\t\t\t\t\t\t CHANGE `text` `text` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `correct` `correct` VARCHAR( 3 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"); $objUpgrade->addQuery("ALTER TABLE `" . $oldFormsTable . "` \n\t\t\t\t\t\t CHANGE `name` `name` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `type` `type` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `required` `required` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"); $objUpgrade->addQuery("ALTER TABLE `" . $oldQuizTable . "` CHANGE `name` `name` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `display_result` `display_result` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'no',\n\t\t\t\t\t\t CHANGE `status` `status` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'disabled',\n\t\t\t\t\t\t CHANGE `notification_type` `notification_type` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'none',\n\t\t\t\t\t\t CHANGE `take_details` `take_details` VARCHAR( 3 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'no',\n\t\t\t\t\t\t CHANGE `use_wp_user` `use_wp_user` VARCHAR( 3 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'no',\n\t\t\t\t\t\t CHANGE `email_template` `email_template` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,\n\t\t\t\t\t\t CHANGE `display_review` `display_review` VARCHAR( 3 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'no'"); $objUpgrade->addQuery("ALTER TABLE `" . $oldQuizSectionTable . "` \n\t\t\t\t\t\t CHANGE `name` `name` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `type` `type` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `difficulty` `difficulty` VARCHAR( 11 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `orderby` `orderby` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'random'"); $objUpgrade->addQuery("ALTER TABLE `" . $oldQuizResultsTable . "` \n\t\t\t\t\t\t CHANGE `person` `person` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,\n\t\t\t\t\t\t CHANGE `sections` `sections` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `status` `status` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'Unviewed',\n\t\t\t\t\t\t CHANGE `person_name` `person_name` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `ipaddress` `ipaddress` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"); $objUpgrade->addQuery("ALTER TABLE `" . $oldSurveyTable . "` \n\t\t\t\t\t\t CHANGE `name` `name` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `take_details` `take_details` VARCHAR( 11 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `status` `status` VARCHAR( 11 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `send_email` `send_email` VARCHAR( 3 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'no',\n\t\t\t\t\t\t CHANGE `email_template` `email_template` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL"); $objUpgrade->addQuery("ALTER TABLE `" . $oldSurveyQuestionsTable . "` CHANGE `text` `text` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `type` `type` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `include_other` `include_other` VARCHAR( 3 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'no'"); $objUpgrade->addQuery("ALTER TABLE `" . $oldSurveyAnswersTable . "` \n\t\t\t\t\t\t CHANGE `text` `text` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"); $objUpgrade->addQuery("ALTER TABLE `" . $oldSurveyResultsTable . "` \n\t\t\t\t\t\t CHANGE `other` `other` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `type` `type` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT 'multiple'"); $objUpgrade->addQuery("ALTER TABLE `" . $oldSurveySectionsTable . "` \n\t\t\t\t\t\t\t\t CHANGE `name` `name` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t\t\t CHANGE `type` `type` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t\t\t CHANGE `orderby` `orderby` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"); $objUpgrade->addQuery("ALTER TABLE `" . $oldSurveySingleResultsTable . "` \n\t\t\t\t\t\t CHANGE `person` `person` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `name` `name` VARCHAR( 255 ) CHARACTER SET ucs2 COLLATE ucs2_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `results` `results` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `ipaddress` `ipaddress` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,\n\t\t\t\t\t\t CHANGE `user_agent` `user_agent` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"); } if (version_compare($version, "1.3.22") < 0) { // 1.3.22 $wpdb->query("ALTER TABLE `" . $oldQuizResultsTable . "` CHANGE `sections` `sections` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"); } if (version_compare($version, "1.3.23") < 0) { // 1.3.23 $wpdb->query("ALTER TABLE `" . $oldQuizTable . "` ADD `email_wp_user` VARCHAR( 3 ) NOT NULL DEFAULT 'no'"); } if (version_compare($version, "1.3.24") < 0) { $wpdb->query("ALTER TABLE `" . $oldQuizTable . "` CHANGE `additional` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"); } if (version_compare($version, "1.3.27") < 0) { $wpdb->query("ALTER TABLE `" . $oldQuizTable . "` ADD `limit_one` VARCHAR( 255 ) NULL DEFAULT NULL"); } if (version_compare($version, '2.0.0') < 0) { $objUpdate = Wpsqt_Core::getObject('Wpsqt_Upgrade_1322'); $objUpgrade->addObject($objUpdate, 'Upgraded to 2.0'); } if (version_compare($version, '2.0.0.3') < 0) { $objUpgrade->addQuery("ALTER TABLE `" . WPSQT_TABLE_RESULTS . "` ADD `score` INT NULL , ADD `total` INT NULL , ADD `percentage` INT NULL", "Added scores columns to results"); } apply_filters('wpsqt_upgrade_object', $objUpgrade, $version); return $objUpgrade; }
/** * Handles displaying the page view. Firstly it * extracts the contents of $this->_pageVariables * and then does a require_once on the return value * of Wpsqt_Core::pageView() using the content of * $this->_pageView. * * @since 2.0 */ public final function display() { extract($this->_pageVars); require_once Wpsqt_Core::pageView($this->_pageView); return; }
/** * Checks the custom pages functionality is working when * when there are no custom directories about to use. */ public function testCustomPagesFunctionalityWithoutAnyCustomPages() { $expectedFileName = WPSQT_DIR . 'pages/site/quiz/section.php'; $actualFileName = Wpsqt_Core::pageView('site/quiz/section.php'); $this->assertEquals($expectedFileName, $actualFileName, "Filename doesn't match what was expected."); }
/** * Handles the end of the quiz/survey. * * @since 2.0 */ public function finishQuiz() { global $wpdb; $quizName = $_SESSION['wpsqt']['current_id']; if (isset($_SESSION['wpsqt'][$quizName]['details']['timer']) && $_SESSION['wpsqt'][$quizName]['details']['timer'] != '0' && $_SESSION['wpsqt'][$quizName]['details']['timer'] != "") { ?> <script type="text/javascript"> jQuery(document).ready( function(){ jQuery(".timer").hide(); }); </script> <?php } if (isset($_SESSION['wpsqt'][$quizName]['details']['use_wp']) && $_SESSION['wpsqt'][$quizName]['details']['use_wp'] == 'yes') { $objUser = wp_get_current_user(); $_SESSION['wpsqt'][$quizName]['person']['name'] = $objUser->user_login; $_SESSION['wpsqt'][$quizName]['person']['fname'] = $objUser->first_name; $_SESSION['wpsqt'][$quizName]['person']['lname'] = $objUser->last_name; $_SESSION['wpsqt'][$quizName]['person']['email'] = $objUser->user_email; } $personName = isset($_SESSION['wpsqt'][$quizName]['person']['name']) ? $_SESSION['wpsqt'][$quizName]['person']['name'] : 'Anonymous'; $timeTaken = microtime(true) - $_SESSION['wpsqt'][$quizName]['start_time']; $totalPoints = 0; $correctAnswers = 0; $canAutoMark = true; if ($_SESSION['wpsqt'][$quizName]['details']['type'] == 'quiz') { $passMark = (int) $_SESSION['wpsqt'][$quizName]['details']['pass_mark']; } foreach ($_SESSION['wpsqt'][$quizName]['sections'] as $quizSection) { if ($this->_type != "quiz" || isset($quizSection['can_automark']) && $quizSection['can_automark'] == false) { $canAutoMark = false; break; } foreach ($quizSection['questions'] as $key => $question) { $totalPoints += $question['points']; } if (!isset($quizSection['stats'])) { continue; } if (isset($quizSection['stats']['correct'])) { $correctAnswers += $quizSection['stats']['correct']; } } if ($canAutoMark === true) { $_SESSION['wpsqt']['current_score'] = $correctAnswers . " correct out of " . $totalPoints; } else { $_SESSION['wpsqt']['current_score'] = "quiz can't be auto marked"; } if ($correctAnswers !== 0) { $percentRight = $correctAnswers / $totalPoints * 100; } else { $percentRight = 0; } $status = 'unviewed'; $pass = '******'; if ($_SESSION['wpsqt'][$quizName]['details']['type'] == 'quiz') { // Check if pass if ($percentRight >= $passMark) { $pass = '******'; } if ($pass == '1') { $status = 'Accepted'; } else { $status = 'unviewed'; } } if (!isset($_SESSION['wpsqt'][$quizName]['details']['store_results']) || $_SESSION['wpsqt'][$quizName]['details']['store_results'] !== "no") { $wpdb->query($wpdb->prepare("INSERT INTO `" . WPSQT_TABLE_RESULTS . "` (datetaken,timetaken,person,sections,item_id,person_name,ipaddress,score,total,percentage,status,pass)\n\t\t\t\t\t\t\t\tVALUES (%s,%d,%s,%s,%d,%s,%s,%d,%d,%d,%s,%d)", array($_SESSION['wpsqt'][$quizName]['start_time'], $timeTaken, serialize($_SESSION['wpsqt'][$quizName]['person']), serialize($_SESSION['wpsqt'][$quizName]['sections']), $_SESSION['wpsqt'][$quizName]['details']['id'], $personName, $_SERVER['REMOTE_ADDR'], $correctAnswers, $totalPoints, $percentRight, $status, $pass))); $_SESSION['wpsqt']['result_id'] = $wpdb->insert_id; } else { $_SESSION['wpsqt']['result_id'] = null; } $emailAddress = get_option('wpsqt_contact_email'); if (isset($_SESSION['wpsqt'][$quizName]['details']['notificaton_type']) && $_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant') { $emailTrue = true; } elseif (isset($_SESSION['wpsqt'][$quizName]['details']['notificaton_type']) && $_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant-100' && $percentRight == 100) { $emailTrue = true; } elseif (isset($_SESSION['wpsqt'][$quizName]['details']['notificaton_type']) && $_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant-75' && $percentRight > 75) { $emailTrue = true; } elseif (isset($_SESSION['wpsqt'][$quizName]['details']['notificaton_type']) && $_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant-50' && $percentRight > 50) { $emailTrue = true; } elseif (isset($_SESSION['wpsqt'][$quizName]['details']['notificaton_type']) && isset($_SESSION['wpsqt'][$quizName]['details']['send_user']) && $_SESSION['wpsqt'][$quizName]['details']['send_user'] == 'yes') { $emailTrue = true; } if (isset($emailTrue)) { Wpsqt_Mail::sendMail(); } if ($this->_type == "survey" || $this->_type == "poll") { $this->_cacheSurveys(); } if (isset($_SESSION['wpsqt'][$quizName]['details']['limit_one_cookie']) && $_SESSION['wpsqt'][$quizName]['details']['limit_one_cookie'] == 'yes') { // Create the cookie ?> <script type="text/javascript"> var c_name = "wpsqt_<?php echo $quizName; ?> _taken"; var value = "yes" var exdays = 365; var exdate = new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; </script> <?php } require_once Wpsqt_Core::pageView('site/' . $this->_type . '/finished.php'); unset($_SESSION['wpsqt']['result_id']); }