Files
assetmgt/products_attributes.php
“VeLiTi” 24481279d5 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.
2026-01-19 15:29:16 +01:00

177 lines
6.4 KiB
PHP

<?php
defined(page_security_key) or exit;
if (debug && debug_id == $_SESSION['authorization']['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 ORIGIN FOR NAVIGATION
$prev_page = $_SESSION['prev_origin'] ?? '';
$page = $_SESSION['origin'] = 'products_attributes';
//Check if allowed
if (isAllowed($page,$_SESSION['authorization']['profile'],$_SESSION['authorization']['permission'],'R') === 0){
header('location: index.php');
exit;
}
//PAGE Security
$page_manage = 'products_attributes_manage';
$update_allowed = 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');
//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=products_attributes'.$status.$search;
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
//CALL TO API
$api_url = '/v2/products_attributes/'.$GET_VALUES;
$responses = ioServer($api_url,'');
//Decode Payload
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
//Return QueryTotal from API
$api_url = '/v2/products_attributes/'.$GET_VALUES.'&totals=';
$query_total = ioServer($api_url,'');
//Decode Payload
if (!empty($query_total)){$query_total = json_decode($query_total,true);}else{$query_total = null;}
// Handle success messages
if (isset($_GET['success_msg'])) {
if ($_GET['success_msg'] == 1) {
$success_msg = $message_patt_1;
}
if ($_GET['success_msg'] == 2) {
$success_msg = $message_patt_2;
}
if ($_GET['success_msg'] == 3) {
$success_msg = $message_patt_3;
}
}
template_header('Products attributes', 'products_attributes','view');
$view = '
<div class="content-title">
<div class="title">
<i class="fa-solid fa-box-open"></i>
<div class="txt">
<h2>'.($products_attributes_h2 ?? 'Product Attributes').' ('.$query_total.')</h2>
<p>'.($products_attributes_p ?? '').'</p>
</div>
</div>
<div class="title-actions">';
if ($create_allowed === 1){
$view .= '<a href="index.php?page=products_attributes_manage" 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="products_attributes">
<div class="filter-row">
<div class="filter-group search-group">
<input type="text" name="search" placeholder="'.($products_attribute_search ?? 'Search attributes...').'" 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=products_attributes">X</a>
</div>
</form>
</div>
</div>
';
$view .= '
<div class="content-block">
<div class="table">
<table class="sortable">
<thead>
<tr>
<th>'.($products_attribute_rowID ?? '#').'</th>
<th>'.($products_attribute_group_status ?? 'status').'</th>
<th>'.($products_attribute_group_name ?? 'name').'</th>
<th>'.($products_attribute_group_name_internal ?? 'Internal name').'</th>
<th>'.($products_attribute_group_type ?? 'type').'</th>
<th class="responsive-hidden">'.$general_created.'</th>
</tr>
</thead>
<tbody>
';
if (empty($responses)){
$view .= '
<tr>
<td colspan="8" style="text-align:center;">'.($message_no_products_attributes ?? '').'</td>
</tr>';
}
else {
foreach ($responses as $response){
$view .= '
<tr onclick="window.location.href=\'index.php?page=products_attributes_manage&rowID='.$response['rowID'].'\'" style="cursor: pointer;">
<td>'.$response['group_id'].'</td>
<td>'.${'general_status_'.$response['group_status']}.'</td>
<td>'.(${$response['group_name']} ?? $response['group_name']).'</td>
<td>'.(${$response['group_name_internal']} ?? $response['group_name_internal']).'</td>
<td>'.(${'general_form_'.$response['group_type']} ?? $response['group_type'] ).'</td>
<td class="responsive-hidden">'.getRelativeTime($response['created']).'</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_products_attributes) == 0 ? 1 : ceil($query_total / $page_rows_products_attributes);
$view .= '<span> '.$general_page.$pagination_page.$general_page_of.$totals.'</span>';
if ($pagination_page * $page_rows_products_attributes < $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();
?>