diff --git a/assets/functions.php b/assets/functions.php index be48e54..ac8ea0e 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -1712,6 +1712,82 @@ if(($imageFileType == "jpg" || $imageFileType == "png" || $imageFileType == "jpe //} } } + +//------------------------------------------ +// UPLOAD PICTURE for PRODUCTS +//------------------------------------------ +function uploadrequest($requestid, $request_line_id, $name){ + + $identifier = date('YmdHis'); + $target_dir = dirname(__FILE__)."/images/requests/"; + $input_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); + $imageFileType = strtolower(pathinfo($input_file,PATHINFO_EXTENSION)); + $target_file = $target_dir . $name.'-'.$identifier .'.jpg'; + $file_input_check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); + $image_name = $name.'-'.$identifier .'.jpg'; + //Do when JPG or PNG or JPEG or GIF and smaller than 5MB + if(($imageFileType == "jpg" || $imageFileType == "png" || $imageFileType == "jpeg" || $imageFileType == "gif" || $imageFileType == "png") && $_FILES["fileToUpload"]["size"] < 5000000 && $file_input_check !== false) { + //Upload picture + if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { + storeImage($requestid,$request_line_id,$image_name); + } else { + + } + //} + } + } + + function storeImage($requestid, $request_line_id,$image_name){ + + include dirname(__FILE__,2).'/settings/settings.php'; + + $pdo = dbConnect($dbname); + + $sql = 'INSERT INTO images (requestid, request_line_id, image_name) VALUES (?,?,?)'; + $stmt = $pdo->prepare($sql); + $stmt->execute([$requestid, $request_line_id,$image_name]); + } + + //------------------------------------------ + // displayImages + //------------------------------------------ + function displayImages($requestid,$request_type){ + + include dirname(__FILE__,2).'/settings/settings.php'; + + $pdo = dbConnect($dbname); + + switch ($request_type) { + case 'request': + $whereclause = 'requestid = "'.$requestid.'"'; + break; + case 'request_line': + $whereclause = 'request_line_id = "'.$requestid.'"'; + break; + + default: + # code... + break; + } + $sql = 'SELECT * FROM images WHERE '.$whereclause; + $stmt = $pdo->prepare($sql); + $stmt->execute(); + $images = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $output = ''; + + if($images){ + $output .= '
+
'; + + foreach ($images as $image){ + $output .= ''; + } + $output .= '
+
'; + } + return $output; + } //------------------------------------------ // debuglog //------------------------------------------ @@ -2068,11 +2144,12 @@ $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"]); + $cartest = json_decode($message['description'],true) ?? ''; + $carbrand = ucfirst($cartest["CarBrand"] ?? 'Unknown'); + $cartype = ucfirst($cartest["CarType"] ?? 'Unknown'); $questions = json_encode($cartest["Questions"] ??''); $datapoints = json_encode($cartest["plugDataPoints"] ?? ''); + $nametester = $cartest["NameTester"] ?? 'Unknown'; //get header data only unset($cartest["Questions"]); @@ -2083,7 +2160,7 @@ $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); $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"]]); + $stmt->execute([$carbrand,$cartype,$header,$questions,$datapoints,$nametester]); //MARK HISTORY ITEM FOR DELETATION $sql = 'UPDATE history SET type = "delete" WHERE rowID = '.$message['rowID']; diff --git a/cartest.php b/cartest.php index 15397d0..05aefef 100644 --- a/cartest.php +++ b/cartest.php @@ -239,6 +239,7 @@ $view .= '
$x++; } } else { + $cartest_datapoints = is_array($cartest_datapoints)? $cartest_datapoints : json_decode($cartest_datapoints, true); $VCP = $cartest_datapoints['VCP']['VCP']; $VPP1 = $cartest_datapoints['VPP1']['VPP1']; $VPP2 = $cartest_datapoints['VPP2']['VPP2']; @@ -249,7 +250,7 @@ $view .= '
} $view.= '
-
+

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