Files
assetmgt/orders.php
“VeLiTi” 18469fe958 Refactor authorization checks to use 'permissions' instead of 'profile' in multiple files
- Updated authorization checks in product management, product attributes, configurations, software, and user management files to use 'permissions' for consistency.
- Ensured that all relevant pages correctly check user permissions for read, update, delete, and create actions.
- Adjusted session variable references to align with the new permissions structure across various modules.
2026-01-20 15:00:00 +01:00

178 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'] = 'orders';
//Check if allowed
if (isAllowed($page,$_SESSION['authorization']['permissions'],$_SESSION['authorization']['permission'],'R') === 0){
header('location: index.php');
exit;
}
//PAGE Security
$page_manage = 'order';
$update_allowed = isAllowed($page_manage ,$_SESSION['authorization']['permissions'],$_SESSION['authorization']['permission'],'U');
$delete_allowed = isAllowed($page_manage ,$_SESSION['authorization']['permissions'],$_SESSION['authorization']['permission'],'D');
$create_allowed = isAllowed($page_manage ,$_SESSION['authorization']['permissions'],$_SESSION['authorization']['permission'],'C');
//GET PARAMETERS
$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
// Determine the URL
$url = 'index.php?page=orders'.$search;
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
//CALL TO API
$api_url = '/v2/transactions/'.$GET_VALUES;
$orders = ioServer($api_url,'');
//Decode Payload
if (!empty($orders)){$orders = json_decode($orders,true);}else{$orders = null;}
//Return QueryTotal from API
$api_url = '/v2/transactions/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_orders_1 ?? 'Created';
}
if ($_GET['success_msg'] == 2) {
$success_msg = $message_orders_2 ?? 'Updated';
}
if ($_GET['success_msg'] == 3) {
$success_msg = $message_orders_3 ?? 'Deleted' ;
}
}
template_header('orders', 'orders','view');
$view = '
<div class="content-title">
<div class="title">
<i class="fa-solid fa-truck-fast"></i>
<div class="txt">
<h2>'.($orders_h2 ?? 'orders').' ('.$query_total.')</h2>
<p>'.($orders_p ?? '').'</p>
</div>
</div>
<div class="title-actions">';
if ($create_allowed === 1){
$view .= '<a href="index.php?page=orders_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="orders">
<div class="filter-row">
<div class="filter-group search-group">
<input type="text" name="search" placeholder="'.($orders_search ?? 'Search orders...').'" 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=orders">'.$general_filters_clear.'</a>
</div>
</form>
</div>
</div>
';
$view .= '
<div class="content-block">
<div class="table">
<table>
<thead>
<tr>
<td>'.($orders_id ?? '#').'</td>
<td>'.($orders_customer ?? 'name').'</td>
<td>'.($orders_payment_amount ?? 'Total').'</td>
<td class="responsive-hidden">'.($orders_method ?? 'Method').'</td>
<td class="responsive-hidden">'.($orders_status ?? 'Status').'</td>
<td class="responsive-hidden">'.($orders_created ?? 'Created').'</td>
</tr>
</thead>
<tbody>';
if (empty($orders)){
$view .= '<tr>
<td colspan="8" style="text-align:center;">'.($message_no_orders ?? 'There are no orders').'</td>
</tr>';
}
else {
foreach ($orders as $order){
//Translate status INT to STR
$payment_status = 'payment_status_'.$order['payment_status'];
$payment_method = 'payment_method_'.$order['payment_method'];
$view .= '
<tr onclick="window.location.href=\'index.php?page=order&id='.$order['id'].'\'" style="cursor: pointer;">
<td>'.$order['id'].'</td>
<td>'.$order['first_name'].' '.$order['last_name'].'</td>
<td>'.number_format($order['payment_amount'], 2).'</td>
<td class="responsive-hidden">'.(${$payment_method} ?? $order['payment_method']).'</td>
<td class="responsive-hidden">'.(${$payment_status} ?? $order['payment_status']).'</td>
<td class="responsive-hidden">'.getRelativeTime($order['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_transactions) == 0 ? 1 : ceil($query_total / $page_rows_transactions);
$view .= '<span> '.$general_page.$pagination_page.$general_page_of.$totals.'</span>';
if ($pagination_page * $page_rows_transactions < $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();
?>