diff --git a/api/v0/post/application.php b/api/v0/post/application.php index ff0ed19..5e61f19 100644 --- a/api/v0/post/application.php +++ b/api/v0/post/application.php @@ -229,17 +229,24 @@ if (!empty($post_content['sn']) && !empty($post_content['testdetails'])) { } else { //GET HW + SW from object - $hw_version = $post_content['testdetails']['logdetails']['HW']; - $sw_version = $post_content['testdetails']['logdetails']['HEX_FW']; + $hw_version = $post_content['testdetails']['logdetails']['HW'] ?? ''; + $fw_version = $post_content['testdetails']['logdetails']['FW'] ?? ''; + $sw_version = $post_content['testdetails']['logdetails']['HEX_FW'] ?? ''; + + //GET COMMITCODE + $commitCode = compareCommitCodes($sw_version,$fw_version); + + //IF COMMITCODE IS EMPTY THEN RETURN HEX_FW + $sw_version = ($commitCode != '' || !empty($commitCode)) ? $commitCode : $sw_version; } - //check SW_VERSION for filetype + //check SW_VERSION for filetype HEX_FW can contain extension $version_file_type = strtolower(substr($sw_version, -4)); // filetype - + if ($version_file_type[0] == '.'){ $sw_version = substr($sw_version, 0, -4); } - + //Update Equipment record $sql = "UPDATE equipment SET hw_version = ?, sw_version = ? $whereclause"; $stmt = $pdo->prepare($sql); diff --git a/api/v2/post/history.php b/api/v2/post/history.php index 935fd34..2ad217f 100644 --- a/api/v2/post/history.php +++ b/api/v2/post/history.php @@ -215,8 +215,15 @@ if (isset($post_content['sn']) && isset($post_content['payload'])){ } else { //GET HW + SW from object - $hw_version = $post_content['payload']['logdetails']['HW']; - $sw_version = $post_content['payload']['logdetails']['HEX_FW']; + $hw_version = $post_content['testdetails']['logdetails']['HW'] ?? ''; + $fw_version = $post_content['testdetails']['logdetails']['FW'] ?? ''; + $sw_version = $post_content['testdetails']['logdetails']['HEX_FW'] ?? ''; + + //GET COMMITCODE + $commitCode = compareCommitCodes($sw_version,$fw_version); + + //IF COMMITCODE IS EMPTY THEN RETURN HEX_FW + $sw_version = ($commitCode != '' || !empty($commitCode)) ? $commitCode : $sw_version; } //check SW_VERSION for filetype diff --git a/assets/functions.php b/assets/functions.php index cd1931f..196997c 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -3401,7 +3401,7 @@ class ShoppingCartCalculator { private function getTaxRate() { - $sql = "SELECT rate FROM taxes WHERE country = ?"; + $sql = "SELECT rate FROM taxes WHERE id = ?"; $stmt = $this->db->prepare($sql); $stmt->execute([$this->selected_country]); $tax = $stmt->fetch(PDO::FETCH_ASSOC); @@ -3557,7 +3557,7 @@ class ShoppingCartCalculator { } private function calculateTaxTotal($amount_to_tax) { - $sql = "SELECT rate FROM taxes WHERE country = ?"; + $sql = "SELECT rate FROM taxes WHERE id = ?"; $stmt = $this->db->prepare($sql); $stmt->execute([$this->selected_country]); $tax = $stmt->fetch(PDO::FETCH_ASSOC); @@ -3866,4 +3866,47 @@ function createGiftCart($pdo, $orderID, $giftcard_categoryID,$accounthierarchy){ } } +} + +//======================================= +// findGitCommitHash +//======================================= + +function findShortGitCommitHash($string) { + // Step 1: Find all hexadecimal sequences + preg_match_all('/[0-9a-f]+/i', $string, $matches); + $allHexMatches = $matches[0] ?? []; + + // Step 2: Filter to only include those with exactly 6 or 7 characters + $commitHashes = array_filter($allHexMatches, function($match) { + return strlen($match) === 6 || strlen($match) === 7; + }); + + return array_values($commitHashes); // Re-index array +} + +function compareCommitCodes($stringA, $stringB) { + // Get commit codes from both strings + $commitCodesA = findShortGitCommitHash($stringA); + $commitCodesB = findShortGitCommitHash($stringB); + + // Case 1: Check if there are matching commit codes between A and B + foreach ($commitCodesA as $codeA) { + if (in_array($codeA, $commitCodesB)) { + return $codeA; // Return the first matching commit code + } + } + + // Case 2: If A has commit code but B doesn't + if (count($commitCodesA) > 0 && count($commitCodesB) === 0) { + return $commitCodesA[0]; // Return the first commit code from A + } + + // Case 3: If A has no commit code but B does + if (count($commitCodesA) === 0 && count($commitCodesB) > 0) { + return $commitCodesB[0]; // Return the first commit code from B + } + + // Case 4: Neither has commit code + return ""; } \ No newline at end of file diff --git a/assets/scripts.js b/assets/scripts.js index a472121..df20983 100644 --- a/assets/scripts.js +++ b/assets/scripts.js @@ -64,7 +64,7 @@ async function listenToPort() { var item = serialResultsDiv.innerHTML; x = Array.from(new Set(item.split(";"))).toString(); - if (x.indexOf("SN=") > 0 && x.indexOf("HW=") > 0 && x.indexOf("FW=") >0 && x.indexOf("FWDATE=") >0 && x.indexOf("STATE=") > 0) + if (x.indexOf("SN=") > 0 && x.indexOf("HW=") > 0 && x.indexOf("FW=") >0 && x.indexOf("HEX_FW=") >0 && x.indexOf("STATE=") > 0) { progressBar("60", "Reading device completed", "#04AA6D"); setTimeout(getDeviceData, 4000); @@ -100,16 +100,17 @@ async function getDeviceData(){ fw = fw.replace(/^0+/, ''); } - if (x.indexOf("FWDATE=") > 0){ - var a = x.indexOf("FWDATE="); - var b = a + 7; - var c = b + 10; - fwdate = x.substring(b,c); - fwdate = fwdate.replaceAll('-', ''); + if (x.indexOf("HEX_FW=") > 0){ + var startIndex = x.indexOf("HEX_FW="); + var valueStart = startIndex + 7; // + // Find the closing quotation mark + var valueEnd = x.indexOf("\"", valueStart); + // Extract the value + hex_fw = x.substring(valueStart, valueEnd); } //Check if HW is retrieved from device - if (x.indexOf("HW=") > 0 && x.indexOf("FW=") >0 && x.indexOf("FWDATE=") >0){ + if (x.indexOf("HW=") > 0 && x.indexOf("FW=") >0 && x.indexOf("HEX_FW=") >0){ var a = x.indexOf("HW="); var b = a + 3; var c = b + 8; @@ -126,13 +127,13 @@ async function getDeviceData(){ hw = 'R'+f; sw = 'R'+f; } + + //GET THE COMMITCODE + commitCode = compareCommitCodes(hex_fw,fw); - fw_name = fwdate+'_Firmware_'+fw+'_'+sw; - console.log(fw_name); getServiceID().then(firmwareUpdate); progressBar("80", "checking for available firmware", "#04AA6D"); setTimeout(checkAvailableFirmware, 5000); - console.log(hw); } else { progressBar("80", "Reading of device not successful, please try again", "#ff6666"); @@ -143,7 +144,7 @@ async function getDeviceData(){ function firmwareUpdate(data){ var serialnumber = serial; - var action = '/v2/products_software/sn='+serialnumber+'&version='+fw_name+'&hw_version='+hw; + var action = '/v2/products_software/sn='+serialnumber+'&version='+commitCode+'&hw_version='+hw; var url = link+action; var bearer = 'Bearer ' + data; @@ -171,6 +172,43 @@ function firmwareUpdate(data){ } +function findShortGitCommitHash(string) { + // Step 1: Find all hexadecimal sequences + const hexSequencePattern = /[0-9a-f]+/gi; + const allHexMatches = string.match(hexSequencePattern) || []; + + // Step 2: Filter to only include those with exactly 6 or 7 characters + const commitHashes = allHexMatches.filter(match => match.length === 6 || match.length === 7); + + return commitHashes; +} + +function compareCommitCodes(stringA, stringB) { + // Get commit codes from both strings + const commitCodesA = findShortGitCommitHash(stringA); + const commitCodesB = findShortGitCommitHash(stringB); + + // Case 1: Check if there are matching commit codes between A and B + for (const codeA of commitCodesA) { + if (commitCodesB.includes(codeA)) { + return codeA; // Return the first matching commit code + } + } + + // Case 2: If A has commit code but B doesn't + if (commitCodesA.length > 0 && commitCodesB.length === 0) { + return commitCodesA[0]; // Return the first commit code from A + } + + // Case 3: If A has no commit code but B does + if (commitCodesA.length === 0 && commitCodesB.length > 0) { + return commitCodesB[0]; // Return the first commit code from B + } + + // Case 4: Neither has commit code + return ""; +} + function checkAvailableFirmware(){ if (typeof firmwarelocation !== 'undefined') { @@ -182,33 +220,24 @@ function checkAvailableFirmware(){ //document.getElementById("updateAvailabe").style.display = "none"; progressBar("100", "No firmware found for this device", "#ff6666"); } - else{ - var item2 = serialResultsDiv.innerHTML; - z = Array.from(new Set(item2.split(";"))).toString(); - - if (z.indexOf("FW=") > 0){ - const latest_fw_provided = hex_fw.split("_"); - var latest_fw = latest_fw_provided[2].toUpperCase(); - console.log(latest_fw); - var element = document.getElementById("Device_output"); - console.log(element); - - if (z.indexOf(latest_fw) > 0){ - readBar.innerHTML = 'Latest Firmware already on device'; + else { + var element = document.getElementById("Device_output"); + + //COMPARE commitCODE from DEVICE with RETURNED CODE FROM API + if (commitCode.toUpperCase() == upgraded_version.toUpperCase()){ + readBar.innerHTML = 'Latest Firmware already on device'; - if (typeof(element) != 'undefined' && element != null) - { - document.getElementById("Device_output").style.display = "none"; - } + if (typeof(element) != 'undefined' && element != null) + { + document.getElementById("Device_output").style.display = "none"; } - else { - readBar.innerHTML = 'Firmware available'; - - if (typeof(element) != 'undefined' && element != null){ - document.getElementById("Device_output").style.display = "block"; - } - } + else { + readBar.innerHTML = 'Firmware available'; + + if (typeof(element) != 'undefined' && element != null){ + document.getElementById("Device_output").style.display = "block"; + } } } } diff --git a/catalog.php b/catalog.php index c9c86ec..9a208b5 100644 --- a/catalog.php +++ b/catalog.php @@ -28,18 +28,40 @@ $search = isset($_GET['search']) ? '&search='.$_GET['search'] : ''; $url = 'index.php?page=catalog'.$search; //GET Details from URL $GET_VALUES = urlGETdetails($_GET) ?? ''; -//CALL TO API -$api_url = '/v2/catalog/'.$GET_VALUES; -$catalog = ioServer($api_url,''); -//Decode Payload -if (!empty($catalog)){$catalog = json_decode($catalog,true);}else{$catalog = null;} + +//Get all the categories from the database +$categories = ioServer('/v2/categories/',''); +$categories = json_decode($categories,true); + +//IF CATEGORY IS RECEIVED ONLY GET RELATED PRODUCTS +$url_input = ''; +if(isset($_GET['category']) && !isset($_POST['category'])){ + $url_input = 'category='.$_GET['category']; +} + +if (isset($_POST['category'])){ + + $filter_input = ''; + + foreach (array_keys($_POST['category']) as $cat_filter){ + $filter_input .= $cat_filter.','; + } + + if ($url_input != ''){ + $url_input = $url_input.','.substr($filter_input,0, -1); + + } else { + $url_input = 'category='.substr($filter_input,0, -1); + } +} + +//GET CATALOG DATA +$products = ioServer('/v2/catalog/'.$url_input,''); +$products = json_decode($products,true); //Return QueryTotal from API -$api_url = '/v2/products/'.$GET_VALUES.'&totals=&salesflag=1&status=1'; -$query_total = ioServer($api_url,''); - -//Decode Payload -if (!empty($query_total)){$query_total = json_decode($query_total,true);}else{$query_total = null;} +$query_total = ioServer('/v2/products/'.$GET_VALUES.'&totals=&salesflag=1&status=1',''); +$query_total = json_decode($query_total,true); template_header('Catalog', 'catalog','view'); $view = ' @@ -60,12 +82,182 @@ $view .= '
' . $description . '-
'.$stock_status.'
+ '; + + /*if (free_shipment_indicator){ + $shipment = freeShipment($product_price,'span'); + $view .= $shipment; + }*/ + $option_id =''; + $view .=' + '.(${$product['productname']} ?? $product['productname']).''; + + if (isset($product_price)){ + + $view .= ''.(($product_price != 0.00) ? number_format($product_price,2) : '').''; + + if (isset($product['rrp']) && $product['rrp'] > 0){ + $view .= ''.number_format($product['rrp'],2).''; + } + $view .= ''; + } + $view .= ' + +