'', '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 ='