2026-10-18 17:01:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class Statuses extends Base {
|
|
|
|
|
|
|
|
|
|
// Variables.
|
|
|
|
|
|
|
|
|
|
private $current_user_serial = 0;
|
|
|
|
|
|
|
|
|
|
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_name = $_SESSION[self::USER_NAME] ?? "";
|
|
|
|
|
$this->current_user_email = $_SESSION[self::USER_EMAIL] ?? "";
|
|
|
|
|
|
2026-10-20 06:45:30 -04:00
|
|
|
$this->pagination_page = 1;
|
2026-10-18 17:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==========
|
|
|
|
|
// Add Status
|
|
|
|
|
// ==========
|
|
|
|
|
|
|
|
|
|
public function addStatus() {
|
|
|
|
|
|
|
|
|
|
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
|
|
|
|
|
|
|
|
|
switch ($step) {
|
|
|
|
|
|
|
|
|
|
case "prompt":
|
|
|
|
|
|
|
|
|
|
$content = $this->applyXSL("", $this->getXSL("addStatus"));
|
|
|
|
|
|
|
|
|
|
$this->displayContent($content);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "add":
|
2026-10-20 06:45:30 -04:00
|
|
|
(new MaintenanceService())->saveStatus(0,$_POST);
|
2026-10-18 17:01:36 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
$this->displayHome();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =============
|
|
|
|
|
// Delete Status
|
|
|
|
|
// =============
|
|
|
|
|
|
|
|
|
|
public function deleteStatus() {
|
2026-10-20 06:45:30 -04:00
|
|
|
(new MaintenanceService())->deleteStatus(MaintenanceService::id($_POST['status_serial']??null));
|
2026-10-18 17:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ============================
|
|
|
|
|
// Determine if a Status exists
|
|
|
|
|
// ============================
|
|
|
|
|
|
|
|
|
|
public function statusExists() {
|
|
|
|
|
|
|
|
|
|
$status_serial = filter_input(INPUT_POST, "status_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
|
|
|
|
$status_name = filter_input(INPUT_POST, "status_name") ?: "";
|
|
|
|
|
|
|
|
|
|
$SQL = "select status_serial
|
|
|
|
|
from view_statuses
|
|
|
|
|
where status_serial != :status_serial
|
|
|
|
|
and lower(status_name) = :status_name";
|
|
|
|
|
|
|
|
|
|
$statement = $this->connect()->prepare($SQL);
|
|
|
|
|
|
|
|
|
|
$statement->bindValue(":status_serial", $status_serial);
|
|
|
|
|
$statement->bindValue(":status_name", strtolower($status_name));
|
|
|
|
|
|
|
|
|
|
$statement->execute();
|
|
|
|
|
|
|
|
|
|
$recordset = $statement->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
|
|
$exists = (count($recordset) > 0) ? true : false;
|
|
|
|
|
|
|
|
|
|
echo json_encode($exists);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ======================================
|
|
|
|
|
// Determine if a Status is Active (AJAX)
|
|
|
|
|
// ======================================
|
|
|
|
|
|
|
|
|
|
public function statusActive() {
|
2026-10-20 06:45:30 -04:00
|
|
|
$stmt=$this->connect()->prepare('SELECT status_default FROM statuses WHERE status_serial=?');
|
|
|
|
|
$stmt->execute([MaintenanceService::id($_POST['status_serial']??null)]);$row=$stmt->fetch();
|
|
|
|
|
if(!$row)throw new AppException('Status not found.',404);
|
|
|
|
|
echo json_encode((bool)$row['status_default']);
|
2026-10-18 17:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =============
|
|
|
|
|
// Edit a Status
|
|
|
|
|
// =============
|
|
|
|
|
|
|
|
|
|
public function editStatus() {
|
|
|
|
|
|
|
|
|
|
$step = filter_input(INPUT_POST, "step") ?: "prompt";
|
|
|
|
|
|
|
|
|
|
switch ($step) {
|
|
|
|
|
|
|
|
|
|
case "prompt":
|
|
|
|
|
|
|
|
|
|
$status_serial = filter_input(INPUT_POST, "status_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
|
|
|
|
|
|
|
|
|
$status = $this->getStatus($status_serial);
|
|
|
|
|
|
|
|
|
|
if ($status->count() == 0) {
|
|
|
|
|
$this->logError("Invalid Status ({$status_serial}). " . __METHOD__);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$XML = $this->mergeXML($status, "<XML/>");
|
|
|
|
|
|
|
|
|
|
$content = $this->applyXSL($XML, $this->getXSL("editStatus"));
|
|
|
|
|
|
|
|
|
|
$this->displayContent($content);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "update":
|
2026-10-20 06:45:30 -04:00
|
|
|
(new MaintenanceService())->saveStatus(MaintenanceService::id($_POST['status_serial']??null),$_POST);
|
2026-10-18 17:01:36 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
$this->displayHome();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ================================
|
|
|
|
|
// Return an Active Statuses Object
|
|
|
|
|
// ================================
|
|
|
|
|
|
|
|
|
|
public function getActiveStatuses() {
|
|
|
|
|
|
|
|
|
|
$SQL = "select view_statuses.*
|
|
|
|
|
from view_statuses
|
|
|
|
|
where status_active is true";
|
|
|
|
|
|
|
|
|
|
return $this->getTable("statuses", $SQL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -------------------------
|
|
|
|
|
// Return the Default Status
|
|
|
|
|
// -------------------------
|
|
|
|
|
|
|
|
|
|
public function getDefaultStatus() {
|
|
|
|
|
|
|
|
|
|
$SQL = "select status_serial
|
|
|
|
|
from view_statuses
|
|
|
|
|
where status_default is true";
|
|
|
|
|
|
|
|
|
|
return $this->getTable("statuses", $SQL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =======================
|
|
|
|
|
// Return an Status Object
|
|
|
|
|
// =======================
|
|
|
|
|
|
|
|
|
|
public function getStatus($status_serial = 0) {
|
|
|
|
|
|
|
|
|
|
$SQL = "select view_statuses.*
|
|
|
|
|
from view_statuses
|
|
|
|
|
where status_serial = {$status_serial}";
|
|
|
|
|
|
|
|
|
|
return $this->getTable("statuses", $SQL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===========================
|
|
|
|
|
// Return a Statuss Object
|
|
|
|
|
// ===========================
|
|
|
|
|
|
|
|
|
|
public function getStatuses() {
|
|
|
|
|
|
|
|
|
|
$SQL = "select view_statuses.*
|
|
|
|
|
from view_statuses";
|
|
|
|
|
|
|
|
|
|
return $this->getTable("statuses", $SQL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ============================
|
|
|
|
|
// Return a Statuss Page Object
|
|
|
|
|
// ============================
|
|
|
|
|
|
|
|
|
|
public function getStatusesPage() {
|
2026-10-20 06:45:30 -04:00
|
|
|
$this->pagination_size=(int)($_POST['statuses_per_page']??20);
|
2026-10-18 17:01:36 +00:00
|
|
|
|
|
|
|
|
// Find Criteria
|
|
|
|
|
|
|
|
|
|
$find_status = filter_input(INPUT_POST, "find_status") ?: "";
|
2026-10-20 06:45:30 -04:00
|
|
|
$find_status = trim($find_status);
|
2026-10-18 17:01:36 +00:00
|
|
|
|
2026-10-20 06:45:30 -04:00
|
|
|
$find_words = implode("|", array_map(static fn($word) => preg_quote($word), explode(" ", $find_status)));
|
2026-10-18 17:01:36 +00:00
|
|
|
|
|
|
|
|
// Record Count
|
|
|
|
|
|
|
|
|
|
$connection = $this->connect();
|
|
|
|
|
|
|
|
|
|
$SQL = "select count(*) as count
|
|
|
|
|
from view_statuses
|
|
|
|
|
where status_name regexp :status_name
|
|
|
|
|
or status_classes regexp :status_classes";
|
|
|
|
|
|
|
|
|
|
$statement = $connection->prepare($SQL);
|
|
|
|
|
|
|
|
|
|
$statement->bindValue(":status_name", $find_words);
|
|
|
|
|
$statement->bindValue(":status_classes", $find_words);
|
|
|
|
|
|
|
|
|
|
$statement->execute();
|
|
|
|
|
|
|
|
|
|
$recordset = $statement->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
|
|
$count = (count($recordset) > 0) ? (int) $recordset["count"] : (int) 0;
|
|
|
|
|
|
|
|
|
|
// Pagination
|
|
|
|
|
|
|
|
|
|
$pagination = filter_input(INPUT_POST, "pagination") ?: "";
|
|
|
|
|
|
2026-10-20 06:45:30 -04:00
|
|
|
$paging=Pagination::session(__METHOD__,$count,(int)$this->pagination_size,$pagination);
|
|
|
|
|
$this->pagination_size=$paging['size'];$this->pagination_page=$paging['page'];
|
|
|
|
|
$offset=$paging['offset'];$start=$paging['start'];$end=$paging['end'];
|
2026-10-18 17:01:36 +00:00
|
|
|
|
|
|
|
|
// Data
|
|
|
|
|
|
|
|
|
|
$SQL = "select view_statuses.*
|
|
|
|
|
from view_statuses
|
|
|
|
|
where status_name regexp :status_name
|
|
|
|
|
or status_classes regexp :status_classes
|
2026-10-20 06:45:30 -04:00
|
|
|
order by status_name,status_serial
|
2026-10-18 17:01:36 +00:00
|
|
|
limit {$this->pagination_size}
|
|
|
|
|
offset {$offset}";
|
|
|
|
|
|
|
|
|
|
$statement = $connection->prepare($SQL);
|
|
|
|
|
|
|
|
|
|
$statement->bindValue(":status_name", $find_words);
|
|
|
|
|
$statement->bindValue(":status_classes", $find_words);
|
|
|
|
|
|
|
|
|
|
$statement->execute();
|
|
|
|
|
|
|
|
|
|
$statuses = $this->getTableXML("statuses", $statement);
|
|
|
|
|
|
|
|
|
|
// Insert Pagination Attributes
|
|
|
|
|
|
|
|
|
|
$statuses->addAttribute("count", $count);
|
|
|
|
|
$statuses->addAttribute("start", $start);
|
|
|
|
|
$statuses->addAttribute("end", $end);
|
|
|
|
|
$statuses->addAttribute("page", $this->pagination_page);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $statuses;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==============
|
|
|
|
|
// Setup Statuses
|
|
|
|
|
// ==============
|
|
|
|
|
|
|
|
|
|
public function setupStatuses() {
|
|
|
|
|
|
|
|
|
|
$statuses = $this->getStatusesPage();
|
|
|
|
|
$popovers = (new Popovers())->getPopovers();
|
|
|
|
|
|
|
|
|
|
$XML = $this->mergeXML($statuses, "<XML/>");
|
|
|
|
|
$XML = $this->mergeXML($popovers, $XML);
|
|
|
|
|
|
|
|
|
|
$content = $this->applyXSL($XML, $this->getXSL("setupStatuses"));
|
|
|
|
|
|
|
|
|
|
$this->displayContent($content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|