From 463f90a103efa529693c085bc40870843cbe63fe Mon Sep 17 00:00:00 2001 From: johnnyq Date: Mon, 30 Jan 2023 17:54:50 -0500 Subject: [PATCH] Feature When editing vendor templates you can now update all vendors based off of the template --- client_vendors.php | 1 + database_updates.php | 14 +++++++++++--- database_version.php | 2 +- db.sql | 4 +++- post.php | 25 +++++++++++++++++++------ vendor_edit_modal.php | 21 +++++++++++++++++++++ vendor_template_edit_modal.php | 9 ++++++++- vendors.php | 1 + 8 files changed, 65 insertions(+), 12 deletions(-) diff --git a/client_vendors.php b/client_vendors.php index b4bf3160..bf85a8ba 100644 --- a/client_vendors.php +++ b/client_vendors.php @@ -114,6 +114,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); $vendor_sla = htmlentities($row['vendor_sla']); $vendor_code = htmlentities($row['vendor_code']); $vendor_notes = htmlentities($row['vendor_notes']); + $vendor_template_id = intval($row['vendor_template_id']); ?> diff --git a/database_updates.php b/database_updates.php index 328dc460..d233b9f0 100644 --- a/database_updates.php +++ b/database_updates.php @@ -832,11 +832,19 @@ if(LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION){ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.3.9'"); } - //if(CURRENT_DATABASE_VERSION == '0.3.9'){ - // Insert queries here required to update to DB version 0.4.0 + if(CURRENT_DATABASE_VERSION == '0.3.9'){ + + mysqli_query($mysqli, "ALTER TABLE `vendors` ADD `vendor_template_id` INT(11) NOT NULL DEFAULT 0 AFTER `vendor_client_id`"); + mysqli_query($mysqli, "ALTER TABLE `software` ADD `software_template_id` INT(11) NOT NULL DEFAULT 0 AFTER `software_client_id`"); + + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.0'"); + } + + //if(CURRENT_DATABASE_VERSION == '0.4.0'){ + // Insert queries here required to update to DB version 0.4.1 // Then, update the database to the next sequential version - // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.0'"); + // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.1'"); //} } else { diff --git a/database_version.php b/database_version.php index 7b52d7a0..10b5e79a 100644 --- a/database_version.php +++ b/database_version.php @@ -5,4 +5,4 @@ * It is used in conjunction with database_updates.php */ -DEFINE("LATEST_DATABASE_VERSION", "0.3.9"); +DEFINE("LATEST_DATABASE_VERSION", "0.4.0"); diff --git a/db.sql b/db.sql index 67165f7c..2aa31099 100644 --- a/db.sql +++ b/db.sql @@ -1146,6 +1146,7 @@ CREATE TABLE `software` ( `software_accessed_at` datetime DEFAULT NULL, `software_login_id` int(11) NOT NULL DEFAULT 0, `software_client_id` int(11) NOT NULL, + `software_template_id` int(11) NOT NULL DEFAULT 0, `company_id` int(11) NOT NULL, PRIMARY KEY (`software_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; @@ -1519,6 +1520,7 @@ CREATE TABLE `vendors` ( `vendor_archived_at` datetime DEFAULT NULL, `vendor_accessed_at` datetime DEFAULT NULL, `vendor_client_id` int(11) NOT NULL DEFAULT 0, + `vendor_template_id` int(11) NOT NULL DEFAULT 0, `company_id` int(11) NOT NULL, PRIMARY KEY (`vendor_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; @@ -1533,4 +1535,4 @@ CREATE TABLE `vendors` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2023-01-30 15:02:15 +-- Dump completed on 2023-01-30 17:53:50 diff --git a/post.php b/post.php index 083f2b9a..82196f90 100644 --- a/post.php +++ b/post.php @@ -2088,7 +2088,6 @@ if(isset($_POST['edit_vendor_template'])){ $vendor_id = intval($_POST['vendor_id']); $name = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']))); $description = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']))); - $account_number = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['account_number']))); $contact_name = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['contact_name']))); $phone = preg_replace("/[^0-9]/", '',$_POST['phone']); $extension = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['extension']))); @@ -2096,10 +2095,17 @@ if(isset($_POST['edit_vendor_template'])){ $website = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['website']))); $hours = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['hours']))); $sla = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['sla']))); - $code = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['code']))); $notes = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['notes']))); + $vendor_template_id = intval($_POST['vendor_template_id']); - mysqli_query($mysqli,"UPDATE vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code',vendor_account_number = '$account_number', vendor_notes = '$notes' WHERE vendor_id = $vendor_id AND company_id = $session_company_id"); + if($_POST['update_base_vendors'] == 1) { + $sql_update_vendors = "OR vendor_template_id = $vendor_id"; + } else{ + $sql_update_vendors = ""; + } + + //Update the exisiting template and all templates bassed of this vendor template + mysqli_query($mysqli,"UPDATE vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code',vendor_account_number = '$account_number', vendor_notes = '$notes' WHERE (vendor_id = $vendor_id $sql_update_vendors) AND company_id = $session_company_id"); //Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Vendor Template', log_action = 'Modify', log_description = '$session_name modified vendor template $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id"); @@ -2134,7 +2140,7 @@ if(isset($_POST['add_vendor_from_template'])){ $notes = trim(strip_tags(mysqli_real_escape_string($mysqli,$row['vendor_notes']))); // Vendor add query - mysqli_query($mysqli,"INSERT INTO vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code', vendor_account_number = '$account_number', vendor_notes = '$notes', vendor_client_id = $client_id, company_id = $session_company_id"); + mysqli_query($mysqli,"INSERT INTO vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code', vendor_account_number = '$account_number', vendor_notes = '$notes', vendor_client_id = $client_id, vendor_template_id = $vendor_template_id, company_id = $session_company_id"); $vendor_id = mysqli_insert_id($mysqli); @@ -2192,8 +2198,9 @@ if(isset($_POST['edit_vendor'])){ $sla = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['sla']))); $code = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['code']))); $notes = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['notes']))); + $vendor_template_id = intval($_POST['vendor_template_id']); - mysqli_query($mysqli,"UPDATE vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code',vendor_account_number = '$account_number', vendor_notes = '$notes' WHERE vendor_id = $vendor_id AND company_id = $session_company_id"); + mysqli_query($mysqli,"UPDATE vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone = '$phone', vendor_extension = '$extension', vendor_email = '$email', vendor_website = '$website', vendor_hours = '$hours', vendor_sla = '$sla', vendor_code = '$code',vendor_account_number = '$account_number', vendor_notes = '$notes', vendor_template_id = $vendor_template_id WHERE vendor_id = $vendor_id AND company_id = $session_company_id"); //Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Vendor', log_action = 'Modify', log_description = '$session_name modified vendor $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id"); @@ -2228,8 +2235,14 @@ if(isset($_GET['delete_vendor'])){ //Get Vendor Name $sql = mysqli_query($mysqli,"SELECT * FROM vendors WHERE vendor_id = $vendor_id AND company_id = $session_company_id"); $row = mysqli_fetch_array($sql); - $vendor_name = $row['vendor_name']; + $vendor_name = strip_tags(mysqli_real_escape_string($mysqli, $row['vendor_name'])); $client_id = intval($row['vendor_client_id']); + $vendor_template_id = intval($row['vendor_template_id']); + + // If its a template reset all vendors based off this template to no template base + if ($vendor_template_id > 0){ + mysqli_query($mysqli,"UPDATE vendors SET vendor_template_id = 0 WHERE vendor_template_id = $vendor_template_id"); + } mysqli_query($mysqli,"DELETE FROM vendors WHERE vendor_id = $vendor_id AND company_id = $session_company_id"); diff --git a/vendor_edit_modal.php b/vendor_edit_modal.php index db2f8ea9..e55b3543 100644 --- a/vendor_edit_modal.php +++ b/vendor_edit_modal.php @@ -69,6 +69,27 @@ +
+ +
+
+ +
+ +
+
+
diff --git a/vendor_template_edit_modal.php b/vendor_template_edit_modal.php index 9025a7d5..27942ac4 100644 --- a/vendor_template_edit_modal.php +++ b/vendor_template_edit_modal.php @@ -69,6 +69,13 @@
+
+
+ + +
+
+
@@ -155,7 +162,7 @@
diff --git a/vendors.php b/vendors.php index 4dead675..1ffe6c98 100644 --- a/vendors.php +++ b/vendors.php @@ -120,6 +120,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); $vendor_sla = htmlentities($row['vendor_sla']); $vendor_code = htmlentities($row['vendor_code']); $vendor_notes = htmlentities($row['vendor_notes']); + $vendor_template_id = intval($row['vendor_template_id']); ?>