2026-05-29 14:52:16 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class PermitFacts 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 searchPermitFacts() {
|
|
|
|
|
|
|
|
|
|
$subscription_serial = $_SESSION['subscription_serial'];
|
|
|
|
|
$usersubscription_serial = $_SESSION['usersubscription_serial'];
|
|
|
|
|
|
|
|
|
|
$subscription = (new Subscriptions())->getSubscription($subscription_serial);
|
|
|
|
|
|
|
|
|
|
if ($subscription->count() === 0) {
|
|
|
|
|
$this->logError("Invalid Subscription ({$subscription_serial}): " . __METHOD__);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$userssubscription = (new Users())->getUserSubscription($usersubscription_serial);
|
|
|
|
|
|
|
|
|
|
$user_subscription_start_date = $userssubscription->record->usersubscription_start_date;
|
|
|
|
|
$user_subscription_end_date = $userssubscription->record->usersubscription_end_date;
|
|
|
|
|
|
|
|
|
|
$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->getPermitFactsPage($user_subscription_start_date, $user_subscription_end_date);
|
|
|
|
|
|
|
|
|
|
$searchhistory = (new SearchHistory())->getUsersPreviousSearchParameters($this->current_user_serial, $subscription_serial);
|
|
|
|
|
|
|
|
|
|
// Populate Entry Dates with what was searched for if provided or users entry dates if no entry dates were provided
|
|
|
|
|
|
|
|
|
|
$searchhistory->record->searchhistory_parameters->permitfact_entry_date_from = $permits->record->permitfact_entry_date_from;
|
|
|
|
|
$searchhistory->record->searchhistory_parameters->permitfact_entry_date_to = $permits->record->permitfact_entry_date_to;
|
|
|
|
|
|
|
|
|
|
$popovers = (new Popovers())->getPopovers();
|
|
|
|
|
$dropdowns = (new Dropdowns())->getDropdowns();
|
|
|
|
|
$cities = (new Cities())->getSubscriptionCities($subscription_serial);
|
|
|
|
|
$counties = (new Counties())->getSubscriptionCounties($subscription_serial);
|
|
|
|
|
|
|
|
|
|
$availablerecordcount = $this->userTotalAvailableRecordCount($user_subscription_start_date, $user_subscription_end_date);
|
|
|
|
|
|
|
|
|
|
$XML = $this->mergeXML($permits, "<XML/>");
|
|
|
|
|
$XML = $this->mergeXML($subscription, $XML);
|
|
|
|
|
$XML = $this->mergeXML($popovers, $XML);
|
|
|
|
|
$XML = $this->mergeXML($dropdowns, $XML);
|
|
|
|
|
$XML = $this->mergeXML($cities, $XML);
|
|
|
|
|
$XML = $this->mergeXML($counties, $XML);
|
|
|
|
|
$XML = $this->mergeXML($searchhistory, $XML);
|
|
|
|
|
$XML = $this->mergeXML($availablerecordcount, $XML);
|
|
|
|
|
|
|
|
|
|
$content = $this->applyXSL($XML, $this->getXSL("searchPermitFacts"));
|
|
|
|
|
$this->displayContent($content);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
// =================================
|
|
|
|
|
// Return a Permit Facts Page Object
|
|
|
|
|
// =================================
|
2026-05-29 14:52:16 -04:00
|
|
|
|
|
|
|
|
public function getPermitFactsPage($user_subscription_start_date, $user_subscription_end_date) {
|
|
|
|
|
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
|
|
|
|
|
$connection = $this->connect();
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$post = function ($name) {
|
|
|
|
|
return trim((string) (filter_input(INPUT_POST, $name) ?: ""));
|
|
|
|
|
};
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$dateOrNull = function ($value) {
|
|
|
|
|
if ($value === "") {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$timestamp = strtotime($value);
|
|
|
|
|
return $timestamp ? date("Y-m-d", $timestamp) : null;
|
|
|
|
|
};
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$numberOrNull = function ($value) {
|
|
|
|
|
$value = str_replace([",", "$"], "", trim((string) $value));
|
|
|
|
|
return is_numeric($value) ? $value : null;
|
|
|
|
|
};
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$addInClause = function (&$where, &$params, $column, $rawValue, $prefix) {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($rawValue === "") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$items = array_filter(array_map(function ($item) {
|
|
|
|
|
return trim($item, " \t\n\r\0\x0B'\"");
|
|
|
|
|
}, explode(",", $rawValue)));
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if (empty($items)) {
|
|
|
|
|
return;
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$placeholders = [];
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
foreach ($items as $index => $item) {
|
|
|
|
|
$param = ":{$prefix}_{$index}";
|
|
|
|
|
$placeholders[] = $param;
|
|
|
|
|
$params[$param] = $item;
|
|
|
|
|
}
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$where[] = "{$column} IN (" . implode(", ", $placeholders) . ")";
|
|
|
|
|
};
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
// ----------------------------
|
|
|
|
|
// Subscription Date Restriction
|
|
|
|
|
// ----------------------------
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$oneYearAgo = date("Y-m-d", strtotime("-1 year"));
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($user_subscription_start_date <= $oneYearAgo) {
|
|
|
|
|
$user_subscription_start_date = $oneYearAgo;
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
// -----------
|
|
|
|
|
// POST Values
|
|
|
|
|
// -----------
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$permitfact_company = $post("permitfact_company");
|
|
|
|
|
$permitfact_project_name = $post("permitfact_project_name");
|
|
|
|
|
$permitfact_project_zip = $post("permitfact_project_zip");
|
|
|
|
|
$permitfact_project_city = $post("permitfact_project_city");
|
|
|
|
|
$permitfact_county = $post("permitfact_county");
|
|
|
|
|
$permitfact_project_type = $post("permitfact_project_type");
|
|
|
|
|
$permitfact_work_type = $post("permitfact_work_type");
|
|
|
|
|
$permitfact_building_type = $post("permitfact_building_type");
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$permitfact_size_from = $numberOrNull($post("permitfact_size_from"));
|
|
|
|
|
$permitfact_size_to = $numberOrNull($post("permitfact_size_to"));
|
|
|
|
|
$permitfact_value_from = $numberOrNull($post("permitfact_value_from"));
|
|
|
|
|
$permitfact_value_to = $numberOrNull($post("permitfact_value_to"));
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$permitfact_permit_date_from = $dateOrNull($post("permitfact_permit_date_from"));
|
|
|
|
|
$permitfact_permit_date_to = $dateOrNull($post("permitfact_permit_date_to"));
|
|
|
|
|
$permitfact_entry_date_from = $dateOrNull($post("permitfact_entry_date_from"));
|
|
|
|
|
$permitfact_entry_date_to = $dateOrNull($post("permitfact_entry_date_to"));
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$pagination = $post("pagination");
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$this->pagination_size = filter_input(INPUT_POST, "permitfacts_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
// -----------------
|
|
|
|
|
// Build SQL Filters
|
|
|
|
|
// -----------------
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$where = [];
|
|
|
|
|
$params = [];
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
/*
|
|
|
|
|
* This is the required subscription gate.
|
|
|
|
|
* It always limits records by entry date.
|
|
|
|
|
*/
|
|
|
|
|
$where[] = "view_permitfacts.permitfact_entry_date BETWEEN :user_subscription_start_date AND :user_subscription_end_date";
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$params[":user_subscription_start_date"] = $user_subscription_start_date;
|
|
|
|
|
$params[":user_subscription_end_date"] = $user_subscription_end_date;
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($permitfact_company !== "") {
|
|
|
|
|
$where[] = "view_permitfacts.permitfact_company REGEXP :permitfact_company";
|
|
|
|
|
$params[":permitfact_company"] = $permitfact_company;
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($permitfact_project_name !== "") {
|
|
|
|
|
$where[] = "view_permitfacts.permitfact_project_name REGEXP :permitfact_project_name";
|
|
|
|
|
$params[":permitfact_project_name"] = $permitfact_project_name;
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($permitfact_project_zip !== "") {
|
|
|
|
|
$where[] = "view_permitfacts.permitfact_project_zip = :permitfact_project_zip";
|
|
|
|
|
$params[":permitfact_project_zip"] = $permitfact_project_zip;
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$addInClause($where, $params, "view_permitfacts.permitfact_project_city", $permitfact_project_city, "city");
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($permitfact_county !== "") {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$addInClause($where, $params, "view_permitfacts.permitfact_county", $permitfact_county, "county");
|
|
|
|
|
} else {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$counties = (new Counties())->getSubscriptionCounties($_SESSION["subscription_serial"]);
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$countyList = [];
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
foreach ($counties as $county) {
|
|
|
|
|
$countyList[] = (string) $county->subscriptioncounty_county;
|
|
|
|
|
}
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if (!empty($countyList)) {
|
|
|
|
|
$addInClause(
|
|
|
|
|
$where,
|
|
|
|
|
$params,
|
|
|
|
|
"view_permitfacts.permitfact_county",
|
|
|
|
|
implode(",", $countyList),
|
|
|
|
|
"sub_county"
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$addInClause($where, $params, "view_permitfacts.permitfact_project_type", $permitfact_project_type, "project_type");
|
|
|
|
|
$addInClause($where, $params, "view_permitfacts.permitfact_work_type", $permitfact_work_type, "work_type");
|
|
|
|
|
$addInClause($where, $params, "view_permitfacts.permitfact_building_type", $permitfact_building_type, "building_type");
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
// -----------
|
|
|
|
|
// Size Filter
|
|
|
|
|
// -----------
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($permitfact_size_from !== null && $permitfact_size_to !== null) {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($permitfact_size_from > $permitfact_size_to) {
|
|
|
|
|
[$permitfact_size_from, $permitfact_size_to] = [$permitfact_size_to, $permitfact_size_from];
|
|
|
|
|
}
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$where[] = "view_permitfacts.permitfact_size BETWEEN :permitfact_size_from AND :permitfact_size_to";
|
|
|
|
|
$params[":permitfact_size_from"] = $permitfact_size_from;
|
|
|
|
|
$params[":permitfact_size_to"] = $permitfact_size_to;
|
|
|
|
|
} elseif ($permitfact_size_from !== null) {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$where[] = "view_permitfacts.permitfact_size >= :permitfact_size_from";
|
|
|
|
|
$params[":permitfact_size_from"] = $permitfact_size_from;
|
|
|
|
|
} elseif ($permitfact_size_to !== null) {
|
|
|
|
|
|
|
|
|
|
$where[] = "view_permitfacts.permitfact_size <= :permitfact_size_to";
|
|
|
|
|
$params[":permitfact_size_to"] = $permitfact_size_to;
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
// -----------
|
|
|
|
|
// Value Filter
|
|
|
|
|
// -----------
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($permitfact_value_from !== null && $permitfact_value_to !== null) {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($permitfact_value_from > $permitfact_value_to) {
|
|
|
|
|
[$permitfact_value_from, $permitfact_value_to] = [$permitfact_value_to, $permitfact_value_from];
|
|
|
|
|
}
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$where[] = "view_permitfacts.permitfact_value BETWEEN :permitfact_value_from AND :permitfact_value_to";
|
|
|
|
|
$params[":permitfact_value_from"] = $permitfact_value_from;
|
|
|
|
|
$params[":permitfact_value_to"] = $permitfact_value_to;
|
|
|
|
|
} elseif ($permitfact_value_from !== null) {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$where[] = "view_permitfacts.permitfact_value >= :permitfact_value_from";
|
|
|
|
|
$params[":permitfact_value_from"] = $permitfact_value_from;
|
|
|
|
|
} elseif ($permitfact_value_to !== null) {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$where[] = "view_permitfacts.permitfact_value <= :permitfact_value_to";
|
|
|
|
|
$params[":permitfact_value_to"] = $permitfact_value_to;
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
// ------------------
|
|
|
|
|
// Permit Date Filter
|
|
|
|
|
// ------------------
|
|
|
|
|
// This is optional and works WITH the entry-date subscription gate.
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($permitfact_permit_date_from !== null && $permitfact_permit_date_to !== null) {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($permitfact_permit_date_from > $permitfact_permit_date_to) {
|
|
|
|
|
[$permitfact_permit_date_from, $permitfact_permit_date_to] = [
|
|
|
|
|
$permitfact_permit_date_to,
|
|
|
|
|
$permitfact_permit_date_from
|
|
|
|
|
];
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$where[] = "view_permitfacts.permitfact_permit_date BETWEEN :permit_date_from AND :permit_date_to";
|
|
|
|
|
$params[":permit_date_from"] = $permitfact_permit_date_from;
|
|
|
|
|
$params[":permit_date_to"] = $permitfact_permit_date_to;
|
|
|
|
|
} elseif ($permitfact_permit_date_from !== null) {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$where[] = "view_permitfacts.permitfact_permit_date = :permit_date_from";
|
|
|
|
|
$params[":permit_date_from"] = $permitfact_permit_date_from;
|
|
|
|
|
} elseif ($permitfact_permit_date_to !== null) {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$where[] = "view_permitfacts.permitfact_permit_date = :permit_date_to";
|
|
|
|
|
$params[":permit_date_to"] = $permitfact_permit_date_to;
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
// -----------------
|
|
|
|
|
// Entry Date Filter
|
|
|
|
|
// -----------------
|
|
|
|
|
// This further narrows the already-required subscription entry-date gate.
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($permitfact_entry_date_from !== null && $permitfact_entry_date_to !== null) {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($permitfact_entry_date_from > $permitfact_entry_date_to) {
|
|
|
|
|
[$permitfact_entry_date_from, $permitfact_entry_date_to] = [
|
|
|
|
|
$permitfact_entry_date_to,
|
|
|
|
|
$permitfact_entry_date_from
|
|
|
|
|
];
|
|
|
|
|
}
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$where[] = "view_permitfacts.permitfact_entry_date BETWEEN :entry_date_from AND :entry_date_to";
|
|
|
|
|
$params[":entry_date_from"] = $permitfact_entry_date_from;
|
|
|
|
|
$params[":entry_date_to"] = $permitfact_entry_date_to;
|
|
|
|
|
} elseif ($permitfact_entry_date_from !== null) {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$where[] = "view_permitfacts.permitfact_entry_date >= :entry_date_from";
|
|
|
|
|
$params[":entry_date_from"] = $permitfact_entry_date_from;
|
|
|
|
|
} elseif ($permitfact_entry_date_to !== null) {
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$where[] = "view_permitfacts.permitfact_entry_date <= :entry_date_to";
|
|
|
|
|
$params[":entry_date_to"] = $permitfact_entry_date_to;
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$whereSQL = implode(" AND ", $where);
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
// ------------
|
|
|
|
|
// Record Count
|
|
|
|
|
// ------------
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$countSQL = "
|
|
|
|
|
SELECT COUNT(*) AS count
|
|
|
|
|
FROM view_permitfacts
|
|
|
|
|
WHERE {$whereSQL}
|
|
|
|
|
";
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$statement = $connection->prepare($countSQL);
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
foreach ($params as $param => $value) {
|
|
|
|
|
$statement->bindValue($param, $value, PDO::PARAM_STR);
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$statement->execute();
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$recordset = $statement->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
$count = $recordset ? (int) $recordset["count"] : 0;
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
// ----------
|
|
|
|
|
// Pagination
|
|
|
|
|
// ----------
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$totalPages = max(1, (int) ceil($count / $this->pagination_size));
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
switch ($pagination) {
|
|
|
|
|
case "first":
|
|
|
|
|
$this->pagination_page = 1;
|
|
|
|
|
break;
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
case "previous":
|
|
|
|
|
$this->pagination_page = max($this->pagination_page - 1, 1);
|
|
|
|
|
break;
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
case "next":
|
|
|
|
|
$this->pagination_page = min($this->pagination_page + 1, $totalPages);
|
|
|
|
|
break;
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
case "last":
|
|
|
|
|
$this->pagination_page = $totalPages;
|
|
|
|
|
break;
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
default:
|
|
|
|
|
$this->pagination_page = max(1, min($this->pagination_page, $totalPages));
|
|
|
|
|
break;
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$offset = max(0, ($this->pagination_page - 1) * $this->pagination_size);
|
|
|
|
|
$start = $count > 0 ? $offset + 1 : 0;
|
|
|
|
|
$end = min($count, $offset + $this->pagination_size);
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
// ----------
|
|
|
|
|
// Data Query
|
|
|
|
|
// ----------
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$dataSQL = "
|
|
|
|
|
SELECT view_permitfacts.*
|
|
|
|
|
FROM view_permitfacts
|
|
|
|
|
WHERE {$whereSQL}
|
|
|
|
|
ORDER BY view_permitfacts.permitfact_entry_date DESC,
|
|
|
|
|
view_permitfacts.permitfact_permit_date DESC
|
|
|
|
|
";
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($pagination !== "off") {
|
|
|
|
|
$dataSQL .= "
|
|
|
|
|
LIMIT :limit
|
|
|
|
|
OFFSET :offset
|
|
|
|
|
";
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$statement = $connection->prepare($dataSQL);
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
foreach ($params as $param => $value) {
|
|
|
|
|
$statement->bindValue($param, $value, PDO::PARAM_STR);
|
|
|
|
|
}
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if ($pagination !== "off") {
|
|
|
|
|
$statement->bindValue(":limit", (int) $this->pagination_size, PDO::PARAM_INT);
|
|
|
|
|
$statement->bindValue(":offset", (int) $offset, PDO::PARAM_INT);
|
2026-05-29 14:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$statement->execute();
|
|
|
|
|
|
|
|
|
|
$permitfacts = $this->getTableXML("permitfacts", $statement);
|
|
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
if (!isset($permitfacts->record)) {
|
|
|
|
|
$permitfacts->addChild("record");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$permitfacts->record->permitfact_entry_date_from = !empty($permitfact_entry_date_from) ? date("m/d/Y", strtotime($permitfact_entry_date_from)) : date("m/d/Y", strtotime($user_subscription_start_date));
|
|
|
|
|
|
|
|
|
|
$permitfacts->record->permitfact_entry_date_to = !empty($permitfact_entry_date_to) ? date("m/d/Y", strtotime($permitfact_entry_date_to)) : date("m/d/Y", strtotime($user_subscription_end_date));
|
|
|
|
|
|
|
|
|
|
$permitfacts->record->permitfact_permit_date_from = !empty($permitfact_permit_date_from) ? date("m/d/Y", strtotime($permitfact_permit_date_from)) : "";
|
2026-05-29 14:52:16 -04:00
|
|
|
|
2026-06-13 11:13:36 -04:00
|
|
|
$permitfacts->record->permitfact_permit_date_to = !empty($permitfact_permit_date_to) ? date("m/d/Y", strtotime($permitfact_permit_date_to)) : "";
|
2026-05-29 14:52:16 -04:00
|
|
|
|
|
|
|
|
$permitfacts->addAttribute("count", $count);
|
|
|
|
|
$permitfacts->addAttribute("start", $start);
|
|
|
|
|
$permitfacts->addAttribute("end", $end);
|
|
|
|
|
$permitfacts->addAttribute("page", $this->pagination_page);
|
|
|
|
|
|
|
|
|
|
$_SESSION[self::PAGINATION_PAGE] = $this->pagination_page;
|
|
|
|
|
|
|
|
|
|
return $permitfacts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================================
|
|
|
|
|
// Users Total Available Record Count
|
|
|
|
|
// ==================================
|
|
|
|
|
|
|
|
|
|
public function userTotalAvailableRecordCount($user_subscription_start_date, $user_subscription_end_date) {
|
|
|
|
|
|
|
|
|
|
// determine real date range based upon users subscription start date
|
|
|
|
|
|
|
|
|
|
if ($user_subscription_start_date <= date('Y-m-d', strtotime('-1 year'))) {
|
|
|
|
|
$user_subscription_start_date = date('Y-m-d', strtotime('-1 year'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$SQL = "select count(*) as count
|
|
|
|
|
from view_permitfacts
|
|
|
|
|
where view_permitfacts.permitfact_entry_date between '{$user_subscription_start_date}' and '{$user_subscription_end_date}' ";
|
|
|
|
|
|
|
|
|
|
$counties = (new Counties())->getSubscriptionCounties($_SESSION['subscription_serial']);
|
|
|
|
|
|
|
|
|
|
$countyNames = [];
|
|
|
|
|
|
|
|
|
|
foreach ($counties as $county) {
|
|
|
|
|
$countyNames[] = " " . (string) $county->subscriptioncounty_county . " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$permitfact_county = ' ' . implode(', ', $countyNames) . ' ';
|
|
|
|
|
|
|
|
|
|
$SQL .= " and view_permitfacts.permitfact_county in ($permitfact_county) ";
|
|
|
|
|
|
|
|
|
|
return $this->getTable("userstotalavailablerecords", $SQL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ======================
|
|
|
|
|
// Get Users Full Dataset
|
|
|
|
|
// ======================
|
|
|
|
|
|
|
|
|
|
public function getPermitFactsFullDataset($user_subscription_start_date, $user_subscription_end_date) {
|
|
|
|
|
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
|
|
|
|
|
$connection = $this->connect();
|
|
|
|
|
|
|
|
|
|
$SQL = "select view_permitfacts.*
|
|
|
|
|
from view_permitfacts
|
|
|
|
|
where view_permitfacts.permitfact_entry_date between :user_subscription_start_date and :user_subscription_end_date";
|
|
|
|
|
|
|
|
|
|
$statement = $connection->prepare($SQL);
|
|
|
|
|
|
|
|
|
|
$statement->bindValue(":user_subscription_start_date", $user_subscription_start_date, PDO::PARAM_STR);
|
|
|
|
|
$statement->bindValue(":user_subscription_end_date", $user_subscription_end_date, PDO::PARAM_STR);
|
|
|
|
|
|
|
|
|
|
$statement->execute();
|
|
|
|
|
|
|
|
|
|
$permitfacts = $this->getTableXML("permitfacts", $statement);
|
|
|
|
|
|
|
|
|
|
return $permitfacts;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|