Custom Fields for registration and Profile, but not yet finished for upload picture
This commit is contained in:
parent
242dda2e99
commit
eb970b257a
3
init.php
3
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));
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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']);
|
||||
|
53
system/controllers/customfield.php
Normal file
53
system/controllers/customfield.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
||||
* by https://t.me/ibnux
|
||||
**/
|
||||
|
||||
_admin();
|
||||
$ui->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;
|
||||
}
|
@ -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', "");
|
||||
|
@ -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"
|
||||
}
|
40
ui/ui/customer/custom_field.tpl
Normal file
40
ui/ui/customer/custom_field.tpl
Normal file
@ -0,0 +1,40 @@
|
||||
{if $register}
|
||||
<div class="form-group">
|
||||
<label>{ucwords($field['name'])}</label>
|
||||
{if $field['type'] == 'option'}
|
||||
<select class="form-control" {if $field['required'] == 1} required{/if} name="{$field['name']}" style="width: 100%">
|
||||
{assign var="opts" value=explode(',', $field['value'])}
|
||||
{foreach $opts as $opt}
|
||||
<option value="{$opt}">{$opt}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
{elseif $field['image'] == 'image'}
|
||||
<input type="file" class="form-control" {if $field['required'] == 1} required{/if} name="{$field['name']}"
|
||||
style="width: 100%" placeholder="{$field['placeholder']}" accept="image/*">
|
||||
{else}
|
||||
<input type="{$field['type']}" class="form-control" {if $field['required'] == 1} required{/if}
|
||||
name="{$field['name']}" value="{$field['value']}" style="width: 100%" placeholder="{$field['placeholder']}">
|
||||
{/if}
|
||||
</div>
|
||||
{else}
|
||||
<div class="form-group">
|
||||
<label class="col-md-3 control-label">{ucwords($field['name'])}</label>
|
||||
<div class="col-md-9">
|
||||
{if $field['type'] == 'option'}
|
||||
<select class="form-control" {if $field['required'] == 1} required{/if} name="{$field['name']}"
|
||||
style="width: 100%">
|
||||
{assign var="opts" value=explode(',', $field['value'])}
|
||||
{foreach $opts as $opt}
|
||||
<option value="{$opt}" {if $attrs[$field['name']] == $opt}selected{/if}>{$opt}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
{elseif $field['image'] == 'image'}
|
||||
<input type="file" class="form-control" {if $field['required'] == 1} required{/if} name="{$field['name']}"
|
||||
style="width: 100%" placeholder="{$field['placeholder']}" accept="image/*">
|
||||
{else}
|
||||
<input type="{$field['type']}" class="form-control" {if $field['required'] == 1} required{/if}
|
||||
name="{$field['name']}" value="{$attrs[$field['name']]}" style="width: 100%" placeholder="{$field['placeholder']}">
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
@ -109,6 +109,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{$customFields}
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-3 col-md-9">
|
||||
<button class="btn btn-success btn-block" type="submit">
|
||||
|
@ -10,7 +10,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form action="{$_url}register/post" method="post">
|
||||
<form enctype="multipart/form-data" action="{$_url}register/post" method="post">
|
||||
<div class="col-md-4">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">1. {Lang::T('Register as Member')}</div>
|
||||
@ -45,6 +45,7 @@
|
||||
<label>{Lang::T('Address')}</label>
|
||||
<input type="text" name="address" id="address" value="{$address}" class="form-control">
|
||||
</div>
|
||||
{$customFields}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -10,13 +10,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form class="form-horizontal" action="{$_url}register/post" method="post">
|
||||
<form enctype="multipart/form-data" action="{$_url}register/post" method="post">
|
||||
<div class="col-md-4">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">1. {Lang::T('Register as Member')}</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-container">
|
||||
<div class="md-input-container">
|
||||
<div class="form-group">
|
||||
<label>
|
||||
{if $_c['registration_username'] == 'phone'}
|
||||
{Lang::T('Phone Number')}
|
||||
@ -41,20 +41,21 @@
|
||||
placeholder="{if $_c['country_code_phone']!= '' || $_c['registration_username'] == 'phone'}{$_c['country_code_phone']} {Lang::T('Phone Number')}{elseif $_c['registration_username'] == 'email'}{Lang::T('Email')}{else}{Lang::T('Username')}{/if}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-input-container md-float-label">
|
||||
<div class="form-group">
|
||||
<label>{Lang::T('Full Name')}</label>
|
||||
<input type="text" required class="form-control" id="fullname" value="{$fullname}"
|
||||
name="fullname">
|
||||
</div>
|
||||
<div class="md-input-container md-float-label">
|
||||
<div class="form-group">
|
||||
<label>{Lang::T('Email')}</label>
|
||||
<input type="text" class="form-control" id="email" placeholder="xxxxxxx@xxxx.xx"
|
||||
value="{$email}" name="email">
|
||||
</div>
|
||||
<div class="md-input-container md-float-label">
|
||||
<div class="form-group">
|
||||
<label>{Lang::T('Address')}</label>
|
||||
<input type="text" name="address" id="address" value="{$address}" class="form-control">
|
||||
</div>
|
||||
{$customFields}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -64,11 +65,11 @@
|
||||
<div class="panel-heading">2. {Lang::T('Password')}</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-container">
|
||||
<div class="md-input-container md-float-label">
|
||||
<div class="form-group">
|
||||
<label>{Lang::T('Password')}</label>
|
||||
<input type="password" required class="form-control" id="password" name="password">
|
||||
</div>
|
||||
<div class="md-input-container md-float-label">
|
||||
<div class="form-group">
|
||||
<label>{Lang::T('Confirm Password')}</label>
|
||||
<input type="password" required class="form-control" id="cpassword" name="cpassword">
|
||||
</div>
|
||||
|
151
ui/ui/customfield.tpl
Normal file
151
ui/ui/customfield.tpl
Normal file
@ -0,0 +1,151 @@
|
||||
{include file="sections/header.tpl"}
|
||||
|
||||
<form class="form-horizontal" method="post" role="form" action="{$_url}customfield/save">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="panel panel-success panel-hovered panel-stacked mb30">
|
||||
<div class="panel-heading">{Lang::T('New Field')}</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<label class="col-md-4 control-label">Order</label>
|
||||
<div class="col-md-8">
|
||||
<input type="number" class="form-control" name="order[]" style="width: 100%" value="99"
|
||||
placeholder="99">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-4 control-label">Name</label>
|
||||
<div class="col-md-8">
|
||||
<input type="text" class="form-control" name="name[]" style="width: 100%"
|
||||
placeholder="Your Salary">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-4 control-label">Placeholder</label>
|
||||
<div class="col-md-8">
|
||||
<input type="text" class="form-control" name="placeholder[]" style="width: 100%"
|
||||
placeholder="this is placeholder">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-4 control-label">Type</label>
|
||||
<div class="col-md-8">
|
||||
<select class="form-control" name="type[]" style="width: 100%">
|
||||
<option value="text">Text</option>
|
||||
<option value="date">Date</option>
|
||||
<option value="time">Time</option>
|
||||
<option value="number">Number</option>
|
||||
<option value="option">Option</option>
|
||||
<option value="image">Image</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-4 control-label">Option Values</label>
|
||||
<div class="col-md-8">
|
||||
<input type="text" class="form-control" name="value[]" style="width: 100%"
|
||||
placeholder="Male,Female">
|
||||
<span class="help-block">for option using comma separated value.</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-4 control-label">Register Page</label>
|
||||
<div class="col-md-8">
|
||||
<select class="form-control" name="register[]" style="width: 100%">
|
||||
<option value="1">show</option>
|
||||
<option value="0">hide</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-4 control-label">Required</label>
|
||||
<div class="col-md-8">
|
||||
<select class="form-control" name="required[]" style="width: 100%">
|
||||
<option value="1">Yes</option>
|
||||
<option value="0">No</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-8 col-md-offset-3">
|
||||
<button class="btn btn-success btn-sm btn-block" type="submit">{Lang::T('Add')}</button>
|
||||
<span class="help-block">To delete, empty the name</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
{foreach $fields as $field}
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<label class="col-md-4 control-label">Order</label>
|
||||
<div class="col-md-8">
|
||||
<input type="number" class="form-control" name="order[]" style="width: 100%" value="{$field['order']}"
|
||||
placeholder="99">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-4 control-label">Name</label>
|
||||
<div class="col-md-8">
|
||||
<input type="text" class="form-control" name="name[]" style="width: 100%"
|
||||
placeholder="Your Salary" value="{$field['name']}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-4 control-label">Placeholder</label>
|
||||
<div class="col-md-8">
|
||||
<input type="text" class="form-control" name="placeholder[]" style="width: 100%"
|
||||
placeholder="this is placeholder" value="{$field['placeholder']}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-4 control-label">Type</label>
|
||||
<div class="col-md-8">
|
||||
<select class="form-control" name="type[]" style="width: 100%">
|
||||
<option value="text" {if $field['type'] == 'text'}selected{/if}>Text</option>
|
||||
<option value="date" {if $field['type'] == 'date'}selected{/if}>Date</option>
|
||||
<option value="time" {if $field['type'] == 'time'}selected{/if}>Time</option>
|
||||
<option value="number" {if $field['type'] == 'number'}selected{/if}>Number</option>
|
||||
<option value="option" {if $field['type'] == 'option'}selected{/if}>Option</option>
|
||||
<option value="image" {if $field['type'] == 'image'}selected{/if}>Image</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-4 control-label">Option Values</label>
|
||||
<div class="col-md-8">
|
||||
<input type="text" class="form-control" name="value[]" style="width: 100%"
|
||||
placeholder="Male,Female" value="{$field['value']}">
|
||||
<span class="help-block">for option using comma separated value.</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group {if $field['register'] == 1}has-success{/if}">
|
||||
<label class="col-md-4 control-label">Register Page</label>
|
||||
<div class="col-md-8">
|
||||
<select class="form-control" name="register[]" style="width: 100%">
|
||||
<option value="1" {if $field['register'] == 1}selected{/if}>show</option>
|
||||
<option value="0" {if $field['register'] != 1}selected{/if}>hide</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group {if $field['required'] == 1}has-error{/if}"">
|
||||
<label class="col-md-4 control-label">Required</label>
|
||||
<div class="col-md-8">
|
||||
<select class="form-control" name="required[]" style="width: 100%">
|
||||
<option value="1" {if $field['required'] == 1}selected{/if}>Yes</option>
|
||||
<option value="0" {if $field['required'] != 1}selected{/if}>No</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/foreach}
|
||||
<button class="btn btn-success btn-sm btn-block" type="submit">{Lang::T('Save')}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
{include file="sections/footer.tpl"}
|
@ -1416,6 +1416,8 @@
|
||||
href="{$_url}settings/app">{Lang::T('General Settings')}</a></li>
|
||||
<li {if $_routes[1] eq 'localisation' }class="active" {/if}><a
|
||||
href="{$_url}settings/localisation">{Lang::T('Localisation')}</a></li>
|
||||
<li {if $_routes[0] eq 'customfield' }class="active" {/if}><a
|
||||
href="{$_url}customfield">{Lang::T('Custom Fields')}</a></li>
|
||||
<li {if $_routes[1] eq 'miscellaneous' }class="active" {/if}><a
|
||||
href="{$_url}settings/miscellaneous">{Lang::T('Miscellaneous')}</a></li>
|
||||
<li {if $_routes[1] eq 'maintenance' }class="active" {/if}><a
|
||||
|
Loading…
x
Reference in New Issue
Block a user