Files
assetmgt/equipments.php
2025-03-13 12:07:18 +01:00

285 lines
12 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.php';
//SET PAGE ORIGIN FOR NAVIGATION AND SECURITY
$prev_page = $_SESSION['prev_origin'] ?? '';
$page = $_SESSION['origin'] = 'equipments';
//create backbutton to prev_origin
$back_btn_orgin = ($prev_page != '')? '<a href="'.$prev_page.'" class="btn alt mar-right-2">'.$button_back.'</a>':'';
//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
//PAGE Security
$page_manage = 'equipment_manage';
$update_allowed = 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');
//GET PARAMETERS && STORE in SESSION for FURTHER USE/NAVIGATION
$pagination_page = $_SESSION['p'] = isset($_GET['p']) ? $_GET['p'] : 1;
$status = $_SESSION['status'] = isset($_GET['status']) ? '&status='.$_GET['status'] : '';
$sort = $_SESSION['sort'] = isset($_GET['sort']) ? '&sort='.$_GET['sort'] : '';
$search = $_SESSION['search'] = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
$software = $_SESSION['firmware'] = isset($_GET['firmware']) ? '&firmware='.$_GET['firmware'] : '';
$servicedate = $_SESSION['servicedate'] = isset($_GET['servicedate']) ? '&servicedate='.$_GET['servicedate'] : '';
$warrantydate = $_SESSION['warrantydate'] = isset($_GET['warrantydate']) ? '&warrantydate='.$_GET['warrantydate'] : '';
$partnerid = $_SESSION['partnerid'] = isset($_GET['partnerid']) ? '&partnerid='.$_GET['partnerid'] : '';
$productselected = $_SESSION['productcode'] = isset($_GET['productcode']) ? '&productcode='.$_GET['productcode'] : '';
$serialnumber_input = $_SESSION['serialnumber'] = isset($_GET['serialnumber']) ? '&serialnumber='.$_GET['serialnumber'] : '';
//GET PARAMETERS FOR FILTERS
$filter = urlGETdetailsFilter($_GET) ?? '';
// Determine the URL
$url = 'index.php?page=equipments'.$status.$search.$software.$servicedate.$warrantydate.$partnerid.$sort.$productselected.$serialnumber_input;
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
//CALL TO API
$api_url = '/v1/equipments/'.$GET_VALUES;
$responses = ioServer($api_url,'');
//Decode Payload
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;}
//Return QueryTotal from API
$total_url = ((!empty($GET_VALUES) && $GET_VALUES !='') ? '&totals=' : 'totals=' );
$api_url = '/v1/equipments/'.$GET_VALUES.$total_url;
$query_total = ioServer($api_url,'');
//Decode Payload
if (!empty($query_total)){$query_total = decode_payload($query_total);}else{$query_total = null;}
//Get Products related to assets
$product_url = ((!empty($GET_VALUES) && $GET_VALUES !='') ? '&products=' : 'products=' );
$api_url = '/v1/equipments/'.$GET_VALUES.$product_url;
$query_products = ioServer($api_url,'');
//Decode Payload
if (!empty($query_products)){$query_products = decode_payload($query_products);}else{$query_products = null;}
//BUILD LIST OF PRODUCTS
$product_list = '';
if ($query_products != null){
$product_list = '
<select name="productcode">
<option value="" disabled selected>'.$equipment_label4.'</option>';
foreach ($query_products as $product){
$product_list .= '<option value="'.$product->productcode.'">'.(${$product->productname} ?? $product->productname).'</option>';
}
$product_list .= '</select>';
}
//CALL TO API
$api_url = '/v2/media/';
$media_responses = ioServer($api_url,'');
//Decode Payload
if (!empty($media_responses)){$media_responses = json_decode($media_responses,true);}else{$media_responses = null;}
// Handle success messages
if (isset($_GET['success_msg'])) {
if ($_GET['success_msg'] == 1) {
$success_msg = $message_eq_1;
}
if ($_GET['success_msg'] == 2) {
$success_msg = $message_eq_2;
}
if ($_GET['success_msg'] == 3) {
$success_msg = $message_eq_3;
}
}
if (isset($_GET['download'])){
downloadToExcel('equipment',$responses);
}
template_header('Assets', 'assets','view');
$view = '
<div class="content-title">
<div class="title">
<i class="fa-solid fa-database"></i>
<div class="txt">
<h2>'.$assets_h2.' ('.$query_total.')</h2>
<p>'.$assets_p.' </p>
</div>
</div>
'.$back_btn_orgin.'
</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 class="content-header responsive-flex-column pad-top-5">';
if ($create_allowed ===1){
$view .= '<a href="index.php?page=equipment_manage" class="btn">'.$button_create_asset.'</a>';
}
$view .= '
<form action="" method="get">
'.$filter.'
<div class="filters">
<a href="#"><i class="fa-solid fa-filter"></i>'.$general_filters.'</a>
<div class="list">
<select name="status">
<option value="" disabled selected>'.$equipment_label3.'</option>
<option value="0"'.($status==0?' selected':'').'>'.$status0_text.'</option>
<option value="1"'.($status==1?' selected':'').'>'.$status1_text.'</option>
<option value="2"'.($status==2?' selected':'').'>'.$status2_text.'</option>
<option value="3"'.($status==3?' selected':'').'>'.$status3_text.'</option>
<option value="4"'.($status==4?' selected':'').'>'.$status4_text.'</option>
<option value="5"'.($status==5?' selected':'').'>'.$status5_text.'</option>
</select>
'.$product_list.'
<button type="submit">'.$button_apply.'</button>
<a class="cancel_link" style="color: #FFFFFF;text-decoration: none;" href="index.php?page=equipments">'.$general_filters_clear.'</a>
</div>
</div>
<div class="sort">
<a href="#"><i class="fa-solid fa-sort"></i>'.$general_sort.'</a>
<div class="list">
<select name="sort">
<option value="" disabled selected>'.$general_sort.'</option>
<option value="1"'.($sort==1?' selected':'').'>'.$equipment_label2.' '.$general_sort_type_1.'</option>
<option value="2"'.($sort==2?' selected':'').'>'.$equipment_label2.' '.$general_sort_type_2.'</option>
<option value="3"'.($sort==3?' selected':'').'>'.$equipment_label3.' '.$general_sort_type_1.'</option>
<option value="4"'.($sort==4?' selected':'').'>'.$equipment_label3.' '.$general_sort_type_2.'</option>
<option value="5"'.($sort==5?' selected':'').'>'.$warranty_status.' '.$general_sort_type_1.'</option>
<option value="6"'.($sort==6?' selected':'').'>'.$warranty_status.' '.$general_sort_type_2.'</option>
<option value="7"'.($sort==7?' selected':'').'>'.$service_status.' '.$general_sort_type_1.'</option>
<option value="8"'.($sort==8?' selected':'').'>'.$service_status.' '.$general_sort_type_2.'</option>
<option value="9"'.($sort==9?' selected':'').'>'.$general_sort_type_3.'</option>
<option value="10"'.($sort==10?' selected':'').'>'.$general_sort_type_4.'</option>
</select>
<button type="submit">'.$button_apply.'</button>
</div>
</div>';
//SHOW DOWNLOAD TO EXCELL OPTION ONLY TO ADMIN USERS
if ($_SESSION['permission'] == 3 || $_SESSION['permission'] == 4){
$view .='<div class="filters">
<a href="index.php?page=equipments&download="><i class="fa-solid fa-download"></i></a>
</div>';
}
$view .= '<div class="search">
<label for="search">
<input id="search" type="text" name="search" placeholder="'.$equiment_search.'" value="" class="responsive-width-100">
<i class="fas fa-search"></i>
</label>
</div>
</form>
</div>
';
$view .= '
<div class="content-block">
<div class="table">
<table class="sortable">
<thead>
<tr>
<th class="responsive-hidden">'.$equipment_label1.'</th>
<th>'.$equipment_label2.'</th>
<th>'.$equipment_label3.'</th>
<th>'.$equipment_label4.'</th>
<th class="responsive-hidden"></th>
<th class="responsive-hidden">'.$general_location.'</th>
<th class="responsive-hidden">'.$general_section.'</th>
<th>'.$view_asset_actions.'</th>
</tr>
</thead>
<tbody>
';
if (empty($responses)){
$view .= '
<tr>
<td colspan="8" style="text-align:center;">'.$message_no_assets.'</td>
</tr>';
}
foreach ($responses as $response){
//Translate status INT to STR
$status_text = 'status'.$response->status.'_text';
//GetPartnerDetails
$partner_data = json_decode($response->accounthierarchy);
//Default location
$location = getPartnerName($partner_data->location) ?? $not_specified;
//Check if productcode is 0 and status
if ($response->productcode == 0 && $response->status == 0) {$location = $product_location_raw;}
if ($response->productcode == 0 && $response->status == 1) {$location = $product_location_SFG;}
if ($response->productcode == 0 && $response->status == 2) {$location = $product_location_FG;}
//Check for Section
if (isset($partner_data->section)){$section = getPartnerName($partner_data->section) ?? $not_specified;} else {$section = $not_specified;}
//GET PATH OF ASSIGNED MEDIA
$full_path = '';
foreach ($media_responses as $media){
if($response->product_media == $media['rowID']){
$full_path = $media['full_path'];
}
}
$indicators = overviewIndicators($response->warranty_date,$response->service_date,$response->sw_version, $response->sw_version_latest);
$view .= '<tr>
<td class="responsive-hidden">'.$indicators.'</td>
<td>'.$response->serialnumber.'</td>
<td><span class="status id'.$response->status.'">'.$$status_text.'</span></td>
<td>'.$response->productcode.'-'.(${$response->productname} ?? $response->productname).'</td>
<td class="responsive-hidden">'.(($full_path !='')?'<img style="border-radius: 4px;height: 50px;" src="'.$full_path.'" alt="">' : '').'</td>
<td class="responsive-hidden">'.$location.'</td>
<td class="responsive-hidden">'.$section.'</td>
<td><a href="index.php?page=equipment&equipmentID='.$response->equipmentID.'" class="btn_link">'.$general_view .'</a></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_equipment) == 0 ? 1 : ceil($query_total / $page_rows_equipment);
$view .= '<span> '.$general_page.$pagination_page.$general_page_of.$totals.'</span>';
if ($pagination_page * $page_rows_equipment < $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();
?>