- 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.
198 lines
7.2 KiB
PHP
198 lines
7.2 KiB
PHP
<?php
|
|
defined(page_security_key) or exit;
|
|
|
|
if (debug && debug_id == $_SESSION['id']){
|
|
ini_set('display_errors', '1');
|
|
ini_set('display_startup_errors', '1');
|
|
error_reporting(E_ALL);
|
|
}
|
|
|
|
include_once './assets/functions.php';
|
|
include_once './settings/settings_redirector.php';
|
|
|
|
//SET PAGE ORIGIN FOR NAVIGATION AND SECURITY
|
|
$prev_page = (isset($_SESSION['origin']) && $_SESSION['origin'] == 'equipments') ? $_SESSION['prev_origin_equipment'] : ((isset($_SESSION['origin']) && $_SESSION['origin'] == 'account')? $_SESSION['prev_origin'] :'');
|
|
$page = 'users';
|
|
|
|
//create backbutton to prev_origin
|
|
$back_btn_orgin = ($prev_page != '')? '<a href="'.$prev_page.'" class="btn alt mar-right-2">←</a>':'';
|
|
|
|
//Check if allowed
|
|
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
|
|
header('location: index.php');
|
|
exit;
|
|
}
|
|
//PAGE Security
|
|
$update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'U');
|
|
$delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'D');
|
|
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
|
|
|
|
|
|
//GET PARAMETERS
|
|
$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
|
|
$status = isset($_GET['status']) ? '&status='.$_GET['status'] : '';
|
|
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
|
|
|
|
// Determine the URL
|
|
$url = 'index.php?page=users'.$status.$search;
|
|
//GET Details from URL
|
|
$GET_VALUES = urlGETdetails($_GET) ?? '';
|
|
//CALL TO API
|
|
$api_url = '/v2/users/'.$GET_VALUES;
|
|
$responses = ioServer($api_url,'');
|
|
//Decode Payload
|
|
if (!empty($responses)){$responses = json_decode($responses);}else{$responses = null;}
|
|
|
|
//Return QueryTotal from API
|
|
$api_url = '/v2/users/'.$GET_VALUES.'&totals=';
|
|
$query_total = ioServer($api_url,'');
|
|
//Decode Payload
|
|
if (!empty($query_total)){$query_total = json_decode($query_total);}else{$query_total = null;}
|
|
|
|
// Handle success messages
|
|
if (isset($_GET['success_msg'])) {
|
|
if ($_GET['success_msg'] == 1) {
|
|
$success_msg = $message_us_1;
|
|
}
|
|
if ($_GET['success_msg'] == 2) {
|
|
$success_msg = $message_us_2;
|
|
}
|
|
if ($_GET['success_msg'] == 3) {
|
|
$success_msg = $message_us_3;
|
|
}
|
|
}
|
|
|
|
template_header('Users', 'users','view');
|
|
$view = '
|
|
<div class="content-title">
|
|
<div class="title">
|
|
<i class="fa-solid fa-users-gear"></i>
|
|
<div class="txt">
|
|
<h2>'.$users_h2.' ('.$query_total.')</h2>
|
|
<p>'.$users_p.'</p>
|
|
</div>
|
|
</div>
|
|
<div class="title-actions">
|
|
'.$back_btn_orgin;
|
|
|
|
if ($create_allowed === 1){
|
|
$view .= '<a href="index.php?page=user" class="btn">+</a>';
|
|
}
|
|
|
|
$view .= '<button id="filter-toggle" class="btn alt" onclick="toggleFilters()">
|
|
<i class="fa-solid fa-search"></i>
|
|
</button>
|
|
</div>
|
|
</div>';
|
|
|
|
if (isset($success_msg)){
|
|
$view .= ' <div class="msg success">
|
|
<i class="fas fa-check-circle"></i>
|
|
<p>'.$success_msg.'</p>
|
|
<i class="fas fa-times"></i>
|
|
</div>';
|
|
}
|
|
|
|
$view .= '
|
|
<div id="filter-panel" class="filter-panel" style="display: none;">
|
|
<div class="filter-content">
|
|
<form action="" method="get">
|
|
<input type="hidden" name="page" value="users">
|
|
<div class="filter-row">
|
|
<div class="filter-group">
|
|
<select name="userkey">
|
|
<option value="" disabled selected>Active</option>
|
|
<option value="0"'.($status==0?' selected':'').'>'.$disabled.'</option>
|
|
<option value="1"'.($status==1?' selected':'').'>'.$enabled.'</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="filter-group search-group">
|
|
<input type="text" name="search" placeholder="'.$users_search.'" value="">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="filter-actions">
|
|
<button type="submit" class="btn"><i class="fas fa-level-down-alt fa-rotate-90"></i></button>
|
|
<a class="btn alt" href="index.php?page=users">'.$general_filters_clear.'</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
';
|
|
|
|
$view .= '
|
|
<div class="content-block">
|
|
<div class="table">
|
|
<table class="sortable">
|
|
<thead>
|
|
<tr>
|
|
<th class="responsive-hidden"></th>
|
|
<th class="responsive-hidden">'.$User_update.'</th>
|
|
<th class="responsive-hidden">'.$User_service.'</th>
|
|
<th>'.$User_username.'</th>
|
|
<th>'.$User_partnerhierarchy.'</th>
|
|
<th>'.$User_permission.'</th>
|
|
<th>'.$User_profile.'</th>
|
|
<th class="responsive-hidden">'.$User_lastlogin.'</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
';
|
|
|
|
if (empty($responses)){
|
|
|
|
$view .= '
|
|
<tr>
|
|
<td colspan="8" style="text-align:center;">'.$message_no_users.'</td>
|
|
</tr>';
|
|
}
|
|
else {
|
|
foreach ($responses as $response){
|
|
|
|
//Replace JSON ITEMS
|
|
$search = ['{', '}', '"',':',','];
|
|
$replace = ['', '','','=',' || '];
|
|
$partner_hierarchy = str_replace($search, $replace, $response->partnerhierarchy);
|
|
|
|
$permission_user = 'permission'.$response->view;
|
|
$view .= '
|
|
<tr onclick="window.location.href=\'index.php?page=user&id='.$response->id.'\'" style="cursor: pointer;">
|
|
<td class="responsive-hidden"></td>
|
|
<td class="responsive-hidden">'.(($response->login_count > 4)? '<span class="status disabled">'.$User_block:(($response->userkey && $response->userkey !='')? '<span class="status enabled">'.$enabled:'<span class="status">'.$disabled)).'</td>
|
|
<td class="responsive-hidden">'.(($response->service && $response->service !='')? '<span class="status enabled">'.$enabled:'<span class="status">'.$disabled).'</td>
|
|
<td>'.$response->username.'</td>
|
|
<td>'.$partner_hierarchy.'</td>
|
|
<td>'.$$permission_user.'</td>
|
|
<td>'.$response->settings.'</td>
|
|
<td class="responsive-hidden">'.getRelativeTime($response->lastlogin).'</td>
|
|
</tr>
|
|
';
|
|
}
|
|
}
|
|
$view .= '
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
';
|
|
|
|
$view.='<div class="pagination">';
|
|
if ($pagination_page > 1) {
|
|
$page = $pagination_page-1;
|
|
$view .= '<a href="'.$url.'&p=1">'.$general_first.'</a>';
|
|
$view .= '<a href="'.$url.'&p='.$page.'">'.$general_prev.'</a>';
|
|
}
|
|
$totals = ceil($query_total / $page_rows_users) == 0 ? 1 : ceil($query_total / $page_rows_users);
|
|
$view .= '<span> '.$general_page.$pagination_page.$general_page_of.$totals.'</span>';
|
|
if ($pagination_page * $page_rows_users < $query_total){
|
|
$page = $pagination_page+1;
|
|
$view .= '<a href="'.$url.'&p='.$page.'">'.$general_next.'</a>';
|
|
$view .= '<a href="'.$url.'&p='.$totals.'">'.$general_last.'</a>';
|
|
}
|
|
$view .= '</div>';
|
|
//OUTPUT
|
|
echo $view;
|
|
|
|
template_footer();
|
|
?>
|