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} +