Various Issues have been resolved in this commit.
This commit is contained in:
+3
-1
@@ -37,8 +37,10 @@ class Export extends Base {
|
||||
// Create Export Request
|
||||
// =====================
|
||||
|
||||
public function createExportRequest() {
|
||||
public function createExportRequest($subscription_serial = 0, $export_type = "", $report_type = "") {
|
||||
|
||||
$this->debug($_POST);
|
||||
|
||||
$subscription_serial = filter_input(INPUT_POST, "subscription_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
|
||||
$subscription = (new Subscriptions())->getSubscription($subscription_serial);
|
||||
|
||||
+278
-399
@@ -87,479 +87,358 @@ class PermitFacts extends Base {
|
||||
$this->displayContent($content);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Return a Permit Facts Page Object
|
||||
// =================================
|
||||
// =================================
|
||||
// Return a Permit Facts Page Object
|
||||
// =================================
|
||||
|
||||
public function getPermitFactsPage($user_subscription_start_date, $user_subscription_end_date) {
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
// Sanitize inputs
|
||||
$permitfact_company = filter_input(INPUT_POST, "permitfact_company") ?: "";
|
||||
$permitfact_project_name = filter_input(INPUT_POST, "permitfact_project_name") ?: "";
|
||||
$permitfact_project_zip = filter_input(INPUT_POST, "permitfact_project_zip") ?: "";
|
||||
$permitfact_project_city = filter_input(INPUT_POST, "permitfact_project_city") ?: "";
|
||||
$permitfact_county = filter_input(INPUT_POST, "permitfact_county") ?: "";
|
||||
$permitfact_project_type = filter_input(INPUT_POST, "permitfact_project_type") ?: "";
|
||||
$permitfact_work_type = filter_input(INPUT_POST, "permitfact_work_type") ?: "";
|
||||
$permitfact_building_type = filter_input(INPUT_POST, "permitfact_building_type") ?: "";
|
||||
$permitfact_size_from = filter_input(INPUT_POST, "permitfact_size_from") ?: "";
|
||||
$permitfact_size_to = filter_input(INPUT_POST, "permitfact_size_to") ?: "";
|
||||
$permitfact_value_from = filter_input(INPUT_POST, "permitfact_value_from") ?: "";
|
||||
$permitfact_value_to = filter_input(INPUT_POST, "permitfact_value_to") ?: "";
|
||||
$permitfact_permit_date_from = filter_input(INPUT_POST, "permitfact_permit_date_from") ?: "";
|
||||
$permitfact_permit_date_to = filter_input(INPUT_POST, "permitfact_permit_date_to") ?: "";
|
||||
$permitfact_entry_date_from = filter_input(INPUT_POST, "permitfact_entry_date_from") ?: "";
|
||||
$permitfact_entry_date_to = filter_input(INPUT_POST, "permitfact_entry_date_to") ?: "";
|
||||
|
||||
// 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'));
|
||||
}
|
||||
|
||||
$permitfact_permit_date_from = ($permitfact_permit_date_from == "") ? null : date("Y-m-d", strtotime($permitfact_permit_date_from));
|
||||
$permitfact_permit_date_to = ($permitfact_permit_date_to == "") ? null : date("Y-m-d", strtotime($permitfact_permit_date_to));
|
||||
$permitfact_entry_date_from = ($permitfact_entry_date_from == "") ? null : date("Y-m-d", strtotime($permitfact_entry_date_from));
|
||||
$permitfact_entry_date_to = ($permitfact_entry_date_to == "") ? null : date("Y-m-d", strtotime($permitfact_entry_date_to));
|
||||
|
||||
// Pagination settings
|
||||
$pagination = filter_input(INPUT_POST, "pagination") ?: "";
|
||||
$this->pagination_size = filter_input(INPUT_POST, "permitfacts_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
||||
|
||||
// Connect to DB
|
||||
$connection = $this->connect();
|
||||
|
||||
// Record Count
|
||||
$SQL = "select count(*) as count
|
||||
from view_permitfacts
|
||||
where view_permitfacts.permitfact_entry_date between :user_subscription_start_date and :user_subscription_end_date ";
|
||||
$post = function ($name) {
|
||||
return trim((string) (filter_input(INPUT_POST, $name) ?: ""));
|
||||
};
|
||||
|
||||
if ($permitfact_company !== '') {
|
||||
$SQL .= " and permitfact_company regexp :permitfact_company ";
|
||||
$dateOrNull = function ($value) {
|
||||
if ($value === "") {
|
||||
return null;
|
||||
}
|
||||
|
||||
$timestamp = strtotime($value);
|
||||
return $timestamp ? date("Y-m-d", $timestamp) : null;
|
||||
};
|
||||
|
||||
$numberOrNull = function ($value) {
|
||||
$value = str_replace([",", "$"], "", trim((string) $value));
|
||||
return is_numeric($value) ? $value : null;
|
||||
};
|
||||
|
||||
$addInClause = function (&$where, &$params, $column, $rawValue, $prefix) {
|
||||
|
||||
if ($rawValue === "") {
|
||||
return;
|
||||
}
|
||||
|
||||
$items = array_filter(array_map(function ($item) {
|
||||
return trim($item, " \t\n\r\0\x0B'\"");
|
||||
}, explode(",", $rawValue)));
|
||||
|
||||
if (empty($items)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$placeholders = [];
|
||||
|
||||
foreach ($items as $index => $item) {
|
||||
$param = ":{$prefix}_{$index}";
|
||||
$placeholders[] = $param;
|
||||
$params[$param] = $item;
|
||||
}
|
||||
|
||||
$where[] = "{$column} IN (" . implode(", ", $placeholders) . ")";
|
||||
};
|
||||
|
||||
// ----------------------------
|
||||
// Subscription Date Restriction
|
||||
// ----------------------------
|
||||
|
||||
$oneYearAgo = date("Y-m-d", strtotime("-1 year"));
|
||||
|
||||
if ($user_subscription_start_date <= $oneYearAgo) {
|
||||
$user_subscription_start_date = $oneYearAgo;
|
||||
}
|
||||
|
||||
if ($permitfact_project_name !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_project_name regexp :permitfact_project_name ";
|
||||
// -----------
|
||||
// POST Values
|
||||
// -----------
|
||||
|
||||
$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");
|
||||
|
||||
$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"));
|
||||
|
||||
$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"));
|
||||
|
||||
$pagination = $post("pagination");
|
||||
|
||||
$this->pagination_size = filter_input(INPUT_POST, "permitfacts_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
||||
|
||||
// -----------------
|
||||
// Build SQL Filters
|
||||
// -----------------
|
||||
|
||||
$where = [];
|
||||
$params = [];
|
||||
|
||||
/*
|
||||
* 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";
|
||||
|
||||
$params[":user_subscription_start_date"] = $user_subscription_start_date;
|
||||
$params[":user_subscription_end_date"] = $user_subscription_end_date;
|
||||
|
||||
if ($permitfact_company !== "") {
|
||||
$where[] = "view_permitfacts.permitfact_company REGEXP :permitfact_company";
|
||||
$params[":permitfact_company"] = $permitfact_company;
|
||||
}
|
||||
|
||||
if ($permitfact_project_zip !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_project_zip = :permitfact_project_zip ";
|
||||
if ($permitfact_project_name !== "") {
|
||||
$where[] = "view_permitfacts.permitfact_project_name REGEXP :permitfact_project_name";
|
||||
$params[":permitfact_project_name"] = $permitfact_project_name;
|
||||
}
|
||||
|
||||
if ($permitfact_project_city !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_project_city in ($permitfact_project_city) ";
|
||||
if ($permitfact_project_zip !== "") {
|
||||
$where[] = "view_permitfacts.permitfact_project_zip = :permitfact_project_zip";
|
||||
$params[":permitfact_project_zip"] = $permitfact_project_zip;
|
||||
}
|
||||
|
||||
// if ($permitfact_project_city !== '') {
|
||||
// $SQL .= " and view_permitfacts.permitfact_city in ($permitfact_project_city) ";
|
||||
// } else {
|
||||
// $cities = (new Cities())->getSubscriptionCities($_SESSION['subscription_serial']);
|
||||
//
|
||||
// $cityNames = [];
|
||||
//
|
||||
// foreach ($cities as $city) {
|
||||
// $cityNames[] = " " . (string) $city->subscriptioncity_city . " ";
|
||||
// }
|
||||
//
|
||||
// $permitfact_project_city = ' ' . implode(', ', $cityNames) . ' ';
|
||||
//
|
||||
// $SQL .= " and view_permitfacts.permitfact_city in ($permitfact_project_city) ";
|
||||
// }
|
||||
$addInClause($where, $params, "view_permitfacts.permitfact_project_city", $permitfact_project_city, "city");
|
||||
|
||||
if ($permitfact_county !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_county in ($permitfact_county) ";
|
||||
if ($permitfact_county !== "") {
|
||||
|
||||
$addInClause($where, $params, "view_permitfacts.permitfact_county", $permitfact_county, "county");
|
||||
} else {
|
||||
$counties = (new Counties())->getSubscriptionCounties($_SESSION['subscription_serial']);
|
||||
|
||||
$countyNames = [];
|
||||
$counties = (new Counties())->getSubscriptionCounties($_SESSION["subscription_serial"]);
|
||||
|
||||
$countyList = [];
|
||||
|
||||
foreach ($counties as $county) {
|
||||
$countyNames[] = " " . (string) $county->subscriptioncounty_county . " ";
|
||||
$countyList[] = (string) $county->subscriptioncounty_county;
|
||||
}
|
||||
|
||||
$permitfact_county = ' ' . implode(', ', $countyNames) . ' ';
|
||||
|
||||
$SQL .= " and view_permitfacts.permitfact_county in ($permitfact_county) ";
|
||||
}
|
||||
|
||||
|
||||
if ($permitfact_project_type !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_project_type in ($permitfact_project_type) ";
|
||||
}
|
||||
|
||||
if ($permitfact_work_type !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_work_type in ($permitfact_work_type) ";
|
||||
}
|
||||
|
||||
if ($permitfact_building_type !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_building_type in ($permitfact_building_type) ";
|
||||
}
|
||||
|
||||
if ($permitfact_size_from !== '' && $permitfact_size_to !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_size between '{$permitfact_size_from}' and '{$permitfact_size_to}' ";
|
||||
} elseif ($permitfact_size_from != '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_size = '{$permitfact_size_from}' ";
|
||||
} elseif ($permitfact_size_to != '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_size = '{$permitfact_size_to}' ";
|
||||
}
|
||||
|
||||
if ($permitfact_value_from !== '' && $permitfact_value_to !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_value between '{$permitfact_value_from}' and '{$permitfact_value_to}' ";
|
||||
} elseif ($permitfact_value_from != '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_value = '{$permitfact_value_from}' ";
|
||||
} elseif ($permitfact_value_to != '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_value = '{$permitfact_value_to}' ";
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Permit Date Logic Start
|
||||
// =======================
|
||||
|
||||
$permitFrom = $permitfact_permit_date_from; // null or Y-m-d
|
||||
$permitTo = $permitfact_permit_date_to; // null or Y-m-d
|
||||
|
||||
$subStart = $user_subscription_start_date; // Y-m-d
|
||||
$subEnd = $user_subscription_end_date; // Y-m-d
|
||||
// ---- Enforce subscription window for permit dates (only if user provided them) ----
|
||||
if ($permitFrom !== null) {
|
||||
if ($permitFrom < $subStart || $permitFrom > $subEnd) {
|
||||
$this->displayNotice("The Permit Issue 'from' date or date range {$this->current_user_name} selected is outside your authorized access period.");
|
||||
return;
|
||||
if (!empty($countyList)) {
|
||||
$addInClause(
|
||||
$where,
|
||||
$params,
|
||||
"view_permitfacts.permitfact_county",
|
||||
implode(",", $countyList),
|
||||
"sub_county"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($permitTo !== null) {
|
||||
if ($permitTo < $subStart || $permitTo > $subEnd) {
|
||||
$this->displayNotice("The Permit Issue 'to' date or date range {$this->current_user_name} selected is outside your authorized access period.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
$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");
|
||||
|
||||
// ---- Build the permit date filter logic ----
|
||||
if ($permitFrom !== null && $permitTo !== null) {
|
||||
// -----------
|
||||
// Size Filter
|
||||
// -----------
|
||||
|
||||
// If user reversed the dates, swap them
|
||||
if ($permitFrom > $permitTo) {
|
||||
$tmp = $permitFrom;
|
||||
$permitFrom = $permitTo;
|
||||
$permitTo = $tmp;
|
||||
if ($permitfact_size_from !== null && $permitfact_size_to !== null) {
|
||||
|
||||
if ($permitfact_size_from > $permitfact_size_to) {
|
||||
[$permitfact_size_from, $permitfact_size_to] = [$permitfact_size_to, $permitfact_size_from];
|
||||
}
|
||||
|
||||
$SQL .= " AND view_permitfacts.permitfact_permit_date BETWEEN '{$permitFrom}' AND '{$permitTo}'";
|
||||
} elseif ($permitFrom !== null) {
|
||||
$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) {
|
||||
|
||||
// User entered only "From" => treat as a specific date
|
||||
$SQL .= " AND view_permitfacts.permitfact_permit_date = '{$permitFrom}'";
|
||||
} elseif ($permitTo !== null) {
|
||||
$where[] = "view_permitfacts.permitfact_size >= :permitfact_size_from";
|
||||
$params[":permitfact_size_from"] = $permitfact_size_from;
|
||||
} elseif ($permitfact_size_to !== null) {
|
||||
|
||||
// User entered only "To" => treat as a specific date
|
||||
$SQL .= " AND view_permitfacts.permitfact_permit_date = '{$permitTo}'";
|
||||
$where[] = "view_permitfacts.permitfact_size <= :permitfact_size_to";
|
||||
$params[":permitfact_size_to"] = $permitfact_size_to;
|
||||
}
|
||||
|
||||
// =====================
|
||||
// Permit Date Logic End
|
||||
// =====================
|
||||
// ======================
|
||||
// Entry Date Logic Start
|
||||
// ======================
|
||||
// -----------
|
||||
// Value Filter
|
||||
// -----------
|
||||
|
||||
$entryFrom = $permitfact_entry_date_from; // null or Y-m-d
|
||||
$entryTo = $permitfact_entry_date_to; // null or Y-m-d
|
||||
if ($permitfact_value_from !== null && $permitfact_value_to !== null) {
|
||||
|
||||
$subStart = $user_subscription_start_date; // Y-m-d
|
||||
$subEnd = $user_subscription_end_date; // Y-m-d
|
||||
// ---- Enforce subscription window for entry dates (only if user provided them) ----
|
||||
if ($entryFrom !== null) {
|
||||
if ($entryFrom < $subStart || $entryFrom > $subEnd) {
|
||||
$this->displayNotice("The Entry 'from' date or date range {$this->current_user_name} selected is outside your authorized access period.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($entryTo !== null) {
|
||||
if ($entryTo < $subStart || $entryTo > $subEnd) {
|
||||
$this->displayNotice("The Entry 'to' date or date range {$this->current_user_name} selected is outside your authorized access period.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Build the entry date filter logic ----
|
||||
if ($entryFrom !== null && $entryTo !== null) {
|
||||
|
||||
// If user reversed the dates, swap them
|
||||
if ($entryFrom > $entryTo) {
|
||||
$tmp = $entryFrom;
|
||||
$entryFrom = $entryTo;
|
||||
$entryTo = $tmp;
|
||||
if ($permitfact_value_from > $permitfact_value_to) {
|
||||
[$permitfact_value_from, $permitfact_value_to] = [$permitfact_value_to, $permitfact_value_from];
|
||||
}
|
||||
|
||||
$SQL .= " AND view_permitfacts.permitfact_entry_date BETWEEN '{$entryFrom}' AND '{$entryTo}'";
|
||||
} elseif ($entryFrom !== null) {
|
||||
$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) {
|
||||
|
||||
// User entered only "From" => treat as a specific date
|
||||
$SQL .= " AND view_permitfacts.permitfact_entry_date = '{$entryFrom}'";
|
||||
} elseif ($entryTo !== null) {
|
||||
$where[] = "view_permitfacts.permitfact_value >= :permitfact_value_from";
|
||||
$params[":permitfact_value_from"] = $permitfact_value_from;
|
||||
} elseif ($permitfact_value_to !== null) {
|
||||
|
||||
// User entered only "To" => treat as a specific date
|
||||
$SQL .= " AND view_permitfacts.permitfact_entry_date = '{$entryTo}'";
|
||||
}
|
||||
|
||||
// ====================
|
||||
// Entry Date Logic End
|
||||
// ====================
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
if ($permitfact_company !== '') {
|
||||
$statement->bindValue(":permitfact_company", $permitfact_company, PDO::PARAM_STR);
|
||||
$where[] = "view_permitfacts.permitfact_value <= :permitfact_value_to";
|
||||
$params[":permitfact_value_to"] = $permitfact_value_to;
|
||||
}
|
||||
|
||||
if ($permitfact_project_name !== '') {
|
||||
$statement->bindValue(":permitfact_project_name", $permitfact_project_name, PDO::PARAM_STR);
|
||||
// ------------------
|
||||
// Permit Date Filter
|
||||
// ------------------
|
||||
// This is optional and works WITH the entry-date subscription gate.
|
||||
|
||||
if ($permitfact_permit_date_from !== null && $permitfact_permit_date_to !== null) {
|
||||
|
||||
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
|
||||
];
|
||||
}
|
||||
|
||||
$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) {
|
||||
|
||||
$where[] = "view_permitfacts.permitfact_permit_date = :permit_date_from";
|
||||
$params[":permit_date_from"] = $permitfact_permit_date_from;
|
||||
} elseif ($permitfact_permit_date_to !== null) {
|
||||
|
||||
$where[] = "view_permitfacts.permitfact_permit_date = :permit_date_to";
|
||||
$params[":permit_date_to"] = $permitfact_permit_date_to;
|
||||
}
|
||||
|
||||
if ($permitfact_project_zip !== '') {
|
||||
$statement->bindValue(":permitfact_project_zip", $permitfact_project_zip, PDO::PARAM_STR);
|
||||
// -----------------
|
||||
// Entry Date Filter
|
||||
// -----------------
|
||||
// This further narrows the already-required subscription entry-date gate.
|
||||
|
||||
if ($permitfact_entry_date_from !== null && $permitfact_entry_date_to !== null) {
|
||||
|
||||
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
|
||||
];
|
||||
}
|
||||
|
||||
$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) {
|
||||
|
||||
$where[] = "view_permitfacts.permitfact_entry_date >= :entry_date_from";
|
||||
$params[":entry_date_from"] = $permitfact_entry_date_from;
|
||||
} elseif ($permitfact_entry_date_to !== null) {
|
||||
|
||||
$where[] = "view_permitfacts.permitfact_entry_date <= :entry_date_to";
|
||||
$params[":entry_date_to"] = $permitfact_entry_date_to;
|
||||
}
|
||||
|
||||
$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);
|
||||
$whereSQL = implode(" AND ", $where);
|
||||
|
||||
// ------------
|
||||
// Record Count
|
||||
// ------------
|
||||
|
||||
$countSQL = "
|
||||
SELECT COUNT(*) AS count
|
||||
FROM view_permitfacts
|
||||
WHERE {$whereSQL}
|
||||
";
|
||||
|
||||
$statement = $connection->prepare($countSQL);
|
||||
|
||||
foreach ($params as $param => $value) {
|
||||
$statement->bindValue($param, $value, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
$count = $recordset ? (int) $recordset["count"] : 0;
|
||||
|
||||
// === PAGINATION LOGIC ===
|
||||
// ----------
|
||||
// Pagination
|
||||
// ----------
|
||||
|
||||
$totalPages = max(1, (int) ceil($count / $this->pagination_size));
|
||||
|
||||
switch ($pagination) {
|
||||
case "first": $this->pagination_page = 1;
|
||||
case "first":
|
||||
$this->pagination_page = 1;
|
||||
break;
|
||||
case "previous": $this->pagination_page = max($this->pagination_page - 1, 1);
|
||||
|
||||
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));
|
||||
|
||||
case "next":
|
||||
$this->pagination_page = min($this->pagination_page + 1, $totalPages);
|
||||
break;
|
||||
case "last": $this->pagination_page = (int) ceil($count / $this->pagination_size);
|
||||
|
||||
case "last":
|
||||
$this->pagination_page = $totalPages;
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->pagination_page = max(1, min($this->pagination_page, $totalPages));
|
||||
break;
|
||||
}
|
||||
|
||||
$offset = max(0, ($this->pagination_page - 1) * $this->pagination_size);
|
||||
$start = $offset + 1;
|
||||
$end = min($count, $start + $this->pagination_size - 1);
|
||||
$start = $count > 0 ? $offset + 1 : 0;
|
||||
$end = min($count, $offset + $this->pagination_size);
|
||||
|
||||
// === DATA QUERY ===
|
||||
$SQL = "select view_permitfacts.*
|
||||
from view_permitfacts
|
||||
where view_permitfacts.permitfact_entry_date between :user_subscription_start_date and :user_subscription_end_date ";
|
||||
// ----------
|
||||
// Data Query
|
||||
// ----------
|
||||
|
||||
if ($permitfact_company !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_company regexp :permitfact_company ";
|
||||
$dataSQL = "
|
||||
SELECT view_permitfacts.*
|
||||
FROM view_permitfacts
|
||||
WHERE {$whereSQL}
|
||||
ORDER BY view_permitfacts.permitfact_entry_date DESC,
|
||||
view_permitfacts.permitfact_permit_date DESC
|
||||
";
|
||||
|
||||
if ($pagination !== "off") {
|
||||
$dataSQL .= "
|
||||
LIMIT :limit
|
||||
OFFSET :offset
|
||||
";
|
||||
}
|
||||
|
||||
if ($permitfact_project_name !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_project_name regexp :permitfact_project_name ";
|
||||
$statement = $connection->prepare($dataSQL);
|
||||
|
||||
foreach ($params as $param => $value) {
|
||||
$statement->bindValue($param, $value, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
if ($permitfact_project_zip !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_project_zip = :permitfact_project_zip ";
|
||||
}
|
||||
|
||||
if ($permitfact_project_city !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_project_city in ($permitfact_project_city) ";
|
||||
}
|
||||
|
||||
// if ($permitfact_project_city !== '') {
|
||||
// $SQL .= " and view_permitfacts.permitfact_city in ($permitfact_project_city) ";
|
||||
// } else {
|
||||
// $cities = (new Cities())->getSubscriptionCities($_SESSION['subscription_serial']);
|
||||
//
|
||||
// $cityNames = [];
|
||||
//
|
||||
// foreach ($cities as $city) {
|
||||
// $cityNames[] = " " . (string) $city->subscriptioncity_city . " ";
|
||||
// }
|
||||
//
|
||||
// $permitfact_project_city = ' ' . implode(', ', $cityNames) . ' ';
|
||||
//
|
||||
// $SQL .= " and view_permitfacts.permitfact_city in ($permitfact_project_city) ";
|
||||
// }
|
||||
|
||||
if ($permitfact_county !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_county in ($permitfact_county) ";
|
||||
} else {
|
||||
$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) ";
|
||||
}
|
||||
|
||||
|
||||
if ($permitfact_project_type !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_project_type in ($permitfact_project_type) ";
|
||||
}
|
||||
|
||||
if ($permitfact_work_type !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_work_type in ($permitfact_work_type) ";
|
||||
}
|
||||
|
||||
if ($permitfact_building_type !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_building_type in ($permitfact_building_type) ";
|
||||
}
|
||||
|
||||
if ($permitfact_size_from !== '' && $permitfact_size_to !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_size between '{$permitfact_size_from}' and '{$permitfact_size_from}' ";
|
||||
} elseif ($permitfact_size_from != '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_size = '{$permitfact_size_from}' ";
|
||||
} elseif ($permitfact_size_to != '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_size = '{$permitfact_size_from}' ";
|
||||
}
|
||||
|
||||
if ($permitfact_value_from !== '' && $permitfact_value_to !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_value between '{$permitfact_value_from}' and '{$permitfact_value_to}' ";
|
||||
} elseif ($permitfact_value_from !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_value = '{$permitfact_value_to}' ";
|
||||
} elseif ($permitfact_value_to !== '') {
|
||||
$SQL .= " and view_permitfacts.permitfact_value = '{$permitfact_value_to}' ";
|
||||
}
|
||||
|
||||
// =======================
|
||||
// Permit Date Logic Start
|
||||
// =======================
|
||||
$permitFrom = $permitfact_permit_date_from; // null or Y-m-d
|
||||
$permitTo = $permitfact_permit_date_to; // null or Y-m-d
|
||||
|
||||
$subStart = $user_subscription_start_date; // Y-m-d
|
||||
$subEnd = $user_subscription_end_date; // Y-m-d
|
||||
// ---- Enforce subscription window for permit dates (only if user provided them) ----
|
||||
if ($permitFrom !== null) {
|
||||
if ($permitFrom < $subStart || $permitFrom > $subEnd) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($permitTo !== null) {
|
||||
if ($permitTo < $subStart || $permitTo > $subEnd) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Build the permit date filter logic ----
|
||||
if ($permitFrom !== null && $permitTo !== null) {
|
||||
|
||||
// If user reversed the dates, swap them
|
||||
if ($permitFrom > $permitTo) {
|
||||
$tmp = $permitFrom;
|
||||
$permitFrom = $permitTo;
|
||||
$permitTo = $tmp;
|
||||
}
|
||||
|
||||
$SQL .= " AND view_permitfacts.permitfact_permit_date BETWEEN '{$permitFrom}' AND '{$permitTo}'";
|
||||
} elseif ($permitFrom !== null) {
|
||||
|
||||
// User entered only "From" => treat as a specific date
|
||||
$SQL .= " AND view_permitfacts.permitfact_permit_date = '{$permitFrom}'";
|
||||
} elseif ($permitTo !== null) {
|
||||
|
||||
// User entered only "To" => treat as a specific date
|
||||
$SQL .= " AND view_permitfacts.permitfact_permit_date = '{$permitTo}'";
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Permit Date Logic End
|
||||
// ======================
|
||||
// ======================
|
||||
// Entry Date Logic Start
|
||||
// ======================
|
||||
|
||||
$entryFrom = $permitfact_entry_date_from; // null or Y-m-d
|
||||
$entryTo = $permitfact_entry_date_to; // null or Y-m-d
|
||||
|
||||
$subStart = $user_subscription_start_date; // Y-m-d
|
||||
$subEnd = $user_subscription_end_date; // Y-m-d
|
||||
// ---- Enforce subscription window for entry dates (only if user provided them) ----
|
||||
if ($entryFrom !== null) {
|
||||
if ($entryFrom < $subStart || $entryFrom > $subEnd) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($entryTo !== null) {
|
||||
if ($entryTo < $subStart || $entryTo > $subEnd) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Build the entry date filter logic ----
|
||||
if ($entryFrom !== null && $entryTo !== null) {
|
||||
|
||||
// If user reversed the dates, swap them
|
||||
if ($entryFrom > $entryTo) {
|
||||
$tmp = $entryFrom;
|
||||
$entryFrom = $entryTo;
|
||||
$entryTo = $tmp;
|
||||
}
|
||||
|
||||
$SQL .= " AND view_permitfacts.permitfact_entry_date BETWEEN '{$entryFrom}' AND '{$entryTo}'";
|
||||
} elseif ($entryFrom !== null) {
|
||||
|
||||
// User entered only "From" => treat as a specific date
|
||||
$SQL .= " AND view_permitfacts.permitfact_entry_date = '{$entryFrom}'";
|
||||
} elseif ($entryTo !== null) {
|
||||
|
||||
// User entered only "To" => treat as a specific date
|
||||
$SQL .= " AND view_permitfacts.permitfact_entry_date = '{$entryTo}'";
|
||||
}
|
||||
|
||||
// ====================
|
||||
// Entry Date Logic End
|
||||
// ====================
|
||||
|
||||
if ($pagination !== 'off') {
|
||||
$SQL .= " limit :limit
|
||||
offset :offset";
|
||||
}
|
||||
|
||||
|
||||
$statement = $connection->prepare($SQL);
|
||||
|
||||
if ($permitfact_company !== '') {
|
||||
$statement->bindValue(":permitfact_company", $permitfact_company, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
if ($permitfact_project_name !== '') {
|
||||
$statement->bindValue(":permitfact_project_name", $permitfact_project_name, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
if ($permitfact_project_zip !== '') {
|
||||
$statement->bindValue(":permitfact_project_zip", $permitfact_project_zip, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
$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);
|
||||
|
||||
if ($pagination !== 'off') {
|
||||
$statement->bindValue(":limit", $this->pagination_size, PDO::PARAM_INT);
|
||||
$statement->bindValue(":offset", $offset, PDO::PARAM_INT);
|
||||
if ($pagination !== "off") {
|
||||
$statement->bindValue(":limit", (int) $this->pagination_size, PDO::PARAM_INT);
|
||||
$statement->bindValue(":offset", (int) $offset, PDO::PARAM_INT);
|
||||
}
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$permitfacts = $this->getTableXML("permitfacts", $statement);
|
||||
|
||||
// Add searched entry_dates for search history
|
||||
if (!isset($permitfacts->record)) {
|
||||
$permitfacts->addChild("record");
|
||||
}
|
||||
|
||||
$permitfacts->record->permitfact_entry_date_from = !empty($entryFrom) ? date('m/d/Y', strtotime($entryFrom)) : date('m/d/Y', strtotime($user_subscription_start_date));
|
||||
$permitfacts->record->permitfact_entry_date_to = !empty($entryTo) ? date('m/d/Y', strtotime($entryTo)) : date('m/d/Y', strtotime($user_subscription_end_date));
|
||||
$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)) : "";
|
||||
|
||||
$permitfacts->record->permitfact_permit_date_to = !empty($permitfact_permit_date_to) ? date("m/d/Y", strtotime($permitfact_permit_date_to)) : "";
|
||||
|
||||
// Insert Pagination Attributes
|
||||
$permitfacts->addAttribute("count", $count);
|
||||
$permitfacts->addAttribute("start", $start);
|
||||
$permitfacts->addAttribute("end", $end);
|
||||
|
||||
@@ -114,21 +114,21 @@ class PlanningAndZoningFacts extends Base {
|
||||
|
||||
public function getPZFactsPage($user_subscription_start_date, $user_subscription_end_date) {
|
||||
|
||||
// ---------------------------
|
||||
// -----------------------
|
||||
// Read + normalize inputs
|
||||
// ---------------------------
|
||||
$pzfact_project_name = trim((string) filter_input(INPUT_POST, "pzfact_project_name")) ?: "";
|
||||
$pzfact_project_city = trim((string) filter_input(INPUT_POST, "pzfact_project_city")) ?: "";
|
||||
$pzfact_county = trim((string) filter_input(INPUT_POST, "pzfact_county")) ?: "";
|
||||
$pzfact_project_type = trim((string) filter_input(INPUT_POST, "pzfact_project_type")) ?: "";
|
||||
$pzfact_action_code = trim((string) filter_input(INPUT_POST, "pzfact_action_code")) ?: "";
|
||||
$pzfact_acres_from = trim((string) filter_input(INPUT_POST, "pzfact_acres_from")) ?: "";
|
||||
$pzfact_acres_to = trim((string) filter_input(INPUT_POST, "pzfact_acres_to")) ?: "";
|
||||
$pzfact_entry_date_from = trim((string) filter_input(INPUT_POST, "pzfact_entry_date_from")) ?: "";
|
||||
$pzfact_entry_date_to = trim((string) filter_input(INPUT_POST, "pzfact_entry_date_to")) ?: "";
|
||||
// --------------------------
|
||||
$pzfact_project_name = trim((string) filter_input(INPUT_POST, "pzfact_project_name")) ?: "";
|
||||
$pzfact_project_city = trim((string) filter_input(INPUT_POST, "pzfact_project_city")) ?: "";
|
||||
$pzfact_county = trim((string) filter_input(INPUT_POST, "pzfact_county")) ?: "";
|
||||
$pzfact_project_type = trim((string) filter_input(INPUT_POST, "pzfact_project_type")) ?: "";
|
||||
$pzfact_action_code = trim((string) filter_input(INPUT_POST, "pzfact_action_code")) ?: "";
|
||||
$pzfact_acres_from = trim((string) filter_input(INPUT_POST, "pzfact_acres_from")) ?: "";
|
||||
$pzfact_acres_to = trim((string) filter_input(INPUT_POST, "pzfact_acres_to")) ?: "";
|
||||
$pzfact_entry_date_from = trim((string) filter_input(INPUT_POST, "pzfact_entry_date_from")) ?: "";
|
||||
$pzfact_entry_date_to = trim((string) filter_input(INPUT_POST, "pzfact_entry_date_to")) ?: "";
|
||||
|
||||
// Pagination
|
||||
$pagination = trim((string) filter_input(INPUT_POST, "pagination")) ?: "";
|
||||
$pagination = trim((string) filter_input(INPUT_POST, "pagination")) ?: "";
|
||||
$this->pagination_size = filter_input(INPUT_POST, "pzfacts_per_page", FILTER_SANITIZE_NUMBER_INT) ?: $this->pagination_size;
|
||||
|
||||
// --------------------------------------------------------------
|
||||
@@ -150,7 +150,7 @@ class PlanningAndZoningFacts extends Base {
|
||||
// Normalize entry dates to Y-m-d or null
|
||||
// --------------------------------------
|
||||
$entryFrom = ($pzfact_entry_date_from === "") ? null : date("Y-m-d", strtotime($pzfact_entry_date_from));
|
||||
$entryTo = ($pzfact_entry_date_to === "") ? null : date("Y-m-d", strtotime($pzfact_entry_date_to));
|
||||
$entryTo = ($pzfact_entry_date_to === "") ? null : date("Y-m-d", strtotime($pzfact_entry_date_to));
|
||||
|
||||
// -------
|
||||
// Connect
|
||||
@@ -223,15 +223,15 @@ class PlanningAndZoningFacts extends Base {
|
||||
|
||||
// Acres filter (numeric; bind params)
|
||||
if ($pzfact_acres_from !== '' && $pzfact_acres_to !== '') {
|
||||
$clauses[] = "view_pzfacts.pzfact_acres BETWEEN :acres_from AND :acres_to";
|
||||
$clauses[] = "view_pzfacts.pzfact_acres BETWEEN :acres_from AND :acres_to";
|
||||
$params[':acres_from'] = (float) $pzfact_acres_from;
|
||||
$params[':acres_to'] = (float) $pzfact_acres_to;
|
||||
$params[':acres_to'] = (float) $pzfact_acres_to;
|
||||
} elseif ($pzfact_acres_from !== '') {
|
||||
$clauses[] = "view_pzfacts.pzfact_acres = :acres_eq";
|
||||
$params[':acres_eq'] = (float) $pzfact_acres_from;
|
||||
$clauses[] = "view_pzfacts.pzfact_acres = :acres_eq";
|
||||
$params[':acres_eq'] = (float) $pzfact_acres_from;
|
||||
} elseif ($pzfact_acres_to !== '') {
|
||||
$clauses[] = "view_pzfacts.pzfact_acres = :acres_eq";
|
||||
$params[':acres_eq'] = (float) $pzfact_acres_to;
|
||||
$clauses[] = "view_pzfacts.pzfact_acres = :acres_eq";
|
||||
$params[':acres_eq'] = (float) $pzfact_acres_to;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
@@ -252,9 +252,9 @@ class PlanningAndZoningFacts extends Base {
|
||||
|
||||
// Swap if reversed
|
||||
if ($entryFrom > $entryTo) {
|
||||
$tmp = $entryFrom;
|
||||
$tmp = $entryFrom;
|
||||
$entryFrom = $entryTo;
|
||||
$entryTo = $tmp;
|
||||
$entryTo = $tmp;
|
||||
}
|
||||
|
||||
// Enforce subscription window with your existing policy (reject + notice)
|
||||
@@ -294,9 +294,9 @@ class PlanningAndZoningFacts extends Base {
|
||||
$recordset = $stmtCount->fetch(PDO::FETCH_ASSOC);
|
||||
$count = $recordset ? (int) $recordset["count"] : 0;
|
||||
|
||||
// ---------------------------
|
||||
// ----------------
|
||||
// Pagination logic
|
||||
// ---------------------------
|
||||
// ----------------
|
||||
switch ($pagination) {
|
||||
case "first":
|
||||
$this->pagination_page = 1;
|
||||
@@ -321,9 +321,12 @@ class PlanningAndZoningFacts extends Base {
|
||||
// ----------
|
||||
$sqlData = "SELECT view_pzfacts.*
|
||||
FROM view_pzfacts
|
||||
{$whereSql}
|
||||
LIMIT :limit
|
||||
OFFSET :offset";
|
||||
{$whereSql}";
|
||||
|
||||
if ($pagination !== 'off') {
|
||||
$sqlData .= " limit :limit
|
||||
offset :offset";
|
||||
}
|
||||
|
||||
$stmtData = $connection->prepare($sqlData);
|
||||
|
||||
@@ -333,8 +336,10 @@ class PlanningAndZoningFacts extends Base {
|
||||
$stmtData->bindValue($k, $v, $type);
|
||||
}
|
||||
|
||||
$stmtData->bindValue(":limit", (int) $this->pagination_size, PDO::PARAM_INT);
|
||||
$stmtData->bindValue(":offset", (int) $offset, PDO::PARAM_INT);
|
||||
if ($pagination !== 'off') {
|
||||
$stmtData->bindValue(":limit", (int) $this->pagination_size, PDO::PARAM_INT);
|
||||
$stmtData->bindValue(":offset", (int) $offset, PDO::PARAM_INT);
|
||||
}
|
||||
|
||||
$stmtData->execute();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user