From eb970b257a59de7a60d886091ed6d15431fd7a4a Mon Sep 17 00:00:00 2001 From: iBNu Maksum Date: Tue, 19 Nov 2024 18:11:34 +0700 Subject: [PATCH] Custom Fields for registration and Profile, but not yet finished for upload picture --- init.php | 3 +- system/autoload/User.php | 42 ++++++++ system/controllers/accounts.php | 3 + system/controllers/customfield.php | 53 ++++++++++ system/controllers/register.php | 5 +- system/lan/english.json | 4 +- ui/ui/customer/custom_field.tpl | 40 ++++++++ ui/ui/customer/profile.tpl | 1 + ui/ui/customer/register-otp.tpl | 3 +- ui/ui/customer/register.tpl | 15 +-- ui/ui/customfield.tpl | 151 +++++++++++++++++++++++++++++ ui/ui/sections/header.tpl | 2 + 12 files changed, 311 insertions(+), 11 deletions(-) create mode 100644 system/controllers/customfield.php create mode 100644 ui/ui/customer/custom_field.tpl create mode 100644 ui/ui/customfield.tpl diff --git a/init.php b/init.php index dbe56a7e..f42eab25 100644 --- a/init.php +++ b/init.php @@ -152,7 +152,8 @@ $lan_file = $root_path . File::pathFixer('system/lan/' . $config['language'] . ' if (file_exists($lan_file)) { $_L = json_decode(file_get_contents($lan_file), true); } else { - $_L['author'] = 'Auto Generated by iBNuX Script'; + die("why"); + $_L['author'] = 'Auto Generated by PHPNuxBill Script'; file_put_contents($lan_file, json_encode($_L)); } diff --git a/system/autoload/User.php b/system/autoload/User.php index 54aa8fe8..fff7a620 100644 --- a/system/autoload/User.php +++ b/system/autoload/User.php @@ -275,4 +275,46 @@ class User ->find_many(); return $d; } + + public static function setFormCustomField($uid = 0){ + global $UPLOAD_PATH; + $fieldPath = $UPLOAD_PATH . DIRECTORY_SEPARATOR . "customer_field.json"; + if(!file_exists($fieldPath)){ + return ''; + } + $fields = json_decode(file_get_contents($fieldPath), true); + foreach($fields as $field){ + if(!empty(_post($field['name']))){ + self::setAttribute($field['name'], _post($field['name']), $uid); + } + } + } + + public static function getFormCustomField($ui, $register = false, $uid = 0){ + global $UPLOAD_PATH; + $fieldPath = $UPLOAD_PATH . DIRECTORY_SEPARATOR . "customer_field.json"; + if(!file_exists($fieldPath)){ + return ''; + } + $fields = json_decode(file_get_contents($fieldPath), true); + $attrs = []; + if(!$register){ + $attrs = self::getAttributes('', $uid); + $ui->assign('attrs', $attrs); + } + $html = ''; + $ui->assign('register', $register); + foreach($fields as $field){ + if($register){ + if($field['register']){ + $ui->assign('field', $field); + $html .= $ui->fetch('customer/custom_field.tpl'); + } + }else{ + $ui->assign('field', $field); + $html .= $ui->fetch('customer/custom_field.tpl'); + } + } + return $html; + } } diff --git a/system/controllers/accounts.php b/system/controllers/accounts.php index 52c0dba6..d21934d5 100644 --- a/system/controllers/accounts.php +++ b/system/controllers/accounts.php @@ -75,6 +75,7 @@ switch ($action) { run_hook('customer_view_edit_profile'); #HOOK $csrf_token = Csrf::generateAndStoreToken(); $ui->assign('csrf_token', $csrf_token); + $ui->assign('customFields', User::getFormCustomField($ui, false, $user['id'])); $ui->display('customer/profile.tpl'); break; case 'edit-profile-post': @@ -154,6 +155,8 @@ switch ($action) { $user->email = $email; } + User::setFormCustomField($user['id']); + $user->save(); _log('[' . $user['username'] . ']: ' . Lang::T('User Updated Successfully'), 'User', $user['id']); diff --git a/system/controllers/customfield.php b/system/controllers/customfield.php new file mode 100644 index 00000000..b63b7a42 --- /dev/null +++ b/system/controllers/customfield.php @@ -0,0 +1,53 @@ +assign('_title', Lang::T('Custom Fields')); +$ui->assign('_system_menu', 'settings'); + +$action = $routes['1']; +$ui->assign('_admin', $admin); + +$fieldPath = $UPLOAD_PATH . DIRECTORY_SEPARATOR . "customer_field.json"; + +switch ($action) { + case 'save': + print_r($_POST); + $datas = []; + $count = count($_POST['name']); + for($n=0;$n<$count;$n++){ + if(!empty($_POST['name'][$n])){ + $datas[] = [ + 'order' => $_POST['order'][$n], + 'name' => $_POST['name'][$n], + 'type' => $_POST['type'][$n], + 'placeholder' => $_POST['placeholder'][$n], + 'value' => $_POST['value'][$n], + 'register' => $_POST['register'][$n], + 'required' => $_POST['required'][$n] + ]; + } + } + if(count($datas)>1){ + usort($datas, function ($item1, $item2) { + return $item1['order'] <=> $item2['order']; + }); + } + if(file_put_contents($fieldPath, json_encode($datas))){ + r2(U . 'customfield', 's', 'Successfully saved custom fields!'); + }else{ + r2(U . 'customfield', 'e', 'Failed to save custom fields!'); + } + default: + $fields = []; + if(file_exists($fieldPath)){ + $fields = json_decode(file_get_contents($fieldPath), true); + } + $ui->assign('fields', $fields); + $ui->display('customfield.tpl'); + break; +} \ No newline at end of file diff --git a/system/controllers/register.php b/system/controllers/register.php index 1999f904..62fa0c54 100644 --- a/system/controllers/register.php +++ b/system/controllers/register.php @@ -86,7 +86,6 @@ switch ($do) { } if ($msg == '') { - run_hook('register_user'); #HOOK $d = ORM::for_table('tbl_customers')->create(); $d->username = alphanumeric($username, "+_.@-"); $d->password = $password; @@ -96,6 +95,8 @@ switch ($do) { $d->phonenumber = $phone_number; if ($d->save()) { $user = $d->id(); + User::setFormCustomField($user); + run_hook('register_user'); #HOOK r2(U . 'login', 's', Lang::T('Register Success! You can login now')); } else { $ui->assign('username', $username); @@ -163,6 +164,7 @@ switch ($do) { $ui->assign('notify', 'Registration code has been sent to your phone'); $ui->assign('notify_t', 's'); $ui->assign('_title', Lang::T('Register')); + $ui->assign('customFields', User::getFormCustomField($ui, true)); $ui->display('customer/register-otp.tpl'); } } else { @@ -171,6 +173,7 @@ switch ($do) { $ui->display('customer/register-rotp.tpl'); } } else { + $ui->assign('customFields', User::getFormCustomField($ui, true)); $ui->assign('username', ""); $ui->assign('fullname', ""); $ui->assign('address', ""); diff --git a/system/lan/english.json b/system/lan/english.json index b08a934f..17690130 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -909,5 +909,7 @@ "Login_Page_Settings_Saved_Successfully": "Login Page Settings Saved Successfully", "Sign_in_into_your_account": "Sign in into your account", "Don_t_have_an_account_": "Don't have an account?", - "You_do_not_have_permission_to_access_this_page_in_demo_mode": "You do not have permission to access this page in demo mode" + "You_do_not_have_permission_to_access_this_page_in_demo_mode": "You do not have permission to access this page in demo mode", + "Custom_Fields": "Custom Fields", + "New_Field": "New Field" } \ No newline at end of file diff --git a/ui/ui/customer/custom_field.tpl b/ui/ui/customer/custom_field.tpl new file mode 100644 index 00000000..257dded6 --- /dev/null +++ b/ui/ui/customer/custom_field.tpl @@ -0,0 +1,40 @@ +{if $register} +
+ + {if $field['type'] == 'option'} + + {elseif $field['image'] == 'image'} + + {else} + + {/if} +
+{else} +
+ +
+ {if $field['type'] == 'option'} + + {elseif $field['image'] == 'image'} + + {else} + + {/if} +
+
+{/if} \ No newline at end of file diff --git a/ui/ui/customer/profile.tpl b/ui/ui/customer/profile.tpl index fb7164d2..007ef3f8 100644 --- a/ui/ui/customer/profile.tpl +++ b/ui/ui/customer/profile.tpl @@ -109,6 +109,7 @@ {/if} + {$customFields}
-
+
1. {Lang::T('Register as Member')}
@@ -45,6 +45,7 @@
+ {$customFields}
diff --git a/ui/ui/customer/register.tpl b/ui/ui/customer/register.tpl index 247db74d..9d33bd06 100644 --- a/ui/ui/customer/register.tpl +++ b/ui/ui/customer/register.tpl @@ -10,13 +10,13 @@ - +
1. {Lang::T('Register as Member')}
-
+
-
+
-
+
-
+
+ {$customFields}
@@ -64,11 +65,11 @@
2. {Lang::T('Password')}
-
+
-
+
diff --git a/ui/ui/customfield.tpl b/ui/ui/customfield.tpl new file mode 100644 index 00000000..349ecefb --- /dev/null +++ b/ui/ui/customfield.tpl @@ -0,0 +1,151 @@ +{include file="sections/header.tpl"} + + +
+
+
+
{Lang::T('New Field')}
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ + for option using comma separated value. +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ + To delete, empty the name +
+
+
+
+
+
+ {foreach $fields as $field} +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ + for option using comma separated value. +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ {/foreach} + +
+
+ + + +{include file="sections/footer.tpl"} \ No newline at end of file diff --git a/ui/ui/sections/header.tpl b/ui/ui/sections/header.tpl index 66d22e42..f3b7c9ce 100644 --- a/ui/ui/sections/header.tpl +++ b/ui/ui/sections/header.tpl @@ -1416,6 +1416,8 @@ href="{$_url}settings/app">{Lang::T('General Settings')}
  • {Lang::T('Localisation')}
  • +
  • {Lang::T('Custom Fields')}
  • {Lang::T('Miscellaneous')}