mirror of
https://github.com/hotspotbilling/phpnuxbill.git
synced 2025-02-21 22:15:32 +08:00
update
admin can add more fields when editing customers
This commit is contained in:
parent
941c723193
commit
aa8fa3f436
2 changed files with 77 additions and 8 deletions
|
@ -422,18 +422,42 @@ switch ($action) {
|
||||||
$customField->set('field_value', $customFieldValue);
|
$customField->set('field_value', $customFieldValue);
|
||||||
$customField->save();
|
$customField->save();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_POST['delete_custom_fields'])) {
|
// Add new custom fields
|
||||||
$fieldsToDelete = $_POST['delete_custom_fields'];
|
if (isset($_POST['custom_field_name']) && isset($_POST['custom_field_value'])) {
|
||||||
foreach ($fieldsToDelete as $fieldName) {
|
$newCustomFieldNames = $_POST['custom_field_name'];
|
||||||
// Delete the custom field with the given field name
|
$newCustomFieldValues = $_POST['custom_field_value'];
|
||||||
ORM::for_table('tbl_customers_custom_fields')
|
|
||||||
->where('field_name', $fieldName)
|
// Check if the number of field names and values match
|
||||||
->delete_many();
|
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) {
|
if ($userDiff || $pppoeDiff || $passDiff) {
|
||||||
$c = ORM::for_table('tbl_user_recharges')->where('username', ($userDiff) ? $oldusername : $username)->find_one();
|
$c = ORM::for_table('tbl_user_recharges')->where('username', ($userDiff) ? $oldusername : $username)->find_one();
|
||||||
if ($c) {
|
if ($c) {
|
||||||
|
|
|
@ -102,7 +102,16 @@
|
||||||
</div>
|
</div>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
{/if}
|
{/if}
|
||||||
<!--custom field edit end-->
|
<!--custom field edit end -->
|
||||||
|
<!--custom field 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 field add end -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-lg-offset-2 col-lg-10">
|
<div class="col-lg-offset-2 col-lg-10">
|
||||||
<button class="btn btn-primary waves-effect waves-light" type="submit">{Lang::T('Save
|
<button class="btn btn-primary waves-effect waves-light" type="submit">{Lang::T('Save
|
||||||
|
@ -117,4 +126,40 @@
|
||||||
</div>
|
</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"}
|
{include file="sections/footer.tpl"}
|
Loading…
Reference in a new issue