333 lines
11 KiB
PHP
333 lines
11 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
class CountyCodes extends Base {
|
||
|
|
|
||
|
|
// Variables.
|
||
|
|
|
||
|
|
private $current_user_serial = 0;
|
||
|
|
private $current_user_id = "";
|
||
|
|
private $current_user_name = "";
|
||
|
|
private $current_user_email = "";
|
||
|
|
private $pagination_size = 20;
|
||
|
|
private $pagination_page = 1;
|
||
|
|
|
||
|
|
// =================
|
||
|
|
// Class Constructor
|
||
|
|
// =================
|
||
|
|
|
||
|
|
public function __construct() {
|
||
|
|
|
||
|
|
set_error_handler(array($this, "displayError"));
|
||
|
|
|
||
|
|
date_default_timezone_set(self::TIMEZONE);
|
||
|
|
|
||
|
|
$this->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;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ==================
|
||
|
|
// Setup County Codes
|
||
|
|
// ==================
|
||
|
|
|
||
|
|
public function setupCountyCodes() {
|
||
|
|
|
||
|
|
$countycodes = $this->getCountyCodesPage();
|
||
|
|
$popovers = (new Popovers())->getPopovers();
|
||
|
|
|
||
|
|
$XML = $this->mergeXML($countycodes, "<XML/>");
|
||
|
|
$XML = $this->mergeXML($popovers, $XML);
|
||
|
|
|
||
|
|
$content = $this->applyXSL($XML, $this->getXSL("setupCountyCodes"));
|
||
|
|
|
||
|
|
$this->displayContent($content);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ================
|
||
|
|
// Add County Code
|
||
|
|
// ================
|
||
|
|
|
||
|
|
public function addCountyCode() {
|
||
|
|
|
||
|
|
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||
|
|
|
||
|
|
switch ($step) {
|
||
|
|
|
||
|
|
case "prompt":
|
||
|
|
|
||
|
|
$constants = $this->getConstants();
|
||
|
|
|
||
|
|
$content = $this->applyXSL($constants, $this->getXSL("addCountyCode"));
|
||
|
|
|
||
|
|
$this->displayContent($content);
|
||
|
|
|
||
|
|
break;
|
||
|
|
|
||
|
|
case "add":
|
||
|
|
|
||
|
|
$countycode_code = filter_input(INPUT_POST, "countycode_code") ?: "";
|
||
|
|
$countycode_name = filter_input(INPUT_POST, "countycode_name") ?: "";
|
||
|
|
$countycode_state = filter_input(INPUT_POST, "countycode_state") ?: "";
|
||
|
|
|
||
|
|
$SQL = "insert into countycodes
|
||
|
|
|
||
|
|
( countycode_code,
|
||
|
|
countycode_name,
|
||
|
|
countycode_state,
|
||
|
|
countycode_active,
|
||
|
|
countycode_creator,
|
||
|
|
countycode_created )
|
||
|
|
|
||
|
|
VALUES ( :countycode_code,
|
||
|
|
:countycode_name,
|
||
|
|
:countycode_state,
|
||
|
|
:countycode_active,
|
||
|
|
:countycode_creator,
|
||
|
|
:countycode_created )";
|
||
|
|
|
||
|
|
$statement = $this->connect()->prepare($SQL);
|
||
|
|
|
||
|
|
$statement->bindValue(":countycode_code", strtoupper($countycode_code));
|
||
|
|
$statement->bindValue(":countycode_name", $countycode_name);
|
||
|
|
$statement->bindValue(":countycode_state", $countycode_state);
|
||
|
|
$statement->bindValue(":countycode_active", true, PDO::PARAM_BOOL);
|
||
|
|
$statement->bindValue(":countycode_creator", $this->current_user_name);
|
||
|
|
$statement->bindValue(":countycode_created", $this->getTimestamp());
|
||
|
|
|
||
|
|
$statement->execute();
|
||
|
|
|
||
|
|
break;
|
||
|
|
|
||
|
|
default:
|
||
|
|
|
||
|
|
$this->displayHome();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// ===================
|
||
|
|
// Edit a County Code
|
||
|
|
// ===================
|
||
|
|
|
||
|
|
public function editCountyCode() {
|
||
|
|
|
||
|
|
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||
|
|
|
||
|
|
switch ($step) {
|
||
|
|
|
||
|
|
case "prompt":
|
||
|
|
|
||
|
|
$countycode_serial = filter_input(INPUT_POST, "countycode_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||
|
|
|
||
|
|
$countycode = $this->getCountyCode($countycode_serial);
|
||
|
|
|
||
|
|
if ($countycode->count() == 0) {
|
||
|
|
$this->logError("Invalid County Code ({$countycode_serial}). " . __METHOD__);
|
||
|
|
}
|
||
|
|
|
||
|
|
$constants = $this->getConstants();
|
||
|
|
|
||
|
|
$XML = $this->mergeXML($countycode, "<XML/>");
|
||
|
|
$XML = $this->mergeXML($constants, $XML);
|
||
|
|
|
||
|
|
$content = $this->applyXSL($XML, $this->getXSL("editCountyCode"));
|
||
|
|
|
||
|
|
$this->displayContent($content);
|
||
|
|
|
||
|
|
break;
|
||
|
|
|
||
|
|
case "update":
|
||
|
|
|
||
|
|
$countycode_serial = filter_input(INPUT_POST, "countycode_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||
|
|
$countycode_code = filter_input(INPUT_POST, "countycode_code") ?: "";
|
||
|
|
$countycode_name = filter_input(INPUT_POST, "countycode_name") ?: "";
|
||
|
|
$countycode_state = filter_input(INPUT_POST, "countycode_state") ?: "";
|
||
|
|
$countycode_active = filter_input(INPUT_POST, "countycode_active", FILTER_VALIDATE_BOOLEAN) ?: false;
|
||
|
|
|
||
|
|
// Verify the CountyCodes
|
||
|
|
|
||
|
|
$countycode = $this->getCountyCode($countycode_serial);
|
||
|
|
|
||
|
|
if ($countycode->count() == 0) {
|
||
|
|
$this->logError("Invalid CountyCodes ({$countycode_serial}). " . __METHOD__);
|
||
|
|
}
|
||
|
|
|
||
|
|
$SQL = "update countycodes
|
||
|
|
set countycode_code = :countycode_code,
|
||
|
|
countycode_name = :countycode_name,
|
||
|
|
countycode_state = :countycode_state,
|
||
|
|
countycode_active = :countycode_active,
|
||
|
|
countycode_changer = :countycode_changer,
|
||
|
|
countycode_changed = :countycode_changed
|
||
|
|
where countycode_serial = :countycode_serial";
|
||
|
|
|
||
|
|
$statement = $this->connect()->prepare($SQL);
|
||
|
|
|
||
|
|
$statement->bindValue(":countycode_serial", $countycode_serial);
|
||
|
|
$statement->bindValue(":countycode_code", strtoupper($countycode_code));
|
||
|
|
$statement->bindValue(":countycode_state", $countycode_state);
|
||
|
|
$statement->bindValue(":countycode_name", $countycode_name);
|
||
|
|
$statement->bindValue(":countycode_active", $countycode_active, PDO::PARAM_BOOL);
|
||
|
|
$statement->bindValue(":countycode_changer", $this->current_user_name);
|
||
|
|
$statement->bindValue(":countycode_changed", $this->getTimestamp());
|
||
|
|
|
||
|
|
$statement->execute();
|
||
|
|
|
||
|
|
break;
|
||
|
|
|
||
|
|
default:
|
||
|
|
|
||
|
|
$this->displayHome();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// ===================
|
||
|
|
// Delete County Code
|
||
|
|
// ===================
|
||
|
|
|
||
|
|
public function deleteCountyCode() {
|
||
|
|
|
||
|
|
$countycode_serial = filter_input(INPUT_POST, "countycode_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||
|
|
|
||
|
|
$countycode = $this->getCountyCode($countycode_serial);
|
||
|
|
|
||
|
|
if ($countycode->count() == 0) {
|
||
|
|
$this->logError("Invalid County Code ({$countycode_serial}). " . __METHOD__);
|
||
|
|
}
|
||
|
|
|
||
|
|
$SQL = "delete from countycodes where countycode_serial = {$countycode_serial}";
|
||
|
|
|
||
|
|
$this->executeSQL($SQL);
|
||
|
|
}
|
||
|
|
|
||
|
|
// =====================================
|
||
|
|
// Return an Active County Codes Object
|
||
|
|
// =====================================
|
||
|
|
|
||
|
|
public function getActiveCountyCodes() {
|
||
|
|
|
||
|
|
$SQL = "select view_countycodes.*
|
||
|
|
from view_countycodes
|
||
|
|
where countycode_active is true";
|
||
|
|
|
||
|
|
return $this->getTable("countycodes", $SQL);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ==============================
|
||
|
|
// Return an County Codes Object
|
||
|
|
// ==============================
|
||
|
|
|
||
|
|
public function getCountyCode($countycode_serial = 0) {
|
||
|
|
|
||
|
|
$SQL = "select view_countycodes.*
|
||
|
|
from view_countycodes
|
||
|
|
where countycode_serial = {$countycode_serial}";
|
||
|
|
|
||
|
|
return $this->getTable("countycodes", $SQL);
|
||
|
|
}
|
||
|
|
|
||
|
|
// =============================
|
||
|
|
// Return a County Codes Object
|
||
|
|
// =============================
|
||
|
|
|
||
|
|
public function getCountyCodes() {
|
||
|
|
|
||
|
|
$SQL = "select view_countycodes.*
|
||
|
|
from view_countycodes";
|
||
|
|
|
||
|
|
return $this->getTable("countycodes", $SQL);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ==================================
|
||
|
|
// Return a County Codes Page Object
|
||
|
|
// ==================================
|
||
|
|
|
||
|
|
public function getCountyCodesPage() {
|
||
|
|
|
||
|
|
// Find Criteria
|
||
|
|
|
||
|
|
$find_countycode = filter_input(INPUT_POST, "find_countycode") ?: "";
|
||
|
|
$find_countycode = $this->sanitizeString($find_countycode);
|
||
|
|
|
||
|
|
$find_words = implode("|", explode(" ", $find_countycode));
|
||
|
|
|
||
|
|
// Record Count
|
||
|
|
|
||
|
|
$connection = $this->connect();
|
||
|
|
|
||
|
|
$SQL = "select count(*) as count
|
||
|
|
from view_countycodes
|
||
|
|
where countycode_code regexp :countycode_code
|
||
|
|
or countycode_name regexp :countycode_name
|
||
|
|
or countycode_state regexp :countycode_state";
|
||
|
|
|
||
|
|
$statement = $connection->prepare($SQL);
|
||
|
|
|
||
|
|
$statement->bindValue(":countycode_code", $find_words);
|
||
|
|
$statement->bindValue(":countycode_name", $find_words);
|
||
|
|
$statement->bindValue(":countycode_state", $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_countycodes.*
|
||
|
|
from view_countycodes
|
||
|
|
where countycode_code regexp :countycode_code
|
||
|
|
or countycode_name regexp :countycode_name
|
||
|
|
or countycode_state regexp :countycode_state
|
||
|
|
order by countycode_code
|
||
|
|
limit {$this->pagination_size}
|
||
|
|
offset {$offset}";
|
||
|
|
|
||
|
|
$statement = $connection->prepare($SQL);
|
||
|
|
|
||
|
|
$statement->bindValue(":countycode_code", $find_words);
|
||
|
|
$statement->bindValue(":countycode_name", $find_words);
|
||
|
|
$statement->bindValue(":countycode_state", $find_words);
|
||
|
|
|
||
|
|
$statement->execute();
|
||
|
|
|
||
|
|
$countycodes = $this->getTableXML("countycodes", $statement);
|
||
|
|
|
||
|
|
// Insert Pagination Attributes
|
||
|
|
|
||
|
|
$countycodes->addAttribute("count", $count);
|
||
|
|
$countycodes->addAttribute("start", $start);
|
||
|
|
$countycodes->addAttribute("end", $end);
|
||
|
|
$countycodes->addAttribute("page", $this->pagination_page);
|
||
|
|
|
||
|
|
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||
|
|
|
||
|
|
return $countycodes;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
?>
|