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"; }
/** * (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'; } }