CMXX - Pricelists

This commit is contained in:
“VeLiTi”
2025-01-23 12:54:16 +01:00
parent 53686b3c33
commit 661783270a
16 changed files with 811 additions and 182 deletions

View File

@@ -18,7 +18,7 @@ $products_versions = [
'productrowid' => '',
'status' => '',
'version' => '',
'software' => '',
'config' => '',
'created' => '',
'createdby' => $_SESSION['username'],
'measurement' => '',
@@ -30,11 +30,11 @@ $productrowid = $_GET['productrowid'] ?? '';
if (isset($_GET['rowID'])) {
// ID param exists, edit an existing product
//CALL TO API
$api_url = '/v1/products_versions/rowID='.$_GET['rowID'].'&productrowid='.$productrowid;
$api_url = '/v2/products_versions/rowID='.$_GET['rowID'].'&productrowid='.$productrowid;
$responses = ioServer($api_url,'');
//Decode Payload
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;}
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
$products_versions = json_decode(json_encode($responses[0]), true);
@@ -42,40 +42,10 @@ if (isset($_GET['rowID'])) {
if ($update_allowed === 1){
if (isset($_POST['submit'])) {
//CHECK FOR FIRMWARE FILE
$firmware_file = $_FILES["fileToUpload"]["name"] ?? '';
if($firmware_file !='' || !empty($firmware_file)){
$extension = strtolower(pathinfo($firmware_file, PATHINFO_EXTENSION));
$target_dir = dirname(__FILE__)."/firmware/";
if ($extension == 'hex'){
//READ FILE
$contents = file_get_contents($_FILES["fileToUpload"]["tmp_name"]);
//firmwarename
$firmware_name = pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_FILENAME);
//Filename
$input_file = $target_dir . $firmware_name.'.HEX';
//store firmware file
file_put_contents($input_file, $contents);
} else {
$target_file = $target_dir . $firmware_file;
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
$firmware_name = $firmware_file;
}
//Use firmwarefile name as software version
$_POST['software'] = $firmware_name;
}
//GET ALL POST DATA
$data = json_encode($_POST, JSON_UNESCAPED_UNICODE);
//Secure data
$payload = generate_payload($data);
$payload = json_encode($_POST, JSON_UNESCAPED_UNICODE);
//API call
$responses = ioServer('/v1/products_versions', $payload);
$responses = ioServer('/v2/products_versions', $payload);
if ($responses === 'NOK'){
} else {
@@ -89,11 +59,9 @@ if (isset($_GET['rowID'])) {
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);
$payload = json_encode($_POST, JSON_UNESCAPED_UNICODE);
//API call
$responses = ioServer('/v1/products_versions', $payload);
$responses = ioServer('/v2/products_versions', $payload);
if ($responses === 'NOK'){
} else {
@@ -108,42 +76,12 @@ if (isset($_GET['rowID'])) {
// Create a new product
if (isset($_POST['submit']) && $create_allowed === 1) {
//CHECK FOR FIRMWARE FILE
$firmware_file = $_FILES["fileToUpload"]["name"] ?? '';
if($firmware_file !='' || !empty($firmware_file)){
$extension = strtolower(pathinfo($firmware_file, PATHINFO_EXTENSION));
$target_dir = dirname(__FILE__)."/firmware/";
if ($extension == 'hex'){
//READ FILE
$contents = file_get_contents($_FILES["fileToUpload"]["tmp_name"]);
//firmwarename
$firmware_name = pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_FILENAME);
//Filename
$input_file = $target_dir . $firmware_name.'.HEX';
//store firmware file
file_put_contents($input_file, $contents);
$firmware_name = $firmware_name.'.HEX';
} else {
$target_file = $target_dir . $firmware_file;
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
$firmware_name = $firmware_file;
}
//Use firmwarefile name as software version
$_POST['software'] = $firmware_name;
}
//GET ALL POST DATA
$data = json_encode($_POST , JSON_UNESCAPED_UNICODE);
//Secure data
$payload = generate_payload($data);
//API call
$responses = ioServer('/v1/products_versions', $payload);
$responses = ioServer('/v2/products_versions', $payload);
if ($responses === 'NOK'){
}
@@ -189,7 +127,18 @@ $view .= '<div class="content-block tab-content active">
<input id="name" type="text" name="version" placeholder="'.$product_version_version.'" value="'.$products_versions['version'].'" required>
';
//VIEW FOR PRODUCT CONFIGURATION
if (isset($_GET['rowID']) && $_GET['rowID'] !=''){
$view .= '
<label for="">'.($product_version_config ?? 'Config').'</label>
<div class="table">
<textarea id="config" name="config" placeholder="'.($product_version_config ?? 'Config').'">'.$products_versions['config'].'</textarea>
</table>
</div>';
}
if (isset($_GET['rowID']) && $_GET['rowID'] !='' && !empty($products_versions['measurement'])){
$measurements = json_decode($products_versions['measurement'],true);