CMXX - Update products_software to include versions
This commit is contained in:
@@ -11,7 +11,13 @@ $pdo = dbConnect($dbname);
|
|||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
//UPDATE SW_STATUS
|
//UPDATE SW_STATUS
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
$sql = 'UPDATE equipment e JOIN products_software ps ON e.productrowid = ps.productrowid SET e.sw_version_latest = 1 WHERE ps.latest = 1 AND lower(e.sw_version) = lower(ps.version) AND e.sw_version_latest = 0';
|
//UPDATE LATEST TO NO IN CASE HW_VERSION ARE EQUAL AND SW_VERSIONS NOT AND NOT LATEST
|
||||||
|
$sql = 'UPDATE equipment e JOIN products_software ps ON e.productrowid = ps.productrowid SET e.sw_version_latest = 0 WHERE ps.latest = 1 AND lower(e.sw_version) <> lower(ps.version) AND lower(e.hw_version) = lower(ps.hw_version) AND e.sw_version_latest = 1';
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
//UPDATE LATEST TO YES IN CASE HW_VERSION ARE EQUAL AND SW_VERSIONS ARE EQUAL
|
||||||
|
$sql = 'UPDATE equipment e JOIN products_software ps ON e.productrowid = ps.productrowid SET e.sw_version_latest = 1 WHERE ps.latest = 1 AND lower(e.sw_version) = lower(ps.version) AND lower(e.hw_version) = lower(ps.hw_version) AND e.sw_version_latest = 0';
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
|
|||||||
@@ -138,17 +138,11 @@ else {
|
|||||||
// IF PRODUCTCODE AND VERSION IS SEND ASSUME SOFTWARE REQUEST
|
// IF PRODUCTCODE AND VERSION IS SEND ASSUME SOFTWARE REQUEST
|
||||||
if (!isset($criterias['productrowid']) && isset($criterias['sn']) && $criterias['sn'] != '' ){
|
if (!isset($criterias['productrowid']) && isset($criterias['sn']) && $criterias['sn'] != '' ){
|
||||||
|
|
||||||
//check if current version is send and update the equipment record
|
|
||||||
if(isset($criterias['version']) && $criterias['version'] !=''){
|
|
||||||
$sql = 'UPDATE equipment SET sw_version = ? WHERE serialnumber = ? ';
|
|
||||||
$stmt = $pdo->prepare($sql);
|
|
||||||
$stmt->execute([$criterias['version'],$criterias['sn']]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//default output
|
//default output
|
||||||
$output = array(
|
$output = array(
|
||||||
"productcode" => "",
|
"productcode" => "",
|
||||||
"version"=> "",
|
"version"=> "",
|
||||||
|
"hw_version"=> "",
|
||||||
"mandatory"=> "",
|
"mandatory"=> "",
|
||||||
"latest"=> "",
|
"latest"=> "",
|
||||||
"software"=> "",
|
"software"=> "",
|
||||||
@@ -156,98 +150,86 @@ if (!isset($criterias['productrowid']) && isset($criterias['sn']) && $criterias[
|
|||||||
"source_type" => ""
|
"source_type" => ""
|
||||||
);
|
);
|
||||||
|
|
||||||
//CHECK IF VERSION IS LATEST
|
//check if current version is send and update the equipment record
|
||||||
$latest_check = 0;
|
if(isset($criterias['version']) && $criterias['version'] !=''){
|
||||||
$sw_upgrade_version = 0;
|
$sql = 'UPDATE equipment SET sw_version = ? WHERE serialnumber = ? ';
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
foreach ($messages as $message){
|
$stmt->execute([$criterias['version'],$criterias['sn']]);
|
||||||
if ($message['latest'] == 1 && ($message['sw_version_upgrade']== 0 || $message['sw_version_upgrade']== '')){
|
|
||||||
|
|
||||||
$file_contents = 'https://'.$_SERVER['SERVER_NAME'].'/firmware'.'/'.$message['software'];
|
|
||||||
|
|
||||||
$output = array(
|
|
||||||
"productcode" => $message['productcode'],
|
|
||||||
"version"=> $message['version'],
|
|
||||||
"mandatory"=> $message['mandatory'],
|
|
||||||
"latest"=> $message['latest'],
|
|
||||||
"software"=> $message['software'],
|
|
||||||
"source" => $file_contents,
|
|
||||||
"source_type" => "url"
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
//Check if sw_version_upgrade is set
|
|
||||||
if ($message['sw_version_upgrade'] > 0){
|
|
||||||
$sw_upgrade_version = $message['sw_version_upgrade'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//GET PRODUCTCODE BASED ON SN WHEN NO RECORDS FOUND
|
//GET PRODUCTCODE, SW_VERSION_UPGRADE, HW_VERSION from equipment SN
|
||||||
if (isset($criterias['sn']) && !isset($criterias['productcode'])){
|
$sql = 'SELECT p.productcode, e.sw_version_upgrade, e.hw_version FROM equipment e JOIN products p ON e.productrowid = p.rowID WHERE e.serialnumber = ?';
|
||||||
$sql = 'SELECT p.productcode, e.sw_version_upgrade FROM equipment e JOIN products p ON e.productrowid = p.rowID WHERE e.serialnumber = ?';
|
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
//Excute Query
|
//Excute Query
|
||||||
$stmt->execute([$criterias['sn']]);
|
$stmt->execute([$criterias['sn']]);
|
||||||
//Get results
|
//Get results
|
||||||
$productcodes = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$productcodes = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
//assign serialnumber to productcode
|
//assign serialnumber to productcode
|
||||||
$criterias['productcode'] = $productcodes[0]['productcode'];
|
$criterias['productcode'] = $productcodes[0]['productcode']?? '';
|
||||||
$sw_upgrade_version = $productcodes[0]['sw_version_upgrade'];
|
$sw_upgrade_version = $productcodes[0]['sw_version_upgrade'] ?? '';
|
||||||
}
|
$hw_eq_version = $productcodes[0]['hw_version'] ?? '';
|
||||||
|
|
||||||
if ($latest_check == 0){
|
//GET LATEST BASED ON PRODUCTCODE
|
||||||
//GET LATEST BASED ON PRODUCTCODE
|
if ($sw_upgrade_version > 0){
|
||||||
if ($sw_upgrade_version > 0){
|
//sw_version_upgrade set => change query
|
||||||
//sw_version_upgrade set => change query
|
$sql = 'SELECT * FROM products_software ps JOIN products p ON ps.productrowid = p.rowID WHERE ps.rowID = ? AND ps.status = "1"';
|
||||||
$sql = 'SELECT * FROM products_software ps JOIN products p ON ps.productrowid = p.rowID WHERE ps.rowID = ? AND ps.status = "1"';
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt = $pdo->prepare($sql);
|
//Excute Query
|
||||||
//Excute Query
|
$stmt->execute([$sw_upgrade_version]);
|
||||||
$stmt->execute([$sw_upgrade_version]);
|
}
|
||||||
}
|
else {
|
||||||
else {
|
//GET THE LATEST
|
||||||
//GET THE LATEST
|
if (!empty($hw_eq_version) || $hw_eq_version != ''){
|
||||||
$sql = 'SELECT * FROM products_software ps JOIN products p ON ps.productrowid = p.rowID WHERE p.productcode = ? AND ps.status = "1" AND ps.latest = "1"';
|
$sql = 'SELECT * FROM products_software ps JOIN products p ON ps.productrowid = p.rowID WHERE p.productcode = ? AND ps.hw_version = ? AND ps.status = "1" AND ps.latest = "1"';
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
//Excute Query
|
//Excute Query
|
||||||
$stmt->execute([$criterias['productcode']]);
|
$stmt->execute([$criterias['productcode'],$hw_eq_version]);
|
||||||
|
} else {
|
||||||
|
$sql = 'SELECT * FROM products_software ps JOIN products p ON ps.productrowid = p.rowID WHERE p.productcode = ? AND ps.status = "1" AND ps.latest = "1"';
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
//Excute Query
|
||||||
|
$stmt->execute([$criterias['productcode']]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Get results
|
//Get results
|
||||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
foreach ($messages as $message){
|
foreach ($messages as $message){
|
||||||
|
|
||||||
//CHECK IF FIRMWARE FILE IS AVAILABLE
|
//CHECK IF FIRMWARE FILE IS AVAILABLE
|
||||||
$software_file = dirname(__FILE__,4)."/firmware/".$message['software'];
|
$software_file = dirname(__FILE__,4)."/firmware/".$message['software'];
|
||||||
$file = glob($software_file, GLOB_BRACE);
|
$file = glob($software_file, GLOB_BRACE);
|
||||||
|
|
||||||
if (!empty($file)){
|
if (!empty($file)){
|
||||||
//GET FILE EXTENTION
|
//GET FILE EXTENTION
|
||||||
$ext = strtolower(pathinfo($file[0], PATHINFO_EXTENSION));
|
$ext = strtolower(pathinfo($file[0], PATHINFO_EXTENSION));
|
||||||
if ($ext == 'hex'){
|
if ($ext == 'hex'){
|
||||||
//GET SOURCE CODE
|
//GET SOURCE CODE
|
||||||
$file_contents = file_get_contents($software_file);
|
$file_contents = file_get_contents($software_file);
|
||||||
//REMOVE RETURN \R
|
//REMOVE RETURN \R
|
||||||
$file_contents = str_replace("\r", '',$file_contents);
|
$file_contents = str_replace("\r", '',$file_contents);
|
||||||
$source_type = 'HEX';
|
$source_type = 'HEX';
|
||||||
}
|
|
||||||
else {
|
|
||||||
//PROVIDE URL TO FILE
|
|
||||||
$file_contents = 'https://'.$_SERVER['SERVER_NAME'].'/firmware'.'/'.$message['software'];
|
|
||||||
$source_type = 'url';
|
|
||||||
}
|
}
|
||||||
// Default input product values
|
else {
|
||||||
$output = array(
|
//PROVIDE URL TO FILE
|
||||||
"productcode" => $message['productcode'],
|
$file_contents = 'https://'.$_SERVER['SERVER_NAME'].'/firmware'.'/'.$message['software'];
|
||||||
"version"=> $message['version'],
|
$source_type = 'url';
|
||||||
"mandatory"=> $message['mandatory'],
|
|
||||||
"latest"=> $message['latest'],
|
|
||||||
"software"=> $message['software'],
|
|
||||||
"source" => $file_contents,
|
|
||||||
"source_type" => $source_type
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default input product values
|
||||||
|
$output = array(
|
||||||
|
"productcode" => $message['productcode'],
|
||||||
|
"version"=> $message['version'],
|
||||||
|
"hw_version"=> $message['hw_version'] ?? '',
|
||||||
|
"mandatory"=> $message['mandatory'],
|
||||||
|
"latest"=> $message['latest'],
|
||||||
|
"software"=> $message['software'],
|
||||||
|
"source" => $file_contents ?? '',
|
||||||
|
"source_type" => $source_type ?? ''
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$messages = $output;
|
$messages = $output;
|
||||||
|
|||||||
@@ -87,14 +87,17 @@ if (isset($post_content['productrowid']) && $post_content['productrowid'] != '')
|
|||||||
$clause_insert = substr($clause_insert, 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
|
$input_insert = substr($input_insert, 1); //Clean clause - remove first comma
|
||||||
|
|
||||||
|
//SET HW VERSION
|
||||||
|
$hw_eq_version = (isset($criterias['hw_version']))? $criterias['hw_version']:'';
|
||||||
|
|
||||||
//QUERY AND VERIFY ALLOWED
|
//QUERY AND VERIFY ALLOWED
|
||||||
if ($command == 'update' && isAllowed('products_software',$profile,$permission,'U') === 1){
|
if ($command == 'update' && isAllowed('products_software',$profile,$permission,'U') === 1){
|
||||||
|
|
||||||
//REMOVE LATEST FLAG FROM OTHER WHEN SEND
|
//REMOVE LATEST FLAG FROM OTHER WHEN SEND
|
||||||
if ($criterias['latest'] == 1){
|
if ($criterias['latest'] == 1){
|
||||||
$sql = 'UPDATE products_software SET latest = 0 WHERE productrowid = ?';
|
$sql = 'UPDATE products_software SET latest = 0 WHERE productrowid = ? AND hw_version = ?';
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute([$post_content['productrowid']]);
|
$stmt->execute([$post_content['productrowid'], $hw_eq_version ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = 'UPDATE products_software SET '.$clause.' WHERE rowID = ? '.$whereclause.'';
|
$sql = 'UPDATE products_software SET '.$clause.' WHERE rowID = ? '.$whereclause.'';
|
||||||
@@ -104,10 +107,10 @@ if (isset($post_content['productrowid']) && $post_content['productrowid'] != '')
|
|||||||
}
|
}
|
||||||
elseif ($command == 'insert' && isAllowed('products_software',$profile,$permission,'C') === 1){
|
elseif ($command == 'insert' && isAllowed('products_software',$profile,$permission,'C') === 1){
|
||||||
|
|
||||||
//REMOVE LATEST FLAG FROM OTHER
|
//REMOVE LATEST FLAG FROM OTHER
|
||||||
$sql = 'UPDATE products_software SET latest = 0 WHERE productrowid = ?';
|
$sql = 'UPDATE products_software SET latest = 0 WHERE productrowid = ? AND hw_version = ?';
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute([$post_content['productrowid']]);
|
$stmt->execute([$post_content['productrowid'], $hw_eq_version]);
|
||||||
|
|
||||||
//INSERT NEW ITEM
|
//INSERT NEW ITEM
|
||||||
$sql = 'INSERT INTO products_software ('.$clause_insert.') VALUES ('.$input_insert.')';
|
$sql = 'INSERT INTO products_software ('.$clause_insert.') VALUES ('.$input_insert.')';
|
||||||
|
|||||||
@@ -11,7 +11,13 @@ $pdo = dbConnect($dbname);
|
|||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
//UPDATE SW_STATUS
|
//UPDATE SW_STATUS
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
$sql = 'UPDATE equipment e JOIN products_software ps ON e.productrowid = ps.productrowid SET e.sw_version_latest = 1 WHERE ps.latest = 1 AND lower(e.sw_version) = lower(ps.version) AND e.sw_version_latest = 0';
|
//UPDATE LATEST TO NO IN CASE HW_VERSION ARE EQUAL AND SW_VERSIONS NOT AND NOT LATEST
|
||||||
|
$sql = 'UPDATE equipment e JOIN products_software ps ON e.productrowid = ps.productrowid SET e.sw_version_latest = 0 WHERE ps.latest = 1 AND lower(e.sw_version) <> lower(ps.version) AND lower(e.hw_version) = lower(ps.hw_version) AND e.sw_version_latest = 1';
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
//UPDATE LATEST TO YES IN CASE HW_VERSION ARE EQUAL AND SW_VERSIONS ARE EQUAL
|
||||||
|
$sql = 'UPDATE equipment e JOIN products_software ps ON e.productrowid = ps.productrowid SET e.sw_version_latest = 1 WHERE ps.latest = 1 AND lower(e.sw_version) = lower(ps.version) AND lower(e.hw_version) = lower(ps.hw_version) AND e.sw_version_latest = 0';
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
|
|||||||
@@ -137,17 +137,11 @@ else {
|
|||||||
// IF PRODUCTCODE AND VERSION IS SEND ASSUME SOFTWARE REQUEST
|
// IF PRODUCTCODE AND VERSION IS SEND ASSUME SOFTWARE REQUEST
|
||||||
if (!isset($criterias['productrowid']) && isset($criterias['sn']) && $criterias['sn'] != '' ){
|
if (!isset($criterias['productrowid']) && isset($criterias['sn']) && $criterias['sn'] != '' ){
|
||||||
|
|
||||||
//check if current version is send and update the equipment record
|
|
||||||
if(isset($criterias['version']) && $criterias['version'] !=''){
|
|
||||||
$sql = 'UPDATE equipment SET sw_version = ? WHERE serialnumber = ? ';
|
|
||||||
$stmt = $pdo->prepare($sql);
|
|
||||||
$stmt->execute([$criterias['version'],$criterias['sn']]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//default output
|
//default output
|
||||||
$output = array(
|
$output = array(
|
||||||
"productcode" => "",
|
"productcode" => "",
|
||||||
"version"=> "",
|
"version"=> "",
|
||||||
|
"hw_version"=> "",
|
||||||
"mandatory"=> "",
|
"mandatory"=> "",
|
||||||
"latest"=> "",
|
"latest"=> "",
|
||||||
"software"=> "",
|
"software"=> "",
|
||||||
@@ -155,104 +149,91 @@ if (!isset($criterias['productrowid']) && isset($criterias['sn']) && $criterias[
|
|||||||
"source_type" => ""
|
"source_type" => ""
|
||||||
);
|
);
|
||||||
|
|
||||||
//CHECK IF VERSION IS LATEST
|
//check if current version is send and update the equipment record
|
||||||
$latest_check = 0;
|
if(isset($criterias['version']) && $criterias['version'] !=''){
|
||||||
$sw_upgrade_version = 0;
|
$sql = 'UPDATE equipment SET sw_version = ? WHERE serialnumber = ? ';
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
foreach ($messages as $message){
|
$stmt->execute([$criterias['version'],$criterias['sn']]);
|
||||||
if ($message['latest'] == 1 && ($message['sw_version_upgrade']== 0 || $message['sw_version_upgrade']== '')){
|
|
||||||
|
|
||||||
$file_contents = 'https://'.$_SERVER['SERVER_NAME'].'/firmware'.'/'.$message['software'];
|
|
||||||
|
|
||||||
$output = array(
|
|
||||||
"productcode" => $message['productcode'],
|
|
||||||
"version"=> $message['version'],
|
|
||||||
"mandatory"=> $message['mandatory'],
|
|
||||||
"latest"=> $message['latest'],
|
|
||||||
"software"=> $message['software'],
|
|
||||||
"source" => $file_contents,
|
|
||||||
"source_type" => "url"
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
//Check if sw_version_upgrade is set
|
|
||||||
if ($message['sw_version_upgrade'] > 0){
|
|
||||||
$sw_upgrade_version = $message['sw_version_upgrade'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//GET PRODUCTCODE BASED ON SN WHEN NO RECORDS FOUND
|
//GET PRODUCTCODE, SW_VERSION_UPGRADE, HW_VERSION from equipment SN
|
||||||
if (isset($criterias['sn']) && !isset($criterias['productcode'])){
|
$sql = 'SELECT p.productcode, e.sw_version_upgrade, e.hw_version FROM equipment e JOIN products p ON e.productrowid = p.rowID WHERE e.serialnumber = ?';
|
||||||
$sql = 'SELECT p.productcode, e.sw_version_upgrade FROM equipment e JOIN products p ON e.productrowid = p.rowID WHERE e.serialnumber = ?';
|
$stmt = $pdo->prepare($sql);
|
||||||
|
//Excute Query
|
||||||
|
$stmt->execute([$criterias['sn']]);
|
||||||
|
//Get results
|
||||||
|
$productcodes = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
//assign serialnumber to productcode
|
||||||
|
$criterias['productcode'] = $productcodes[0]['productcode']?? '';
|
||||||
|
$sw_upgrade_version = $productcodes[0]['sw_version_upgrade'] ?? '';
|
||||||
|
$hw_eq_version = $productcodes[0]['hw_version'] ?? '';
|
||||||
|
|
||||||
|
//GET LATEST BASED ON PRODUCTCODE
|
||||||
|
if ($sw_upgrade_version > 0){
|
||||||
|
//sw_version_upgrade set => change query
|
||||||
|
$sql = 'SELECT * FROM products_software ps JOIN products p ON ps.productrowid = p.rowID WHERE ps.rowID = ? AND ps.status = "1"';
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
//Excute Query
|
//Excute Query
|
||||||
$stmt->execute([$criterias['sn']]);
|
$stmt->execute([$sw_upgrade_version]);
|
||||||
//Get results
|
}
|
||||||
$productcodes = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
else {
|
||||||
//assign serialnumber to productcode
|
//GET THE LATEST
|
||||||
$criterias['productcode'] = $productcodes[0]['productcode'];
|
if (!empty($hw_eq_version) || $hw_eq_version != ''){
|
||||||
$sw_upgrade_version = $productcodes[0]['sw_version_upgrade'];
|
$sql = 'SELECT * FROM products_software ps JOIN products p ON ps.productrowid = p.rowID WHERE p.productcode = ? AND ps.hw_version = ? AND ps.status = "1" AND ps.latest = "1"';
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
//Excute Query
|
||||||
|
$stmt->execute([$criterias['productcode'],$hw_eq_version]);
|
||||||
|
} else {
|
||||||
|
$sql = 'SELECT * FROM products_software ps JOIN products p ON ps.productrowid = p.rowID WHERE p.productcode = ? AND ps.status = "1" AND ps.latest = "1"';
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
//Excute Query
|
||||||
|
$stmt->execute([$criterias['productcode']]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($latest_check == 0){
|
//Get results
|
||||||
//GET LATEST BASED ON PRODUCTCODE
|
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
if ($sw_upgrade_version > 0){
|
|
||||||
//sw_version_upgrade set => change query
|
|
||||||
$sql = 'SELECT * FROM products_software ps JOIN products p ON ps.productrowid = p.rowID WHERE ps.rowID = ? AND ps.status = "1"';
|
|
||||||
$stmt = $pdo->prepare($sql);
|
|
||||||
//Excute Query
|
|
||||||
$stmt->execute([$sw_upgrade_version]);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//GET THE LATEST
|
|
||||||
$sql = 'SELECT * FROM products_software ps JOIN products p ON ps.productrowid = p.rowID WHERE p.productcode = ? AND ps.status = "1" AND ps.latest = "1"';
|
|
||||||
$stmt = $pdo->prepare($sql);
|
|
||||||
//Excute Query
|
|
||||||
$stmt->execute([$criterias['productcode']]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get results
|
foreach ($messages as $message){
|
||||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
foreach ($messages as $message){
|
//CHECK IF FIRMWARE FILE IS AVAILABLE
|
||||||
|
$software_file = dirname(__FILE__,4)."/firmware/".$message['software'];
|
||||||
|
$file = glob($software_file, GLOB_BRACE);
|
||||||
|
|
||||||
//CHECK IF FIRMWARE FILE IS AVAILABLE
|
if (!empty($file)){
|
||||||
$software_file = dirname(__FILE__,4)."/firmware/".$message['software'];
|
//GET FILE EXTENTION
|
||||||
$file = glob($software_file, GLOB_BRACE);
|
$ext = strtolower(pathinfo($file[0], PATHINFO_EXTENSION));
|
||||||
|
if ($ext == 'hex'){
|
||||||
if (!empty($file)){
|
//GET SOURCE CODE
|
||||||
//GET FILE EXTENTION
|
$file_contents = file_get_contents($software_file);
|
||||||
$ext = strtolower(pathinfo($file[0], PATHINFO_EXTENSION));
|
//REMOVE RETURN \R
|
||||||
if ($ext == 'hex'){
|
$file_contents = str_replace("\r", '',$file_contents);
|
||||||
//GET SOURCE CODE
|
$source_type = 'HEX';
|
||||||
$file_contents = file_get_contents($software_file);
|
|
||||||
//REMOVE RETURN \R
|
|
||||||
$file_contents = str_replace("\r", '',$file_contents);
|
|
||||||
$source_type = 'HEX';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//PROVIDE URL TO FILE
|
|
||||||
$file_contents = 'https://'.$_SERVER['SERVER_NAME'].'/firmware'.'/'.$message['software'];
|
|
||||||
$source_type = 'url';
|
|
||||||
}
|
}
|
||||||
// Default input product values
|
else {
|
||||||
$output = array(
|
//PROVIDE URL TO FILE
|
||||||
"productcode" => $message['productcode'],
|
$file_contents = 'https://'.$_SERVER['SERVER_NAME'].'/firmware'.'/'.$message['software'];
|
||||||
"version"=> $message['version'],
|
$source_type = 'url';
|
||||||
"mandatory"=> $message['mandatory'],
|
|
||||||
"latest"=> $message['latest'],
|
|
||||||
"software"=> $message['software'],
|
|
||||||
"source" => $file_contents,
|
|
||||||
"source_type" => $source_type
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default input product values
|
||||||
|
$output = array(
|
||||||
|
"productcode" => $message['productcode'],
|
||||||
|
"version"=> $message['version'],
|
||||||
|
"hw_version"=> $message['hw_version'] ?? '',
|
||||||
|
"mandatory"=> $message['mandatory'],
|
||||||
|
"latest"=> $message['latest'],
|
||||||
|
"software"=> $message['software'],
|
||||||
|
"source" => $file_contents ?? '',
|
||||||
|
"source_type" => $source_type ?? ''
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$messages = $output;
|
$messages = $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Encrypt results
|
//Encrypt results
|
||||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||||
|
|
||||||
|
|||||||
@@ -86,14 +86,17 @@ if (isset($post_content['productrowid']) && $post_content['productrowid'] != '')
|
|||||||
$clause_insert = substr($clause_insert, 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
|
$input_insert = substr($input_insert, 1); //Clean clause - remove first comma
|
||||||
|
|
||||||
|
//SET HW VERSION
|
||||||
|
$hw_eq_version = (isset($criterias['hw_version']))? $criterias['hw_version']:'';
|
||||||
|
|
||||||
//QUERY AND VERIFY ALLOWED
|
//QUERY AND VERIFY ALLOWED
|
||||||
if ($command == 'update' && isAllowed('products_software',$profile,$permission,'U') === 1){
|
if ($command == 'update' && isAllowed('products_software',$profile,$permission,'U') === 1){
|
||||||
|
|
||||||
//REMOVE LATEST FLAG FROM OTHER WHEN SEND
|
//REMOVE LATEST FLAG FROM OTHER WHEN SEND
|
||||||
if ($criterias['latest'] == 1){
|
if ($criterias['latest'] == 1){
|
||||||
$sql = 'UPDATE products_software SET latest = 0 WHERE productrowid = ?';
|
$sql = 'UPDATE products_software SET latest = 0 WHERE productrowid = ? AND hw_version = ?';
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute([$post_content['productrowid']]);
|
$stmt->execute([$post_content['productrowid'], $hw_eq_version ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = 'UPDATE products_software SET '.$clause.' WHERE rowID = ? '.$whereclause.'';
|
$sql = 'UPDATE products_software SET '.$clause.' WHERE rowID = ? '.$whereclause.'';
|
||||||
@@ -104,9 +107,9 @@ if (isset($post_content['productrowid']) && $post_content['productrowid'] != '')
|
|||||||
elseif ($command == 'insert' && isAllowed('products_software',$profile,$permission,'C') === 1){
|
elseif ($command == 'insert' && isAllowed('products_software',$profile,$permission,'C') === 1){
|
||||||
|
|
||||||
//REMOVE LATEST FLAG FROM OTHER
|
//REMOVE LATEST FLAG FROM OTHER
|
||||||
$sql = 'UPDATE products_software SET latest = 0 WHERE productrowid = ?';
|
$sql = 'UPDATE products_software SET latest = 0 WHERE productrowid = ? AND hw_version = ?';
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute([$post_content['productrowid']]);
|
$stmt->execute([$post_content['productrowid'], $hw_eq_version]);
|
||||||
|
|
||||||
//INSERT NEW ITEM
|
//INSERT NEW ITEM
|
||||||
$sql = 'INSERT INTO products_software ('.$clause_insert.') VALUES ('.$input_insert.')';
|
$sql = 'INSERT INTO products_software ('.$clause_insert.') VALUES ('.$input_insert.')';
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ function checkAvailableFirmware(){
|
|||||||
hex_fw = firmwarelocation.split("/firmware/").pop();
|
hex_fw = firmwarelocation.split("/firmware/").pop();
|
||||||
console.log(hex_fw)
|
console.log(hex_fw)
|
||||||
|
|
||||||
if (hex_fw == 'null.HEX' || hex_fw == '.HEX'){
|
if (hex_fw == 'null' || hex_fw == ''){
|
||||||
//document.getElementById("updateAvailabe").style.display = "none";
|
//document.getElementById("updateAvailabe").style.display = "none";
|
||||||
progressBar("100", "No firmware found for this device", "#ff6666");
|
progressBar("100", "No firmware found for this device", "#ff6666");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,6 +211,7 @@ $view .= '<div class="content-block">
|
|||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>'.$product_status.'</th>
|
<th>'.$product_status.'</th>
|
||||||
<th>'.$product_version_version.'</th>
|
<th>'.$product_version_version.'</th>
|
||||||
|
<th>'.$equipment_label5.'</th>
|
||||||
<th>'.$product_version_software .'</th>
|
<th>'.$product_version_software .'</th>
|
||||||
<th>'.ucfirst($register_mandatory).'</th>
|
<th>'.ucfirst($register_mandatory).'</th>
|
||||||
<th>'.ucfirst($general_sort_type_3).'</th>
|
<th>'.ucfirst($general_sort_type_3).'</th>
|
||||||
@@ -224,6 +225,7 @@ $view .= '<div class="content-block">
|
|||||||
<td>'.$version->rowID.'</td>
|
<td>'.$version->rowID.'</td>
|
||||||
<td>'.(($version->status == 1)? '<span class="status enabled">'.$prod_status_1:'<span class="status">'.$prod_status_0).'</td>
|
<td>'.(($version->status == 1)? '<span class="status enabled">'.$prod_status_1:'<span class="status">'.$prod_status_0).'</td>
|
||||||
<td>'.$version->version.'</td>
|
<td>'.$version->version.'</td>
|
||||||
|
<td>'.$version->hw_version.'</td>
|
||||||
<td>'.$version->software.'</td>
|
<td>'.$version->software.'</td>
|
||||||
<td>'.(($version->mandatory == 1)? $general_yes: $general_no).'</td>
|
<td>'.(($version->mandatory == 1)? $general_yes: $general_no).'</td>
|
||||||
<td>'.(($version->latest == 1)? $general_yes: $general_no).'</td>
|
<td>'.(($version->latest == 1)? $general_yes: $general_no).'</td>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ $products_software = [
|
|||||||
'productrowid' => '',
|
'productrowid' => '',
|
||||||
'status' => '',
|
'status' => '',
|
||||||
'version' => '',
|
'version' => '',
|
||||||
|
'hw_version' => '',
|
||||||
'software' => '',
|
'software' => '',
|
||||||
'created' => '',
|
'created' => '',
|
||||||
'createdby' => $_SESSION['username'],
|
'createdby' => $_SESSION['username'],
|
||||||
@@ -188,7 +189,9 @@ $view .= '<div class="content-block tab-content active">
|
|||||||
</select>
|
</select>
|
||||||
<label for=""><i class="required">*</i>'.$product_version_version.'</label>
|
<label for=""><i class="required">*</i>'.$product_version_version.'</label>
|
||||||
<input id="name" type="text" name="version" placeholder="'.$product_version_version.'" value="'.$products_software['version'].'" >
|
<input id="name" type="text" name="version" placeholder="'.$product_version_version.'" value="'.$products_software['version'].'" >
|
||||||
';
|
<label for=""><i class="required">*</i>'.$equipment_label5.'</label>
|
||||||
|
<input id="name" type="text" name="hw_version" placeholder="'.$equipment_label5.'" value="'.$products_software['hw_version'].'" >
|
||||||
|
';
|
||||||
if ($products_software['software'] !=''){
|
if ($products_software['software'] !=''){
|
||||||
$view .= '
|
$view .= '
|
||||||
<label for=""><i class="required">*</i>'.$product_version_software.'</label>
|
<label for=""><i class="required">*</i>'.$product_version_software.'</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user