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; } // =================== // Setup History Codes // =================== public function setupHistoryCodes() { $historycodes = $this->getHistoryCodesPage(); $popovers = (new Popovers())->getPopovers(); $XML = $this->mergeXML($historycodes, ""); $XML = $this->mergeXML($popovers, $XML); $content = $this->applyXSL($XML, $this->getXSL("setupHistoryCodes")); $this->displayContent($content); } // ================ // Add History Code // ================ public function addHistoryCode() { $step = filter_input(INPUT_POST, "step") ?: "prompt"; switch ($step) { case "prompt": $content = $this->applyXSL("", $this->getXSL("addHistoryCode")); $this->displayContent($content); break; case "add": $historycode_code = filter_input(INPUT_POST, "historycode_code") ?: ""; $historycode_description = filter_input(INPUT_POST, "historycode_description") ?: ""; $SQL = "insert into historycodes ( historycode_code, historycode_description, historycode_active, historycode_creator, historycode_created ) VALUES ( :historycode_code, :historycode_description, :historycode_active, :historycode_creator, :historycode_created )"; $statement = $this->connect()->prepare($SQL); $statement->bindValue(":historycode_code", strtoupper($historycode_code)); $statement->bindValue(":historycode_description", $historycode_description); $statement->bindValue(":historycode_active", true, PDO::PARAM_BOOL); $statement->bindValue(":historycode_creator", $this->current_user_name); $statement->bindValue(":historycode_created", $this->getTimestamp()); $statement->execute(); break; default: $this->displayHome(); } } // =================== // Edit a History Code // =================== public function editHistoryCode() { $step = filter_input(INPUT_POST, "step") ?: "prompt"; switch ($step) { case "prompt": $historycode_serial = filter_input(INPUT_POST, "historycode_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0; $historycode = $this->getHistoryCode($historycode_serial); if ($historycode->count() == 0) { $this->logError("Invalid History Code ({$historycode_serial}). " . __METHOD__); } $content = $this->applyXSL($historycode, $this->getXSL("editHistoryCode")); $this->displayContent($content); break; case "update": $historycode_serial = filter_input(INPUT_POST, "historycode_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0; $historycode_code = filter_input(INPUT_POST, "historycode_code") ?: ""; $historycode_description = filter_input(INPUT_POST, "historycode_description") ?: ""; $historycode_active = filter_input(INPUT_POST, "historycode_active", FILTER_VALIDATE_BOOLEAN) ?: false; // Verify the HistoryCodes $historycode = $this->getHistoryCode($historycode_serial); if ($historycode->count() == 0) { $this->logError("Invalid HistoryCodes ({$historycode_serial}). " . __METHOD__); } $SQL = "update historycodes set historycode_code = :historycode_code, historycode_description = :historycode_description, historycode_active = :historycode_active, historycode_changer = :historycode_changer, historycode_changed = :historycode_changed where historycode_serial = :historycode_serial"; $statement = $this->connect()->prepare($SQL); $statement->bindValue(":historycode_serial", $historycode_serial); $statement->bindValue(":historycode_code", strtoupper($historycode_code)); $statement->bindValue(":historycode_description", $historycode_description); $statement->bindValue(":historycode_active", $historycode_active, PDO::PARAM_BOOL); $statement->bindValue(":historycode_changer", $this->current_user_name); $statement->bindValue(":historycode_changed", $this->getTimestamp()); $statement->execute(); break; default: $this->displayHome(); } } // =================== // Delete History Code // =================== public function deleteHistoryCode() { $historycode_serial = filter_input(INPUT_POST, "historycode_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0; $historycode = $this->getHistoryCode($historycode_serial); if ($historycode->count() == 0) { $this->logError("Invalid History Code ({$historycode_serial}). " . __METHOD__); } $SQL = "delete from historycodes where historycode_serial = {$historycode_serial}"; $this->executeSQL($SQL); } // ===================================== // Return an Active History Codes Object // ===================================== public function getActiveHistoryCodes() { $SQL = "select view_historycodes.* from view_historycodes where historycode_active is true"; return $this->getTable("historycodes", $SQL); } // ============================== // Return an History Codes Object // ============================== public function getHistoryCode($historycode_serial = 0) { $SQL = "select view_historycodes.* from view_historycodes where historycode_serial = {$historycode_serial}"; return $this->getTable("historycodes", $SQL); } // ============================= // Return a History Codes Object // ============================= public function getHistoryCodes() { $SQL = "select view_historycodes.* from view_historycodes"; return $this->getTable("historycodes", $SQL); } // ================================== // Return a History Codes Page Object // ================================== public function getHistoryCodesPage() { // Find Criteria $find_historycode = filter_input(INPUT_POST, "find_historycode") ?: ""; $find_historycode = $this->sanitizeString($find_historycode); $find_words = implode("|", explode(" ", $find_historycode)); // Record Count $connection = $this->connect(); $SQL = "select count(*) as count from view_historycodes where historycode_code regexp :historycode_code or historycode_description regexp :historycode_description"; $statement = $connection->prepare($SQL); $statement->bindValue(":historycode_code", $find_words); $statement->bindValue(":historycode_description", $find_words); $statement->execute(); $recordset = $statement->fetch(PDO::FETCH_ASSOC); $count = (count($recordset) > 0) ? (integer) $recordset["count"] : (integer) 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_historycodes.* from view_historycodes where historycode_code regexp :historycode_code or historycode_description regexp :historycode_description order by historycode_code limit {$this->pagination_size} offset {$offset}"; $statement = $connection->prepare($SQL); $statement->bindValue(":historycode_code", $find_words); $statement->bindValue(":historycode_description", $find_words); $statement->execute(); $historycodes = $this->getTableXML("historycodes", $statement); // Insert Pagination Attributes $historycodes->addAttribute("count", $count); $historycodes->addAttribute("start", $start); $historycodes->addAttribute("end", $end); $historycodes->addAttribute("page", $this->pagination_page); $_SESSION[self::PAGINATION_PAGE] = $this->pagination_page; return $historycodes; } } ?>