Beispiel #1
0
 /**
  * (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";
 }
Beispiel #2
0
 /**
  * (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 . "&section=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 . "&section=questions&subsection=" . strtolower($_GET['subsection']) . "&id=" . $_GET['id'] . "&edit=true";
         }
         $this->_pageView = "admin/misc/redirect.php";
     }
 }