CIM69 - car database
This commit is contained in:
@@ -9,6 +9,7 @@ if (debug && debug_id == $_SESSION['id']){
|
||||
|
||||
include_once './assets/functions.php';
|
||||
include_once './settings/settings.php';
|
||||
include_once './settings/systemcartest.php';
|
||||
|
||||
$page = 'cartest_manage';
|
||||
//Check if allowed
|
||||
@@ -23,34 +24,232 @@ $create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],
|
||||
|
||||
$bearertoken = createCommunicationToken($_SESSION['userkey']);
|
||||
|
||||
//GET PRODUCTS FROM DB
|
||||
$pdo = dbConnect($dbname);
|
||||
$sql = 'SELECT rowID, productcode, productname, product_category,sn from products where status = "1" and build = "1"';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
//Excute Query
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$rowID = $_GET['rowID'] ?? '';
|
||||
|
||||
template_header('Buildtool', 'buildtool','view');
|
||||
if ($rowID !=''){
|
||||
$url = 'index.php?page=cartest&rowID='.$rowID.'';
|
||||
} else {
|
||||
$url = 'index.php?page=cartests';
|
||||
}
|
||||
|
||||
$view = '
|
||||
<div class="content-title">
|
||||
<div class="title">
|
||||
<i class="fa-solid fa-box-open"></i>
|
||||
<div class="txt">
|
||||
<h2>'.$buildtool_h2 .'</h2>
|
||||
<p>'.$buildtool_p.'</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
// Default input product values
|
||||
$cartest = [
|
||||
'rowID' => '',
|
||||
'carbrand' => '',
|
||||
'cartype' => '',
|
||||
'header' => [
|
||||
'CarVIN' => '',
|
||||
'NameTester'=> $_SESSION['username'],
|
||||
'SN' =>'',
|
||||
'HW' =>'',
|
||||
'FW' =>''
|
||||
],
|
||||
'questions' => [],
|
||||
'datapoints' => [],
|
||||
'created' => ''
|
||||
];
|
||||
|
||||
$view .= '
|
||||
<div class="content-header responsive-flex-column pad-top-5">
|
||||
<a href="index.php?page=dashboard" class="btn">'.$button_cancel.'</a>
|
||||
</div>
|
||||
if (isset($_GET['rowID'])) {
|
||||
// ID param exists, edit an existing product
|
||||
//CALL TO API
|
||||
$api_url = '/v1/cartests/rowID='.$_GET['rowID'];
|
||||
$responses = ioServer($api_url,'');
|
||||
//Decode Payload
|
||||
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;}
|
||||
|
||||
$cartest = json_decode(json_encode($responses[0]), true);
|
||||
|
||||
$cartest['header'] = (is_string($cartest['header']))? json_decode($cartest['header'],true) : '';
|
||||
$cartest['questions'] = (is_string($cartest['questions']))? json_decode($cartest['questions'],true) : '';
|
||||
$cartest['datapoints'] = (is_string($cartest['datapoints']))? json_decode($cartest['datapoints'],true) : '';
|
||||
|
||||
if ($update_allowed === 1){
|
||||
if (isset($_POST['submit'])) {
|
||||
//ARRAY convert to JSON
|
||||
$_POST['header'] = json_encode($_POST['header'], JSON_UNESCAPED_UNICODE);
|
||||
$_POST['questions'] = json_encode($_POST['questions'], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//CHECK IF DATAPOINTS IS NOT EMPTY THEN UPDATE IF NOT REMOVE EMPTY ARRAY FROM POST
|
||||
if (!empty($_POST['datapoints']) || $_POST['datapoints'] !="") {
|
||||
$_POST['datapoints'] = json_encode($_POST['datapoints'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
else {
|
||||
unset($_POST['datapoints']);
|
||||
}
|
||||
|
||||
//GET ALL POST DATA
|
||||
$data = json_encode($_POST, JSON_UNESCAPED_UNICODE);
|
||||
//Secure data
|
||||
$payload = generate_payload($data);
|
||||
//API call
|
||||
$responses = ioServer('/v1/cartests', $payload);
|
||||
if ($responses === 'NOK'){
|
||||
|
||||
} else {
|
||||
header('Location: index.php?page=cartest&rowID='.$_GET['rowID'].'&success_msg=2');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($delete_allowed === 1){
|
||||
if (isset($_POST['delete'])) {
|
||||
//GET ALL POST DATA
|
||||
$data = json_encode($_POST , JSON_UNESCAPED_UNICODE);
|
||||
//Secure data
|
||||
$payload = generate_payload($data);
|
||||
//API call
|
||||
$responses = ioServer('/v1/cartests', $payload);
|
||||
// Redirect and delete equipment
|
||||
if ($responses === 'NOK'){
|
||||
|
||||
} else {
|
||||
header('Location: index.php?page=cartests&success_msg=3');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Create a new equipment
|
||||
if (isset($_POST['submit'])) {
|
||||
//ARRAY convert to JSON
|
||||
$_POST['header'] = json_encode($_POST['header'], JSON_UNESCAPED_UNICODE);
|
||||
$_POST['questions'] = json_encode($_POST['questions'], JSON_UNESCAPED_UNICODE);
|
||||
$_POST['datapoints'] = json_encode($_POST['datapoints'], JSON_UNESCAPED_UNICODE);
|
||||
//GET ALL POST DATA
|
||||
$data = json_encode($_POST, JSON_UNESCAPED_UNICODE);
|
||||
//Secure data
|
||||
$payload = generate_payload($data);
|
||||
//API call
|
||||
$responses = ioServer('/v1/cartests', $payload);
|
||||
if ($responses === 'NOK'){
|
||||
|
||||
} else {
|
||||
header('Location: index.php?page=cartests&success_msg=1');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template_header('Cartesttool', 'cartesttool','manage');
|
||||
|
||||
$view ='
|
||||
<form action="" method="post">
|
||||
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
||||
<h2 class="responsive-width-100"><?=$page?>'.$cartest_h2.'</h2>
|
||||
<a href="'.$url .'" class="btn alt mar-right-2">'.$button_cancel.'</a>
|
||||
';
|
||||
|
||||
if ($delete_allowed === 1){
|
||||
$view .= '<input type="submit" name="delete" value="Delete" class="btn red mar-right-2" onclick="return confirm(\'Are you sure you want to delete this cartest?\')">';
|
||||
}
|
||||
if ($update_allowed === 1){
|
||||
$view .= '<input type="submit" name="submit" value="Save" class="btn">';
|
||||
}
|
||||
|
||||
$view .= '</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><input type="text" name="carbrand" value="'.$cartest['carbrand'].'">
|
||||
<input type="hidden" name="rowID" value="'.$rowID.'">
|
||||
</p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$cartest_cartype.'</h3>
|
||||
<p><input type="text" name="cartype" value="'.$cartest['cartype'].'"></p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$cartest_carvin.'</h3>
|
||||
<p><input type="text" name="header[CarVIN]" value="'.$cartest['header']['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><input type="text" name="header[NameTester]" value="'.$cartest['header']['NameTester'].'"></p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$cartest_device.'</h3>
|
||||
<p><input type="text" name="header[SN]" value="'.$cartest['header']['SN'].'"></p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$cartest_device_hw.'</h3>
|
||||
<p><input type="text" name="header[HW]" value="'.$cartest['header']['HW'].'"></p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$cartest_device_sw.'</h3>
|
||||
<p><input type="text" name="header[FW]" value="'.$cartest['header']['FW'].'"></p>
|
||||
</div>
|
||||
</div>';
|
||||
$view .= '</div>';
|
||||
// -------------------------------
|
||||
//BUILD TO INPUT FORM BASED ON ARRAY
|
||||
// ------------------------------
|
||||
|
||||
$view .= '<div class="tabs">';
|
||||
foreach($arrayQuestions_cartest as $group){
|
||||
|
||||
if ($group['Group_sequence'] == 1){
|
||||
$view .= '<a href="#" class="active">'.$group['Group'].'</a>';
|
||||
} else {
|
||||
$view .= '<a href="#">'.$group['Group'].'</a>';
|
||||
}
|
||||
}
|
||||
$view .= '</div>';
|
||||
|
||||
foreach($arrayQuestions_cartest as $group){
|
||||
|
||||
if ($group['Group_sequence'] == 1){
|
||||
$view .= '<div class="content-block tab-content active">
|
||||
<div class="form responsive-width-100">';
|
||||
} else {
|
||||
$view .= '<div class="content-block tab-content">
|
||||
<div class="form responsive-width-100">';
|
||||
}
|
||||
|
||||
foreach($group['Questions_in_group'] as $question){
|
||||
|
||||
switch ($question['Type']) {
|
||||
case 'dropdown':
|
||||
$view .= '<label for="" id="'.$question['QuestionID'].'">'.$question['Question'].'</label>';
|
||||
$view .= '<select id="" name="questions['.$question['QuestionID'].']" required>';
|
||||
$view .= '<option value=>'.$cartest_allowed_label0.'</option>';
|
||||
foreach ($question['Response'] as $response){
|
||||
$view .= '<option value="'.$response['responseID'].'" '.((isset($cartest['questions'][$question['QuestionID']]) && $cartest['questions'][$question['QuestionID']] == $response['responseID'])? 'selected':'').'>'.$response['Response'].'</option>';
|
||||
}
|
||||
$view .= '</select>';
|
||||
break;
|
||||
|
||||
case 'textarea':
|
||||
$view .= '<label for="" id="'.$question['QuestionID'].']">'.$question['Question'].'</label>';
|
||||
$view .= '<textarea id="QuestionID" name="questions['.$question['QuestionID'].']" placeholder="">'.(isset($cartest['questions'][$question['QuestionID']])?$cartest['questions'][$question['QuestionID']]:'').'</textarea>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
$view .= ' </div>
|
||||
</div>';
|
||||
}
|
||||
//CAPTURE DATA FROM PLUG
|
||||
|
||||
$view .= '<input id="plug_data" type="hidden" name="datapoints" value="">';
|
||||
|
||||
$view .= '</form>';
|
||||
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-bars fa-sm"></i><span id="time">25:00</span>
|
||||
@@ -60,7 +259,7 @@ $view .= '<div class="content-block">
|
||||
<div id="connectdevice" style="display:flex;">
|
||||
<div>
|
||||
<button class="btn" style="margin-right:10px;" onclick="connectSerial();startGraph()">Connect</button>
|
||||
<button class="btn" id="clear" onclick="closePort()" style="">X</button>
|
||||
<button class="btn" id="clear" onclick="closePortCarTest()" style="">X</button>
|
||||
<button class="btn" onClick="window.location.reload()">↺</button>
|
||||
</div>
|
||||
<div id="readStatus" style="width: 75%;background-color: #f1f1f1;">
|
||||
|
||||
Reference in New Issue
Block a user