first commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<style>
|
||||
body {
|
||||
background-color: #333333;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php
|
||||
// Simple Script to create a MySQL Table.
|
||||
|
||||
define("INITIALIZATION_FILE_NAME", "../xml/settings.xml");
|
||||
|
||||
// Retrieve the Table Name.
|
||||
|
||||
$table = (isset($_GET["table"])) ? $_GET["table"] : "";
|
||||
|
||||
if (empty($table)) {
|
||||
echo "No table name given. Table not created.";
|
||||
exit();
|
||||
}
|
||||
|
||||
if ((include "{$table}.php") != true) {
|
||||
echo "{$table}.php not found. Table not created.";
|
||||
exit;
|
||||
}
|
||||
|
||||
// Retrieve Application Settings
|
||||
|
||||
$applicationSettings = simplexml_load_file(INITIALIZATION_FILE_NAME);
|
||||
|
||||
if (empty($applicationSettings)) {
|
||||
echo "Unable to load Application Settings." . PHP_EOL;
|
||||
exit();
|
||||
}
|
||||
|
||||
// Connect to the Database.
|
||||
|
||||
$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}", $user, $password);
|
||||
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
||||
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (PDOException | Exception $e) {
|
||||
echo "Unable to connect to the database. <br/>";
|
||||
echo "Error is: {$e->getMessage()}";
|
||||
exit();
|
||||
}
|
||||
|
||||
// Create the table.
|
||||
|
||||
$connection->exec("set foreign_key_checks = 0");
|
||||
$connection->exec("drop table if exists {$table}");
|
||||
|
||||
try {
|
||||
$connection->exec($SQL);
|
||||
} catch (PDOException | Exception $e) {
|
||||
echo "Error creating table. <br/>";
|
||||
echo "Error is: {$e->getMessage()}";
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($connection->errorCode() != 0) {
|
||||
echo "Error creating table. <br/>";
|
||||
echo "<pre>";
|
||||
print_r($connection->errorInfo());
|
||||
} else {
|
||||
echo "Table {$table} was created.";
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
$SQL = "create table cities (
|
||||
|
||||
city_serial serial,
|
||||
city_name varchar(120) default null,
|
||||
city_state varchar(120) default null,
|
||||
|
||||
city_creator varchar(100) default null,
|
||||
city_created datetime default null,
|
||||
city_changer varchar(100) default null,
|
||||
city_changed datetime default null,
|
||||
|
||||
primary key (city_serial)
|
||||
|
||||
) default character set = utf8";
|
||||
?>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
$SQL = "create table countycodes
|
||||
|
||||
(
|
||||
|
||||
countycode_serial serial,
|
||||
countycode_code char(3) default null,
|
||||
countycode_name varchar(120) default null,
|
||||
countycode_state varchar(120) default null,
|
||||
countycode_active boolean default true,
|
||||
|
||||
countycode_creator varchar(100) default null,
|
||||
countycode_created datetime default null,
|
||||
countycode_changer varchar(100) default null,
|
||||
countycode_changed datetime default null,
|
||||
|
||||
primary key (countycode_serial)
|
||||
|
||||
)
|
||||
|
||||
default character set = utf8";
|
||||
?>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
$SQL = "create table exportjobs (
|
||||
|
||||
exportjob_serial serial,
|
||||
exportjob_export_code char(36) default null,
|
||||
exportjob_license_type varchar(20) default null,
|
||||
exportjob_status enum('queued','running','complete','failed') not null default 'queued',
|
||||
exportjob_file_name varchar(255) default null,
|
||||
exportjob_file_path varchar(1024) default null,
|
||||
exportjob_file_type varchar(10) default null,
|
||||
exportjob_searchcriteria text default null,
|
||||
exportjob_notified boolean default false,
|
||||
exportjob_download_token varchar(1024) default null,
|
||||
exportjob_error_message text default null,
|
||||
exportjob_creator varchar(100) default null,
|
||||
exportjob_created datetime default null,
|
||||
exportjob_completed datetime default null,
|
||||
|
||||
primary key (exportjob_serial),
|
||||
unique key uq_export_job_code (exportjob_export_code),
|
||||
key idx_status_created (exportjob_status, exportjob_created),
|
||||
key idx_created_by (exportjob_creator),
|
||||
key idx_token (exportjob_download_token) )";
|
||||
?>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
$SQL = "create table fwc_commercial_license_codes
|
||||
|
||||
(
|
||||
|
||||
license_serial serial,
|
||||
license_code varchar(10) default null,
|
||||
license_description varchar(255) default null,
|
||||
|
||||
license_creator varchar(100) default null,
|
||||
license_created datetime default null,
|
||||
license_changer varchar(100) default null,
|
||||
license_changed datetime default null,
|
||||
|
||||
primary key (license_serial)
|
||||
|
||||
)
|
||||
|
||||
default character set = utf8";
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
$SQL = "CREATE TABLE fwc_commercial_license_imports (
|
||||
|
||||
import_serial serial,
|
||||
|
||||
import_batch_code CHAR(36) NOT NULL,
|
||||
source_file VARCHAR(100) NOT NULL DEFAULT '',
|
||||
license_code VARCHAR(10) NOT NULL DEFAULT '',
|
||||
|
||||
file_path VARCHAR(255) NOT NULL DEFAULT '',
|
||||
file_size BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
|
||||
records_imported BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
|
||||
import_status ENUM('queued', 'running', 'complete', 'failed') NOT NULL DEFAULT 'queued',
|
||||
error_message TEXT NULL,
|
||||
|
||||
started_at DATETIME NULL,
|
||||
completed_at DATETIME NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
PRIMARY KEY (import_serial),
|
||||
|
||||
UNIQUE KEY uq_import_batch_source (import_batch_code, source_file),
|
||||
KEY idx_license_code (license_code),
|
||||
KEY idx_import_status (import_status),
|
||||
KEY idx_source_file (source_file)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";
|
||||
?>
|
||||
z
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
$SQL = "CREATE TABLE fwc_commercial_licenses (
|
||||
|
||||
commercial_license_serial serial,
|
||||
|
||||
commercial_license_source_file VARCHAR(100) NOT NULL DEFAULT '',
|
||||
commercial_license_code VARCHAR(10) NOT NULL DEFAULT '',
|
||||
|
||||
commercial_license_number VARCHAR(100) NOT NULL DEFAULT '',
|
||||
commercial_license_applicant_id BIGINT UNSIGNED NULL,
|
||||
|
||||
commercial_license_florida_residency VARCHAR(100) NOT NULL DEFAULT '',
|
||||
commercial_license_issued_to VARCHAR(255) NOT NULL DEFAULT '',
|
||||
commercial_license_scope VARCHAR(255) NOT NULL DEFAULT '',
|
||||
|
||||
commercial_license_begin_date DATETIME NULL,
|
||||
commercial_license_expire_date DATETIME NULL,
|
||||
|
||||
commercial_license_company_or_last_name VARCHAR(255) NOT NULL DEFAULT '',
|
||||
commercial_license_first_name VARCHAR(100) NOT NULL DEFAULT '',
|
||||
commercial_license_middle_init VARCHAR(50) NOT NULL DEFAULT '',
|
||||
commercial_license_suffix VARCHAR(50) NOT NULL DEFAULT '',
|
||||
|
||||
commercial_license_email_address VARCHAR(150) NOT NULL DEFAULT '',
|
||||
commercial_license_county VARCHAR(100) NOT NULL DEFAULT '',
|
||||
|
||||
commercial_license_mail_street1 VARCHAR(255) NOT NULL DEFAULT '',
|
||||
commercial_license_mail_street2 VARCHAR(255) NOT NULL DEFAULT '',
|
||||
commercial_license_mail_city VARCHAR(100) NOT NULL DEFAULT '',
|
||||
commercial_license_mail_state VARCHAR(50) NOT NULL DEFAULT '',
|
||||
commercial_license_mail_zip_code VARCHAR(20) NOT NULL DEFAULT '',
|
||||
commercial_license_mail_zip4 VARCHAR(10) NOT NULL DEFAULT '',
|
||||
|
||||
commercial_license_applicant_phone VARCHAR(30) NOT NULL DEFAULT '',
|
||||
|
||||
commercial_license_endorsement_number VARCHAR(100) NOT NULL DEFAULT '',
|
||||
commercial_license_endorsement_expiration_date DATETIME NULL,
|
||||
commercial_license_total_tag_qty INT UNSIGNED NULL,
|
||||
|
||||
commercial_license_import_batch_code CHAR(36) NOT NULL DEFAULT '',
|
||||
commercial_license_imported_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
PRIMARY KEY (commercial_license_serial),
|
||||
|
||||
KEY idx_source_file (commercial_license_source_file),
|
||||
KEY idx_license_code (commercial_license_code),
|
||||
KEY idx_license_number (commercial_license_number),
|
||||
KEY idx_applicant_id (commercial_license_applicant_id),
|
||||
KEY idx_name (commercial_license_company_or_last_name, commercial_license_first_name),
|
||||
KEY idx_email (commercial_license_email_address),
|
||||
KEY idx_county (commercial_license_county),
|
||||
KEY idx_license_dates (commercial_license_begin_date, commercial_license_expire_date),
|
||||
KEY idx_import_batch (commercial_license_import_batch_code)
|
||||
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
?>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
$SQL = "CREATE TABLE fwc_recreational_license_imports (
|
||||
|
||||
import_serial BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
import_batch_code CHAR(36) NOT NULL,
|
||||
source_file VARCHAR(100) NOT NULL DEFAULT '',
|
||||
file_path VARCHAR(255) NOT NULL DEFAULT '',
|
||||
file_size BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
records_imported BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
import_status ENUM('queued', 'running', 'complete', 'failed') NOT NULL DEFAULT 'queued',
|
||||
error_message TEXT NULL,
|
||||
started_at DATETIME NULL,
|
||||
completed_at DATETIME NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
PRIMARY KEY (import_serial),
|
||||
UNIQUE KEY uq_import_batch_source (import_batch_code, source_file),
|
||||
KEY idx_import_status (import_status),
|
||||
KEY idx_source_file (source_file))
|
||||
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
?>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
$SQL = "CREATE TABLE fwc_recreational_licenses (
|
||||
|
||||
license_serial BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
license_source_file VARCHAR(100) NOT NULL DEFAULT '',
|
||||
|
||||
license_last_name VARCHAR(100) NOT NULL DEFAULT '',
|
||||
license_first_name VARCHAR(100) NOT NULL DEFAULT '',
|
||||
license_middle_name VARCHAR(100) NOT NULL DEFAULT '',
|
||||
|
||||
license_street1 VARCHAR(255) NOT NULL DEFAULT '',
|
||||
license_city VARCHAR(100) NOT NULL DEFAULT '',
|
||||
license_state VARCHAR(50) NOT NULL DEFAULT '',
|
||||
license_zip_code VARCHAR(20) NOT NULL DEFAULT '',
|
||||
|
||||
license_phone_number VARCHAR(30) NOT NULL DEFAULT '',
|
||||
license_email_address VARCHAR(150) NOT NULL DEFAULT '',
|
||||
|
||||
license_gender VARCHAR(50) NOT NULL DEFAULT '',
|
||||
license_ethnicity VARCHAR(100) NOT NULL DEFAULT '',
|
||||
|
||||
license_type VARCHAR(255) NOT NULL DEFAULT '',
|
||||
|
||||
license_expire_date DATETIME NULL,
|
||||
license_start_date DATETIME NULL,
|
||||
|
||||
license_age_at_time_of_run INT UNSIGNED NULL,
|
||||
license_county VARCHAR(100) NOT NULL DEFAULT '',
|
||||
|
||||
import_batch_code CHAR(36) NOT NULL DEFAULT '',
|
||||
imported_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
PRIMARY KEY (license_serial),
|
||||
|
||||
KEY idx_source_file (license_source_file),
|
||||
KEY idx_name (license_last_name, license_first_name, license_middle_name),
|
||||
KEY idx_license_type (license_type),
|
||||
KEY idx_expire_date (license_expire_date),
|
||||
KEY idx_start_date (license_start_date),
|
||||
KEY idx_county (license_county),
|
||||
KEY idx_email (license_email_address),
|
||||
KEY idx_import_batch (import_batch_code))
|
||||
|
||||
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
?>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
$SQL = "create table historycodes
|
||||
|
||||
(
|
||||
|
||||
historycode_serial serial,
|
||||
historycode_code char(1) default null,
|
||||
historycode_description varchar(120) default null,
|
||||
historycode_active boolean default true,
|
||||
|
||||
historycode_creator varchar(100) default null,
|
||||
historycode_created datetime default null,
|
||||
historycode_changer varchar(100) default null,
|
||||
historycode_changed datetime default null,
|
||||
|
||||
primary key (historycode_serial)
|
||||
|
||||
)
|
||||
|
||||
default character set = utf8";
|
||||
?>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
$SQL = "create table politicalparties
|
||||
|
||||
(
|
||||
|
||||
politicalparty_serial serial,
|
||||
politicalparty_code char(3) default null,
|
||||
politicalparty_name varchar(120) default null,
|
||||
politicalparty_active boolean default true,
|
||||
|
||||
politicalparty_creator varchar(100) default null,
|
||||
politicalparty_created datetime default null,
|
||||
politicalparty_changer varchar(100) default null,
|
||||
politicalparty_changed datetime default null,
|
||||
|
||||
primary key (politicalparty_serial)
|
||||
|
||||
)
|
||||
|
||||
default character set = utf8";
|
||||
?>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
$SQL = "create table racecodes
|
||||
|
||||
(
|
||||
|
||||
racecode_serial serial,
|
||||
racecode_code tinyint unsigned default null,
|
||||
racecode_description varchar(120) default null,
|
||||
racecode_active boolean default true,
|
||||
|
||||
racecode_creator varchar(100) default null,
|
||||
racecode_created datetime default null,
|
||||
racecode_changer varchar(100) default null,
|
||||
racecode_changed datetime default null,
|
||||
|
||||
primary key (racecode_serial)
|
||||
|
||||
)
|
||||
|
||||
default character set = utf8";
|
||||
?>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
$SQL = "create table searchhistories
|
||||
|
||||
(
|
||||
|
||||
searchhistory_serial serial,
|
||||
searchhistory_user bigint unsigned default null,
|
||||
searchhistory_subscription bigint unsigned default null,
|
||||
searchhistory_parameters longtext default null,
|
||||
|
||||
searchhistory_creator varchar(100) default null,
|
||||
searchhistory_created datetime default null,
|
||||
searchhistory_changer varchar(100) default null,
|
||||
searchhistory_changed datetime default null,
|
||||
|
||||
primary key (searchhistory_serial)
|
||||
|
||||
)
|
||||
|
||||
default character set = utf8";
|
||||
?>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
$SQL = "create table subscriptions
|
||||
|
||||
(
|
||||
|
||||
subscription_serial serial,
|
||||
subscription_title varchar(50) not null default '',
|
||||
subscription_service_level bigint unsigned default null,
|
||||
subscription_market bigint unsigned default null,
|
||||
|
||||
subscription_creator varchar(100) default null,
|
||||
subscription_created datetime default null,
|
||||
subscription_changer varchar(100) default null,
|
||||
subscription_changed datetime default null,
|
||||
|
||||
primary key (subscription_serial)
|
||||
|
||||
)
|
||||
|
||||
default character set = utf8";
|
||||
?>
|
||||
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Create System Tables
|
||||
* - Loads DB settings from ../xml/settings.xml
|
||||
* - Scans current dir for table definition files (*.php), excludes bootstrap scripts
|
||||
* - Drops related view + table, then runs $SQL from each included file
|
||||
* - Seeds data for certain tables (popovers, users)
|
||||
*
|
||||
* NOTE: Your table definition files should set: $SQL = "CREATE TABLE ...";
|
||||
*/
|
||||
define('INITIALIZATION_FILE_NAME', __DIR__ . '/../../xml/settings.xml');
|
||||
|
||||
$logs = [];
|
||||
|
||||
function logLine(array &$logs, string $msg): void {
|
||||
$logs[] = $msg;
|
||||
}
|
||||
|
||||
function runSQL(PDO $db, ?string $sql, string $context, array &$logs): void {
|
||||
if ($sql === null || trim($sql) === '') {
|
||||
logLine($logs, "⚠️ Skipping empty SQL for <strong>{$context}</strong>.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$db->exec($sql);
|
||||
} catch (PDOException $e) {
|
||||
logLine($logs, "❌ Error running <strong>{$context}</strong>: " . htmlspecialchars($e->getMessage(), ENT_QUOTES));
|
||||
renderPage($logs, false);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function renderPage(array $logs, bool $ok): void {
|
||||
$status = $ok ? "✅ System Tables Created." : "❌ Script stopped due to an error.";
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Create System Tables</title>
|
||||
<style>
|
||||
body {
|
||||
background-color:#333;
|
||||
color:#fff;
|
||||
font-family:sans-serif;
|
||||
padding:1em;
|
||||
}
|
||||
.log {
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
.done {
|
||||
margin-top: 1em;
|
||||
font-weight: bold;
|
||||
}
|
||||
code {
|
||||
background: rgba(255,255,255,.08);
|
||||
padding: .15em .35em;
|
||||
border-radius: 6px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?php foreach ($logs as $line): ?>
|
||||
<div class="log"><?= $line ?></div>
|
||||
<?php endforeach; ?>
|
||||
<div class="done"><?= $status ?></div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
}
|
||||
|
||||
// --------------------
|
||||
// Load App Settings
|
||||
// --------------------
|
||||
if (!file_exists(INITIALIZATION_FILE_NAME)) {
|
||||
logLine($logs, "❌ Initialization file not found: <code>" . htmlspecialchars(INITIALIZATION_FILE_NAME, ENT_QUOTES) . "</code>");
|
||||
renderPage($logs, false);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$applicationSettings = @simplexml_load_file(INITIALIZATION_FILE_NAME);
|
||||
if (!$applicationSettings) {
|
||||
logLine($logs, "❌ Unable to load Application Settings from <code>" . htmlspecialchars(INITIALIZATION_FILE_NAME, ENT_QUOTES) . "</code>.");
|
||||
renderPage($logs, false);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// --------------------
|
||||
// Database Connection
|
||||
// --------------------
|
||||
$host = (string) ($applicationSettings->DatabaseServer ?? '');
|
||||
$database = (string) ($applicationSettings->DatabaseName ?? '');
|
||||
$user = (string) ($applicationSettings->DatabaseUser ?? '');
|
||||
$pass = (string) ($applicationSettings->DatabasePassword ?? '');
|
||||
|
||||
if ($host === '' || $database === '' || $user === '') {
|
||||
logLine($logs, "❌ Missing DB settings in settings.xml (DatabaseServer/DatabaseName/DatabaseUser).");
|
||||
renderPage($logs, false);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
$dsn = "mysql:host={$host};dbname={$database};charset=utf8mb4";
|
||||
$db = new PDO($dsn, $user, $pass, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
|
||||
$db->exec("SET FOREIGN_KEY_CHECKS = 0");
|
||||
} catch (Throwable $e) {
|
||||
logLine($logs, "❌ Unable to connect to the database.<br/>Error: " . htmlspecialchars($e->getMessage(), ENT_QUOTES));
|
||||
renderPage($logs, false);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// --------------------
|
||||
// Find Table Files
|
||||
// --------------------
|
||||
$exclude = [
|
||||
'.', '..',
|
||||
'_createSystemTable.php',
|
||||
'_createTable.php',
|
||||
];
|
||||
|
||||
$dirFiles = scandir(__DIR__) ?: [];
|
||||
$tableFiles = array_values(array_filter($dirFiles, function ($f) use ($exclude) {
|
||||
if (in_array($f, $exclude, true))
|
||||
return false;
|
||||
if (pathinfo($f, PATHINFO_EXTENSION) !== 'php')
|
||||
return false;
|
||||
return is_file(__DIR__ . '/' . $f);
|
||||
}));
|
||||
|
||||
if (!$tableFiles) {
|
||||
logLine($logs, "⚠️ No table definition files found in <code>" . htmlspecialchars(__DIR__, ENT_QUOTES) . "</code>.");
|
||||
renderPage($logs, true);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// --------------------
|
||||
// Process Each File
|
||||
// --------------------
|
||||
foreach ($tableFiles as $tableFile) {
|
||||
|
||||
$tableName = pathinfo($tableFile, PATHINFO_FILENAME);
|
||||
logLine($logs, "Processing <strong>" . htmlspecialchars($tableName, ENT_QUOTES) . "</strong>...");
|
||||
|
||||
// Drop view + table
|
||||
try {
|
||||
$db->exec("DROP VIEW IF EXISTS `view_{$tableName}`");
|
||||
} catch (PDOException $e) {
|
||||
logLine($logs, "⚠️ Error dropping view <code>view_{$tableName}</code>: " . htmlspecialchars($e->getMessage(), ENT_QUOTES));
|
||||
}
|
||||
|
||||
try {
|
||||
$db->exec("DROP TABLE IF EXISTS `{$tableName}`");
|
||||
} catch (PDOException $e) {
|
||||
logLine($logs, "⚠️ Error dropping table <code>{$tableName}</code>: " . htmlspecialchars($e->getMessage(), ENT_QUOTES));
|
||||
}
|
||||
|
||||
// Include file (expects it to set $SQL)
|
||||
$SQL = null;
|
||||
$fullPath = __DIR__ . '/' . $tableFile;
|
||||
|
||||
try {
|
||||
$result = include $fullPath;
|
||||
if ($result === false) {
|
||||
logLine($logs, "❌ Failed to include <code>" . htmlspecialchars($tableFile, ENT_QUOTES) . "</code>. Skipping.");
|
||||
continue;
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
logLine($logs, "❌ Exception including <code>" . htmlspecialchars($tableFile, ENT_QUOTES) . "</code>: " . htmlspecialchars($e->getMessage(), ENT_QUOTES));
|
||||
renderPage($logs, false);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
runSQL($db, $SQL, $tableName, $logs);
|
||||
|
||||
// --------------------
|
||||
// Seeds / Extras
|
||||
// --------------------
|
||||
if ($tableFile === 'popovers.php') {
|
||||
|
||||
$sqlQueries = [
|
||||
"INSERT INTO popovers (popover_name, popover_title, popover_placeholder, popover_text, popover_created, popover_creator)
|
||||
VALUES ('find_user', 'Find User', 'Find User...', '<p>Find by Name, Email, or Role</p>', CURDATE(), 'Init Script')",
|
||||
"INSERT INTO popovers (popover_name, popover_title, popover_placeholder, popover_text, popover_created, popover_creator)
|
||||
VALUES ('find_report', 'Find Report', 'Find Report...', '<p>Find by Name or Description</p>', CURDATE(), 'Init Script')",
|
||||
"INSERT INTO popovers (popover_name, popover_title, popover_placeholder, popover_text, popover_created, popover_creator)
|
||||
VALUES ('select_report', 'Select Report', 'Find Report...', '<p>Find by Name, Email, or Role</p>', CURDATE(), 'Init Script')",
|
||||
"INSERT INTO popovers (popover_name, popover_title, popover_placeholder, popover_text, popover_created, popover_creator)
|
||||
VALUES ('find_popover', 'Find Popover', 'Find Popover...', '<p>Find by Name, Title or Placeholder</p>', CURDATE(), 'Init Script')",
|
||||
"INSERT INTO popovers (popover_name, popover_title, popover_placeholder, popover_text, popover_created, popover_creator)
|
||||
VALUES ('find_journal', 'Find Journal', 'Find Journal...', '<p>Find by Name, Email, or Role</p>', CURDATE(), 'Init Script')",
|
||||
"INSERT INTO popovers (popover_name, popover_title, popover_placeholder, popover_text, popover_created, popover_creator)
|
||||
VALUES ('find_status', 'Find Status', 'Find Status...', '<p>Find by Name</p>', CURDATE(), 'Init Script')",
|
||||
"INSERT INTO popovers (popover_name, popover_title, popover_placeholder, popover_text, popover_created, popover_creator)
|
||||
VALUES ('find_dropdowntype', 'Find Dropdown Types', 'Find Dropdown Types...', '<p>Search for dropdown types</p>', CURDATE(), 'Init Script')",
|
||||
];
|
||||
|
||||
foreach ($sqlQueries as $sql) {
|
||||
runSQL($db, $sql, "popovers data", $logs);
|
||||
}
|
||||
}
|
||||
|
||||
if ($tableFile === 'users.php') {
|
||||
|
||||
$adminPasswordHash = 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 ('jric11', 'James Richie', 'james.richie@onesourceits.com', " . $db->quote($adminPasswordHash) . ", 'Administrator', 0, 1, 'Init Script', CURDATE())";
|
||||
|
||||
runSQL($db, $sql, "initial admin user", $logs);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$db->exec("SET FOREIGN_KEY_CHECKS = 1");
|
||||
} catch (PDOException $e) {
|
||||
logLine($logs, "⚠️ Could not re-enable FOREIGN_KEY_CHECKS: " . htmlspecialchars($e->getMessage(), ENT_QUOTES));
|
||||
}
|
||||
|
||||
renderPage($logs, true);
|
||||
@@ -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";
|
||||
|
||||
?>
|
||||
@@ -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";
|
||||
|
||||
?>
|
||||
@@ -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";
|
||||
|
||||
?>
|
||||
@@ -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";
|
||||
?>
|
||||
@@ -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";
|
||||
|
||||
?>
|
||||
@@ -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";
|
||||
|
||||
?>
|
||||
@@ -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";
|
||||
?>
|
||||
@@ -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";
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
$SQL = "CREATE TABLE voterhistory (
|
||||
|
||||
voterhistory_serial serial,
|
||||
|
||||
voterhistory_county_code CHAR(3) NOT NULL,
|
||||
voterhistory_voter_id CHAR(10) NOT NULL,
|
||||
voterhistory_election_date DATE NOT NULL,
|
||||
voterhistory_election_type CHAR(3) NOT NULL,
|
||||
voterhistory_history_code CHAR(1) DEFAULT NULL,
|
||||
|
||||
voterhistory_record_created DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
PRIMARY KEY (voterhistory_serial),
|
||||
|
||||
UNIQUE KEY uq_voterhistory (voterhistory_county_code, voterhistory_voter_id, voterhistory_election_date, voterhistory_election_type),
|
||||
|
||||
KEY idx_vh_voter (voterhistory_county_code, voterhistory_voter_id),
|
||||
KEY idx_vh_election (voterhistory_election_date, voterhistory_election_type),
|
||||
KEY idx_vh_county_election (voterhistory_county_code, voterhistory_election_date, voterhistory_election_type)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ";
|
||||
?>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
$SQL = "CREATE TABLE voters (
|
||||
|
||||
voter_serial serial,
|
||||
|
||||
-- Core Identifiers
|
||||
voter_county_code char(3) NOT null,
|
||||
voter_id char(10) NOT null,
|
||||
|
||||
-- Name
|
||||
voter_name_last varchar(30) null,
|
||||
voter_name_suffix varchar(5) null,
|
||||
voter_name_first varchar(30) null,
|
||||
voter_name_middle varchar(30) null,
|
||||
|
||||
-- Public Records Exemption
|
||||
voter_public_records_exempt char(1) null,
|
||||
|
||||
-- Residence Address
|
||||
voter_residence_address_1 varchar(50) null,
|
||||
voter_residence_address_2 varchar(40) null,
|
||||
voter_residence_city varchar(40) null,
|
||||
voter_residence_state char(2) null,
|
||||
voter_residence_zipcode varchar(10) null,
|
||||
|
||||
-- Mailing Address
|
||||
voter_mailing_address_1 varchar(40) null,
|
||||
voter_mailing_address_2 varchar(40) null,
|
||||
voter_mailing_address_3 varchar(40) null,
|
||||
voter_mailing_city varchar(40) null,
|
||||
voter_mailing_state char(2) null,
|
||||
voter_mailing_zipcode varchar(12) null,
|
||||
voter_mailing_country varchar(40) null,
|
||||
|
||||
-- Demographics
|
||||
voter_gender char(1) null,
|
||||
voter_race char(1) null,
|
||||
|
||||
-- Dates
|
||||
voter_birth_date DATE null,
|
||||
voter_registration_date DATE null,
|
||||
|
||||
-- Voting Info
|
||||
voter_party_affiliation char(3) null,
|
||||
voter_precinct char(6) null,
|
||||
voter_precinct_group char(3) null,
|
||||
voter_precinct_split char(6) null,
|
||||
voter_precinct_suffix char(3) null,
|
||||
voter_voter_status char(3) null,
|
||||
|
||||
-- Districts
|
||||
voter_congressional_district char(3) null,
|
||||
voter_house_district char(3) null,
|
||||
voter_senate_district char(3) null,
|
||||
voter_county_commission_district char(3) null,
|
||||
voter_school_board_district char(2) null,
|
||||
|
||||
-- Contact (Protected)
|
||||
voter_daytime_area_code char(3) null,
|
||||
voter_daytime_phone_number char(7) null,
|
||||
voter_daytime_phone_extension char(4) null,
|
||||
voter_email_address varchar(100) null,
|
||||
|
||||
-- Metadata
|
||||
voter_record_created datetime default current_timestamp,
|
||||
|
||||
PRIMARY KEY (voter_serial),
|
||||
UNIQUE KEY uq_voter (voter_county_code, voter_id),
|
||||
KEY idx_last_name (voter_name_last),
|
||||
KEY idx_precinct (voter_precinct),
|
||||
KEY idx_status (voter_voter_status)
|
||||
|
||||
) ENGINE=InnoDB DEFAULT charSET=utf8mb4";
|
||||
?>
|
||||
Reference in New Issue
Block a user