CMXX - Add service init Analogvoltage
This commit is contained in:
164
api/v1/get/equipment_data.php
Normal file
164
api/v1/get/equipment_data.php
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
<?php
|
||||||
|
defined($security_key) or exit;
|
||||||
|
|
||||||
|
//------------------------------------------
|
||||||
|
// Equipment_data
|
||||||
|
//------------------------------------------
|
||||||
|
|
||||||
|
//Connect to DB
|
||||||
|
$pdo = dbConnect($dbname);
|
||||||
|
|
||||||
|
//Get user_rights from users.php
|
||||||
|
$partner = json_decode($partnerhierarchy);
|
||||||
|
|
||||||
|
//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;
|
||||||
|
case '2':
|
||||||
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||||
|
$whereclause = 'WHERE e.accounthierarchy like :condition ';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
||||||
|
$whereclause = 'WHERE e.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] =='products' || $v[0] =='totals' || $v[0] =='history' || $v[0] =='success_msg' || $v[0] =='download' || $v[0] =='sort'){
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
elseif ($v[0] == 'serialnumber') {
|
||||||
|
//build up serialnumber
|
||||||
|
//check if multiple serialnumbers are provided
|
||||||
|
if (str_contains($v[1], ',')){
|
||||||
|
$inputs = explode(",",$v[1]);
|
||||||
|
$new_querystring = ''; //empty querystring
|
||||||
|
$x=0;
|
||||||
|
foreach($inputs as $input){
|
||||||
|
//create key
|
||||||
|
$new_key = $v[0].'_'.$x;
|
||||||
|
//inject new key/value to array
|
||||||
|
$criterias[$new_key] = $input;
|
||||||
|
$new_querystring .= ':'.$new_key.',';
|
||||||
|
$x++;
|
||||||
|
}
|
||||||
|
//remove obsolete last character from new_querystring
|
||||||
|
$new_querystring = substr($new_querystring,0, -1);
|
||||||
|
//add new_querystring to clause
|
||||||
|
$clause .= ' AND e.serialnumber IN ('.$new_querystring.')';
|
||||||
|
//remove original key/value from array
|
||||||
|
unset($criterias[$v[0]]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$clause .= ' AND e.serialnumber IN (:'.$v[0].')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {//create clause
|
||||||
|
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($whereclause == '' && $clause !=''){
|
||||||
|
$whereclause = 'WHERE '.substr($clause, 4);
|
||||||
|
} else {
|
||||||
|
$whereclause .= $clause;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||||
|
//Request for total rows
|
||||||
|
$sql = 'SELECT count(*) as count from equipment_data ed '.$whereclause.'';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//SQL for Paging
|
||||||
|
$sql = 'SELECT e.productrowid, e.hw_version, e.serialnumber, ed.rowID, ed.equipmentid, ed.measurement, ed.historyid from equipment e JOIN equipment_data ed ON e.rowID = ed.equipmentid '.$whereclause.' ORDER BY ed.equipmentid, ed.historyid ASC';
|
||||||
|
}
|
||||||
|
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
elseif ($key == 'p'){
|
||||||
|
//Do nothing (bug)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------
|
||||||
|
// Debuglog
|
||||||
|
//------------------------------------------
|
||||||
|
if (debug){
|
||||||
|
$message = $date.';'.$sql.';'.$username;
|
||||||
|
debuglog($message);
|
||||||
|
}
|
||||||
|
//------------------------------------------
|
||||||
|
//Add paging details
|
||||||
|
//------------------------------------------
|
||||||
|
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||||
|
$stmt->execute();
|
||||||
|
$messages = $stmt->fetch();
|
||||||
|
$messages = $messages[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
|
||||||
|
//$stmt->bindValue('page', ($current_page - 1) * $page_rows_equipment, PDO::PARAM_INT);
|
||||||
|
//$stmt->bindValue('num_products', $page_rows_equipment, 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;
|
||||||
|
|
||||||
|
?>
|
||||||
164
api/v2/get/equipment_data.php
Normal file
164
api/v2/get/equipment_data.php
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
<?php
|
||||||
|
defined($security_key) or exit;
|
||||||
|
|
||||||
|
//------------------------------------------
|
||||||
|
// Equipment_data
|
||||||
|
//------------------------------------------
|
||||||
|
|
||||||
|
//Connect to DB
|
||||||
|
$pdo = dbConnect($dbname);
|
||||||
|
|
||||||
|
//Get user_rights from users.php
|
||||||
|
$partner = json_decode($partnerhierarchy);
|
||||||
|
|
||||||
|
//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;
|
||||||
|
case '2':
|
||||||
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||||
|
$whereclause = 'WHERE e.accounthierarchy like :condition ';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
||||||
|
$whereclause = 'WHERE e.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] =='products' || $v[0] =='totals' || $v[0] =='history' || $v[0] =='success_msg' || $v[0] =='download' || $v[0] =='sort'){
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
elseif ($v[0] == 'serialnumber') {
|
||||||
|
//build up serialnumber
|
||||||
|
//check if multiple serialnumbers are provided
|
||||||
|
if (str_contains($v[1], ',')){
|
||||||
|
$inputs = explode(",",$v[1]);
|
||||||
|
$new_querystring = ''; //empty querystring
|
||||||
|
$x=0;
|
||||||
|
foreach($inputs as $input){
|
||||||
|
//create key
|
||||||
|
$new_key = $v[0].'_'.$x;
|
||||||
|
//inject new key/value to array
|
||||||
|
$criterias[$new_key] = $input;
|
||||||
|
$new_querystring .= ':'.$new_key.',';
|
||||||
|
$x++;
|
||||||
|
}
|
||||||
|
//remove obsolete last character from new_querystring
|
||||||
|
$new_querystring = substr($new_querystring,0, -1);
|
||||||
|
//add new_querystring to clause
|
||||||
|
$clause .= ' AND e.serialnumber IN ('.$new_querystring.')';
|
||||||
|
//remove original key/value from array
|
||||||
|
unset($criterias[$v[0]]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$clause .= ' AND e.serialnumber IN (:'.$v[0].')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {//create clause
|
||||||
|
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($whereclause == '' && $clause !=''){
|
||||||
|
$whereclause = 'WHERE '.substr($clause, 4);
|
||||||
|
} else {
|
||||||
|
$whereclause .= $clause;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||||
|
//Request for total rows
|
||||||
|
$sql = 'SELECT count(*) as count from equipment_data ed '.$whereclause.'';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//SQL for Paging
|
||||||
|
$sql = 'SELECT e.productrowid, e.hw_version, e.serialnumber, ed.rowID, ed.equipmentid, ed.measurement, ed.historyid from equipment e JOIN equipment_data ed ON e.rowID = ed.equipmentid '.$whereclause.' ORDER BY ed.equipmentid, ed.historyid ASC';
|
||||||
|
}
|
||||||
|
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
elseif ($key == 'p'){
|
||||||
|
//Do nothing (bug)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------
|
||||||
|
// Debuglog
|
||||||
|
//------------------------------------------
|
||||||
|
if (debug){
|
||||||
|
$message = $date.';'.$sql.';'.$username;
|
||||||
|
debuglog($message);
|
||||||
|
}
|
||||||
|
//------------------------------------------
|
||||||
|
//Add paging details
|
||||||
|
//------------------------------------------
|
||||||
|
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||||
|
$stmt->execute();
|
||||||
|
$messages = $stmt->fetch();
|
||||||
|
$messages = $messages[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
|
||||||
|
//$stmt->bindValue('page', ($current_page - 1) * $page_rows_equipment, PDO::PARAM_INT);
|
||||||
|
//$stmt->bindValue('num_products', $page_rows_equipment, 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;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -33,7 +33,9 @@ $init = array(
|
|||||||
"AnalogVoltageCP_0_NEG_Max"=> -11.5,
|
"AnalogVoltageCP_0_NEG_Max"=> -11.5,
|
||||||
"AnalogVoltageCP_0_NEG_Min"=> -12.5,
|
"AnalogVoltageCP_0_NEG_Min"=> -12.5,
|
||||||
"AnalogVoltageCP_2K74_POS_Max"=> 9.2,
|
"AnalogVoltageCP_2K74_POS_Max"=> 9.2,
|
||||||
"AnalogVoltageCP_2K74_POS_Min"=> 8.7
|
"AnalogVoltageCP_2K74_POS_Min"=> 8.7,
|
||||||
|
"AnalogVoltagePP_EP_Off_Max"=>0.3,
|
||||||
|
"AnalogVoltagePP_EP_Off_Min"=>-0.5
|
||||||
),
|
),
|
||||||
"ATM"=> array(
|
"ATM"=> array(
|
||||||
"batteryVoltage_Max"=> 4.9,
|
"batteryVoltage_Max"=> 4.9,
|
||||||
@@ -51,7 +53,9 @@ $init = array(
|
|||||||
"AnalogVoltageCP_0_NEG_Max"=> -11.5,
|
"AnalogVoltageCP_0_NEG_Max"=> -11.5,
|
||||||
"AnalogVoltageCP_0_NEG_Min"=> -12.5,
|
"AnalogVoltageCP_0_NEG_Min"=> -12.5,
|
||||||
"AnalogVoltageCP_2K74_POS_Max"=> 9.2,
|
"AnalogVoltageCP_2K74_POS_Max"=> 9.2,
|
||||||
"AnalogVoltageCP_2K74_POS_Min"=> 8.7
|
"AnalogVoltageCP_2K74_POS_Min"=> 8.7,
|
||||||
|
"AnalogVoltagePP_EP_Off_Max"=>0.3,
|
||||||
|
"AnalogVoltagePP_EP_Off_Min"=>-0.5
|
||||||
),
|
),
|
||||||
"ManualURL"=> "https://lms.tss-learning.com/course/view.php?id=60",
|
"ManualURL"=> "https://lms.tss-learning.com/course/view.php?id=60",
|
||||||
"termsURL"=> "https://emergency-plug.com/en/terms-and-conditions",
|
"termsURL"=> "https://emergency-plug.com/en/terms-and-conditions",
|
||||||
|
|||||||
46
test.php
46
test.php
@@ -9,41 +9,25 @@ include './settings/config.php';
|
|||||||
include_once './settings/translations/translations_US.php';
|
include_once './settings/translations/translations_US.php';
|
||||||
include_once './settings/systemfirmware.php';
|
include_once './settings/systemfirmware.php';
|
||||||
|
|
||||||
$pdo = dbConnect($dbname);
|
|
||||||
$sql = 'SELECT * FROM contracts WHERE status = 1';
|
|
||||||
$stmt = $pdo->prepare($sql);
|
|
||||||
$stmt->execute();
|
|
||||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
foreach ($messages as $message){
|
//define('standard_profile','dashboard,profile,equipments,equipment,histories,history,servicereports,servicereport,firmwaretool,application');
|
||||||
//Calculate contract end date
|
|
||||||
$end_date = date('Y-m-d', strtotime('+'.$message['duration'].' months', strtotime($message['start_date'])));
|
|
||||||
|
|
||||||
//Validate if contract end date is in the past change contact status to closed and set users to not active
|
$allviews = ["dashboard","profile","equipments","equipment","equipmentmanage","equipment_item"];
|
||||||
if (date("Y-m-d") > $end_date){
|
|
||||||
//Contract expired -> change status to closed (2)
|
|
||||||
$sql = 'UPDATE contracts SET status = ? WHERE rowID = ?';
|
|
||||||
$stmt = $pdo->prepare($sql);
|
|
||||||
$stmt->execute([2,$message['rowID']]);
|
|
||||||
|
|
||||||
//CHECK FOR ASSIGNED USER END SET SERVICE TO INACTIVE
|
$admin_profile = ["dashboard","profile","equipments","equipment"];
|
||||||
foreach (json_decode($message['assigned_users']) as $user_assigned){
|
|
||||||
|
|
||||||
//CALL TO API FOR General information
|
$view = '<html><form action="" method="post">';
|
||||||
$clientsecret = createCommunicationToken($_SESSION['userkey']);
|
|
||||||
$responses = ioApi('/v2/users/username='.$user_assigned,'',$clientsecret);
|
|
||||||
|
|
||||||
if (!empty($responses)){
|
foreach ($allviews as $view){
|
||||||
$response = json_decode($responses,true);
|
|
||||||
//If response is not null update the service flag of the user
|
if (in_array($view,$admin_profile)){
|
||||||
if (count($response) != 0){
|
$view .= '<input type="checkbox" id="'.$view.'" name="" value="'.$view.'" checked>';
|
||||||
$id_exist_user = $response[0]['id'];
|
} else {
|
||||||
$sql = 'UPDATE users SET service = ? WHERE id = ? ';
|
$view .= '<input type="checkbox" id="'.$view.'" name="profile[]" value="'.$view.'">';
|
||||||
$stmt = $pdo->prepare($sql);
|
|
||||||
//Remove serviceflag from user when status is Closed
|
|
||||||
$stmt->execute(['',$id_exist_user]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
$view .= '<input type="submit" name="submit" value="Save" class="btn">';
|
||||||
|
$view .= '</form></html>';
|
||||||
|
|
||||||
|
echo $view;
|
||||||
Reference in New Issue
Block a user