From aa8fa3f4366a406874289d16512b4b4bb329dc86 Mon Sep 17 00:00:00 2001 From: Focuslinkstech <45756999+Focuslinkstech@users.noreply.github.com> Date: Sun, 18 Feb 2024 04:56:30 +0100 Subject: [PATCH] update admin can add more fields when editing customers --- system/controllers/customers.php | 38 +++++++++++++++++++++----- ui/ui/customers-edit.tpl | 47 +++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/system/controllers/customers.php b/system/controllers/customers.php index 6b5aab7c..e6663be7 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -422,18 +422,42 @@ switch ($action) { $customField->set('field_value', $customFieldValue); $customField->save(); } + } - if (isset($_POST['delete_custom_fields'])) { - $fieldsToDelete = $_POST['delete_custom_fields']; - foreach ($fieldsToDelete as $fieldName) { - // Delete the custom field with the given field name - ORM::for_table('tbl_customers_custom_fields') - ->where('field_name', $fieldName) - ->delete_many(); + // Add new custom fields + if (isset($_POST['custom_field_name']) && isset($_POST['custom_field_value'])) { + $newCustomFieldNames = $_POST['custom_field_name']; + $newCustomFieldValues = $_POST['custom_field_value']; + + // Check if the number of field names and values match + if (count($newCustomFieldNames) == count($newCustomFieldValues)) { + $numNewFields = count($newCustomFieldNames); + + for ($i = 0; $i < $numNewFields; $i++) { + $fieldName = $newCustomFieldNames[$i]; + $fieldValue = $newCustomFieldValues[$i]; + + // Insert the new custom field + $newCustomField = ORM::for_table('tbl_customers_custom_fields')->create(); + $newCustomField->set('customer_id', $id); + $newCustomField->set('field_name', $fieldName); + $newCustomField->set('field_value', $fieldValue); + $newCustomField->save(); } } } + // Delete custom fields + if (isset($_POST['delete_custom_fields'])) { + $fieldsToDelete = $_POST['delete_custom_fields']; + foreach ($fieldsToDelete as $fieldName) { + // Delete the custom field with the given field name + ORM::for_table('tbl_customers_custom_fields') + ->where('field_name', $fieldName) + ->delete_many(); + } + } + if ($userDiff || $pppoeDiff || $passDiff) { $c = ORM::for_table('tbl_user_recharges')->where('username', ($userDiff) ? $oldusername : $username)->find_one(); if ($c) { diff --git a/ui/ui/customers-edit.tpl b/ui/ui/customers-edit.tpl index f50aad01..91231e96 100644 --- a/ui/ui/customers-edit.tpl +++ b/ui/ui/customers-edit.tpl @@ -102,7 +102,16 @@ {/foreach} {/if} - + + +
+ +
+ +
+
+
+{literal} + +{/literal} + {include file="sections/footer.tpl"} \ No newline at end of file