[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: users-permissions.php
<?php //require 'db_connection.php'; include("functions.php"); //error_reporting(0); if(!isset($_SESSION['dbmail_Xw211qAAsq4'])){ header("location:../auth-login"); } else { $s_code = $_SESSION['s_code_Xw2119904']; function updateUserPermissions($userId, $permissions, $con, $allPermissions) { // Loop through each permission and handle create, edit, view, and delete foreach ($allPermissions as $permission) { $permissionId = $permission['id']; // Check if the permission was submitted (checkbox is checked) $can_create = isset($permissions[$permissionId]['create']) ? 1 : 0; // Set to 1 if checked, otherwise 0 $can_edit = isset($permissions[$permissionId]['edit']) ? 1 : 0; $can_view = isset($permissions[$permissionId]['view']) ? 1 : 0; $can_delete = isset($permissions[$permissionId]['delete']) ? 1 : 0; // Check if the permission for this user already exists $stmt = $con->prepare("SELECT COUNT(*) FROM user_roles2 WHERE user_id = ? AND permission_id = ?"); $stmt->execute([$userId, $permissionId]); $exists = $stmt->fetchColumn(); if ($exists > 0) { // Update if the permission exists $stmt = $con->prepare("UPDATE user_roles2 SET can_create = ?, can_edit = ?, can_view = ?, can_delete = ? WHERE user_id = ? AND permission_id = ?"); $stmt->execute([$can_create, $can_edit, $can_view, $can_delete, $userId, $permissionId]); } else { // Insert if the permission does not exist $stmt = $con->prepare("INSERT INTO user_roles2 (user_id, permission_id, can_create, can_edit, can_view, can_delete) VALUES (?, ?, ?, ?, ?, ?)"); $stmt->execute([$userId, $permissionId, $can_create, $can_edit, $can_view, $can_delete]); } } } // Fetch users and permissions from the database for the form $users = $con->query("SELECT id, user_name FROM schools WHERE school_code ='$s_code' and user_name !='Admin'")->fetchAll(PDO::FETCH_ASSOC); $permissions = $con->query("SELECT id, permission_name FROM permissions2")->fetchAll(PDO::FETCH_ASSOC); // Handle form submission for updating permissions if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['update_permissions'])) { $userId = $_POST['user_id']; $checkedPermissions = isset($_POST['permissions']) ? $_POST['permissions'] : []; // Update the user permissions in the database updateUserPermissions($userId, $checkedPermissions, $con, $permissions); //$message = "Permissions updated successfully!"; echo "<script> document.addEventListener('DOMContentLoaded', function() { Swal.fire({ title: 'Success!', text: 'Permissions updated successfully.', icon: 'Success', confirmButtonText: 'OK' }); }); </script>"; } // If a user is selected, retrieve their assigned permissions (just for displaying) $selectedUserId = isset($_POST['load_permissions']) ? $_POST['user_id'] : null; $assignedPermissions = []; if ($selectedUserId) { $stmt = $con->prepare("SELECT permission_id, can_create, can_edit, can_view, can_delete FROM user_roles2 WHERE user_id = ?"); $stmt->execute([$selectedUserId]); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $assignedPermissions[$row['permission_id']] = [ 'create' => $row['can_create'], 'edit' => $row['can_edit'], 'view' => $row['can_view'], 'delete' => $row['can_delete'] ]; } } } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>STAFF | ALL STAFF</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta content="Premium Multipurpose Admin & Dashboard Template" name="description" /> <meta content="Themesbrand" name="author" /> <!-- App favicon --> <!-- DataTables --> <link href="assets/libs/datatables.net-bs4/css/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css" /> <link href="assets/libs/datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css" /> <!-- Responsive datatable examples --> <link href="assets/libs/datatables.net-responsive-bs4/css/responsive.bootstrap4.min.css" rel="stylesheet" type="text/css" /> <!-- preloader css --> <link rel="stylesheet" href="assets/css/preloader.min.css" type="text/css" /> <!-- Bootstrap Css --> <link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" /> <!-- Icons Css --> <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" /> <!-- App Css--> <link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" /> <link href="assets/libs/sweetalert2/sweetalert2.min.css" rel="stylesheet" type="text/css" /> <style type="text/css"> table { border-collapse: collapse; width: 100%; } table, th, td { border: 1px solid black; } th, td { padding: 10px; text-align: center; } </style> </head> <body> <!-- <body data-layout="horizontal"> --> <!-- Begin page --> <div id="layout-wrapper"> <?php include("includes/header.php");?> <?php include("includes/sidebar.php");?> <div class="main-content"> <div class="page-content"> <div class="container-fluid"> <!-- start page title --> <div class="row"> <div class="col-12"> <div class="page-title-box d-sm-flex align-items-center justify-content-between"> <h4 class="mb-sm-0 font-size-18">Users permissions</h4> <div class="page-title-right"> <ol class="breadcrumb m-0"> <li class="breadcrumb-item"><a href="javascript: void(0);">Home</a></li> <li class="breadcrumb-item active">Users permissions</li> </ol> </div> </div> </div> </div> <!-- end page title --> <div class="row"> <div class="col-12"> <form method="POST" action=""> <div class="row"> <div class="col-md-6"> <label for="user_id">Select Staff:</label> <select name="user_id" id="c_name" class="form-control" style="width: 400px;"> <option value="" >---SELECT USER---</option> <?php foreach ($users as $user): ?> <option value="<?= $user['id']; ?>" <?= isset($selectedUserId) && $selectedUserId == $user['id'] ? 'selected' : ''; ?>> <?= $user['user_name']; ?> </option> <?php endforeach; ?> </select> </div> <div class="col-md-4"> <button type="submit" class="btn btn-success" name="load_permissions">Load Permissions</button> </div> </div> <br><br> <?php if (!empty($permissions)): ?> <table> <thead> <tr> <th>#</th> <th>Permission</th> <th>Create</th> <th>Edit</th> <th>View</th> <th>Delete</th> </tr> </thead> <tbody> <?php $cnt = 1; foreach ($permissions as $permission): ?> <tr> <td><?= $cnt++; ?></td> <td><?= $permission['permission_name']; ?></td> <td> <input type="checkbox" name="permissions[<?= $permission['id']; ?>][create]" value="1" <?= isset($assignedPermissions[$permission['id']]) && $assignedPermissions[$permission['id']]['create'] ? 'checked' : ''; ?>> </td> <td> <input type="checkbox" name="permissions[<?= $permission['id']; ?>][edit]" value="1" <?= isset($assignedPermissions[$permission['id']]) && $assignedPermissions[$permission['id']]['edit'] ? 'checked' : ''; ?>> </td> <td> <input type="checkbox" name="permissions[<?= $permission['id']; ?>][view]" value="1" <?= isset($assignedPermissions[$permission['id']]) && $assignedPermissions[$permission['id']]['view'] ? 'checked' : ''; ?>> </td> <td> <input type="checkbox" name="permissions[<?= $permission['id']; ?>][delete]" value="1" <?= isset($assignedPermissions[$permission['id']]) && $assignedPermissions[$permission['id']]['delete'] ? 'checked' : ''; ?>> </td> </tr> <?php endforeach; ?> </tbody> </table> <?php else: ?> <p>No permissions found or failed to load permissions.</p> <?php endif; ?> <br> <center><button type="submit" class="btn btn-secondary" name="update_permissions">Update Permissions</button></center> </form> <?php if (isset($message)) : ?> <p><?= $message; ?></p> <?php endif; ?> </div> <!-- end row --> </div> <!-- container-fluid --> </div> <!-- End Page-content --> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script> <script> $(document).ready(function() { function select2FocusFix() { var originalOpen = $.fn.select2.amd.require('select2/select').prototype.position; $.fn.select2.amd.require('select2/select').prototype.position = function(...args) { var result = originalOpen.apply(this, args); if (this.$search) { this.$search.focus(); } return result; }; } // Apply Select2 only to specific select elements $('#c_name').select2({ width: 'resolve' }).on('select2:open', function (e) { setTimeout(() => { $(e.target).data('select2').dropdown.$search.get(0).focus(); }, 0); }); select2FocusFix(); }); </script> <?php include("includes/footer.php");?> </div> <!-- end main content--> </div> <!-- END layout-wrapper --> <!-- Right Sidebar --> <div class="right-bar"> <div data-simplebar class="h-100"> <div class="rightbar-title d-flex align-items-center p-3"> <h5 class="m-0 me-2">Theme Customizer</h5> <a href="javascript:void(0);" class="right-bar-toggle ms-auto"> <i class="mdi mdi-close noti-icon"></i> </a> </div> <!-- Settings --> <hr class="m-0" /> <div class="p-4"> <h6 class="mb-3">Layout</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout" id="layout-vertical" value="vertical"> <label class="form-check-label" for="layout-vertical">Vertical</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout" id="layout-horizontal" value="horizontal"> <label class="form-check-label" for="layout-horizontal">Horizontal</label> </div> <h6 class="mt-4 mb-3 pt-2">Layout Mode</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-mode" id="layout-mode-light" value="light"> <label class="form-check-label" for="layout-mode-light">Light</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-mode" id="layout-mode-dark" value="dark"> <label class="form-check-label" for="layout-mode-dark">Dark</label> </div> <h6 class="mt-4 mb-3 pt-2">Layout Width</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-width" id="layout-width-fuild" value="fuild" onchange="document.body.setAttribute('data-layout-size', 'fluid')"> <label class="form-check-label" for="layout-width-fuild">Fluid</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-width" id="layout-width-boxed" value="boxed" onchange="document.body.setAttribute('data-layout-size', 'boxed')"> <label class="form-check-label" for="layout-width-boxed">Boxed</label> </div> <h6 class="mt-4 mb-3 pt-2">Layout Position</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-position" id="layout-position-fixed" value="fixed" onchange="document.body.setAttribute('data-layout-scrollable', 'false')"> <label class="form-check-label" for="layout-position-fixed">Fixed</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-position" id="layout-position-scrollable" value="scrollable" onchange="document.body.setAttribute('data-layout-scrollable', 'true')"> <label class="form-check-label" for="layout-position-scrollable">Scrollable</label> </div> <h6 class="mt-4 mb-3 pt-2">Topbar Color</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="topbar-color" id="topbar-color-light" value="light" onchange="document.body.setAttribute('data-topbar', 'light')"> <label class="form-check-label" for="topbar-color-light">Light</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="topbar-color" id="topbar-color-dark" value="dark" onchange="document.body.setAttribute('data-topbar', 'dark')"> <label class="form-check-label" for="topbar-color-dark">Dark</label> </div> <h6 class="mt-4 mb-3 pt-2 sidebar-setting">Sidebar Size</h6> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-size" id="sidebar-size-default" value="default" onchange="document.body.setAttribute('data-sidebar-size', 'lg')"> <label class="form-check-label" for="sidebar-size-default">Default</label> </div> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-size" id="sidebar-size-compact" value="compact" onchange="document.body.setAttribute('data-sidebar-size', 'md')"> <label class="form-check-label" for="sidebar-size-compact">Compact</label> </div> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-size" id="sidebar-size-small" value="small" onchange="document.body.setAttribute('data-sidebar-size', 'sm')"> <label class="form-check-label" for="sidebar-size-small">Small (Icon View)</label> </div> <h6 class="mt-4 mb-3 pt-2 sidebar-setting">Sidebar Color</h6> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-color" id="sidebar-color-light" value="light" onchange="document.body.setAttribute('data-sidebar', 'light')"> <label class="form-check-label" for="sidebar-color-light">Light</label> </div> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-color" id="sidebar-color-dark" value="dark" onchange="document.body.setAttribute('data-sidebar', 'dark')"> <label class="form-check-label" for="sidebar-color-dark">Dark</label> </div> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-color" id="sidebar-color-brand" value="brand" onchange="document.body.setAttribute('data-sidebar', 'brand')"> <label class="form-check-label" for="sidebar-color-brand">Brand</label> </div> <h6 class="mt-4 mb-3 pt-2">Direction</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-direction" id="layout-direction-ltr" value="ltr"> <label class="form-check-label" for="layout-direction-ltr">LTR</label> </div> </div> </div> <!-- end slimscroll-menu--> </div> <!-- /Right-bar --> <!-- Right bar overlay--> <div class="rightbar-overlay"></div> <!-- JAVASCRIPT --> <script src="assets/libs/jquery/jquery.min.js"></script> <script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script> <script src="assets/libs/metismenu/metisMenu.min.js"></script> <script src="assets/libs/simplebar/simplebar.min.js"></script> <script src="assets/libs/node-waves/waves.min.js"></script> <script src="assets/libs/feather-icons/feather.min.js"></script> <!-- pace js --> <script src="assets/libs/pace-js/pace.min.js"></script> <script src="assets/libs/sweetalert2/sweetalert2.min.js"></script> <!-- Datatable init js --> <script src="assets/js/pages/datatables.init.js"></script> <script src="assets/js/app.js"></script> <script src="assets/js/pages/validation.init.js"></script> <script src="assets/js/pages/modal.init.js"></script> <script> var myModal = document.getElementById('myModal') var myInput = document.getElementById('myInput') myModal.addEventListener('shown.bs.modal', function () { myInput.focus() }) </script> </body> </html>
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 60.07 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002