update users
This commit is contained in:
parent
b2926230f7
commit
58eab84b92
87
users.php
87
users.php
@ -240,6 +240,20 @@ require __DIR__ . '/includes/header.php';
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-12 mb-3">
|
||||||
|
<label class="form-label"><?= h(tr('فروع إضافية يمكن الوصول إليها', 'Additional Accessible Branches')) ?></label>
|
||||||
|
<div class="d-flex flex-wrap gap-3 p-2 border rounded bg-light">
|
||||||
|
<?php foreach ($availableBranches as $code => $b): ?>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input additional-branch" type="checkbox" name="allowed_branches[]" value="<?= h($code) ?>" id="ab_<?= h($code) ?>">
|
||||||
|
<label class="form-check-label ms-1" for="ab_<?= h($code) ?>">
|
||||||
|
<?= h(current_lang() === 'ar' ? $b['name_ar'] : $b['name_en']) ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div> <!-- Close row -->
|
</div> <!-- Close row -->
|
||||||
|
|
||||||
<h6 class="mt-4 mb-3"><?= h(tr('صلاحيات الوصول المخصصة', 'Custom Access Permissions')) ?></h6>
|
<h6 class="mt-4 mb-3"><?= h(tr('صلاحيات الوصول المخصصة', 'Custom Access Permissions')) ?></h6>
|
||||||
@ -247,7 +261,12 @@ require __DIR__ . '/includes/header.php';
|
|||||||
<table class="table table-sm table-bordered">
|
<table class="table table-sm table-bordered">
|
||||||
<thead class="table-light">
|
<thead class="table-light">
|
||||||
<tr>
|
<tr>
|
||||||
<th><?= h(tr('الواجهة', 'Module')) ?></th>
|
<th>
|
||||||
|
<div class="form-check d-inline-block mb-0">
|
||||||
|
<input class="form-check-input" type="checkbox" id="selectAllPerms" onchange="toggleAllPerms(this)">
|
||||||
|
<label class="form-check-label ms-1 fw-bold" for="selectAllPerms"><?= h(tr('الواجهة', 'Module')) ?></label>
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
<th class="text-center"><?= h(tr('عرض', 'Show')) ?></th>
|
<th class="text-center"><?= h(tr('عرض', 'Show')) ?></th>
|
||||||
<th class="text-center"><?= h(tr('إضافة', 'Add')) ?></th>
|
<th class="text-center"><?= h(tr('إضافة', 'Add')) ?></th>
|
||||||
<th class="text-center"><?= h(tr('تعديل', 'Edit')) ?></th>
|
<th class="text-center"><?= h(tr('تعديل', 'Edit')) ?></th>
|
||||||
@ -257,12 +276,19 @@ require __DIR__ . '/includes/header.php';
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach (get_app_modules() as $key => $module): ?>
|
<?php foreach (get_app_modules() as $key => $module): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?= h(current_lang() === 'ar' ? $module['name_ar'] : $module['name_en']) ?></td>
|
<td>
|
||||||
|
<div class="form-check mb-0">
|
||||||
|
<input class="form-check-input row-perm-check" type="checkbox" id="row_<?= $key ?>" onchange="toggleRowPerms(this, '<?= $key ?>')">
|
||||||
|
<label class="form-check-label ms-1" for="row_<?= $key ?>">
|
||||||
|
<?= h(current_lang() === 'ar' ? $module['name_ar'] : $module['name_en']) ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
<?php foreach (['show', 'add', 'edit', 'del'] as $act): ?>
|
<?php foreach (['show', 'add', 'edit', 'del'] as $act): ?>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<?php if (in_array($act, $module['actions'])): ?>
|
<?php if (in_array($act, $module['actions'])): ?>
|
||||||
<div class="form-check d-flex justify-content-center mb-0">
|
<div class="form-check d-flex justify-content-center mb-0">
|
||||||
<input class="form-check-input perm-check" type="checkbox" name="permissions[<?= $key ?>][<?= $act ?>]" id="perm_<?= $key ?>_<?= $act ?>" value="1">
|
<input class="form-check-input perm-check perm-row-<?= $key ?>" type="checkbox" name="permissions[<?= $key ?>][<?= $act ?>]" id="perm_<?= $key ?>_<?= $act ?>" value="1">
|
||||||
</div>
|
</div>
|
||||||
<?php else:
|
<?php else:
|
||||||
?>
|
?>
|
||||||
@ -288,16 +314,61 @@ require __DIR__ . '/includes/header.php';
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
let userModal;
|
let userModal;
|
||||||
|
|
||||||
|
function toggleAllPerms(source) {
|
||||||
|
document.querySelectorAll('.perm-check').forEach(cb => {
|
||||||
|
if (!cb.disabled) cb.checked = source.checked;
|
||||||
|
});
|
||||||
|
document.querySelectorAll('.row-perm-check').forEach(cb => {
|
||||||
|
if (!cb.disabled) cb.checked = source.checked;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleRowPerms(source, key) {
|
||||||
|
document.querySelectorAll('.perm-row-' + key).forEach(cb => {
|
||||||
|
if (!cb.disabled) cb.checked = source.checked;
|
||||||
|
});
|
||||||
|
updateSelectAllCheckbox();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSelectAllCheckbox() {
|
||||||
|
let allPerms = document.querySelectorAll('.perm-check');
|
||||||
|
let allChecked = document.querySelectorAll('.perm-check:checked');
|
||||||
|
let selectAllCb = document.getElementById('selectAllPerms');
|
||||||
|
if (selectAllCb) {
|
||||||
|
selectAllCb.checked = (allPerms.length > 0 && allPerms.length === allChecked.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
userModal = new bootstrap.Modal(document.getElementById('userModal'));
|
userModal = new bootstrap.Modal(document.getElementById('userModal'));
|
||||||
|
|
||||||
|
document.querySelectorAll('.perm-check').forEach(cb => {
|
||||||
|
cb.addEventListener('change', function() {
|
||||||
|
let rowClass = Array.from(this.classList).find(c => c.startsWith('perm-row-'));
|
||||||
|
if (rowClass) {
|
||||||
|
let key = rowClass.replace('perm-row-', '');
|
||||||
|
let rowPerms = document.querySelectorAll('.' + rowClass);
|
||||||
|
let rowChecked = document.querySelectorAll('.' + rowClass + ':checked');
|
||||||
|
let rowCb = document.getElementById('row_' + key);
|
||||||
|
if (rowCb) {
|
||||||
|
rowCb.checked = (rowPerms.length > 0 && rowPerms.length === rowChecked.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateSelectAllCheckbox();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function openAddModal() {
|
function openAddModal() {
|
||||||
document.getElementById('userAction').value = 'add';
|
document.getElementById('userAction').value = 'add';
|
||||||
document.getElementById('userId').value = '';
|
document.getElementById('userId').value = '';
|
||||||
document.getElementById('userForm').reset();
|
document.getElementById('userForm').reset();
|
||||||
document.querySelectorAll('.additional-branch').forEach(cb => cb.checked = false);
|
document.querySelectorAll('.additional-branch').forEach(cb => cb.checked = false);
|
||||||
document.querySelectorAll('.perm-check').forEach(cb => cb.checked = false);
|
document.querySelectorAll('.perm-check').forEach(cb => cb.checked = false);
|
||||||
|
document.querySelectorAll('.row-perm-check').forEach(cb => cb.checked = false);
|
||||||
|
if(document.getElementById('selectAllPerms')) document.getElementById('selectAllPerms').checked = false;
|
||||||
document.getElementById('userModalLabel').innerText = '<?= h(tr('إضافة مستخدم جديد', 'Add New User')) ?>';
|
document.getElementById('userModalLabel').innerText = '<?= h(tr('إضافة مستخدم جديد', 'Add New User')) ?>';
|
||||||
document.getElementById('password').required = true;
|
document.getElementById('password').required = true;
|
||||||
document.getElementById('passwordHelp').innerText = '';
|
document.getElementById('passwordHelp').innerText = '';
|
||||||
@ -329,6 +400,8 @@ function openEditModal(account) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.querySelectorAll('.perm-check').forEach(cb => cb.checked = false);
|
document.querySelectorAll('.perm-check').forEach(cb => cb.checked = false);
|
||||||
|
document.querySelectorAll('.row-perm-check').forEach(cb => cb.checked = false);
|
||||||
|
if(document.getElementById('selectAllPerms')) document.getElementById('selectAllPerms').checked = false;
|
||||||
if (account.permissions) {
|
if (account.permissions) {
|
||||||
try {
|
try {
|
||||||
let perms = typeof account.permissions === 'string' ? JSON.parse(account.permissions) : account.permissions;
|
let perms = typeof account.permissions === 'string' ? JSON.parse(account.permissions) : account.permissions;
|
||||||
@ -341,6 +414,14 @@ function openEditModal(account) {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('.row-perm-check').forEach(rowCb => {
|
||||||
|
let key = rowCb.id.replace('row_', '');
|
||||||
|
let rowPerms = document.querySelectorAll('.perm-row-' + key);
|
||||||
|
let rowChecked = document.querySelectorAll('.perm-row-' + key + ':checked');
|
||||||
|
rowCb.checked = (rowPerms.length > 0 && rowPerms.length === rowChecked.length);
|
||||||
|
});
|
||||||
|
updateSelectAllCheckbox();
|
||||||
|
|
||||||
document.getElementById('userModalLabel').innerText = '<?= h(tr('تعديل مستخدم', 'Edit User')) ?>';
|
document.getElementById('userModalLabel').innerText = '<?= h(tr('تعديل مستخدم', 'Edit User')) ?>';
|
||||||
userModal.show();
|
userModal.show();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user