Add user role management functionality with CRUD operations and permissions handling
- 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.
This commit is contained in:
128
api/v2/get/user_role_assignments.php
Normal file
128
api/v2/get/user_role_assignments.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// User Role Assignments
|
||||
//------------------------------------------
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//------------------------------------------
|
||||
//NEW ARRAY
|
||||
//------------------------------------------
|
||||
$criterias = [];
|
||||
$clause = '';
|
||||
|
||||
//------------------------------------------
|
||||
//Check for $_GET variables and build up clause
|
||||
//------------------------------------------
|
||||
if(isset($get_content) && $get_content!=''){
|
||||
//GET VARIABLES FROM URL
|
||||
$requests = explode("&", $get_content);
|
||||
//Check for keys and values
|
||||
foreach ($requests as $y){
|
||||
$v = explode("=", $y);
|
||||
//INCLUDE VARIABLES IN ARRAY
|
||||
$criterias[$v[0]] = $v[1];
|
||||
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='success_msg'){
|
||||
//do nothing
|
||||
}
|
||||
elseif ($v[0] == 'rowid') {
|
||||
//build up search by ID
|
||||
$clause .= ' AND ura.rowID = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'role_id') {
|
||||
//build up search by role_id
|
||||
$clause .= ' AND ura.role_id = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'user_id') {
|
||||
//build up search by user_id
|
||||
$clause .= ' AND ura.user_id = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'status') {
|
||||
//Update status based on status
|
||||
$clause .= ' AND ura.is_active = :'.$v[0];
|
||||
}
|
||||
else {
|
||||
//create clause
|
||||
$clause .= ' AND ura.'.$v[0].' = :'.$v[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Build WHERE clause
|
||||
$whereclause = '';
|
||||
if ($clause != ''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
}
|
||||
|
||||
if (isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||
//Request for total rows
|
||||
$sql = 'SELECT count(*) as count FROM user_role_assignments ura '.$whereclause;
|
||||
}
|
||||
else {
|
||||
//SQL with joined tables for names
|
||||
$sql = 'SELECT ura.*,
|
||||
u.username,
|
||||
u.email,
|
||||
r.name as role_name,
|
||||
r.description as role_description
|
||||
FROM user_role_assignments ura
|
||||
LEFT JOIN users u ON ura.user_id = u.id
|
||||
LEFT JOIN user_roles r ON ura.role_id = r.rowID
|
||||
'.$whereclause.'
|
||||
ORDER BY u.username ASC';
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
//------------------------------------------
|
||||
//Bind to query
|
||||
//------------------------------------------
|
||||
if (!empty($criterias)){
|
||||
foreach ($criterias as $key => $value){
|
||||
$key_condition = ':'.$key;
|
||||
if (str_contains($sql, $key_condition)){
|
||||
if ($key == 'p'){
|
||||
//Do nothing (bug)
|
||||
}
|
||||
else {
|
||||
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// Debuglog
|
||||
//------------------------------------------
|
||||
if (debug){
|
||||
$message = $date.';'.$sql.';'.$username;
|
||||
debuglog($message);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//Execute Query
|
||||
//------------------------------------------
|
||||
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetch();
|
||||
$messages = $messages[0];
|
||||
}
|
||||
else {
|
||||
//Execute Query
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_EnCODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
//------------------------------------------
|
||||
//Send results
|
||||
//------------------------------------------
|
||||
echo $messages;
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user