/** * 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); }
/** * Tests the quiz select quiz functionality is working * as expected. Ensures the 'wpsqt_fetch_quiz_details' * filter is called along the way. * * @since 2.0 */ public function testQuizSelect() { $this->dummyQuizId = Wpsqt_System::insertItemDetails($this->dummyQuizDetails, 'quiz'); $this->filterCalled = false; $retrivedQuizDetails = Wpsqt_System::getItemDetails($this->dummyQuizId, 'quiz'); $expected = $this->dummyQuizDetails; $expected['id'] = $this->dummyQuizId; $diff = array_diff($expected, $retrivedQuizDetails); $this->assertTrue(empty($diff), "Quizzes don't match"); $this->assertTrue($this->filterCalled, "Filter 'wpsqt_fetch_quiz_details' wasn't called it seems."); }
/** * Starts the shortcode off firstly checks to see * if there is a wpsqt key item in the session * array. Then checks to see if there is a step * number provided if not it's zero. If the step * is zero we then build up the quiz data, fetching * the quiz first, then fetching the sections. * * @param integer $identifier * @since 2.0 */ public function __construct($identifier, $type) { global $wpdb; if (!isset($_SESSION['wpsqt'])) { $_SESSION['wpsqt'] = array(); } if (empty($identifier)) { $this->_errors['name'] = "The name is missing for " . $type; } $this->_acceptableTypes = apply_filters("wpsqt_shortcode_types", $this->_acceptableTypes); $this->_acceptableTypes = array_map("strtolower", $this->_acceptableTypes); if (!in_array($type, $this->_acceptableTypes)) { $this->_errors['type'] = "Invalid type given"; } $_SESSION['wpsqt']['current_type'] = $type; $this->_type = $type; $this->_step = isset($_POST['step']) && ctype_digit($_POST['step']) ? intval($_POST['step']) : 0; $_SESSION['wpsqt']['current_id'] = $identifier; if ($this->_step == 0) { $_SESSION['wpsqt'][$identifier]['start_time'] = microtime(true); $_SESSION['wpsqt'][$identifier]['person'] = array(); $_SESSION['wpsqt'][$identifier]['details'] = Wpsqt_System::getItemDetails($identifier, $type); $_SESSION['wpsqt']['item_id'] = $_SESSION['wpsqt'][$identifier]['details']['id']; if (!empty($_SESSION['wpsqt'][$identifier]['details'])) { $_SESSION['wpsqt'][$identifier]['sections'] = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSQT_TABLE_SECTIONS . "` WHERE item_id = %d ORDER BY `id` ASC", array($_SESSION['wpsqt'][$identifier]['details']['id'])), ARRAY_A); } else { $noquiz = true; } } if (empty($_SESSION['wpsqt'][$identifier]['details'])) { if (!isset($noquiz)) { $this->_errors['session'] = true; } else { $this->_errors['noexist'] = true; } } if (isset($_COOKIE['wpsqt_' . $_SESSION['wpsqt']['item_id'] . '_state'])) { $uid = $_COOKIE['wpsqt_' . $_SESSION['wpsqt']['item_id'] . '_state']; if (!empty($uid)) { $state = $wpdb->get_row("SELECT * FROM " . WPSQT_TABLE_QUIZ_STATE . " WHERE uid = '{$uid}'", ARRAY_A); $answers = unserialize($state['answers']); $_SESSION['wpsqt'] = $answers; $_POST = unserialize($state['post']); ?> <script type="text/javascript"> function setCookie(c_name,value,exdays) { 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; } setCookie('wpsqt_<?php echo $_SESSION['wpsqt'][$identifier]['details']['id']; ?> _state', '', '-10'); </script> <?php $this->_key = $state['current_section']; $this->_step = $state['current_section']; $this->_restore = true; } } }
/** * Starts the shortcode off firstly checks to see * if there is a wpsqt key item in the session * array. Then checks to see if there is a step * number provided if not it's zero. If the step * is zero we then build up the quiz data, fetching * the quiz first, then fetching the sections. * * @param integer $identifier * @since 2.0 */ public function __construct($identifier, $type) { global $wpdb; if (!isset($_SESSION['wpsqt'])) { $_SESSION['wpsqt'] = array(); } if (empty($identifier)) { $this->_errors['name'] = "The name is missing for " . $type; } $this->_acceptableTypes = apply_filters("wpsqt_shortcode_types", $this->_acceptableTypes); $this->_acceptableTypes = array_map("strtolower", $this->_acceptableTypes); if (!in_array($type, $this->_acceptableTypes)) { $this->_errors['type'] = "Invalid type given"; } $_SESSION['wpsqt']['current_type'] = $type; $this->_type = $type; $this->_step = isset($_POST['step']) && ctype_digit($_POST['step']) ? intval($_POST['step']) : 0; if ($this->_step == 0) { $_SESSION['wpsqt'][$identifier]['start_time'] = microtime(true); $_SESSION['wpsqt'][$identifier]['person'] = array(); $_SESSION['wpsqt'][$identifier]['details'] = Wpsqt_System::getItemDetails($identifier, $type); $_SESSION['wpsqt']['current_id'] = $identifier; $_SESSION['wpsqt']['item_id'] = $_SESSION['wpsqt'][$identifier]['details']['id']; if (!empty($_SESSION['wpsqt'][$identifier]['details'])) { $_SESSION['wpsqt'][$identifier]['sections'] = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSQT_TABLE_SECTIONS . "` WHERE item_id = %d ORDER BY `id` ASC", array($_SESSION['wpsqt'][$identifier]['details']['id'])), ARRAY_A); } else { $noquiz = true; } } if (empty($_SESSION['wpsqt'][$identifier]['details'])) { if (!isset($noquiz)) { $this->_errors['session'] = true; } else { $this->_errors['noexist'] = true; } } }