public function init() { if (isset($_POST['deleteall'])) { Wpsqt_System::deleteAllResults($_GET['id']); } $this->_pageView = 'admin/poll/result.php'; }
public function process() { global $wpdb; if ($_SERVER['REQUEST_METHOD'] == "POST") { for ($row = 0; $row < intval($_POST['row_count']); $row++) { if (empty($_POST['formitemid'][$row])) { Wpsqt_System::insertFormItem($_GET['id'], $_POST['field_name'][$row], $_POST['type'][$row], $_POST['required'][$row], $_POST['validation'][$row]); continue; } if (isset($_POST['delete'][$row]) && $_POST['delete'][$row] == "yes") { Wpsqt_System::deleteFormItem($_POST['formitemid'][$row]); } else { Wpsqt_System::updateFormItem($_POST['formitemid'][$row], $_POST['field_name'][$row], $_POST['type'][$row], $_POST['required'][$row], $_POST['validation'][$row]); } } $this->_pageVars['updated'] = "Form has successfully been updated"; } $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSQT_TABLE_FORMS . "` WHERE item_id = %s", array($_GET['id'])), ARRAY_A); if (empty($fields)) { $fields[] = array("id" => false, "name" => false, "required" => false, "validation" => false, 'type' => false); } $this->_pageView = 'admin/shared/form.php'; $this->_pageVars['fields'] = $fields; $this->_pageVars['validators'] = Wpsqt_System::fetchValidators(); }
/** * Handles the sections for * both quizzes and surveys. * * @since 2.0 */ public function _doSections() { if ($_SERVER['REQUEST_METHOD'] == "POST") { $nameNeeded = array(); for ($row = 0; $row < intval($_POST['row_count']); $row++) { if (!isset($_POST['section_name'][$row]) || $_POST['section_name'][$row] == "") { $nameNeeded[] = $row; continue; } $sectionName = wp_kses_stripslashes($_POST['section_name'][$row]); if (!isset($_POST['number'][$row]) || $_POST['number'][$row] == "") { $_POST['number'][$row] = 0; } if (!isset($_POST['sectionid'][$row]) || empty($_POST['sectionid'][$row])) { $difficulty = isset($_POST['difficulty'][$row]) ? $_POST['difficulty'][$row] : false; Wpsqt_System::insertSection($_GET['id'], $sectionName, $_POST['number'][$row], $_POST['order'][$row], $difficulty); continue; } if (isset($_POST['delete'][$row]) && !empty($_POST['delete'][$row])) { Wpsqt_System::deleteSection($_POST['sectionid'][$row]); } else { $difficulty = isset($_POST['difficulty'][$row]) ? $_POST['difficulty'][$row] : false; Wpsqt_System::updateSection($_POST['sectionid'][$row], $sectionName, $_POST['number'][$row], $_POST['order'][$row], $difficulty); } } $this->_pageVars['successMessage'] = "Sections updated"; } $validData = Wpsqt_System::fetchSections($_GET['id']); if (!empty($validData)) { $this->_pageVars['validData'] = $validData; } }
/** * (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"; }
public function init() { global $wpdb; $rawQuestion = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSQT_TABLE_QUESTIONS . "` WHERE id = %d", array($_GET['questionid'])), ARRAY_A); $prepdQuestion = array(); foreach (Wpsqt_System::unserializeQuestion($rawQuestion, $_GET['subsection']) as $key => $value) { $prepdQuestion["wpsqt_" . $key] = $value; } $this->_action = "edit"; $this->_question = $prepdQuestion; }
/** * Handles doing quiz and survey insertions into * the database. Starts of creating the form object * using either Wpsqt_Form_Quiz or Wpsqt_Form_Survey * then it moves on to check and see if * * * @since 2.0 */ protected function _doInsert() { $className = "Wpsqt_Form_" . ucfirst($this->_subsection); $objForm = new $className(); $this->_pageVars = array('objForm' => $objForm, 'objTokens' => Wpsqt_Tokens::getTokenObject()); if ($_SERVER['REQUEST_METHOD'] == "POST") { $errorMessages = $objForm->getMessages($_POST); $details = $_POST; unset($details['wpsqt_nonce']); if (empty($errorMessages)) { $details = Wpsqt_Form::getSavableArray($details); $this->_pageVars['id'] = Wpsqt_System::insertItemDetails($details, strtolower($this->_subsection)); do_action('wpsqt_' . strtolower($this->_subsection) . '_addnew'); $this->_pageView = "admin/misc/redirect.php"; $this->_pageVars['redirectLocation'] = WPSQT_URL_MAIN . "§ion=sections&subsection=" . strtolower($this->_subsection) . "&id=" . $this->_pageVars['id'] . "&new=1"; } else { $objForm->setValues($details); $this->_pageVars['errorArray'] = $errorMessages; } } }
/** * (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'; } }
/** * Handles the doing updating of quiz and surveys. * Firstly it gets the quiz or survey details using * either getQuizDetails or getSurveyDetails. Then * creates the page form using either Wpsqt_Form_Quiz * or Wpsqt_Form_Survey. Then it checks to see if it's * a post request if so it then checks to see if it * assigns $_POST as the details for the quiz or survey. * At which point it does a validation call to see if * there are any error messages if not it does an update * call using either Wpsqt_System::updateQuizDetails or * Wpsqt_System::updateSurveyDetails. * * Uses $this->_subsection to find out if it's to use * Quiz or Survey functions. * * @since 2.0 */ protected function _doUpdate() { $this->_pageView = "admin/quiz/create.php"; $details = Wpsqt_Form::getInsertableArray(Wpsqt_System::getItemDetails($_GET['id'], strtolower($this->_subsection))); $className = "Wpsqt_Form_" . ucfirst($this->_subsection); $objForm = new $className(); $this->_pageVars = array('objForm' => $objForm, 'objTokens' => Wpsqt_Tokens::getTokenObject()); if ($_SERVER['REQUEST_METHOD'] == "POST" && !isset($_POST['new-page'])) { $errorMessages = $objForm->getMessages($_POST); $details = $_POST; $details['wpsqt_id'] = $_GET['id']; unset($details['wpsqt_nonce']); if (empty($errorMessages)) { Wpsqt_System::updateItemDetails(Wpsqt_Form::getSavableArray($details), $_GET['subsection']); do_action('wpsqt_' . strtolower($this->_subsection) . '_edit'); $this->_pageVars['successMessage'] = ucfirst($this->_subsection) . " updated!"; } else { $this->_pageVars['errorArray'] = $errorMessages; } } $objForm->setValues($details); }
public function process() { global $wpdb; if (isset($_POST['deleteall'])) { Wpsqt_System::deleteAllResults($_GET['id']); } $result = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSQT_TABLE_SURVEY_CACHE . "` WHERE item_id = %d", array($_GET['id'])), ARRAY_A); $this->_pageVars['sections'] = unserialize($result['sections']); if (!empty($this->_pageVars['sections'])) { foreach ($this->_pageVars['sections'] as $section) { foreach ($section['questions'] as $questionKey => $question) { if ($question['type'] == 'Free Text') { $uncachedResult = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSQT_TABLE_RESULTS . "` WHERE item_id = %d", array($_GET['id'])), ARRAY_A); $this->_pageVars['uncachedresults'] = $uncachedResult; // Storing all the IDs for free text questions $this->_pageVars['freetextq'][] = $questionKey; } } } } $this->_pageView = "admin/surveys/result.total.php"; }
public function execute() { global $wpdb; $wpdb->query("CREATE TABLE IF NOT EXISTS `" . WPSQT_TABLE_QUESTIONS . "` (\n\t\t\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t `name` varchar(255) NOT NULL,\n\t\t\t\t\t `type` varchar(255) NOT NULL,\n\t\t\t\t\t `item_id` int(11) NOT NULL,\n\t\t\t\t\t `section_id` int(11) NOT NULL,\n\t\t\t\t\t `difficulty` varchar(255) NOT NULL,\n\t\t\t\t\t `meta` longtext NOT NULL,\n\t\t\t\t\t `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t\t\t\t PRIMARY KEY (`id`)\n\t\t\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n\t\t"); $wpdb->query("CREATE TABLE IF NOT EXISTS `" . WPSQT_TABLE_RESULTS . "`(\n\t\t\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t `item_id` int(11) NOT NULL,\n\t\t\t\t\t `timetaken` int(11) NOT NULL,\n\t\t\t\t\t `person` longtext NOT NULL,\n\t\t\t\t\t `sections` longtext NOT NULL,\n\t\t\t\t\t `person_name` varchar(255) NOT NULL,\n\t\t\t\t\t `ipaddress` varchar(255) NOT NULL,\n\t\t\t\t\t `timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,\n\t\t\t\t\t `status` varchar(255) NOT NULL DEFAULT 'unviewed',\n\t\t\t\t\t PRIMARY KEY (`id`)\n\t\t\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n\t\t"); $wpdb->query("CREATE TABLE IF NOT EXISTS `" . WPSQT_TABLE_FORMS . "` (\n\t\t\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t `item_id` int(11) NOT NULL,\n\t\t\t\t\t `name` varchar(255) NOT NULL,\n\t\t\t\t\t `type` varchar(255) NOT NULL,\n\t\t\t\t\t `required` varchar(255) NOT NULL,\n\t\t\t\t\t `validation` varchar(355) NOT NULL,\n\t\t\t\t\t `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t\t\t\t PRIMARY KEY (`id`)\n\t\t\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n\t\t\t"); $wpdb->query("CREATE TABLE IF NOT EXISTS `" . WPSQT_TABLE_QUIZ_SURVEYS . "` (\n\t\t\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t `name` varchar(255) NOT NULL,\n\t\t\t\t\t `settings` longtext NOT NULL,\n\t\t\t\t\t `type` varchar(266) NOT NULL,\n\t\t\t\t\t `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t\t\t\t PRIMARY KEY (`id`)\n\t\t\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;"); $wpdb->query("CREATE TABLE IF NOT EXISTS `" . WPSQT_TABLE_SECTIONS . "` (\n\t\t\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t `item_id` int(11) NOT NULL,\n\t\t\t\t\t `name` varchar(255) NOT NULL,\n\t\t\t\t\t `limit` varchar(255) NOT NULL,\n\t\t\t\t\t `order` varchar(11) NOT NULL,\n\t\t\t\t\t `difficulty` varchar(255) NOT NULL,\n\t\t\t\t\t `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t\t\t\t UNIQUE KEY `id` (`id`)\n\t\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n\t\t"); $wpdb->query("CREATE TABLE IF NOT EXISTS `" . WPSQT_TABLE_SURVEY_CACHE . "` (\n\t\t\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t `sections` longtext NOT NULL,\n\t\t\t\t\t `total` int(11) NOT NULL,\n\t\t\t\t\t `item_id` int(11) NOT NULL,\n\t\t\t\t\t `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t\t\t\t PRIMARY KEY (`id`)\n\t\t\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n\t\t"); $quizzes = $wpdb->get_results("SELECT * FROM `" . $wpdb->get_blog_prefix() . "wpsqt_quiz`", ARRAY_A); foreach ($quizzes as $quiz) { $sectionIds = array(); $quiz['display'] = $quiz['display_result']; $quiz['finish_message'] = ''; $quizId = Wpsqt_System::insertItemDetails($quiz, 'quiz'); $questions = $wpdb->get_results("SELECT * FROM `" . $wpdb->get_blog_prefix() . "wpsqt_questions` WHERE quizid = " . $quiz['id'], ARRAY_A); $sections = $wpdb->get_results("SELECT * FROM `" . $wpdb->get_blog_prefix() . "wpsqt_quiz_sections` WHERE quizid = " . $quiz['id'], ARRAY_A); $results = $wpdb->get_results("SELECT * FROM `" . $wpdb->get_blog_prefix() . "wpsqt_results` WHERE quizid = " . $quiz['id'], ARRAY_A); $forms = $wpdb->get_results("SELECT * FROM `" . $wpdb->get_blog_prefix() . "wpsqt_forms` WHERE quizid = " . $quiz['id'], ARRAY_A); if (!empty($forms)) { foreach ($forms as $form) { Wpsqt_System::insertFormItem($quizId, $form['name'], $form['type'], $form['required'], 'none'); } } foreach ($sections as $section) { // So we can relate the old sectionId with the new one. $sectionIds[$section['id']] = Wpsqt_System::insertSection($quizId, $section['name'], $section['number'], $section['orderby'], $section['difficulty']); } foreach ($questions as $question) { $question['name'] = $question['text']; $question['section'] = $question['sectionid']; unset($question['text']); unset($question['sectionid']); $sectionId = $sectionIds[$question['section']]; $answers = $wpdb->get_results("SELECT * FROM `" . $wpdb->get_blog_prefix() . "wpsqt_answer` WHERE questionid = " . $question['id'], ARRAY_A); if (!empty($answers)) { $question['answers'] = $answers; } list($questionText, $questionType, $questionDifficulty, $questionSection, $questionMeta) = Wpsqt_System::serializeQuestion($question, 'quiz'); $wpdb->query($wpdb->prepare("INSERT INTO `" . WPSQT_TABLE_QUESTIONS . "` \n\t\t\t\t\t\t\t\t\t(name,type,item_id,section_id,difficulty,meta) \n\t\t\t\t\t\t\t\t\tVALUES (%s,%s,%d,%d,%s,%s)", array($questionText, $questionType, $quizId, $sectionId, $questionDifficulty, $questionMeta))); } foreach ($results as $result) { $sections = unserialize($result['sections']); foreach ($sections as &$section) { foreach ($section['questions'] as $key => &$value) { $value['name'] = $value['text']; unset($value['text']); } } $result['sections'] = serialize($sections); $wpdb->query($wpdb->prepare("INSERT INTO `" . WPSQT_TABLE_RESULTS . "` (timetaken,person,sections,item_id,person_name,ipaddress,status) \n\t\t\t\t\t\t\t\t\tVALUES (%d,%s,%s,%d,%s,%s,%s)", array($result['timetaken'], $result['person'], $result['sections'], $quizId, $result['person_name'], $result['ipaddress'], $result['status']))); } } $surveys = $wpdb->get_results("SELECT * FROM `" . $wpdb->get_blog_prefix() . "wpsqt_survey`", ARRAY_A); foreach ($surveys as $survey) { $sectionIds = array(); $surveyId = Wpsqt_System::insertItemDetails($survey, 'survey'); $questions = $wpdb->get_results("SELECT * FROM `" . $wpdb->get_blog_prefix() . "wpsqt_survey_questions` WHERE surveyid = " . $survey['id'], ARRAY_A); $sections = $wpdb->get_results("SELECT * FROM `" . $wpdb->get_blog_prefix() . "wpsqt_survey_sections` WHERE surveyid = " . $survey['id'], ARRAY_A); $results = $wpdb->get_results("SELECT * FROM `" . $wpdb->get_blog_prefix() . "wpsqt_survey_single_results` WHERE surveyid = " . $survey['id'], ARRAY_A); $forms = $wpdb->get_results("SELECT * FROM `" . $wpdb->get_blog_prefix() . "wpsqt_forms` WHERE surveyid = " . $survey['id'], ARRAY_A); if (!empty($forms)) { foreach ($forms as $form) { Wpsqt_System::insertFormItem($surveyId, $form['name'], $form['type'], $form['required'], 'none'); } } foreach ($sections as $section) { // So we can relate the old sectionId with the new one. $sectionIds[$section['id']] = Wpsqt_System::insertSection($surveyId, $section['name'], $section['number'], $section['orderby'], false); } foreach ($questions as $question) { $question['name'] = $question['text']; $question['section'] = $question['sectionid']; unset($question['text']); unset($question['sectionid']); $sectionId = $sectionIds[$question['section']]; $answers = $wpdb->get_results("SELECT * FROM `" . $wpdb->get_blog_prefix() . "wpsqt_survey_questions_answers` WHERE questionid = " . $question['id'], ARRAY_A); if (!empty($answers)) { $question['answers'] = $answers; } $question['difficulty'] = false; list($questionText, $questionType, $questionDifficulty, $questionSection, $questionMeta) = Wpsqt_System::serializeQuestion($question, 'survey'); $wpdb->query($wpdb->prepare("INSERT INTO `" . WPSQT_TABLE_QUESTIONS . "` \n\t\t\t\t\t\t\t\t\t(name,type,item_id,section_id,difficulty,meta) \n\t\t\t\t\t\t\t\t\tVALUES (%s,%s,%d,%d,%s,%s)", array($questionText, ucfirst($questionType), $surveyId, $sectionId, $questionDifficulty, $questionMeta))); } $cachedSections = array(); foreach ($results as $result) { $sections = unserialize($result['results']); foreach ($sections as $sectionKey => &$section) { $section['answers'] = array(); foreach ($section['questions'] as $key => &$value) { $questionId = $value['id']; $value['name'] = $value['text']; $section['answers'][$questionId]['given'] = array($value['answer']); $value['type'] = ucfirst($value['type']); if ($value['type'] == 'Multiple') { $value['type'] = 'Multiple Choice'; } unset($value['text']); } if (!array_key_exists($sectionKey, $cachedSections)) { $cachedSections[$sectionKey] = array(); $cachedSections[$sectionKey]['questions'] = array(); } foreach ($section['questions'] as $questionKey => $question) { $questionId = $question['id']; if (!array_key_exists($question['id'], $cachedSections[$sectionKey]['questions'])) { $cachedSections[$sectionKey]['questions'][$questionId] = array(); $cachedSections[$sectionKey]['questions'][$questionId]['name'] = $question['name']; $cachedSections[$sectionKey]['questions'][$questionId]['type'] = $question['type']; $cachedSections[$sectionKey]['questions'][$questionId]['answers'] = array(); } if ($cachedSections[$sectionKey]['questions'][$questionId]['type'] == "Multiple Choice" || $cachedSections[$sectionKey]['questions'][$questionId]['type'] == "Dropdown") { if (empty($cachedSections[$sectionKey]['questions'][$questionId]['answers'])) { foreach ($question['answers'] as $answerKey => $answers) { $answerId = $answers['id']; $cachedSections[$sectionKey]['questions'][$questionId]['answers'][$answerId] = array("text" => $answers['text'], "count" => 0); } } } elseif ($cachedSections[$sectionKey]['questions'][$questionId]['type'] == "Likert" || $cachedSections[$sectionKey]['questions'][$questionId]['type'] == "Scale") { if (empty($cachedSections[$sectionKey]['questions'][$questionId]['answers'])) { for ($i = 0; $i < 10; ++$i) { $cachedSections[$sectionKey]['questions'][$questionId]['answers'][$i] = array('count' => 0); } } } elseif ($cachedSections[$sectionKey]['questions'][$questionId]['type'] == "Free Text") { if (empty($cachedSections[$sectionKey]['questions'][$questionId]['answers'])) { $cachedSections[$sectionKey]['questions'][$questionId]['answers'] = 'None Cached - Free Text Result'; } continue; } else { if (empty($cachedSections[$sectionKey]['questions'][$questionId]['answers'])) { $cachedSections[$sectionKey]['questions'][$questionId]['answers'] = 'None Cached - Not a default question type.'; } continue; } $givenAnswer = (int) current($section['answers'][$questionId]['given']); $cachedSections[$sectionKey]['questions'][$questionId]['answers'][$givenAnswer]["count"]++; } } $result['results'] = serialize($sections); $wpdb->query($wpdb->prepare("INSERT INTO `" . WPSQT_TABLE_RESULTS . "` (timetaken,person,sections,item_id,person_name,ipaddress,status) \n\t\t\t\t\t\t\t\t\tVALUES (%d,%s,%s,%d,%s,%s,%s)", array(0, $result['person'], $result['results'], $surveyId, $result['name'], $result['ipaddress'], 'unviewed'))); } $wpdb->query($wpdb->prepare("INSERT INTO `" . WPSQT_TABLE_SURVEY_CACHE . "` (sections,item_id) VALUES (%s,%d)", array(serialize($cachedSections), $surveyId))); } }
/** * Handles showing the section. * * @since 2.0 */ public function showSection() { global $wpdb; $quizName = $_SESSION["wpsqt"]["current_id"]; $sectionKey = $this->_key; if (isset($_POST['wpsqt-save-state']) && isset($_SESSION['wpsqt'][$quizName]['details']['save_resume']) && $_SESSION['wpsqt'][$quizName]['details']['save_resume'] == 'yes') { Wpsqt_Core::saveCurrentState($sectionKey); _e('Saved the current state. You can resume by revisiting the quiz.', 'wp-survey-and-quiz-tool'); $sectionKey--; $show = false; } else { $show = true; } $section = $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]; $orderBy = $section["order"] == "random" ? "RAND()" : "`order` " . strtoupper($section["order"]); $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]["questions"] = array(); if (!empty($_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]['limit'])) { $end = " LIMIT 0," . $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]['limit']; } else { $end = ''; } $rawQuestions = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSQT_TABLE_QUESTIONS . "` WHERE section_id = %d ORDER BY " . $orderBy . $end, array($section["id"])), ARRAY_A); foreach ($rawQuestions as $rawQuestion) { $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]["questions"][] = Wpsqt_System::unserializeQuestion($rawQuestion, $this->_type); } if ($show) { require Wpsqt_Core::pageView('site/' . $this->_type . '/section.php'); } }
</tr> </tfoot> <tbody class="wpsqt_questions_content"> <?php if (empty($questions)) { ?> <tr> <td colspan="5"><div style="text-align: center;">No questions yet!</div></td> </tr> <?php } else { $count = 0; foreach ($questions as $rawQuestion) { $count++; $question = Wpsqt_System::unserializeQuestion($rawQuestion, $_GET['subsection']); ?> <tr class="<?php echo $count % 2 ? 'wpsqt-odd' : 'wpsqt-even'; ?> " id="<?php echo $question['id']; ?> "> <td><?php echo $question['id']; ?> </td> <td><?php echo stripslashes($question['name']); ?>
/** * Tests the serialization of the Questions array first * serializes and then it unserilizes and then checks * to see if they are the same. * * @since 2.0 */ public function testQuestionsSerializationBothways() { $question = array("text" => "Test Question", "section" => "Section One", "points" => "3", "difficulty" => "easy", "add_text" => "Fix this.", "type" => "question"); $serializedQuestion = array(); list($serializedQuestion['text'], $serializedQuestion['type'], $serializedQuestion['difficulty'], $serializedQuestion['section'], $serializedQuestion['meta']) = Wpsqt_System::serializeQuestion($question, $_GET['subsection'], 'quiz'); $unserializedQuestion = Wpsqt_System::unserializeQuestion($serializedQuestion, 'quiz'); $this->assertEquals($question, $unserializedQuestion, "Arrays don't match up."); }
/** * (non-PHPdoc) * @see Wpsqt_Page::process() */ public function process() { global $wpdb; if ($this->_type == "survey") { $questionTypes = Wpsqt_System::getSurveyQuestionTypes(); } else { if ($this->_type == "poll") { $questionTypes = Wpsqt_System::getPollQuestionTypes(); } else { $questionTypes = Wpsqt_System::getQuizQuestionTypes(); } } $rawSections = Wpsqt_System::fetchSections($_GET['id']); $sections = array(); foreach ($rawSections as $section) { if ($section['name'] !== false) { $sections[] = $section['name']; if (isset($this->_question['wpsqt_section_id']) && $section['id'] == $this->_question['wpsqt_section_id']) { $this->_question['wpsqt_section'] = $section['name']; } } } $this->_pageVars['objForm'] = new Wpsqt_Form_Question($questionTypes, $sections); $this->_pageVars['objForm']->setValues($this->_question); $this->_pageVars['sections'] = $sections; $this->_pageVars['subForm'] = ""; $questionObjects = array(); foreach ($questionTypes as $type => $description) { $objQuestion = Wpsqt_Question::getObject($type); $questionObjects[$type] = $objQuestion; $this->_pageVars['subForm'] .= $objQuestion->processValues($this->_question)->form(); } if ($this->_type == "poll") { $this->_pageView = "admin/questions/pollform.php"; } else { $this->_pageView = "admin/questions/form.php"; } if ($_SERVER['REQUEST_METHOD'] == "POST") { $this->_pageVars['errorArray'] = $this->_pageVars['objForm']->getMessages($_POST); $question = array(); foreach ($questionObjects as $type => $objQuestion) { if ($type != $_POST['wpsqt_type']) { continue; } $result = $objQuestion->processForm($_POST); if (!is_array($result)) { continue; } $question[$result['name']] = $result['content']; $this->_pageVars['errorArray'] = array_merge($this->_pageVars['errorArray'], $result['errors']); } if (!empty($this->_pageVars['errorArray'])) { return; } foreach ($_POST as $key => $value) { $question[str_ireplace("wpsqt_", "", $key)] = $value; } list($questionText, $questionType, $questionDifficulty, $questionSection, $questionMeta) = Wpsqt_System::serializeQuestion($question, $_GET['subsection']); foreach ($rawSections as $section) { if ($section['name'] == $_POST['wpsqt_section']) { $sectionId = $section['id']; break; } } if ($this->_action == "add") { $wpdb->query($wpdb->prepare("INSERT INTO `" . WPSQT_TABLE_QUESTIONS . "` \n\t\t\t\t\t\t\t\t\t(name,type,item_id,section_id,difficulty,meta) \n\t\t\t\t\t\t\t\t\tVALUES (%s,%s,%d,%d,%s,%s)", array($questionText, $questionType, $_GET['id'], $sectionId, $questionDifficulty, $questionMeta))); $this->_pageVars['redirectLocation'] = WPSQT_URL_MAIN . "§ion=questions&subsection=" . strtolower($_GET['subsection']) . "&id=" . $_GET['id'] . "&new=true"; } else { $wpdb->query($wpdb->prepare("UPDATE `" . WPSQT_TABLE_QUESTIONS . "` SET\n\t\t\t\t\t\t\t\t\tname = %s, type = %s,section_id = %d,\n\t\t\t\t\t\t\t\t\tdifficulty = %s,meta = %s WHERE id = %d", array($questionText, $questionType, $sectionId, $questionDifficulty, $questionMeta, $_GET['questionid']))); $this->_pageVars['redirectLocation'] = WPSQT_URL_MAIN . "§ion=questions&subsection=" . strtolower($_GET['subsection']) . "&id=" . $_GET['id'] . "&edit=true"; } $this->_pageView = "admin/misc/redirect.php"; } }
/** * Handles showing the section. * * @since 2.0 */ public function showSection() { global $wpdb; $quizName = $_SESSION["wpsqt"]["current_id"]; $sectionKey = $this->_key; $section = $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]; $orderBy = $section["order"] == "random" ? "RAND()" : "`order` " . strtoupper($section["order"]); $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]["questions"] = array(); if (!empty($_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]['limit'])) { $end = " LIMIT 0," . $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]['limit']; } else { $end = ''; } $rawQuestions = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSQT_TABLE_QUESTIONS . "` WHERE section_id = %d ORDER BY " . $orderBy . $end, array($section["id"])), ARRAY_A); foreach ($rawQuestions as $rawQuestion) { $_SESSION["wpsqt"][$quizName]["sections"][$sectionKey]["questions"][] = Wpsqt_System::unserializeQuestion($rawQuestion, $this->_type); } require Wpsqt_Core::pageView('site/' . $this->_type . '/section.php'); }