generated from jric11/baseProject
Codex's updates...
This commit is contained in:
+237
-186
@@ -4,8 +4,8 @@
|
||||
// Base Class
|
||||
// ==========
|
||||
|
||||
require_once "vendor/autoload.php";
|
||||
require_once "classes/Autoloader.php";
|
||||
require_once __DIR__ . "/../vendor/autoload.php";
|
||||
require_once __DIR__ . "/Autoloader.php";
|
||||
|
||||
class Base {
|
||||
|
||||
@@ -13,31 +13,30 @@ class Base {
|
||||
// Constants
|
||||
// =========
|
||||
|
||||
const APPLICATION_NAME = "Hunting Club Roster";
|
||||
const APPLICATION_NAME = "Hunting Club Roster";
|
||||
const APPLICATION_MNEMONIC = "HUNTINGCLUBROSTER";
|
||||
const VERSION = "1.00";
|
||||
const TIMEZONE = "America/New_York";
|
||||
|
||||
const VERSION = "1.00";
|
||||
const TIMEZONE = "America/New_York";
|
||||
// =================
|
||||
// Session Variables
|
||||
// =================
|
||||
|
||||
const ENVIRONMENT = "HUNTINGCLUBROSTER_ENVIRONMENT";
|
||||
const ACTIVE_SESSION = "HUNTINGCLUBROSTER_ACTIVE_SESSION";
|
||||
const USER_SERIAL = "HUNTINGCLUBROSTER_USER_SERIAL";
|
||||
const USER_NAME = "HUNTINGCLUBROSTER_USER_NAME";
|
||||
const USER_FULL_NAME = "HUNTINGCLUBROSTER_USER_FULL_NAME";
|
||||
const USER_EMAIL = "HUNTINGCLUBROSTER_USER_EMAIL";
|
||||
const USER_ROLE = "HUNTINGCLUBROSTER_USER_ROLE";
|
||||
const USER_AUTHENTICATED = "HUNTINGCLUBROSTER_USER_AUTHENTICATED";
|
||||
const REPORTS_GET = "HUNTINGCLUBROSTER_REPORTS_GET";
|
||||
const REPORTS_POST = "HUNTINGCLUBROSTER_REPORTS_POST";
|
||||
const THEME = "HUNTINGCLUBROSTER_THEME";
|
||||
const AJAX = "HUNTINGCLUBROSTER_AJAX";
|
||||
const TODAY = "HUNTINGCLUBROSTER_TODAY";
|
||||
const COPYRIGHT = "HUNTINGCLUBROSTER_COPYRIGHT";
|
||||
const PAGE = "HUNTINGCLUBROSTER_PAGE";
|
||||
const PAGINATION_PAGE = "HUNTINGCLUBROSTER_PAGINATION_PAGE";
|
||||
const ENVIRONMENT = "HUNTINGCLUBROSTER_ENVIRONMENT";
|
||||
const ACTIVE_SESSION = "HUNTINGCLUBROSTER_ACTIVE_SESSION";
|
||||
const USER_SERIAL = "HUNTINGCLUBROSTER_USER_SERIAL";
|
||||
const USER_NAME = "HUNTINGCLUBROSTER_USER_NAME";
|
||||
const USER_FULL_NAME = "HUNTINGCLUBROSTER_USER_FULL_NAME";
|
||||
const USER_EMAIL = "HUNTINGCLUBROSTER_USER_EMAIL";
|
||||
const USER_ROLE = "HUNTINGCLUBROSTER_USER_ROLE";
|
||||
const USER_AUTHENTICATED = "HUNTINGCLUBROSTER_USER_AUTHENTICATED";
|
||||
const REPORTS_GET = "HUNTINGCLUBROSTER_REPORTS_GET";
|
||||
const REPORTS_POST = "HUNTINGCLUBROSTER_REPORTS_POST";
|
||||
const THEME = "HUNTINGCLUBROSTER_THEME";
|
||||
const AJAX = "HUNTINGCLUBROSTER_AJAX";
|
||||
const TODAY = "HUNTINGCLUBROSTER_TODAY";
|
||||
const COPYRIGHT = "HUNTINGCLUBROSTER_COPYRIGHT";
|
||||
const PAGE = "HUNTINGCLUBROSTER_PAGE";
|
||||
const PAGINATION_PAGE = "HUNTINGCLUBROSTER_PAGINATION_PAGE";
|
||||
|
||||
// =================
|
||||
// Class Constructor
|
||||
@@ -56,7 +55,7 @@ class Base {
|
||||
|
||||
public function appendSXE(SimpleXMLElement $from, SimpleXMLElement $to) {
|
||||
|
||||
$toDOM = dom_import_simplexml($to);
|
||||
$toDOM = dom_import_simplexml($to);
|
||||
$fromDOM = dom_import_simplexml($from);
|
||||
|
||||
$toDOM->appendChild($toDOM->ownerDocument->importNode($fromDOM, true));
|
||||
@@ -80,30 +79,31 @@ class Base {
|
||||
$XSLParms = array();
|
||||
}
|
||||
|
||||
$XSLParms["APPLICATION_NAME"] = self::APPLICATION_NAME;
|
||||
$XSLParms["CSRF_TOKEN"] = $this->csrfToken();
|
||||
$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_FULL_NAME"] = $_SESSION[self::USER_FULL_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");
|
||||
$XSLParms["TODAY_HHMM"] = date("Hi");
|
||||
$XSLParms["COPYRIGHT"] = date("Y");
|
||||
$XSLParms["VERSION"] = self::VERSION;
|
||||
$XSLParms["THEME"] = $_SESSION[self::THEME] ?? self::THEME;
|
||||
$XSLParms["ENVIRONMENT"] = $_SESSION[self::ENVIRONMENT] ?? "Production";
|
||||
$XSLParms["USER_NAME"] = $XSLParms["USER_NAME"] ?? $_SESSION[self::USER_NAME] ?? "";
|
||||
$XSLParms["USER_FULL_NAME"] = $_SESSION[self::USER_FULL_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");
|
||||
$XSLParms["TODAY_HHMM"] = date("Hi");
|
||||
$XSLParms["COPYRIGHT"] = date("Y");
|
||||
|
||||
$XML = new DOMDocument();
|
||||
$XSL = new DOMDocument();
|
||||
$XML = new DOMDocument();
|
||||
$XSL = new DOMDocument();
|
||||
$XSLT = new XSLTProcessor();
|
||||
|
||||
if ($XMLString) {
|
||||
$XML->loadXML($XMLString);
|
||||
$XML->loadXML($XMLString, LIBXML_NONET);
|
||||
}
|
||||
|
||||
if ($XSLString) {
|
||||
$XSL->loadXML($XSLString);
|
||||
$XSL->loadXML($XSLString, LIBXML_NONET);
|
||||
}
|
||||
|
||||
$XSLT->importStylesheet($XSL);
|
||||
@@ -112,6 +112,8 @@ class Base {
|
||||
$XSLT->setParameter("", $XSLParms);
|
||||
}
|
||||
|
||||
if (!$XML->documentElement)
|
||||
$XML->loadXML('<XML/>');
|
||||
$document = $XSLT->transformToXml($XML);
|
||||
|
||||
return $document;
|
||||
@@ -122,27 +124,26 @@ class Base {
|
||||
// ============================
|
||||
|
||||
public function connect(): PDO {
|
||||
|
||||
|
||||
$settings = $this->getSettings();
|
||||
|
||||
$host = ((string) $settings->Environment === 'Production') ? 'localhost' : '192.168.1.190';
|
||||
$database = (string) $settings->DatabaseName;
|
||||
$username = (string) $settings->DatabaseUser;
|
||||
$password = (string) $settings->DatabasePassword;
|
||||
|
||||
$host = (string) $settings->DatabaseServer;
|
||||
$database = (string) $settings->DatabaseName;
|
||||
$username = (string) $settings->DatabaseUser;
|
||||
$password = (string) $settings->DatabasePassword;
|
||||
|
||||
try {
|
||||
|
||||
$dsn = sprintf('mysql:host=%s;dbname=%s;charset=utf8mb4', $host, $database);
|
||||
$dsn = sprintf('mysql:host=%s;port=%d;dbname=%s;charset=utf8mb4', $host, (int) ($settings->DatabasePort ?? 3306), $database);
|
||||
|
||||
return new PDO($dsn, $username, $password,
|
||||
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
PDO::ATTR_PERSISTENT => false,]);
|
||||
|
||||
return new PDO($dsn, $username, $password,
|
||||
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
PDO::ATTR_PERSISTENT => false,]);
|
||||
} catch (PDOException $e) {
|
||||
|
||||
$this->logError("Database Connection Failed: " . $e->getMessage());
|
||||
error_log("Database Connection Failed: " . $e->getMessage());
|
||||
|
||||
throw new Exception("Unable to connect to the database.", 0, $e);
|
||||
}
|
||||
@@ -182,32 +183,17 @@ class Base {
|
||||
// Custom error handler to display informative error page
|
||||
// ======================================================
|
||||
|
||||
public function displayError($error_number = "", $error_message = "", $error_file = "", $error_line = "") {
|
||||
|
||||
if (error_reporting() == 0) {
|
||||
return;
|
||||
public function displayError($error_number = 0, $error_message = '', $error_file = '', $error_line = 0) {
|
||||
if (!(error_reporting() & $error_number)) {
|
||||
return false;
|
||||
}
|
||||
// Never log application failures through the failing database or SMTP service.
|
||||
error_log("PHP {$error_number}: {$error_message} in {$error_file}:{$error_line}");
|
||||
|
||||
$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);
|
||||
if (in_array($error_number, [E_DEPRECATED, E_USER_DEPRECATED], true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$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.
|
||||
throw new ErrorException($error_message, 0, $error_number, $error_file, $error_line);
|
||||
}
|
||||
|
||||
// =====================
|
||||
@@ -241,71 +227,139 @@ class Base {
|
||||
|
||||
public function do() {
|
||||
|
||||
$_SESSION[self::TODAY] = date("Y-m-d");
|
||||
|
||||
// Get the requested Action
|
||||
|
||||
$action = filter_input(INPUT_POST, "action") ?: "";
|
||||
$Xaction = filter_input(INPUT_GET, "Xaction") ?: "";
|
||||
|
||||
$action = (empty($Xaction) ? $action : $Xaction);
|
||||
|
||||
if ($Xaction == 'resetpassword') {
|
||||
$this->resetpassword();
|
||||
}
|
||||
|
||||
// Login
|
||||
|
||||
if (($_SESSION[self::USER_AUTHENTICATED] ?? false) === false) {
|
||||
|
||||
(new SignIn())->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") {
|
||||
if (empty($_SESSION[self::ACTIVE_SESSION])) {
|
||||
$this->initializeSession();
|
||||
}
|
||||
|
||||
// Process the requested Action.
|
||||
$_SESSION[self::AJAX] = strtolower($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '') === 'xmlhttprequest';
|
||||
|
||||
list($class, $method) = array_pad(explode('.', $action), 2, "");
|
||||
$_SESSION[self::TODAY] = date('Y-m-d');
|
||||
|
||||
if (empty($method)) {
|
||||
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
|
||||
|
||||
$method = $class;
|
||||
|
||||
if (method_exists(__CLASS__, $method)) {
|
||||
$this->$method();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (method_exists($class, $method)) {
|
||||
(new $class())->$method();
|
||||
return;
|
||||
}
|
||||
if (!in_array($method, ['GET', 'POST'], true)) {
|
||||
http_response_code(405);
|
||||
exit('Method not allowed.');
|
||||
}
|
||||
|
||||
// Default to the Home Page.
|
||||
$this->displayHome();
|
||||
// Reject arrays and oversized values before passing input to string operations.
|
||||
foreach (array_merge($_GET, $_POST) as $value) {
|
||||
if (!is_string($value) || strlen($value) > 8192) {
|
||||
http_response_code(400);
|
||||
exit('Invalid request.');
|
||||
}
|
||||
}
|
||||
$action = strtolower(trim($_POST['action'] ?? $_GET['Xaction'] ?? $_GET['action'] ?? ''));
|
||||
if ($action === 'signout') {
|
||||
if ($method !== 'POST') {
|
||||
http_response_code(405);
|
||||
exit('Use POST to sign out.');
|
||||
}
|
||||
$this->requireCsrf();
|
||||
$ajax = $_SESSION[self::AJAX];
|
||||
$this->logoutSession();
|
||||
if ($ajax) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(true);
|
||||
exit;
|
||||
}
|
||||
header('Location: main.php', true, 303);
|
||||
exit;
|
||||
}
|
||||
if (in_array($action, ['resetpassword', 'authentication.resetpassword'], true)) {
|
||||
(new Authentication())->resetPassword();
|
||||
}
|
||||
if (in_array($action, ['signup', 'signup.createaccount'], true)) {
|
||||
(new SignUp())->createAccount();
|
||||
}
|
||||
if (in_array($action, ['signin', 'signin.login', 'users.login'], true)) {
|
||||
(new SignIn())->login();
|
||||
}
|
||||
|
||||
$user = (new AuthService())->currentUser();
|
||||
|
||||
if (!$user) {
|
||||
$ajax = $_SESSION[self::AJAX];
|
||||
if (!empty($_SESSION[self::USER_AUTHENTICATED])) {
|
||||
$this->logoutSession();
|
||||
}
|
||||
if ($ajax) {
|
||||
http_response_code(401);
|
||||
exit('Please sign in again.');
|
||||
}
|
||||
(new SignIn())->login();
|
||||
}
|
||||
if ($method === 'POST') {
|
||||
$this->requireCsrf();
|
||||
}
|
||||
if ((bool) $user['user_change_password']) {
|
||||
(new Users())->changePassword();
|
||||
return;
|
||||
}
|
||||
// Only named, reviewed entry points are routable. Helpers are never endpoints.
|
||||
$routes = [
|
||||
'' => [Base::class, 'displayHome', false],
|
||||
'./' => [Base::class, 'displayHome', false],
|
||||
'displayhome' => [Base::class, 'displayHome', false],
|
||||
'toggletheme' => [Base::class, 'toggleTheme', false],
|
||||
'getzipcode' => [Base::class, 'getZipcode', false],
|
||||
'validatedate' => [Base::class, 'validateDate', false],
|
||||
'getage' => [Base::class, 'getAge', false],
|
||||
'users.changepassword' => [Users::class, 'changePassword', false],
|
||||
'print' => [Base::class, 'print', true],
|
||||
'print_all_permitsbybuilder.print' => ['Print_All_PermitsByBuilder', 'print', true],
|
||||
'export_allpermitsbybuildercsv.export' => ['Export_AllPermitsByBuilderCSV', 'export', true],
|
||||
'export_allpermitsbybuilderexcel.export' => ['Export_AllPermitsByBuilderExcel', 'export', true],
|
||||
];
|
||||
$adminRoutes = [
|
||||
'Users' => ['setupUsers', 'addUser', 'editUser', 'deleteUser', 'resetPassword', 'userExists', 'getUser_AJAX', 'updateActiveStatus', 'userActive'],
|
||||
'Alerts' => ['setupAlerts', 'addAlert', 'editAlert', 'deleteAlert'],
|
||||
'Dropdowns' => ['setupDropdowns', 'setupDropdowntypes', 'addDropdown', 'editDropdown', 'deleteDropdown', 'addDropdowntype', 'editDropdowntype', 'deleteDropdowntype', 'dropdownExists', 'dropdowntypeExists', 'dropdowntypetitleExists', 'dropdownActive', 'dropdowntypeActive', 'updateDropdownActive', 'updateDropdownDefault'],
|
||||
'Popovers' => ['setupPopovers', 'addPopover', 'editPopover', 'deletePopover', 'popoverExists'],
|
||||
'Reports' => ['setupReports', 'addReport', 'editReport', 'deleteReport', 'selectReport', 'reportExists'],
|
||||
'Statuses' => ['setupStatuses', 'addStatus', 'editStatus', 'deleteStatus', 'statusExists', 'statusActive'],
|
||||
'Journal' => ['viewJournal', 'clearJournal'],
|
||||
'Notes' => ['addNote', 'editNote', 'deleteNote', 'addNoteQuick'],
|
||||
];
|
||||
foreach ($adminRoutes as $class => $methods) {
|
||||
foreach ($methods as $entry)
|
||||
$routes[strtolower($class . '.' . $entry)] = [$class, $entry, true];
|
||||
}
|
||||
if (!isset($routes[$action])) {
|
||||
http_response_code(404);
|
||||
exit('Page not found.');
|
||||
}
|
||||
[$class, $entry, $adminOnly] = $routes[$action];
|
||||
if ($adminOnly && !in_array($user['user_role'], ['Administrator', 'System Administrator'], true)) {
|
||||
http_response_code(403);
|
||||
exit('You do not have permission to perform this action.');
|
||||
}
|
||||
if ($method !== 'POST' && !in_array($action, ['', './', 'displayhome', 'users.changepassword'], true)) {
|
||||
http_response_code(405);
|
||||
exit('Use POST for this action.');
|
||||
}
|
||||
(new $class())->$entry();
|
||||
}
|
||||
|
||||
public function csrfToken(): string {
|
||||
if (empty($_SESSION['csrf_token']))
|
||||
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
||||
return $_SESSION['csrf_token'];
|
||||
}
|
||||
|
||||
public function requireCsrf(): void {
|
||||
$token = $_POST['csrf_token'] ?? $_SERVER['HTTP_X_CSRF_TOKEN'] ?? '';
|
||||
if (!is_string($token) || !hash_equals($this->csrfToken(), $token)) {
|
||||
http_response_code(403);
|
||||
exit('Your form expired. Reload the page and try again.');
|
||||
}
|
||||
}
|
||||
|
||||
public function logoutSession(): void {
|
||||
$_SESSION = [];
|
||||
session_regenerate_id(true);
|
||||
$this->initializeSession();
|
||||
$this->csrfToken();
|
||||
}
|
||||
|
||||
// ==========================
|
||||
@@ -314,12 +368,12 @@ class Base {
|
||||
|
||||
protected function encrypt($string = "", $key = "") {
|
||||
|
||||
$key = (empty($key)) ? __CLASS__ : $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);
|
||||
$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;
|
||||
@@ -366,7 +420,15 @@ class Base {
|
||||
|
||||
public function getSettings() {
|
||||
|
||||
$settings = new SimpleXMLElement($this->getXML("settings"));
|
||||
$path = getenv('HCR_SETTINGS_FILE') ?: (is_file(__DIR__ . '/../xml/settings.local.xml') ? __DIR__ . '/../xml/settings.local.xml' : __DIR__ . '/../xml/settings.xml');
|
||||
$settings = simplexml_load_file($path, SimpleXMLElement::class, LIBXML_NONET);
|
||||
if (!$settings)
|
||||
throw new RuntimeException('Unable to load application settings.');
|
||||
foreach (['Environment' => 'HCR_ENVIRONMENT', 'DatabaseServer' => 'HCR_DB_HOST', 'DatabasePort' => 'HCR_DB_PORT', 'DatabaseName' => 'HCR_DB_NAME', 'DatabaseUser' => 'HCR_DB_USER', 'DatabasePassword' => 'HCR_DB_PASSWORD', 'SmtpServer' => 'HCR_SMTP_HOST', 'SmtpUserName' => 'HCR_SMTP_USER', 'SmtpPassword' => 'HCR_SMTP_PASSWORD', 'SmtpPort' => 'HCR_SMTP_PORT', 'SmtpFromEmail' => 'HCR_SMTP_FROM', 'ApplicationUrl' => 'HCR_APPLICATION_URL'] as $name => $variable) {
|
||||
$value = getenv($variable);
|
||||
if ($value !== false)
|
||||
$settings->$name = $value;
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
@@ -378,11 +440,11 @@ class Base {
|
||||
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;
|
||||
$date = filter_input(INPUT_POST, "date", FILTER_UNSAFE_RAW) ?: $date;
|
||||
|
||||
$age = 0;
|
||||
$age = 0;
|
||||
|
||||
$date = (empty($date)) ? new Datetime() : new DateTime($date);
|
||||
$date = (empty($date)) ? new Datetime() : new DateTime($date);
|
||||
$birthdate = (empty($birthdate)) ? new Datetime() : new DateTime($birthdate);
|
||||
|
||||
$age = $birthdate->diff($date)->format("%y");
|
||||
@@ -529,8 +591,8 @@ class Base {
|
||||
return "";
|
||||
}
|
||||
|
||||
$document = "xml/" . trim($document) . ".xml";
|
||||
$XML = (file_exists($document) ? file_get_contents($document) : "");
|
||||
$document = __DIR__ . "/../xml/" . trim($document) . ".xml";
|
||||
$XML = (file_exists($document) ? file_get_contents($document) : "");
|
||||
|
||||
return $XML;
|
||||
}
|
||||
@@ -545,8 +607,8 @@ class Base {
|
||||
return "";
|
||||
}
|
||||
|
||||
$document = "xsl/" . trim($document) . ".xsl";
|
||||
$XSL = (file_exists($document) ? file_get_contents($document) : "");
|
||||
$document = __DIR__ . "/../xsl/" . trim($document) . ".xsl";
|
||||
$XSL = (file_exists($document) ? file_get_contents($document) : "");
|
||||
|
||||
return $XSL;
|
||||
}
|
||||
@@ -557,13 +619,13 @@ class Base {
|
||||
|
||||
public function getZipcode($zip_code = 0) {
|
||||
|
||||
$zip_code = filter_input(INPUT_POST, "zip_code", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$zip_code = (int) substr((string) $zip_code, 0, 5);
|
||||
$zip_code = filter_input(INPUT_POST, "zip_code", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$zip_code = (int) substr((string) $zip_code, 0, 5);
|
||||
|
||||
$zipCodeDetail = null;
|
||||
|
||||
$SQL = "select *
|
||||
from zipcodes
|
||||
$SQL = "select *
|
||||
from zipcodes
|
||||
where zipcode_code = {$zip_code}";
|
||||
|
||||
$zipcodes = $this->getTable("zipcodes", $SQL);
|
||||
@@ -571,9 +633,9 @@ class Base {
|
||||
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["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;
|
||||
}
|
||||
|
||||
@@ -592,18 +654,18 @@ class Base {
|
||||
|
||||
$settings = $this->getSettings();
|
||||
|
||||
$_SESSION[self::ACTIVE_SESSION] = true;
|
||||
$_SESSION[self::THEME] = "light";
|
||||
$_SESSION[self::ENVIRONMENT] = (string) ($settings->Environment ?? "Production");
|
||||
$_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_NAME] = "";
|
||||
$_SESSION[self::USER_FULL_NAME] = "";
|
||||
$_SESSION[self::USER_EMAIL] = "";
|
||||
$_SESSION[self::USER_ROLE] = "Guest";
|
||||
$_SESSION[self::REPORTS_GET] = "";
|
||||
$_SESSION[self::REPORTS_POST] = "";
|
||||
$_SESSION[self::AJAX] = false;
|
||||
$_SESSION[self::USER_SERIAL] = 0;
|
||||
$_SESSION[self::USER_NAME] = "";
|
||||
$_SESSION[self::USER_FULL_NAME] = "";
|
||||
$_SESSION[self::USER_EMAIL] = "";
|
||||
$_SESSION[self::USER_ROLE] = "Guest";
|
||||
$_SESSION[self::REPORTS_GET] = "";
|
||||
$_SESSION[self::REPORTS_POST] = "";
|
||||
$_SESSION[self::AJAX] = false;
|
||||
}
|
||||
|
||||
// ============
|
||||
@@ -647,7 +709,7 @@ class Base {
|
||||
$thatDOM = new DOMDocument();
|
||||
$thatDOM->loadXML($thatXML);
|
||||
|
||||
$xpath = new DOMXpath($thisDOM);
|
||||
$xpath = new DOMXpath($thisDOM);
|
||||
$xpathQuery = $xpath->query("/*");
|
||||
|
||||
for ($i = 0; $i < $xpathQuery->length; $i++) {
|
||||
@@ -665,11 +727,15 @@ class Base {
|
||||
|
||||
public function print() {
|
||||
|
||||
$_SESSION[self::REPORTS_GET] = $_GET;
|
||||
$_SESSION[self::REPORTS_GET] = $_GET;
|
||||
$_SESSION[self::REPORTS_POST] = $_POST;
|
||||
|
||||
$report = filter_input(INPUT_POST, "report") ?: "";
|
||||
|
||||
if ($report !== 'Print_All_PermitsByBuilder') {
|
||||
http_response_code(404);
|
||||
exit('Report not found.');
|
||||
}
|
||||
(new $report())->print();
|
||||
}
|
||||
|
||||
@@ -697,10 +763,10 @@ class Base {
|
||||
|
||||
public function validateDate($date = "", $format = "Y-m-d") {
|
||||
|
||||
$date = filter_input(INPUT_POST, "date") ?: $date;
|
||||
$date = filter_input(INPUT_POST, "date") ?: $date;
|
||||
|
||||
$datetime = DateTime::createFromFormat($format, $date);
|
||||
$valid = $datetime && $datetime->format($format) === $date;
|
||||
$valid = $datetime && $datetime->format($format) === $date;
|
||||
|
||||
if ($_SESSION[self::AJAX]) {
|
||||
echo json_encode($valid);
|
||||
@@ -716,10 +782,10 @@ class Base {
|
||||
public function generateRandomPassword($length = 12) {
|
||||
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()-_+=';
|
||||
$password = '';
|
||||
$password = '';
|
||||
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$index = rand(0, strlen($characters) - 1);
|
||||
$index = random_int(0, strlen($characters) - 1);
|
||||
$password .= $characters[$index];
|
||||
}
|
||||
|
||||
@@ -759,7 +825,7 @@ class Base {
|
||||
|
||||
public function testing() {
|
||||
|
||||
$to = "james.richie@onesourceits.com";
|
||||
$to = "james.richie@onesourceits.com";
|
||||
$subject = "Test Subject";
|
||||
$message = "Test Message";
|
||||
|
||||
@@ -773,19 +839,4 @@ class Base {
|
||||
// =====================
|
||||
// Forgot/Reset Password
|
||||
// =====================
|
||||
|
||||
public function resetPassword() {
|
||||
|
||||
require_once 'classes/Authentication.php';
|
||||
|
||||
$XSLParms = [
|
||||
"BTN_SUBMIT" => "main.php?action=Users.signIn&step=authenticate",
|
||||
"RESET_PASSWORD_SUCCESSFUL" => (new Authentication())->resetPassword() ? "TRUE" : "FALSE"
|
||||
];
|
||||
|
||||
echo $this->applyXSL("", $this->getXSL("signIn"), $XSLParms);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user