updated boolean and interger to php8.5 standard
This commit is contained in:
@@ -0,0 +1,470 @@
|
||||
<?php
|
||||
|
||||
// ====================
|
||||
// Business Facts Class
|
||||
// ====================
|
||||
|
||||
class BusinessFacts 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;
|
||||
}
|
||||
|
||||
// =====================
|
||||
// Manage Business Facts
|
||||
// =====================
|
||||
|
||||
public function manageBusinessFacts() {
|
||||
|
||||
$businessfacts = $this->getBusinessFactsPage();
|
||||
$popovers = (new Popovers())->getPopovers();
|
||||
|
||||
$XML = $this->mergeXML($businessfacts, "<XML/>");
|
||||
$XML = $this->mergeXML($popovers, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("manageBusinessFacts"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
// =====================
|
||||
// Business Fact Summary
|
||||
// =====================
|
||||
|
||||
public function businessfactSummary() {
|
||||
|
||||
$businessfact_serial = filter_input(INPUT_POST, "businessfact_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$businessfact = $this->getBusinessFact($businessfact_serial);
|
||||
|
||||
if ($businessfact->count() == 0) {
|
||||
$this->logError("Invalid Business Fact ({$businessfact_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$businessfactemployees = $this->getBusinessFactEmployees($businessfact_serial);
|
||||
$businessfactmaterials = $this->getBusinessFactMaterials($businessfact_serial);
|
||||
$businessfactnotes = $this->getBusinessFactNotes($businessfact_serial);
|
||||
$attachments = (new Attachments())->getAttachments("BusinessFacts", $businessfact_serial);
|
||||
|
||||
$XML = $this->mergeXML($businessfact, "<XML/>");
|
||||
$XML = $this->mergeXML($businessfactemployees, $XML);
|
||||
$XML = $this->mergeXML($businessfactmaterials, $XML);
|
||||
$XML = $this->mergeXML($businessfactnotes, $XML);
|
||||
$XML = $this->mergeXML($attachments, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("businessfactSummary"));
|
||||
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
// ===============
|
||||
// Add Business Fact
|
||||
// ===============
|
||||
|
||||
public function addBusinessFact() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$constants = $this->getConstants();
|
||||
$dropdowns = (new Dropdowns())->getDropdowns();
|
||||
$counties = (new Counties())->getCounties();
|
||||
$cities = (new Cities())->getCities();
|
||||
|
||||
$XML = $this->mergeXML($dropdowns, "<XML/>");
|
||||
$XML = $this->mergeXML($counties, $XML);
|
||||
$XML = $this->mergeXML($cities, $XML);
|
||||
$XML = $this->mergeXML($constants, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("addBusinessFact"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "add":
|
||||
|
||||
$businessfact_business_number = filter_input(INPUT_POST, "businessfact_business_number") ?: "";
|
||||
$businessfact_project_name = filter_input(INPUT_POST, "businessfact_project_name") ?: "";
|
||||
$businessfact_parcel_number = filter_input(INPUT_POST, "businessfact_parcel_number") ?: "";
|
||||
$businessfact_project_type = filter_input(INPUT_POST, "businessfact_project_type", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_business_date = filter_input(INPUT_POST, "businessfact_business_date") ?: "";
|
||||
$businessfact_county_code = filter_input(INPUT_POST, "businessfact_county_code", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_subdivision = filter_input(INPUT_POST, "businessfact_subdivision") ?: "";
|
||||
$businessfact_project_address = filter_input(INPUT_POST, "businessfact_project_address") ?: "";
|
||||
$businessfact_project_city = filter_input(INPUT_POST, "businessfact_project_city") ?: "";
|
||||
$businessfact_project_state = filter_input(INPUT_POST, "businessfact_project_state") ?: "";
|
||||
$businessfact_project_zipcode = filter_input(INPUT_POST, "businessfact_project_zipcode", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_size = filter_input(INPUT_POST, "businessfact_size", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_value = filter_input(INPUT_POST, "businessfact_value", FILTER_VALIDATE_FLOAT) ?: 0.00;
|
||||
$businessfact_work_type = filter_input(INPUT_POST, "businessfact_work_type", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_building_type = filter_input(INPUT_POST, "businessfact_building_type", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_lotblock = filter_input(INPUT_POST, "businessfact_lotblock", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_districtlandlot = filter_input(INPUT_POST, "businessfact_districtlandlot", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_units = filter_input(INPUT_POST, "businessfact_units", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
// Format Dates
|
||||
|
||||
$businessfact_business_date = ($businessfact_business_date == "") ? null : date("Y-m-d", strtotime($businessfact_business_date));
|
||||
|
||||
$businessfact_subdivision = (new Subdivisions())->getSubdivisionByName($businessfact_subdivision)->subdivision_serial;
|
||||
|
||||
$SQL = "insert into businessfacts
|
||||
|
||||
( businessfact_business_number,
|
||||
businessfact_project_name,
|
||||
businessfact_parcel_number,
|
||||
businessfact_project_type,
|
||||
businessfact_business_date,
|
||||
businessfact_county_code,
|
||||
businessfact_subdivision,
|
||||
businessfact_project_address,
|
||||
businessfact_project_city,
|
||||
businessfact_project_state,
|
||||
businessfact_project_zipcode,
|
||||
businessfact_size,
|
||||
businessfact_value,
|
||||
businessfact_work_type,
|
||||
businessfact_building_type,
|
||||
businessfact_lotblock,
|
||||
businessfact_districtlandlot,
|
||||
businessfact_units,
|
||||
businessfact_created,
|
||||
businessfact_created_user )
|
||||
|
||||
values ( :businessfact_business_number,
|
||||
:businessfact_project_name,
|
||||
:businessfact_parcel_number,
|
||||
:businessfact_project_type,
|
||||
:businessfact_business_date,
|
||||
:businessfact_county_code,
|
||||
:businessfact_subdivision,
|
||||
:businessfact_project_address,
|
||||
:businessfact_project_city,
|
||||
:businessfact_project_state,
|
||||
:businessfact_project_zipcode,
|
||||
:businessfact_size,
|
||||
:businessfact_value,
|
||||
:businessfact_work_type,
|
||||
:businessfact_building_type,
|
||||
:businessfact_lotblock,
|
||||
:businessfact_districtlandlot,
|
||||
:businessfact_units,
|
||||
:businessfact_created,
|
||||
:businessfact_created_user )";
|
||||
|
||||
$connection = $this->connect();
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":businessfact_business_number", $businessfact_business_number);
|
||||
$statement->bindValue(":businessfact_project_name", $businessfact_project_name);
|
||||
$statement->bindValue(":businessfact_parcel_number", $businessfact_parcel_number);
|
||||
$statement->bindValue(":businessfact_project_type", $businessfact_project_type);
|
||||
$statement->bindValue(":businessfact_business_date", $businessfact_business_date);
|
||||
$statement->bindValue(":businessfact_county_code", $businessfact_county_code);
|
||||
$statement->bindValue(":businessfact_subdivision", $businessfact_subdivision);
|
||||
$statement->bindValue(":businessfact_project_address", $businessfact_project_address);
|
||||
$statement->bindValue(":businessfact_project_city", $businessfact_project_city);
|
||||
$statement->bindValue(":businessfact_project_state", $businessfact_project_state);
|
||||
$statement->bindValue(":businessfact_project_zipcode", $businessfact_project_zipcode);
|
||||
$statement->bindValue(":businessfact_size", $businessfact_size);
|
||||
$statement->bindValue(":businessfact_value", $businessfact_value);
|
||||
$statement->bindValue(":businessfact_work_type", $businessfact_work_type);
|
||||
$statement->bindValue(":businessfact_building_type", $businessfact_building_type);
|
||||
$statement->bindValue(":businessfact_lotblock", $businessfact_lotblock);
|
||||
$statement->bindValue(":businessfact_districtlandlot", $businessfact_districtlandlot);
|
||||
$statement->bindValue(":businessfact_units", $businessfact_units);
|
||||
$statement->bindValue(":businessfact_created", $this->getTimestamp());
|
||||
$statement->bindValue(":businessfact_created_user", $this->current_user_name);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ================
|
||||
// Edit Business Fact
|
||||
// ================
|
||||
|
||||
public function editBusinessFact() {
|
||||
|
||||
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
||||
|
||||
switch ($step) {
|
||||
|
||||
case "prompt":
|
||||
|
||||
$businessfact_serial = filter_input(INPUT_POST, "businessfact_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$businessfact = $this->getBusinessFact($businessfact_serial);
|
||||
|
||||
if ($businessfact->count() == 0) {
|
||||
$this->logError("Invalid Business Fact ({$businessfact_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
$constants = $this->getConstants();
|
||||
$dropdowns = (new Dropdowns())->getDropdowns();
|
||||
$counties = (new Counties())->getCounties();
|
||||
$cities = (new Cities())->getCities();
|
||||
|
||||
$XML = $this->mergeXML($businessfact, "<XML/>");
|
||||
$XML = $this->mergeXML($dropdowns, $XML);
|
||||
$XML = $this->mergeXML($counties, $XML);
|
||||
$XML = $this->mergeXML($cities, $XML);
|
||||
$XML = $this->mergeXML($constants, $XML);
|
||||
|
||||
$content = $this->applyXSL($XML, $this->getXSL("editBusinessFact"));
|
||||
|
||||
$this->displayContent($content);
|
||||
|
||||
break;
|
||||
|
||||
case "update":
|
||||
|
||||
$businessfact_serial = filter_input(INPUT_POST, "businessfact_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_requestor = filter_input(INPUT_POST, "businessfact_requestor") ?: "";
|
||||
$businessfact_requestor_address = filter_input(INPUT_POST, "businessfact_requestor_address") ?: "";
|
||||
$businessfact_requestor_phone = filter_input(INPUT_POST, "businessfact_requestor_phone") ?: "";
|
||||
$businessfact_requestor_email = filter_input(INPUT_POST, "businessfact_requestor_email") ?: "";
|
||||
$businessfact_requestor_callback = filter_input(INPUT_POST, "businessfact_requestor_callback", FILTER_VALIDATE_BOOLEAN) ?: false;
|
||||
$businessfact_worktype = filter_input(INPUT_POST, "businessfact_worktype", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_priority = filter_input(INPUT_POST, "businessfact_priority", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_facility = filter_input(INPUT_POST, "businessfact_facility", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_department = filter_input(INPUT_POST, "businessfact_department", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_employee = filter_input(INPUT_POST, "businessfact_employee", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_status = filter_input(INPUT_POST, "businessfact_status", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_fema = filter_input(INPUT_POST, "businessfact_fema", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$businessfact_location = filter_input(INPUT_POST, "businessfact_location") ?: "";
|
||||
$businessfact_description = filter_input(INPUT_POST, "businessfact_description") ?: "";
|
||||
$businessfact_completed = filter_input(INPUT_POST, "businessfact_completed") ?: "";
|
||||
|
||||
// Format Dates
|
||||
|
||||
$businessfact_completed = ($businessfact_completed == "") ? null : date("Y-m-d", strtotime($businessfact_completed));
|
||||
|
||||
// Convert 0 to null for Foreign Keys
|
||||
|
||||
$businessfact_worktype = ($businessfact_worktype !== 0) ? $businessfact_worktype : null;
|
||||
$businessfact_priority = ($businessfact_priority !== 0) ? $businessfact_priority : null;
|
||||
$businessfact_facility = ($businessfact_facility !== 0) ? $businessfact_facility : null;
|
||||
$businessfact_department = ($businessfact_department !== 0) ? $businessfact_department : null;
|
||||
$businessfact_employee = ($businessfact_employee !== 0) ? $businessfact_employee : null;
|
||||
$businessfact_status = ($businessfact_status !== 0) ? $businessfact_status : null;
|
||||
$businessfact_fema = ($businessfact_fema !== 0) ? $businessfact_fema : null;
|
||||
|
||||
// Verify the Business Fact
|
||||
|
||||
$businessfact = $this->getBusinessFact($businessfact_serial);
|
||||
|
||||
if ($businessfact->count() == 0) {
|
||||
$this->logError("Invalid Business Fact ({$businessfact_serial}). " . __METHOD__);
|
||||
}
|
||||
|
||||
// Update the Business Fact
|
||||
|
||||
$SQL = "update businessfacts
|
||||
set businessfact_requestor = :businessfact_requestor,
|
||||
businessfact_requestor_address = :businessfact_requestor_address,
|
||||
businessfact_requestor_phone = :businessfact_requestor_phone,
|
||||
businessfact_requestor_email = :businessfact_requestor_email,
|
||||
businessfact_requestor_callback = :businessfact_requestor_callback,
|
||||
businessfact_worktype = :businessfact_worktype,
|
||||
businessfact_priority = :businessfact_priority,
|
||||
businessfact_facility = :businessfact_facility,
|
||||
businessfact_department = :businessfact_department,
|
||||
businessfact_employee = :businessfact_employee,
|
||||
businessfact_status = :businessfact_status,
|
||||
businessfact_fema = :businessfact_fema,
|
||||
businessfact_location = :businessfact_location,
|
||||
businessfact_description = :businessfact_description,
|
||||
businessfact_completed = :businessfact_completed,
|
||||
businessfact_origin = :businessfact_origin
|
||||
where businessfact_serial = :businessfact_serial";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":businessfact_serial", $businessfact_serial);
|
||||
$statement->bindValue(":businessfact_requestor", $businessfact_requestor);
|
||||
$statement->bindValue(":businessfact_requestor_address", $businessfact_requestor_address);
|
||||
$statement->bindValue(":businessfact_requestor_phone", $businessfact_requestor_phone);
|
||||
$statement->bindValue(":businessfact_requestor_email", $businessfact_requestor_email);
|
||||
$statement->bindValue(":businessfact_requestor_callback", $businessfact_requestor_callback, PDO::PARAM_BOOL);
|
||||
$statement->bindValue(":businessfact_worktype", $businessfact_worktype);
|
||||
$statement->bindValue(":businessfact_priority", $businessfact_priority);
|
||||
$statement->bindValue(":businessfact_facility", $businessfact_facility);
|
||||
$statement->bindValue(":businessfact_department", $businessfact_department);
|
||||
$statement->bindValue(":businessfact_employee", $businessfact_employee);
|
||||
$statement->bindValue(":businessfact_status", $businessfact_status);
|
||||
$statement->bindValue(":businessfact_fema", $businessfact_fema);
|
||||
$statement->bindValue(":businessfact_location", $businessfact_location);
|
||||
$statement->bindValue(":businessfact_description", $businessfact_description);
|
||||
$statement->bindValue(":businessfact_completed", $businessfact_completed);
|
||||
$statement->bindValue(":businessfact_origin", $this->current_user_name);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$this->displayHome();
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Return a Business Fact Object
|
||||
// ===========================
|
||||
|
||||
public function getBusinessFact($businessfact_serial = 0) {
|
||||
|
||||
$SQL = "select view_businessfacts.*
|
||||
from view_businessfacts
|
||||
where businessfact_serial = {$businessfact_serial}";
|
||||
|
||||
return $this->getTable("businessfacts", $SQL);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Return a Business Facts Page Object
|
||||
// =================================
|
||||
|
||||
public function getBusinessFactsPage() {
|
||||
|
||||
// Find Criteria
|
||||
|
||||
$find_businessfact = filter_input(INPUT_POST, "find_businessfact") ?: "";
|
||||
$businessfact_released = filter_input(INPUT_POST, "businessfact_released") ?: "true";
|
||||
|
||||
$this->pagination_size = filter_input(INPUT_POST, "businessfacts_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
||||
|
||||
$businessfacts_order_by = filter_input(INPUT_POST, "businessfacts_order_by") ?: "";
|
||||
$businessfacts_order_direction = filter_input(INPUT_POST, "businessfacts_order_direction") ?: "";
|
||||
|
||||
if ($businessfacts_order_by === "") {
|
||||
$orderby = "businessfact_entry_date asc";
|
||||
} else {
|
||||
$orderby = $businessfacts_order_by . " " . $businessfacts_order_direction;
|
||||
}
|
||||
|
||||
$find_businessfact = $this->sanitizeString($find_businessfact);
|
||||
|
||||
$businessfact_released = ($businessfact_released == "true") ? 1 : 0;
|
||||
|
||||
$find_words = implode("|", explode(" ", $find_businessfact));
|
||||
|
||||
// Record Count
|
||||
|
||||
$connection = $this->connect();
|
||||
|
||||
$SQL = "select count(*) as count
|
||||
from view_businessfacts
|
||||
where (businessfact_business_number regexp :businessfact_business_number
|
||||
or businessfact_project_name regexp :businessfact_project_name
|
||||
or businessfact_business_date regexp :businessfact_business_date
|
||||
or businessfact_entry_date regexp :businessfact_entry_date
|
||||
or businessfact_project_address regexp :businessfact_project_address )
|
||||
and businessfact_released = {$businessfact_released} ";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":businessfact_business_number", $find_words);
|
||||
$statement->bindValue(":businessfact_project_name", $find_words);
|
||||
$statement->bindValue(":businessfact_business_date", $find_words);
|
||||
$statement->bindValue(":businessfact_entry_date", $find_words);
|
||||
$statement->bindValue(":businessfact_project_address", $find_words);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$count = (count($recordset) > 0) ? (int) $recordset["count"] : (int) 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_businessfacts.*
|
||||
from view_businessfacts
|
||||
where (businessfact_business_number regexp :businessfact_business_number
|
||||
or businessfact_project_name regexp :businessfact_project_name
|
||||
or businessfact_business_date regexp :businessfact_business_date
|
||||
or businessfact_entry_date regexp :businessfact_entry_date
|
||||
or businessfact_project_address regexp :businessfact_project_address )
|
||||
and businessfact_released = {$businessfact_released}
|
||||
order by {$orderby}
|
||||
limit {$this->pagination_size}
|
||||
offset {$offset}";
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":businessfact_business_number", $find_words);
|
||||
$statement->bindValue(":businessfact_project_name", $find_words);
|
||||
$statement->bindValue(":businessfact_business_date", $find_words);
|
||||
$statement->bindValue(":businessfact_entry_date", $find_words);
|
||||
$statement->bindValue(":businessfact_project_address", $find_words);
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$businessfacts = $this->getTableXML("businessfacts", $statement);
|
||||
|
||||
// Insert Pagination Attributes
|
||||
|
||||
$businessfacts->addAttribute("count", $count);
|
||||
$businessfacts->addAttribute("start", $start);
|
||||
$businessfacts->addAttribute("end", $end);
|
||||
$businessfacts->addAttribute("page", $this->pagination_page);
|
||||
|
||||
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
||||
|
||||
return $businessfacts;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user