From 59bbbe4a8d1e79f12fc0504f6c91b3686d79d5f6 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 13 Mar 2025 16:34:38 -0400 Subject: [PATCH] Removed Patch panel tables as they share similarities with assets and assets interfaces, rename events to calendar events and event attendees to calendar even attendees --- ajax/ajax_calendar_event_edit.php | 2 +- calendar.php | 4 +- database_updates.php | 18 +++- db.sql | 143 ++++++++++-------------------- includes/database_version.php | 2 +- post/user/event.php | 8 +- 6 files changed, 70 insertions(+), 107 deletions(-) diff --git a/ajax/ajax_calendar_event_edit.php b/ajax/ajax_calendar_event_edit.php index c6e6a61c..937b9749 100644 --- a/ajax/ajax_calendar_event_edit.php +++ b/ajax/ajax_calendar_event_edit.php @@ -4,7 +4,7 @@ require_once '../includes/ajax_header.php'; $event_id = intval($_GET['id']); -$sql = mysqli_query($mysqli, "SELECT * FROM events LEFT JOIN calendars ON event_calendar_id = calendar_id WHERE event_id = $event_id LIMIT 1"); +$sql = mysqli_query($mysqli, "SELECT * FROM calendar_events LEFT JOIN calendars ON event_calendar_id = calendar_id WHERE event_id = $event_id LIMIT 1"); $row = mysqli_fetch_array($sql); $event_title = nullable_htmlentities($row['event_title']); diff --git a/calendar.php b/calendar.php index 7608a50f..128cebe0 100644 --- a/calendar.php +++ b/calendar.php @@ -89,7 +89,7 @@ require_once "modals/calendar_add_modal.php"; //loop through IDs and create a modal for each -$sql = mysqli_query($mysqli, "SELECT * FROM events LEFT JOIN calendars ON event_calendar_id = calendar_id $client_event_query"); +$sql = mysqli_query($mysqli, "SELECT * FROM calendar_events LEFT JOIN calendars ON event_calendar_id = calendar_id $client_event_query"); while ($row = mysqli_fetch_array($sql)) { $event_id = intval($row['event_id']); $event_title = nullable_htmlentities($row['event_title']); @@ -170,7 +170,7 @@ while ($row = mysqli_fetch_array($sql)) { }, events: [ CURRENT_DATABASE_VERSION) { mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.0.0'"); } - // if (CURRENT_DATABASE_VERSION == '2.0.0') { - // // Insert queries here required to update to DB version 2.0.1 + if (CURRENT_DATABASE_VERSION == '2.0.0') { + + //Dropping patch panel as a patch panel can be documented as an asset with interfaces. + mysqli_query($mysqli, "DROP TABLE `patch_panel_ports`"); + mysqli_query($mysqli, "DROP TABLE `patch_panels`"); + + mysqli_query($mysqli, "RENAME TABLE `events` TO `calendar_events`"); + mysqli_query($mysqli, "RENAME TABLE `event_attendees` TO `calendar_event_attendees`"); + + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.0.1'"); + } + + // if (CURRENT_DATABASE_VERSION == '2.0.1') { + // // Insert queries here required to update to DB version 2.0.2 // // Then, update the database to the next sequential version - // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.0.1'"); + // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.0.2'"); // } } else { diff --git a/db.sql b/db.sql index db10b2e8..7995c242 100644 --- a/db.sql +++ b/db.sql @@ -299,6 +299,52 @@ CREATE TABLE `budget` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `calendar_event_attendees` +-- + +DROP TABLE IF EXISTS `calendar_event_attendees`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `calendar_event_attendees` ( + `attendee_id` int(11) NOT NULL AUTO_INCREMENT, + `attendee_name` varchar(200) DEFAULT NULL, + `attendee_email` varchar(200) DEFAULT NULL, + `attendee_invitation_status` tinyint(1) NOT NULL DEFAULT 0, + `attendee_created_at` datetime NOT NULL DEFAULT current_timestamp(), + `attendee_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), + `attendee_archived_at` datetime DEFAULT NULL, + `attendee_contact_id` int(11) NOT NULL DEFAULT 0, + `attendee_event_id` int(11) NOT NULL, + PRIMARY KEY (`attendee_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `calendar_events` +-- + +DROP TABLE IF EXISTS `calendar_events`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `calendar_events` ( + `event_id` int(11) NOT NULL AUTO_INCREMENT, + `event_title` varchar(200) NOT NULL, + `event_location` text DEFAULT NULL, + `event_description` longtext DEFAULT NULL, + `event_start` datetime NOT NULL, + `event_end` datetime DEFAULT NULL, + `event_repeat` varchar(200) DEFAULT NULL, + `event_created_at` datetime NOT NULL DEFAULT current_timestamp(), + `event_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), + `event_archived_at` datetime DEFAULT NULL, + `event_client_id` int(11) NOT NULL DEFAULT 0, + `event_location_id` int(11) NOT NULL DEFAULT 0, + `event_calendar_id` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`event_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `calendars` -- @@ -837,52 +883,6 @@ CREATE TABLE `email_queue` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `event_attendees` --- - -DROP TABLE IF EXISTS `event_attendees`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `event_attendees` ( - `attendee_id` int(11) NOT NULL AUTO_INCREMENT, - `attendee_name` varchar(200) DEFAULT NULL, - `attendee_email` varchar(200) DEFAULT NULL, - `attendee_invitation_status` tinyint(1) NOT NULL DEFAULT 0, - `attendee_created_at` datetime NOT NULL DEFAULT current_timestamp(), - `attendee_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), - `attendee_archived_at` datetime DEFAULT NULL, - `attendee_contact_id` int(11) NOT NULL DEFAULT 0, - `attendee_event_id` int(11) NOT NULL, - PRIMARY KEY (`attendee_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `events` --- - -DROP TABLE IF EXISTS `events`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `events` ( - `event_id` int(11) NOT NULL AUTO_INCREMENT, - `event_title` varchar(200) NOT NULL, - `event_location` text DEFAULT NULL, - `event_description` longtext DEFAULT NULL, - `event_start` datetime NOT NULL, - `event_end` datetime DEFAULT NULL, - `event_repeat` varchar(200) DEFAULT NULL, - `event_created_at` datetime NOT NULL DEFAULT current_timestamp(), - `event_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), - `event_archived_at` datetime DEFAULT NULL, - `event_client_id` int(11) NOT NULL DEFAULT 0, - `event_location_id` int(11) NOT NULL DEFAULT 0, - `event_calendar_id` int(11) NOT NULL DEFAULT 0, - PRIMARY KEY (`event_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `expenses` -- @@ -1170,55 +1170,6 @@ CREATE TABLE `notifications` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `patch_panel_ports` --- - -DROP TABLE IF EXISTS `patch_panel_ports`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `patch_panel_ports` ( - `port_id` int(11) NOT NULL AUTO_INCREMENT, - `port_number` int(11) NOT NULL, - `port_name` varchar(200) DEFAULT NULL, - `port_description` text DEFAULT NULL, - `port_type` varchar(200) DEFAULT NULL, - `port_created_at` datetime NOT NULL DEFAULT current_timestamp(), - `port_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), - `port_archived_at` datetime DEFAULT NULL, - `port_asset_id` int(11) DEFAULT NULL, - `port_patch_panel_id` int(11) NOT NULL, - PRIMARY KEY (`port_id`), - KEY `port_patch_panel_id` (`port_patch_panel_id`), - CONSTRAINT `patch_panel_ports_ibfk_1` FOREIGN KEY (`port_patch_panel_id`) REFERENCES `patch_panels` (`patch_panel_id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `patch_panels` --- - -DROP TABLE IF EXISTS `patch_panels`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `patch_panels` ( - `patch_panel_id` int(11) NOT NULL AUTO_INCREMENT, - `patch_panel_name` varchar(200) NOT NULL, - `patch_panel_description` text DEFAULT NULL, - `patch_panel_type` varchar(200) DEFAULT NULL, - `patch_panel_ports` int(11) NOT NULL, - `patch_panel_physical_location` varchar(200) DEFAULT NULL, - `patch_panel_notes` text DEFAULT NULL, - `patch_panel_created_at` datetime NOT NULL DEFAULT current_timestamp(), - `patch_panel_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), - `patch_panel_archived_at` datetime DEFAULT NULL, - `patch_panel_location_id` int(11) DEFAULT NULL, - `patch_panel_rack_id` int(11) DEFAULT NULL, - `patch_panel_client_id` int(11) NOT NULL, - PRIMARY KEY (`patch_panel_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `payments` -- @@ -2451,4 +2402,4 @@ CREATE TABLE `vendors` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2025-03-12 21:27:39 +-- Dump completed on 2025-03-13 16:33:22 diff --git a/includes/database_version.php b/includes/database_version.php index d3e1d495..03c90285 100644 --- a/includes/database_version.php +++ b/includes/database_version.php @@ -5,4 +5,4 @@ * It is used in conjunction with database_updates.php */ -DEFINE("LATEST_DATABASE_VERSION", "2.0.0"); +DEFINE("LATEST_DATABASE_VERSION", "2.0.1"); diff --git a/post/user/event.php b/post/user/event.php index 0ee47441..98b2cb32 100644 --- a/post/user/event.php +++ b/post/user/event.php @@ -46,7 +46,7 @@ if (isset($_POST['add_event'])) { require_once 'post/user/event_model.php'; - mysqli_query($mysqli,"INSERT INTO events SET event_title = '$title', event_location = '$location', event_description = '$description', event_start = '$start', event_end = '$end', event_repeat = '$repeat', event_calendar_id = $calendar_id, event_client_id = $client"); + mysqli_query($mysqli,"INSERT INTO calendar_events SET event_title = '$title', event_location = '$location', event_description = '$description', event_start = '$start', event_end = '$end', event_repeat = '$repeat', event_calendar_id = $calendar_id, event_client_id = $client"); $event_id = mysqli_insert_id($mysqli); @@ -121,7 +121,7 @@ if (isset($_POST['edit_event'])) { $event_id = intval($_POST['event_id']); - mysqli_query($mysqli,"UPDATE events SET event_title = '$title', event_location = '$location', event_description = '$description', event_start = '$start', event_end = '$end', event_repeat = '$repeat', event_calendar_id = $calendar_id, event_client_id = $client WHERE event_id = $event_id"); + mysqli_query($mysqli,"UPDATE calendar_events SET event_title = '$title', event_location = '$location', event_description = '$description', event_start = '$start', event_end = '$end', event_repeat = '$repeat', event_calendar_id = $calendar_id, event_client_id = $client WHERE event_id = $event_id"); //If email is checked if ($email_event == 1) { @@ -187,12 +187,12 @@ if (isset($_GET['delete_event'])) { $event_id = intval($_GET['delete_event']); // Get Event Title - $sql = mysqli_query($mysqli,"SELECT * FROM events WHERE event_id = $event_id"); + $sql = mysqli_query($mysqli,"SELECT * FROM calendar_events WHERE event_id = $event_id"); $row = mysqli_fetch_array($sql); $event_title = sanitizeInput($row['event_title']); $client_id = intval($row['event_client_id']); - mysqli_query($mysqli,"DELETE FROM events WHERE event_id = $event_id"); + mysqli_query($mysqli,"DELETE FROM calendar_events WHERE event_id = $event_id"); // Logging logAction("Calendar Event", "Delete", "$session_name deleted calendar event $event_title", $client_id);