From 348f4b43174ab199bfcd2a5752ea55f7c7370c4e Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 4 Sep 2025 23:21:43 +0000 Subject: [PATCH] Initial version --- .gitignore | 3 + .htaccess | 18 +++ .perm_test_apache | 0 .perm_test_exec | 0 db/config.php | 17 +++ db/migrate.php | 51 +++++++++ db/migrations/001_combined_schema.sql | 105 ++++++++++++++++++ db/migrations/001_initial_schema.sql | 104 +++++++++++++++++ .../002_add_event_management_tables.sql | 0 9 files changed, 298 insertions(+) create mode 100644 .gitignore create mode 100644 .htaccess create mode 100644 .perm_test_apache create mode 100644 .perm_test_exec create mode 100644 db/config.php create mode 100644 db/migrate.php create mode 100644 db/migrations/001_combined_schema.sql create mode 100644 db/migrations/001_initial_schema.sql create mode 100644 db/migrations/002_add_event_management_tables.sql diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e427ff3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +*/node_modules/ +*/build/ diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..e2bbc23 --- /dev/null +++ b/.htaccess @@ -0,0 +1,18 @@ +DirectoryIndex index.php index.html +Options -Indexes +Options -MultiViews + +RewriteEngine On + +# 0) Serve existing files/directories as-is +RewriteCond %{REQUEST_FILENAME} -f [OR] +RewriteCond %{REQUEST_FILENAME} -d +RewriteRule ^ - [L] + +# 1) Internal map: /page or /page/ -> /page.php (if such PHP file exists) +RewriteCond %{REQUEST_FILENAME}.php -f +RewriteRule ^(.+?)/?$ $1.php [L] + +# 2) Optional: strip trailing slash for non-directories (keeps .php links working) +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.+)/$ $1 [R=301,L] diff --git a/.perm_test_apache b/.perm_test_apache new file mode 100644 index 0000000..e69de29 diff --git a/.perm_test_exec b/.perm_test_exec new file mode 100644 index 0000000..e69de29 diff --git a/db/config.php b/db/config.php new file mode 100644 index 0000000..421292b --- /dev/null +++ b/db/config.php @@ -0,0 +1,17 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + ]); + } + return $pdo; +} diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..e5ed311 --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,51 @@ +exec("CREATE TABLE IF NOT EXISTS `migrations` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `migration_file` VARCHAR(255) NOT NULL UNIQUE, + `applied_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); + + // 2. Get all migration files + $migration_files = glob(__DIR__ . '/migrations/*.sql'); + + // 3. Get already applied migrations + $stmt = $pdo->query("SELECT `migration_file` FROM `migrations`"); + $applied_migrations = $stmt->fetchAll(PDO::FETCH_COLUMN); + + echo "Starting migrations...\n"; + + // 4. Apply pending migrations + foreach ($migration_files as $file) { + $filename = basename($file); + if (!in_array($filename, $applied_migrations)) { + echo "Applying migration: {$filename}...\n"; + + // Execute the SQL file + $sql = file_get_contents($file); + if (!empty(trim($sql))) { + $pdo->exec($sql); + } + + // Record the migration + $stmt = $pdo->prepare("INSERT INTO `migrations` (`migration_file`) VALUES (?)"); + $stmt->execute([$filename]); + + echo " ...applied successfully.\n"; + } else { + echo "Migration already applied: {$filename}\n"; + } + } + + echo "Migrations finished.\n"; +} + +// Run migrations if the script is executed directly +if (php_sapi_name() === 'cli' && basename(__FILE__) == basename($_SERVER['PHP_SELF'])) { + run_migrations(); +} diff --git a/db/migrations/001_combined_schema.sql b/db/migrations/001_combined_schema.sql new file mode 100644 index 0000000..34d41c4 --- /dev/null +++ b/db/migrations/001_combined_schema.sql @@ -0,0 +1,105 @@ +-- Combined schema for the event management system + +-- Drop existing tables to ensure a clean slate. +-- This is destructive and should not be used in production with existing data. +DROP TABLE IF EXISTS `event_vendors`, `event_budgets`, `event_guests`, `event_schedules`, `events`, `vendors`, `venues`, `users`, `roles`; + +-- Table structure for table `roles` +CREATE TABLE `roles` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL UNIQUE, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Seed default roles +INSERT INTO `roles` (`name`) VALUES ('Super-Admin'), ('Event Organizer'), ('Vendor'), ('Guest'); + +-- Table structure for table `users` +CREATE TABLE `users` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `email` varchar(255) NOT NULL, + `password` varchar(255) NOT NULL, + `role_id` int(11) NOT NULL, + `created_at` datetime DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + UNIQUE KEY `email` (`email`), + FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `venues` +CREATE TABLE `venues` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(255) NOT NULL, + `capacity` INT, + `amenities` TEXT, + `availability` BOOLEAN DEFAULT TRUE, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `vendors` +CREATE TABLE `vendors` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(255) NOT NULL, + `service_type` VARCHAR(255), + `contact_info` VARCHAR(255), + `rating` DECIMAL(3, 2), + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `events` +CREATE TABLE `events` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `organizer_id` INT NOT NULL, + `venue_id` INT, + `name` VARCHAR(255) NOT NULL, + `description` TEXT, + `start_time` DATETIME, + `end_time` DATETIME, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`organizer_id`) REFERENCES `users`(`id`), + FOREIGN KEY (`venue_id`) REFERENCES `venues`(`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `event_schedules` +CREATE TABLE `event_schedules` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `event_id` INT NOT NULL, + `activity` VARCHAR(255) NOT NULL, + `start_time` DATETIME NOT NULL, + `end_time` DATETIME NOT NULL, + FOREIGN KEY (`event_id`) REFERENCES `events`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `event_guests` +CREATE TABLE `event_guests` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `event_id` INT NOT NULL, + `user_id` INT, + `name` VARCHAR(255) NOT NULL, + `email` VARCHAR(255), + `rsvp_status` ENUM('attending', 'not_attending', 'maybe') NOT NULL, + `meal_preference` VARCHAR(255), + FOREIGN KEY (`event_id`) REFERENCES `events`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `event_budgets` +CREATE TABLE `event_budgets` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `event_id` INT NOT NULL, + `item_name` VARCHAR(255) NOT NULL, + `estimated_cost` DECIMAL(10, 2) NOT NULL, + `actual_cost` DECIMAL(10, 2), + `paid_status` BOOLEAN DEFAULT FALSE, + FOREIGN KEY (`event_id`) REFERENCES `events`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `event_vendors` +CREATE TABLE `event_vendors` ( + `event_id` INT NOT NULL, + `vendor_id` INT NOT NULL, + PRIMARY KEY (`event_id`, `vendor_id`), + FOREIGN KEY (`event_id`) REFERENCES `events`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`vendor_id`) REFERENCES `vendors`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; \ No newline at end of file diff --git a/db/migrations/001_initial_schema.sql b/db/migrations/001_initial_schema.sql new file mode 100644 index 0000000..ce05a10 --- /dev/null +++ b/db/migrations/001_initial_schema.sql @@ -0,0 +1,104 @@ +-- Combined schema for the event management system + +-- Drop existing tables to ensure a clean slate. +-- This is destructive and should not be used in production with existing data. +DROP TABLE IF EXISTS `event_vendors`, `event_budgets`, `event_guests`, `event_schedules`, `events`, `vendors`, `venues`, `users`, `roles`; + +-- Table structure for table `roles` +CREATE TABLE `roles` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL UNIQUE, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Seed default roles +INSERT INTO `roles` (`name`) VALUES ('Super-Admin'), ('Event Organizer'), ('Vendor'), ('Guest'); + +-- Table structure for table `users` +CREATE TABLE `users` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(50) NOT NULL, + `password` varchar(255) NOT NULL, + `role_id` int(11) NOT NULL, + `created_at` datetime DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + UNIQUE KEY `username` (`username`), + FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `venues` +CREATE TABLE `venues` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(255) NOT NULL, + `capacity` INT, + `amenities` TEXT, + `availability` BOOLEAN DEFAULT TRUE, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `vendors` +CREATE TABLE `vendors` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(255) NOT NULL, + `service_type` VARCHAR(255), + `contact_info` VARCHAR(255), + `rating` DECIMAL(3, 2), + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `events` +CREATE TABLE `events` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `organizer_id` INT NOT NULL, + `venue_id` INT, + `name` VARCHAR(255) NOT NULL, + `description` TEXT, + `start_time` DATETIME, + `end_time` DATETIME, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`organizer_id`) REFERENCES `users`(`id`), + FOREIGN KEY (`venue_id`) REFERENCES `venues`(`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `event_schedules` +CREATE TABLE `event_schedules` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `event_id` INT NOT NULL, + `activity` VARCHAR(255) NOT NULL, + `start_time` DATETIME NOT NULL, + `end_time` DATETIME NOT NULL, + FOREIGN KEY (`event_id`) REFERENCES `events`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `event_guests` +CREATE TABLE `event_guests` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `event_id` INT NOT NULL, + `user_id` INT, + `name` VARCHAR(255) NOT NULL, + `email` VARCHAR(255), + `rsvp_status` ENUM('attending', 'not_attending', 'maybe') NOT NULL, + `meal_preference` VARCHAR(255), + FOREIGN KEY (`event_id`) REFERENCES `events`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `event_budgets` +CREATE TABLE `event_budgets` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `event_id` INT NOT NULL, + `item_name` VARCHAR(255) NOT NULL, + `estimated_cost` DECIMAL(10, 2) NOT NULL, + `actual_cost` DECIMAL(10, 2), + `paid_status` BOOLEAN DEFAULT FALSE, + FOREIGN KEY (`event_id`) REFERENCES `events`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Table structure for table `event_vendors` +CREATE TABLE `event_vendors` ( + `event_id` INT NOT NULL, + `vendor_id` INT NOT NULL, + PRIMARY KEY (`event_id`, `vendor_id`), + FOREIGN KEY (`event_id`) REFERENCES `events`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`vendor_id`) REFERENCES `vendors`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/db/migrations/002_add_event_management_tables.sql b/db/migrations/002_add_event_management_tables.sql new file mode 100644 index 0000000..e69de29