forked from kevinowino869/mitrobill
New Feature Added "Custom Fields"
admin can now add unlimited Custom Fields, and also edit or delete the Custom Fields
This commit is contained in:
parent
cb23ddb912
commit
941c723193
@ -188,6 +188,15 @@ CREATE TABLE `tb_languages` (
|
||||
`id` int(11) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
DROP TABLE IF EXISTS `tbl_customers_custom_fields`;
|
||||
CREATE TABLE tbl_customers_custom_fields (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
customer_id INT NOT NULL,
|
||||
field_name VARCHAR(255) NOT NULL,
|
||||
field_value VARCHAR(255) NOT NULL,
|
||||
FOREIGN KEY (customer_id) REFERENCES tbl_customers(id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
ALTER TABLE `tbl_voucher` ADD `generated_by` INT NOT NULL DEFAULT '0' COMMENT 'id admin' AFTER `status`;
|
||||
ALTER TABLE `tbl_users` ADD `root` INT NOT NULL DEFAULT '0' COMMENT 'for sub account' AFTER `id`;
|
||||
ALTER TABLE `tbl_users` CHANGE `user_type` `user_type` ENUM('SuperAdmin','Admin','Report','Agent','Sales') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;
|
||||
|
@ -166,6 +166,13 @@ switch ($action) {
|
||||
$customer = ORM::for_table('tbl_customers')->find_one($id);
|
||||
}
|
||||
if ($customer) {
|
||||
|
||||
|
||||
// Fetch the custom field values from the tbl_customer_custom_fields table
|
||||
$customFields = ORM::for_table('tbl_customers_custom_fields')
|
||||
->where('customer_id', $customer['id'])
|
||||
->find_many();
|
||||
|
||||
$v = $routes['3'];
|
||||
if (empty($v) || $v == 'order') {
|
||||
$v = 'order';
|
||||
@ -193,6 +200,7 @@ switch ($action) {
|
||||
$ui->assign('package', $package);
|
||||
$ui->assign('v', $v);
|
||||
$ui->assign('d', $customer);
|
||||
$ui->assign('customFields', $customFields);
|
||||
$ui->display('customers-view.tpl');
|
||||
} else {
|
||||
r2(U . 'customers/list', 'e', $_L['Account_Not_Found']);
|
||||
@ -202,8 +210,13 @@ switch ($action) {
|
||||
$id = $routes['2'];
|
||||
run_hook('edit_customer'); #HOOK
|
||||
$d = ORM::for_table('tbl_customers')->find_one($id);
|
||||
// Fetch the custom field values from the tbl_customers_custom_fields table
|
||||
$customFields = ORM::for_table('tbl_customers_custom_fields')
|
||||
->where('customer_id', $id)
|
||||
->find_many();
|
||||
if ($d) {
|
||||
$ui->assign('d', $d);
|
||||
$ui->assign('customFields', $customFields);
|
||||
$ui->display('customers-edit.tpl');
|
||||
} else {
|
||||
r2(U . 'customers/list', 'e', $_L['Account_Not_Found']);
|
||||
@ -218,6 +231,8 @@ switch ($action) {
|
||||
run_hook('delete_customer'); #HOOK
|
||||
$d = ORM::for_table('tbl_customers')->find_one($id);
|
||||
if ($d) {
|
||||
// Delete the associated custom field records from tbl_customer_custom_fields table
|
||||
ORM::for_table('tbl_customers_custom_fields')->where('customer_id', $id)->delete_many();
|
||||
$c = ORM::for_table('tbl_user_recharges')->where('username', $d['username'])->find_one();
|
||||
if ($c) {
|
||||
$p = ORM::for_table('tbl_plans')->find_one($c['plan_id']);
|
||||
@ -270,6 +285,10 @@ switch ($action) {
|
||||
$address = _post('address');
|
||||
$phonenumber = _post('phonenumber');
|
||||
$service_type = _post('service_type');
|
||||
//post custom field
|
||||
$custom_field_names = (array) $_POST['custom_field_name'];
|
||||
$custom_field_values = (array) $_POST['custom_field_value'];
|
||||
|
||||
run_hook('add_customer'); #HOOK
|
||||
$msg = '';
|
||||
if (Validator::Length($username, 35, 2) == false) {
|
||||
@ -299,6 +318,25 @@ switch ($action) {
|
||||
$d->phonenumber = Lang::phoneFormat($phonenumber);
|
||||
$d->service_type = $service_type;
|
||||
$d->save();
|
||||
|
||||
// Retrieve the customer ID of the newly created customer
|
||||
$customerId = $d->id();
|
||||
// Save custom field details
|
||||
if (!empty($custom_field_names) && !empty($custom_field_values)) {
|
||||
$totalFields = min(count($custom_field_names), count($custom_field_values));
|
||||
for ($i = 0; $i < $totalFields; $i++) {
|
||||
$name = $custom_field_names[$i];
|
||||
$value = $custom_field_values[$i];
|
||||
|
||||
if (!empty($name)) {
|
||||
$customField = ORM::for_table('tbl_customers_custom_fields')->create();
|
||||
$customField->customer_id = $customerId;
|
||||
$customField->field_name = $name;
|
||||
$customField->field_value = $value;
|
||||
$customField->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
r2(U . 'customers/list', 's', Lang::T('Account Created Successfully'));
|
||||
} else {
|
||||
r2(U . 'customers/add', 'e', $msg);
|
||||
@ -330,6 +368,12 @@ switch ($action) {
|
||||
|
||||
$id = _post('id');
|
||||
$d = ORM::for_table('tbl_customers')->find_one($id);
|
||||
|
||||
//lets find user custom field using id
|
||||
$customFields = ORM::for_table('tbl_customers_custom_fields')
|
||||
->where('customer_id', $id)
|
||||
->find_many();
|
||||
|
||||
if (!$d) {
|
||||
$msg .= Lang::T('Data Not Found') . '<br>';
|
||||
}
|
||||
@ -343,7 +387,7 @@ switch ($action) {
|
||||
if ($oldusername != $username) {
|
||||
$c = ORM::for_table('tbl_customers')->where('username', $username)->find_one();
|
||||
if ($c) {
|
||||
$msg .= Lang::T('Account already axist') . '<br>';
|
||||
$msg .= Lang::T('Account already exist') . '<br>';
|
||||
}
|
||||
$userDiff = true;
|
||||
}
|
||||
@ -368,6 +412,28 @@ switch ($action) {
|
||||
$d->phonenumber = $phonenumber;
|
||||
$d->service_type = $service_type;
|
||||
$d->save();
|
||||
|
||||
|
||||
// Update custom field values in tbl_customers_custom_fields table
|
||||
foreach ($customFields as $customField) {
|
||||
$fieldName = $customField['field_name'];
|
||||
if (isset($_POST['custom_fields'][$fieldName])) {
|
||||
$customFieldValue = $_POST['custom_fields'][$fieldName];
|
||||
$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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($userDiff || $pppoeDiff || $passDiff) {
|
||||
$c = ORM::for_table('tbl_user_recharges')->where('username', ($userDiff) ? $oldusername : $username)->find_one();
|
||||
if ($c) {
|
||||
|
@ -55,5 +55,8 @@
|
||||
],
|
||||
"2024.2.16": [
|
||||
"ALTER TABLE `tbl_customers` ADD `created_by` INT NOT NULL DEFAULT '0' AFTER `auto_renewal`;"
|
||||
],
|
||||
"2024.2.17": [
|
||||
"CREATE TABLE `tbl_customers_custom_fields` (`id` INT PRIMARY KEY AUTO_INCREMENT, `customer_id` INT NOT NULL, `field_name` VARCHAR(255) NOT NULL, `field_value` VARCHAR(255) NOT NULL, FOREIGN KEY (customer_id) REFERENCES tbl_customers(id));"
|
||||
]
|
||||
}
|
@ -62,8 +62,8 @@
|
||||
<input type="password" class="form-control" id="pppoe_password" name="pppoe_password"
|
||||
value="{$d['pppoe_password']}" onmouseleave="this.type = 'password'"
|
||||
onmouseenter="this.type = 'text'">
|
||||
<span
|
||||
class="help-block">{Lang::T('User Cannot change this, only admin. if it Empty it will use user password')}</span>
|
||||
<span class="help-block">{Lang::T('User Cannot change this, only admin. if it Empty it will
|
||||
use user password')}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@ -76,17 +76,27 @@
|
||||
<label class="col-md-2 control-label">{Lang::T('Service Type')}</label>
|
||||
<div class="col-md-6">
|
||||
<select class="form-control" id="service_type" name="service_type">
|
||||
<option value="Hotspot" {if $d['service_type'] eq 'Hotspot'}selected{/if}>Hotspot</option>
|
||||
<option value="Hotspot" {if $d['service_type'] eq 'Hotspot' }selected{/if}>Hotspot
|
||||
</option>
|
||||
<option value="PPPoE" {if $d['service_type'] eq 'PPPoE' }selected{/if}>PPPoE</option>
|
||||
<option value="Others" {if $d['service_type'] eq 'Others' }selected{/if}>Others</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Custom fields add start -->
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">{Lang::T('Custom Field')}</label>
|
||||
<div id="custom-fields-container" class="col-md-6">
|
||||
<button class="btn btn-success btn-sm waves-effect waves-light" type="button"
|
||||
id="add-custom-field">+</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Custom fields add end -->
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-lg-offset-2 col-lg-10">
|
||||
<button class="btn btn-primary waves-effect waves-light"
|
||||
type="submit">{Lang::T('Save Changes')}</button>
|
||||
<button class="btn btn-primary waves-effect waves-light" type="submit">{Lang::T('Save
|
||||
Changes')}</button>
|
||||
Or <a href="{$_url}customers/list">{Lang::T('Cancel')}</a>
|
||||
</div>
|
||||
</div>
|
||||
@ -96,6 +106,41 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{literal}
|
||||
<script type="text/javascript">
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
var customFieldsContainer = document.getElementById('custom-fields-container');
|
||||
var addCustomFieldButton = document.getElementById('add-custom-field');
|
||||
|
||||
addCustomFieldButton.addEventListener('click', function() {
|
||||
var fieldIndex = customFieldsContainer.children.length;
|
||||
var newField = document.createElement('div');
|
||||
newField.className = 'form-group';
|
||||
newField.innerHTML = `
|
||||
<label class="col-md-2 control-label">Name:</label>
|
||||
<div class="col-md-3">
|
||||
<input type="text" class="form-control" name="custom_field_name[]" placeholder="Name">
|
||||
</div>
|
||||
<label class="col-md-2 control-label">Value:</label>
|
||||
<div class="col-md-3">
|
||||
<input type="text" class="form-control" name="custom_field_value[]" placeholder="Value">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="button" class="remove-custom-field btn btn-danger btn-sm waves-effect waves-light">-</button>
|
||||
</div>
|
||||
`;
|
||||
customFieldsContainer.appendChild(newField);
|
||||
});
|
||||
|
||||
customFieldsContainer.addEventListener('click', function(event) {
|
||||
if (event.target.classList.contains('remove-custom-field')) {
|
||||
var fieldContainer = event.target.parentNode.parentNode;
|
||||
fieldContainer.parentNode.removeChild(fieldContainer);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{/literal}
|
||||
|
||||
|
||||
{include file="sections/footer.tpl"}
|
@ -67,8 +67,8 @@
|
||||
<input type="password" autocomplete="off" class="form-control" id="pppoe_password"
|
||||
name="pppoe_password" value="{$d['pppoe_password']}"
|
||||
onmouseleave="this.type = 'password'" onmouseenter="this.type = 'text'">
|
||||
<span
|
||||
class="help-block">{Lang::T('User Cannot change this, only admin. if it Empty it will use user password')}</span>
|
||||
<span class="help-block">{Lang::T('User Cannot change this, only admin. if it Empty it will
|
||||
use user password')}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@ -81,17 +81,32 @@
|
||||
<label class="col-md-2 control-label">{Lang::T('Service Type')}</label>
|
||||
<div class="col-md-6">
|
||||
<select class="form-control" id="service_type" name="service_type">
|
||||
<option value="Hotspot" {if $d['service_type'] eq 'Hotspot'}selected{/if}>Hotspot</option>
|
||||
<option value="Hotspot" {if $d['service_type'] eq 'Hotspot' }selected{/if}>Hotspot
|
||||
</option>
|
||||
<option value="PPPoE" {if $d['service_type'] eq 'PPPoE' }selected{/if}>PPPoE</option>
|
||||
<option value="Others" {if $d['service_type'] eq 'Others' }selected{/if}>Others</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--custom field edit start -->
|
||||
{if $customFields}
|
||||
{foreach $customFields as $customField}
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label"
|
||||
for="{$customField.field_name}">{$customField.field_name}</label>
|
||||
<div class="col-md-6">
|
||||
<input class="form-control" type="text" name="custom_fields[{$customField.field_name}]"
|
||||
id="{$customField.field_name}" value="{$customField.field_value}">
|
||||
</div>
|
||||
<input type="checkbox" name="delete_custom_fields[]" value="{$customField.field_name}"> Delete
|
||||
</div>
|
||||
{/foreach}
|
||||
{/if}
|
||||
<!--custom field edit end-->
|
||||
<div class="form-group">
|
||||
<div class="col-lg-offset-2 col-lg-10">
|
||||
<button class="btn btn-primary waves-effect waves-light"
|
||||
type="submit">{Lang::T('Save Changes')}</button>
|
||||
<button class="btn btn-primary waves-effect waves-light" type="submit">{Lang::T('Save
|
||||
Changes')}</button>
|
||||
Or <a href="{$_url}customers/list">{Lang::T('Cancel')}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -37,6 +37,15 @@
|
||||
onclick="this.select()">
|
||||
</li>
|
||||
{/if}
|
||||
<!--custom field view start -->
|
||||
{if $customFields}
|
||||
{foreach $customFields as $customField}
|
||||
<li class="list-group-item">
|
||||
<b>{$customField.field_name}</b> <span class="pull-right">{$customField.field_value}</span>
|
||||
</li>
|
||||
{/foreach}
|
||||
{/if}
|
||||
<!--custom field view end -->
|
||||
<li class="list-group-item">
|
||||
<b>{Lang::T('Service Type')}</b> <span class="pull-right">{Lang::T($d['service_type'])}</span>
|
||||
</li>
|
||||
@ -44,8 +53,8 @@
|
||||
<b>{Lang::T('Balance')}</b> <span class="pull-right">{Lang::moneyFormat($d['balance'])}</span>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<b>{Lang::T('Auto Renewal')}</b> <span
|
||||
class="pull-right">{if $d['auto_renewal']}yes{else}no{/if}</span>
|
||||
<b>{Lang::T('Auto Renewal')}</b> <span class="pull-right">{if
|
||||
$d['auto_renewal']}yes{else}no{/if}</span>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<b>{Lang::T('Created On')}</b> <span
|
||||
@ -59,8 +68,8 @@
|
||||
<div class="row">
|
||||
<div class="col-xs-4">
|
||||
<a href="{$_url}customers/delete/{$d['id']}" id="{$d['id']}"
|
||||
class="btn btn-danger btn-block btn-sm" onclick="return confirm('{Lang::T('Delete')}?')"><span
|
||||
class="fa fa-trash"></span></a>
|
||||
class="btn btn-danger btn-block btn-sm"
|
||||
onclick="return confirm('{Lang::T('Delete')}?')"><span class="fa fa-trash"></span></a>
|
||||
</div>
|
||||
<div class="col-xs-8">
|
||||
<a href="{$_url}customers/edit/{$d['id']}"
|
||||
@ -75,8 +84,8 @@
|
||||
<h4 class="text-center">{$package['type']} - {$package['namebp']}</h4>
|
||||
<ul class="list-group list-group-unbordered">
|
||||
<li class="list-group-item">
|
||||
{Lang::T('Active')} <span
|
||||
class="pull-right">{if $package['status']=='on'}yes{else}no{/if}</span>
|
||||
{Lang::T('Active')} <span class="pull-right">{if
|
||||
$package['status']=='on'}yes{else}no{/if}</span>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
{Lang::T('Created On')} <span
|
||||
@ -84,7 +93,8 @@
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
{Lang::T('Expires On')} <span
|
||||
class="pull-right">{Lang::dateAndTimeFormat($package['expiration'], $package['time'])}</span>
|
||||
class="pull-right">{Lang::dateAndTimeFormat($package['expiration'],
|
||||
$package['time'])}</span>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
{$package['routers']} <span class="pull-right">{$package['method']}</span>
|
||||
|
Loading…
x
Reference in New Issue
Block a user