git commit all base code

This commit is contained in:
2026-06-30 21:34:42 -04:00
parent 11fdf7b164
commit 1a643d7935
1452 changed files with 433360 additions and 0 deletions
+311
View File
@@ -0,0 +1,311 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create System Tables</title>
<style>
body {
background-color: #333;
color: white;
font-family: sans-serif;
padding: 1em;
}
.log {
margin-bottom: 1em;
}
.success {
color: #8fd19e;
}
.warning {
color: #ffd966;
}
.error {
color: #ff9999;
}
</style>
</head>
<body>
<?php
define("INITIALIZATION_FILE_NAME", "../xml/settings.xml");
define("INIT_SCRIPT_USER", "Init Script");
// Safety switch.
// Change this to true when you intentionally want to rebuild system tables.
$allow_rebuild = true;
if (!$allow_rebuild) {
echoLog("Rebuild is disabled. Set \$allow_rebuild to true to continue.", "warning");
exit();
}
// --------------------------
// Load Application Settings
// --------------------------
$applicationSettings = simplexml_load_file(INITIALIZATION_FILE_NAME);
if (empty($applicationSettings)) {
echoLog("Unable to load Application Settings.", "error");
exit();
}
// ---------------------
// Database Connection
// ---------------------
$host = (string) $applicationSettings->DatabaseServer;
$database = (string) $applicationSettings->DatabaseName;
$user = (string) $applicationSettings->DatabaseUser;
$password = (string) $applicationSettings->DatabasePassword;
try {
$connection = new PDO(
"mysql:host={$host};dbname={$database};charset=utf8mb4",
$user,
$password,
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]
);
$connection->exec("SET FOREIGN_KEY_CHECKS = 0");
} catch (PDOException | Exception $e) {
echoLog("Unable to connect to the database.", "error");
exit();
}
// ----------------------------
// Get Table Definition Files
// ----------------------------
$tableFiles = glob("*.php");
$excludedFiles = [
"_createSystemTable.php",
"_createTable.php",
basename(__FILE__),
];
$tableFiles = array_values(array_filter($tableFiles, function ($file) use ($excludedFiles) {
return !in_array($file, $excludedFiles, true);
}));
sort($tableFiles);
// ----------------------------
// Process Table Files
// ----------------------------
foreach ($tableFiles as $tableFile) {
$tableName = basename($tableFile, ".php");
echoLog("Processing {$tableName}...", "warning");
try {
$connection->exec("DROP VIEW IF EXISTS `view_{$tableName}`");
echoLog("Dropped view_{$tableName}, if it existed.", "success");
} catch (PDOException $e) {
echoLog("Could not drop view_{$tableName}.", "error");
continue;
}
try {
$connection->exec("DROP TABLE IF EXISTS `{$tableName}`");
echoLog("Dropped {$tableName}, if it existed.", "success");
} catch (PDOException $e) {
echoLog("Could not drop table {$tableName}.", "error");
continue;
}
$SQL = null;
if (!include $tableFile) {
echoLog("Failed to include {$tableFile}. Skipping.", "error");
continue;
}
if (empty($SQL)) {
echoLog("No SQL found in {$tableFile}. Skipping.", "error");
continue;
}
runSQL($SQL, $connection, "create {$tableName}");
switch ($tableFile) {
case "popovers.php":
seedPopovers($connection);
break;
case "users.php":
seedInitialAdminUser($connection);
break;
}
}
try {
$connection->exec("SET FOREIGN_KEY_CHECKS = 1");
} catch (PDOException $e) {
echoLog("Warning: Could not re-enable foreign key checks.", "warning");
}
echoLog("System tables created successfully.", "success");
// -------------------------
// Helper Functions
// -------------------------
function runSQL($SQL, PDO $connection, $context = "query") {
try {
$connection->exec($SQL);
echoLog("Completed {$context}.", "success");
} catch (PDOException $e) {
echoLog("Error running {$context}.", "error");
exit();
}
}
function seedPopovers(PDO $connection) {
$popovers = [
[
"find_user",
"Find User",
"Find User...",
"<p>Find by Name, Email, or Role</p>"
],
[
"find_report",
"Find Report",
"Find Report...",
"<p>Find by Name or Description</p>"
],
[
"select_report",
"Select Report",
"Find Report...",
"<p>Find by Name, Email, or Role</p>"
],
[
"find_popover",
"Find Popover",
"Find Popover...",
"<p>Find by Name, Title or Placeholder</p>"
],
[
"find_journal",
"Find Journal",
"Find Journal...",
"<p>Find by Name, Email, or Role</p>"
],
[
"find_status",
"Find Status",
"Find Status...",
"<p>Find by Name</p>"
],
[
"find_dropdowntype",
"Find Dropdown Types",
"Find Dropdown Types...",
"<p>Search for dropdown types</p>"
],
];
$SQL = "
INSERT INTO popovers (
popover_name,
popover_title,
popover_placeholder,
popover_text,
popover_created,
popover_creator
) VALUES (
:popover_name,
:popover_title,
:popover_placeholder,
:popover_text,
CURDATE(),
:popover_creator
)
";
$statement = $connection->prepare($SQL);
foreach ($popovers as $popover) {
$statement->execute([
":popover_name" => $popover[0],
":popover_title" => $popover[1],
":popover_placeholder" => $popover[2],
":popover_text" => $popover[3],
":popover_creator" => INIT_SCRIPT_USER,
]);
}
echoLog("Seeded popovers.", "success");
}
function seedInitialAdminUser(PDO $connection) {
$password = password_hash("349Jamot@", PASSWORD_DEFAULT);
$SQL = "
INSERT INTO users (
user_id,
user_name,
user_email,
user_password,
user_role,
user_change_password,
user_active,
user_creator,
user_created
) VALUES (
:user_id,
:user_name,
:user_email,
:user_password,
:user_role,
:user_change_password,
:user_active,
:user_creator,
CURDATE()
)
";
$statement = $connection->prepare($SQL);
$statement->execute([
":user_id" => "DSYSADMIN",
":user_name" => "James Richie",
":user_email" => "james.richie@onesourceits.com",
":user_password" => $password,
":user_role" => "Administrator",
":user_change_password" => 1,
":user_active" => 1,
":user_creator" => INIT_SCRIPT_USER,
]);
echoLog("Seeded initial administrator user.", "success");
}
function echoLog($message, $type = "") {
$class = trim("log {$type}");
echo "<div class='{$class}'>" . htmlspecialchars($message, ENT_QUOTES, "UTF-8") . "</div>";
}
?>
</body>
</html>
+101
View File
@@ -0,0 +1,101 @@
<style>
body {
background-color: #333333;
color: white;
font-family: sans-serif;
padding: 1em;
}
</style>
<?php
define("INITIALIZATION_FILE_NAME", "../xml/settings.xml");
// Retrieve and validate table name.
$table = trim($_GET["table"] ?? "");
if ($table === "") {
echo "No table name given. Table not created.";
exit();
}
if (!preg_match('/^[a-zA-Z0-9_]+$/', $table)) {
echo "Invalid table name. Table not created.";
exit();
}
$tableFile = __DIR__ . "/{$table}.php";
if (!is_file($tableFile)) {
echo htmlspecialchars("{$table}.php not found. Table not created.", ENT_QUOTES, "UTF-8");
exit();
}
// Load table SQL.
$SQL = null;
include $tableFile;
if (empty($SQL)) {
echo htmlspecialchars("No SQL found in {$table}.php. Table not created.", ENT_QUOTES, "UTF-8");
exit();
}
// Retrieve Application Settings.
$applicationSettings = simplexml_load_file(INITIALIZATION_FILE_NAME);
if (empty($applicationSettings)) {
echo "Unable to load Application Settings.";
exit();
}
// Connect to the Database.
$host = ((string) $applicationSettings->Environment === "Production") ? "localhost" : "192.168.1.190";
$database = (string) $applicationSettings->DatabaseName;
$user = (string) $applicationSettings->DatabaseUser;
$password = (string) $applicationSettings->DatabasePassword;
try {
$connection = new PDO(
"mysql:host={$host};dbname={$database};charset=utf8mb4",
$user,
$password,
[
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]
);
} catch (PDOException | Exception $e) {
echo "Unable to connect to the database.";
exit();
}
// Drop and recreate table.
try {
$connection->exec("SET FOREIGN_KEY_CHECKS = 0");
$connection->exec("DROP TABLE IF EXISTS `{$table}`");
$connection->exec($SQL);
$connection->exec("SET FOREIGN_KEY_CHECKS = 1");
echo htmlspecialchars("Table {$table} was created.", ENT_QUOTES, "UTF-8");
} catch (PDOException | Exception $e) {
try {
$connection->exec("SET FOREIGN_KEY_CHECKS = 1");
} catch (Exception $ignored) {
}
echo "Error creating table.";
exit();
}
?>
+23
View File
@@ -0,0 +1,23 @@
<?php
$SQL = "create table alerts
(
alert_serial serial,
alert_title varchar(100) default null,
alert_started datetime default null,
alert_expired datetime default null,
alert_message varchar(1000) default null,
alert_creator varchar(100) default null,
alert_created datetime default null,
alert_changer varchar(100) default null,
alert_changed datetime default null,
primary key (alert_serial)
)
default character set = utf8";
?>
+30
View File
@@ -0,0 +1,30 @@
<?php
$SQL = "create table dropdowns
(
dropdown_serial serial,
dropdown_dropdowntype bigint unsigned default 0,
dropdown_value varchar(100) default null,
dropdown_default boolean default false,
dropdown_active boolean default false,
dropdown_creator varchar(100) default null,
dropdown_created datetime default null,
dropdown_changer varchar(100) default null,
dropdown_changed datetime default null,
primary key (dropdown_serial),
unique key (dropdown_dropdowntype, dropdown_value),
foreign key (dropdown_dropdowntype)
references dropdowntypes(dropdowntype_serial)
on update cascade
on delete restrict
)
default character set = utf8";
?>
+25
View File
@@ -0,0 +1,25 @@
<?php
$SQL = "create table dropdowntypes
(
dropdowntype_serial serial,
dropdowntype_name varchar(100) default null,
dropdowntype_title varchar(100) default null,
dropdowntype_table varchar(100) default null,
dropdowntype_column varchar(100) default null,
dropdowntype_creator varchar(100) default null,
dropdowntype_created datetime default null,
dropdowntype_changer varchar(100) default null,
dropdowntype_changed datetime default null,
primary key (dropdowntype_serial),
unique key (dropdowntype_name)
)
default character set = utf8";
?>
+20
View File
@@ -0,0 +1,20 @@
<?php
$SQL = "create table journal
(
journal_serial serial,
journal_timestamp timestamp default current_timestamp,
journal_origin varchar(100) default null,
journal_ip varchar(128) default null,
journal_entry varchar(1000) default null,
primary key (journal_serial),
index (journal_timestamp)
)
default character set = utf8";
?>
+22
View File
@@ -0,0 +1,22 @@
<?php
$SQL = "create table notes
(
note_serial serial,
note_type varchar(20) default null,
note_reference bigint unsigned default 0,
note_text text,
note_timestamp timestamp default current_timestamp on update current_timestamp,
note_origin varchar(100) default null,
primary key (note_serial),
index (note_type),
index (note_reference),
index (note_timestamp)
)
default character set = utf8";
?>
+24
View File
@@ -0,0 +1,24 @@
<?php
$SQL = "create table popovers
(
popover_serial serial,
popover_name varchar(100) default null,
popover_title varchar(100) default null,
popover_placeholder varchar(100) default null,
popover_text varchar(1000) default null,
popover_creator varchar(100) default null,
popover_created datetime default null,
popover_changer varchar(100) default null,
popover_changed datetime default null,
primary key (popover_serial),
unique key (popover_name)
)
default character set = utf8";
?>
+24
View File
@@ -0,0 +1,24 @@
<?php
$SQL = "create table reports
(
report_serial serial,
report_class varchar(100) default null,
report_name varchar(100) default null,
report_description varchar(100) default null,
report_type varchar(10) default null,
report_target varchar(50) default null,
report_creator varchar(100) default null,
report_created datetime default null,
report_changer varchar(100) default null,
report_changed datetime default null,
primary key (report_serial)
)
default character set = utf8";
?>
+24
View File
@@ -0,0 +1,24 @@
<?php
$SQL = "create table statuses
(
status_serial serial,
status_name varchar(100) default null,
status_classes varchar(100) default null,
status_active boolean default true,
status_default boolean default false,
status_creator varchar(100) default null,
status_created datetime default null,
status_changer varchar(100) default null,
status_changed datetime default null,
primary key (status_serial),
index (status_name)
)
default character set = utf8";
?>
+29
View File
@@ -0,0 +1,29 @@
<?php
$SQL = "create table users
(
user_serial serial,
user_id varchar(100) default null,
user_name varchar(128) default null,
user_email varchar(100) default null,
user_client_name varchar(128) default null,
user_password varchar(255) not null,
user_role varchar(255) not null,
user_change_password boolean default false,
user_active boolean default true,
user_login datetime default null,
user_creator varchar(100) default null,
user_created datetime default null,
user_changer varchar(100) default null,
user_changed datetime default null,
primary key (user_serial),
unique key (user_name),
index (user_name)
)
default character set = utf8";
?>
+21
View File
@@ -0,0 +1,21 @@
<?php
$SQL = "create table zipcodes
(
zipcode_serial serial,
zipcode_code bigint not null default 0,
zipcode_city varchar(50) not null default '',
zipcode_state varchar(50) not null default '',
zipcode_county varchar(50) not null default '',
zipcode_country varchar(50) not null default '',
primary key (zipcode_serial),
unique key (zipcode_code)
)
default character set = utf8";
?>