Refactor user session handling and permissions management
- Updated session variables to use 'authorization' array instead of 'username' for user identification across multiple files. - Introduced a new function `getUserPermissions` to consolidate user permissions retrieval based on assigned roles. - Modified API calls to use the new authorization structure and updated endpoints to v2. - Enhanced language support by adding 'PL' to the list of supported languages. - Cleaned up redundant code and improved session management during user login and registration processes. - Added a new API endpoint for fetching user permissions based on user ID.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
defined(page_security_key) or exit;
|
||||
|
||||
if (debug && debug_id == $_SESSION['id']){
|
||||
if (debug && debug_id == $_SESSION['authorization']['id']){
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
@@ -14,19 +14,19 @@ include_once './settings/settings_redirector.php';
|
||||
$_SESSION['prev_origin_equipment'] = $_SERVER['REQUEST_URI'];
|
||||
$page = 'equipment';
|
||||
//Check if allowed
|
||||
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
|
||||
if (isAllowed($page,$_SESSION['authorization']['profile'],$_SESSION['authorization']['permission'],'R') === 0){
|
||||
header('location: index.php');
|
||||
exit;
|
||||
}
|
||||
//PAGE Security
|
||||
$page_manage = 'equipment_manage';
|
||||
$update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'U');
|
||||
$update_allowed_edit = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'U');
|
||||
$delete_allowed = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'D');
|
||||
$create_allowed = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'C');
|
||||
$view_product = isAllowed('product' ,$_SESSION['profile'],$_SESSION['permission'],'R');
|
||||
$view_history = isAllowed('history' ,$_SESSION['profile'],$_SESSION['permission'],'C');
|
||||
$view_contracts = isAllowed('contracts' ,$_SESSION['profile'],$_SESSION['permission'],'R');
|
||||
$update_allowed = isAllowed($page ,$_SESSION['authorization']['profile'],$_SESSION['authorization']['permission'],'U');
|
||||
$update_allowed_edit = isAllowed($page_manage ,$_SESSION['authorization']['profile'],$_SESSION['authorization']['permission'],'U');
|
||||
$delete_allowed = isAllowed($page_manage ,$_SESSION['authorization']['profile'],$_SESSION['authorization']['permission'],'D');
|
||||
$create_allowed = isAllowed($page_manage ,$_SESSION['authorization']['profile'],$_SESSION['authorization']['permission'],'C');
|
||||
$view_product = isAllowed('product' ,$_SESSION['authorization']['profile'],$_SESSION['authorization']['permission'],'R');
|
||||
$view_history = isAllowed('history' ,$_SESSION['authorization']['profile'],$_SESSION['authorization']['permission'],'C');
|
||||
$view_contracts = isAllowed('contracts' ,$_SESSION['authorization']['profile'],$_SESSION['authorization']['permission'],'R');
|
||||
|
||||
//GET Details from URL
|
||||
$GET_VALUES = urlGETdetails($_GET) ?? '';
|
||||
@@ -108,7 +108,7 @@ if (!empty($responses->sw_version_upgrade) && isset($products_software) && $prod
|
||||
}
|
||||
|
||||
//Calculate Healthindex based on last test
|
||||
$total_score = assetHealthIndex($_SESSION['profile'],$_SESSION['permission'],$equipment_data,0);
|
||||
$total_score = assetHealthIndex($_SESSION['authorization']['profile'],$_SESSION['authorization']['permission'],$equipment_data,0);
|
||||
|
||||
//GetPartnerDetails
|
||||
$partner_data = json_decode($responses->accounthierarchy);
|
||||
@@ -163,7 +163,7 @@ $view = '
|
||||
//------------------------------------
|
||||
//CHECK IF USER IS ALSO CREATOR OF RECORD THEN OVERRIDE UPDATE_ALLOWED_EDIT
|
||||
//------------------------------------
|
||||
$equipment_owner = (($responses->createdby == $_SESSION['username'])? 1 : 0);
|
||||
$equipment_owner = (($responses->createdby == $_SESSION['authorization']['clientID'])? 1 : 0);
|
||||
//------------------------------------
|
||||
//
|
||||
//------------------------------------
|
||||
@@ -369,7 +369,7 @@ if (!empty($responses->geolocation) || $responses->geolocation != ''){
|
||||
}
|
||||
|
||||
//Get all related service events
|
||||
if (isAllowed('servicereports',$_SESSION['profile'],$_SESSION['permission'],'R') === 1){
|
||||
if (isAllowed('servicereports',$_SESSION['authorization']['profile'],$_SESSION['authorization']['permission'],'R') === 1){
|
||||
$service_events = serviceEvents($history,$page);
|
||||
|
||||
$view .= '<div class="content-block">
|
||||
@@ -382,7 +382,7 @@ $view .= '<div class="content-block">
|
||||
}
|
||||
|
||||
//Show equipment_data when available and allowed
|
||||
if (isAllowed('equipment_data',$_SESSION['profile'],$_SESSION['permission'],'R') === 1 && !empty($equipment_data)){
|
||||
if (isAllowed('equipment_data',$_SESSION['authorization']['profile'],$_SESSION['authorization']['permission'],'R') === 1 && !empty($equipment_data)){
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-bars fa-sm"></i>'.($view_asset_data_text ?? '').'
|
||||
@@ -455,13 +455,13 @@ $shipto_id = explode("-",$partner_data->shipto) ?? '';
|
||||
$partner_users_id = ($shipto_id[0] != '')? $shipto_id[0] : (($soldto_id[0] != '')? $soldto_id[0] : 1);
|
||||
|
||||
$view_communication = '';
|
||||
if ($partner_users_id != 1 && ($_SESSION['permission'] == 3 || $_SESSION['permission'] == 4)){
|
||||
if ($partner_users_id != 1 && ($_SESSION['authorization']['permission'] == 3 || $_SESSION['authorization']['permission'] == 4)){
|
||||
$view_communication = ' <a href="index.php?page=communications&partnerid='.$partner_users_id.'" class="btn">'.$button_partner_assigned_communication.'</a>';
|
||||
}
|
||||
|
||||
//DISPLAY RELATED USERS
|
||||
$view_users ='';
|
||||
if ($partner_users_id != 1 && ($_SESSION['permission'] == 3 || $_SESSION['permission'] == 4)){
|
||||
if ($partner_users_id != 1 && ($_SESSION['authorization']['permission'] == 3 || $_SESSION['authorization']['permission'] == 4)){
|
||||
$view_users = ' <a href="index.php?page=users&partnerid='.$partner_users_id.'" class="btn">'.$button_partner_assigned_users.'</a>';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user