CMXX - Upgrade products_software
This commit is contained in:
@@ -44,12 +44,16 @@ if(isset($get_content) && $get_content!=''){
|
|||||||
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list' || $v[0] =='history'|| $v[0] =='success_msg'){
|
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list' || $v[0] =='history'|| $v[0] =='success_msg'){
|
||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
|
elseif ($v[0] == 'rowid') {
|
||||||
|
//build up search
|
||||||
|
$clause .= ' AND ps.rowID = :'.$v[0];
|
||||||
|
}
|
||||||
elseif ($v[0] == 'search') {
|
elseif ($v[0] == 'search') {
|
||||||
//build up search
|
//build up search
|
||||||
$clause .= ' AND productcode like :'.$v[0];
|
$clause .= ' AND p.productcode like :'.$v[0];
|
||||||
}
|
}
|
||||||
else {//create clause
|
else {//create clause
|
||||||
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($whereclause == '' && $clause !=''){
|
if ($whereclause == '' && $clause !=''){
|
||||||
@@ -59,82 +63,138 @@ if(isset($get_content) && $get_content!=''){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//ENSURE PRODUCTROWID IS SEND
|
|
||||||
if (isset($criterias['productrowid']) && $criterias['productrowid'] != ''){
|
|
||||||
|
|
||||||
//CHECK IF ALLOWED TO CRUD VERSIONS
|
//Define Query
|
||||||
$sql = "SELECT * FROM products WHERE rowID = ? '.$whereclause.'";
|
if(isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||||
$stmt = $pdo->prepare($sql);
|
//Request for total rows
|
||||||
$stmt->execute([$criterias['productrowid']]);
|
$sql = 'SELECT count(*) as count FROM products_software '.$whereclause.'';
|
||||||
$product_data = $stmt->fetch();
|
}
|
||||||
$product_owner = ($product_data['rowID'])? 1 : 0;
|
elseif (isset($criterias['list']) && $criterias['list'] =='') {
|
||||||
|
//SQL for Paging
|
||||||
//IF PRODUCT IS OWNED THEN CRUD is ALLOWED
|
$sql = 'SELECT p.productcode, ps.* FROM products p JOIN products_software ps ON p.rowID = ps.productrowid '.$whereclause.'';
|
||||||
if ($product_owner === 1 ){
|
}
|
||||||
|
else {
|
||||||
|
//SQL for Paging
|
||||||
|
$sql = 'SELECT p.productcode, ps.* FROM products p JOIN products_software ps ON p.rowID = ps.productrowid '.$whereclause.'';
|
||||||
|
}
|
||||||
|
|
||||||
//Define Query
|
$stmt = $pdo->prepare($sql);
|
||||||
if(isset($criterias['totals']) && $criterias['totals'] ==''){
|
|
||||||
//Request for total rows
|
|
||||||
$sql = 'SELECT count(*) as count FROM products_software '.$whereclause.'';
|
|
||||||
}
|
|
||||||
elseif (isset($criterias['list']) && $criterias['list'] =='') {
|
|
||||||
//SQL for Paging
|
|
||||||
$sql = 'SELECT * FROM products_software '.$whereclause.'';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//SQL for Paging
|
|
||||||
$sql = 'SELECT * FROM products_software '.$whereclause.'';
|
|
||||||
}
|
|
||||||
|
|
||||||
$stmt = $pdo->prepare($sql);
|
//Bind to query
|
||||||
|
if (str_contains($whereclause, ':condition')){
|
||||||
|
$stmt->bindValue('condition', $condition, PDO::PARAM_STR);
|
||||||
|
}
|
||||||
|
|
||||||
//Bind to query
|
if (!empty($criterias)){
|
||||||
if (str_contains($whereclause, ':condition')){
|
foreach ($criterias as $key => $value){
|
||||||
$stmt->bindValue('condition', $condition, PDO::PARAM_STR);
|
$key_condition = ':'.$key;
|
||||||
}
|
if (str_contains($whereclause, $key_condition)){
|
||||||
|
if ($key == 'search'){
|
||||||
if (!empty($criterias)){
|
$search_value = '%'.$value.'%';
|
||||||
foreach ($criterias as $key => $value){
|
$stmt->bindValue($key, $search_value, PDO::PARAM_STR);
|
||||||
$key_condition = ':'.$key;
|
}
|
||||||
if (str_contains($whereclause, $key_condition)){
|
else {
|
||||||
if ($key == 'search'){
|
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
||||||
$search_value = '%'.$value.'%';
|
|
||||||
$stmt->bindValue($key, $search_value, PDO::PARAM_STR);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add paging details
|
|
||||||
if(isset($criterias['totals']) && $criterias['totals']==''){
|
|
||||||
$stmt->execute();
|
|
||||||
$messages = $stmt->fetch();
|
|
||||||
$messages = $messages[0];
|
|
||||||
}
|
|
||||||
elseif(isset($criterias['list']) && $criterias['list']==''){
|
|
||||||
//Excute Query
|
|
||||||
$stmt->execute();
|
|
||||||
//Get results
|
|
||||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
|
|
||||||
//$stmt->bindValue('page', ($current_page - 1) * $page_rows_products, PDO::PARAM_INT);
|
|
||||||
//$stmt->bindValue('num_products', $page_rows_products, PDO::PARAM_INT);
|
|
||||||
|
|
||||||
//Excute Query
|
|
||||||
$stmt->execute();
|
|
||||||
//Get results
|
|
||||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
}
|
|
||||||
//Encrypt results
|
|
||||||
$messages = generate_payload($messages);
|
|
||||||
|
|
||||||
//Send results
|
|
||||||
echo $messages;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Add paging details
|
||||||
|
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||||
|
$stmt->execute();
|
||||||
|
$messages = $stmt->fetch();
|
||||||
|
$messages = $messages[0];
|
||||||
|
}
|
||||||
|
elseif(isset($criterias['list']) && $criterias['list']==''){
|
||||||
|
//Excute Query
|
||||||
|
$stmt->execute();
|
||||||
|
//Get results
|
||||||
|
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
|
||||||
|
//$stmt->bindValue('page', ($current_page - 1) * $page_rows_products, PDO::PARAM_INT);
|
||||||
|
//$stmt->bindValue('num_products', $page_rows_products, PDO::PARAM_INT);
|
||||||
|
|
||||||
|
//Excute Query
|
||||||
|
$stmt->execute();
|
||||||
|
//Get results
|
||||||
|
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
}
|
||||||
|
|
||||||
|
// IF PRODUCTCODE AND VERSION IS SEND ASSUME SOFTWARE REQUEST
|
||||||
|
if (!isset($criterias['productrowid']) && isset($criterias['productcode']) && $criterias['productcode'] != '' && isset($criterias['version'])){
|
||||||
|
|
||||||
|
//CHECK IF VERSION IS LATEST
|
||||||
|
$latest_check = 0;
|
||||||
|
foreach ($messages as $message){
|
||||||
|
if ($message['latest'] == 1){
|
||||||
|
$output = array(
|
||||||
|
"productcode" => $message['productcode'],
|
||||||
|
"version"=> $message['version'],
|
||||||
|
"mandatory"=> $message['mandatory'],
|
||||||
|
"latest"=> $message['latest'],
|
||||||
|
"software"=> $message['software'],
|
||||||
|
"source" => "",
|
||||||
|
"source_type" => ""
|
||||||
|
);
|
||||||
|
$latest_check = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($latest_check == 0){
|
||||||
|
//GET LATEST BASED ON PRODUCTCODE
|
||||||
|
$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
|
||||||
|
$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);
|
||||||
|
|
||||||
|
if (!empty($file)){
|
||||||
|
//GET FILE EXTENTION
|
||||||
|
$ext = strtolower(pathinfo($file[0], PATHINFO_EXTENSION));
|
||||||
|
if ($ext == 'hex'){
|
||||||
|
//GET SOURCE CODE
|
||||||
|
$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
|
||||||
|
$output = array(
|
||||||
|
"productcode" => $message['productcode'],
|
||||||
|
"version"=> $message['version'],
|
||||||
|
"mandatory"=> $message['mandatory'],
|
||||||
|
"latest"=> $message['latest'],
|
||||||
|
"software"=> $message['software'],
|
||||||
|
"source" => $file_contents,
|
||||||
|
"source_type" => $source_type
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$messages = $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Encrypt results
|
||||||
|
$messages = generate_payload($messages);
|
||||||
|
|
||||||
|
//Send results
|
||||||
|
echo $messages;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -53,6 +53,7 @@ if (isset($post_content['productrowid']) && $post_content['productrowid'] != '')
|
|||||||
$input_insert = '';
|
$input_insert = '';
|
||||||
|
|
||||||
if ($command == 'insert'){
|
if ($command == 'insert'){
|
||||||
|
$post_content['latest'] = 1; //New software is always latest
|
||||||
$post_content['created'] = $date;
|
$post_content['created'] = $date;
|
||||||
$post_content['createdby'] = $username;
|
$post_content['createdby'] = $username;
|
||||||
}
|
}
|
||||||
@@ -86,9 +87,17 @@ if (isset($post_content['productrowid']) && $post_content['productrowid'] != '')
|
|||||||
$stmt->execute($execute_input);
|
$stmt->execute($execute_input);
|
||||||
}
|
}
|
||||||
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
|
||||||
|
$sql = 'UPDATE products_software SET latest = 0 WHERE productrowid = ?';
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
$stmt->execute([$post_content['productrowid']]);
|
||||||
|
|
||||||
|
//INSERT NEW ITEM
|
||||||
$sql = 'INSERT INTO products_software ('.$clause_insert.') VALUES ('.$input_insert.')';
|
$sql = 'INSERT INTO products_software ('.$clause_insert.') VALUES ('.$input_insert.')';
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute($execute_input);
|
$stmt->execute($execute_input);
|
||||||
|
|
||||||
}
|
}
|
||||||
elseif ($command == 'delete' && isAllowed('products_software',$profile,$permission,'D') === 1){
|
elseif ($command == 'delete' && isAllowed('products_software',$profile,$permission,'D') === 1){
|
||||||
$stmt = $pdo->prepare('DELETE FROM products_software WHERE rowID = ? '.$whereclause.'');
|
$stmt = $pdo->prepare('DELETE FROM products_software WHERE rowID = ? '.$whereclause.'');
|
||||||
|
|||||||
@@ -1,10 +1,36 @@
|
|||||||
<?php
|
<?php
|
||||||
defined($security_key) or exit;
|
defined($security_key) or exit;
|
||||||
|
|
||||||
|
ini_set('display_errors', '1');
|
||||||
|
ini_set('display_startup_errors', '1');
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
// Products_software
|
// Products
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
|
|
||||||
|
//Connect to DB
|
||||||
|
$pdo = dbConnect($dbname);
|
||||||
|
|
||||||
|
//SoldTo is empty
|
||||||
|
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||||
|
|
||||||
|
//default whereclause
|
||||||
|
$whereclause = '';
|
||||||
|
|
||||||
|
switch ($permission) {
|
||||||
|
case '4':
|
||||||
|
$whereclause = '';
|
||||||
|
break;
|
||||||
|
case '3':
|
||||||
|
$whereclause = '';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||||
|
$whereclause = 'WHERE p.accounthierarchy like "'.$condition.'"';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
//NEW ARRAY
|
//NEW ARRAY
|
||||||
$criterias = [];
|
$criterias = [];
|
||||||
$clause = '';
|
$clause = '';
|
||||||
@@ -18,57 +44,161 @@ if(isset($get_content) && $get_content!=''){
|
|||||||
$v = explode("=", $y);
|
$v = explode("=", $y);
|
||||||
//INCLUDE VARIABLES IN ARRAY
|
//INCLUDE VARIABLES IN ARRAY
|
||||||
$criterias[$v[0]] = $v[1];
|
$criterias[$v[0]] = $v[1];
|
||||||
|
|
||||||
|
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list' || $v[0] =='history'|| $v[0] =='success_msg'){
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
elseif ($v[0] == 'rowid') {
|
||||||
|
//build up search
|
||||||
|
$clause .= ' AND ps.rowID = :'.$v[0];
|
||||||
|
}
|
||||||
|
elseif ($v[0] == 'search') {
|
||||||
|
//build up search
|
||||||
|
$clause .= ' AND p.productcode like :'.$v[0];
|
||||||
|
}
|
||||||
|
else {//create clause
|
||||||
|
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if ($whereclause == '' && $clause !=''){
|
||||||
|
$whereclause = 'WHERE '.substr($clause, 4);
|
||||||
|
} else {
|
||||||
|
$whereclause .= $clause;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Define Query
|
||||||
|
if(isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||||
|
//Request for total rows
|
||||||
|
$sql = 'SELECT count(*) as count FROM products_software '.$whereclause.'';
|
||||||
|
}
|
||||||
|
elseif (isset($criterias['list']) && $criterias['list'] =='') {
|
||||||
|
//SQL for Paging
|
||||||
|
$sql = 'SELECT p.productcode, ps.* FROM products p JOIN products_software ps ON p.rowID = ps.productrowid '.$whereclause.'';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//SQL for Paging
|
||||||
|
$sql = 'SELECT p.productcode, ps.* FROM products p JOIN products_software ps ON p.rowID = ps.productrowid '.$whereclause.'';
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if productcode and product_version are send
|
$stmt = $pdo->prepare($sql);
|
||||||
if (isset($criterias['productcode']) && $criterias['productcode'] != '' && isset($criterias['version'])){
|
|
||||||
|
|
||||||
//Connect to DB
|
//Bind to query
|
||||||
$pdo = dbConnect($dbname);
|
if (str_contains($whereclause, ':condition')){
|
||||||
|
$stmt->bindValue('condition', $condition, PDO::PARAM_STR);
|
||||||
|
}
|
||||||
|
|
||||||
//SQL for Paging
|
if (!empty($criterias)){
|
||||||
$sql = 'SELECT * FROM products_software pv JOIN products p ON pv.productrowid = p.rowID WHERE p.productcode = ? AND pv.version = ? AND pv.status = "1"';
|
foreach ($criterias as $key => $value){
|
||||||
$stmt = $pdo->prepare($sql);
|
$key_condition = ':'.$key;
|
||||||
//Excute Query
|
if (str_contains($whereclause, $key_condition)){
|
||||||
$stmt->execute([$criterias['productcode'],$criterias['version']]);
|
if ($key == 'search'){
|
||||||
//Get results
|
$search_value = '%'.$value.'%';
|
||||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$stmt->bindValue($key, $search_value, PDO::PARAM_STR);
|
||||||
|
}
|
||||||
foreach ($messages as $message){
|
else {
|
||||||
|
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
||||||
//CHECK IF FIRMWARE FILE IS AVAILABLE
|
|
||||||
$software_file = dirname(__FILE__,4)."/firmware/".$message['software'];
|
|
||||||
$file = glob($software_file, GLOB_BRACE);
|
|
||||||
|
|
||||||
if (!empty($file)){
|
|
||||||
//GET FILE EXTENTION
|
|
||||||
$ext = strtolower(pathinfo($file[0], PATHINFO_EXTENSION));
|
|
||||||
if ($ext == 'hex'){
|
|
||||||
//GET SOURCE CODE
|
|
||||||
$file_contents = file_get_contents($software_file);
|
|
||||||
//REMOVE RETURN \R
|
|
||||||
$file_contents = str_replace("\r", '',$file_contents);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//PROVIDE URL TO FILE
|
|
||||||
$file_contents = 'https://'.$_SERVER['SERVER_NAME'].'/firmware'.'/'.$message['software'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = array("hw_version"=> $message['version'], "HEX_FW"=> $message['software'], "Firmware" => $file_contents);
|
|
||||||
|
|
||||||
//------------------------------------------
|
|
||||||
//JSON_ENCODE
|
|
||||||
//------------------------------------------
|
|
||||||
$output = json_encode($output, JSON_UNESCAPED_UNICODE);
|
|
||||||
|
|
||||||
//Send results
|
|
||||||
echo $output;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Add paging details
|
||||||
|
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||||
|
$stmt->execute();
|
||||||
|
$messages = $stmt->fetch();
|
||||||
|
$messages = $messages[0];
|
||||||
|
}
|
||||||
|
elseif(isset($criterias['list']) && $criterias['list']==''){
|
||||||
|
//Excute Query
|
||||||
|
$stmt->execute();
|
||||||
|
//Get results
|
||||||
|
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
http_response_code(404);
|
//$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
|
||||||
|
//$stmt->bindValue('page', ($current_page - 1) * $page_rows_products, PDO::PARAM_INT);
|
||||||
|
//$stmt->bindValue('num_products', $page_rows_products, PDO::PARAM_INT);
|
||||||
|
|
||||||
|
//Excute Query
|
||||||
|
$stmt->execute();
|
||||||
|
//Get results
|
||||||
|
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IF PRODUCTCODE AND VERSION IS SEND ASSUME SOFTWARE REQUEST
|
||||||
|
if (!isset($criterias['productrowid']) && isset($criterias['productcode']) && $criterias['productcode'] != '' && isset($criterias['version'])){
|
||||||
|
|
||||||
|
//CHECK IF VERSION IS LATEST
|
||||||
|
$latest_check = 0;
|
||||||
|
foreach ($messages as $message){
|
||||||
|
if ($message['latest'] == 1){
|
||||||
|
$output = array(
|
||||||
|
"productcode" => $message['productcode'],
|
||||||
|
"version"=> $message['version'],
|
||||||
|
"mandatory"=> $message['mandatory'],
|
||||||
|
"latest"=> $message['latest'],
|
||||||
|
"software"=> $message['software'],
|
||||||
|
"source" => "",
|
||||||
|
"source_type" => ""
|
||||||
|
);
|
||||||
|
$latest_check = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($latest_check == 0){
|
||||||
|
//GET LATEST BASED ON PRODUCTCODE
|
||||||
|
$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
|
||||||
|
$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);
|
||||||
|
|
||||||
|
if (!empty($file)){
|
||||||
|
//GET FILE EXTENTION
|
||||||
|
$ext = strtolower(pathinfo($file[0], PATHINFO_EXTENSION));
|
||||||
|
if ($ext == 'hex'){
|
||||||
|
//GET SOURCE CODE
|
||||||
|
$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
|
||||||
|
$output = array(
|
||||||
|
"productcode" => $message['productcode'],
|
||||||
|
"version"=> $message['version'],
|
||||||
|
"mandatory"=> $message['mandatory'],
|
||||||
|
"latest"=> $message['latest'],
|
||||||
|
"software"=> $message['software'],
|
||||||
|
"source" => $file_contents,
|
||||||
|
"source_type" => $source_type
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$messages = $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Encrypt results
|
||||||
|
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||||
|
|
||||||
|
//Send results
|
||||||
|
echo $messages;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -53,6 +53,7 @@ if (isset($post_content['productrowid']) && $post_content['productrowid'] != '')
|
|||||||
$input_insert = '';
|
$input_insert = '';
|
||||||
|
|
||||||
if ($command == 'insert'){
|
if ($command == 'insert'){
|
||||||
|
$post_content['latest'] = 1; //New software is always latest
|
||||||
$post_content['created'] = $date;
|
$post_content['created'] = $date;
|
||||||
$post_content['createdby'] = $username;
|
$post_content['createdby'] = $username;
|
||||||
}
|
}
|
||||||
@@ -86,6 +87,13 @@ if (isset($post_content['productrowid']) && $post_content['productrowid'] != '')
|
|||||||
$stmt->execute($execute_input);
|
$stmt->execute($execute_input);
|
||||||
}
|
}
|
||||||
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
|
||||||
|
$sql = 'UPDATE products_software SET latest = 0 WHERE productrowid = ?';
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
$stmt->execute([$post_content['productrowid']]);
|
||||||
|
|
||||||
|
//INSERT NEW ITEM
|
||||||
$sql = 'INSERT INTO products_software ('.$clause_insert.') VALUES ('.$input_insert.')';
|
$sql = 'INSERT INTO products_software ('.$clause_insert.') VALUES ('.$input_insert.')';
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute($execute_input);
|
$stmt->execute($execute_input);
|
||||||
|
|||||||
10
product.php
10
product.php
@@ -48,7 +48,7 @@ $product_versions = ioServer($api_url,'');
|
|||||||
//Decode Payload
|
//Decode Payload
|
||||||
if (!empty($product_versions)){$product_versions = decode_payload($product_versions);}else{$product_versions = null;}
|
if (!empty($product_versions)){$product_versions = decode_payload($product_versions);}else{$product_versions = null;}
|
||||||
|
|
||||||
//CALL TO API FOR Product_versions
|
//CALL TO API FOR Product_software
|
||||||
$api_url = '/v1/products_software/productrowid='.$_GET['rowID'];
|
$api_url = '/v1/products_software/productrowid='.$_GET['rowID'];
|
||||||
$product_software = ioServer($api_url,'');
|
$product_software = ioServer($api_url,'');
|
||||||
//Decode Payload
|
//Decode Payload
|
||||||
@@ -199,7 +199,7 @@ $view .= '
|
|||||||
|
|
||||||
$view .= '<div class="content-block">
|
$view .= '<div class="content-block">
|
||||||
<div class="block-header">
|
<div class="block-header">
|
||||||
<i class="fa-solid fa-bars fa-sm"></i>'.($product_software ?? '').'
|
<i class="fa-solid fa-bars fa-sm"></i>'.($product_version_software ?? '').'
|
||||||
<a href="index.php?page=products_software&productrowid='.$_GET['rowID'].'" class="btn2"> + </a>
|
<a href="index.php?page=products_software&productrowid='.$_GET['rowID'].'" class="btn2"> + </a>
|
||||||
</div>';
|
</div>';
|
||||||
if (!empty($product_software)){
|
if (!empty($product_software)){
|
||||||
@@ -212,6 +212,8 @@ $view .= '<div class="content-block">
|
|||||||
<th>'.$product_status.'</th>
|
<th>'.$product_status.'</th>
|
||||||
<th>'.$product_version_version.'</th>
|
<th>'.$product_version_version.'</th>
|
||||||
<th>'.$product_version_software .'</th>
|
<th>'.$product_version_software .'</th>
|
||||||
|
<th>'.ucfirst($register_mandatory).'</th>
|
||||||
|
<th>'.ucfirst($general_sort_type_3).'</th>
|
||||||
<th>'.$general_actions.'</th>
|
<th>'.$general_actions.'</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -223,7 +225,9 @@ $view .= '<div class="content-block">
|
|||||||
<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->software.'</td>
|
<td>'.$version->software.'</td>
|
||||||
<td><a href="index.php?page=products_versions&productrowid='.$_GET['rowID'].'&rowID='.$version->rowID.'" class="btn_link">'.$general_view.'</a></td>
|
<td>'.(($version->mandatory == 1)? $general_yes: $general_no).'</td>
|
||||||
|
<td>'.(($version->latest == 1)? $general_yes: $general_no).'</td>
|
||||||
|
<td><a href="index.php?page=products_software&productrowid='.$_GET['rowID'].'&rowID='.$version->rowID.'" class="btn_link">'.$general_view.'</a></td>
|
||||||
</tr>';
|
</tr>';
|
||||||
}
|
}
|
||||||
$view .= '
|
$view .= '
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
defined(page_security_key) or exit;
|
defined(page_security_key) or exit;
|
||||||
|
|
||||||
$page = 'products_versions';
|
$page = 'products_software';
|
||||||
//Check if allowed
|
//Check if allowed
|
||||||
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
|
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
|
||||||
header('location: index.php');
|
header('location: index.php');
|
||||||
@@ -13,7 +13,7 @@ $delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],
|
|||||||
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
|
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
|
||||||
|
|
||||||
// Default input product values
|
// Default input product values
|
||||||
$products_versions = [
|
$products_software = [
|
||||||
'rowID' => '',
|
'rowID' => '',
|
||||||
'productrowid' => '',
|
'productrowid' => '',
|
||||||
'status' => '',
|
'status' => '',
|
||||||
@@ -21,7 +21,8 @@ $products_versions = [
|
|||||||
'software' => '',
|
'software' => '',
|
||||||
'created' => '',
|
'created' => '',
|
||||||
'createdby' => $_SESSION['username'],
|
'createdby' => $_SESSION['username'],
|
||||||
'measurement' => '',
|
'mandatory' => '',
|
||||||
|
'latest' => ''
|
||||||
];
|
];
|
||||||
|
|
||||||
//productrowid is required by api
|
//productrowid is required by api
|
||||||
@@ -36,7 +37,7 @@ if (isset($_GET['rowID'])) {
|
|||||||
//Decode Payload
|
//Decode Payload
|
||||||
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;}
|
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;}
|
||||||
|
|
||||||
$products_versions = json_decode(json_encode($responses[0]), true);
|
$products_software = json_decode(json_encode($responses[0]), true);
|
||||||
|
|
||||||
|
|
||||||
if ($update_allowed === 1){
|
if ($update_allowed === 1){
|
||||||
@@ -182,24 +183,37 @@ $view .= '<div class="content-block tab-content active">
|
|||||||
<div class="form responsive-width-100">
|
<div class="form responsive-width-100">
|
||||||
<label for="status">'.$product_status.'</label>
|
<label for="status">'.$product_status.'</label>
|
||||||
<select id="status" name="status">
|
<select id="status" name="status">
|
||||||
<option value="1" '.($products_versions['status']==1?' selected':'').'>'.$prod_status_1 .'</option>
|
<option value="1" '.($products_software['status']==1?' selected':'').'>'.$prod_status_1 .'</option>
|
||||||
<option value="0" '.($products_versions['status']==0?' selected':'').'>'.$prod_status_0 .'</option>
|
<option value="0" '.($products_software['status']==0?' selected':'').'>'.$prod_status_0 .'</option>
|
||||||
</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_versions['version'].'" required>
|
<input id="name" type="text" name="version" placeholder="'.$product_version_version.'" value="'.$products_software['version'].'" required>
|
||||||
|
';
|
||||||
|
if ($products_software['software'] !=''){
|
||||||
|
$view .= '
|
||||||
<label for=""><i class="required">*</i>'.$product_version_software.'</label>
|
<label for=""><i class="required">*</i>'.$product_version_software.'</label>
|
||||||
<input id="name" type="text" name="software" placeholder="'.$product_version_software.'" value="'.$products_versions['software'].'">
|
<input id="name" type="text" name="software" placeholder="'.$product_version_software.'" value="'.$products_software['software'].'">
|
||||||
|
';
|
||||||
<label for=""><i class="required">*</i>'.ucfirst($register_mandatory).'</label>
|
}
|
||||||
|
$view .= ' <label for=""><i class="required">*</i>'.ucfirst($register_mandatory).'</label>
|
||||||
<select id="mandatory" name="mandatory">
|
<select id="mandatory" name="mandatory">
|
||||||
<option value="0" '.($products_software['mandatory']==0?' selected':'').'>'.$general_no.'</option>
|
<option value="0" '.($products_software['mandatory']==0?' selected':'').'>'.$general_no.'</option>
|
||||||
<option value="1" '.($products_software['mandatory']==1?' selected':'').'>'.$general_yes.'</option>
|
<option value="1" '.($products_software['mandatory']==1?' selected':'').'>'.$general_yes.'</option>
|
||||||
</select>
|
</select>';
|
||||||
|
|
||||||
|
if ($products_software['software'] !=''){
|
||||||
|
$view .= '
|
||||||
|
<label for=""><i class="required">*</i>'.ucfirst($general_sort_type_3).'</label>
|
||||||
|
<select id="latest" name="latest">
|
||||||
|
<option value="0" '.($products_software['latest']==0?' selected':'').'>'.$general_no.'</option>
|
||||||
|
<option value="1" '.($products_software['latest']==1?' selected':'').'>'.$general_yes.'</option>
|
||||||
|
</select>
|
||||||
|
';
|
||||||
|
}
|
||||||
|
$view .= '
|
||||||
<label for=""></label>
|
<label for=""></label>
|
||||||
<input type="file" name="fileToUpload" id="fileToUpload" accept=".hex, .HEX, .bin,.BIN,.exe,.EXE" style="width: 30%;padding: 50px 0 0 0;height: 10px;">
|
<input type="file" name="fileToUpload" id="fileToUpload" accept=".hex, .HEX, .bin,.BIN,.exe,.EXE" style="width: 30%;padding: 50px 0 0 0;height: 10px;">
|
||||||
<input type="hidden" name="rowID" value="'.$products_versions['rowID'].'">
|
<input type="hidden" name="rowID" value="'.$products_software['rowID'].'">
|
||||||
<input type="hidden" name="productrowid" value="'.$productrowid.'">
|
<input type="hidden" name="productrowid" value="'.$productrowid.'">
|
||||||
</div>
|
</div>
|
||||||
</div>';
|
</div>';
|
||||||
@@ -207,9 +221,9 @@ $view .= '<div class="content-block tab-content active">
|
|||||||
$view .= '<div class="content-block tab-content">
|
$view .= '<div class="content-block tab-content">
|
||||||
<div class="form responsive-width-100">
|
<div class="form responsive-width-100">
|
||||||
<label for="productcode">'.$general_created.'</label>
|
<label for="productcode">'.$general_created.'</label>
|
||||||
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.$products_versions['created'].'" readonly>
|
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.$products_software['created'].'" readonly>
|
||||||
<label for="productcode">'.$general_createdby.'</label>
|
<label for="productcode">'.$general_createdby.'</label>
|
||||||
<input id="name" type="text" name="" placeholder="'.$general_createdby.'" value="'.$products_versions['createdby'].'" readonly>
|
<input id="name" type="text" name="" placeholder="'.$general_createdby.'" value="'.$products_software['createdby'].'" readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>';
|
</div>';
|
||||||
$view .= '</form>';
|
$view .= '</form>';
|
||||||
|
|||||||
Reference in New Issue
Block a user