From 78695208b75646f63b92eb0391a071a2b9e25de5 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sun, 7 May 2023 20:46:09 -0400 Subject: [PATCH] Fix custom Fields DB Structure Remove Unique Indexes change defaut type TEXT to text Added Add edit Delete Read for custom fields --- custom_field_create_modal.php | 41 ++++++++++++ custom_field_edit_modal.php | 40 ++++++++++++ database_updates.php | 10 +-- db.sql | 12 ++-- models/custom_field.php | 3 + post.php | 49 ++++++++++++++ settings_custom_fields.php | 119 ++++++++++++++++++++++++++++++++++ settings_side_nav.php | 7 ++ 8 files changed, 266 insertions(+), 15 deletions(-) create mode 100644 custom_field_create_modal.php create mode 100644 custom_field_edit_modal.php create mode 100644 models/custom_field.php create mode 100644 settings_custom_fields.php diff --git a/custom_field_create_modal.php b/custom_field_create_modal.php new file mode 100644 index 00000000..0468c63a --- /dev/null +++ b/custom_field_create_modal.php @@ -0,0 +1,41 @@ + diff --git a/custom_field_edit_modal.php b/custom_field_edit_modal.php new file mode 100644 index 00000000..f1cdb882 --- /dev/null +++ b/custom_field_edit_modal.php @@ -0,0 +1,40 @@ + diff --git a/database_updates.php b/database_updates.php index 79c6fe05..99d238ee 100644 --- a/database_updates.php +++ b/database_updates.php @@ -987,13 +987,10 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { `custom_field_id` int(11) NOT NULL AUTO_INCREMENT, `custom_field_table` varchar(255) NOT NULL, `custom_field_label` varchar(255) NOT NULL, - `custom_field_type` varchar(255) NOT NULL DEFAULT 'TEXT', + `custom_field_type` varchar(255) NOT NULL DEFAULT 'text', `custom_field_location` int(11) NOT NULL DEFAULT 0, `custom_field_order` int(11) NOT NULL DEFAULT 999, - PRIMARY KEY (`custom_field_id`), - UNIQUE KEY (`custom_field_table`), - UNIQUE KEY (`custom_field_label`), - UNIQUE KEY (`custom_field_type`) + PRIMARY KEY (`custom_field_id`) )"); mysqli_query($mysqli, "CREATE TABLE `custom_values` ( @@ -1008,8 +1005,7 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { `asset_custom_field_value` int(11) NOT NULL, `asset_custom_field_id` int(11) NOT NULL, `asset_custom_asset_id` int(11) NOT NULL, - PRIMARY KEY (`asset_custom_id`), - UNIQUE KEY (`asset_custom_field_id`) + PRIMARY KEY (`asset_custom_id`) )"); // Then, update the database to the next sequential version diff --git a/db.sql b/db.sql index 45e7bc11..2e6250e5 100644 --- a/db.sql +++ b/db.sql @@ -65,8 +65,7 @@ CREATE TABLE `asset_custom` ( `asset_custom_field_value` int(11) NOT NULL, `asset_custom_field_id` int(11) NOT NULL, `asset_custom_asset_id` int(11) NOT NULL, - PRIMARY KEY (`asset_custom_id`), - UNIQUE KEY `asset_custom_field_id` (`asset_custom_field_id`) + PRIMARY KEY (`asset_custom_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -381,13 +380,10 @@ CREATE TABLE `custom_fields` ( `custom_field_id` int(11) NOT NULL AUTO_INCREMENT, `custom_field_table` varchar(255) NOT NULL, `custom_field_label` varchar(255) NOT NULL, - `custom_field_type` varchar(255) NOT NULL DEFAULT 'TEXT', + `custom_field_type` varchar(255) NOT NULL DEFAULT 'text', `custom_field_location` int(11) NOT NULL DEFAULT 0, `custom_field_order` int(11) NOT NULL DEFAULT 999, - PRIMARY KEY (`custom_field_id`), - UNIQUE KEY `custom_field_table` (`custom_field_table`), - UNIQUE KEY `custom_field_label` (`custom_field_label`), - UNIQUE KEY `custom_field_type` (`custom_field_type`) + PRIMARY KEY (`custom_field_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -1544,4 +1540,4 @@ CREATE TABLE `vendors` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2023-05-07 19:45:11 +-- Dump completed on 2023-05-07 20:45:03 diff --git a/models/custom_field.php b/models/custom_field.php new file mode 100644 index 00000000..2cd6fb47 --- /dev/null +++ b/models/custom_field.php @@ -0,0 +1,3 @@ + $sb, 'o' => $o))); + +$sql = mysqli_query( + $mysqli, + "SELECT SQL_CALC_FOUND_ROWS * FROM custom_fields + WHERE custom_field_label LIKE '%$q%' + AND custom_field_table = '$table' + ORDER BY $sb $o LIMIT $record_from, $record_to" +); + +$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); + +?> + + +
+
+

Fields

+
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+
+
+
+ Assets + Clients +
+
+
+
+
+
+ + "> + + + + + + + + + + + + + + + + + +
LabelTypeAction
;"> + +
+
+ +
+
+ + + +