- Created user_role.php for viewing and editing user roles and their permissions. - Implemented inline editing for role details and permissions. - Added user_role_manage.php for creating and managing user roles. - Introduced user_roles.php for listing all user roles with pagination and filtering options. - Integrated API calls for fetching and updating role data and permissions. - Enhanced user interface with success messages and navigation controls.
76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
defined($security_key) or exit;
|
|
|
|
//------------------------------------------
|
|
// Role Access Permissions
|
|
//------------------------------------------
|
|
//Connect to DB
|
|
$pdo = dbConnect($dbname);
|
|
|
|
//CONTENT FROM API (POST)
|
|
$post_content = json_decode($input,true);
|
|
|
|
//SET PARAMETERS FOR QUERY
|
|
$id = $post_content['rowID'] ?? '';
|
|
$command = ($id == '')? 'insert' : 'update';
|
|
if (isset($post_content['delete'])){$command = 'delete';}
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
//CREATE EMPTY STRINGS
|
|
$clause = '';
|
|
$clause_insert ='';
|
|
$input_insert = '';
|
|
$execute_input = [];
|
|
$criterias = [];
|
|
|
|
//ADD STANDARD PARAMETERS TO ARRAY BASED ON INSERT OR UPDATE
|
|
if ($command == 'update'){
|
|
$post_content['updatedby'] = $username;;
|
|
$post_content['updated'] = $date;
|
|
}
|
|
elseif ($command == 'insert'){
|
|
$post_content['created'] = $date;
|
|
$post_content['createdby'] = $username;;
|
|
}
|
|
|
|
//CREAT NEW ARRAY AND MAP TO CLAUSE
|
|
if(isset($post_content) && $post_content!=''){
|
|
foreach ($post_content as $key => $var){
|
|
if ($key == 'submit' || $key == 'rowID' || str_contains($key, 'old_')){
|
|
//do nothing
|
|
}
|
|
else {
|
|
$criterias[$key] = $var;
|
|
$clause .= ' , '.$key.' = ?';
|
|
$clause_insert .= ' , '.$key.'';
|
|
$input_insert .= ', ?';
|
|
$execute_input[]= $var;
|
|
}
|
|
}
|
|
}
|
|
|
|
//CLEAN UP INPUT
|
|
$clause = substr($clause, 2);
|
|
$clause_insert = substr($clause_insert, 2);
|
|
$input_insert = substr($input_insert, 1);
|
|
|
|
//QUERY AND VERIFY ALLOWED
|
|
if ($command == 'update' && isAllowed('user_role_manage',$profile,$permission,'U') === 1){
|
|
$sql = 'UPDATE role_access_permissions SET '.$clause.' WHERE rowID = ?';
|
|
$execute_input[] = $id;
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($execute_input);
|
|
}
|
|
elseif ($command == 'insert' && isAllowed('user_role_manage',$profile,$permission,'C') === 1){
|
|
$sql = 'INSERT INTO role_access_permissions ('.$clause_insert.') VALUES ('.$input_insert.')';
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($execute_input);
|
|
}
|
|
elseif ($command == 'delete' && isAllowed('user_role_manage',$profile,$permission,'D') === 1){
|
|
//Delete permission
|
|
$stmt = $pdo->prepare('DELETE FROM role_access_permissions WHERE rowID = ?');
|
|
$stmt->execute([$id]);
|
|
}
|
|
|
|
?>
|