From ca519fe4e1bb586bbd2a5a546b2150ddedf5eba9 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 26 Jun 2025 16:27:11 -0400 Subject: [PATCH] Fix Adding a vendor from a template and adding country code to vendor template --- ajax/ajax_vendor_template_edit.php | 18 +++++++++------- assets.php | 3 ++- post/admin/admin_vendor_template.php | 4 ++-- post/user/vendor.php | 31 ++++++++++++++-------------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/ajax/ajax_vendor_template_edit.php b/ajax/ajax_vendor_template_edit.php index 23865fcd..afb365f2 100644 --- a/ajax/ajax_vendor_template_edit.php +++ b/ajax/ajax_vendor_template_edit.php @@ -10,7 +10,8 @@ $vendor_name = nullable_htmlentities($row['vendor_template_name']); $vendor_description = nullable_htmlentities($row['vendor_template_description']); $vendor_account_number = nullable_htmlentities($row['vendor_template_account_number']); $vendor_contact_name = nullable_htmlentities($row['vendor_template_contact_name']); -$vendor_phone = formatPhoneNumber($row['vendor_template_phone']); +$vendor_phone_country_code = intval($row['vendor_template_phone_country_code']); +$vendor_phone = formatPhoneNumber($row['vendor_template_phone'], $vendor_phone_country_code); $vendor_extension = nullable_htmlentities($row['vendor_template_extension']); $vendor_email = nullable_htmlentities($row['vendor_template_email']); $vendor_website = nullable_htmlentities($row['vendor_template_website']); @@ -133,17 +134,20 @@ ob_start();
+ -
-
- -
-
- +
+ +
+
+ +
+
+
diff --git a/assets.php b/assets.php index d27c121c..e4bd1aa7 100644 --- a/assets.php +++ b/assets.php @@ -191,9 +191,10 @@ if (mysqli_num_rows($os_sql) > 0) { Import + 0) { ?> - + Export diff --git a/post/admin/admin_vendor_template.php b/post/admin/admin_vendor_template.php index 3237dc8d..719eec80 100644 --- a/post/admin/admin_vendor_template.php +++ b/post/admin/admin_vendor_template.php @@ -77,7 +77,7 @@ if (isset($_POST['edit_vendor_template'])) { } if ($_POST['global_update_vendor_phone'] == 1) { - $sql_global_update_vendor_phone = ", vendor_phone = '$phone', vendor_extension = '$extension'"; + $sql_global_update_vendor_phone = ", vendor_phone_country_code = '$phone_country_code', vendor_phone = '$phone', vendor_extension = '$extension'"; } else { $sql_global_update_vendor_phone = ""; } @@ -119,7 +119,7 @@ if (isset($_POST['edit_vendor_template'])) { } // Update just the template - mysqli_query($mysqli,"UPDATE vendor_templates SET vendor_template_name = '$name', vendor_template_description = '$description', vendor_template_contact_name = '$contact_name', vendor_template_phone = '$phone', vendor_template_extension = '$extension', vendor_template_email = '$email', vendor_template_website = '$website', vendor_template_hours = '$hours', vendor_template_sla = '$sla', vendor_template_code = '$code', vendor_template_account_number = '$account_number', vendor_template_notes = '$notes' WHERE vendor_template_id = $vendor_template_id"); + mysqli_query($mysqli,"UPDATE vendor_templates SET vendor_template_name = '$name', vendor_template_description = '$description', vendor_template_contact_name = '$contact_name', vendor_template_phone_country_code = '$phone_country_code', vendor_template_phone = '$phone', vendor_template_extension = '$extension', vendor_template_email = '$email', vendor_template_website = '$website', vendor_template_hours = '$hours', vendor_template_sla = '$sla', vendor_template_code = '$code', vendor_template_account_number = '$account_number', vendor_template_notes = '$notes' WHERE vendor_template_id = $vendor_template_id"); if ($_POST['update_base_vendors'] == 1) { // Update client related vendors if anything is checked diff --git a/post/user/vendor.php b/post/user/vendor.php index ddd794b1..3f6ad7db 100644 --- a/post/user/vendor.php +++ b/post/user/vendor.php @@ -13,25 +13,26 @@ if (isset($_POST['add_vendor_from_template'])) { $vendor_template_id = intval($_POST['vendor_template_id']); //GET Vendor Info - $sql_vendor = mysqli_query($mysqli,"SELECT * FROM vendors WHERE vendor_id = $vendor_template_id"); + $sql_vendor_templates = mysqli_query($mysqli,"SELECT * FROM vendor_templates WHERE vendor_template_id = $vendor_template_id"); - $row = mysqli_fetch_array($sql_vendor); + $row = mysqli_fetch_array($sql_vendor_templates); - $name = sanitizeInput($row['vendor_name']); - $description = sanitizeInput($row['vendor_description']); - $account_number = sanitizeInput($row['vendor_account_number']); - $contact_name = sanitizeInput($row['vendor_contact_name']); - $phone = preg_replace("/[^0-9]/", '',$row['vendor_phone']); - $extension = preg_replace("/[^0-9]/", '',$row['vendor_extension']); - $email = sanitizeInput($row['vendor_email']); - $website = sanitizeInput($row['vendor_website']); - $hours = sanitizeInput($row['vendor_hours']); - $sla = sanitizeInput($row['vendor_sla']); - $code = sanitizeInput($row['vendor_code']); - $notes = sanitizeInput($row['vendor_notes']); + $name = sanitizeInput($row['vendor_template_name']); + $description = sanitizeInput($row['vendor_template_description']); + $account_number = sanitizeInput($row['vendor_template_account_number']); + $contact_name = sanitizeInput($row['vendor_template_contact_name']); + $phone_country_code = preg_replace("/[^0-9]/", '',$row['vendor_template_phone_country_code']); + $phone = preg_replace("/[^0-9]/", '',$row['vendor_template_phone']); + $extension = preg_replace("/[^0-9]/", '',$row['vendor_template_extension']); + $email = sanitizeInput($row['vendor_template_email']); + $website = sanitizeInput($row['vendor_template_website']); + $hours = sanitizeInput($row['vendor_template_hours']); + $sla = sanitizeInput($row['vendor_template_sla']); + $code = sanitizeInput($row['vendor_template_code']); + $notes = sanitizeInput($row['vendor_template_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, vendor_template_id = $vendor_template_id"); + mysqli_query($mysqli,"INSERT INTO vendors SET vendor_name = '$name', vendor_description = '$description', vendor_contact_name = '$contact_name', vendor_phone_country_code = '$phone_country_code', 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"); $vendor_id = mysqli_insert_id($mysqli);