CMXX - Firmware improvement
This commit is contained in:
128
api/v2/get/products.php
Normal file
128
api/v2/get/products.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// 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 accounthierarchy like "'.$condition.'"';
|
||||
break;
|
||||
}
|
||||
|
||||
//NEW ARRAY
|
||||
$criterias = [];
|
||||
$clause = '';
|
||||
|
||||
//Check for $_GET variables and build up clause
|
||||
if(isset($get_content) && $get_content!=''){
|
||||
//GET VARIABLES FROM URL
|
||||
$requests = explode("&", $get_content);
|
||||
//Check for keys and values
|
||||
foreach ($requests as $y){
|
||||
$v = explode("=", $y);
|
||||
//INCLUDE VARIABLES IN ARRAY
|
||||
$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] == 'search') {
|
||||
//build up search
|
||||
$clause .= ' AND 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 '.$whereclause.'';
|
||||
}
|
||||
elseif (isset($criterias['list']) && $criterias['list'] =='') {
|
||||
//SQL for Paging
|
||||
$sql = 'SELECT * FROM products '.$whereclause.'';
|
||||
}
|
||||
else {
|
||||
//SQL for Paging
|
||||
$sql = 'SELECT * FROM products '.$whereclause.' LIMIT :page,:num_products';
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
//Bind to query
|
||||
if (str_contains($whereclause, ':condition')){
|
||||
$stmt->bindValue('condition', $condition, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
if (!empty($criterias)){
|
||||
foreach ($criterias as $key => $value){
|
||||
$key_condition = ':'.$key;
|
||||
if (str_contains($whereclause, $key_condition)){
|
||||
if ($key == 'search'){
|
||||
$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);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_ENCODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//Send results
|
||||
echo $messages;
|
||||
|
||||
?>
|
||||
66
api/v2/get/products_software.php
Normal file
66
api/v2/get/products_software.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Products_software
|
||||
//------------------------------------------
|
||||
|
||||
//NEW ARRAY
|
||||
$criterias = [];
|
||||
$clause = '';
|
||||
|
||||
//Check for $_GET variables and build up clause
|
||||
if(isset($get_content) && $get_content!=''){
|
||||
//GET VARIABLES FROM URL
|
||||
$requests = explode("&", $get_content);
|
||||
//Check for keys and values
|
||||
foreach ($requests as $y){
|
||||
$v = explode("=", $y);
|
||||
//INCLUDE VARIABLES IN ARRAY
|
||||
$criterias[$v[0]] = $v[1];
|
||||
}
|
||||
}
|
||||
|
||||
//check if productcode and product_version are send
|
||||
if (isset($criterias['productcode']) && $criterias['productcode'] != '' && isset($criterias['version'])){
|
||||
|
||||
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//SQL for Paging
|
||||
$sql = 'SELECT * FROM products_versions pv JOIN products p ON pv.productrowid = p.rowID WHERE p.productcode = ? AND pv.version = ? AND pv.status = "1"';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
//Excute Query
|
||||
$stmt->execute([$criterias['productcode'],$criterias['version']]);
|
||||
//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'].'.HEX';
|
||||
if (file_exists($software_file)){
|
||||
//GET SOURCE CODE
|
||||
$file_contents = file_get_contents($software_file);
|
||||
} else {
|
||||
$file_contents = '';
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
http_response_code(404);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -41,6 +41,23 @@ 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)){
|
||||
//READ FILE
|
||||
$contents = file_get_contents($_FILES["fileToUpload"]["tmp_name"]);
|
||||
//firmwarename
|
||||
$firmware_name = pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_FILENAME);
|
||||
//Filename
|
||||
$target_dir = dirname(__FILE__)."/firmware/";
|
||||
$input_file = $target_dir . $firmware_name.'.HEX';
|
||||
//store firmware file
|
||||
file_put_contents($input_file, $contents);
|
||||
//Use firmwarefile name as software version
|
||||
$_POST['software'] = $firmware_name;
|
||||
}
|
||||
|
||||
//GET ALL POST DATA
|
||||
$data = json_encode($_POST, JSON_UNESCAPED_UNICODE);
|
||||
//Secure data
|
||||
@@ -78,6 +95,25 @@ if (isset($_GET['rowID'])) {
|
||||
} else {
|
||||
// Create a new product
|
||||
if (isset($_POST['submit']) && $create_allowed === 1) {
|
||||
|
||||
//CHECK FOR FIRMWARE FILE
|
||||
$firmware_file = $_FILES["fileToUpload"]["name"] ?? '';
|
||||
|
||||
//FIRMWARE FILE UPLOADED
|
||||
if($firmware_file !='' || !empty($firmware_file)){
|
||||
//READ FILE
|
||||
$contents = file_get_contents($_FILES["fileToUpload"]["tmp_name"]);
|
||||
//firmwarename
|
||||
$firmware_name = pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_FILENAME);
|
||||
//Filename
|
||||
$target_dir = dirname(__FILE__)."/firmware/";
|
||||
$input_file = $target_dir . $firmware_name.'.HEX';
|
||||
//store firmware file
|
||||
file_put_contents($input_file, $contents);
|
||||
//Use firmwarefile name as software version
|
||||
$_POST['software'] = $firmware_name.'.HEX';
|
||||
}
|
||||
|
||||
//GET ALL POST DATA
|
||||
$data = json_encode($_POST , JSON_UNESCAPED_UNICODE);
|
||||
//Secure data
|
||||
@@ -97,7 +133,7 @@ if (isset($_GET['rowID'])) {
|
||||
template_header('Products versions', 'products_versions', 'manage');
|
||||
|
||||
$view ='
|
||||
<form action="" method="post">
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
||||
<h2 class="responsive-width-100">'.$product_version_version.'</h2>
|
||||
<a href="index.php?page=product&rowID='.$productrowid.'" class="btn alt mar-right-2">'.$button_cancel.'</a>
|
||||
@@ -130,6 +166,11 @@ $view .= '<div class="content-block tab-content active">
|
||||
|
||||
<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'].'" required>
|
||||
|
||||
<label for=""></label>
|
||||
<input type="file" name="fileToUpload" id="fileToUpload" accept=".hex, .HEX" style="width: 30%;padding: 50px 0 0 0;height: 10px;">
|
||||
|
||||
|
||||
';
|
||||
|
||||
if (isset($_GET['rowID']) && $_GET['rowID'] !='' && !empty($products_versions['measurement'])){
|
||||
|
||||
@@ -32,6 +32,7 @@ $all_views = [
|
||||
"buildtool",
|
||||
"products",
|
||||
"products_versions",
|
||||
"products_software",
|
||||
"product",
|
||||
"product_manage",
|
||||
"servicereports",
|
||||
|
||||
@@ -519,6 +519,7 @@ main .content-block {
|
||||
padding: 15px;
|
||||
box-shadow: 0px 0px 5px 1px rgba(0, 0, 0, 0.03);
|
||||
overflow: hidden;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
main .content-block .block-header {
|
||||
@@ -554,6 +555,7 @@ main .content-block-wrapper {
|
||||
main .content-block-wrapper .content-block {
|
||||
width: 100%;
|
||||
margin: 0 10px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
main .content-block-wrapper .content-block:first-child {
|
||||
@@ -617,6 +619,7 @@ main .dashboard .stat {
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-flow: wrap;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
main .dashboard .stat > i {
|
||||
@@ -2546,6 +2549,7 @@ input[type='file'] {
|
||||
display: block;
|
||||
background-color: #2FAC66;
|
||||
animation: draw 1s ease-in-out;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.chart span::before{
|
||||
|
||||
Reference in New Issue
Block a user