'', 'carbrand' => '', 'cartype' => '', 'header' => [ 'CarVIN' => '', 'year' => '', 'NameTester'=> $_SESSION['username'], 'SN' =>'', 'HW' =>'', 'FW' =>'' ], 'questions' => [ 'cartest_19' => '', 'cartest_20' => '', 'cartest_22' => '' ], 'datapoints' => [], 'created' => '' ]; 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'])) { //UPLOAD ALL PICTURES foreach ($_FILES["fileToUpload"]["name"] as $key => $value){ //ONLY UPDATE PICTURES IF SOMETHING IS RETURNED if($value !='' || !empty($value)){ uploadrequest($key); } } //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'])) { //UPLOAD ALL PICTURES foreach ($_FILES["fileToUpload"]["name"] as $key => $value){ //ONLY UPDATE PICTURES IF SOMETHING IS RETURNED if($value !='' || !empty($value)){ uploadrequest($key); } } //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; } } } //CREATE CARTEST BRAND DROPDOWN $carbrands_input =' '; //END CARBRAND DROPDOWN template_header('Cartesttool', 'cartesttool','manage'); $view ='

'.$cartest_h2.'

'; if ($delete_allowed === 1){ $view .= ''; } if ($update_allowed === 1){ $view .= ''; } $view .= '
'; $view .= '
'; $view .= '
'.$cartest_information.'

'.$cartest_carvin.'

'.$cartest_carbrand.'

'.$carbrands_input.'

'.$cartest_cartype.'

'.$general_year.'

'; $view .='
'.$cartest_details_text.'

'.$cartest_created.'

'.$cartest['created'].'

'.$cartest_tester.'

'.$cartest_device.'

'.$cartest_device_hw.'

'.$cartest_device_sw.'

'; $view .= '
'; // ------------------------------- //BUILD TO INPUT FORM BASED ON ARRAY // ------------------------------ foreach($arrayQuestions_cartest as $group){ if ($group['Group_sequence'] == 1){ $view .= '
'.$group['Group'].'
'; $view .= '
'; } else { $view .= ''; $view .= '
'; } foreach($group['Questions_in_group'] as $question){ switch ($question['Type']) { case 'dropdown': $view .= ''; $view .= ''; break; case 'textarea': $view .= ''; $view .= ''; break; case 'file'; $view .= ''; if ($question['QuestionID'] !=''){ $view .= ' '; } else { $view .= ''; } break; } } $view .= '
'; } //CAPTURE DATA FROM PLUG $view .= ''; $view .= ''; $view .= '
25:00

STATE: -5 = WAIT_CONNECT, 0 = DISCONNECTED, 3 = REACTIVATE, 5 = FULL_CONNECT

'; //OUTPUT echo $view; //ADD JS FILES echo ' '; template_footer(); ?>