CIM69 - Car database

This commit is contained in:
“VeLiTi”
2024-04-23 17:09:31 +02:00
parent 5f89767faf
commit 0b4ba34ea5
12 changed files with 604 additions and 10 deletions

View File

@@ -324,5 +324,23 @@ case 'getfirmwareCommunication':
break;
case 'getCartest':
//FILTER FOR GROUPBY FILTERS on CAR
$filter1 = '"CarBrand": "';
$filter2 = '"CarType": "';
$filter3 = '"CarVIN": "';
//CONNECT TO DB
$pdo = dbConnect($dbname);
$sql = "SELECT * from history where type='cartest' group by SUBSTRING_INDEX(SUBSTRING_INDEX(description, '$filter1', -1),'$filter2',1), SUBSTRING_INDEX(SUBSTRING_INDEX(description, '$filter2', -1),'$filter3',1) ORDER BY description ASC";
$stmt = $pdo->prepare($sql);
$stmt->execute();
//Get results
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($result,JSON_UNESCAPED_UNICODE);
break;
}
// end switch

115
api/v1/get/cartests.php Normal file
View File

@@ -0,0 +1,115 @@
<?php
defined($security_key) or exit;
//------------------------------------------
// Products
//------------------------------------------
//Connect to DB
$pdo = dbConnect($dbname);
//NEW ARRAY
$criterias = [];
$whereclause = 'WHERE type="cartest"';
$clause = '';
//FILTER FOR GROUPBY FILTERS on CAR
$filter1 = '"CarBrand": "';
$filter2 = '"CarType": "';
$filter3 = '"CarVIN": "';
$car_brand = 'SUBSTRING_INDEX(SUBSTRING_INDEX(description, "'.$filter1.'", -1),"'.$filter2.'",1)';
$car_type = 'SUBSTRING_INDEX(SUBSTRING_INDEX(description, "'.$filter2.'", -1),"'.$filter3.'",1)';
//Check for $_GET variables and build up clause
if(isset($get_content) && $get_content!=''){
//GET VARIABLES FROM URL
$requests = explode("&", $get_content);
//Check for keys and values
foreach ($requests as $y){
$v = explode("=", $y);
//INCLUDE VARIABLES IN ARRAY
$criterias[$v[0]] = $v[1];
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list'|| $v[0] =='success_msg'){
//do nothing
}
elseif ($v[0] == 'search') {
//build up search
$clause .= ' AND '.$car_brand.' like :'.$v[0];
}
else {//create clause
$clause .= ' AND '.$v[0].' = :'.$v[0];
}
}
if ($whereclause == '' && $clause !=''){
$whereclause = 'WHERE '.substr($clause, 4);
} else {
$whereclause .= $clause;
}
}
//Define Query
if(isset($criterias['totals']) && $criterias['totals'] ==''){
//Request for total rows
$sql = 'SELECT count(*) as count FROM history '.$whereclause;
}
elseif(isset($criterias['list']) && $criterias['list'] ==''){
//Request for total rows
$sql = 'SELECT distinct('.$car_brand.') FROM history '.$whereclause;
}
else {
//SQL for Paging
$sql = "SELECT *, SUBSTRING_INDEX(SUBSTRING_INDEX(description, '$filter1', -1),'$filter2',1) as carbrand from history $whereclause group by SUBSTRING_INDEX(SUBSTRING_INDEX(description, '$filter1', -1),'$filter2',1), SUBSTRING_INDEX(SUBSTRING_INDEX(description, '$filter2', -1),'$filter3',1) ORDER BY carbrand DESC LIMIT :page,:num_products";
}
$stmt = $pdo->prepare($sql);
//Bind to query
if (str_contains($whereclause, ':condition')){
$stmt->bindValue('condition', $condition, PDO::PARAM_STR);
}
if (!empty($criterias)){
foreach ($criterias as $key => $value){
$key_condition = ':'.$key;
if (str_contains($whereclause, $key_condition)){
if ($key == 'search'){
$search_value = '%'.$value.'%';
$stmt->bindValue($key, $search_value, PDO::PARAM_STR);
}
else {
$stmt->bindValue($key, $value, PDO::PARAM_STR);
}
}
}
}
//Add paging details
if(isset($criterias['totals']) && $criterias['totals']==''){
$stmt->execute();
$messages = $stmt->fetch();
$messages = $messages[0];
}
elseif(isset($criterias['list']) && $criterias['list']==''){
//Excute Query
$stmt->execute();
//Get results
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
else {
$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
$stmt->bindValue('page', ($current_page - 1) * $page_rows_cartest, PDO::PARAM_INT);
$stmt->bindValue('num_products', $page_rows_cartest, PDO::PARAM_INT);
//Excute Query
$stmt->execute();
//Get results
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
//Encrypt results
$messages = generate_payload($messages);
//Send results
echo $messages;
?>

View File

@@ -109,7 +109,7 @@ if(isset($get_content) && $get_content!=''){
}
if (isset($criterias['download']) && $criterias['download'] ==''){
//Request for download
$sql = 'SELECT e.rowID as equipmentID, e.productrowid, e.serialnumber, e.status, e.created, e.hw_version, e.sw_version, e.accounthierarchy, e.service_date, e.warranty_date, p.productcode, p.productname from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY equipmentID';
$sql = 'SELECT e.rowID as equipmentID, e.*, p.productcode, p.productname from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY equipmentID';
}
elseif (isset($criterias['totals']) && $criterias['totals'] =='' && !isset($criterias['type'])){
//Request for total rows

View File

@@ -312,7 +312,7 @@ switch ($action) {
// --------------------------------------------
// Send generic account to user for software updates
// --------------------------------------------
if ($firmware_account_send == 2){
if ($firmware_account_send == 1){
include_once './assets/mail/email_template_software.php';
send_mail($post_content['email'],$subject,$message,'','');
}

View File

@@ -107,7 +107,7 @@ else {
foreach ($account as $key => $value){
if ($key != "section"){
//CHECK for id- pattern
if (preg_match('/\-.*/',$value)){
if (empty($value) ||$value == '' || preg_match('/\-.*/',$value)){
//Do Nothing
}
else {

View File

@@ -232,6 +232,7 @@ echo <<<EOT
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.0.0/css/all.css">
<script src="./assets/leaflet.js"></script>
<script src="./assets/charts.js"></script>
</head>
<body class="admin">
<aside class="responsive-width-100 responsive-hidden">

232
cartest.php Normal file
View File

@@ -0,0 +1,232 @@
<?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';
$page = 'cartest';
//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
//PAGE Security
$update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'U');
$delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'D');
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
//CALL TO API FOR cartest
$api_url = '/v1/cartests/rowID='.$_GET['rowID'];
$cartest = ioServer($api_url,'');
//Decode Payload
if (!empty($cartest)){$cartest = decode_payload($cartest);}else{$cartest = null;}
$cartest = $cartest[0];
//GET TEST DETAILS
$cartest_details = json_decode($cartest->description,true);
// Handle success messages
if (isset($_GET['success_msg'])) {
if ($_GET['success_msg'] == 1) {
$success_msg = $message_ct_1;
}
if ($_GET['success_msg'] == 2) {
$success_msg = $message_ct_2;
}
if ($_GET['success_msg'] == 3) {
$success_msg = $message_ct_3;
}
}
template_header('Cartest', 'cartest', 'view');
$view = '
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
<h2 class="responsive-width-100">'.$cartest_h2.' - '.$_GET['rowID'].'</h2>
<a href="index.php?page=cartests" class="btn alt mar-right-2">'.$button_cancel.'</a>
';
$view .= '</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-block-wrapper">';
$view .= ' <div class="content-block order-details">
<div class="block-header">
<i class="fa-solid fa-circle-info"></i></i>'.$cartest_information.'
</div>
<div class="order-detail">
<h3>'.$cartest_carbrand.'</h3>
<p>'.$cartest_details['CarBrand'].'</p>
</div>
<div class="order-detail">
<h3>'.$cartest_cartype.'</h3>
<p>'.$cartest_details['CarType'].'</p>
</div>
<div class="order-detail">
<h3>'.$cartest_carvin.'</h3>
<p>'.$cartest_details['CarVIN'].'</p>
</div>
</div>
';
$view .='<div class="content-block order-details">
<div class="block-header">
<i class="fa-solid fa-user fa-sm"></i>'.$cartest_details_text.'
</div>
<div class="order-detail">
<h3>'.$cartest_created.'</h3>
<p>'.$cartest->created.'</p>
</div>
<div class="order-detail">
<h3>'.$cartest_tester.'</h3>
<p>'.$cartest_details['NameTester'].'</p>
</div>
<div class="order-detail">
<h3>'.$cartest_device.'</h3>
<p>'.$cartest_details['SN'].'</p>
</div>
<div class="order-detail">
<h3>'.$cartest_device_hw.'</h3>
<p>'.$cartest_details['HW'].'</p>
</div>
<div class="order-detail">
<h3>'.$cartest_device_sw.'</h3>
<p>'.$cartest_details['FW'].'</p>
</div>
</div>';
$view .= '</div>';
$view .= '<div class="content-block">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>'.$cartest_questions.'
</div>
<div class="table order-table">
<table>';
//Retrieve questions and anwers
foreach ($cartest_details['Questions'] as $key => $value){
$view .= '<tr>
<td style="width:25%;">'.$key.'</td>
<td>'.((!empty($value)|| $value !='')?$value:$not_specified).'</td>
</tr>';
}
$view .= '
</table>
</div>
</div>
';
if (isset($cartest_details['plugDataPoints']) && $cartest_details['plugDataPoints'] !=''){
$view .= '<div class="content-block">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>'.$cartest_charts.'';
//CREATE ARRAYS FOR DATAPOINTS
$VCP = []; //for VCP values
$VPP1 = []; //for VPP1 values
$VPP2 = []; //for VPP2 values
$VBAT = []; //for VBAT values
$PWM = []; //for PWM values
$STATE= []; //for state values
$xaxis= []; //values for xaxis
$x = 0;
foreach ($cartest_details['plugDataPoints'] as $datapoint){
$VCP[] = $datapoint['vcp'];
$VPP1[] = $datapoint['vpp1'];
$VPP2[] = $datapoint['vpp2'];
$VBAT[] = $datapoint['vbat'];
$PWM[] = $datapoint['pwm'];
switch ($datapoint['state']) {
case 'FULL_CONNECT':
$STATE[] = 5;
break;
case 'REACTIVATE':
$STATE[] = 3;
break;
case 'DISCONNECTED':
$STATE[] = 0;
break;
}
//Add to x-axis
$xaxis[] = $x;
$x++;
}
$view.= '
<div>
<canvas id="chart_VCP" style="width:400px;max-width:800px"></canvas></div>
<p><small>STATE: 0 = DISCONNECTED, 3 = REACTIVATE, 5 = FULL_CONNECT</small></p>
<script>
const xValues = '.json_encode($xaxis).'; //xChart;
new Chart("chart_VCP", {
type: "line",
data: {
labels: xValues,
datasets: [{
label: "VCP",
data: '.json_encode($VCP).',
borderColor: "red",
fill: false
},
{
label: "VBAT",
data: '.json_encode($VBAT).',
borderColor: "black",
fill: false
},{
label: "VPP1",
data: '.json_encode($VPP1).',
borderColor: "green",
fill: false
}, {
label: "VPP2",
data: '.json_encode($VPP2).',
borderColor: "blue",
fill: false
},
{
label: "PWM",
data: '.json_encode($PWM).',
backgroundColor: "yellow",
fill: false
},
{
label: "STATE",
data: '.json_encode($STATE).',
backgroundColor: "purple",
fill: false
}
]
},
options: {
legend: {display: true}
}
});
</script>';
$view .= '</div></div>';
}
//OUTPUT
echo $view;
template_footer()
?>

166
cartests.php Normal file
View File

@@ -0,0 +1,166 @@
<?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';
$page = 'cartests';
//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
//PAGE Security
$update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'U');
$delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'D');
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
//GET PARAMETERS
$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
$car_brand = isset($_GET['car_brand']) ? '&car_brand='.$_GET['car_brand'] : '';
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
// Determine the URL
$url = 'index.php?page='.$page.$car_brand.$search;
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
//CALL TO API
$api_url = '/v1/cartests/'.$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/cartests/'.$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_ct_1;
}
if ($_GET['success_msg'] == 2) {
$success_msg = $message_ct_2;
}
if ($_GET['success_msg'] == 3) {
$success_msg = $message_ct_3;
}
}
template_header('Cartests', 'cartests' ,'view');
$view = '
<div class="content-title">
<div class="title">
<i class="fa-solid fa-box-open"></i>
<div class="txt">
<h2>'.$cartests_h2.' ('.$query_total.')</h2>
<p>'.$cartests_p.'</p>
</div>
</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 class="content-header responsive-flex-column pad-top-5">';
if ($create_allowed ===1){
$view .= '<a href="index.php?page=partner" class="btn">'.$button_create_cartest.'</a>';
}
$view .= '
<form action="" method="get">
<input type="hidden" name="page" value="partners">
<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>Active</option>
<option value="0">'.$disabled.'</option>
<option value="1">'.$enabled.'</option>
</select>
<button type="submit">'.$button_apply.'</button>
</div>
</div>
<div class="search">
<label for="search">
<input id="search" type="text" name="search" placeholder="'.$cartest_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">'.$cartest_rowID.'</th>
<th>'.$cartest_carbrand.'</th>
<th>'.$cartest_cartype.'</th>
<th>'.$general_actions.'</th>
</tr>
</thead>
<tbody>
';
if (empty($responses)){
$view .= '
<tr>
<td colspan="8" style="text-align:center;">'.$message_no_ct.'</td>
</tr>';
}
else {
foreach ($responses as $response){
//get cartest details
$cartest = json_decode($response->description,true);
$view .= '
<tr>
<td class="responsive-hidden">'.$response->rowID.'</td>
<td>'.$cartest['CarBrand'].'</td>
<td>'.$cartest['CarType'].'</td>
<td><a href="index.php?page=cartest&rowID='.$response->rowID.'" 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_cartest) == 0 ? 1 : ceil($query_total / $page_rows_cartest);
$view .= '<span> '.$general_page.$pagination_page.$general_page_of.$totals.'</span>';
if ($pagination_page * $page_rows_cartest < $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();
?>

View File

@@ -221,7 +221,7 @@ $view .= '
$changelog = showlog('equipment',$equipment_ID)?? '';
//GEOLOCATION
$geo_details = json_decode($equipment['geolocation']) ?? '';
$geo_details = (is_string($equipment['geolocation']))? json_decode($equipment['geolocation']) : '';
if (is_array($geo_details)) {
$geodetails_lat = $geo_details[0];
$geodetails_lon = $geo_details[1];

View File

@@ -70,10 +70,12 @@ if ($update_allowed === 1){
$output_excel[$val]['status'] = $_POST['status'];
$output_excel[$val]['salesid'] = $_POST['salesid'];
$output_excel[$val]['soldto'] = $_POST['soldto'];
if (!empty($_POST['shipto']) || $_POST['shipto'] !=''){
$output_excel[$val]['shipto'] = $_POST['shipto'];
}
if (!empty($_POST['location']) || $_POST['location'] !=''){
$output_excel[$val]['location'] = $_POST['location'];
$output_excel[$val]['section'] = '';
}
//Count total_rowID
$total_rowID++;
}

View File

@@ -20,6 +20,7 @@ $menu_language = 'Taal';
$menu_log = 'Log';
$menu_marketing = 'Marketing';
$menu_build = 'Build';
$menu_cartest = 'Auto database';
//TABS
$tab1 = 'Algemeen';
@@ -74,6 +75,7 @@ $button_partner_assigned_equipment = 'Gerelateerde activa';
$button_partner_assigned_contracts = 'Gerelateerde contracten';
$button_create_contract = 'Maak contract';
$button_create_communication_send = 'Firmware communicatie';
$button_create_cartest = 'Maak autotest';
//Account / Users
$account_h2 = 'Profiel';
@@ -637,3 +639,31 @@ $marketing_p = 'Marketing materiaal';
//Unscribe
$unscribe_msg1 = 'Email gedactiveerd';
$unscribe_msg_error = 'Er is iets mis gegaan, neem contact op met uw leverancier voor assistentie';
//Cartest
$cartests_h2 = 'Auto Database';
$cartests_p = 'Bekijk, update en zoek auto test.';
$cartest_h2 = 'Autotest';
$cartest_charts = 'Testgrafieken';
$message_ct_1 = 'Autotest aangemaakt!';
$message_ct_2 = 'Autotest aangepast!';
$message_ct_3 = 'Autotest verwijderd!';
$message_no_ct = 'Er zijn geen autotest';
$cartest_search = 'Zoek automerk ...';
$cartest_information = 'Autotest informatie';
$cartest_rowID = 'Test ID';
$cartest_carbrand = 'Automerk';
$cartest_cartype = 'Autotype';
$cartest_carvin = 'VIN';
$cartest_details_text = 'Test details';
$cartest_created = 'Datum';
$cartest_tester = 'Tester';
$cartest_device = 'Gebruikte activa';
$cartest_device_hw = 'Gebruikte hardware';
$cartest_device_sw = 'Gebruikte software';
$cartest_questions = 'Vraag & Antwoord';

View File

@@ -20,6 +20,7 @@ $menu_language = 'Language';
$menu_log = 'Log';
$menu_marketing = 'Marketing';
$menu_build = 'Build';
$menu_cartest = 'Car database';
//TABS
$tab1 = 'General';
@@ -74,6 +75,7 @@ $button_partner_assigned_equipment = 'Related assets';
$button_partner_assigned_contracts = 'Related contracts';
$button_create_contract = 'Create contract';
$button_create_communication_send = 'Firmware communication';
$button_create_cartest = 'Create cartest';
//Account / Users
$account_h2 = 'Account';
@@ -635,3 +637,31 @@ $marketing_p = 'Marketing catalog';
//Unscribe
$unscribe_msg1 = 'Email unsubscribed';
$unscribe_msg_error = 'Something went wrong, please contact your supplier for assistance';
//Cartest
$cartests_h2 = 'Car Database';
$cartests_p = 'View, manage, and search car details.';
$cartest_h2 = 'Cartest';
$cartest_charts = 'Testgraphs';
$message_ct_1 = 'Cartest created successfully!';
$message_ct_2 = 'Cartest updated successfully!';
$message_ct_3 = 'Cartest deleted successfully!';
$message_no_ct = 'There are no cartest';
$cartest_search = 'Search carbrand...';
$cartest_information = 'Cartest information';
$cartest_rowID = 'Test ID';
$cartest_carbrand = 'Carbrand';
$cartest_cartype = 'Cartype';
$cartest_carvin = 'VIN';
$cartest_details_text = 'Test details';
$cartest_created = 'Timestamp';
$cartest_tester = 'Tester';
$cartest_device = 'Used asset';
$cartest_device_hw = 'Used hardware';
$cartest_device_sw = 'Used software';
$cartest_questions = 'Question & answer';