diff --git a/api/v0/get/application.php b/api/v0/get/application.php index d1da30e..ada4860 100644 --- a/api/v0/get/application.php +++ b/api/v0/get/application.php @@ -198,7 +198,12 @@ case 'getQuestions': case 'final': $arrayQuestions = $arrayQuestions_finalize; break; - } + + case 'cartest': + include './settings/systemcartest.php'; + $arrayQuestions = $arrayQuestions_cartest; + break; + } //Return JSON echo json_encode($arrayQuestions); } diff --git a/api/v0/post/application.php b/api/v0/post/application.php index ab38242..0fb0adb 100644 --- a/api/v0/post/application.php +++ b/api/v0/post/application.php @@ -53,7 +53,7 @@ if (!empty($post_content['sn']) && !empty($post_content['testdetails'])) { $historyUpdate_type = 0; //update type of history $updateObject_visual = 0; //update visual inspection object $sendServiceReport = 0; //send service report via email - + $transfercartest = 0; //Update cartest table with incoming data // +++++++++++++++++++++++++++++++++++++++++++++++++++++++ //SET DEFAULT PARAMETERS // +++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -154,6 +154,7 @@ if (!empty($post_content['sn']) && !empty($post_content['testdetails'])) { case 11: //car_test $historytype = 'CarTest'; $equipmentCreate = 1; + $transfercartest = 1; break; case 'firmware': //update from Portal @@ -341,7 +342,13 @@ if (!empty($post_content['sn']) && !empty($post_content['testdetails'])) { $servicereport = serviceReport($result, 'email'); generatedPDF($servicereport,$last_id,$useremail); } - } + } + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++ + // transfer to cartest table ++++++++++++++++++++++++++ + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++ + if ($transfercartest == 1){ + convertCartest(); + } } else { diff --git a/api/v1/get/cartests.php b/api/v1/get/cartests.php index 84c05ab..ff8ece3 100644 --- a/api/v1/get/cartests.php +++ b/api/v1/get/cartests.php @@ -10,17 +10,9 @@ $pdo = dbConnect($dbname); //NEW ARRAY $criterias = []; -$whereclause = 'WHERE type="cartest"'; +$whereclause = ''; $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 @@ -31,12 +23,12 @@ if(isset($get_content) && $get_content!=''){ //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'){ + if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='download' || $v[0] =='list'|| $v[0] =='success_msg'){ //do nothing } elseif ($v[0] == 'search') { //build up search - $clause .= ' AND '.$car_brand.' like :'.$v[0]; + $clause .= ' AND (carbrand like :'.$v[0].' OR createdby like :'.$v[0].')'; } else {//create clause $clause .= ' AND '.$v[0].' = :'.$v[0]; @@ -51,15 +43,23 @@ if(isset($get_content) && $get_content!=''){ //Define Query if(isset($criterias['totals']) && $criterias['totals'] ==''){ //Request for total rows - $sql = 'SELECT count(*) as count FROM history '.$whereclause; + $sql = 'SELECT count(*) as count FROM cartest '.$whereclause; } -elseif(isset($criterias['list']) && $criterias['list'] ==''){ +elseif(isset($criterias['list']) && $criterias['list'] =='brand'){ //Request for total rows - $sql = 'SELECT distinct('.$car_brand.') FROM history '.$whereclause; - } + $sql = 'SELECT distinct(carbrand) FROM cartest '.$whereclause; +} +elseif(isset($criterias['list']) && $criterias['list'] =='type'){ + //Request for total rows + $sql = 'SELECT distinct(cartype) FROM cartest '.$whereclause; +} +elseif(isset($criterias['download']) && $criterias['download'] ==''){ + //Request for total rows + $sql = 'SELECT * FROM cartest '.$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"; + $sql = "SELECT * from cartest $whereclause ORDER BY carbrand, cartype DESC LIMIT :page,:num_products"; } $stmt = $pdo->prepare($sql); @@ -84,13 +84,21 @@ if (!empty($criterias)){ } } +//------------------------------------------ +// Debuglog +//------------------------------------------ +if (debug){ + $message = $date.';'.$sql.';'.$username; + debuglog($message); +} + //Add paging details if(isset($criterias['totals']) && $criterias['totals']==''){ $stmt->execute(); $messages = $stmt->fetch(); $messages = $messages[0]; } -elseif(isset($criterias['list']) && $criterias['list']==''){ +elseif ((isset($criterias['list']) && $criterias['list']!='') || (isset($criterias['download']) && $criterias['download'] =='')){ //Excute Query $stmt->execute(); //Get results diff --git a/api/v1/post/cartests.php b/api/v1/post/cartests.php new file mode 100644 index 0000000..3b5e984 --- /dev/null +++ b/api/v1/post/cartests.php @@ -0,0 +1,76 @@ + $var){ + if ($key == 'submit' || $key == 'delete' || $key == 'rowID'){ + //do nothing + } + else { + $criterias[$key] = $var; + $clause .= ' , '.$key.' = ?'; + $clause_insert .= ' , '.$key.''; + $input_insert .= ', ?'; // ? for each insert item + $execute_input[]= $var; // Build array for input + } + } +} + +//CLEAN UP INPUT +$clause = substr($clause, 2); //Clean clause - remove first comma +$clause_insert = substr($clause_insert, 2); //Clean clause - remove first comma +$input_insert = substr($input_insert, 1); //Clean clause - remove first comma + +//QUERY AND VERIFY ALLOWED +if ($command == 'update' && isAllowed('cartest_manage',$profile,$permission,'U') === 1){ + $sql = 'UPDATE cartest SET '.$clause.' WHERE rowID = ? '.$whereclause.''; + $execute_input[] = $id; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); +} +elseif ($command == 'insert' && isAllowed('cartest_manage',$profile,$permission,'C') === 1){ + $sql = 'INSERT INTO cartest ('.$clause_insert.') VALUES ('.$input_insert.')'; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); +} +elseif ($command == 'delete' && isAllowed('cartest_manage',$profile,$permission,'D') === 1){ + $stmt = $pdo->prepare('DELETE FROM cartest WHERE rowID = ? '.$whereclause.''); + $stmt->execute([ $id ]); + + //Add deletion to changelog + changelog($dbname,'cartest',$id,'Delete','Delete',$username); +} else +{ + //do nothing +} + +?> \ No newline at end of file diff --git a/assets/functions.php b/assets/functions.php index cd8a377..be48e54 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -2048,4 +2048,47 @@ function getQuestions($type){ $view .= ''; } } +} +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// convert cartest from history to cartest table +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +function convertCartest(){ + +include dirname(__FILE__,2).'/settings/settings.php'; + +//GET CARTEST FROM HISTORY TABLE +$pdo = dbConnect($dbname); +$sql = 'SELECT * FROM history WHERE type="cartest"'; +$stmt = $pdo->prepare($sql); +//Excute Query +$stmt->execute(); +//Get results +$messages = $stmt->fetchAll(PDO::FETCH_ASSOC); + +//FOR EACH CARTEST TRANSFER TO CARTEST TABLE + foreach ($messages as $message){ + //GET VARIABLES + $cartest = json_decode($message['description'],true); + $carbrand = ucfirst($cartest["CarBrand"]); + $cartype = ucfirst($cartest["CarType"]); + $questions = json_encode($cartest["Questions"] ??''); + $datapoints = json_encode($cartest["plugDataPoints"] ?? ''); + + //get header data only + unset($cartest["Questions"]); + unset($cartest["plugDataPoints"]); + $header = json_encode($cartest); + + //INSERT INTO CARTEST + $sql = 'INSERT INTO cartest (carbrand, cartype,header,questions,datapoints,createdby) VALUES (?,?,?,?,?,?)'; + $stmt = $pdo->prepare($sql); + //Excute Query + $stmt->execute([$carbrand,$cartype,$header,$questions,$datapoints,$cartest["NameTester"]]); + + //MARK HISTORY ITEM FOR DELETATION + $sql = 'UPDATE history SET type = "delete" WHERE rowID = '.$message['rowID']; + $stmt = $pdo->prepare($sql); + //Excute Query + $stmt->execute(); + } } \ No newline at end of file diff --git a/assets/readdevice.js b/assets/readdevice.js index 3346194..b648312 100644 --- a/assets/readdevice.js +++ b/assets/readdevice.js @@ -235,10 +235,18 @@ async function listenToPort() { } const serialResultsDiv = document.getElementById("serialResults"); +const plug_data = document.getElementById("plug_data"); async function appendToTerminal(newStuff) { serialResultsDiv.innerHTML += newStuff; - serialOutput +=newStuff + //vcp_data.value +=newStuff + if (typeof plug_data !== "undefined"){ + var plugdata = {"VCP":{VCP}, "VPP1":{VPP1},"VPP2":{VPP2},"VBAT":{VBAT}, "PWM":{PWM},"STATE":{STATE}, "xChart":{xChart}} + plug_data.value = JSON.stringify(plugdata); + } + + serialOutput +=newStuff; + } @@ -374,6 +382,37 @@ async function closePort(){ window.location.reload(); } +async function closePortCarTest(){ + + reader.cancel(); + await readableStreamClosed.catch(() => { /* Ignore the error */ }); + writer.close(); + await writableStreamClosed + console.log(maintenanceRun); + await port.close(); + + //Check for errors maintenanceRun = 999 + if (maintenanceRun != 999){ + serialResultsDiv.innerHTML = ''; + + if (maintenanceRun !=0){ + if (value != 33){//Include the correct ROWID of the Productrecord + progressBar("100", "Ready", "#04AA6D"); + } + else{ + progressBar("100", "Ready => Warning: Product requires TESLA adapter", "#ff6666"); + } + + } + else { + progressBar("100", "Ready", "#04AA6D"); + } + } + + maintenanceRun = 0; // reset maintenanceRun + +} + async function updateHistory(){ var data = document.getElementById("servicetoken").innerHTML; //get ServiceID diff --git a/cartest.php b/cartest.php index 9d3161f..15397d0 100644 --- a/cartest.php +++ b/cartest.php @@ -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'; //Check if allowed @@ -28,8 +29,13 @@ $cartest = ioServer($api_url,''); //Decode Payload if (!empty($cartest)){$cartest = decode_payload($cartest);}else{$cartest = null;} $cartest = $cartest[0]; + +//CHECK FOR CARTEST APP OR PORTAL +$version = str_contains($cartest->questions,'GoToP')?0:1; //GET TEST DETAILS -$cartest_details = json_decode($cartest->description,true); +$cartest_header = json_decode($cartest->header,true) ?? ''; +$cartest_questions = json_decode($cartest->questions,true) ?? ''; +$cartest_datapoints = json_decode($cartest->datapoints,true) ?? ''; // Handle success messages if (isset($_GET['success_msg'])) { @@ -44,6 +50,10 @@ if (isset($_GET['success_msg'])) { } } +if (isset($_GET['download'])){ + downloadToExcel('cartests',$cartest); +} + template_header('Cartest', 'cartest', 'view'); $view = '
'.$cartest_details['CarBrand'].'
+'.$cartest->carbrand.'
'.$cartest_details['CarType'].'
+'.$cartest->cartype.'
'.$cartest_details['CarVIN'].'
+'.$cartest_header['CarVIN'].'
'.$cartest_details['NameTester'].'
+'.$cartest_header['NameTester'].'
'.$cartest_details['SN'].'
+'.$cartest_header['SN'].'
'.$cartest_details['HW'].'
+'.$cartest_header['HW'].'
'.$cartest_details['FW'].'
+'.$cartest_header['FW'].'
| '.$key.' | -'.((!empty($value)|| $value !='')?$value:$not_specified).' | -
| '.$key.' | +'.((!empty($value)|| $value !='')?$value:$not_specified).' | +
'.$buildtool_p.'
-