Initial comming of full program to main branch
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
Base_Autoloader::Register();
|
||||
|
||||
// ================
|
||||
// Autoloader Class
|
||||
// ================
|
||||
|
||||
class Base_Autoloader {
|
||||
|
||||
public static function Register() {
|
||||
|
||||
if (function_exists("__autoload")) {
|
||||
spl_autoload_register("__autoload");
|
||||
}
|
||||
|
||||
return spl_autoload_register(array("Base_Autoloader", "Load"), true, true);
|
||||
|
||||
}
|
||||
|
||||
public static function Load($pClassName) {
|
||||
|
||||
if (class_exists($pClassName, false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Try for a "classes" Class first, then a "reports" Class.
|
||||
|
||||
$pClassFilePath = "classes/{$pClassName}.php";
|
||||
|
||||
if ((file_exists($pClassFilePath) === false) || (is_readable($pClassFilePath) === false)) {
|
||||
|
||||
$pClassFilePath = "reports/{$pClassName}.php";
|
||||
|
||||
if ((file_exists($pClassFilePath) === false) || (is_readable($pClassFilePath) === false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
require($pClassFilePath);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,788 @@
|
||||
<?php
|
||||
|
||||
// ==========
|
||||
// Base Class
|
||||
// ==========
|
||||
|
||||
require_once "vendor/autoload.php";
|
||||
require_once "classes/Autoloader.php";
|
||||
|
||||
class Base {
|
||||
|
||||
// =========
|
||||
// Constants
|
||||
// =========
|
||||
|
||||
const APPLICATION_NAME = "Georgia Housing Report";
|
||||
const APPLICATION_MNEMONIC = "GAHOUSINGREPORT";
|
||||
const VERSION = "2.00";
|
||||
const TIMEZONE = "America/New_York";
|
||||
// =================
|
||||
// Session Variables
|
||||
// =================
|
||||
|
||||
const ENVIRONMENT = "GAHOUSINGREPORT_ENVIRONMENT";
|
||||
const ACTIVE_SESSION = "GAHOUSINGREPORT_ACTIVE_SESSION";
|
||||
const USER_ID = "GAHOUSINGREPORT_USER_ID";
|
||||
const USER_SERIAL = "GAHOUSINGREPORT_USER_SERIAL";
|
||||
const USER_NAME = "GAHOUSINGREPORT_USER_NAME";
|
||||
const USER_CLIENT_NAME = "GAHOUSINGREPORT_USER_CLIENT_NAME";
|
||||
const USER_EMAIL = "GAHOUSINGREPORT_USER_EMAIL";
|
||||
const USER_ROLE = "GAHOUSINGREPORT_USER_ROLE";
|
||||
const USER_AUTHENTICATED = "GAHOUSINGREPORT_USER_AUTHENTICATED";
|
||||
const REPORTS_GET = "GAHOUSINGREPORT_REPORTS_GET";
|
||||
const REPORTS_POST = "GAHOUSINGREPORT_REPORTS_POST";
|
||||
const THEME = "GAHOUSINGREPORT_THEME";
|
||||
const AJAX = "GAHOUSINGREPORT_AJAX";
|
||||
const TODAY = "GAHOUSINGREPORT_TODAY";
|
||||
const PAGE = "GAHOUSINGREPORT_PAGE";
|
||||
const PAGINATION_PAGE = "GAHOUSINGREPORT_PAGINATION_PAGE";
|
||||
|
||||
// =================
|
||||
// Class Constructor
|
||||
// =================
|
||||
|
||||
public function __construct() {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
}
|
||||
|
||||
// ===============================================
|
||||
// Append a SimpleXMLElement to a SimpleXMLElememt
|
||||
// ===============================================
|
||||
|
||||
public function appendSXE(SimpleXMLElement $from, SimpleXMLElement $to) {
|
||||
|
||||
$toDOM = dom_import_simplexml($to);
|
||||
$fromDOM = dom_import_simplexml($from);
|
||||
|
||||
$toDOM->appendChild($toDOM->ownerDocument->importNode($fromDOM, true));
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// Apply an XSL Stylesheet to an XML Document
|
||||
// ==========================================
|
||||
|
||||
public function applyXSL($XMLString = "", $XSLString = "", $XSLParms = "") {
|
||||
|
||||
if ($XMLString instanceof SimpleXMLElement) {
|
||||
$XMLString = $XMLString->asXML();
|
||||
}
|
||||
|
||||
if (empty($XSLString)) {
|
||||
trigger_error("No XSL Stylesheet provided.");
|
||||
}
|
||||
|
||||
if (!is_array($XSLParms)) {
|
||||
$XSLParms = array();
|
||||
}
|
||||
|
||||
$XSLParms["APPLICATION_NAME"] = self::APPLICATION_NAME;
|
||||
$XSLParms["APPLICATION_MNEMONIC"] = self::APPLICATION_MNEMONIC;
|
||||
$XSLParms["VERSION"] = self::VERSION;
|
||||
$XSLParms["THEME"] = $_SESSION[self::THEME] ?? self::THEME;
|
||||
$XSLParms["ENVIRONMENT"] = $_SESSION[self::ENVIRONMENT] ?? "Production";
|
||||
$XSLParms["USER_NAME"] = $_SESSION[self::USER_NAME] ?? "";
|
||||
$XSLParms["USER_CLIENT_NAME"] = $_SESSION[self::USER_CLIENT_NAME] ?? "";
|
||||
$XSLParms["USER_ROLE"] = $_SESSION[self::USER_ROLE] ?? "Guest";
|
||||
$XSLParms["RANDOM_NUMBER"] = rand();
|
||||
$XSLParms["TODAY_YYYYMMDD"] = date("Y-m-d");
|
||||
$XSLParms["TODAY_MMDDYYYY"] = date("m/d/Y");
|
||||
|
||||
$XML = new DOMDocument();
|
||||
$XSL = new DOMDocument();
|
||||
$XSLT = new XSLTProcessor();
|
||||
|
||||
if ($XMLString) {
|
||||
$XML->loadXML($XMLString);
|
||||
}
|
||||
|
||||
if ($XSLString) {
|
||||
$XSL->loadXML($XSLString);
|
||||
}
|
||||
|
||||
$XSLT->importStylesheet($XSL);
|
||||
|
||||
if ($XSLParms) {
|
||||
$XSLT->setParameter("", $XSLParms);
|
||||
}
|
||||
|
||||
$document = $XSLT->transformToXml($XML);
|
||||
|
||||
return $document;
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Return a Database Connection
|
||||
// ============================
|
||||
|
||||
public function connect() {
|
||||
|
||||
$Settings = $this->getSettings();
|
||||
|
||||
if ($Settings->Environment == 'Production') {
|
||||
$host = 'localhost';
|
||||
} else {
|
||||
$host = '192.168.1.190';
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$database = (string) $Settings->DatabaseName;
|
||||
$user = (string) $Settings->DatabaseUser;
|
||||
$password = (string) $Settings->DatabasePassword;
|
||||
|
||||
$connection = new PDO("mysql:host={$host};dbname={$database};charset=utf8", $user, $password);
|
||||
|
||||
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
||||
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (PDOException | Exception $e) {
|
||||
|
||||
trigger_error($e->getMessage());
|
||||
}
|
||||
|
||||
return $connection;
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Debug an Object
|
||||
// ===============
|
||||
|
||||
public function debug($object = "") {
|
||||
|
||||
if ($_SESSION[self::AJAX]) {
|
||||
error_log(print_r($object, true));
|
||||
} else {
|
||||
echo "<pre>";
|
||||
print_r($object);
|
||||
}
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Return a decrypted string
|
||||
// =========================
|
||||
|
||||
protected function decrypt($encrypted = "", $key = "") {
|
||||
|
||||
$key = (empty($key)) ? __CLASS__ : $key;
|
||||
|
||||
$decoded = base64_decode($encrypted);
|
||||
$ivlen = openssl_cipher_iv_length($cipher = "AES-128-CBC");
|
||||
$iv = substr($decoded, 0, $ivlen);
|
||||
$hmac = substr($decoded, $ivlen, $sha2len = 32);
|
||||
$raw = substr($decoded, $ivlen + $sha2len);
|
||||
$decrypted = openssl_decrypt($raw, $cipher, $key, $options = OPENSSL_RAW_DATA, $iv);
|
||||
$calcmac = hash_hmac("sha256", $raw, $key, $as_binary = true);
|
||||
|
||||
if (($hmac === false) or ($calcmac === false)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return (hash_equals($hmac, $calcmac)) ? $decrypted : "";
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Display a Content Page
|
||||
// ======================
|
||||
|
||||
public function displayContent($content = "") {
|
||||
|
||||
$html = $this->applyXSL("", $this->getXSL("content"));
|
||||
$html = str_replace("$$$-CONTENT-$$$", $content, $html);
|
||||
|
||||
echo $html;
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
// Custom error handler to display informative error page
|
||||
// ======================================================
|
||||
|
||||
public function displayError($error_number = "", $error_message = "", $error_file = "", $error_line = "") {
|
||||
|
||||
if (error_reporting() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$error_file = explode("/", $error_file);
|
||||
$error_file = end($error_file);
|
||||
$error_message = str_replace("'", '"', $error_message);
|
||||
|
||||
(new Journal())->journalEntry("{$error_file} | {$error_line} | {$error_message}");
|
||||
|
||||
if (($_SESSION[self::ENVIRONMENT] ?? "Production") == "Production") {
|
||||
(new Email())->sendErrorEmail($error_message, $error_file, $error_line);
|
||||
}
|
||||
|
||||
$XSLParms["FILE_NAME"] = $error_file;
|
||||
$XSLParms["LINE_NUMBER"] = $error_line;
|
||||
$XSLParms["ERROR_MESSAGE"] = $error_message;
|
||||
$XSLParms["ERROR_NUMBER"] = $error_number;
|
||||
|
||||
$content = $this->applyXSL("", $this->getXSL("error"), $XSLParms);
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
exit(); // Exit so that only one error is presented.
|
||||
}
|
||||
|
||||
// =====================
|
||||
// Display a Notice Page
|
||||
// =====================
|
||||
|
||||
public function displayNotice($messgae = "") {
|
||||
|
||||
$XSLParms["MESSAGE"] = $messgae;
|
||||
|
||||
$content = $this->applyXSL("", $this->getXSL("notice"), $XSLParms);
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
// =====================
|
||||
// Display the Home Page
|
||||
// =====================
|
||||
|
||||
public function displayHome() {
|
||||
|
||||
(new Subscriptions())->userSubscriptions();
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Do the requested Action
|
||||
// =======================
|
||||
|
||||
public function do() {
|
||||
|
||||
// $this->debug($_POST);
|
||||
|
||||
$_SESSION[self::TODAY] = date("Y-m-d");
|
||||
|
||||
// Login
|
||||
|
||||
if (($_SESSION[self::USER_AUTHENTICATED] ?? false) === false) {
|
||||
|
||||
(new Users())->login();
|
||||
}
|
||||
|
||||
// Determine if user needs a password change
|
||||
if ($this->userChangePassword() === true) {
|
||||
(new Users())->changePassword();
|
||||
exit();
|
||||
}
|
||||
|
||||
// Determine if this is an AJAX request.
|
||||
|
||||
$_SESSION[self::AJAX] = (isset($_SERVER["HTTP_X_REQUESTED_WITH"]) and strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) === "xmlhttprequest");
|
||||
|
||||
// Get the requested Action
|
||||
|
||||
$action = filter_input(INPUT_POST, "action") ?: "";
|
||||
$Xaction = filter_input(INPUT_GET, "Xaction") ?: "";
|
||||
|
||||
$action = (empty($Xaction) ? $action : $Xaction);
|
||||
|
||||
// Sign Out if requested.
|
||||
|
||||
if (strtolower(trim($action)) === "signout") {
|
||||
$this->initializeSession();
|
||||
}
|
||||
|
||||
// Process the requested Action.
|
||||
|
||||
list($class, $method) = array_pad(explode('.', $action), 2, "");
|
||||
|
||||
if (empty($method)) {
|
||||
|
||||
$method = $class;
|
||||
|
||||
if (method_exists(__CLASS__, $method)) {
|
||||
$this->$method();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (method_exists($class, $method)) {
|
||||
(new $class())->$method();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Default to the Home Page.
|
||||
$this->displayHome();
|
||||
}
|
||||
|
||||
// ==========================
|
||||
// Return an encrypted string
|
||||
// ==========================
|
||||
|
||||
protected function encrypt($string = "", $key = "") {
|
||||
|
||||
$key = (empty($key)) ? __CLASS__ : $key;
|
||||
|
||||
$ivlen = openssl_cipher_iv_length($cipher = "AES-128-CBC");
|
||||
$iv = openssl_random_pseudo_bytes($ivlen);
|
||||
$raw = openssl_encrypt($string, $cipher, $key, $options = OPENSSL_RAW_DATA, $iv);
|
||||
$hmac = hash_hmac("sha256", $raw, $key, $as_binary = true);
|
||||
$encrypted = base64_encode($iv . $hmac . $raw);
|
||||
|
||||
return $encrypted;
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Execute an SQL Statement
|
||||
// ========================
|
||||
|
||||
public function executeSQL($SQL = "") {
|
||||
|
||||
if (trim($SQL) == "") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->connect()->query($SQL);
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Format an XML document
|
||||
// ======================
|
||||
|
||||
public function formatXML($XML = "") {
|
||||
|
||||
if (!$XML) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($XML instanceof SimpleXMLElement) {
|
||||
$XML = $XML->asXML();
|
||||
}
|
||||
|
||||
$dom = new DOMDocument("1.0");
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$dom->formatOutput = true;
|
||||
$dom->loadXML($XML);
|
||||
|
||||
return $dom->saveXML();
|
||||
}
|
||||
|
||||
// =====================================
|
||||
// Return an Application Settings Object
|
||||
// =====================================
|
||||
|
||||
public function getSettings() {
|
||||
|
||||
$settings = new SimpleXMLElement($this->getXML("settings"));
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// ==================================================================
|
||||
// Return Age in Years based on given Birthdate ("yyyy-mm-dd" format)
|
||||
// ==================================================================
|
||||
|
||||
public function getAge($birthdate = "", $date = "") {
|
||||
|
||||
$birthdate = filter_input(INPUT_POST, "birthdate", FILTER_UNSAFE_RAW) ?: $birthdate;
|
||||
$date = filter_input(INPUT_POST, "date", FILTER_UNSAFE_RAW) ?: $date;
|
||||
|
||||
$age = 0;
|
||||
|
||||
$date = (empty($date)) ? new Datetime() : new DateTime($date);
|
||||
$birthdate = (empty($birthdate)) ? new Datetime() : new DateTime($birthdate);
|
||||
|
||||
$age = $birthdate->diff($date)->format("%y");
|
||||
|
||||
if ($_SESSION[self::AJAX]) {
|
||||
echo json_encode($age);
|
||||
} else {
|
||||
return $age;
|
||||
}
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Return a Constants Object
|
||||
// =========================
|
||||
|
||||
public function getConstants() {
|
||||
|
||||
$Constants = new SimpleXMLElement($this->getXML("constants"));
|
||||
|
||||
return $Constants;
|
||||
}
|
||||
|
||||
// ==================
|
||||
// Return a Recordset
|
||||
// ==================
|
||||
|
||||
public function getRecordset($SQL = "") {
|
||||
|
||||
if (empty($SQL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$recordSet = $this->connect()->query($SQL);
|
||||
|
||||
return $recordSet;
|
||||
}
|
||||
|
||||
// =======================================
|
||||
// Return Table Data as a SimpleXMLElement
|
||||
// =======================================
|
||||
|
||||
public function getTable($table = "", $SQL = "") {
|
||||
|
||||
if (empty($table)) {
|
||||
return new SimpleXMLElement("<unknown/>");
|
||||
}
|
||||
|
||||
$SXE = new SimpleXMLElement("<{$table}/>");
|
||||
|
||||
$recordset = $this->getRecordset(empty($SQL) ? "select * from {$table}" : $SQL);
|
||||
|
||||
if ($recordset) {
|
||||
|
||||
while ($row = $recordset->fetch(PDO::FETCH_ASSOC)) {
|
||||
|
||||
$record = $SXE->addChild("record");
|
||||
|
||||
foreach ($row as $name => $value) {
|
||||
$record->$name = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $SXE;
|
||||
}
|
||||
|
||||
// =======================================
|
||||
// Return Table Data as a SimpleXMLElement
|
||||
// =======================================
|
||||
|
||||
public function getTableXML($table = "", $statement = "") {
|
||||
|
||||
if (empty($table)) {
|
||||
return new SimpleXMLElement("<unknown/>");
|
||||
}
|
||||
|
||||
$SXE = new SimpleXMLElement("<{$table}/>");
|
||||
|
||||
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
|
||||
|
||||
$record = $SXE->addChild("record");
|
||||
|
||||
foreach ($row as $name => $value) {
|
||||
$record->$name = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $SXE;
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Return the Time Elapsed since now
|
||||
// =================================
|
||||
|
||||
public function getTimeElapsed($timestamp = "") {
|
||||
|
||||
$now = new DateTime;
|
||||
$then = new DateTime($timestamp);
|
||||
$diff = (array) $now->diff($then);
|
||||
|
||||
$diff["w"] = floor($diff["d"] / 7);
|
||||
$diff["d"] -= $diff["w"] * 7;
|
||||
|
||||
$string = array(
|
||||
"y" => "year",
|
||||
"m" => "month",
|
||||
"w" => "week",
|
||||
"d" => "day",
|
||||
"h" => "hour",
|
||||
"i" => "minute",
|
||||
"s" => "second",
|
||||
);
|
||||
|
||||
foreach ($string as $k => & $v) {
|
||||
|
||||
if ($diff[$k]) {
|
||||
$v = $diff[$k] . " " . $v . ($diff[$k] > 1 ? "s" : "");
|
||||
} else {
|
||||
unset($string[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
$string = array_slice($string, 0, 1);
|
||||
|
||||
return $string ? implode(", ", $string) . " ago" : "just now";
|
||||
}
|
||||
|
||||
// ===================
|
||||
// Return a Time Stamp
|
||||
// ===================
|
||||
|
||||
public function getTimestamp() {
|
||||
|
||||
return date("Y-m-d H:i:s");
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Return an XML Document
|
||||
// ======================
|
||||
|
||||
public function getXML($document = "") {
|
||||
|
||||
if (trim($document) == "") {
|
||||
return "";
|
||||
}
|
||||
|
||||
$document = "xml/" . trim($document) . ".xml";
|
||||
$XML = (file_exists($document) ? file_get_contents($document) : "");
|
||||
|
||||
return $XML;
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Return an XSL Stylesheet
|
||||
// ========================
|
||||
|
||||
public function getXSL($document = "") {
|
||||
|
||||
if (trim($document) == "") {
|
||||
return "";
|
||||
}
|
||||
|
||||
$document = "xsl/" . trim($document) . ".xsl";
|
||||
$XSL = (file_exists($document) ? file_get_contents($document) : "");
|
||||
|
||||
return $XSL;
|
||||
}
|
||||
|
||||
// =======================================
|
||||
// Return a Zip Code Detail Object (Array)
|
||||
// =======================================
|
||||
|
||||
public function getZipcode($zip_code = 0) {
|
||||
|
||||
$zip_code = filter_input(INPUT_POST, "zip_code", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$zip_code = (integer) substr((string) $zip_code, 0, 5);
|
||||
|
||||
$zipCodeDetail = null;
|
||||
|
||||
$SQL = "select *
|
||||
from zipcodes
|
||||
where zipcode_code = {$zip_code}";
|
||||
|
||||
$zipcodes = $this->getTable("zipcodes", $SQL);
|
||||
|
||||
if ($zipcodes->count() > 0) {
|
||||
|
||||
$zipCodeDetail["ZipCode"] = $zip_code;
|
||||
$zipCodeDetail["City"] = (string) $zipcodes->record->zipcode_city;
|
||||
$zipCodeDetail["State"] = (string) $zipcodes->record->zipcode_state;
|
||||
$zipCodeDetail["County"] = (string) $zipcodes->record->zipcode_county;
|
||||
$zipCodeDetail["Country"] = (string) $zipcodes->record->zipcode_country;
|
||||
}
|
||||
|
||||
if ($_SESSION[self::AJAX]) {
|
||||
echo json_encode($zipCodeDetail);
|
||||
} else {
|
||||
return $zipCodeDetail;
|
||||
}
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Initialize the Session
|
||||
// ======================
|
||||
|
||||
public function initializeSession() {
|
||||
|
||||
$settings = $this->getSettings();
|
||||
|
||||
$_SESSION[self::ACTIVE_SESSION] = true;
|
||||
$_SESSION[self::THEME] = "light";
|
||||
$_SESSION[self::ENVIRONMENT] = (string) ($settings->Environment ?? "Production");
|
||||
$_SESSION[self::USER_AUTHENTICATED] = false;
|
||||
$_SESSION[self::USER_SERIAL] = 0;
|
||||
$_SESSION[self::USER_ID] = "";
|
||||
$_SESSION[self::USER_NAME] = "";
|
||||
$_SESSION[self::USER_CLIENT_NAME] = "";
|
||||
$_SESSION[self::USER_EMAIL] = "";
|
||||
$_SESSION[self::USER_ROLE] = "Guest";
|
||||
$_SESSION[self::REPORTS_GET] = "";
|
||||
$_SESSION[self::REPORTS_POST] = "";
|
||||
$_SESSION[self::AJAX] = false;
|
||||
}
|
||||
|
||||
// ============
|
||||
// Log an Error
|
||||
// ============
|
||||
|
||||
public function logError($error_message = "") {
|
||||
|
||||
(new Journal())->journalEntry($error_message);
|
||||
|
||||
$this->displayHome();
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
// ==========================
|
||||
// Merge thisXML with thatXML
|
||||
// ==========================
|
||||
|
||||
public function mergeXML($thisXML = "", $thatXML = "") {
|
||||
|
||||
if ($thisXML instanceof SimpleXMLElement) {
|
||||
$thisXML = $thisXML->asXML();
|
||||
}
|
||||
|
||||
if ($thatXML instanceof SimpleXMLElement) {
|
||||
$thatXML = $thatXML->asXML();
|
||||
}
|
||||
|
||||
if (trim($thisXML) == "") {
|
||||
return $thatXML;
|
||||
}
|
||||
|
||||
if (trim($thatXML) == "") {
|
||||
return $thisXML;
|
||||
}
|
||||
|
||||
$thisDOM = new DOMDocument();
|
||||
$thisDOM->loadXML($thisXML);
|
||||
|
||||
$thatDOM = new DOMDocument();
|
||||
$thatDOM->loadXML($thatXML);
|
||||
|
||||
$xpath = new DOMXpath($thisDOM);
|
||||
$xpathQuery = $xpath->query("/*");
|
||||
|
||||
for ($i = 0; $i < $xpathQuery->length; $i++) {
|
||||
$thatDOM->documentElement->appendChild($thatDOM->importNode($xpathQuery->item($i), true));
|
||||
}
|
||||
|
||||
$thatSXE = simplexml_import_dom($thatDOM);
|
||||
|
||||
return $thatSXE->asXML();
|
||||
}
|
||||
|
||||
// ==============
|
||||
// Print a Report
|
||||
// ==============
|
||||
|
||||
public function print() {
|
||||
|
||||
$_SESSION[self::REPORTS_GET] = $_GET;
|
||||
$_SESSION[self::REPORTS_POST] = $_POST;
|
||||
|
||||
$report = filter_input(INPUT_POST, "report") ?: "";
|
||||
|
||||
(new $report())->print();
|
||||
}
|
||||
|
||||
// =================
|
||||
// Sanitize a string
|
||||
// =================
|
||||
|
||||
public function sanitizeString($string = "") {
|
||||
|
||||
return trim(preg_replace("/\s+/", " ", htmlspecialchars($string, ENT_NOQUOTES | ENT_HTML5)));
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Toggle the current Theme
|
||||
// ========================
|
||||
|
||||
public function toggleTheme() {
|
||||
|
||||
$_SESSION[self::THEME] = (($_SESSION[self::THEME] ?? "light") === "dark") ? "light" : "dark";
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// Validate a Date (local or AJAX)
|
||||
// ===============================
|
||||
|
||||
public function validateDate($date = "", $format = "Y-m-d") {
|
||||
|
||||
$date = filter_input(INPUT_POST, "date") ?: $date;
|
||||
|
||||
$datetime = DateTime::createFromFormat($format, $date);
|
||||
|
||||
$valid = $datetime && $datetime->format($format) === $date;
|
||||
|
||||
if ($_SESSION[self::AJAX]) {
|
||||
echo json_encode($valid);
|
||||
} else {
|
||||
return $valid;
|
||||
}
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Generate Random Password
|
||||
// ========================
|
||||
|
||||
public function generateRandomPassword($length = 12) {
|
||||
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()-_+=';
|
||||
$password = '';
|
||||
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$index = rand(0, strlen($characters) - 1);
|
||||
$password .= $characters[$index];
|
||||
}
|
||||
|
||||
return $password;
|
||||
}
|
||||
|
||||
// ====================
|
||||
// User Change Password
|
||||
// ====================
|
||||
|
||||
public function userChangePassword() {
|
||||
|
||||
$user = (new Users())->getUserByUserName($_SESSION[self::USER_NAME]);
|
||||
|
||||
if ($user->record->user_change_password == 1) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ==============================
|
||||
// Alter Sting to Parahgraph Case
|
||||
// ==============================
|
||||
|
||||
public function toParagraphCase($text) {
|
||||
|
||||
$text = ucwords(strtolower($text));
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
// ==========================
|
||||
// Developer Testing Function
|
||||
// ==========================
|
||||
|
||||
public function testing() {
|
||||
|
||||
$to = "james.richie@onesourceits.com";
|
||||
$subject = "test for dev";
|
||||
$message = "test";
|
||||
|
||||
$email = (new Email())->sendEmail($to, $subject, $message);
|
||||
|
||||
$this->debug($email);
|
||||
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
|
||||
class Consolidation extends Base {
|
||||
|
||||
// Variables.
|
||||
|
||||
private $current_user_serial = 0;
|
||||
private $current_user_id = "";
|
||||
private $current_user_name = "";
|
||||
private $current_user_email = "";
|
||||
|
||||
// =================
|
||||
// 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] ?? "";
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Consolidation Sequence
|
||||
// ======================
|
||||
|
||||
public function consolidationSequence() {
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$content = $this->applyXSL("", $this->getXSL("consolidationAlert"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "run":
|
||||
|
||||
$sql_insert = "insert into rdiconsolidations
|
||||
|
||||
( rdiconsolidation_permit_facts_id,
|
||||
rdiconsolidation_entry_date_str,
|
||||
rdiconsolidation_entry_date,
|
||||
rdiconsolidation_permit_number,
|
||||
rdiconsolidation_permit_date_str,
|
||||
rdiconsolidation_permit_date,
|
||||
rdiconsolidation_project_addr,
|
||||
rdiconsolidation_sub_div_name,
|
||||
rdiconsolidation_project_type,
|
||||
rdiconsolidation_company,
|
||||
rdiconsolidation_address,
|
||||
rdiconsolidation_city,
|
||||
rdiconsolidation_state,
|
||||
rdiconsolidation_zip,
|
||||
rdiconsolidation_phone,
|
||||
rdiconsolidation_project_city,
|
||||
rdiconsolidation_project_state,
|
||||
rdiconsolidation_size,
|
||||
rdiconsolidation_units,
|
||||
rdiconsolidation_building_type,
|
||||
rdiconsolidation_value,
|
||||
rdiconsolidation_work_type,
|
||||
rdiconsolidation_county,
|
||||
rdiconsolidation_lot,
|
||||
rdiconsolidation_dist_ll,
|
||||
rdiconsolidation_ct1,
|
||||
rdiconsolidation_owner_name,
|
||||
rdiconsolidation_owner_address,
|
||||
rdiconsolidation_owner_city,
|
||||
rdiconsolidation_owner_state,
|
||||
rdiconsolidation_owner_zip,
|
||||
rdiconsolidation_owner_phone,
|
||||
rdiconsolidation_ytd_permits,
|
||||
rdiconsolidation_ytd_value,
|
||||
rdiconsolidation_12mth_prev_permits,
|
||||
rdiconsolidation_date )
|
||||
|
||||
values ( :rdiconsolidation_permit_facts_id,
|
||||
:rdiconsolidation_entry_date_str,
|
||||
:rdiconsolidation_entry_date,
|
||||
:rdiconsolidation_permit_number,
|
||||
:rdiconsolidation_permit_date_str,
|
||||
:rdiconsolidation_permit_date,
|
||||
:rdiconsolidation_project_addr,
|
||||
:rdiconsolidation_sub_div_name,
|
||||
:rdiconsolidation_project_type,
|
||||
:rdiconsolidation_company,
|
||||
:rdiconsolidation_address,
|
||||
:rdiconsolidation_city,
|
||||
:rdiconsolidation_state,
|
||||
:rdiconsolidation_zip,
|
||||
:rdiconsolidation_phone,
|
||||
:rdiconsolidation_project_city,
|
||||
:rdiconsolidation_project_state,
|
||||
:rdiconsolidation_size,
|
||||
:rdiconsolidation_units,
|
||||
:rdiconsolidation_building_type,
|
||||
:rdiconsolidation_value,
|
||||
:rdiconsolidation_work_type,
|
||||
:rdiconsolidation_county,
|
||||
:rdiconsolidation_lot,
|
||||
:rdiconsolidation_dist_ll,
|
||||
:rdiconsolidation_ct1,
|
||||
:rdiconsolidation_owner_name,
|
||||
:rdiconsolidation_owner_address,
|
||||
:rdiconsolidation_owner_city,
|
||||
:rdiconsolidation_owner_state,
|
||||
:rdiconsolidation_owner_zip,
|
||||
:rdiconsolidation_owner_phone,
|
||||
:rdiconsolidation_ytd_permits,
|
||||
:rdiconsolidation_ytd_value,
|
||||
:rdiconsolidation_12mth_prev_permits,
|
||||
:rdiconsolidation_date ) ";
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$connection->beginTransaction();
|
||||
$statement = $connection->prepare($sql_insert);
|
||||
|
||||
$rdi_records = $this->getRdiTable();
|
||||
$rdi_record_count = $rdi_records->count();
|
||||
|
||||
$processed_record_count = 0;
|
||||
|
||||
foreach ($rdi_records as $record) {
|
||||
|
||||
$rdiconsolidation_permit_facts_id = (integer) $record->permit_facts_id ?: 0;
|
||||
$rdiconsolidation_entry_date_str = (integer) $record->entry_date_str ?: "";
|
||||
$rdiconsolidation_entry_date = (string) $record->entry_date ?: "0000-00-00";
|
||||
$rdiconsolidation_permit_number = (string) $record->permit_number ?: "";
|
||||
$rdiconsolidation_permit_date_str = (string) $record->permit_date_str ?: "";
|
||||
$rdiconsolidation_permit_date = (string) $record->permit_date ?: "0000-00-00";
|
||||
$rdiconsolidation_project_addr = (string) $record->project_addr ?: "";
|
||||
$rdiconsolidation_sub_div_name = (string) $record->sub_div_name ?: "";
|
||||
$rdiconsolidation_project_type = (string) $record->project_type ?: "";
|
||||
$rdiconsolidation_company = (string) $record->company ?: "";
|
||||
$rdiconsolidation_address = (string) $record->address ?: "";
|
||||
$rdiconsolidation_city = (string) $record->city ?: "";
|
||||
$rdiconsolidation_state = (string) $record->state ?: "";
|
||||
$rdiconsolidation_zip = (string) $record->zip ?: "";
|
||||
$rdiconsolidation_phone = (string) $record->phone ?: "";
|
||||
$rdiconsolidation_project_city = (string) $record->project_city ?: "";
|
||||
$rdiconsolidation_project_state = (string) $record->project_state ?: "";
|
||||
$rdiconsolidation_size = (integer) $record->size ?: 0;
|
||||
$rdiconsolidation_units = (integer) $record->units ?: 0;
|
||||
$rdiconsolidation_building_type = (integer) $record->building_type ?: 0;
|
||||
$rdiconsolidation_value = (integer) $record->value ?: 0;
|
||||
$rdiconsolidation_work_type = (integer) $record->work_type ?: 0;
|
||||
$rdiconsolidation_county = (string) $record->county ?: "";
|
||||
$rdiconsolidation_lot = (string) $record->lot ?: "";
|
||||
$rdiconsolidation_dist_ll = (string) $record->dist_ll ?: "";
|
||||
$rdiconsolidation_ct1 = (integer) $record->ct1 ?: 0;
|
||||
$rdiconsolidation_owner_name = (string) $record->owner_name ?: "";
|
||||
$rdiconsolidation_owner_address = (string) $record->owner_address ?: "";
|
||||
$rdiconsolidation_owner_city = (string) $record->owner_city ?: "";
|
||||
$rdiconsolidation_owner_state = (string) $record->owner_state ?: "";
|
||||
$rdiconsolidation_owner_zip = (string) $record->owner_zip ?: "";
|
||||
$rdiconsolidation_owner_phone = (string) $record->owner_phone ?: "";
|
||||
$rdiconsolidation_ytd_permits = (integer) $record->ytd_permits ?: 0;
|
||||
$rdiconsolidation_ytd_value = (integer) $record->ytd_value ?: 0;
|
||||
$rdiconsolidation_12mth_prev_permits = (integer) $record->{"12mth_prev_permits"} ?: 0;
|
||||
$rdiconsolidation_date = date("Y-m-d");
|
||||
|
||||
$statement->bindValue(":rdiconsolidation_permit_facts_id", $rdiconsolidation_permit_facts_id);
|
||||
$statement->bindValue(":rdiconsolidation_entry_date_str", $rdiconsolidation_entry_date_str);
|
||||
$statement->bindValue(":rdiconsolidation_entry_date", $rdiconsolidation_entry_date);
|
||||
$statement->bindValue(":rdiconsolidation_permit_number", $rdiconsolidation_permit_number);
|
||||
$statement->bindValue(":rdiconsolidation_permit_date_str", $rdiconsolidation_permit_date_str);
|
||||
$statement->bindValue(":rdiconsolidation_permit_date", $rdiconsolidation_permit_date);
|
||||
$statement->bindValue(":rdiconsolidation_project_addr", $rdiconsolidation_project_addr);
|
||||
$statement->bindValue(":rdiconsolidation_sub_div_name", $rdiconsolidation_sub_div_name);
|
||||
$statement->bindValue(":rdiconsolidation_project_type", $rdiconsolidation_project_type);
|
||||
$statement->bindValue(":rdiconsolidation_company", $rdiconsolidation_company);
|
||||
$statement->bindValue(":rdiconsolidation_address", $rdiconsolidation_address);
|
||||
$statement->bindValue(":rdiconsolidation_city", $rdiconsolidation_city);
|
||||
$statement->bindValue(":rdiconsolidation_state", $rdiconsolidation_state);
|
||||
$statement->bindValue(":rdiconsolidation_zip", $rdiconsolidation_zip);
|
||||
$statement->bindValue(":rdiconsolidation_phone", $rdiconsolidation_phone);
|
||||
$statement->bindValue(":rdiconsolidation_project_city", $rdiconsolidation_project_city);
|
||||
$statement->bindValue(":rdiconsolidation_project_state", $rdiconsolidation_project_state);
|
||||
$statement->bindValue(":rdiconsolidation_size", $rdiconsolidation_size);
|
||||
$statement->bindValue(":rdiconsolidation_units", $rdiconsolidation_units);
|
||||
$statement->bindValue(":rdiconsolidation_building_type", $rdiconsolidation_building_type);
|
||||
$statement->bindValue(":rdiconsolidation_value", $rdiconsolidation_value);
|
||||
$statement->bindValue(":rdiconsolidation_work_type", $rdiconsolidation_work_type);
|
||||
$statement->bindValue(":rdiconsolidation_county", $rdiconsolidation_county);
|
||||
$statement->bindValue(":rdiconsolidation_lot", $rdiconsolidation_lot);
|
||||
$statement->bindValue(":rdiconsolidation_dist_ll", $rdiconsolidation_dist_ll);
|
||||
$statement->bindValue(":rdiconsolidation_ct1", $rdiconsolidation_ct1);
|
||||
$statement->bindValue(":rdiconsolidation_owner_name", $rdiconsolidation_owner_name);
|
||||
$statement->bindValue(":rdiconsolidation_owner_address", $rdiconsolidation_owner_address);
|
||||
$statement->bindValue(":rdiconsolidation_owner_city", $rdiconsolidation_owner_city);
|
||||
$statement->bindValue(":rdiconsolidation_owner_state", $rdiconsolidation_owner_state);
|
||||
$statement->bindValue(":rdiconsolidation_owner_zip", $rdiconsolidation_owner_zip);
|
||||
$statement->bindValue(":rdiconsolidation_owner_phone", $rdiconsolidation_owner_phone);
|
||||
$statement->bindValue(":rdiconsolidation_ytd_permits", $rdiconsolidation_ytd_permits);
|
||||
$statement->bindValue(":rdiconsolidation_ytd_value", $rdiconsolidation_ytd_value);
|
||||
$statement->bindValue(":rdiconsolidation_12mth_prev_permits", $rdiconsolidation_12mth_prev_permits);
|
||||
$statement->bindValue(":rdiconsolidation_date", $rdiconsolidation_date);
|
||||
|
||||
if (!$statement->execute()) {
|
||||
|
||||
$connection->rollBack();
|
||||
$this->debug($connection->errorInfo()[2]);
|
||||
}
|
||||
|
||||
$processed_record_count++;
|
||||
}
|
||||
|
||||
if ($processed_record_count !== $rdi_record_count) {
|
||||
$connection->rollBack();
|
||||
$XSLParms["CONSOLIDATION_ERROR"] = "Record Counts Did not match. Rolling Back Database. Contact Support.";
|
||||
} else {
|
||||
$connection->commit();
|
||||
$this->executeSQL("truncate rdis");
|
||||
}
|
||||
|
||||
$XSLParms["RDI-RECORD-COUNT"] = $rdi_record_count;
|
||||
$XSLParms["PROCESSED-RECORD-COUNT"] = $processed_record_count;
|
||||
$content = $this->applyXSL("", $this->getXSL("consolidationResults"), $XSLParms);
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ====================
|
||||
// Return an RDI Object
|
||||
// ====================
|
||||
|
||||
public function getRdiTable() {
|
||||
|
||||
$SQL = "SELECT * FROM rdis";
|
||||
|
||||
return $this->getTable("rdis", $SQL);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,389 @@
|
||||
<?php
|
||||
|
||||
class Counties 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;
|
||||
}
|
||||
|
||||
// ==========
|
||||
// Add County
|
||||
// ==========
|
||||
|
||||
public function addCounty() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$constants = $this->getConstants();
|
||||
$content = $this->applyXSL($constants, $this->getXSL("addCounty"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "add":
|
||||
|
||||
$county_name = filter_input(INPUT_POST, "county_name") ?: "";
|
||||
|
||||
$SQL = "insert into counties
|
||||
|
||||
( county_name,
|
||||
county_area,
|
||||
county_creator,
|
||||
county_created )
|
||||
|
||||
VALUES ( :county_name,
|
||||
:county_area,
|
||||
:county_creator,
|
||||
:county_created )";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":county_name", $county_name);
|
||||
$statement->bindValue(":county_area", $county_name);
|
||||
$statement->bindValue(":county_creator", $this->current_user_name);
|
||||
$statement->bindValue(":county_created", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// =============
|
||||
// Delete County
|
||||
// =============
|
||||
|
||||
public function deleteCounty() {
|
||||
|
||||
$county_serial = filter_input(INPUT_POST, "county_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$county = $this->getCounty($county_serial);
|
||||
|
||||
if ($county->count() == 0) {
|
||||
$this->logError("Invalid County ({$county_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "delete from counties
|
||||
where county_serial = {$county_serial}";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Determine if a County exists
|
||||
// ============================
|
||||
|
||||
public function countyExists() {
|
||||
|
||||
$county_serial = filter_input(INPUT_POST, "county_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$county_name = filter_input(INPUT_POST, "county_name") ?: "";
|
||||
|
||||
$SQL = "select county_serial
|
||||
from view_counties
|
||||
where county_serial != :county_serial
|
||||
and lower(county_name) = :county_name";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":county_serial", $county_serial);
|
||||
$statement->bindValue(":county_name", strtolower($county_name));
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$exists = (count($recordset) > 0) ? true : false;
|
||||
|
||||
echo json_encode($exists);
|
||||
}
|
||||
|
||||
// ======================================
|
||||
// Determine if a County is Active (AJAX)
|
||||
// ======================================
|
||||
|
||||
public function countyActive() {
|
||||
|
||||
$rdi_county = filter_input(INPUT_POST, "rdi_county") ?: "";
|
||||
|
||||
$active = false;
|
||||
|
||||
$SQL = "select rdi_county
|
||||
from rdis
|
||||
where rdi_county = {$rdi_county}
|
||||
limit 1";
|
||||
|
||||
$workorders = $this->getTable("county", $SQL);
|
||||
|
||||
$active = ($workorders->count() > 0) ? true : false;
|
||||
|
||||
echo json_encode($active);
|
||||
}
|
||||
|
||||
// =============
|
||||
// Edit a County
|
||||
// =============
|
||||
|
||||
public function editCounty() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$county_serial = filter_input(INPUT_POST, "county_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$county = $this->getCounty($county_serial);
|
||||
|
||||
if ($county->count() == 0) {
|
||||
$this->logError("Invalid County ({$county_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$constants = $this->getConstants();
|
||||
|
||||
$XML = $this->mergeXML($county, "<XML/>");
|
||||
$XML = $this->mergeXML($constants, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("editCounty"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "update":
|
||||
|
||||
$county_serial = filter_input(INPUT_POST, "county_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$county_name = filter_input(INPUT_POST, "county_name") ?: "";
|
||||
$county_area = filter_input(INPUT_POST, "county_area") ?: "";
|
||||
|
||||
// Verify the County
|
||||
|
||||
$county = $this->getCounty($county_serial);
|
||||
|
||||
if ($county->count() == 0) {
|
||||
$this->logError("Invalid County ({$county_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "update counties
|
||||
set county_name = :county_name,
|
||||
county_area = :county_area,
|
||||
county_creator = :county_creator,
|
||||
county_created = :county_created
|
||||
where county_serial = :county_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":county_serial", $county_serial);
|
||||
$statement->bindValue(":county_name", $county_name);
|
||||
$statement->bindValue(":county_area", $county_area);
|
||||
$statement->bindValue(":county_creator", $this->current_user_name);
|
||||
$statement->bindValue(":county_created", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ================================
|
||||
// Return an Active Counties Object
|
||||
// ================================
|
||||
|
||||
public function getActiveCounties() {
|
||||
|
||||
$SQL = "select view_counties.*
|
||||
from view_counties
|
||||
where county_active is true";
|
||||
|
||||
return $this->getTable("counties", $SQL);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Return an County Object
|
||||
// =======================
|
||||
|
||||
public function getCounty($county_serial = 0) {
|
||||
|
||||
$SQL = "select view_counties.*
|
||||
from view_counties
|
||||
where county_serial = {$county_serial}";
|
||||
|
||||
return $this->getTable("counties", $SQL);
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Return a Counties Object
|
||||
// ========================
|
||||
|
||||
public function getCounties() {
|
||||
|
||||
$SQL = "select view_counties.*
|
||||
from view_counties";
|
||||
|
||||
return $this->getTable("counties", $SQL);
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Return a Counties Object
|
||||
// ========================
|
||||
|
||||
public function getCountiesByArea($area) {
|
||||
|
||||
$SQL = "select view_counties.*
|
||||
from view_counties";
|
||||
|
||||
if ($area != "All") {
|
||||
$SQL .= " where view_counties.county_area = '{$area}'";
|
||||
}
|
||||
|
||||
return $this->getTable("counties", $SQL);
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Return a Counties Object
|
||||
// ========================
|
||||
|
||||
public function getCountiesByName($county_name) {
|
||||
|
||||
$SQL = "select view_counties.*
|
||||
from view_counties
|
||||
where view_counties.county_name = '{$county_name}'";
|
||||
|
||||
return $this->getTable("counties", $SQL);
|
||||
}
|
||||
|
||||
// =============================
|
||||
// Return a Counties Page Object
|
||||
// =============================
|
||||
|
||||
public function getCountiesPage() {
|
||||
|
||||
// Find Criteria
|
||||
|
||||
$find_county = filter_input(INPUT_POST, "find_county") ?: "";
|
||||
$find_county = $this->sanitizeString($find_county);
|
||||
|
||||
$find_words = implode("|", explode(" ", $find_county));
|
||||
|
||||
// Record Count
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "select count(*) as count
|
||||
from view_counties
|
||||
where county_name regexp :county_name";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":county_name", $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_counties.*
|
||||
from view_counties
|
||||
where county_name regexp :county_name
|
||||
order by county_name
|
||||
limit {$this->pagination_size}
|
||||
offset {$offset}";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":county_name", $find_words);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$counties = $this->getTableXML("counties", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
|
||||
$counties->addAttribute("count", $count);
|
||||
$counties->addAttribute("start", $start);
|
||||
$counties->addAttribute("end", $end);
|
||||
$counties->addAttribute("page", $this->pagination_page);
|
||||
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $counties;
|
||||
}
|
||||
|
||||
// ==============
|
||||
// Setup Counties
|
||||
// ==============
|
||||
|
||||
public function setupCounties() {
|
||||
|
||||
$counties = $this->getCountiesPage();
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
$XML = $this->mergeXML($counties, "<XML/>");
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("setupCounties"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,733 @@
|
||||
<?php
|
||||
|
||||
// ===============
|
||||
// Dropdowns Class
|
||||
// ===============
|
||||
|
||||
class Dropdowns extends Base {
|
||||
|
||||
// Variables.
|
||||
|
||||
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_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;
|
||||
}
|
||||
|
||||
// ============
|
||||
// Add Dropdown
|
||||
// ============
|
||||
|
||||
public function addDropdown() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$dropdowntype_serial = filter_input(INPUT_POST, "dropdowntype_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$dropdowntype = $this->getDropdowntype($dropdowntype_serial);
|
||||
|
||||
if ($dropdowntype->count() == 0) {
|
||||
$this->logError("Invalid Dropdowntype ({$dropdowntype_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$XML = $this->mergeXML($dropdowntype, "<XML/>");
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("addDropdown"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "add":
|
||||
|
||||
$dropdowntype_serial = filter_input(INPUT_POST, "dropdowntype_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$dropdown_value = filter_input(INPUT_POST, "dropdown_value") ?: "";
|
||||
|
||||
$SQL = "insert into dropdowns
|
||||
|
||||
( dropdown_dropdowntype,
|
||||
dropdown_value,
|
||||
dropdown_creator,
|
||||
dropdown_created )
|
||||
|
||||
VALUES ( :dropdown_dropdowntype,
|
||||
:dropdown_value,
|
||||
:dropdown_creator,
|
||||
:dropdown_created )";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":dropdown_dropdowntype", $dropdowntype_serial);
|
||||
$statement->bindValue(":dropdown_value", $dropdown_value);
|
||||
$statement->bindValue(":dropdown_creator", $this->current_user_name);
|
||||
$statement->bindValue(":dropdown_created", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ================
|
||||
// Add Dropdowntype
|
||||
// ================
|
||||
|
||||
public function addDropdowntype() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$content = $this->applyXSL("", $this->getXSL("addDropdowntype"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "add":
|
||||
|
||||
$dropdowntype_name = filter_input(INPUT_POST, "dropdowntype_name") ?: "";
|
||||
$dropdowntype_title = filter_input(INPUT_POST, "dropdowntype_title") ?: "";
|
||||
$dropdowntype_table = filter_input(INPUT_POST, "dropdowntype_table") ?: "";
|
||||
$dropdowntype_column = filter_input(INPUT_POST, "dropdowntype_column") ?: "";
|
||||
|
||||
$SQL = "insert into dropdowntypes
|
||||
|
||||
( dropdowntype_name,
|
||||
dropdowntype_title,
|
||||
dropdowntype_table,
|
||||
dropdowntype_column,
|
||||
dropdowntype_creator,
|
||||
dropdowntype_created )
|
||||
|
||||
VALUES ( :dropdowntype_name,
|
||||
:dropdowntype_title,
|
||||
:dropdowntype_table,
|
||||
:dropdowntype_column,
|
||||
:dropdowntype_creator,
|
||||
:dropdowntype_created )";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":dropdowntype_name", $dropdowntype_name);
|
||||
$statement->bindValue(":dropdowntype_title", $dropdowntype_title);
|
||||
$statement->bindValue(":dropdowntype_table", $dropdowntype_table);
|
||||
$statement->bindValue(":dropdowntype_column", $dropdowntype_column);
|
||||
$statement->bindValue(":dropdowntype_creator", $this->current_user_name);
|
||||
$statement->bindValue(":dropdowntype_created", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Delete Dropdown
|
||||
// ===============
|
||||
|
||||
public function deleteDropdown() {
|
||||
|
||||
$dropdown_serial = filter_input(INPUT_POST, "dropdown_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$dropdown = $this->getDropdown($dropdown_serial);
|
||||
|
||||
if ($dropdown->count() == 0) {
|
||||
$this->logError("Invalid Dropdown ({$dropdown_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "delete from dropdowns
|
||||
where dropdown_serial = {$dropdown_serial}";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
}
|
||||
|
||||
// ===================
|
||||
// Delete Dropdowntype
|
||||
// ===================
|
||||
|
||||
public function deleteDropdowntype() {
|
||||
|
||||
$dropdowntype_serial = filter_input(INPUT_POST, "dropdowntype_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$dropdowntype = $this->getDropdowntype($dropdowntype_serial);
|
||||
|
||||
if ($dropdowntype->count() == 0) {
|
||||
$this->logError("Invalid Dropdowntype ({$dropdowntype_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "delete from dropdowntypes
|
||||
where dropdowntype_serial = {$dropdowntype_serial}";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
}
|
||||
|
||||
// ==============================
|
||||
// Determine if a Dropdown exists
|
||||
// ==============================
|
||||
|
||||
public function dropdownExists() {
|
||||
|
||||
$dropdowntype_serial = filter_input(INPUT_POST, "dropdowntype_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$dropdown_serial = filter_input(INPUT_POST, "dropdown_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$dropdown_value = filter_input(INPUT_POST, "dropdown_value") ?: "";
|
||||
|
||||
$dropdown_value = strtolower($dropdown_value);
|
||||
|
||||
$SQL = "select dropdown_serial
|
||||
from view_dropdowns
|
||||
where dropdown_serial != :dropdown_serial
|
||||
and dropdown_dropdowntype = :dropdown_dropdowntype
|
||||
and lower(dropdown_value) = :dropdown_value";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":dropdown_serial", $dropdown_serial);
|
||||
$statement->bindValue(":dropdown_dropdowntype", $dropdowntype_serial);
|
||||
$statement->bindValue(":dropdown_value", $dropdown_value);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$exists = (count($recordset) > 0) ? true : false;
|
||||
|
||||
echo json_encode($exists);
|
||||
}
|
||||
|
||||
// ==================================
|
||||
// Determine if a Dropdowntype exists
|
||||
// ==================================
|
||||
|
||||
public function dropdowntypeExists() {
|
||||
|
||||
$dropdowntype_serial = filter_input(INPUT_POST, "dropdowntype_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$dropdowntype_name = filter_input(INPUT_POST, "dropdowntype_name") ?: "";
|
||||
|
||||
$dropdowntype_name = strtolower($dropdowntype_name);
|
||||
|
||||
$SQL = "select dropdowntype_serial
|
||||
from view_dropdowntypes
|
||||
where dropdowntype_serial != :dropdowntype_serial
|
||||
and lower(dropdowntype_name) = :dropdowntype_name";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":dropdowntype_serial", $dropdowntype_serial);
|
||||
$statement->bindValue(":dropdowntype_name", $dropdowntype_name);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$exists = (count($recordset) > 0) ? true : false;
|
||||
|
||||
echo json_encode($exists);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Determine if a Dropdowntype Title exists
|
||||
// ========================================
|
||||
|
||||
public function dropdowntypetitleExists() {
|
||||
|
||||
$dropdowntype_serial = filter_input(INPUT_POST, "dropdowntype_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$dropdowntype_title = filter_input(INPUT_POST, "dropdowntype_title") ?: "";
|
||||
|
||||
$dropdowntype_title = strtolower($dropdowntype_title);
|
||||
|
||||
$SQL = "select dropdowntype_serial
|
||||
from view_dropdowntypes
|
||||
where dropdowntype_serial != :dropdowntype_serial
|
||||
and lower(dropdowntype_title) = :dropdowntype_title";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":dropdowntype_serial", $dropdowntype_serial);
|
||||
$statement->bindValue(":dropdowntype_title", $dropdowntype_title);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$exists = (count($recordset) > 0) ? true : false;
|
||||
|
||||
echo json_encode($exists);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Determine if a Dropdown is Active
|
||||
// =================================
|
||||
|
||||
public function dropdownActive() {
|
||||
|
||||
$dropdown_serial = filter_input(INPUT_POST, "dropdown_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$dropdown = $this->getDropdown($dropdown_serial);
|
||||
|
||||
if ($dropdown->count() == 0) {
|
||||
$this->logError("Invalid Dropdown ({$dropdown_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$table = (string) $dropdown->record->dropdowntype_table;
|
||||
$column = (string) $dropdown->record->dropdowntype_column;
|
||||
|
||||
$active = false;
|
||||
|
||||
switch ($table) {
|
||||
|
||||
case "*none": // No table, never Active.
|
||||
|
||||
break;
|
||||
|
||||
case "*function": // Requires it's own function to determine if Active.
|
||||
|
||||
if (method_exists(__CLASS__, $column)) {
|
||||
$active = $this->$column($dropdown_serial);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default: // All others, test the Column in the Table.
|
||||
|
||||
$SQL = "select {$column}
|
||||
from {$table}
|
||||
where {$column} = {$dropdown_serial}";
|
||||
|
||||
$results = $this->getTable("results", $SQL);
|
||||
|
||||
$active = ($results->count() > 0) ? true : false;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
echo json_encode($active);
|
||||
}
|
||||
|
||||
// =====================================
|
||||
// Determine if a Dropdowntype is Active
|
||||
// =====================================
|
||||
|
||||
public function dropdowntypeActive() {
|
||||
|
||||
$dropdowntype_serial = (integer) filter_input(INPUT_POST, "dropdowntype_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$SQL = "select dropdown_serial
|
||||
from view_dropdowns
|
||||
where dropdown_dropdowntype = {$dropdowntype_serial}";
|
||||
|
||||
$dropdowns = $this->getTable("dropdowns", $SQL);
|
||||
|
||||
$active = ($dropdowns->count() > 0) ? true : false;
|
||||
|
||||
echo json_encode($active);
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Edit a Dropdown
|
||||
// ===============
|
||||
|
||||
public function editDropdown() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$dropdown_serial = filter_input(INPUT_POST, "dropdown_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$dropdown = $this->getDropdown($dropdown_serial);
|
||||
|
||||
if ($dropdown->count() == 0) {
|
||||
$this->logError("Invalid Dropdown ({$dropdown_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$XML = $this->mergeXML($dropdown, "<XML/>");
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("editDropdown"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "update":
|
||||
|
||||
$dropdown_serial = filter_input(INPUT_POST, "dropdown_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$dropdown_value = filter_input(INPUT_POST, "dropdown_value") ?: "";
|
||||
|
||||
$dropdown = $this->getDropdown($dropdown_serial);
|
||||
|
||||
if ($dropdown->count() == 0) {
|
||||
$this->logError("Invalid Dropdown ({$dropdown_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "update dropdowns
|
||||
set dropdown_value = :dropdown_value,
|
||||
dropdown_changer = :dropdown_changer,
|
||||
dropdown_changed = :dropdown_changed
|
||||
where dropdown_serial = :dropdown_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":dropdown_serial", $dropdown_serial);
|
||||
$statement->bindValue(":dropdown_value", $dropdown_value);
|
||||
$statement->bindValue(":dropdown_changer", $this->current_user_name);
|
||||
$statement->bindValue(":dropdown_changed", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ===================
|
||||
// Edit a Dropdowntype
|
||||
// ===================
|
||||
|
||||
public function editDropdowntype() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$dropdowntype_serial = filter_input(INPUT_POST, "dropdowntype_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$dropdowntype = $this->getDropdowntype($dropdowntype_serial);
|
||||
|
||||
if ($dropdowntype->count() == 0) {
|
||||
$this->logError("Invalid Dropdowntype ({$dropdowntype_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$XML = $this->mergeXML($dropdowntype, "<XML/>");
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("editDropdowntype"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "update":
|
||||
|
||||
$dropdowntype_serial = filter_input(INPUT_POST, "dropdowntype_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$dropdowntype_name = filter_input(INPUT_POST, "dropdowntype_name") ?: "";
|
||||
$dropdowntype_title = filter_input(INPUT_POST, "dropdowntype_title") ?: "";
|
||||
$dropdowntype_table = filter_input(INPUT_POST, "dropdowntype_table") ?: "";
|
||||
$dropdowntype_column = filter_input(INPUT_POST, "dropdowntype_column") ?: "";
|
||||
|
||||
$dropdowntype = $this->getDropdowntype($dropdowntype_serial);
|
||||
|
||||
if ($dropdowntype->count() == 0) {
|
||||
$this->logError("Invalid Dropdowntype ({$dropdowntype_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "update dropdowntypes
|
||||
set dropdowntype_name = :dropdowntype_name,
|
||||
dropdowntype_title = :dropdowntype_title,
|
||||
dropdowntype_table = :dropdowntype_table,
|
||||
dropdowntype_column = :dropdowntype_column,
|
||||
dropdowntype_changer = :dropdowntype_changer,
|
||||
dropdowntype_changed = :dropdowntype_changed
|
||||
where dropdowntype_serial = :dropdowntype_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":dropdowntype_serial", $dropdowntype_serial);
|
||||
$statement->bindValue(":dropdowntype_name", $dropdowntype_name);
|
||||
$statement->bindValue(":dropdowntype_title", $dropdowntype_title);
|
||||
$statement->bindValue(":dropdowntype_table", $dropdowntype_table);
|
||||
$statement->bindValue(":dropdowntype_column", $dropdowntype_column);
|
||||
$statement->bindValue(":dropdowntype_changer", $this->current_user_name);
|
||||
$statement->bindValue(":dropdowntype_changed", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Return an Active Dropdowns Object
|
||||
// =================================
|
||||
|
||||
public function getActiveDropdowns() {
|
||||
|
||||
$SQL = "select view_dropdowns.*
|
||||
from view_dropdowns
|
||||
where dropdown_active is true";
|
||||
|
||||
return $this->getTable("dropdowns", $SQL);
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Return a Dropdown Object
|
||||
// ========================
|
||||
|
||||
public function getDropdown($dropdown_serial = 0) {
|
||||
|
||||
$SQL = "select view_dropdowns.*
|
||||
from view_dropdowns
|
||||
where dropdown_serial = {$dropdown_serial}";
|
||||
|
||||
return $this->getTable("dropdowns", $SQL);
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Return a Dropdowns Object
|
||||
// =========================
|
||||
|
||||
public function getDropdowns() {
|
||||
|
||||
$SQL = "select view_dropdowns.*
|
||||
from view_dropdowns";
|
||||
|
||||
return $this->getTable("dropdowns", $SQL);
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Return a Dropdowntype Object
|
||||
// ============================
|
||||
|
||||
public function getDropdowntype($dropdowntype_serial = 0) {
|
||||
|
||||
$SQL = "select view_dropdowntypes.*
|
||||
from view_dropdowntypes
|
||||
where dropdowntype_serial = {$dropdowntype_serial}";
|
||||
|
||||
return $this->getTable("dropdowntypes", $SQL);
|
||||
}
|
||||
|
||||
// =============================
|
||||
// Return a Dropdowntypes Object
|
||||
// =============================
|
||||
|
||||
public function getDropdowntypes() {
|
||||
|
||||
$SQL = "select view_dropdowntypes.*
|
||||
from view_dropdowntypes";
|
||||
|
||||
return $this->getTable("dropdowntypes", $SQL);
|
||||
}
|
||||
|
||||
// ==================================
|
||||
// Return a Dropdowntypes Page Object
|
||||
// ==================================
|
||||
|
||||
public function getDropdowntypesPage() {
|
||||
|
||||
// Find Criteria
|
||||
|
||||
$find_dropdowntype = filter_input(INPUT_POST, "find_dropdowntype") ?: "";
|
||||
$find_words = $this->sanitizeString($find_dropdowntype);
|
||||
|
||||
// Show Per Page
|
||||
|
||||
$this->pagination_size = filter_input(INPUT_POST, "users_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
||||
|
||||
// Record Count
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "select count(*) as count
|
||||
from view_dropdowntypes
|
||||
where (dropdowntype_name regexp :dropdowntype_name
|
||||
or dropdowntype_title regexp :dropdowntype_title
|
||||
or dropdowntype_table regexp :dropdowntype_table
|
||||
or dropdowntype_column regexp :dropdowntype_column)";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":dropdowntype_name", $find_words);
|
||||
$statement->bindValue(":dropdowntype_title", $find_words);
|
||||
$statement->bindValue(":dropdowntype_table", $find_words);
|
||||
$statement->bindValue(":dropdowntype_column", $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_dropdowntypes.*
|
||||
from view_dropdowntypes
|
||||
where (dropdowntype_name regexp :dropdowntype_name
|
||||
or dropdowntype_title regexp :dropdowntype_title
|
||||
or dropdowntype_table regexp :dropdowntype_table
|
||||
or dropdowntype_column regexp :dropdowntype_column)
|
||||
limit {$this->pagination_size}
|
||||
offset {$offset}";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":dropdowntype_name", $find_words);
|
||||
$statement->bindValue(":dropdowntype_title", $find_words);
|
||||
$statement->bindValue(":dropdowntype_table", $find_words);
|
||||
$statement->bindValue(":dropdowntype_column", $find_words);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$dropdowntypes = $this->getTableXML("dropdowntypes", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
|
||||
$dropdowntypes->addAttribute("count", $count);
|
||||
$dropdowntypes->addAttribute("start", $start);
|
||||
$dropdowntypes->addAttribute("end", $end);
|
||||
$dropdowntypes->addAttribute("page", $this->pagination_page);
|
||||
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $dropdowntypes;
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Setup Dropdowns
|
||||
// ===============
|
||||
|
||||
public function setupDropdowns() {
|
||||
|
||||
$dropdowntypes = $this->getDropdowntypes();
|
||||
$dropdowns = $this->getDropdowns();
|
||||
|
||||
$XML = $this->mergeXML($dropdowntypes, "<XML/>");
|
||||
$XML = $this->mergeXML($dropdowns, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("setupDropdowns"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
// ===================
|
||||
// Setup Dropdowntypes
|
||||
// ===================
|
||||
|
||||
public function setupDropdowntypes() {
|
||||
|
||||
$dropdowntypes = $this->getDropdowntypesPage();
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
$XML = $this->mergeXML($dropdowntypes, "<XML/>");
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("setupDropdowntypes"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Update Dropdown Active
|
||||
// ======================
|
||||
|
||||
public function updateDropdownActive() {
|
||||
|
||||
$dropdown_serial = filter_input(INPUT_POST, "dropdown_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$dropdown_checked = filter_input(INPUT_POST, "dropdown_checked", FILTER_VALIDATE_BOOLEAN) ?: false;
|
||||
|
||||
$SQL = "update dropdowns
|
||||
set dropdown_active = :dropdown_active,
|
||||
dropdown_changer = :dropdown_changer,
|
||||
dropdown_changed = :dropdown_changed
|
||||
where dropdown_serial = :dropdown_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":dropdown_serial", $dropdown_serial);
|
||||
$statement->bindValue(":dropdown_active", $dropdown_checked, PDO::PARAM_BOOL);
|
||||
$statement->bindValue(":dropdown_changer", $this->current_user_name);
|
||||
$statement->bindValue(":dropdown_changed", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Update Dropdown Default
|
||||
// =======================
|
||||
|
||||
public function updateDropdownDefault() {
|
||||
|
||||
$dropdown_serial = filter_input(INPUT_POST, "dropdown_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$dropdown_dropdowntype = filter_input(INPUT_POST, "dropdown_dropdowntype", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$dropdown_checked = filter_input(INPUT_POST, "dropdown_checked") ?: "false";
|
||||
|
||||
// Unset the Default for the Dropdown Type.
|
||||
|
||||
$SQL = "update dropdowns
|
||||
set dropdown_default = false
|
||||
where dropdown_dropdowntype = {$dropdown_dropdowntype}";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
|
||||
// Set the Default for the clicked Dropdown.
|
||||
|
||||
$SQL = "update dropdowns
|
||||
set dropdown_default = {$dropdown_checked}
|
||||
where dropdown_serial = {$dropdown_serial}";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
// ===========
|
||||
// Email Class
|
||||
// ===========
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
class Email extends Base {
|
||||
|
||||
// Variables.
|
||||
|
||||
private $current_user_name = "";
|
||||
private $current_user_email = "";
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct() {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
|
||||
$this->current_user_name = $_SESSION[self::USER_NAME] ?? "";
|
||||
$this->current_user_email = $_SESSION[self::USER_EMAIL] ?? "";
|
||||
}
|
||||
|
||||
// =============================
|
||||
// Email a new users credentials
|
||||
// =============================
|
||||
|
||||
public function emailNewUserCredentials($user, $password) {
|
||||
|
||||
if (!$user instanceof SimpleXMLElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare the email
|
||||
|
||||
$to = (string) $user->record->user_email;
|
||||
|
||||
$XSLParms['USER-TEMP-PASSWORD'] = $password;
|
||||
|
||||
$subject = "DEC International DMS - New User Credentials";
|
||||
$message = $this->applyXSL($user, $this->getXSL("emailNewUserCredentials"), $XSLParms);
|
||||
|
||||
// Send the Email
|
||||
$this->sendEmail($to, $subject, $message);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Email a users Password Reset Link
|
||||
// =================================
|
||||
|
||||
public function emailUserPasswordResetLink($user, $password) {
|
||||
|
||||
if (!$user instanceof SimpleXMLElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare the email.
|
||||
|
||||
$XSLParms['USER-TEMP-PASSWORD'] = $password;
|
||||
|
||||
$to = (string) $user->record->user_email;
|
||||
$subject = "DEC International DMS - Password Reset Request";
|
||||
$message = $this->applyXSL($user, $this->getXSL("emailPasswordResetLink"), $XSLParms);
|
||||
|
||||
// Send the Email
|
||||
$this->sendEmail($to, $subject, $message);
|
||||
}
|
||||
|
||||
// =======================================
|
||||
// Send an email with optional attachments
|
||||
// =======================================
|
||||
|
||||
public function sendEmail($to = "", $subject = "", $message = "", $attachments = "", $attachment_names = "unknown") {
|
||||
|
||||
if (empty($to) or empty($subject) or empty($message)) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$settings = $this->getSettings();
|
||||
|
||||
$SmtpHost = $settings->SmtpServer;
|
||||
$SmtpUsername = $settings->SmtpUserName;
|
||||
$SmtpPassword = $settings->SmtpPassword;
|
||||
$SmtpPort = $settings->SmtpPort;
|
||||
|
||||
$email = new PHPMailer(true);
|
||||
|
||||
// Only for development
|
||||
|
||||
$message = "<span style='font-family: Calibri, Arial, sans-serif;'>" . $message . "</span>";
|
||||
|
||||
try {
|
||||
|
||||
//Server settings
|
||||
$email->isSMTP();
|
||||
$email->Host = $SmtpHost;
|
||||
$email->SMTPAuth = true;
|
||||
$email->Username = $SmtpUsername; // Your Gmail address
|
||||
$email->Password = $SmtpPassword; // App password from Google
|
||||
// $email->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // or 'tls'
|
||||
$email->Port = $SmtpPort;
|
||||
|
||||
$email->isHTML(true);
|
||||
$email->SetFrom("info@onesourceits.com", "OneSource IT Solutions LLC");
|
||||
|
||||
if (is_array($to)) {
|
||||
foreach ($to as $address) {
|
||||
$address = trim(str_replace(" ", "", $address));
|
||||
if (empty($address)) {
|
||||
continue;
|
||||
}
|
||||
$email->addAddress($address);
|
||||
}
|
||||
} else {
|
||||
$email->addAddress($to);
|
||||
}
|
||||
|
||||
$email->Subject = $subject;
|
||||
$email->Body = $message;
|
||||
|
||||
if (is_array($attachments)) {
|
||||
foreach ($attachments as $index => $item) {
|
||||
if (!empty($item)) {
|
||||
$email->addStringAttachment($item, ($attachment_names[$index] ?? "unknown"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!empty($attachments)) {
|
||||
$email->addStringAttachment($attachments, $attachment_names);
|
||||
}
|
||||
}
|
||||
|
||||
$success = $email->Send();
|
||||
} catch (phpMailerException $e) {
|
||||
|
||||
(new Journal())->journalEntry($e->errorMessage());
|
||||
$success = false;
|
||||
} catch (Exception $e) {
|
||||
|
||||
(new Journal())->journalEntry($e->getMessage());
|
||||
$success = false;
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
// ==============================
|
||||
// Send an Error Email to Support
|
||||
// ==============================
|
||||
|
||||
public function sendErrorEmail($error_message = "", $error_file = "", $error_line = "") {
|
||||
|
||||
$settings = $this->getSettings();
|
||||
|
||||
$Environment = (string) $settings->Environment;
|
||||
$SupportEmail = (string) $settings->SupportEmail;
|
||||
|
||||
if ($Environment == "Development") {
|
||||
return;
|
||||
}
|
||||
|
||||
$application_name = self::APPLICATION_NAME;
|
||||
|
||||
$message = "";
|
||||
|
||||
$message .= "<p>An application error has occurred in the {$application_name} application.<br/><br/></p>";
|
||||
$message .= "<p>File: {$error_file}</p>";
|
||||
$message .= "<p>Line: {$error_line}</p>";
|
||||
$message .= "<p>Error: {$error_message}</p>";
|
||||
|
||||
$to = $SupportEmail;
|
||||
$subject = "{$application_name} Application Error";
|
||||
|
||||
$this->sendEmail($to, $subject, $message);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
// ============
|
||||
// Export Class
|
||||
// ============
|
||||
|
||||
class Export extends Base {
|
||||
|
||||
// Variables
|
||||
|
||||
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_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;
|
||||
}
|
||||
|
||||
// =============
|
||||
// Choose Export
|
||||
// =============
|
||||
|
||||
public function chooseExport() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$dropdowns = (new Dropdowns())->getDropdowns();
|
||||
|
||||
$XML = $this->mergeXML($dropdowns, "<XML/>");
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("chooseExport"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "run":
|
||||
|
||||
$process_date = filter_input(INPUT_POST, "export_processdate") ?: "";
|
||||
$accounting_period = filter_input(INPUT_POST, "export_accounting_period") ?: "";
|
||||
$export_type = filter_input(INPUT_POST, "export_type", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
// Format Dates
|
||||
|
||||
$process_date = ($process_date == "") ? null : date("Y-m-d", strtotime($process_date));
|
||||
|
||||
switch ($export_type) {
|
||||
|
||||
case "1": // ALL Export Types
|
||||
|
||||
break;
|
||||
|
||||
case "2": // Only Hunting & Fishing
|
||||
|
||||
(new HuntingAndFishing())->createHuntingAndFishingExport($process_date, $accounting_period);
|
||||
|
||||
break;
|
||||
|
||||
case "3": // Only PTAX
|
||||
|
||||
break;
|
||||
|
||||
case "4": // Only FRVIS
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Send Completion Notifications
|
||||
// $this->sendNotifications($workorder_serial);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ==================================
|
||||
// Send Work Order Notification Email
|
||||
// ==================================
|
||||
|
||||
public function sendNotifications($workorder_serial = 0) {
|
||||
|
||||
if (empty($workorder_serial)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$users = (new Users())->getUsers();
|
||||
$to = array();
|
||||
|
||||
foreach ($users as $user) {
|
||||
|
||||
$user_notifications = (integer) $user->user_notifications;
|
||||
$user_email = (string) $user->user_email;
|
||||
|
||||
if (($user_notifications == true) and (!(empty($user_email)))) {
|
||||
$to[] = $user_email;
|
||||
}
|
||||
}
|
||||
|
||||
$to = array_unique($to);
|
||||
|
||||
$pdf = (new PrintWorkOrder())->print($workorder_serial, "string");
|
||||
|
||||
if (count($to) > 0) {
|
||||
|
||||
$subject = "New ATLHousingReport Work Order";
|
||||
$body = "Attached is a new ATLHousingReport Work Order.";
|
||||
|
||||
(new Email())->sendEmail($to, $subject, $body, $pdf, "WorkOrder.pdf");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,397 @@
|
||||
<?php
|
||||
|
||||
// ============
|
||||
// Import Class
|
||||
// ============
|
||||
|
||||
class Import extends Base {
|
||||
|
||||
const UPLOADS_DIRECTORY = "uploads";
|
||||
|
||||
// Variables
|
||||
|
||||
private $current_user_serial = 0;
|
||||
private $current_user_id = "";
|
||||
private $current_user_name = "";
|
||||
private $current_user_email = "";
|
||||
|
||||
// =================
|
||||
// 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] ?? "";
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Upload CSV File
|
||||
// ===============
|
||||
|
||||
public function uploadCSVFile() {
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$content = $this->applyXSL("", $this->getXSL("uploadCSVFile"));
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "upload":
|
||||
|
||||
$XSLParms['UPLOAD_STATUS'] = "UPLOAD SUCCESSFUL";
|
||||
$environment = (string) $this->getSettings()->Environment ?: "Production";
|
||||
|
||||
if (empty($environment)) {
|
||||
$this->logError("Invalid Environment ({$environment}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$environment_directory = self::UPLOADS_DIRECTORY . "/{$environment}";
|
||||
|
||||
// Process the Attachment
|
||||
|
||||
if (!empty($_FILES)) {
|
||||
|
||||
if (!is_dir($environment_directory)) {
|
||||
mkdir($environment_directory);
|
||||
}
|
||||
|
||||
$tempname = $_FILES["csvfile"]["tmp_name"];
|
||||
$filename = $_FILES["csvfile"]["name"];
|
||||
|
||||
if (empty($tempname) or empty($filename)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!move_uploaded_file($tempname, "{$environment_directory}/{$filename}")) {
|
||||
$XSLParms['UPLOAD_STATUS'] = "UPLOAD FAILED";
|
||||
}
|
||||
}
|
||||
|
||||
$file_directory = "{$environment_directory}/{$filename}";
|
||||
|
||||
$this->parseCSVFile($file_directory);
|
||||
|
||||
$content = $this->applyXSL("", $this->getXSL("uploadMessage"), $XSLParms);
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ==============
|
||||
// Parse CSV File
|
||||
// ==============
|
||||
|
||||
public function parseCSVFile($file) {
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$csvfile = fopen($file, 'r');
|
||||
|
||||
$RecordCount = 0;
|
||||
|
||||
while (($data = fgetcsv($csvfile, 0, ",", '"', '\\')) !== FALSE) {
|
||||
|
||||
$PermitFactsId = $data[1];
|
||||
$EntryDate = $this->fixDate($data[2]);
|
||||
$PermitNumber = $data[4];
|
||||
$PermitDate = $this->fixDate($data[5]);
|
||||
$ProjectAddress = $data[7];
|
||||
$SubdivisionName = $data[8];
|
||||
$ProjectType = $data[9];
|
||||
$Company = substr($data[10], 0, 30);
|
||||
$Address = substr($data[11], 0, 30);
|
||||
$City = $data[12];
|
||||
$State = $data[13];
|
||||
$Zip = $data[14];
|
||||
$Phone = $data[15];
|
||||
$ProjectCity = $data[16];
|
||||
$ProjectState = $data[17];
|
||||
$Size = $data[18] ?: 0;
|
||||
$Units = $data[19];
|
||||
$BuildingType = $data[20];
|
||||
$Value = $data[21] ?: 0;
|
||||
$WorkType = $data[22];
|
||||
$County = $data[23];
|
||||
$Lot = $data[24];
|
||||
$DistrictLL = $data[25];
|
||||
$Ctl = $data[26];
|
||||
$OwnerName = substr($data[27], 0, 30);
|
||||
$OwnerAddress = substr($data[28], 0, 30);
|
||||
$OwnerCity = $data[29];
|
||||
$OwnerState = substr($data[30], 0, 2);
|
||||
$OwnerZip = $data[31];
|
||||
$OwnerPhone = $data[32];
|
||||
$YTDPermits = $data[33] ?: 0;
|
||||
$YTDValue = $data[34] ?: 0;
|
||||
$TwelveMonthPreviousPermits = $data[35] ?: 0;
|
||||
|
||||
$County = (new Counties())->getCountiesByName($County)->record->county_serial;
|
||||
|
||||
$SQL = "INSERT INTO rdis (
|
||||
rdi_permit_facts_id,
|
||||
rdi_entry_date,
|
||||
rdi_permit_number,
|
||||
rdi_permit_date,
|
||||
rdi_project_addr,
|
||||
rdi_sub_div_name,
|
||||
rdi_project_type,
|
||||
rdi_company,
|
||||
rdi_address,
|
||||
rdi_city,
|
||||
rdi_state,
|
||||
rdi_zip,
|
||||
rdi_phone,
|
||||
rdi_project_city,
|
||||
rdi_project_state,
|
||||
rdi_size,
|
||||
rdi_units,
|
||||
rdi_building_type,
|
||||
rdi_value,
|
||||
rdi_work_type,
|
||||
rdi_county,
|
||||
rdi_lot,
|
||||
rdi_dist_ll,
|
||||
rdi_ct1,
|
||||
rdi_owner_name,
|
||||
rdi_owner_address,
|
||||
rdi_owner_city,
|
||||
rdi_owner_state,
|
||||
rdi_owner_zip,
|
||||
rdi_owner_phone,
|
||||
rdi_ytd_permits,
|
||||
rdi_ytd_value,
|
||||
rdi_12mth_prev_permits )
|
||||
VALUES (
|
||||
:rdi_permit_facts_id,
|
||||
:rdi_entry_date,
|
||||
:rdi_permit_number,
|
||||
:rdi_permit_date,
|
||||
:rdi_project_addr,
|
||||
:rdi_sub_div_name,
|
||||
:rdi_project_type,
|
||||
:rdi_company,
|
||||
:rdi_address,
|
||||
:rdi_city,
|
||||
:rdi_state,
|
||||
:rdi_zip,
|
||||
:rdi_phone,
|
||||
:rdi_project_city,
|
||||
:rdi_project_state,
|
||||
:rdi_size,
|
||||
:rdi_units,
|
||||
:rdi_building_type,
|
||||
:rdi_value,
|
||||
:rdi_work_type,
|
||||
:rdi_county,
|
||||
:rdi_lot,
|
||||
:rdi_dist_ll,
|
||||
:rdi_ct1,
|
||||
:rdi_owner_name,
|
||||
:rdi_owner_address,
|
||||
:rdi_owner_city,
|
||||
:rdi_owner_state,
|
||||
:rdi_owner_zip,
|
||||
:rdi_owner_phone,
|
||||
:rdi_ytd_permits,
|
||||
:rdi_ytd_value,
|
||||
:rdi_12mth_prev_permits )";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":rdi_permit_facts_id", $PermitFactsId);
|
||||
$statement->bindValue(":rdi_permit_number", $PermitNumber);
|
||||
$statement->bindValue(":rdi_entry_date", $EntryDate);
|
||||
$statement->bindValue(":rdi_permit_date", $PermitDate);
|
||||
$statement->bindValue(":rdi_project_addr", $ProjectAddress);
|
||||
$statement->bindValue(":rdi_sub_div_name", $SubdivisionName);
|
||||
$statement->bindValue(":rdi_project_type", $ProjectType);
|
||||
$statement->bindValue(":rdi_company", $Company);
|
||||
$statement->bindValue(":rdi_address", $Address);
|
||||
$statement->bindValue(":rdi_city", $City);
|
||||
$statement->bindValue(":rdi_state", $State);
|
||||
$statement->bindValue(":rdi_zip", $Zip);
|
||||
$statement->bindValue(":rdi_phone", $Phone);
|
||||
$statement->bindValue(":rdi_project_city", $ProjectCity);
|
||||
$statement->bindValue(":rdi_project_state", $ProjectState);
|
||||
$statement->bindValue(":rdi_size", $Size);
|
||||
$statement->bindValue(":rdi_units", $Units);
|
||||
$statement->bindValue(":rdi_building_type", $BuildingType);
|
||||
$statement->bindValue(":rdi_value", $Value);
|
||||
$statement->bindValue(":rdi_work_type", $WorkType);
|
||||
$statement->bindValue(":rdi_county", $County);
|
||||
$statement->bindValue(":rdi_lot", $Lot);
|
||||
$statement->bindValue(":rdi_dist_ll", $DistrictLL);
|
||||
$statement->bindValue(":rdi_ct1", $Ctl);
|
||||
$statement->bindValue(":rdi_owner_name", $OwnerName);
|
||||
$statement->bindValue(":rdi_owner_address", $OwnerAddress);
|
||||
$statement->bindValue(":rdi_owner_city", $OwnerCity);
|
||||
$statement->bindValue(":rdi_owner_state", $OwnerState);
|
||||
$statement->bindValue(":rdi_owner_zip", $OwnerZip);
|
||||
$statement->bindValue(":rdi_owner_phone", $OwnerPhone);
|
||||
$statement->bindValue(":rdi_ytd_permits", $YTDPermits);
|
||||
$statement->bindValue(":rdi_ytd_value", $YTDValue);
|
||||
$statement->bindValue(":rdi_12mth_prev_permits", $TwelveMonthPreviousPermits);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$RecordCount++;
|
||||
}
|
||||
|
||||
// Run Updates on rdi joining 12 month tables
|
||||
|
||||
$this->update1();
|
||||
$this->update2();
|
||||
$this->update3();
|
||||
$this->update4();
|
||||
$this->update5();
|
||||
$this->update6();
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Return an Formatted Date
|
||||
// ========================
|
||||
|
||||
public function fixDate($givenDate) {
|
||||
|
||||
$formattedDate = date('Y-m-d', strtotime($givenDate));
|
||||
|
||||
return $formattedDate;
|
||||
}
|
||||
|
||||
// ========
|
||||
// Update 1
|
||||
// ========
|
||||
|
||||
public function update1() {
|
||||
|
||||
$sql = "UPDATE rdis AS r
|
||||
INNER JOIN vw_ytd_permits_by_builder_sf v_ytd
|
||||
ON r.rdi_company = v_ytd.company
|
||||
AND r.rdi_city = v_ytd.city
|
||||
AND r.rdi_state = v_ytd.state
|
||||
AND r.rdi_zip = v_ytd.zip
|
||||
SET r.rdi_ytd_permits = v_ytd.ytd_permits,
|
||||
r.rdi_ytd_value = v_ytd.ytd_value
|
||||
WHERE r.rdi_project_type
|
||||
LIKE 'SINGLE%'";
|
||||
|
||||
$this->executeSQL($sql);
|
||||
}
|
||||
|
||||
// ========
|
||||
// Update 2
|
||||
// ========
|
||||
|
||||
public function update2() {
|
||||
|
||||
$sql = "UPDATE rdis AS r
|
||||
LEFT JOIN vw_ytd_permits_by_builder_sf v_ytd
|
||||
ON r.rdi_company = v_ytd.company
|
||||
AND r.rdi_city = v_ytd.city
|
||||
AND r.rdi_state = v_ytd.state
|
||||
AND r.rdi_zip = v_ytd.zip
|
||||
SET r.rdi_ytd_permits = 0,
|
||||
r.rdi_ytd_value = 0
|
||||
WHERE v_ytd.company IS NULL
|
||||
AND r.rdi_project_type
|
||||
LIKE 'SINGLE%';";
|
||||
|
||||
$this->executeSQL($sql);
|
||||
}
|
||||
|
||||
// ========
|
||||
// Update 3
|
||||
// ========
|
||||
|
||||
public function update3() {
|
||||
|
||||
$sql = "UPDATE rdis AS r
|
||||
INNER JOIN vw_12mth_prev_permits_by_builder_sf v_12p
|
||||
on r.rdi_company = v_12p.company
|
||||
AND r.rdi_city = v_12p.city
|
||||
AND r.rdi_state = v_12p.state
|
||||
AND r.rdi_zip = v_12p.zip
|
||||
SET r.rdi_12mth_prev_permits = v_12p.12mth_prev_permits
|
||||
WHERE r.rdi_project_type
|
||||
LIKE 'SINGLE%';";
|
||||
|
||||
$this->executeSQL($sql);
|
||||
}
|
||||
|
||||
// ========
|
||||
// Update 4
|
||||
// ========
|
||||
|
||||
public function update4() {
|
||||
|
||||
$sql = "UPDATE rdis AS r
|
||||
INNER JOIN vw_ytd_permits_by_builder_mf v_ytd
|
||||
ON r.rdi_company = v_ytd.company
|
||||
AND r.rdi_city = v_ytd.city
|
||||
AND r.rdi_state = v_ytd.state
|
||||
AND r.rdi_zip = v_ytd.zip
|
||||
SET r.rdi_ytd_permits = v_ytd.ytd_permits,
|
||||
r.rdi_ytd_value = v_ytd.ytd_value
|
||||
WHERE r.rdi_project_type
|
||||
LIKE 'MULTI%';";
|
||||
|
||||
$this->executeSQL($sql);
|
||||
}
|
||||
|
||||
// ========
|
||||
// Update 5
|
||||
// ========
|
||||
|
||||
public function update5() {
|
||||
|
||||
$sql = "UPDATE rdis AS r
|
||||
LEFT JOIN vw_ytd_permits_by_builder_mf v_ytd
|
||||
ON r.rdi_company = v_ytd.company
|
||||
AND r.rdi_city = v_ytd.city
|
||||
AND r.rdi_state = v_ytd.state
|
||||
AND r.rdi_zip = v_ytd.zip
|
||||
SET r.rdi_ytd_permits = 0,
|
||||
r.rdi_ytd_value = 0
|
||||
WHERE v_ytd.company IS NULL
|
||||
AND r.rdi_project_type
|
||||
LIKE 'MULTI%';";
|
||||
|
||||
$this->executeSQL($sql);
|
||||
}
|
||||
|
||||
// ========
|
||||
// Update 6
|
||||
// ========
|
||||
|
||||
public function update6() {
|
||||
|
||||
$sql = "UPDATE rdis AS r
|
||||
INNER JOIN vw_12mth_prev_permits_by_builder_mf v_12p
|
||||
on r.rdi_company = v_12p.company
|
||||
AND r.rdi_city = v_12p.city
|
||||
AND r.rdi_state = v_12p.state
|
||||
AND r.rdi_zip = v_12p.zip
|
||||
SET r.rdi_12mth_prev_permits = v_12p.12mth_prev_permits
|
||||
WHERE r.rdi_project_type
|
||||
LIKE 'MULTI%';";
|
||||
|
||||
$this->executeSQL($sql);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
// =============
|
||||
// Journal Class
|
||||
// =============
|
||||
|
||||
class Journal extends Base {
|
||||
|
||||
// Variables.
|
||||
|
||||
private $current_user_id = "";
|
||||
private $current_user_name = "";
|
||||
private $current_user_email = "";
|
||||
|
||||
private $pagination_page = 1;
|
||||
private $pagination_size = 20;
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct() {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
|
||||
$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;
|
||||
|
||||
}
|
||||
|
||||
// =================
|
||||
// Clear the Journal
|
||||
// =================
|
||||
|
||||
public function clearJournal() {
|
||||
|
||||
$SQL = "truncate journal";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
|
||||
$this->journalEntry("Journal was Cleared.");
|
||||
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Return a Journal Object
|
||||
// =======================
|
||||
|
||||
public function getJournal($limit = 500) {
|
||||
|
||||
$SQL = "select journal.*,
|
||||
date_format(journal.journal_timestamp, '%Y-%m-%d %h:%i %p') as journal_timestamp_verbose
|
||||
from journal
|
||||
order by journal.journal_timestamp desc
|
||||
limit {$limit}";
|
||||
|
||||
return $this->getTable("journal", $SQL);
|
||||
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Return a Journal Page Object
|
||||
// ============================
|
||||
|
||||
public function getJournalPage() {
|
||||
|
||||
// Find Criteria
|
||||
|
||||
$find_journal = filter_input(INPUT_POST, "find_journal") ?: "";
|
||||
$find_words = $this->sanitizeString($find_journal);
|
||||
|
||||
// Show Per Page
|
||||
|
||||
$this->pagination_size = filter_input(INPUT_POST, "journals_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
||||
|
||||
// Record Count
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "select count(*) as count
|
||||
from view_journal
|
||||
where journal_timestamp regexp :journal_timestamp
|
||||
or journal_origin regexp :journal_origin
|
||||
or journal_ip regexp :journal_ip
|
||||
or journal_entry regexp :journal_entry";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":journal_timestamp", $find_words);
|
||||
$statement->bindValue(":journal_origin", $find_words);
|
||||
$statement->bindValue(":journal_ip", $find_words);
|
||||
$statement->bindValue(":journal_entry", $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_journal.*
|
||||
from view_journal
|
||||
where journal_timestamp regexp :journal_timestamp
|
||||
or journal_origin regexp :journal_origin
|
||||
or journal_ip regexp :journal_ip
|
||||
or journal_entry regexp :journal_entry
|
||||
limit {$this->pagination_size}
|
||||
offset {$offset}";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":journal_timestamp", $find_words);
|
||||
$statement->bindValue(":journal_origin", $find_words);
|
||||
$statement->bindValue(":journal_ip", $find_words);
|
||||
$statement->bindValue(":journal_entry", $find_words);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$journal = $this->getTableXML("journal", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
|
||||
$journal->addAttribute("count", $count);
|
||||
$journal->addAttribute("start", $start);
|
||||
$journal->addAttribute("end", $end);
|
||||
$journal->addAttribute("page", $this->pagination_page);
|
||||
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $journal;
|
||||
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Create a Journal Entry
|
||||
// ======================
|
||||
|
||||
public function journalEntry($journal_entry = "") {
|
||||
|
||||
if (empty($journal_entry)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$SQL = "insert into journal
|
||||
|
||||
( journal_origin,
|
||||
journal_ip,
|
||||
journal_entry )
|
||||
|
||||
VALUES ( :journal_origin,
|
||||
:journal_ip,
|
||||
:journal_entry )";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":journal_origin", $this->current_user_name);
|
||||
$statement->bindValue(":journal_ip", $_SERVER["REMOTE_ADDR"] ?? "");
|
||||
$statement->bindValue(":journal_entry", $journal_entry);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
}
|
||||
|
||||
// ============
|
||||
// View Journal
|
||||
// ============
|
||||
|
||||
public function viewJournal() {
|
||||
|
||||
$journal = $this->getJournalPage();
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
$XML = $this->mergeXML($journal, "<XML/>");
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("viewJournal"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
// =============
|
||||
// Metrics Class
|
||||
// =============
|
||||
|
||||
class Metrics extends Base {
|
||||
|
||||
// ==================
|
||||
// Class Constructor.
|
||||
// ==================
|
||||
|
||||
public function __construct() {
|
||||
|
||||
set_error_handler(array($this,"displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Return a Daily Work Order Metrics Object
|
||||
// ========================================
|
||||
|
||||
private function getDailyWorkOrderMetrics() {
|
||||
|
||||
$SQL = "select dayname(workorder_created) as day,
|
||||
count(*) as count
|
||||
from view_workorders
|
||||
where date(workorder_created) >= (date(now()) - interval 6 day)
|
||||
group by day
|
||||
order by workorder_created desc";
|
||||
|
||||
return $this->getTable("dailymetrics", $SQL);
|
||||
|
||||
}
|
||||
|
||||
// =====================================
|
||||
// Return a Monthly Call Metrics Object.
|
||||
// =====================================
|
||||
|
||||
private function getMonthlyWorkOrderMetrics() {
|
||||
|
||||
$SQL = "select monthname(workorder_created) as month,
|
||||
count(*) as count
|
||||
from view_workorders
|
||||
where date(workorder_created) >= (date(now()) - interval 6 month)
|
||||
group by month
|
||||
order by workorder_created desc";
|
||||
|
||||
return $this->getTable("monthlymetrics", $SQL);
|
||||
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Return a Weekly Work Order Metrics Object
|
||||
// =========================================
|
||||
|
||||
private function getWeeklyWorkOrderMetrics() {
|
||||
|
||||
$SQL = "select week(workorder_created) as week,
|
||||
count(*) as count
|
||||
from view_workorders
|
||||
where date(workorder_created) >= (date(now()) - interval 6 week)
|
||||
group by week
|
||||
order by workorder_created desc";
|
||||
|
||||
return $this->getTable("weeklymetrics", $SQL);
|
||||
|
||||
}
|
||||
|
||||
// =======================
|
||||
// View Work Order Metrics
|
||||
// =======================
|
||||
|
||||
public function viewWorkOrderMetrics() {
|
||||
|
||||
$dailymetrics = $this->getDailyWorkOrderMetrics();
|
||||
$weeklymetrics = $this->getWeeklyWorkOrderMetrics();
|
||||
$monthlymetrics = $this->getMonthlyWorkorderMetrics();
|
||||
|
||||
$XSLParms["DAILYMETRICS"] = $dailymetrics->asXML();
|
||||
$XSLParms["WEEKLYMETRICS"] = $weeklymetrics->asXML();
|
||||
$XSLParms["MONTHLYMETRICS"] = $monthlymetrics->asXML();
|
||||
|
||||
$content = $this->applyXSL("", $this->getXSL("viewWorkOrderMetrics"), $XSLParms);
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
exit();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
|
||||
// ===========
|
||||
// Notes Class
|
||||
// ===========
|
||||
|
||||
class Notes extends Base {
|
||||
|
||||
// Constants
|
||||
|
||||
const VALID_TYPES = array("User");
|
||||
|
||||
// Variables
|
||||
|
||||
private $current_user_id = "";
|
||||
private $current_user_name = "";
|
||||
private $current_user_email = "";
|
||||
|
||||
// =================
|
||||
// Class Constructor
|
||||
// =================
|
||||
|
||||
public function __construct() {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
|
||||
$this->current_user_id = $_SESSION[self::USER_ID] ?? "";
|
||||
$this->current_user_name = $_SESSION[self::USER_NAME] ?? "";
|
||||
$this->current_user_email = $_SESSION[self::USER_EMAIL] ?? "";
|
||||
}
|
||||
|
||||
// ========
|
||||
// Add Note
|
||||
// ========
|
||||
|
||||
public function addNote() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$note_type = filter_input(INPUT_POST, "note_type") ?: "";
|
||||
$note_reference = filter_input(INPUT_POST, "note_reference", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
if (!in_array($note_type, self::VALID_TYPES) or empty($note_reference)) {
|
||||
$this->logError("Invalid Note Type ({$note_type} or Reference {$note_reference} " . __METHOD__);
|
||||
}
|
||||
|
||||
$XSLParms["NOTE_TYPE"] = $note_type;
|
||||
$XSLParms["NOTE_REFERENCE"] = $note_reference;
|
||||
|
||||
$content = $this->applyXSL("", $this->getXSL("addNote"), $XSLParms);
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "add":
|
||||
|
||||
$note_type = filter_input(INPUT_POST, "note_type") ?: "";
|
||||
$note_reference = filter_input(INPUT_POST, "note_reference", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$note_text = filter_input(INPUT_POST, "note_text") ?: "";
|
||||
|
||||
$SQL = "insert into notes
|
||||
|
||||
( note_type,
|
||||
note_reference,
|
||||
note_text,
|
||||
note_origin )
|
||||
|
||||
VALUES ( :note_type,
|
||||
:note_reference,
|
||||
:note_text,
|
||||
:note_origin )";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":note_type", $note_type);
|
||||
$statement->bindValue(":note_reference", $note_reference);
|
||||
$statement->bindValue(":note_text", $note_text);
|
||||
$statement->bindValue(":note_origin", $this->current_user_name);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ===========
|
||||
// Delete Note
|
||||
// ===========
|
||||
|
||||
public function deleteNote() {
|
||||
|
||||
$note_serial = filter_input(INPUT_POST, "note_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$note = $this->getNote($note_serial);
|
||||
|
||||
if ($note->count() == 0) {
|
||||
$this->logError("Invalid Note ({$note_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "delete from notes
|
||||
where note_serial = {$note_serial}";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
}
|
||||
|
||||
// =========
|
||||
// Edit Note
|
||||
// =========
|
||||
|
||||
public function editNote() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$note_serial = filter_input(INPUT_POST, "note_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$note = $this->getNote($note_serial);
|
||||
|
||||
if ($note->count() == 0) {
|
||||
$this->logError("Invalid Note ({$note_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$XML = $this->mergeXML($note, "<XML/>");
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("editNote"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "update":
|
||||
|
||||
$note_serial = filter_input(INPUT_POST, "note_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$note_text = filter_input(INPUT_POST, "note_text") ?: "";
|
||||
|
||||
$SQL = "update notes
|
||||
set note_text = :note_text,
|
||||
note_origin = :note_origin
|
||||
where note_serial = :note_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":note_serial", $note_serial);
|
||||
$statement->bindValue(":note_text", $note_text);
|
||||
$statement->bindValue(":note_origin", $this->current_user_name);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ====================
|
||||
// Return a Note Object
|
||||
// ====================
|
||||
|
||||
public function getNote($note_serial = 0) {
|
||||
|
||||
$SQL = "select view_notes.*
|
||||
from view_notes
|
||||
where note_serial = {$note_serial}";
|
||||
|
||||
return $this->getTable("notes", $SQL);
|
||||
}
|
||||
|
||||
// =====================
|
||||
// Return a Notes Object
|
||||
// =====================
|
||||
|
||||
public function getNotes($note_type = "", $note_reference = 0) {
|
||||
|
||||
$SQL = "select view_notes.*
|
||||
from view_notes
|
||||
where note_type = '{$note_type}'
|
||||
and note_reference = {$note_reference}
|
||||
order by note_timestamp asc";
|
||||
|
||||
return $this->getTable("notes", $SQL);
|
||||
}
|
||||
|
||||
// =====================
|
||||
// Return a Notes Object
|
||||
// =====================
|
||||
|
||||
public function getAllNotes($note_reference = 0) {
|
||||
|
||||
$SQL = "select view_notes.*
|
||||
from view_notes
|
||||
where note_reference = {$note_reference}
|
||||
order by note_timestamp asc";
|
||||
|
||||
// $this->debug($SQL);
|
||||
|
||||
return $this->getTable("notes", $SQL);
|
||||
}
|
||||
|
||||
// ==============
|
||||
// Add Note Quick
|
||||
// ==============
|
||||
|
||||
public function addNoteQuick($note_type = "", $note_reference = 0, $note_text = "") {
|
||||
|
||||
$SQL = "insert into notes
|
||||
|
||||
( note_type,
|
||||
note_reference,
|
||||
note_text,
|
||||
note_origin )
|
||||
|
||||
VALUES ( :note_type,
|
||||
:note_reference,
|
||||
:note_text,
|
||||
:note_origin )";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":note_type", $note_type);
|
||||
$statement->bindValue(":note_reference", $note_reference);
|
||||
$statement->bindValue(":note_text", $note_text);
|
||||
$statement->bindValue(":note_origin", $this->current_user_name);
|
||||
|
||||
$statement->execute();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,340 @@
|
||||
<?php
|
||||
|
||||
class PermitsByBuilder 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;
|
||||
}
|
||||
|
||||
// ==============
|
||||
// Search Permits
|
||||
// ==============
|
||||
|
||||
public function searchPermits($subscription_serial = 0) {
|
||||
|
||||
$subscription_serial = filter_input(INPUT_POST, "subscription_serial") ?: $subscription_serial;
|
||||
|
||||
$subscription = (new Subscriptions())->getSubscription($subscription_serial);
|
||||
|
||||
$permit_area = $subscription->record->subscription_area;
|
||||
$projecttype = $subscription->record->subscription_projecttype;
|
||||
|
||||
$searchhistory = (new SearchHistory())->getUsersPreviousSearchParameters($this->current_user_serial, $subscription_serial);
|
||||
|
||||
// Update Search History Record
|
||||
if (empty($searchhistory)) {
|
||||
(new SearchHistory())->saveUserSearchParameters($_POST);
|
||||
} else {
|
||||
(new SearchHistory())->updateUserSearchParameters($_POST);
|
||||
}
|
||||
|
||||
$permits = $this->getPermits($permit_area, $projecttype);
|
||||
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
// Populate Entry Dates with what was searched for if provided or users entry dates if no entry dates were provided
|
||||
|
||||
$searchhistory->record->searchhistory_parameters->rdi_entry_start_date = $permits->record->rdi_entry_start_date;
|
||||
$searchhistory->record->searchhistory_parameters->rdi_entry_end_date = $permits->record->rdi_entry_end_date;
|
||||
|
||||
$XML = $this->mergeXML($permits, "<XML/>");
|
||||
$XML = $this->mergeXML($subscription, $XML);
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("searchPermitsByBuilder"));
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
// =====================
|
||||
// Search Permits Object
|
||||
// =====================
|
||||
|
||||
public function getPermits($permit_area, $projecttype) {
|
||||
|
||||
// Sanitize inputs
|
||||
$rdi_company = filter_input(INPUT_POST, "rdi_company") ?: "";
|
||||
$rdi_and_or = filter_input(INPUT_POST, "rdi_and_or") ?: "OR";
|
||||
$rdi_entry_start_date = filter_input(INPUT_POST, "rdi_entry_start_date") ?: "";
|
||||
$rdi_entry_end_date = filter_input(INPUT_POST, "rdi_entry_end_date") ?: "";
|
||||
$rdi_permit_start_date = filter_input(INPUT_POST, "rdi_permit_start_date") ?: "";
|
||||
$rdi_permit_end_date = filter_input(INPUT_POST, "rdi_permit_end_date") ?: "";
|
||||
$pagination = filter_input(INPUT_POST, "pagination") ?: "";
|
||||
|
||||
$rdi_entry_start_date = ($rdi_entry_start_date == "") ? null : date("Y-m-d", strtotime($rdi_entry_start_date));
|
||||
$rdi_entry_end_date = ($rdi_entry_end_date == "") ? null : date("Y-m-d", strtotime($rdi_entry_end_date));
|
||||
$rdi_permit_start_date = ($rdi_permit_start_date == "") ? null : date("Y-m-d", strtotime($rdi_permit_start_date));
|
||||
$rdi_permit_end_date = ($rdi_permit_end_date == "") ? null : date("Y-m-d", strtotime($rdi_permit_end_date));
|
||||
|
||||
// Validate AND/OR
|
||||
if (!in_array(strtoupper($rdi_and_or), ["AND", "OR"])) {
|
||||
$rdi_and_or = "OR";
|
||||
}
|
||||
|
||||
// Pagination settings
|
||||
$this->pagination_size = filter_input(INPUT_POST, "rdis_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
||||
$rdis_order_by = filter_input(INPUT_POST, "rdis_order_by") ?: "rdi_permit_number";
|
||||
$rdis_order_direction = strtoupper(filter_input(INPUT_POST, "rdis_order_direction") ?: "DESC");
|
||||
|
||||
// Ensure valid order by column
|
||||
$allowed_order_columns = ["rdi_permit_number", "rdi_entry_date", "rdi_permit_date", "rdi_company", "rdi_permit_count"];
|
||||
if (!in_array($rdis_order_by, $allowed_order_columns)) {
|
||||
$rdis_order_by = "rdi_permit_number";
|
||||
}
|
||||
|
||||
// Connect to DB
|
||||
$connection = $this->connect();
|
||||
|
||||
// === count QUERY ===
|
||||
$SQL = "select count(distinct rdi_company, rdi_address, rdi_city, rdi_state, rdi_zip, rdi_phone_verbose,
|
||||
rdi_ytd_permits, rdi_ytd_value, rdi_12mth_prev_permits) as totalcount
|
||||
from view_rdis r
|
||||
join counties c on r.rdi_county = c.county_serial
|
||||
where r.rdi_project_type = :rdi_project_type";
|
||||
|
||||
if ($permit_area != "All") {
|
||||
$SQL .= " and c.county_area = :permit_area";
|
||||
}
|
||||
|
||||
if (!empty($rdi_company)) {
|
||||
$SQL .= " and r.rdi_company REGEXP :rdi_company";
|
||||
}
|
||||
|
||||
if (!empty($rdi_entry_start_date)) {
|
||||
$SQL .= " $rdi_and_or (r.rdi_entry_date between :rdi_entry_start_date and :rdi_entry_end_date)";
|
||||
}
|
||||
|
||||
if (!empty($rdi_permit_start_date)) {
|
||||
$SQL .= " $rdi_and_or (r.rdi_permit_date between :rdi_permit_start_date and :rdi_permit_end_date)";
|
||||
}
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":rdi_project_type", $projecttype, PDO::PARAM_STR);
|
||||
|
||||
if ($permit_area != "All") {
|
||||
$statement->bindValue(":permit_area", $permit_area, PDO::PARAM_STR);
|
||||
}
|
||||
if (!empty($rdi_company)) {
|
||||
$statement->bindValue(":rdi_company", $rdi_company, PDO::PARAM_STR);
|
||||
}
|
||||
if (!empty($rdi_entry_start_date)) {
|
||||
$statement->bindValue(":rdi_entry_start_date", $rdi_entry_start_date);
|
||||
$statement->bindValue(":rdi_entry_end_date", $rdi_entry_end_date);
|
||||
}
|
||||
if (!empty($rdi_permit_start_date)) {
|
||||
$statement->bindValue(":rdi_permit_start_date", $rdi_permit_start_date);
|
||||
$statement->bindValue(":rdi_permit_end_date", $rdi_permit_end_date);
|
||||
}
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$count = $recordset ? (int) $recordset["totalcount"] : 0;
|
||||
|
||||
// === PAGINATION LOGIC ===
|
||||
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 = min($this->pagination_page + 1, ceil($count / $this->pagination_size));
|
||||
break;
|
||||
case "last": $this->pagination_page = (int) ceil($count / $this->pagination_size);
|
||||
break;
|
||||
}
|
||||
|
||||
$offset = max(0, ($this->pagination_page - 1) * $this->pagination_size);
|
||||
$start = $offset + 1;
|
||||
$end = min($count, $start + $this->pagination_size - 1);
|
||||
|
||||
// === DATA QUERY ===
|
||||
$SQL = "select r.rdi_serial, r.rdi_company, r.rdi_address, r.rdi_city, r.rdi_state, r.rdi_zip, r.rdi_phone_verbose,
|
||||
r.rdi_ytd_permits, r.rdi_ytd_value, r.rdi_12mth_prev_permits,
|
||||
count(*) as rdi_permit_count, SUM(r.rdi_value) as rdi_value_verbose,
|
||||
case
|
||||
when rdi_12mth_prev_permits is null or rdi_12mth_prev_permits = 0 then ''
|
||||
|
||||
/* your 75% rule: current is < 75% of last year */
|
||||
when (r.rdi_ytd_permits / rdi_12mth_prev_permits) < 0.75 then '='
|
||||
/* ±5% band */
|
||||
when ((r.rdi_ytd_permits - rdi_12mth_prev_permits) / rdi_12mth_prev_permits) >= 0.05 then 'up'
|
||||
when ((r.rdi_ytd_permits - rdi_12mth_prev_permits) / rdi_12mth_prev_permits) <= -0.05 then 'down'
|
||||
else '='
|
||||
end as permits_trend
|
||||
|
||||
from view_rdis r
|
||||
join counties c on r.rdi_county = c.county_serial
|
||||
where r.rdi_project_type = :rdi_project_type";
|
||||
|
||||
if ($permit_area != "All") {
|
||||
$SQL .= " and c.county_area = :permit_area";
|
||||
}
|
||||
if (!empty($rdi_company)) {
|
||||
$SQL .= " and r.rdi_company REGEXP :rdi_company";
|
||||
}
|
||||
if (!empty($rdi_entry_start_date)) {
|
||||
$SQL .= " $rdi_and_or (r.rdi_entry_date between :rdi_entry_start_date and :rdi_entry_end_date)";
|
||||
}
|
||||
if (!empty($rdi_permit_start_date)) {
|
||||
$SQL .= " $rdi_and_or (r.rdi_permit_date between :rdi_permit_start_date and :rdi_permit_end_date)";
|
||||
}
|
||||
|
||||
$SQL .= " group by r.rdi_company, r.rdi_address, r.rdi_city, r.rdi_state, r.rdi_zip, r.rdi_phone,
|
||||
r.rdi_ytd_permits, r.rdi_ytd_value, r.rdi_12mth_prev_permits
|
||||
order by $rdis_order_by $rdis_order_direction
|
||||
limit :limit
|
||||
offset :offset";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":rdi_project_type", $projecttype, PDO::PARAM_STR);
|
||||
|
||||
if ($permit_area != "All") {
|
||||
$statement->bindValue(":permit_area", $permit_area, PDO::PARAM_STR);
|
||||
}
|
||||
if (!empty($rdi_company)) {
|
||||
$statement->bindValue(":rdi_company", $rdi_company, PDO::PARAM_STR);
|
||||
}
|
||||
if (!empty($rdi_entry_start_date)) {
|
||||
$statement->bindValue(":rdi_entry_start_date", $rdi_entry_start_date);
|
||||
$statement->bindValue(":rdi_entry_end_date", $rdi_entry_end_date);
|
||||
}
|
||||
if (!empty($rdi_permit_start_date)) {
|
||||
$statement->bindValue(":rdi_permit_start_date", $rdi_permit_start_date);
|
||||
$statement->bindValue(":rdi_permit_end_date", $rdi_permit_end_date);
|
||||
}
|
||||
|
||||
$statement->bindValue(":limit", $this->pagination_size, PDO::PARAM_INT);
|
||||
$statement->bindValue(":offset", $offset, PDO::PARAM_INT);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$rdis = $this->getTableXML("rdis", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
$rdis->addAttribute("count", $count);
|
||||
$rdis->addAttribute("start", $start);
|
||||
$rdis->addAttribute("end", $end);
|
||||
$rdis->addAttribute("page", $this->pagination_page);
|
||||
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $rdis;
|
||||
}
|
||||
|
||||
// =============================
|
||||
// Fetch All Permits for Exports
|
||||
// =============================
|
||||
|
||||
public function getAllPermitsByBuilder($permit_area, $projecttype) {
|
||||
|
||||
// Connect to DB
|
||||
$connection = $this->connect();
|
||||
|
||||
// === count QUERY ===
|
||||
$SQL = "SELECT count(DISTINCT rdi_company, rdi_address, rdi_city, rdi_state, rdi_zip, rdi_phone_verbose,
|
||||
rdi_ytd_permits, rdi_ytd_value, rdi_12mth_prev_permits) AS count
|
||||
FROM view_rdis r
|
||||
JOIN counties c on r.rdi_county = c.county_serial
|
||||
WHERE r.rdi_project_type = :rdi_project_type";
|
||||
|
||||
if ($permit_area !== "All") {
|
||||
$SQL .= " and c.county_area = :permit_area";
|
||||
}
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":rdi_project_type", $projecttype, PDO::PARAM_STR);
|
||||
|
||||
if ($permit_area !== "All") {
|
||||
$statement->bindValue(":permit_area", $permit_area, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
$count = $recordset ? (int) $recordset["count"] : 0;
|
||||
|
||||
// === DATA QUERY ===
|
||||
$SQL = "SELECT r.rdi_company, r.rdi_address, r.rdi_city, r.rdi_state, r.rdi_zip, r.rdi_phone_verbose,
|
||||
r.rdi_ytd_permits, r.rdi_ytd_value, r.rdi_12mth_prev_permits,
|
||||
count(*) AS rdi_permit_count, SUM(r.rdi_value) AS rdi_value
|
||||
FROM view_rdis r
|
||||
JOIN counties c on r.rdi_county = c.county_serial
|
||||
WHERE r.rdi_project_type = :rdi_project_type";
|
||||
|
||||
if ($permit_area !== "All") {
|
||||
$SQL .= " and c.county_area = :permit_area";
|
||||
}
|
||||
|
||||
$SQL .= " group by r.rdi_company, r.rdi_address, r.rdi_city, r.rdi_state, r.rdi_zip, r.rdi_phone,
|
||||
r.rdi_ytd_permits, r.rdi_ytd_value, r.rdi_12mth_prev_permits";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":rdi_project_type", $projecttype, PDO::PARAM_STR);
|
||||
|
||||
if ($permit_area !== "All") {
|
||||
$statement->bindValue(":permit_area", $permit_area, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$rdis = $this->getTableXML("rdis", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
$rdis->addAttribute("count", $count);
|
||||
|
||||
return $rdis;
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Return a Permit Object
|
||||
// ======================
|
||||
|
||||
public function getSelectedPermits($permit_area, $projecttype, $permit_serial = 0) {
|
||||
|
||||
$SQL = "SELECT r.rdi_company, r.rdi_address, r.rdi_city, r.rdi_state, r.rdi_zip, r.rdi_phone_verbose,
|
||||
r.rdi_ytd_permits, r.rdi_ytd_value, r.rdi_12mth_prev_permits,
|
||||
count(*) AS rdi_permit_count, SUM(r.rdi_value) AS rdi_value
|
||||
FROM view_rdis r
|
||||
JOIN counties c on r.rdi_county = c.county_serial
|
||||
WHERE r.rdi_project_type = '{$projecttype}' ";
|
||||
|
||||
if ($permit_area !== "All") {
|
||||
$SQL .= " and c.county_area = '$permit_area'";
|
||||
}
|
||||
|
||||
$SQL .= " and rdi_serial in ({$permit_serial}) ";
|
||||
$SQL .= " group by r.rdi_company, r.rdi_address, r.rdi_city, r.rdi_state, r.rdi_zip, r.rdi_phone,
|
||||
r.rdi_ytd_permits, r.rdi_ytd_value, r.rdi_12mth_prev_permits";
|
||||
|
||||
return $this->getTable("permits", $SQL);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,533 @@
|
||||
<?php
|
||||
|
||||
class PermitsBySubdivision 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;
|
||||
}
|
||||
|
||||
// ==============
|
||||
// Search Permits
|
||||
// ==============
|
||||
|
||||
public function searchPermits($subscription_serial = 0) {
|
||||
|
||||
$subscription_serial = filter_input(INPUT_POST, "subscription_serial") ?: $subscription_serial;
|
||||
|
||||
$subscription = (new Subscriptions())->getSubscription($subscription_serial);
|
||||
|
||||
if ($subscription->count() == 0) {
|
||||
$this->logError("Invalid Subscription ({$subscription_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$permit_area = $subscription->record->subscription_area;
|
||||
$projecttype = $subscription->record->subscription_projecttype;
|
||||
|
||||
$permits = $this->getPermits($permit_area, $projecttype);
|
||||
|
||||
$counties = (new Counties())->getCountiesByArea($permit_area);
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
$XML = $this->mergeXML($permits, "<XML/>");
|
||||
$XML = $this->mergeXML($counties, $XML);
|
||||
$XML = $this->mergeXML($subscription, $XML);
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("searchPermitsBySubdivision"));
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
public function getPermits($permit_area, $projecttype) {
|
||||
|
||||
$rdi_county_raw = trim(filter_input(INPUT_POST, "rdi_county") ?: "");
|
||||
$rdi_and_or = trim(filter_input(INPUT_POST, "rdi_and_or") ?: "OR");
|
||||
$rdi_company = trim(filter_input(INPUT_POST, "rdi_company") ?: "");
|
||||
$rdi_sub_div_name = trim(filter_input(INPUT_POST, "rdi_sub_div_name") ?: "");
|
||||
$rdi_project_city = trim(filter_input(INPUT_POST, "rdi_project_city") ?: "");
|
||||
$rdi_project_addr = trim(filter_input(INPUT_POST, "rdi_project_addr") ?: "");
|
||||
|
||||
$rdi_entry_start_date = filter_input(INPUT_POST, "rdi_entry_start_date") ?: "";
|
||||
$rdi_entry_end_date = filter_input(INPUT_POST, "rdi_entry_end_date") ?: "";
|
||||
$rdi_permit_start_date = filter_input(INPUT_POST, "rdi_permit_start_date") ?: "";
|
||||
$rdi_permit_end_date = filter_input(INPUT_POST, "rdi_permit_end_date") ?: "";
|
||||
|
||||
$pagination = filter_input(INPUT_POST, "pagination") ?: "";
|
||||
|
||||
// Normalize dates to Y-m-d or null
|
||||
$rdi_entry_start_date = ($rdi_entry_start_date === "") ? null : date("Y-m-d", strtotime($rdi_entry_start_date));
|
||||
$rdi_entry_end_date = ($rdi_entry_end_date === "") ? null : date("Y-m-d", strtotime($rdi_entry_end_date));
|
||||
$rdi_permit_start_date = ($rdi_permit_start_date === "") ? null : date("Y-m-d", strtotime($rdi_permit_start_date));
|
||||
$rdi_permit_end_date = ($rdi_permit_end_date === "") ? null : date("Y-m-d", strtotime($rdi_permit_end_date));
|
||||
|
||||
// Validate AND/OR
|
||||
if (!in_array(strtoupper($rdi_and_or), ["AND", "OR"], true)) {
|
||||
$rdi_and_or = "OR";
|
||||
}
|
||||
|
||||
// Pagination / ordering
|
||||
$this->pagination_size = filter_input(INPUT_POST, "rdis_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
||||
$rdis_order_by = filter_input(INPUT_POST, "rdis_order_by") ?: "rdi_permit_number";
|
||||
$rdis_order_direction = filter_input(INPUT_POST, "rdis_order_direction" ?? "DESC");
|
||||
|
||||
$allowed_order_columns = [
|
||||
"rdi_permit_number",
|
||||
"rdi_county", "rdi_sub_div_name", "rdi_project_addr", "rdi_city",
|
||||
"rdi_state", "rdi_zip", "rdi_company", "rdi_permit_date", "rdi_size", "rdi_value"
|
||||
];
|
||||
|
||||
if (!in_array($rdis_order_by, $allowed_order_columns, true)) {
|
||||
$rdis_order_by = "rdi_sub_div_name";
|
||||
}
|
||||
if (!in_array(strtoupper((string) $rdis_order_direction), ["ASC", "DESC"], true)) {
|
||||
$rdis_order_direction = "DESC";
|
||||
}
|
||||
|
||||
// Database Connection
|
||||
$connection = $this->connect();
|
||||
|
||||
// -------- County clause (shared) --------
|
||||
// Parse "1,12" -> [1,12], keep only digits, cast to int
|
||||
$countyIds = array_values(array_filter(
|
||||
array_map(
|
||||
fn($v) => ctype_digit(trim($v)) ? (int) trim($v) : null,
|
||||
explode(",", $rdi_county_raw)
|
||||
),
|
||||
fn($v) => $v !== null
|
||||
));
|
||||
|
||||
$countyClauseCount = "";
|
||||
$countyClauseData = "";
|
||||
$countyParams = []; // [':county_0' => 1, ':county_1' => 12]
|
||||
$bindArea = false;
|
||||
|
||||
if (!empty($countyIds)) {
|
||||
if (count($countyIds) === 1) {
|
||||
$countyClauseCount = " and rdi_county = :county_0";
|
||||
$countyClauseData = " and view_rdis.rdi_county = :county_0";
|
||||
$countyParams[':county_0'] = $countyIds[0];
|
||||
} else {
|
||||
$ph = [];
|
||||
foreach ($countyIds as $i => $id) {
|
||||
$k = ":county_$i";
|
||||
$ph[] = $k;
|
||||
$countyParams[$k] = $id;
|
||||
}
|
||||
$in = implode(",", $ph);
|
||||
$countyClauseCount = " and rdi_county in ($in)";
|
||||
$countyClauseData = " and view_rdis.rdi_county in ($in)";
|
||||
}
|
||||
} elseif ($permit_area != "All") {
|
||||
$countyClauseCount = " and rdi_county in (select county_serial from view_counties where county_area = :permit_area)";
|
||||
$countyClauseData = " and view_rdis.rdi_county in (select county_serial from view_counties where county_area = :permit_area)";
|
||||
$bindArea = true;
|
||||
} else {
|
||||
// No county/area filter -> omit entirely to keep the plan simple
|
||||
$countyClauseCount = "";
|
||||
$countyClauseData = "";
|
||||
}
|
||||
|
||||
// ===================== COUNT QUERY =====================
|
||||
$SQL = "select count(*) as count
|
||||
from view_rdis
|
||||
where rdi_project_type = :rdi_project_type
|
||||
$countyClauseCount ";
|
||||
|
||||
if (!empty($rdi_company)) {
|
||||
$SQL .= " and rdi_company like :rdi_company";
|
||||
}
|
||||
|
||||
if (!empty($rdi_sub_div_name)) {
|
||||
$SQL .= " and rdi_sub_div_name like :rdi_sub_div_name";
|
||||
}
|
||||
|
||||
if (!empty($rdi_project_city)) {
|
||||
$SQL .= " and rdi_project_city like :rdi_project_city";
|
||||
}
|
||||
|
||||
if (!empty($rdi_project_addr)) {
|
||||
$SQL .= " and rdi_project_addr like :rdi_project_addr";
|
||||
}
|
||||
|
||||
// group date conditions so $rdi_and_or applies between themcx
|
||||
|
||||
$dateConds = [];
|
||||
|
||||
if ($rdi_entry_start_date && $rdi_entry_end_date) {
|
||||
$dateConds[] = "(rdi_entry_date between :rdi_entry_start_date and :rdi_entry_end_date)";
|
||||
} elseif ($rdi_entry_start_date) {
|
||||
$dateConds[] = "(rdi_entry_date >= :rdi_entry_start_date)";
|
||||
}
|
||||
if ($rdi_permit_start_date && $rdi_permit_end_date) {
|
||||
$dateConds[] = "(rdi_permit_date between :rdi_permit_start_date and :rdi_permit_end_date)";
|
||||
} elseif ($rdi_permit_start_date) {
|
||||
$dateConds[] = "(rdi_permit_date >= :rdi_permit_start_date)";
|
||||
}
|
||||
if ($dateConds) {
|
||||
$SQL .= " and (" . implode(" $rdi_and_or ", $dateConds) . ")";
|
||||
}
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":rdi_project_type", $projecttype, PDO::PARAM_STR);
|
||||
|
||||
foreach ($countyParams as $k => $v) {
|
||||
$statement->bindValue($k, $v, PDO::PARAM_INT);
|
||||
}
|
||||
|
||||
if ($bindArea) {
|
||||
$statement->bindValue(":permit_area", $permit_area, PDO::PARAM_STR);
|
||||
}
|
||||
if (!empty($rdi_company)) {
|
||||
$statement->bindValue(":rdi_company", '%' . $rdi_company . '%', PDO::PARAM_STR);
|
||||
}
|
||||
if (!empty($rdi_sub_div_name)) {
|
||||
$statement->bindValue(":rdi_sub_div_name", '%' . $rdi_sub_div_name . '%', PDO::PARAM_STR);
|
||||
}
|
||||
if (!empty($rdi_project_city)) {
|
||||
$statement->bindValue(":rdi_project_city", '%' . $rdi_project_city . '%', PDO::PARAM_STR);
|
||||
}
|
||||
if (!empty($rdi_project_addr)) {
|
||||
$statement->bindValue(":rdi_project_addr", '%' . $rdi_project_addr . '%', PDO::PARAM_STR);
|
||||
}
|
||||
if ($rdi_entry_start_date) {
|
||||
$statement->bindValue(":rdi_entry_start_date", $rdi_entry_start_date);
|
||||
}
|
||||
if ($rdi_entry_end_date && str_contains($SQL, ":rdi_entry_end_date")) {
|
||||
$statement->bindValue(":rdi_entry_end_date", $rdi_entry_end_date);
|
||||
}
|
||||
if ($rdi_permit_start_date) {
|
||||
$statement->bindValue(":rdi_permit_start_date", $rdi_permit_start_date);
|
||||
}
|
||||
if ($rdi_permit_end_date && str_contains($SQL, ":rdi_permit_end_date")) {
|
||||
$statement->bindValue(":rdi_permit_end_date", $rdi_permit_end_date);
|
||||
}
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$count = $recordset ? (int) $recordset["count"] : 0;
|
||||
|
||||
// -------- 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 = min($this->pagination_page + 1, (int) ceil($count / $this->pagination_size));
|
||||
break;
|
||||
case "last": $this->pagination_page = (int) ceil($count / $this->pagination_size);
|
||||
break;
|
||||
}
|
||||
|
||||
$offset = max(0, ($this->pagination_page - 1) * $this->pagination_size);
|
||||
$start = $offset + 1;
|
||||
$end = min($count, $start + $this->pagination_size - 1);
|
||||
|
||||
// ===================== DATA QUERY =====================
|
||||
$SQL = "select view_rdis.*
|
||||
from view_rdis
|
||||
where view_rdis.rdi_project_type = :rdi_project_type
|
||||
$countyClauseData";
|
||||
|
||||
if (!empty($rdi_company)) {
|
||||
$SQL .= " and view_rdis.rdi_company like :rdi_company";
|
||||
}
|
||||
|
||||
if (!empty($rdi_sub_div_name)) {
|
||||
$SQL .= " and view_rdis.rdi_sub_div_name like :rdi_sub_div_name";
|
||||
}
|
||||
|
||||
if (!empty($rdi_project_city)) {
|
||||
$SQL .= " and view_rdis.rdi_project_city like :rdi_project_city";
|
||||
}
|
||||
|
||||
if (!empty($rdi_project_addr)) {
|
||||
$SQL .= " and view_rdis.rdi_project_addr like :rdi_project_addr";
|
||||
}
|
||||
|
||||
$dateConds = [];
|
||||
if ($rdi_entry_start_date && $rdi_entry_end_date) {
|
||||
$dateConds[] = "(view_rdis.rdi_entry_date between :rdi_entry_start_date and :rdi_entry_end_date)";
|
||||
} elseif ($rdi_entry_start_date) {
|
||||
$dateConds[] = "(view_rdis.rdi_entry_date >= :rdi_entry_start_date)";
|
||||
}
|
||||
if ($rdi_permit_start_date && $rdi_permit_end_date) {
|
||||
$dateConds[] = "(view_rdis.rdi_permit_date between :rdi_permit_start_date and :rdi_permit_end_date)";
|
||||
} elseif ($rdi_permit_start_date) {
|
||||
$dateConds[] = "(view_rdis.rdi_permit_date >= :rdi_permit_start_date)";
|
||||
}
|
||||
if ($dateConds) {
|
||||
$SQL .= " and (" . implode(" $rdi_and_or ", $dateConds) . ")";
|
||||
}
|
||||
|
||||
$SQL .= " order by $rdis_order_by $rdis_order_direction
|
||||
limit :limit
|
||||
offset :offset";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":rdi_project_type", $projecttype, PDO::PARAM_STR);
|
||||
|
||||
foreach ($countyParams as $k => $v) {
|
||||
$statement->bindValue($k, $v, PDO::PARAM_INT);
|
||||
}
|
||||
|
||||
if ($bindArea) {
|
||||
$statement->bindValue(":permit_area", $permit_area, PDO::PARAM_STR);
|
||||
}
|
||||
if (!empty($rdi_company)) {
|
||||
$statement->bindValue(":rdi_company", '%' . $rdi_company . '%', PDO::PARAM_STR);
|
||||
}
|
||||
if (!empty($rdi_sub_div_name)) {
|
||||
$statement->bindValue(":rdi_sub_div_name", '%' . $rdi_sub_div_name . '%', PDO::PARAM_STR);
|
||||
}
|
||||
if (!empty($rdi_project_city)) {
|
||||
$statement->bindValue(":rdi_project_city", '%' . $rdi_project_city . '%', PDO::PARAM_STR);
|
||||
}
|
||||
if (!empty($rdi_project_addr)) {
|
||||
$statement->bindValue(":rdi_project_addr", '%' . $rdi_project_addr . '%', PDO::PARAM_STR);
|
||||
}
|
||||
if ($rdi_entry_start_date) {
|
||||
$statement->bindValue(":rdi_entry_start_date", $rdi_entry_start_date);
|
||||
}
|
||||
if ($rdi_entry_end_date && str_contains($SQL, ":rdi_entry_end_date")) {
|
||||
$statement->bindValue(":rdi_entry_end_date", $rdi_entry_end_date);
|
||||
}
|
||||
if ($rdi_permit_start_date) {
|
||||
$statement->bindValue(":rdi_permit_start_date", $rdi_permit_start_date);
|
||||
}
|
||||
if ($rdi_permit_end_date && str_contains($SQL, ":rdi_permit_end_date")) {
|
||||
$statement->bindValue(":rdi_permit_end_date", $rdi_permit_end_date);
|
||||
}
|
||||
$statement->bindValue(":limit", $this->pagination_size, PDO::PARAM_INT);
|
||||
$statement->bindValue(":offset", $offset, PDO::PARAM_INT);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$rdis = $this->getTableXML("rdis", $statement);
|
||||
|
||||
foreach ($rdis as $rdi) {
|
||||
if (!empty($rdi->rdi_county)) {
|
||||
$county = (new Counties())->getCounty($rdi->rdi_county);
|
||||
$rdi->rdi_county_name_verbose = $county->record->county_name ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
// Pagination attributes
|
||||
$rdis->addAttribute("count", $count);
|
||||
$rdis->addAttribute("start", $start);
|
||||
$rdis->addAttribute("end", $end);
|
||||
$rdis->addAttribute("page", $this->pagination_page);
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $rdis;
|
||||
}
|
||||
|
||||
// =============================
|
||||
// Fetch All Permits for Exports
|
||||
// =============================
|
||||
|
||||
public function getAllPermitsBySubDivision($permit_area, $projecttype) {
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
// Count Query
|
||||
$SQL = "select count(*) as count
|
||||
from view_rdis r
|
||||
join counties c on r.rdi_county = c.county_serial
|
||||
where r.rdi_project_type = :rdi_project_type
|
||||
and r.rdi_county in
|
||||
(select county_serial
|
||||
from view_counties
|
||||
where county_area = :permit_area)";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":rdi_project_type", $projecttype, PDO::PARAM_STR);
|
||||
$statement->bindValue(":permit_area", $permit_area, PDO::PARAM_STR);
|
||||
|
||||
$statement->execute();
|
||||
$recordset = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
$count = $recordset ? (int) $recordset["count"] : 0;
|
||||
|
||||
// === DATA QUERY ===
|
||||
$SQL = "select r.*, c.county_name as rdi_county_name_verbose
|
||||
from view_rdis r
|
||||
join counties c on r.rdi_county = c.county_serial
|
||||
where r.rdi_project_type = :rdi_project_type
|
||||
and r.rdi_county in
|
||||
(select county_serial
|
||||
from view_counties
|
||||
where county_area = :permit_area)";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":rdi_project_type", $projecttype, PDO::PARAM_STR);
|
||||
$statement->bindValue(":permit_area", $permit_area, PDO::PARAM_STR);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$rdis = $this->getTableXML("rdis", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
$rdis->addAttribute("count", $count);
|
||||
|
||||
return $rdis;
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Return a Permit Object
|
||||
// ======================
|
||||
|
||||
public function getSelectedPermits($permits = array()) {
|
||||
|
||||
if (empty($permits)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$SQL = "select view_rdis.* from view_rdis where rdi_serial in ({$permits})";
|
||||
|
||||
return $this->getTable("permits", $SQL);
|
||||
}
|
||||
|
||||
// ================================
|
||||
// Return AutoComplete Names (ajax)
|
||||
// ================================
|
||||
|
||||
public function getAutoCompleteSubdivisions() {
|
||||
|
||||
$results = array();
|
||||
|
||||
$subdivision = filter_input(INPUT_GET, "rdi_sub_div_name") ?: "";
|
||||
$subdivision = trim(preg_replace("/\s+/", " ", $subdivision));
|
||||
$subdivision = preg_replace("/'+/", "'", $subdivision);
|
||||
$subdivision = preg_replace('/"+/', '"', $subdivision);
|
||||
$subdivision = str_replace("'", "''", $subdivision);
|
||||
|
||||
$SQL = "select distinct rdi_sub_div_name from view_rdis where rdi_sub_div_name like '%{$subdivision}%' order by rdi_sub_div_name limit 10 offset 0";
|
||||
|
||||
$matches = $this->getTable("subdivisions", $SQL);
|
||||
|
||||
foreach ($matches as $match) {
|
||||
$results[] = (string) $match->rdi_sub_div_name;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($results);
|
||||
exit();
|
||||
}
|
||||
|
||||
// ================================
|
||||
// Return AutoComplete Names (ajax)
|
||||
// ================================
|
||||
|
||||
public function getAutoCompleteCities() {
|
||||
|
||||
$results = array();
|
||||
|
||||
$city = filter_input(INPUT_GET, "rdi_project_city") ?: "";
|
||||
$city = trim(preg_replace("/\s+/", " ", $city));
|
||||
$city = preg_replace("/'+/", "'", $city);
|
||||
$city = preg_replace('/"+/', '"', $city);
|
||||
$city = str_replace("'", "''", $city);
|
||||
|
||||
$SQL = "select distinct rdi_project_city from view_rdis where rdi_project_city like '%{$city}%' order by rdi_project_city limit 10 offset 0";
|
||||
|
||||
$matches = $this->getTable("cities", $SQL);
|
||||
|
||||
foreach ($matches as $match) {
|
||||
$results[] = (string) $match->rdi_project_city;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($results);
|
||||
exit();
|
||||
}
|
||||
|
||||
// ================================
|
||||
// Return AutoComplete Names (ajax)
|
||||
// ================================
|
||||
|
||||
public function getAutoCompleteStreets() {
|
||||
|
||||
$results = array();
|
||||
|
||||
$street = filter_input(INPUT_GET, "rdi_project_addr") ?: "";
|
||||
$street = trim(preg_replace("/\s+/", " ", $street));
|
||||
$street = preg_replace("/'+/", "'", $street);
|
||||
$street = preg_replace('/"+/', '"', $street);
|
||||
$street = str_replace("'", "''", $street);
|
||||
|
||||
$SQL = "select distinct rdi_project_addr from view_rdis where rdi_project_addr like '%{$street}%' order by rdi_project_addr limit 10 offset 0";
|
||||
|
||||
$matches = $this->getTable("cities", $SQL);
|
||||
|
||||
foreach ($matches as $match) {
|
||||
$results[] = (string) $match->rdi_project_addr;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($results);
|
||||
exit();
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Return a Permit Object
|
||||
// ======================
|
||||
|
||||
public function getPermit($rdi_serial = 0) {
|
||||
|
||||
$SQL = "select view_rdis.* from view_rdis where rdi_serial = {$rdi_serial}";
|
||||
|
||||
return $this->getTable("permit", $SQL);
|
||||
}
|
||||
|
||||
// =============================
|
||||
// Return a Permit Record Dialog
|
||||
// =============================
|
||||
|
||||
public function getPermitRecordDialog() {
|
||||
|
||||
$rdi_serial = filter_input(INPUT_POST, "rdi_serial", FILTER_SANITIZE_NUMBER_INT) ?: 9;
|
||||
|
||||
$permit_record = $this->getPermit($rdi_serial);
|
||||
|
||||
$rdi_county = (new Counties())->getCounty($permit_record->record->rdi_county);
|
||||
$permit_record->record->rdi_county = $rdi_county->record->county_name;
|
||||
|
||||
$content = $this->applyXSL($permit_record, $this->getXSL("permitRecordDialog"));
|
||||
|
||||
if ($_SESSION[self::AJAX]) {
|
||||
echo $content;
|
||||
} else {
|
||||
$this->displayContentPage($content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,352 @@
|
||||
<?php
|
||||
|
||||
// ==============
|
||||
// Popovers Class
|
||||
// ==============
|
||||
|
||||
class Popovers extends Base {
|
||||
|
||||
// Variables.
|
||||
|
||||
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_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;
|
||||
}
|
||||
|
||||
// ===========
|
||||
// Add Popover
|
||||
// ===========
|
||||
|
||||
public function addPopover() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$content = $this->applyXSL("", $this->getXSL("addPopover"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "add":
|
||||
|
||||
$popover_name = filter_input(INPUT_POST, "popover_name") ?: "";
|
||||
$popover_title = filter_input(INPUT_POST, "popover_title") ?: "";
|
||||
$popover_placeholder = filter_input(INPUT_POST, "popover_placeholder") ?: "";
|
||||
$popover_text = filter_input(INPUT_POST, "popover_text") ?: "";
|
||||
|
||||
$SQL = "insert into popovers
|
||||
|
||||
( popover_name,
|
||||
popover_title,
|
||||
popover_placeholder,
|
||||
popover_text,
|
||||
popover_creator,
|
||||
popover_created )
|
||||
|
||||
VALUES ( :popover_name,
|
||||
:popover_title,
|
||||
:popover_placeholder,
|
||||
:popover_text,
|
||||
:popover_creator,
|
||||
:popover_created)";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":popover_name", $popover_name);
|
||||
$statement->bindValue(":popover_title", $popover_title);
|
||||
$statement->bindValue(":popover_placeholder", $popover_placeholder);
|
||||
$statement->bindValue(":popover_text", $popover_text);
|
||||
$statement->bindValue(":popover_creator", $this->current_user_name);
|
||||
$statement->bindValue(":popover_created", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ==============
|
||||
// Delete Popover
|
||||
// ==============
|
||||
|
||||
public function deletePopover() {
|
||||
|
||||
$popover_serial = filter_input(INPUT_POST, "popover_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$popover = $this->getPopover($popover_serial);
|
||||
|
||||
if ($popover->count() == 0) {
|
||||
$this->logError("Invalid Popover ({$popover_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "delete from popovers
|
||||
where popover_serial = {$popover_serial}";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
}
|
||||
|
||||
// ============
|
||||
// Edit Popover
|
||||
// ============
|
||||
|
||||
public function editPopover() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$popover_serial = filter_input(INPUT_POST, "popover_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$popover = $this->getPopover($popover_serial);
|
||||
|
||||
if ($popover->count() == 0) {
|
||||
$this->logError("Invalid Popover ({$popover_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$XML = $this->mergeXML($popover, "<XML/>");
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("editPopover"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "update":
|
||||
|
||||
$popover_serial = filter_input(INPUT_POST, "popover_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$popover_name = filter_input(INPUT_POST, "popover_name") ?: "";
|
||||
$popover_title = filter_input(INPUT_POST, "popover_title") ?: "";
|
||||
$popover_placeholder = filter_input(INPUT_POST, "popover_placeholder") ?: "";
|
||||
$popover_text = filter_input(INPUT_POST, "popover_text") ?: "";
|
||||
|
||||
$popover = $this->getPopover($popover_serial);
|
||||
|
||||
if ($popover->count() == 0) {
|
||||
$this->logError("Invalid Popover ({$popover_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "update popovers
|
||||
set popover_name = :popover_name,
|
||||
popover_title = :popover_title,
|
||||
popover_placeholder = :popover_placeholder,
|
||||
popover_text = :popover_text,
|
||||
popover_changer = :popover_changer,
|
||||
popover_changed = :popover_changed
|
||||
where popover_serial = :popover_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":popover_serial", $popover_serial);
|
||||
$statement->bindValue(":popover_name", $popover_name);
|
||||
$statement->bindValue(":popover_title", $popover_title);
|
||||
$statement->bindValue(":popover_placeholder", $popover_placeholder);
|
||||
$statement->bindValue(":popover_text", $popover_text);
|
||||
$statement->bindValue(":popover_changer", $this->current_user_name);
|
||||
$statement->bindValue(":popover_changed", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Return a Popover Object
|
||||
// =======================
|
||||
|
||||
public function getPopover($popover_serial = 0) {
|
||||
|
||||
$SQL = "select view_popovers.*
|
||||
from view_popovers
|
||||
where popover_serial = {$popover_serial}";
|
||||
|
||||
return $this->getTable("popovers", $SQL);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Return a Popover Object
|
||||
// =======================
|
||||
|
||||
public function getPopoverByName($popover_name = "") {
|
||||
|
||||
$SQL = "select view_popovers.*
|
||||
from view_popovers
|
||||
where popover_name = '{$popover_name}'";
|
||||
|
||||
return $this->getTable("popovers", $SQL);
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Return a Popovers Object
|
||||
// ========================
|
||||
|
||||
public function getPopovers() {
|
||||
|
||||
$SQL = "select view_popovers.*
|
||||
from view_popovers";
|
||||
|
||||
return $this->getTable("popovers", $SQL);
|
||||
}
|
||||
|
||||
// =============================
|
||||
// Return a Popovers Page Object
|
||||
// =============================
|
||||
|
||||
public function getPopoversPage() {
|
||||
|
||||
// Find Criteria
|
||||
|
||||
$find_popover = filter_input(INPUT_POST, "find_popover") ?: "";
|
||||
$find_words = $this->sanitizeString($find_popover);
|
||||
|
||||
// Show Per Page
|
||||
|
||||
$this->pagination_size = filter_input(INPUT_POST, "popovers_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
||||
|
||||
// Record Count
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "select count(*) as count
|
||||
from view_popovers
|
||||
where popover_name regexp :popover_name
|
||||
or popover_title regexp :popover_title";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":popover_name", $find_words);
|
||||
$statement->bindValue(":popover_title", $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_popovers.*
|
||||
from view_popovers
|
||||
where popover_name regexp :popover_name
|
||||
or popover_title regexp :popover_title
|
||||
limit {$this->pagination_size}
|
||||
offset {$offset}";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":popover_name", $find_words);
|
||||
$statement->bindValue(":popover_title", $find_words);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$popovers = $this->getTableXML("popovers", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
|
||||
$popovers->addAttribute("count", $count);
|
||||
$popovers->addAttribute("start", $start);
|
||||
$popovers->addAttribute("end", $end);
|
||||
$popovers->addAttribute("page", $this->pagination_page);
|
||||
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $popovers;
|
||||
}
|
||||
|
||||
// =============================
|
||||
// Determine if a Popover exists
|
||||
// =============================
|
||||
|
||||
public function popoverExists() {
|
||||
|
||||
$popover_serial = filter_input(INPUT_POST, "popover_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$popover_name = filter_input(INPUT_POST, "popover_name") ?: "";
|
||||
|
||||
$popover_name = strtolower($popover_name);
|
||||
|
||||
$SQL = "select popover_serial
|
||||
from view_popovers
|
||||
where popover_serial != :popover_serial
|
||||
and lower(popover_name) = :popover_name";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":popover_serial", $popover_serial);
|
||||
$statement->bindValue(":popover_name", $popover_name);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$popovers = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$exists = (count($popovers) > 0) ? true : false;
|
||||
|
||||
echo json_encode($exists);
|
||||
}
|
||||
|
||||
// ==============
|
||||
// Setup Popovers
|
||||
// ==============
|
||||
|
||||
public function setupPopovers() {
|
||||
|
||||
$popovers = $this->getPopoversPage();
|
||||
$XML = $this->mergeXML($popovers, "<XML/>");
|
||||
$content = $this->applyXSL($XML, $this->getXSL("setupPopovers"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
+549
@@ -0,0 +1,549 @@
|
||||
<?php
|
||||
|
||||
class RDI 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;
|
||||
}
|
||||
|
||||
// ==========
|
||||
// Manage RDI
|
||||
// ==========
|
||||
|
||||
public function manageRDI() {
|
||||
|
||||
$rdi = $this->getRDIPage();
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
$XML = $this->mergeXML($rdi, "<XML/>");
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("manageRDI"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
// =======
|
||||
// Add RDI
|
||||
// =======
|
||||
|
||||
public function addRDI() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$constants = $this->getConstants();
|
||||
$counties = (new Counties())->getCounties();
|
||||
|
||||
$XML = $this->mergeXML($constants, "<XML/>");
|
||||
$XML = $this->mergeXML($counties, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("addRDI"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "add":
|
||||
|
||||
$rdi_permit_facts_id = filter_input(INPUT_POST, "rdi_permit_facts_id", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_permit_number = filter_input(INPUT_POST, "rdi_permit_number") ?: '';
|
||||
$rdi_entry_date = filter_input(INPUT_POST, "rdi_entry_date") ?: '';
|
||||
$rdi_permit_date = filter_input(INPUT_POST, "rdi_permit_date") ?: '';
|
||||
$rdi_sub_div_name = filter_input(INPUT_POST, "rdi_sub_div_name") ?: '';
|
||||
$rdi_project_type = filter_input(INPUT_POST, "rdi_project_type") ?: '';
|
||||
$rdi_county = filter_input(INPUT_POST, "rdi_county") ?: '';
|
||||
$rdi_company = filter_input(INPUT_POST, "rdi_company") ?: '';
|
||||
$rdi_phone = filter_input(INPUT_POST, "rdi_phone") ?: '';
|
||||
$rdi_project_addr = filter_input(INPUT_POST, "rdi_project_addr") ?: '';
|
||||
$rdi_city = filter_input(INPUT_POST, "rdi_city") ?: '';
|
||||
$rdi_state = filter_input(INPUT_POST, "rdi_state") ?: '';
|
||||
$rdi_zip = filter_input(INPUT_POST, "rdi_zip", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_project_city = filter_input(INPUT_POST, "rdi_project_city") ?: '';
|
||||
$rdi_project_state = filter_input(INPUT_POST, "rdi_project_state") ?: '';
|
||||
$rdi_value = filter_input(INPUT_POST, "rdi_value", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_lot = filter_input(INPUT_POST, "rdi_lot", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_dist_ll = filter_input(INPUT_POST, "rdi_dist_ll", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_owner_name = filter_input(INPUT_POST, "rdi_owner_name") ?: '';
|
||||
$rdi_owner_phone = filter_input(INPUT_POST, "rdi_owner_phone", FILTER_SANITIZE_NUMBER_INT) ?: '';
|
||||
$rdi_owner_address = filter_input(INPUT_POST, "rdi_owner_address") ?: '';
|
||||
$rdi_owner_city = filter_input(INPUT_POST, "rdi_owner_city") ?: '';
|
||||
$rdi_owner_state = filter_input(INPUT_POST, "rdi_owner_state") ?: '';
|
||||
$rdi_owner_zip = filter_input(INPUT_POST, "rdi_owner_zip", FILTER_SANITIZE_NUMBER_INT) ?: '';
|
||||
$rdi_size = filter_input(INPUT_POST, "rdi_size", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_units = filter_input(INPUT_POST, "rdi_units", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_building_type = filter_input(INPUT_POST, "rdi_building_type", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_work_type = filter_input(INPUT_POST, "rdi_work_type", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_ct1 = filter_input(INPUT_POST, "rdi_ct1", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_ytd_permits = filter_input(INPUT_POST, "rdi_ytd_permits", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_ytd_value = filter_input(INPUT_POST, "rdi_ytd_value") ?: 0;
|
||||
$rdi_12mth_prev_permits = filter_input(INPUT_POST, "rdi_12mth_prev_permits", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$rdi_entry_date = date("Y-m-d", strtotime($rdi_entry_date));
|
||||
$rdi_permit_date = date("Y-m-d", strtotime($rdi_permit_date));
|
||||
$rdi_value = str_replace(",", "", $rdi_value);
|
||||
|
||||
$SQL = "INSERT INTO rdis (
|
||||
rdi_permit_facts_id,
|
||||
rdi_permit_number,
|
||||
rdi_entry_date,
|
||||
rdi_permit_date,
|
||||
rdi_sub_div_name,
|
||||
rdi_project_type,
|
||||
rdi_county,
|
||||
rdi_company,
|
||||
rdi_phone,
|
||||
rdi_project_addr,
|
||||
rdi_city,
|
||||
rdi_state,
|
||||
rdi_zip,
|
||||
rdi_project_city,
|
||||
rdi_project_state,
|
||||
rdi_value,
|
||||
rdi_lot,
|
||||
rdi_dist_ll,
|
||||
rdi_owner_name,
|
||||
rdi_owner_phone,
|
||||
rdi_owner_address,
|
||||
rdi_owner_city,
|
||||
rdi_owner_state,
|
||||
rdi_owner_zip,
|
||||
rdi_size,
|
||||
rdi_units,
|
||||
rdi_building_type,
|
||||
rdi_work_type,
|
||||
rdi_ct1,
|
||||
rdi_ytd_permits,
|
||||
rdi_ytd_value,
|
||||
rdi_12mth_prev_permits
|
||||
) VALUES (
|
||||
:rdi_permit_facts_id,
|
||||
:rdi_permit_number,
|
||||
:rdi_entry_date,
|
||||
:rdi_permit_date,
|
||||
:rdi_sub_div_name,
|
||||
:rdi_project_type,
|
||||
:rdi_county,
|
||||
:rdi_company,
|
||||
:rdi_phone,
|
||||
:rdi_project_addr,
|
||||
:rdi_city,
|
||||
:rdi_state,
|
||||
:rdi_zip,
|
||||
:rdi_project_city,
|
||||
:rdi_project_state,
|
||||
:rdi_value,
|
||||
:rdi_lot,
|
||||
:rdi_dist_ll,
|
||||
:rdi_owner_name,
|
||||
:rdi_owner_phone,
|
||||
:rdi_owner_address,
|
||||
:rdi_owner_city,
|
||||
:rdi_owner_state,
|
||||
:rdi_owner_zip,
|
||||
:rdi_size,
|
||||
:rdi_units,
|
||||
:rdi_building_type,
|
||||
:rdi_work_type,
|
||||
:rdi_ct1,
|
||||
:rdi_ytd_permits,
|
||||
:rdi_ytd_value,
|
||||
:rdi_12mth_prev_permits
|
||||
)";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":rdi_permit_facts_id", $rdi_permit_facts_id);
|
||||
$statement->bindValue(":rdi_permit_number", $rdi_permit_number);
|
||||
$statement->bindValue(":rdi_entry_date", $rdi_entry_date);
|
||||
$statement->bindValue(":rdi_permit_date", $rdi_permit_date);
|
||||
$statement->bindValue(":rdi_sub_div_name", $rdi_sub_div_name);
|
||||
$statement->bindValue(":rdi_project_type", $rdi_project_type);
|
||||
$statement->bindValue(":rdi_county", $rdi_county);
|
||||
$statement->bindValue(":rdi_company", $rdi_company);
|
||||
$statement->bindValue(":rdi_phone", $rdi_phone);
|
||||
$statement->bindValue(":rdi_project_addr", $rdi_project_addr);
|
||||
$statement->bindValue(":rdi_city", $rdi_city);
|
||||
$statement->bindValue(":rdi_state", $rdi_state);
|
||||
$statement->bindValue(":rdi_zip", $rdi_zip);
|
||||
$statement->bindValue(":rdi_project_city", $rdi_project_city);
|
||||
$statement->bindValue(":rdi_project_state", $rdi_project_state);
|
||||
$statement->bindValue(":rdi_value", $rdi_value);
|
||||
$statement->bindValue(":rdi_lot", $rdi_lot);
|
||||
$statement->bindValue(":rdi_dist_ll", $rdi_dist_ll);
|
||||
$statement->bindValue(":rdi_owner_name", $rdi_owner_name);
|
||||
$statement->bindValue(":rdi_owner_phone", $rdi_owner_phone);
|
||||
$statement->bindValue(":rdi_owner_address", $rdi_owner_address);
|
||||
$statement->bindValue(":rdi_owner_city", $rdi_owner_city);
|
||||
$statement->bindValue(":rdi_owner_state", $rdi_owner_state);
|
||||
$statement->bindValue(":rdi_owner_zip", $rdi_owner_zip);
|
||||
$statement->bindValue(":rdi_size", $rdi_size);
|
||||
$statement->bindValue(":rdi_units", $rdi_units);
|
||||
$statement->bindValue(":rdi_building_type", $rdi_building_type);
|
||||
$statement->bindValue(":rdi_work_type", $rdi_work_type);
|
||||
$statement->bindValue(":rdi_ct1", $rdi_ct1);
|
||||
$statement->bindValue(":rdi_ytd_permits", $rdi_ytd_permits);
|
||||
$statement->bindValue(":rdi_ytd_value", $rdi_ytd_value);
|
||||
$statement->bindValue(":rdi_12mth_prev_permits", $rdi_12mth_prev_permits);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ==========
|
||||
// Delete RDI
|
||||
// ==========
|
||||
|
||||
public function deleteRDI() {
|
||||
|
||||
$rdi_serial = filter_input(INPUT_POST, "rdi_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$rdi = $this->getRDI($rdi_serial);
|
||||
|
||||
if ($rdi->count() == 0) {
|
||||
$this->logError("Invalid RDI ({$rdi_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "delete from rdis
|
||||
where rdi_serial = {$rdi_serial}";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
}
|
||||
|
||||
// ==========
|
||||
// Edit a RDI
|
||||
// ==========
|
||||
|
||||
public function editRDI() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$rdi_serial = filter_input(INPUT_POST, "rdi_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$rdi = $this->getRDI($rdi_serial);
|
||||
|
||||
if ($rdi->count() == 0) {
|
||||
$this->logError("Invalid RDI ({$rdi_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$constants = $this->getConstants();
|
||||
$counties = (new Counties())->getCounties();
|
||||
|
||||
$XML = $this->mergeXML($rdi, "<XML/>");
|
||||
$XML = $this->mergeXML($constants, $XML);
|
||||
$XML = $this->mergeXML($counties, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("editRDI"));
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "update":
|
||||
|
||||
$rdi_serial = filter_input(INPUT_POST, "rdi_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_permit_facts_id = filter_input(INPUT_POST, "rdi_permit_facts_id", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_permit_number = filter_input(INPUT_POST, "rdi_permit_number") ?: '';
|
||||
$rdi_entry_date = filter_input(INPUT_POST, "rdi_entry_date") ?: '';
|
||||
$rdi_permit_date = filter_input(INPUT_POST, "rdi_permit_date") ?: '';
|
||||
$rdi_sub_div_name = filter_input(INPUT_POST, "rdi_sub_div_name") ?: '';
|
||||
$rdi_project_type = filter_input(INPUT_POST, "rdi_project_type") ?: '';
|
||||
$rdi_county = filter_input(INPUT_POST, "rdi_county") ?: '';
|
||||
$rdi_company = filter_input(INPUT_POST, "rdi_company") ?: '';
|
||||
$rdi_phone = filter_input(INPUT_POST, "rdi_phone") ?: '';
|
||||
$rdi_project_addr = filter_input(INPUT_POST, "rdi_project_addr") ?: '';
|
||||
$rdi_city = filter_input(INPUT_POST, "rdi_city") ?: '';
|
||||
$rdi_state = filter_input(INPUT_POST, "rdi_state") ?: '';
|
||||
$rdi_zip = filter_input(INPUT_POST, "rdi_zip", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_project_city = filter_input(INPUT_POST, "rdi_project_city") ?: '';
|
||||
$rdi_project_state = filter_input(INPUT_POST, "rdi_project_state") ?: '';
|
||||
$rdi_value = filter_input(INPUT_POST, "rdi_value", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_lot = filter_input(INPUT_POST, "rdi_lot", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_dist_ll = filter_input(INPUT_POST, "rdi_dist_ll", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_owner_name = filter_input(INPUT_POST, "rdi_owner_name") ?: '';
|
||||
$rdi_owner_phone = filter_input(INPUT_POST, "rdi_owner_phone", FILTER_SANITIZE_NUMBER_INT) ?: '';
|
||||
$rdi_owner_address = filter_input(INPUT_POST, "rdi_owner_address") ?: '';
|
||||
$rdi_owner_city = filter_input(INPUT_POST, "rdi_owner_city") ?: '';
|
||||
$rdi_owner_state = filter_input(INPUT_POST, "rdi_owner_state") ?: '';
|
||||
$rdi_owner_zip = filter_input(INPUT_POST, "rdi_owner_zip", FILTER_SANITIZE_NUMBER_INT) ?: '';
|
||||
$rdi_size = filter_input(INPUT_POST, "rdi_size", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_units = filter_input(INPUT_POST, "rdi_units", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_building_type = filter_input(INPUT_POST, "rdi_building_type", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_work_type = filter_input(INPUT_POST, "rdi_work_type", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_ct1 = filter_input(INPUT_POST, "rdi_ct1", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_ytd_permits = filter_input(INPUT_POST, "rdi_ytd_permits", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$rdi_ytd_value = filter_input(INPUT_POST, "rdi_ytd_value") ?: 0;
|
||||
$rdi_12mth_prev_permits = filter_input(INPUT_POST, "rdi_12mth_prev_permits", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$rdi_entry_date = date("Y-m-d", strtotime($rdi_entry_date));
|
||||
$rdi_permit_date = date("Y-m-d", strtotime($rdi_permit_date));
|
||||
$rdi_value = str_replace(",", "", $rdi_value);
|
||||
|
||||
// Verify the RDI
|
||||
$rdi = $this->getRDI($rdi_serial);
|
||||
|
||||
if ($rdi->count() == 0) {
|
||||
$this->logError("Invalid RDI ({$rdi_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "UPDATE rdis
|
||||
SET rdi_permit_facts_id = :rdi_permit_facts_id,
|
||||
rdi_permit_number = :rdi_permit_number,
|
||||
rdi_entry_date = :rdi_entry_date,
|
||||
rdi_permit_date = :rdi_permit_date,
|
||||
rdi_sub_div_name = :rdi_sub_div_name,
|
||||
rdi_project_type = :rdi_project_type,
|
||||
rdi_county = :rdi_county,
|
||||
rdi_company = :rdi_company,
|
||||
rdi_phone = :rdi_phone,
|
||||
rdi_project_addr = :rdi_project_addr,
|
||||
rdi_city = :rdi_city,
|
||||
rdi_state = :rdi_state,
|
||||
rdi_zip = :rdi_zip,
|
||||
rdi_project_city = :rdi_project_city,
|
||||
rdi_project_state = :rdi_project_state,
|
||||
rdi_value = :rdi_value,
|
||||
rdi_lot = :rdi_lot,
|
||||
rdi_dist_ll = :rdi_dist_ll,
|
||||
rdi_owner_name = :rdi_owner_name,
|
||||
rdi_owner_phone = :rdi_owner_phone,
|
||||
rdi_owner_address = :rdi_owner_address,
|
||||
rdi_owner_city = :rdi_owner_city,
|
||||
rdi_owner_state = :rdi_owner_state,
|
||||
rdi_owner_zip = :rdi_owner_zip,
|
||||
rdi_size = :rdi_size,
|
||||
rdi_units = :rdi_units,
|
||||
rdi_building_type = :rdi_building_type,
|
||||
rdi_work_type = :rdi_work_type,
|
||||
rdi_ct1 = :rdi_ct1,
|
||||
rdi_ytd_permits = :rdi_ytd_permits,
|
||||
rdi_ytd_value = :rdi_ytd_value,
|
||||
rdi_12mth_prev_permits = :rdi_12mth_prev_permits
|
||||
WHERE rdi_serial = :rdi_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":rdi_serial", $rdi_serial);
|
||||
$statement->bindValue(":rdi_permit_facts_id", $rdi_permit_facts_id);
|
||||
$statement->bindValue(":rdi_permit_number", $rdi_permit_number);
|
||||
$statement->bindValue(":rdi_entry_date", $rdi_entry_date);
|
||||
$statement->bindValue(":rdi_permit_date", $rdi_permit_date);
|
||||
$statement->bindValue(":rdi_sub_div_name", $rdi_sub_div_name);
|
||||
$statement->bindValue(":rdi_project_type", $rdi_project_type);
|
||||
$statement->bindValue(":rdi_county", $rdi_county);
|
||||
$statement->bindValue(":rdi_company", $rdi_company);
|
||||
$statement->bindValue(":rdi_phone", $rdi_phone);
|
||||
$statement->bindValue(":rdi_project_addr", $rdi_project_addr);
|
||||
$statement->bindValue(":rdi_city", $rdi_city);
|
||||
$statement->bindValue(":rdi_state", $rdi_state);
|
||||
$statement->bindValue(":rdi_zip", $rdi_zip);
|
||||
$statement->bindValue(":rdi_project_city", $rdi_project_city);
|
||||
$statement->bindValue(":rdi_project_state", $rdi_project_state);
|
||||
$statement->bindValue(":rdi_value", $rdi_value);
|
||||
$statement->bindValue(":rdi_lot", $rdi_lot);
|
||||
$statement->bindValue(":rdi_dist_ll", $rdi_dist_ll);
|
||||
$statement->bindValue(":rdi_owner_name", $rdi_owner_name);
|
||||
$statement->bindValue(":rdi_owner_phone", $rdi_owner_phone);
|
||||
$statement->bindValue(":rdi_owner_address", $rdi_owner_address);
|
||||
$statement->bindValue(":rdi_owner_city", $rdi_owner_city);
|
||||
$statement->bindValue(":rdi_owner_state", $rdi_owner_state);
|
||||
$statement->bindValue(":rdi_owner_zip", $rdi_owner_zip);
|
||||
$statement->bindValue(":rdi_size", $rdi_size);
|
||||
$statement->bindValue(":rdi_units", $rdi_units);
|
||||
$statement->bindValue(":rdi_building_type", $rdi_building_type);
|
||||
$statement->bindValue(":rdi_work_type", $rdi_work_type);
|
||||
$statement->bindValue(":rdi_ct1", $rdi_ct1);
|
||||
$statement->bindValue(":rdi_ytd_permits", $rdi_ytd_permits);
|
||||
$statement->bindValue(":rdi_ytd_value", $rdi_ytd_value);
|
||||
$statement->bindValue(":rdi_12mth_prev_permits", $rdi_12mth_prev_permits);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ================================
|
||||
// Return an Active RDI Object
|
||||
// ================================
|
||||
|
||||
public function getActiveRDI() {
|
||||
|
||||
$SQL = "select view_rdis.*
|
||||
from view_rdis
|
||||
where rdi_status is true";
|
||||
|
||||
return $this->getTable("rdis", $SQL);
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Return an RDI Object
|
||||
// ========================
|
||||
|
||||
public function getRDI($rdi_serial = 0) {
|
||||
|
||||
$SQL = "select view_rdis.*
|
||||
from view_rdis
|
||||
where rdi_serial = {$rdi_serial}";
|
||||
|
||||
return $this->getTable("rdis", $SQL);
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Return a RDI Object
|
||||
// ========================
|
||||
|
||||
public function getRDIs() {
|
||||
|
||||
$SQL = "select view_rdis.*
|
||||
from view_rdis";
|
||||
|
||||
return $this->getTable("rdis", $SQL);
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Return a RDI Page Object
|
||||
// ========================
|
||||
|
||||
public function getRDIPage() {
|
||||
|
||||
// Find Criteria
|
||||
|
||||
$find_rdi = filter_input(INPUT_POST, "find_rdi") ?: "";
|
||||
$find_rdi = $this->sanitizeString($find_rdi);
|
||||
|
||||
$this->pagination_size = filter_input(INPUT_POST, "rdis_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
||||
|
||||
$rdis_order_by = filter_input(INPUT_POST, "rdis_order_by") ?: "";
|
||||
$rdis_order_direction = filter_input(INPUT_POST, "rdis_order_direction") ?: "";
|
||||
|
||||
if ($rdis_order_by === "") {
|
||||
$orderby = "rdi_permit_number desc";
|
||||
} else {
|
||||
$orderby = $rdis_order_by . " " . $rdis_order_direction;
|
||||
}
|
||||
|
||||
// Record Count
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "select count(*) as count
|
||||
from view_rdis
|
||||
where rdi_permit_number regexp :rdi_permit_number
|
||||
or rdi_entry_date_verbose regexp :rdi_entry_date_verbose
|
||||
or rdi_permit_date_verbose regexp :rdi_permit_date_verbose
|
||||
or rdi_sub_div_name regexp :rdi_sub_div_name
|
||||
or rdi_project_type regexp :rdi_project_type";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":rdi_permit_number", $find_rdi);
|
||||
$statement->bindValue(":rdi_entry_date_verbose", $find_rdi);
|
||||
$statement->bindValue(":rdi_permit_date_verbose", $find_rdi);
|
||||
$statement->bindValue(":rdi_sub_div_name", $find_rdi);
|
||||
$statement->bindValue(":rdi_project_type", $find_rdi);
|
||||
|
||||
$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_rdis.*
|
||||
from view_rdis
|
||||
where rdi_permit_number regexp :rdi_permit_number
|
||||
or rdi_entry_date_verbose regexp :rdi_entry_date_verbose
|
||||
or rdi_permit_date_verbose regexp :rdi_permit_date_verbose
|
||||
or rdi_sub_div_name regexp :rdi_sub_div_name
|
||||
or rdi_project_type regexp :rdi_project_type
|
||||
order by {$orderby}
|
||||
limit {$this->pagination_size}
|
||||
offset {$offset}";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":rdi_permit_number", $find_rdi);
|
||||
$statement->bindValue(":rdi_entry_date_verbose", $find_rdi);
|
||||
$statement->bindValue(":rdi_permit_date_verbose", $find_rdi);
|
||||
$statement->bindValue(":rdi_sub_div_name", $find_rdi);
|
||||
$statement->bindValue(":rdi_project_type", $find_rdi);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$rdis = $this->getTableXML("rdis", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
|
||||
$rdis->addAttribute("count", $count);
|
||||
$rdis->addAttribute("start", $start);
|
||||
$rdis->addAttribute("end", $end);
|
||||
$rdis->addAttribute("page", $this->pagination_page);
|
||||
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $rdis;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,479 @@
|
||||
<?php
|
||||
|
||||
// =============
|
||||
// Reports Class
|
||||
// =============
|
||||
|
||||
class Reports extends Base {
|
||||
|
||||
// Variables.
|
||||
|
||||
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_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;
|
||||
}
|
||||
|
||||
// ==========
|
||||
// Add Report
|
||||
// ==========
|
||||
|
||||
public function addReport() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$constants = $this->getConstants();
|
||||
|
||||
$XML = $this->mergeXML($constants, "<XML/>");
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("addReport"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "add":
|
||||
|
||||
$report_name = filter_input(INPUT_POST, "report_name") ?: "";
|
||||
$report_class = filter_input(INPUT_POST, "report_class") ?: "";
|
||||
$report_type = filter_input(INPUT_POST, "report_type") ?: "Report";
|
||||
$report_description = filter_input(INPUT_POST, "report_description") ?: "";
|
||||
$report_target = filter_input(INPUT_POST, "report_target") ?: "";
|
||||
|
||||
$report_class = trim(preg_replace("/\s+/", " ", $report_class));
|
||||
|
||||
$SQL = "insert into reports
|
||||
|
||||
( report_class,
|
||||
report_type,
|
||||
report_name,
|
||||
report_description,
|
||||
report_target )
|
||||
|
||||
VALUES ( :report_class,
|
||||
:report_type,
|
||||
:report_name,
|
||||
:report_description,
|
||||
:report_target)";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":report_class", $report_class);
|
||||
$statement->bindValue(":report_type", $report_type);
|
||||
$statement->bindValue(":report_name", $report_name);
|
||||
$statement->bindValue(":report_description", $report_description);
|
||||
$statement->bindValue(":report_target", $report_target);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// =============
|
||||
// Delete Report
|
||||
// =============
|
||||
|
||||
public function deleteReport() {
|
||||
|
||||
$report_serial = filter_input(INPUT_POST, "report_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$reports = $this->getReport($report_serial);
|
||||
|
||||
if ($reports->count() == 0) {
|
||||
$this->logError("Invalid Report ({$report_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "delete from reports
|
||||
where report_serial = {$report_serial}";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
}
|
||||
|
||||
// ===========
|
||||
// Edit Report
|
||||
// ===========
|
||||
|
||||
public function editReport() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$report_serial = filter_input(INPUT_POST, "report_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$reports = $this->getReport($report_serial);
|
||||
|
||||
if ($reports->count() == 0) {
|
||||
$this->logError("Invalid Report ({$report_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$constants = $this->getConstants();
|
||||
|
||||
$XML = $this->mergeXML($reports, "<XML/>");
|
||||
$XML = $this->mergeXML($constants, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("editReport"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "update":
|
||||
|
||||
$report_serial = filter_input(INPUT_POST, "report_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$report_name = filter_input(INPUT_POST, "report_name") ?: "";
|
||||
$report_class = filter_input(INPUT_POST, "report_class") ?: "";
|
||||
$report_type = filter_input(INPUT_POST, "report_type") ?: "Report";
|
||||
$report_description = filter_input(INPUT_POST, "report_description") ?: "";
|
||||
$report_target = filter_input(INPUT_POST, "report_target") ?: "";
|
||||
|
||||
$report_class = trim(preg_replace("/\s+/", " ", $report_class));
|
||||
|
||||
$reports = $this->getReport($report_serial);
|
||||
|
||||
if ($reports->count() == 0) {
|
||||
$this->logError("Invalid Report ({$report_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "update reports
|
||||
set report_class = :report_class,
|
||||
report_type = :report_type,
|
||||
report_name = :report_name,
|
||||
report_description = :report_description,
|
||||
report_target = :report_target
|
||||
where report_serial = :report_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":report_serial", $report_serial);
|
||||
$statement->bindValue(":report_class", $report_class);
|
||||
$statement->bindValue(":report_type", $report_type);
|
||||
$statement->bindValue(":report_name", $report_name);
|
||||
$statement->bindValue(":report_description", $report_description);
|
||||
$statement->bindValue(":report_target", $report_target);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Return a Report Object
|
||||
// ======================
|
||||
|
||||
public function getReport($report_serial = 0) {
|
||||
|
||||
$SQL = "select view_reports.*
|
||||
from view_reports
|
||||
where report_serial = {$report_serial}";
|
||||
|
||||
return $this->getTable("reports", $SQL);
|
||||
}
|
||||
|
||||
// ===========================================
|
||||
// Return the report_serial for a report_class
|
||||
// ===========================================
|
||||
|
||||
public function getReportSerial($report_class = "") {
|
||||
|
||||
$SQL = "select view_reports.report_serial
|
||||
from view_reports
|
||||
where report_class = '{$report_class}'";
|
||||
|
||||
$reports = $this->getTable("reports", $SQL);
|
||||
|
||||
return (integer) ($reports->record->report_serial ?? 0);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Return a Reports Object
|
||||
// =======================
|
||||
|
||||
public function getReports() {
|
||||
|
||||
$SQL = "select view_reports.*
|
||||
from view_reports";
|
||||
|
||||
return $this->getTable("reports", $SQL);
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Return a Reports Page Object
|
||||
// ============================
|
||||
|
||||
public function getReportsPage() {
|
||||
|
||||
// Find Criteria
|
||||
|
||||
$find_report = filter_input(INPUT_POST, "find_report") ?: "";
|
||||
$find_words = $this->sanitizeString($find_report);
|
||||
|
||||
// $find_words = implode("|", explode(" ", $find_report));
|
||||
// Show Per Page
|
||||
|
||||
$this->pagination_size = filter_input(INPUT_POST, "reports_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
||||
|
||||
// Record Count
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "select count(*) as count
|
||||
from view_reports
|
||||
where (report_class regexp :report_class
|
||||
or report_name regexp :report_name
|
||||
or report_type regexp :report_type
|
||||
or report_description regexp :report_description)";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":report_class", $find_words);
|
||||
$statement->bindValue(":report_name", $find_words);
|
||||
$statement->bindValue(":report_type", $find_words);
|
||||
$statement->bindValue(":report_description", $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_reports.*
|
||||
from view_reports
|
||||
where (report_class regexp :report_class
|
||||
or report_name regexp :report_name
|
||||
or report_type regexp :report_type
|
||||
or report_description regexp :report_description)
|
||||
limit {$this->pagination_size}
|
||||
offset {$offset}";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":report_class", $find_words);
|
||||
$statement->bindValue(":report_name", $find_words);
|
||||
$statement->bindValue(":report_type", $find_words);
|
||||
$statement->bindValue(":report_description", $find_words);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$reports = $this->getTableXML("reports", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
|
||||
$reports->addAttribute("count", $count);
|
||||
$reports->addAttribute("start", $start);
|
||||
$reports->addAttribute("end", $end);
|
||||
$reports->addAttribute("page", $this->pagination_page);
|
||||
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $reports;
|
||||
}
|
||||
|
||||
// ==================================
|
||||
// Return a Select Report Page Object
|
||||
// ==================================
|
||||
|
||||
public function getSelectReportPage() {
|
||||
|
||||
// Find Criteria
|
||||
|
||||
$select_report = filter_input(INPUT_POST, "select_report") ?: "";
|
||||
$find_words = $this->sanitizeString($select_report);
|
||||
|
||||
// Show Per Page
|
||||
|
||||
$this->pagination_size = filter_input(INPUT_POST, "reports_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
||||
|
||||
// Record Count
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "select count(*) as count
|
||||
from view_reports
|
||||
where report_name regexp :report_name
|
||||
or report_description regexp :report_description";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":report_name", $find_words);
|
||||
$statement->bindValue(":report_description", $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_reports.*
|
||||
from view_reports
|
||||
where report_name regexp :report_name
|
||||
or report_description regexp :report_description
|
||||
limit {$this->pagination_size}
|
||||
offset {$offset}";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":report_name", $find_words);
|
||||
$statement->bindValue(":report_description", $find_words);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$reports = $this->getTableXML("reports", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
|
||||
$reports->addAttribute("count", $count);
|
||||
$reports->addAttribute("start", $start);
|
||||
$reports->addAttribute("end", $end);
|
||||
$reports->addAttribute("page", $this->pagination_page);
|
||||
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $reports;
|
||||
}
|
||||
|
||||
// ====================================
|
||||
// Determine if the Report Class Exists
|
||||
// ====================================
|
||||
|
||||
public function reportExists() {
|
||||
|
||||
$exists = false;
|
||||
|
||||
$report_serial = filter_input(INPUT_POST, "report_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$report_class = filter_input(INPUT_POST, "report_class") ?: "";
|
||||
|
||||
$report_class = trim(preg_replace("/\s+/", " ", $report_class));
|
||||
|
||||
$SQL = "select report_serial
|
||||
from view_reports
|
||||
where report_serial != :report_serial
|
||||
and lower(report_class) = :report_class";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":report_serial", $report_serial);
|
||||
$statement->bindValue(":report_class", $report_class);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$exists = (count($recordset) > 0) ? true : false;
|
||||
|
||||
echo json_encode($exists);
|
||||
}
|
||||
|
||||
// ================
|
||||
// Select a Report.
|
||||
// ================
|
||||
|
||||
public function selectReport() {
|
||||
|
||||
$reports = $this->getSelectReportPage();
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
$XML = $this->mergeXML($reports, "<XML/>");
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("selectReport"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
// =============
|
||||
// Setup Reports
|
||||
// =============
|
||||
|
||||
public function setupReports() {
|
||||
|
||||
$reports = $this->getReportsPage();
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
$XML = $this->mergeXML($reports, "<XML/>");
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("setupReports"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
class SearchHistory extends Base {
|
||||
|
||||
// Variables
|
||||
|
||||
private $current_user_serial = 0;
|
||||
private $current_user_id = "";
|
||||
private $current_user_name = "";
|
||||
private $current_user_email = "";
|
||||
|
||||
// =================
|
||||
// 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] ?? "";
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Save Users Search Parameters
|
||||
// ============================
|
||||
|
||||
public function saveUserSearchParameters($searchpayload) {
|
||||
|
||||
$user = $this->current_user_serial;
|
||||
$subscription_serial = $searchpayload['subscription_serial'];
|
||||
|
||||
switch ($subscription_serial) {
|
||||
|
||||
case 5:
|
||||
case 9:
|
||||
case 11:
|
||||
case 13:
|
||||
case 15:
|
||||
|
||||
$searchcriteria = json_encode(array_filter($searchpayload, fn($key) => str_starts_with($key, 'rdi_'), ARRAY_FILTER_USE_KEY));
|
||||
|
||||
break;
|
||||
|
||||
case 7:
|
||||
case 10:
|
||||
case 12:
|
||||
case 14:
|
||||
case 16:
|
||||
|
||||
$searchcriteria = json_encode(array_filter($searchpayload, fn($key) => str_starts_with($key, 'rdi_'), ARRAY_FILTER_USE_KEY));
|
||||
|
||||
break;
|
||||
|
||||
default :
|
||||
$this->debug("ERROR....");
|
||||
return;
|
||||
}
|
||||
|
||||
$SQL = "insert into searchhistories
|
||||
|
||||
( searchhistory_user,
|
||||
searchhistory_subscription,
|
||||
searchhistory_parameters,
|
||||
searchhistory_creator,
|
||||
searchhistory_created )
|
||||
|
||||
values ( :searchhistory_user,
|
||||
:searchhistory_subscription,
|
||||
:searchhistory_parameters,
|
||||
:searchhistory_creator,
|
||||
:searchhistory_created )";
|
||||
|
||||
$connection = $this->connect();
|
||||
$statement = $connection->prepare($SQL);
|
||||
$statement->bindValue(":searchhistory_user", $user);
|
||||
$statement->bindValue(":searchhistory_subscription", $subscription_serial);
|
||||
$statement->bindValue(":searchhistory_parameters", $searchcriteria);
|
||||
$statement->bindValue(":searchhistory_creator", $this->current_user_name);
|
||||
$statement->bindValue(":searchhistory_created", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Save Users Search Parameters
|
||||
// ============================
|
||||
|
||||
public function updateUserSearchParameters($searchpayload) {
|
||||
|
||||
$user = $this->current_user_serial;
|
||||
$subscription_serial = $searchpayload['subscription_serial'];
|
||||
|
||||
switch ($subscription_serial) {
|
||||
|
||||
case 5:
|
||||
case 9:
|
||||
case 11:
|
||||
case 13:
|
||||
case 15:
|
||||
|
||||
$searchcriteria = json_encode(array_filter($searchpayload, fn($key) => str_starts_with($key, 'rdi_'), ARRAY_FILTER_USE_KEY));
|
||||
|
||||
break;
|
||||
|
||||
case 7:
|
||||
case 10:
|
||||
case 12:
|
||||
case 14:
|
||||
case 16:
|
||||
|
||||
$searchcriteria = json_encode(array_filter($searchpayload, fn($key) => str_starts_with($key, 'rdi_'), ARRAY_FILTER_USE_KEY));
|
||||
|
||||
break;
|
||||
|
||||
default :
|
||||
return;
|
||||
}
|
||||
|
||||
$SQL = "update searchhistories
|
||||
set searchhistory_parameters = :searchhistory_parameters,
|
||||
searchhistory_changer = :searchhistory_changer,
|
||||
searchhistory_changed = :searchhistory_changed
|
||||
where searchhistory_user = :searchhistory_user
|
||||
and searchhistory_subscription = :searchhistory_subscription";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":searchhistory_parameters", $searchcriteria);
|
||||
$statement->bindValue(":searchhistory_changer", $this->current_user_name);
|
||||
$statement->bindValue(":searchhistory_changed", $this->getTimestamp());
|
||||
$statement->bindValue(":searchhistory_user", $user);
|
||||
$statement->bindValue(":searchhistory_subscription", $subscription_serial);
|
||||
|
||||
$statement->execute();
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Gets Users Search Parameters
|
||||
// ============================
|
||||
|
||||
public function getUsersPreviousSearchParameters($user, $subscription) {
|
||||
|
||||
$SQL = "select view_searchhistories.*
|
||||
from view_searchhistories
|
||||
where view_searchhistories.searchhistory_user = {$user}
|
||||
and view_searchhistories.searchhistory_subscription = {$subscription}";
|
||||
|
||||
$recordset = $this->getTable("searchhistory", $SQL);
|
||||
|
||||
return $this->materializeSearchHistoryParameters($recordset);
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Gets Users Search Parameters
|
||||
// ============================
|
||||
|
||||
public function materializeSearchHistoryParameters(SimpleXMLElement $SXE): SimpleXMLElement {
|
||||
|
||||
if (!isset($SXE->record)) {
|
||||
return $SXE;
|
||||
}
|
||||
|
||||
// Keys that should ALWAYS materialize as <key><id>..</id></key>
|
||||
// even if there is only one value.
|
||||
$multiSelectKeys = [
|
||||
'permitfact_project_city', 'permitfact_county', 'permitfact_project_type', 'permitfact_work_type', 'permitfact_building_type',
|
||||
'businessfact_city', 'businessfact_city', 'businessfact_county', 'businessfact_action', 'businessfact_business_class',
|
||||
'pzfact_project_city', 'pzfact_project_city', 'pzfact_project_city', 'pzfact_project_city'
|
||||
];
|
||||
|
||||
foreach ($SXE->record as $record) {
|
||||
|
||||
if (!isset($record->searchhistory_parameters)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$json = trim((string) $record->searchhistory_parameters);
|
||||
if ($json === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = json_decode($json, true);
|
||||
if (!is_array($data)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Clear existing text content
|
||||
$record->searchhistory_parameters[0] = null;
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
|
||||
$nodeName = preg_replace('/[^A-Za-z0-9_\-:.]/', '_', (string) $key);
|
||||
|
||||
$isMulti = in_array($key, $multiSelectKeys, true);
|
||||
|
||||
// If this is a multi-select key:
|
||||
// - Accept arrays (preferred)
|
||||
// - Accept CSV strings (legacy)
|
||||
// - Accept single scalar and wrap it in <id>
|
||||
if ($isMulti) {
|
||||
$parent = $record->searchhistory_parameters->addChild($nodeName);
|
||||
|
||||
if (is_array($value)) {
|
||||
$parts = $value;
|
||||
} else {
|
||||
$valueStr = trim((string) $value);
|
||||
|
||||
// empty -> create empty parent node and move on
|
||||
if ($valueStr === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// CSV or single
|
||||
$parts = (strpos($valueStr, ',') !== false) ? explode(',', $valueStr) : [$valueStr];
|
||||
}
|
||||
|
||||
$parts = array_values(array_filter(array_map('trim', $parts), fn($v) => $v !== ''));
|
||||
|
||||
foreach ($parts as $p) {
|
||||
$parent->addChild('id', htmlspecialchars($p, ENT_XML1 | ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Non-multi-select keys (same as your current behavior)
|
||||
if (is_string($value) && strpos($value, ',') !== false) {
|
||||
|
||||
$parent = $record->searchhistory_parameters->addChild($nodeName);
|
||||
|
||||
$parts = array_values(array_filter(array_map('trim', explode(',', $value)), fn($v) => $v !== ''));
|
||||
foreach ($parts as $p) {
|
||||
$parent->addChild('id', htmlspecialchars($p, ENT_XML1 | ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
} else {
|
||||
$record->searchhistory_parameters->addChild(
|
||||
$nodeName,
|
||||
htmlspecialchars((string) $value, ENT_XML1 | ENT_QUOTES, 'UTF-8')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $SXE;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,384 @@
|
||||
<?php
|
||||
|
||||
class Statuses 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;
|
||||
}
|
||||
|
||||
// ==========
|
||||
// Add Status
|
||||
// ==========
|
||||
|
||||
public function addStatus() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$content = $this->applyXSL("", $this->getXSL("addStatus"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "add":
|
||||
|
||||
$status_name = filter_input(INPUT_POST, "status_name") ?: "";
|
||||
$status_classes = filter_input(INPUT_POST, "status_classes") ?: "";
|
||||
$status_active = filter_input(INPUT_POST, "status_active", FILTER_VALIDATE_BOOLEAN) ?: false;
|
||||
|
||||
$SQL = "insert into statuses
|
||||
|
||||
( status_name,
|
||||
status_classes,
|
||||
status_active,
|
||||
status_creator,
|
||||
status_created )
|
||||
|
||||
VALUES ( :status_name,
|
||||
:status_classes,
|
||||
:status_active,
|
||||
:status_creator,
|
||||
:status_created )";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":status_name", $status_name);
|
||||
$statement->bindValue(":status_classes", $status_classes);
|
||||
$statement->bindValue(":status_active", $status_active, PDO::PARAM_BOOL);
|
||||
$statement->bindValue(":status_creator", $this->current_user_name);
|
||||
$statement->bindValue(":status_created", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// =============
|
||||
// Delete Status
|
||||
// =============
|
||||
|
||||
public function deleteStatus() {
|
||||
|
||||
$status_serial = filter_input(INPUT_POST, "status_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$status = $this->getStatus($status_serial);
|
||||
|
||||
if ($status->count() == 0) {
|
||||
$this->logError("Invalid Status ({$status_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "delete from statuses
|
||||
where status_serial = {$status_serial}";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Determine if a Status exists
|
||||
// ============================
|
||||
|
||||
public function statusExists() {
|
||||
|
||||
$status_serial = filter_input(INPUT_POST, "status_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$status_name = filter_input(INPUT_POST, "status_name") ?: "";
|
||||
|
||||
$SQL = "select status_serial
|
||||
from view_statuses
|
||||
where status_serial != :status_serial
|
||||
and lower(status_name) = :status_name";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":status_serial", $status_serial);
|
||||
$statement->bindValue(":status_name", strtolower($status_name));
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$exists = (count($recordset) > 0) ? true : false;
|
||||
|
||||
echo json_encode($exists);
|
||||
}
|
||||
|
||||
// ======================================
|
||||
// Determine if a Status is Active (AJAX)
|
||||
// ======================================
|
||||
|
||||
public function statusActive() {
|
||||
|
||||
$status_serial = filter_input(INPUT_POST, "status_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$active = false;
|
||||
|
||||
$SQL = "select workorder_status
|
||||
from workorders
|
||||
where workorder_status = {$status_serial}
|
||||
limit 1";
|
||||
|
||||
$workorders = $this->getTable("workorders", $SQL);
|
||||
|
||||
$active = ($workorders->count() > 0) ? true : false;
|
||||
|
||||
echo json_encode($active);
|
||||
}
|
||||
|
||||
// =============
|
||||
// Edit a Status
|
||||
// =============
|
||||
|
||||
public function editStatus() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$status_serial = filter_input(INPUT_POST, "status_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$status = $this->getStatus($status_serial);
|
||||
|
||||
if ($status->count() == 0) {
|
||||
$this->logError("Invalid Status ({$status_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$XML = $this->mergeXML($status, "<XML/>");
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("editStatus"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "update":
|
||||
|
||||
$status_serial = filter_input(INPUT_POST, "status_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$status_name = filter_input(INPUT_POST, "status_name") ?: "";
|
||||
$status_classes = filter_input(INPUT_POST, "status_classes") ?: "";
|
||||
$status_active = filter_input(INPUT_POST, "status_active", FILTER_VALIDATE_BOOLEAN) ?: false;
|
||||
$status_default = filter_input(INPUT_POST, "status_default", FILTER_VALIDATE_BOOLEAN) ?: false;
|
||||
|
||||
// Verify the Status
|
||||
|
||||
$status = $this->getStatus($status_serial);
|
||||
|
||||
if ($status->count() == 0) {
|
||||
$this->logError("Invalid Status ({$status_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "update statuses
|
||||
set status_name = :status_name,
|
||||
status_classes = :status_classes,
|
||||
status_active = :status_active,
|
||||
status_default = :status_default,
|
||||
status_changer = :status_changer,
|
||||
status_changed = :status_changed
|
||||
where status_serial = :status_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":status_serial", $status_serial);
|
||||
$statement->bindValue(":status_name", $status_name);
|
||||
$statement->bindValue(":status_classes", $status_classes);
|
||||
$statement->bindValue(":status_active", $status_active, PDO::PARAM_BOOL);
|
||||
$statement->bindValue(":status_default", $status_default, PDO::PARAM_BOOL);
|
||||
$statement->bindValue(":status_changer", $this->current_user_name);
|
||||
$statement->bindValue(":status_changed", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ================================
|
||||
// Return an Active Statuses Object
|
||||
// ================================
|
||||
|
||||
public function getActiveStatuses() {
|
||||
|
||||
$SQL = "select view_statuses.*
|
||||
from view_statuses
|
||||
where status_active is true";
|
||||
|
||||
return $this->getTable("statuses", $SQL);
|
||||
}
|
||||
|
||||
// -------------------------
|
||||
// Return the Default Status
|
||||
// -------------------------
|
||||
|
||||
public function getDefaultStatus() {
|
||||
|
||||
$SQL = "select status_serial
|
||||
from view_statuses
|
||||
where status_default is true";
|
||||
|
||||
return $this->getTable("statuses", $SQL);
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Return an Status Object
|
||||
// =======================
|
||||
|
||||
public function getStatus($status_serial = 0) {
|
||||
|
||||
$SQL = "select view_statuses.*
|
||||
from view_statuses
|
||||
where status_serial = {$status_serial}";
|
||||
|
||||
return $this->getTable("statuses", $SQL);
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Return a Statuss Object
|
||||
// ===========================
|
||||
|
||||
public function getStatuses() {
|
||||
|
||||
$SQL = "select view_statuses.*
|
||||
from view_statuses";
|
||||
|
||||
return $this->getTable("statuses", $SQL);
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Return a Statuss Page Object
|
||||
// ============================
|
||||
|
||||
public function getStatusesPage() {
|
||||
|
||||
// Find Criteria
|
||||
|
||||
$find_status = filter_input(INPUT_POST, "find_status") ?: "";
|
||||
$find_status = $this->sanitizeString($find_status);
|
||||
|
||||
$find_words = implode("|", explode(" ", $find_status));
|
||||
|
||||
// Record Count
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "select count(*) as count
|
||||
from view_statuses
|
||||
where status_name regexp :status_name
|
||||
or status_classes regexp :status_classes";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":status_name", $find_words);
|
||||
$statement->bindValue(":status_classes", $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_statuses.*
|
||||
from view_statuses
|
||||
where status_name regexp :status_name
|
||||
or status_classes regexp :status_classes
|
||||
order by status_name
|
||||
limit {$this->pagination_size}
|
||||
offset {$offset}";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":status_name", $find_words);
|
||||
$statement->bindValue(":status_classes", $find_words);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$statuses = $this->getTableXML("statuses", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
|
||||
$statuses->addAttribute("count", $count);
|
||||
$statuses->addAttribute("start", $start);
|
||||
$statuses->addAttribute("end", $end);
|
||||
$statuses->addAttribute("page", $this->pagination_page);
|
||||
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $statuses;
|
||||
}
|
||||
|
||||
// ==============
|
||||
// Setup Statuses
|
||||
// ==============
|
||||
|
||||
public function setupStatuses() {
|
||||
|
||||
$statuses = $this->getStatusesPage();
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
$XML = $this->mergeXML($statuses, "<XML/>");
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("setupStatuses"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,662 @@
|
||||
<?php
|
||||
|
||||
class Subscriptions 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 Subscriptions
|
||||
// ===================
|
||||
|
||||
public function setupSubscriptions() {
|
||||
|
||||
$subscriptions = $this->getSubscriptionsPage();
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
$XML = $this->mergeXML($subscriptions, "<XML/>");
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("setupSubscriptions"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Go To Subscription Driver
|
||||
// =========================
|
||||
|
||||
public function goToSubscription($subscription_serial = 0) {
|
||||
|
||||
$subscription_serial = (integer) filter_input(INPUT_POST, "subscription_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$subscription = $this->getSubscription($subscription_serial);
|
||||
|
||||
if ($subscription->count() === 0) {
|
||||
$this->logError("Invalid Subscription ({$subscription_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
switch ($subscription_serial) {
|
||||
|
||||
case 5:
|
||||
|
||||
$_SESSION['subscription_serial'] = $subscription_serial;
|
||||
|
||||
(new PermitsByBuilder())->searchPermits($subscription_serial);
|
||||
|
||||
break;
|
||||
|
||||
case 7:
|
||||
|
||||
$_SESSION['subscription_serial'] = $subscription_serial;
|
||||
|
||||
(new PermitsBySubdivision())->searchPermits($subscription_serial);
|
||||
|
||||
break;
|
||||
|
||||
case 9:
|
||||
|
||||
$project_type = "SingleFamily";
|
||||
$area = "South";
|
||||
|
||||
(new PermitsByBuilder())->searchPermits($project_type, $area);
|
||||
|
||||
break;
|
||||
|
||||
case 10:
|
||||
|
||||
$project_type = "SingleFamily";
|
||||
$area = "South";
|
||||
|
||||
(new PermitsBySubdivision())->searchPermits($project_type, $area);
|
||||
|
||||
break;
|
||||
|
||||
case 11:
|
||||
|
||||
$project_type = "SingleFamily";
|
||||
$area = "All";
|
||||
|
||||
(new PermitsByBuilder())->searchPermits($project_type, $area);
|
||||
|
||||
break;
|
||||
|
||||
case 12:
|
||||
|
||||
$project_type = "SingleFamily";
|
||||
$area = "All";
|
||||
|
||||
(new PermitsBySubdivision())->searchPermits($project_type, $area);
|
||||
|
||||
break;
|
||||
|
||||
case 13:
|
||||
|
||||
$project_type = "MultiFamily";
|
||||
$area = "South";
|
||||
|
||||
(new PermitsByBuilder())->searchPermits($project_type, $area);
|
||||
|
||||
break;
|
||||
|
||||
case 14:
|
||||
|
||||
$project_type = "MultiFamily";
|
||||
$area = "South";
|
||||
|
||||
(new PermitsBySubdivision())->searchPermits($project_type, $area);
|
||||
|
||||
break;
|
||||
|
||||
case 15:
|
||||
|
||||
$project_type = "MultiFamily";
|
||||
$area = "North";
|
||||
|
||||
(new PermitsByBuilder())->searchPermits($project_type, $area);
|
||||
|
||||
break;
|
||||
|
||||
case 16:
|
||||
|
||||
$project_type = "MultiFamily";
|
||||
$area = "North";
|
||||
|
||||
(new PermitsBySubdivision())->searchPermits($project_type, $area);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ================
|
||||
// Add Subscription
|
||||
// ================
|
||||
|
||||
public function addSubscription() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$constants = $this->getConstants();
|
||||
|
||||
$content = $this->applyXSL($constants, $this->getXSL("addSubscription"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "add":
|
||||
|
||||
$subscription_title = filter_input(INPUT_POST, "subscription_title") ?: "";
|
||||
$subscription_description = filter_input(INPUT_POST, "subscription_description") ?: "";
|
||||
$subscription_projecttype = filter_input(INPUT_POST, "subscription_projecttype") ?: "";
|
||||
$subscription_area = filter_input(INPUT_POST, "subscription_area") ?: "";
|
||||
|
||||
$SQL = "insert into subscriptions
|
||||
|
||||
( subscription_title,
|
||||
subscription_description,
|
||||
subscription_projecttype,
|
||||
subscription_area,
|
||||
subscription_creator,
|
||||
subscription_created )
|
||||
|
||||
VALUES ( :subscription_title,
|
||||
:subscription_description,
|
||||
:subscription_projecttype,
|
||||
:subscription_area,
|
||||
:subscription_creator,
|
||||
:subscription_created )";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":subscription_title", $subscription_title);
|
||||
$statement->bindValue(":subscription_description", $subscription_description);
|
||||
$statement->bindValue(":subscription_projecttype", $subscription_projecttype);
|
||||
$statement->bindValue(":subscription_area", $subscription_area);
|
||||
$statement->bindValue(":subscription_creator", $this->current_user_name);
|
||||
$statement->bindValue(":subscription_created", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// =================
|
||||
// Edit Subscription
|
||||
// =================
|
||||
|
||||
public function editSubscription() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$subscription_serial = (integer) filter_input(INPUT_POST, "subscription_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$subscription = $this->getSubscription($subscription_serial);
|
||||
|
||||
if ($subscription->count() === 0) {
|
||||
$this->logError("Invalid Subscription ({$subscription_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$constants = $this->getConstants();
|
||||
|
||||
$XML = $this->mergeXML($constants, "<XML/>");
|
||||
$XML = $this->mergeXML($subscription, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("editSubscription"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "update":
|
||||
|
||||
$subscription_serial = filter_input(INPUT_POST, "subscription_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$subscription_title = filter_input(INPUT_POST, "subscription_title") ?: "";
|
||||
$subscription_description = filter_input(INPUT_POST, "subscription_description") ?: "";
|
||||
$subscription_projecttype = filter_input(INPUT_POST, "subscription_projecttype") ?: "";
|
||||
$subscription_area = filter_input(INPUT_POST, "subscription_area") ?: "";
|
||||
|
||||
$subscriptions = $this->getSubscription($subscription_serial);
|
||||
|
||||
if ($subscriptions->count() == 0) {
|
||||
$this->logError("Invalid Subscription ({$subscription_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
// Update the Subscription
|
||||
|
||||
$SQL = "update subscriptions
|
||||
set subscription_title = :subscription_title,
|
||||
subscription_description = :subscription_description,
|
||||
subscription_projecttype = :subscription_projecttype,
|
||||
subscription_area = :subscription_area
|
||||
where subscription_serial = :subscription_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":subscription_serial", $subscription_serial);
|
||||
$statement->bindValue(":subscription_title", $subscription_title);
|
||||
$statement->bindValue(":subscription_description", $subscription_description);
|
||||
$statement->bindValue(":subscription_projecttype", $subscription_projecttype);
|
||||
$statement->bindValue(":subscription_area", $subscription_area);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ===================
|
||||
// Delete Subscription
|
||||
// ===================
|
||||
|
||||
public function deleteSubscription() {
|
||||
|
||||
$subscription_serial = filter_input(INPUT_POST, "subscription_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$subscription = $this->getSubscription($subscription_serial);
|
||||
|
||||
if ($subscription->count() == 0) {
|
||||
$this->logError("Invalid Subscription ({$subscription_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "delete from subscriptions
|
||||
where subscription_serial = {$subscription_serial}";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Add Subscription to User
|
||||
// ========================
|
||||
|
||||
public function addSubscriptionToUser() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$user_serial = filter_input(INPUT_POST, "user_reference", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$user = (new Users())->getUser($user_serial);
|
||||
$subscriptions = $this->getSubscriptions();
|
||||
|
||||
$XML = $this->mergeXML($user, "<XML/>");
|
||||
$XML = $this->mergeXML($subscriptions, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("addSubscriptionToUser"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "add":
|
||||
|
||||
$subscription_serial = filter_input(INPUT_POST, "subscription_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$user_serial = filter_input(INPUT_POST, "user_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$subscription_stop_date = filter_input(INPUT_POST, "subscription_stop_date") ?: "";
|
||||
|
||||
$subscription_stop_date = date("Y-m-d", strtotime($subscription_stop_date));
|
||||
|
||||
$SQL = "insert into usersubscriptions
|
||||
|
||||
( usersubscription_user_serial,
|
||||
usersubscription_subscription_serial,
|
||||
usersubscription_stop_date,
|
||||
usersubscription_origin,
|
||||
usersubscription_timestamp )
|
||||
|
||||
VALUES ( :usersubscription_user_serial,
|
||||
:usersubscription_subscription_serial,
|
||||
:usersubscription_stop_date,
|
||||
:usersubscription_origin,
|
||||
:usersubscription_timestamp )";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":usersubscription_user_serial", $user_serial);
|
||||
$statement->bindValue(":usersubscription_subscription_serial", $subscription_serial);
|
||||
$statement->bindValue(":usersubscription_stop_date", $subscription_stop_date);
|
||||
$statement->bindValue(":usersubscription_timestamp", $this->getTimestamp());
|
||||
$statement->bindValue(":usersubscription_origin", $this->current_user_name);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Edit a Users Subscription
|
||||
// =========================
|
||||
|
||||
public function editUsersSubscription() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$user_serial = filter_input(INPUT_POST, "user_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$usersubscription_serial = filter_input(INPUT_POST, "usersubscription_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$user = (new Users())->getUser($user_serial);
|
||||
$usersubscription = $this->getUsersSubscription($usersubscription_serial);
|
||||
$subscriptions = $this->getSubscriptions();
|
||||
|
||||
$XML = $this->mergeXML($user, "<XML/>");
|
||||
$XML = $this->mergeXML($usersubscription, $XML);
|
||||
$XML = $this->mergeXML($subscriptions, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("editUsersSubscription"));
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "update":
|
||||
|
||||
$subscription_serial = filter_input(INPUT_POST, "subscription_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$usersubscription_serial = filter_input(INPUT_POST, "usersubscription_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$subscription_stop_date = filter_input(INPUT_POST, "subscription_stop_date") ?: "";
|
||||
|
||||
$subscription_stop_date = date("Y-m-d", strtotime($subscription_stop_date));
|
||||
|
||||
$SQL = "update usersubscriptions
|
||||
set usersubscription_stop_date = :usersubscription_stop_date,
|
||||
usersubscription_subscription_serial = :usersubscription_subscription_serial,
|
||||
usersubscription_origin = :usersubscription_origin,
|
||||
usersubscription_timestamp = :usersubscription_timestamp
|
||||
where usersubscription_serial = :usersubscription_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":usersubscription_stop_date", $subscription_stop_date);
|
||||
$statement->bindValue(":usersubscription_subscription_serial", $subscription_serial);
|
||||
$statement->bindValue(":usersubscription_origin", $this->current_user_name);
|
||||
$statement->bindValue(":usersubscription_timestamp", $this->getTimestamp());
|
||||
$statement->bindValue(":usersubscription_serial", $usersubscription_serial);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Delete Users Subscription
|
||||
// =========================
|
||||
|
||||
public function deleteUsersSubscription() {
|
||||
|
||||
$usersubscription_serial = filter_input(INPUT_POST, "usersubscription_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$subscription = $this->getUsersSubscription($usersubscription_serial);
|
||||
|
||||
if ($subscription->count() == 0) {
|
||||
$this->logError("Invalid Subscription ({$usersubscription_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "delete from usersubscriptions
|
||||
where usersubscription_serial = {$usersubscription_serial}";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Return a Subscription Object
|
||||
// ============================
|
||||
|
||||
public function getSubscription($subscription_serial = 0) {
|
||||
|
||||
$SQL = "select view_subscriptions.*
|
||||
from view_subscriptions
|
||||
where subscription_serial = {$subscription_serial}";
|
||||
|
||||
return $this->getTable("subscriptions", $SQL);
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Return a Subscription Object
|
||||
// ============================
|
||||
|
||||
public function getSubscriptions() {
|
||||
|
||||
$SQL = "select view_subscriptions.*
|
||||
from view_subscriptions";
|
||||
|
||||
return $this->getTable("subscriptions", $SQL);
|
||||
}
|
||||
|
||||
// ==================================
|
||||
// Return a Subscriptions Page Object
|
||||
// ==================================
|
||||
|
||||
public function getSubscriptionsPage() {
|
||||
|
||||
// Find Criteria
|
||||
|
||||
$find_subscription = filter_input(INPUT_POST, "find_subscription") ?: "";
|
||||
$find_subscription = $this->sanitizeString($find_subscription);
|
||||
|
||||
$find_words = implode("|", explode(" ", $find_subscription));
|
||||
|
||||
// Record Count
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "select count(*) as count
|
||||
from view_subscriptions
|
||||
where subscription_title regexp :subscription_title
|
||||
or subscription_description regexp :subscription_description
|
||||
or subscription_projecttype regexp :subscription_projecttype
|
||||
or subscription_area regexp :subscription_area";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":subscription_title", $find_words);
|
||||
$statement->bindValue(":subscription_description", $find_words);
|
||||
$statement->bindValue(":subscription_projecttype", $find_words);
|
||||
$statement->bindValue(":subscription_area", $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_subscriptions.*
|
||||
from view_subscriptions
|
||||
where subscription_title regexp :subscription_title
|
||||
or subscription_description regexp :subscription_description
|
||||
or subscription_projecttype regexp :subscription_projecttype
|
||||
or subscription_area regexp :subscription_area
|
||||
order by subscription_title
|
||||
limit {$this->pagination_size}
|
||||
offset {$offset}";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":subscription_title", $find_words);
|
||||
$statement->bindValue(":subscription_description", $find_words);
|
||||
$statement->bindValue(":subscription_projecttype", $find_words);
|
||||
$statement->bindValue(":subscription_area", $find_words);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$subscriptions = $this->getTableXML("subscriptions", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
|
||||
$subscriptions->addAttribute("count", $count);
|
||||
$subscriptions->addAttribute("start", $start);
|
||||
$subscriptions->addAttribute("end", $end);
|
||||
$subscriptions->addAttribute("page", $this->pagination_page);
|
||||
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $subscriptions;
|
||||
}
|
||||
|
||||
// ==================
|
||||
// User Subscriptions
|
||||
// ==================
|
||||
|
||||
public function userSubscriptions() {
|
||||
|
||||
$subscriptions = $this->getUsersActiveSubscriptions($this->current_user_serial);
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
$XML = $this->mergeXML($subscriptions, "<XML/>");
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("userSubscriptions"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Return a Users Subscriptions
|
||||
// ============================
|
||||
|
||||
public function getUsersActiveSubscriptions($user_serial) {
|
||||
|
||||
$SQL = "select view_usersubscriptions.*
|
||||
from view_usersubscriptions
|
||||
where usersubscription_user_serial = {$user_serial}
|
||||
and view_usersubscriptions.usersubscription_status = 'ACTIVE'
|
||||
and view_usersubscriptions.usersubscription_stop_date >= now()
|
||||
order by view_usersubscriptions.subscription_title, view_usersubscriptions.usersubscription_status";
|
||||
|
||||
return $this->getTable("usersubscriptions", $SQL);
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Return a Users Subscriptions
|
||||
// ============================
|
||||
|
||||
public function getAllUsersSubscriptions($user_serial) {
|
||||
|
||||
$SQL = "select view_usersubscriptions.*
|
||||
from view_usersubscriptions
|
||||
where usersubscription_user_serial = {$user_serial}
|
||||
order by view_usersubscriptions.usersubscription_status, view_usersubscriptions.subscription_title";
|
||||
|
||||
return $this->getTable("usersubscriptions", $SQL);
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Return a Users Subscription
|
||||
// ===========================
|
||||
|
||||
public function getUsersSubscription($usersubscription_serial) {
|
||||
|
||||
$SQL = "select view_usersubscriptions.*
|
||||
from view_usersubscriptions
|
||||
where usersubscription_serial = {$usersubscription_serial}";
|
||||
|
||||
return $this->getTable("usersubscription", $SQL);
|
||||
}
|
||||
|
||||
// ==================================
|
||||
// Determine if a Subscription exists
|
||||
// ==================================
|
||||
|
||||
public function subscriptionExists() {
|
||||
|
||||
$subscription_serial = filter_input(INPUT_POST, "subscription_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$subscription_title = filter_input(INPUT_POST, "subscription_title") ?: "";
|
||||
|
||||
$SQL = "select subscription_serial
|
||||
from view_subscriptions
|
||||
where subscription_serial != :subscription_serial
|
||||
and lower(subscription_title) = :subscription_title";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":subscription_serial", $subscription_serial);
|
||||
$statement->bindValue(":subscription_title", strtolower($subscription_title));
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$exists = (count($recordset) > 0) ? true : false;
|
||||
|
||||
echo json_encode($exists);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,312 @@
|
||||
<?php
|
||||
|
||||
// =====================
|
||||
// Support Tickets Class
|
||||
// =====================
|
||||
|
||||
class SupportTickets 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;
|
||||
}
|
||||
|
||||
// ====================
|
||||
// View Support Tickets
|
||||
// ====================
|
||||
|
||||
public function viewSupportTickets() {
|
||||
|
||||
$supporttickets = $this->getSupportTicketsPage();
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
$XML = $this->mergeXML($supporttickets, "<XML/>");
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("viewSupportTickets"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Support Ticket Summary
|
||||
// ======================
|
||||
|
||||
public function viewSupportTicketSummary() {
|
||||
|
||||
$supportticket_serial = filter_input(INPUT_POST, "supportticket_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$supportticket = $this->getSupportTicket($supportticket_serial);
|
||||
|
||||
if ($supportticket->count() == 0) {
|
||||
$this->logError("Invalid Support Ticket ({$supportticket_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$user_name = $supportticket->record->supportticket_creator;
|
||||
|
||||
$user = (new Users())->getUserByUserName($user_name);
|
||||
|
||||
$XML = $this->mergeXML($supportticket, "<XML/>");
|
||||
$XML = $this->mergeXML($user, $XML);
|
||||
|
||||
// echo $XML;
|
||||
// die();
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("ticketSummary"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
// ====================================
|
||||
// Return a Support Tickets Page Object
|
||||
// ====================================
|
||||
|
||||
public function getSupportTicketsPage() {
|
||||
|
||||
// Find Criteria
|
||||
|
||||
$find_supportticket = filter_input(INPUT_POST, "find_supportticket") ?: "";
|
||||
$find_supportticket = $this->sanitizeString($find_supportticket);
|
||||
|
||||
$this->pagination_size = filter_input(INPUT_POST, "supporttickets_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
||||
|
||||
$supporttickets_order_by = filter_input(INPUT_POST, "supporttickets_order_by") ?: "";
|
||||
$supporttickets_order_direction = filter_input(INPUT_POST, "supporttickets_order_direction") ?: "";
|
||||
|
||||
if ($supporttickets_order_by === "") {
|
||||
$orderby = "supportticket_serial desc";
|
||||
} else {
|
||||
$orderby = $supporttickets_order_by . " " . $supporttickets_order_direction;
|
||||
}
|
||||
|
||||
// Record Count
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "select count(*) as count
|
||||
from view_supporttickets
|
||||
where supportticket_creator regexp :supportticket_creator
|
||||
or supportticket_catagory_verbose regexp :supportticket_catagory_verbose
|
||||
or supportticket_message regexp :supportticket_message
|
||||
or supportticket_status regexp :supportticket_status
|
||||
or supportticket_subject regexp :supportticket_subject";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":supportticket_creator", $find_supportticket);
|
||||
$statement->bindValue(":supportticket_catagory_verbose", $find_supportticket);
|
||||
$statement->bindValue(":supportticket_message", $find_supportticket);
|
||||
$statement->bindValue(":supportticket_status", $find_supportticket);
|
||||
$statement->bindValue(":supportticket_subject", $find_supportticket);
|
||||
|
||||
$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_supporttickets.*
|
||||
from view_supporttickets
|
||||
where supportticket_creator regexp :supportticket_creator
|
||||
or supportticket_catagory_verbose regexp :supportticket_catagory_verbose
|
||||
or supportticket_message regexp :supportticket_message
|
||||
or supportticket_status regexp :supportticket_status
|
||||
or supportticket_subject regexp :supportticket_subject
|
||||
order by {$orderby}
|
||||
limit {$this->pagination_size}
|
||||
offset {$offset}";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":supportticket_creator", $find_supportticket);
|
||||
$statement->bindValue(":supportticket_catagory_verbose", $find_supportticket);
|
||||
$statement->bindValue(":supportticket_message", $find_supportticket);
|
||||
$statement->bindValue(":supportticket_status", $find_supportticket);
|
||||
$statement->bindValue(":supportticket_subject", $find_supportticket);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$supporttickets = $this->getTableXML("supporttickets", $statement);
|
||||
|
||||
foreach ($supporttickets as $supportticket) {
|
||||
$html_message = trim(strip_tags($supportticket->supportticket_message));
|
||||
$supportticket->supportticket_message_raw = $html_message;
|
||||
}
|
||||
|
||||
|
||||
// Insert Pagination Attributes
|
||||
$supporttickets->addAttribute("count", $count);
|
||||
$supporttickets->addAttribute("start", $start);
|
||||
$supporttickets->addAttribute("end", $end);
|
||||
$supporttickets->addAttribute("page", $this->pagination_page);
|
||||
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $supporttickets;
|
||||
}
|
||||
|
||||
// ====================
|
||||
// Start Support Ticket
|
||||
// ====================
|
||||
|
||||
public function startSupportTicket() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$user = (new Users())->getUser($this->current_user_serial);
|
||||
$dropdowns = (new Dropdowns())->getDropdowns();
|
||||
|
||||
$XML = $this->mergeXML($user, "<XML/>");
|
||||
$XML = $this->mergeXML($dropdowns, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("startSupportTicket"));
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "send":
|
||||
|
||||
$supportticket_subject = filter_input(INPUT_POST, "supportticket_subject") ?: "";
|
||||
$supportticket_category = filter_input(INPUT_POST, "supportticket_category") ?: "";
|
||||
$supportticket_category_other = filter_input(INPUT_POST, "supportticket_category_other") ?: "";
|
||||
$supportticket_message = filter_input(INPUT_POST, "supportticket_message") ?: "";
|
||||
|
||||
$SQL = "insert into supporttickets
|
||||
|
||||
( supportticket_subject,
|
||||
supportticket_category,
|
||||
supportticket_category_other,
|
||||
supportticket_message,
|
||||
supportticket_status,
|
||||
supportticket_creator,
|
||||
supportticket_created )
|
||||
|
||||
VALUES ( :supportticket_subject,
|
||||
:supportticket_category,
|
||||
:supportticket_category_other,
|
||||
:supportticket_message,
|
||||
:supportticket_status,
|
||||
:supportticket_creator,
|
||||
:supportticket_created )";
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":supportticket_subject", $supportticket_subject);
|
||||
$statement->bindValue(":supportticket_category", $supportticket_category);
|
||||
$statement->bindValue(":supportticket_category_other", $supportticket_category_other);
|
||||
$statement->bindValue(":supportticket_message", $supportticket_message);
|
||||
$statement->bindValue(":supportticket_status", 5); // Dropdown value of the dropdown type 2 for ticket statuses
|
||||
$statement->bindValue(":supportticket_creator", $this->current_user_name);
|
||||
$statement->bindValue(":supportticket_created", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$supportticket_serial = $connection->lastInsertId();
|
||||
|
||||
// Send Email to Support Center
|
||||
$this->sendNotifications($supportticket_serial);
|
||||
|
||||
$this->displayNotice("Support ticket submitted successfully. The Support team will respond as soon as possible.");
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================
|
||||
// Send Support Center Ticket Notification Email
|
||||
// =============================================
|
||||
|
||||
public function sendNotifications($supportticket_serial = 0) {
|
||||
|
||||
if (empty($supportticket_serial)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = $this->getSettings();
|
||||
|
||||
$Environment = (string) $settings->Environment;
|
||||
$SupportEmail = (string) $settings->SupportEmail;
|
||||
|
||||
if ($Environment == "Development") {
|
||||
return;
|
||||
}
|
||||
|
||||
$supportticket = $this->getSupportTicket($supportticket_serial);
|
||||
|
||||
$to = $SupportEmail;
|
||||
$subject = "Georgia Housing Report - Support Ticket Submittal";
|
||||
$message = $this->applyXSL($supportticket, $this->getXSL("emailSupportTicket"));
|
||||
|
||||
// Send the Email
|
||||
(new Email())->sendEmail($to, $subject, $message);
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// Return an Support Ticket Object
|
||||
// ===============================
|
||||
|
||||
public function getSupportTicket($supportticket_serial = 0) {
|
||||
|
||||
$SQL = "select view_supporttickets.*
|
||||
from view_supporttickets
|
||||
where view_supporttickets.supportticket_serial = {$supportticket_serial}";
|
||||
|
||||
return $this->getTable("supporttickets", $SQL);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,748 @@
|
||||
<?php
|
||||
|
||||
// ===========
|
||||
// Users Class
|
||||
// ===========
|
||||
|
||||
class Users extends Base {
|
||||
|
||||
// Variables
|
||||
|
||||
private $current_user_id = "";
|
||||
private $current_user_serial = "";
|
||||
private $current_user_name = "";
|
||||
private $current_user_client_name = "";
|
||||
private $current_user_email = "";
|
||||
private $pagination_size = 20;
|
||||
private $pagination_page = 1;
|
||||
|
||||
// ================================
|
||||
// __construct : Class Constructor.
|
||||
// ================================
|
||||
|
||||
public function __construct() {
|
||||
|
||||
set_error_handler(array($this, "displayError"));
|
||||
|
||||
date_default_timezone_set(self::TIMEZONE);
|
||||
|
||||
$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->current_user_client_name = $_SESSION[self::USER_CLIENT_NAME] ?? "";
|
||||
|
||||
$this->pagination_page = $_SESSION[self::PAGINATION_PAGE] ?? 1;
|
||||
}
|
||||
|
||||
// ===========
|
||||
// Setup Users
|
||||
// ===========
|
||||
|
||||
public function setupUsers() {
|
||||
|
||||
$users = $this->getUsersPage();
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
$XML = $this->mergeXML($users, "<XML/>");
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$html = $this->applyXSL($XML, $this->getXSL("setupUsers"));
|
||||
|
||||
$this->displayContent($html);
|
||||
}
|
||||
|
||||
// ============
|
||||
// User Summary
|
||||
// ============
|
||||
|
||||
public function userSummary() {
|
||||
|
||||
$user_serial = filter_input(INPUT_POST, "user_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$user = $this->getUser($user_serial);
|
||||
|
||||
if ($user->count() == 0) {
|
||||
$this->logError("Invalid User ({$user_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$notes = (new Notes())->getAllNotes($user_serial);
|
||||
$subscriptions = (new Subscriptions())->getAllUsersSubscriptions($user_serial);
|
||||
|
||||
$XML = $this->mergeXML($user, "<XML/>");
|
||||
$XML = $this->mergeXML($subscriptions, $XML);
|
||||
$XML = $this->mergeXML($notes, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("userSummary"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
// ========
|
||||
// Add User
|
||||
// ========
|
||||
|
||||
public function addUser() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
$constants = $this->getConstants();
|
||||
|
||||
$XML = $this->mergeXML($popovers, "<XML/>");
|
||||
$XML = $this->mergeXML($constants, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("addUser"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "add":
|
||||
|
||||
$user_name = filter_input(INPUT_POST, "user_name") ?: "";
|
||||
$user_client_name = filter_input(INPUT_POST, "user_client_name") ?: "";
|
||||
$user_email = filter_input(INPUT_POST, "user_email") ?: "";
|
||||
$user_role = filter_input(INPUT_POST, "user_role") ?: "";
|
||||
|
||||
$user_name = strtoupper(preg_replace("/\s+/", " ", $user_name));
|
||||
|
||||
$user_random_password = $this->generateRandomPassword();
|
||||
$user_temp_password = password_hash($user_random_password, PASSWORD_DEFAULT);
|
||||
|
||||
$user_change_password = (boolean) true;
|
||||
$user_active = (boolean) true;
|
||||
|
||||
// Add the User
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "insert into users
|
||||
|
||||
( user_name,
|
||||
user_email,
|
||||
user_client_name,
|
||||
user_password,
|
||||
user_role,
|
||||
user_change_password,
|
||||
user_active,
|
||||
user_creator,
|
||||
user_created )
|
||||
|
||||
values ( :user_name,
|
||||
:user_email,
|
||||
:user_client_name,
|
||||
:user_password,
|
||||
:user_role,
|
||||
:user_change_password,
|
||||
:user_active,
|
||||
:user_creator,
|
||||
:user_created )";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":user_name", $user_name);
|
||||
$statement->bindValue(":user_email", $user_email);
|
||||
$statement->bindValue(":user_client_name", $user_client_name);
|
||||
$statement->bindValue(":user_password", $user_temp_password);
|
||||
$statement->bindValue(":user_role", $user_role);
|
||||
$statement->bindValue(":user_change_password", $user_change_password, PDO::PARAM_BOOL);
|
||||
$statement->bindValue(":user_active", $user_active, PDO::PARAM_BOOL);
|
||||
$statement->bindValue(":user_creator", $this->current_user_name);
|
||||
$statement->bindValue(":user_created", $this->getTimestamp());
|
||||
|
||||
if (!$statement->execute()) {
|
||||
trigger_error($statement->errorInfo()[2]);
|
||||
}
|
||||
|
||||
$user = $this->getUserByUserName($user_name);
|
||||
|
||||
// Send User Credentials
|
||||
|
||||
(new Email())->emailNewUserCredentials($user, $user_random_password);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ===========
|
||||
// Delete User
|
||||
// ===========
|
||||
|
||||
public function deleteUser() {
|
||||
|
||||
$user_serial = filter_input(INPUT_POST, "user_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$users = $this->getUser($user_serial);
|
||||
|
||||
if ($users->count() == 0) {
|
||||
$this->logError("Invalid User ({$user_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$SQL = "delete from users
|
||||
where user_serial = {$user_serial}";
|
||||
|
||||
$this->executeSQL($SQL);
|
||||
}
|
||||
|
||||
// =========
|
||||
// Edit User
|
||||
// =========
|
||||
|
||||
public function editUser() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$user_serial = (integer) filter_input(INPUT_POST, "user_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$user = $this->getUser($user_serial);
|
||||
|
||||
if ($user->count() === 0) {
|
||||
$this->logError("Invalid User ({$user_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
$constants = $this->getConstants();
|
||||
|
||||
$XML = $this->mergeXML($user, "<XML/>");
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
$XML = $this->mergeXML($constants, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("editUser"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "update":
|
||||
|
||||
$user_serial = filter_input(INPUT_POST, "user_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$user_name = filter_input(INPUT_POST, "user_name") ?: "";
|
||||
$user_email = filter_input(INPUT_POST, "user_email") ?: "";
|
||||
$user_client_name = filter_input(INPUT_POST, "user_client_name") ?: "";
|
||||
$user_role = filter_input(INPUT_POST, "user_role") ?: "";
|
||||
$user_active = filter_input(INPUT_POST, "user_active", FILTER_VALIDATE_BOOLEAN) ?: false;
|
||||
|
||||
$users = $this->getUser($user_serial);
|
||||
|
||||
if ($users->count() == 0) {
|
||||
$this->logError("Invalid User ({$user_serial}): " . __METHOD__);
|
||||
}
|
||||
|
||||
// Update the User
|
||||
|
||||
$SQL = "update users
|
||||
set user_name = :user_name,
|
||||
user_email = :user_email,
|
||||
user_client_name = :user_client_name,
|
||||
user_role = :user_role,
|
||||
user_active = :user_active,
|
||||
user_changer = :user_changer,
|
||||
user_changed = :user_changed
|
||||
where user_serial = :user_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":user_serial", $user_serial);
|
||||
$statement->bindValue(":user_name", $user_name);
|
||||
$statement->bindValue(":user_email", $user_email);
|
||||
$statement->bindValue(":user_client_name", $user_client_name);
|
||||
$statement->bindValue(":user_role", $user_role);
|
||||
$statement->bindValue(":user_active", $user_active, PDO::PARAM_BOOL);
|
||||
$statement->bindValue(":user_changer", $this->current_user_name);
|
||||
$statement->bindValue(":user_changed", $this->getTimestamp());
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ====================
|
||||
// Return a User Object
|
||||
// ====================
|
||||
|
||||
public function getUser($user_serial = 0) {
|
||||
|
||||
$SQL = "select view_users.*
|
||||
from view_users
|
||||
where user_serial = {$user_serial}";
|
||||
|
||||
return $this->getTable("users", $SQL);
|
||||
}
|
||||
|
||||
// ====================
|
||||
// Return a User Object
|
||||
// ====================
|
||||
|
||||
public function getUserByUserName($user_name) {
|
||||
|
||||
$SQL = "select view_users.*
|
||||
from view_users
|
||||
where user_name = '{$user_name}'
|
||||
or user_client_name = '{$user_name}'";
|
||||
|
||||
return $this->getTable("user", $SQL);
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Return a User's Serial
|
||||
// ======================
|
||||
|
||||
public function getUserSerial($user_id = "") {
|
||||
|
||||
$users = $this->getUserByUserId($user_id);
|
||||
|
||||
return ($users->count() === 0) ? 0 : (integer) $users->record->user_serial;
|
||||
}
|
||||
|
||||
// =====================
|
||||
// Return a Users Object
|
||||
// =====================
|
||||
|
||||
public function getUsers() {
|
||||
|
||||
$SQL = "select view_users.*
|
||||
from view_users";
|
||||
|
||||
return $this->getTable("users", $SQL);
|
||||
}
|
||||
|
||||
// ==========================
|
||||
// Return a Users Page Object
|
||||
// ==========================
|
||||
|
||||
public function getUsersPage() {
|
||||
|
||||
// Find Criteria
|
||||
|
||||
$find_user = filter_input(INPUT_POST, "find_user") ?: "";
|
||||
$find_user = $this->sanitizeString($find_user);
|
||||
|
||||
$find_words = implode("|", explode(" ", $find_user));
|
||||
|
||||
// Record Count
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "select count(*) as count
|
||||
from view_users
|
||||
where user_name regexp :user_name
|
||||
or user_client_name regexp :user_client_name
|
||||
or user_email regexp :user_email
|
||||
or user_role regexp :user_role";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":user_name", $find_words);
|
||||
$statement->bindValue(":user_client_name", $find_words);
|
||||
$statement->bindValue(":user_email", $find_words);
|
||||
$statement->bindValue(":user_role", $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_users.*
|
||||
from view_users
|
||||
where user_name regexp :user_name
|
||||
or user_client_name regexp :user_client_name
|
||||
or user_email regexp :user_email
|
||||
or user_role regexp :user_role
|
||||
limit {$this->pagination_size}
|
||||
offset {$offset}";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":user_name", $find_words);
|
||||
$statement->bindValue(":user_client_name", $find_words);
|
||||
$statement->bindValue(":user_email", $find_words);
|
||||
$statement->bindValue(":user_role", $find_words);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$users = $this->getTableXML("users", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
|
||||
$users->addAttribute("count", $count);
|
||||
$users->addAttribute("start", $start);
|
||||
$users->addAttribute("end", $end);
|
||||
$users->addAttribute("page", $this->pagination_page);
|
||||
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Return an User Object(AJAX)
|
||||
// ===========================
|
||||
|
||||
public function getUser_AJAX($user_name = "") {
|
||||
|
||||
$user_name = filter_input(INPUT_POST, "user_name") ?: $user_name;
|
||||
|
||||
$users = $this->getUserByUserName($user_name);
|
||||
|
||||
// Create the User Object.
|
||||
|
||||
$User = array();
|
||||
|
||||
$User["exists"] = ($users->count() > 0) ? true : false;
|
||||
|
||||
if ($_SESSION[self::AJAX]) {
|
||||
echo json_encode($User);
|
||||
} else {
|
||||
return $User;
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================
|
||||
// Determine if a User Exists
|
||||
// ==========================
|
||||
|
||||
public function userExists() {
|
||||
|
||||
$user_serial = filter_input(INPUT_POST, "user_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$user_id = filter_input(INPUT_POST, "user_id") ?: "";
|
||||
|
||||
$user_id = strtolower(trim(preg_replace("/\s+/", " ", $user_id)));
|
||||
|
||||
$SQL = "select user_id
|
||||
from view_users
|
||||
where user_serial != :user_serial
|
||||
and user_id = :user_id";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":user_serial", $user_serial);
|
||||
$statement->bindValue(":user_id", $user_id);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$exists = (count($recordset) > 0) ? true : false;
|
||||
|
||||
echo json_encode($exists);
|
||||
}
|
||||
|
||||
// =============================
|
||||
// Determine if a User is Active
|
||||
// =============================
|
||||
|
||||
public function userActive() {
|
||||
|
||||
$user_serial = (integer) filter_input(INPUT_POST, "user_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$SQL = "select request_serial
|
||||
from requests
|
||||
where request_user = {$user_serial}";
|
||||
|
||||
$requests = $this->getTable("requests", $SQL);
|
||||
|
||||
$active = ($requests->count() > 0) ? true : $active;
|
||||
|
||||
echo json_encode($active);
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Login to the application
|
||||
// ========================
|
||||
|
||||
public function login() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$XSLParms["BTN_SUBMIT"] = "main.php?action=Users.login&step=authenticate";
|
||||
$XSLParms["INVALID_SIGNIN"] = "FALSE";
|
||||
|
||||
echo $this->applyXSL("", $this->getXSL("signIn"), $XSLParms);
|
||||
exit();
|
||||
|
||||
break;
|
||||
|
||||
case "authenticate":
|
||||
|
||||
$user_name = filter_input(INPUT_POST, "user_name") ?: "";
|
||||
$user_password = filter_input(INPUT_POST, "user_password") ?: "";
|
||||
|
||||
// The User must exist in the Users Table
|
||||
|
||||
$user = $this->getUserByUserName($user_name);
|
||||
|
||||
// Automatically deny authentication if user is inactive
|
||||
|
||||
if ($user->record->user_active == 0) {
|
||||
$XSLParms["BTN_SUBMIT"] = "main.php?action=Users.signIn&step=authenticate";
|
||||
$XSLParms["INVALID_SIGNIN"] = "TRUE";
|
||||
|
||||
echo $this->applyXSL("", $this->getXSL("signIn"), $XSLParms);
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($user->count() > 0) {
|
||||
|
||||
$stored_hashed_password = $user->record->user_password;
|
||||
|
||||
// Verify Password
|
||||
|
||||
if (password_verify($user_password, $stored_hashed_password)) {
|
||||
|
||||
$_SESSION[self::USER_AUTHENTICATED] = true;
|
||||
$_SESSION[self::USER_SERIAL] = (integer) $user->record->user_serial;
|
||||
$_SESSION[self::USER_ID] = (string) $user->record->user_id;
|
||||
$_SESSION[self::USER_NAME] = (string) $user->record->user_name;
|
||||
$_SESSION[self::USER_EMAIL] = (string) $user->record->user_email;
|
||||
$_SESSION[self::USER_CLIENT_NAME] = (string) $user->record->user_client_name;
|
||||
$_SESSION[self::USER_ROLE] = (string) $user->record->user_role;
|
||||
|
||||
$this->current_user_id = $_SESSION[self::USER_ID] ?? "";
|
||||
$this->current_user_serial = $_SESSION[self::USER_SERIAL] ?? 0;
|
||||
$this->current_user_name = $_SESSION[self::USER_NAME] ?? "";
|
||||
$this->current_user_email = $_SESSION[self::USER_EMAIL] ?? "";
|
||||
|
||||
// Determine if this is a System Administrator
|
||||
|
||||
if (count($this->getSettings()->xpath("//SystemAdministrator[. = '{$user_name}']")) > 0) {
|
||||
|
||||
$_SESSION[self::USER_ROLE] = "System Administrator";
|
||||
}
|
||||
|
||||
// Create Journal Entry and finish
|
||||
(new Journal())->journalEntry("{$_SESSION[self::USER_NAME]} logged in ({$_SESSION[self::USER_ROLE]}).");
|
||||
|
||||
$this->updateLogin();
|
||||
|
||||
header("Location: ./");
|
||||
exit();
|
||||
} else {
|
||||
|
||||
$XSLParms["BTN_SUBMIT"] = "main.php?action=Users.signIn&step=authenticate";
|
||||
$XSLParms["INVALID_SIGNIN"] = "TRUE";
|
||||
|
||||
echo $this->applyXSL("", $this->getXSL("signIn"), $XSLParms);
|
||||
die();
|
||||
}
|
||||
} else {
|
||||
|
||||
$XSLParms["BTN_SUBMIT"] = "main.php?action=Users.signIn&step=authenticate";
|
||||
$XSLParms["INVALID_SIGNIN"] = "TRUE";
|
||||
|
||||
echo $this->applyXSL("", $this->getXSL("signIn"), $XSLParms);
|
||||
die();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// User NOT Validated.
|
||||
header("Location: ./");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Change Password
|
||||
// ===============
|
||||
|
||||
public function changePassword() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
$XML = $this->mergeXML($popovers, "<XML/>");
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("changePassword"));
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "change":
|
||||
|
||||
$user_serial = $_SESSION[self::USER_SERIAL];
|
||||
$user_new_password = filter_input(INPUT_POST, "user_new_password") ?: "";
|
||||
$user_verify_password = filter_input(INPUT_POST, "user_verify_password") ?: "";
|
||||
|
||||
if (!$user_new_password == $user_verify_password) {
|
||||
$this->initializeSession();
|
||||
}
|
||||
|
||||
$user_new_hashed_password = password_hash($user_new_password, PASSWORD_DEFAULT);
|
||||
|
||||
// Update User Password
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "update users
|
||||
set user_password = :user_password,
|
||||
user_change_password = :user_change_password,
|
||||
user_changer = :user_changer,
|
||||
user_changed = :user_changed
|
||||
where user_serial = :user_serial";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":user_serial", $user_serial);
|
||||
$statement->bindValue(":user_password", $user_new_hashed_password);
|
||||
$statement->bindValue(":user_change_password", 0);
|
||||
$statement->bindValue(":user_changer", $this->current_user_name);
|
||||
$statement->bindValue(":user_changed", $this->getTimestamp());
|
||||
|
||||
if (!$statement->execute()) {
|
||||
$this->debug($statement->errorInfo()[2]);
|
||||
}
|
||||
|
||||
(new Journal())->journalEntry("{$_SESSION[self::USER_NAME]} changed their password.");
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ==============
|
||||
// Reset Password
|
||||
// ==============
|
||||
|
||||
public function resetPassword() {
|
||||
|
||||
$reset = false;
|
||||
|
||||
$user_serial = filter_input(INPUT_POST, "user_serial") ?: "";
|
||||
|
||||
$user = $this->getUser($user_serial);
|
||||
|
||||
$user_name = $user->record->user_name;
|
||||
|
||||
$user_random_password = $this->generateRandomPassword();
|
||||
$user_temp_password = password_hash($user_random_password, PASSWORD_DEFAULT);
|
||||
|
||||
// Update User Password
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "update users
|
||||
set user_password = :user_password,
|
||||
user_change_password = :user_change_password
|
||||
where user_serial = :user_serial";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":user_serial", $user_serial);
|
||||
$statement->bindValue(":user_password", $user_temp_password);
|
||||
$statement->bindValue(":user_change_password", 1);
|
||||
|
||||
if (!$statement->execute()) {
|
||||
$this->debug($statement->errorInfo()[2]);
|
||||
} else {
|
||||
$reset = true;
|
||||
}
|
||||
|
||||
// Send User Credentials
|
||||
|
||||
(new Email())->emailUserPasswordResetLink($user, $user_random_password);
|
||||
|
||||
(new Journal())->journalEntry("{$_SESSION[self::USER_NAME]} reset {$user_name}'s password.");
|
||||
|
||||
echo json_encode($reset);
|
||||
}
|
||||
|
||||
// ===============================================
|
||||
// Update the Login timestamp for the current User
|
||||
// ===============================================
|
||||
|
||||
public function updateLogin() {
|
||||
|
||||
$SQL = "update users
|
||||
set user_login = :user_login
|
||||
where user_serial = :user_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":user_login", $this->getTimestamp());
|
||||
$statement->bindValue(":user_serial", $this->current_user_serial);
|
||||
|
||||
$statement->execute();
|
||||
}
|
||||
|
||||
// ====================
|
||||
// Update Active Status
|
||||
// ====================
|
||||
|
||||
public function updateActiveStatus() {
|
||||
|
||||
$user_serial = filter_input(INPUT_POST, "user_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$user_active = filter_input(INPUT_POST, "user_active", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$SQL = "update users
|
||||
set user_active = :user_active,
|
||||
user_changed = :user_changed,
|
||||
user_changer = :user_changer
|
||||
where user_serial = :user_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":user_serial", $user_serial);
|
||||
$statement->bindValue(":user_active", $user_active);
|
||||
$statement->bindValue(":user_changed", $this->getTimestamp());
|
||||
$statement->bindValue(":user_changer", $this->current_user_name);
|
||||
|
||||
if (!$statement->execute()) {
|
||||
error_log($statement->errorInfo()[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user