current_user_serial = $_SESSION[self::USER_SERIAL] ?? 0; $this->current_user_id = $_SESSION[self::USER_ID] ?? ""; $this->current_user_name = $_SESSION[self::USER_NAME] ?? ""; $this->current_user_email = $_SESSION[self::USER_EMAIL] ?? ""; $this->pagination_page = $_SESSION[self::PAGINATION_PAGE] ?? 1; } // =========== // View Voters // =========== public function viewVoters() { $voters = $this->getVoterHistoryPage(); $popovers = (new Popovers())->getPopovers(); $XML = $this->mergeXML($voters, ""); $XML = $this->mergeXML($popovers, $XML); echo $XML; die(); $content = $this->applyXSL($XML, $this->getXSL("viewVoters")); $this->displayContent($content); } // ============================ // Return a Voters Page Object // ============================ public function getVotersPage() { // Find Criteria $find_voter = filter_input(INPUT_POST, "find_voter") ?: ""; $find_voter = $this->sanitizeString($find_voter); $find_words = implode("|", explode(" ", $find_voter)); // Record Count $connection = $this->connect(); $SQL = "select count(*) as count from view_voterhistory"; // where voter_name_first regexp :voter_name_first"; $statement = $connection->prepare($SQL); $statement->bindValue(":voter_name_first", $find_words); $statement->execute(); $recordset = $statement->fetch(PDO::FETCH_ASSOC); $count = (count($recordset) > 0) ? (integer) $recordset["count"] : (integer) 0; // Pagination $pagination = filter_input(INPUT_POST, "pagination") ?: ""; switch ($pagination) { case "first" : $this->pagination_page = 1; break; case "previous" : $this->pagination_page = max(($this->pagination_page - 1), 1); break; case "next" : $this->pagination_page = ($this->pagination_page + 1); break; case "last" : $this->pagination_page = ($count / $this->pagination_size); break; } $offset = (($this->pagination_page * $this->pagination_size) - $this->pagination_size); $start = ($offset + 1); $end = min($count, (($start + $this->pagination_size) - 1)); // Data $SQL = "select view_voters.* from view_voters -- where voter_name_first regexp :voter_name_first order by voter_name_first limit {$this->pagination_size} offset {$offset}"; $statement = $connection->prepare($SQL); $statement->bindValue(":voter_name_first", $find_words); $statement->execute(); $voters = $this->getTableXML("voters", $statement); // Insert Pagination Attributes $voters->addAttribute("count", $count); $voters->addAttribute("start", $start); $voters->addAttribute("end", $end); $voters->addAttribute("page", $this->pagination_page); $_SESSION[self::PAGINATION_PAGE] = $this->pagination_page; return $voters; } } ?>