- 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.
203 lines
7.3 KiB
PHP
203 lines
7.3 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 PAGE ORIGIN FOR NAVIGATION AND SECURITY
|
|
$page = $_SESSION['origin'] = 'contracts';
|
|
$prev_page = ($_SESSION['origin'] == 'equipments') ? $_SESSION['prev_origin_equipment'] : (($_SESSION['origin'] == 'account')? $_SESSION['prev_origin'] :'');
|
|
|
|
//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['authorization']['profile'],$_SESSION['authorization']['permission'],'R') === 0){
|
|
header('location: index.php');
|
|
exit;
|
|
}
|
|
//PAGE Security
|
|
$page_manage = 'contract_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');
|
|
|
|
//Close Contracts when end_date expired
|
|
closeContract();
|
|
|
|
//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=contracts'.$status.$search;
|
|
//GET Details from URL
|
|
$GET_VALUES = urlGETdetails($_GET) ?? '';
|
|
//CALL TO API
|
|
$api_url = '/v1/contracts/'.$GET_VALUES;
|
|
$responses = ioServer($api_url,'');
|
|
//Decode Payload
|
|
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;}
|
|
//Return QueryTotal from API
|
|
$api_url = '/v1/contracts/'.$GET_VALUES.'&totals=';
|
|
$query_total = ioServer($api_url,'');
|
|
//Decode Payload
|
|
if (!empty($query_total)){$query_total = decode_payload($query_total);}else{$query_total = null;}
|
|
|
|
// Handle success messages
|
|
if (isset($_GET['success_msg'])) {
|
|
if ($_GET['success_msg'] == 1) {
|
|
$success_msg = $message_contract_1;
|
|
}
|
|
if ($_GET['success_msg'] == 2) {
|
|
$success_msg = $message_contract_2;
|
|
}
|
|
if ($_GET['success_msg'] == 3) {
|
|
$success_msg = $message_contract_3;
|
|
}
|
|
}
|
|
|
|
template_header('contracts', 'contracts','view');
|
|
$view = '
|
|
<div class="content-title">
|
|
<div class="title">
|
|
<i class="fa-solid fa-box-open"></i>
|
|
<div class="txt">
|
|
<h2>'.$contract_h2.' ('.$query_total.')</h2>
|
|
<p>'.$contract_p .'</p>
|
|
</div>
|
|
</div>
|
|
<div class="title-actions">
|
|
'.$back_btn_orgin;
|
|
|
|
if ($create_allowed === 1){
|
|
$view .= '<a href="index.php?page=contract_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="contracts">
|
|
<div class="filter-row">
|
|
<div class="filter-group">
|
|
<select name="status">
|
|
<option value="" disabled selected>'.$contract_status.'</option>
|
|
<option value="0">'.$contract_status0.'</option>
|
|
<option value="1">'.$contract_status1.'</option>
|
|
<option value="2">'.$contract_status2.'</option>
|
|
<option value="3">'.$contract_status3.'</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="filter-group search-group">
|
|
<input type="text" name="search" placeholder="'.$contract_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=contracts">'.$general_filters_clear.'</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
';
|
|
|
|
$view .= '
|
|
<div class="content-block">
|
|
<div class="table">
|
|
<table class="sortable">
|
|
<thead>
|
|
<tr>
|
|
<th>'.$contract_id.'</th>
|
|
<th>'.$contract_status.'</th>
|
|
<th>'.$contract_account.'</th>
|
|
<th>'.$contract_type.'</th>
|
|
<th>'.$contract_start_date.'</th>
|
|
<th>'.$contract_end_date.'</th>
|
|
<th>'.$contract_reference.'</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
';
|
|
|
|
if (empty($responses)){
|
|
|
|
$view .= '
|
|
<tr>
|
|
<td colspan="8" style="text-align:center;">'.$message_no_contract.'</td>
|
|
</tr>';
|
|
}
|
|
else {
|
|
foreach ($responses as $response){
|
|
//Variable translation
|
|
$status = 'contract_status' . $response->status;
|
|
$type = 'contract_type'.$response->type;
|
|
//calculate enddate from duration
|
|
$date = date('Y-m-d', strtotime('+'.$response->duration.' months', strtotime($response->start_date)));
|
|
|
|
//GetPartnerDetails
|
|
$partner_data = json_decode($response->accounthierarchy);
|
|
|
|
$view .= '
|
|
<tr onclick="window.location.href=\'index.php?page=contract&rowID='.$response->rowID.'\'" style="cursor: pointer;">
|
|
<td>'.$response->rowID.'</td>
|
|
<td>'.(($response->status == 1)? '<span class="status enabled">'.$$status: (($response->status == 3) ? '<span class="status disabled">'.$$status : '<span class="status">'.$$status)).'</td>
|
|
<td>'.$partner_data->soldto.'</td>
|
|
<td>'.$$type.'</td>
|
|
<td>'.$response->start_date.'</td>
|
|
<td>'.$date.'</td>
|
|
<td>'.$response->reference.'</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_contracts) == 0 ? 1 : ceil($query_total / $page_rows_contracts);
|
|
$view .= '<span> '.$general_page.$pagination_page.$general_page_of.$totals.'</span>';
|
|
if ($pagination_page * $page_rows_contracts < $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();
|
|
?>
|