From b2601ff32bcc7d4e9493d1c13a8f8e3cf4ffdb0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CVeLiTi=E2=80=9D?= <“info@veliti.nl”> Date: Mon, 6 May 2024 12:32:47 +0200 Subject: [PATCH] CIM71 - Add related users to assest, CIM72 Add related users to accounts --- account.php | 16 ++- api/v1/get/communications.php | 8 ++ api/v1/get/users.php | 8 ++ assets/readdevice.js | 105 +++++++++--------- cartest_manage.php | 127 ++++++++++++++++++++++ cartests.php | 2 +- communication.php | 5 +- communications.php | 12 +- contracts.php | 11 +- equipment.php | 24 +++- settings/translations/translations_NL.php | 2 + settings/translations/translations_US.php | 2 + user.php | 2 +- users.php | 7 ++ 14 files changed, 267 insertions(+), 64 deletions(-) create mode 100644 cartest_manage.php diff --git a/account.php b/account.php index b037b63..212a49c 100644 --- a/account.php +++ b/account.php @@ -235,13 +235,27 @@ $view .= '
'; $soldto_id = explode("-",$account_hierarchy->soldto) ?? ''; + +//DISPLAY RELATED COMMUNICATION RECORDS +$view_communication = ''; +if ($_SESSION['permission'] == 3 || $_SESSION['permission'] == 4){ + $view_communication = ' '.$button_partner_assigned_communication.''; +} + +//DISPLAY RELATED USERS +$view_users =''; +if ($_SESSION['permission'] == 3 || $_SESSION['permission'] == 4){ + $view_users = ' '.$button_partner_assigned_users.''; +} + $view .= '
'.$view_asset_actions.'
'.$button_partner_assigned_equipment.' '.$button_partner_assigned_contracts.' - + '.$view_communication.' + '.$view_users.'
'; //OUTPUT diff --git a/api/v1/get/communications.php b/api/v1/get/communications.php index 50cb443..0025932 100644 --- a/api/v1/get/communications.php +++ b/api/v1/get/communications.php @@ -48,6 +48,10 @@ if(isset($get_content) && $get_content!=''){ //build up search $clause .= ' AND email like :'.$v[0]; } + elseif ($v[0] == 'partnerid') { + //check partnerID related records + $clause .= ' AND partnerID like :'.$v[0]; + } else {//create clause $clause .= ' AND '.$v[0].' = :'.$v[0]; } @@ -87,6 +91,10 @@ if (!empty($criterias)){ $search_value = '%'.$value.'%'; $stmt->bindValue($key, $search_value, PDO::PARAM_STR); } + elseif ($key == 'partnerid'){ + $search_value = $value.'-%'; + $stmt->bindValue($key, $search_value, PDO::PARAM_STR); + } else { $stmt->bindValue($key, $value, PDO::PARAM_STR); } diff --git a/api/v1/get/users.php b/api/v1/get/users.php index 06c5071..0c35a49 100644 --- a/api/v1/get/users.php +++ b/api/v1/get/users.php @@ -51,6 +51,10 @@ if(isset($get_content) && $get_content!=''){ //build up search $clause .= ' AND username like :'.$v[0]; } + elseif ($v[0] == 'partnerid') { + //check accounthierarchy related users + $clause .= ' AND partnerhierarchy like :'.$v[0]; + } else {//create clause $clause .= ' AND '.$v[0].' = :'.$v[0]; } @@ -86,6 +90,10 @@ if (!empty($criterias)){ $search_value = '%'.$value.'%'; $stmt->bindValue($key, $search_value, PDO::PARAM_STR); } + elseif ($key == 'partnerid'){ + $search_value = '%"_"'.$value.'-%'; + $stmt->bindValue($key, $search_value, PDO::PARAM_STR); + } else { $stmt->bindValue($key, $value, PDO::PARAM_STR); } diff --git a/assets/readdevice.js b/assets/readdevice.js index 171daa8..3346194 100644 --- a/assets/readdevice.js +++ b/assets/readdevice.js @@ -8,9 +8,9 @@ const VPP1 = []; //for VPP1 values const VPP2 = []; //for VPP2 values const VBAT = []; //for VBAT values const PWM = []; //for PWM values +const STATE = []; //for STATE values const xChart = []; //x-axis chart values - function progressBar(percentage, message, color){ var readbar = document.getElementById("readBar"); readBar.style.background = color; @@ -238,14 +238,13 @@ const serialResultsDiv = document.getElementById("serialResults"); async function appendToTerminal(newStuff) { serialResultsDiv.innerHTML += newStuff; - + serialOutput +=newStuff } function renderChart(){ var test = serialResultsDiv.innerHTML.split(";"); - console.log(test) test.forEach(getData); const xValues = xChart; new Chart("chart_VCP", { @@ -263,6 +262,26 @@ function renderChart(){ data: VBAT, borderColor: "black", fill: false + },{ + label: "VPP1", + data: VPP1, + borderColor: "green", + fill: false + },{ + label: "VPP2", + data: VPP2, + borderColor: "blue", + fill: false + },{ + label: "PWM", + data: PWM, + backgroundColor: "yellow", + fill: false + },{ + label: "STATE", + data: STATE, + backgroundColor: "purple", + fill: false } ] }, @@ -270,75 +289,57 @@ function renderChart(){ legend: {display: true} } }); - - - new Chart("chart_VPP", { - type: "line", - data: { - labels: xValues, - datasets: [{ - label: "VPP1", - data: VPP1, - borderColor: "green", - fill: false - }, { - label: "VPP2", - data: VPP2, - borderColor: "blue", - fill: false - }, - ] - }, - options: { - legend: {display: true} - } - }); - - new Chart("chart_PWM", { - type: "bar", - data: { - labels: xValues, - datasets: [{ - label: "PWM", - data: PWM, - backgroundColor: "yellow", - fill: false - } - ] - }, - options: { - legend: {display: true} - } - }); - } //Get the RAW data and turn into object function getData(item) { + let item_array = item.split("="); let xaxis = xChart.length + 1; if (item_array[0] == "VCP"){ - VCP.push(item_array[1]) + let vcp = item_array[1] / 1000000; + VCP.push(vcp) xChart.push(xaxis); } if (item_array[0] == "VPP1"){ - VPP1.push(item_array[1]) + let vpp1 = item_array[1] / 1000000; + VPP1.push(vpp1) } if (item_array[0] == "VPP2"){ - VPP2.push(item_array[1]) + let vpp2 = item_array[1] / 1000000; + VPP2.push(vpp2) } if (item_array[0] == "VBAT"){ - VBAT.push(item_array[1]) + let vbat = item_array[1] / 1000000; + VBAT.push(vbat) + } + if (item_array[0] == "STATE"){ + let state + switch (item_array[1]) { + case 'FULL_CONNECT': + state = 5; + break; + case 'REACTIVATE': + state = 3; + break; + case 'WAIT_CONNECT': + state = -5; + break; + case 'DISCONNECTED': + state = 0; + break; + } + STATE.push(state) } if (item_array[0] == "PWM") { - var check_return = item_array[1].match(/[^\r\n]+/g); - console.log(check_return, check_return[0]) + var check_return = item_array[1].match(/[^\r\n]+/g); if (check_return.length == 2){ - PWM.push(check_return[0]) + let pwm = check_return[0] / 10; + PWM.push(pwm) + } } - } } async function closePort(){ diff --git a/cartest_manage.php b/cartest_manage.php new file mode 100644 index 0000000..128b6ca --- /dev/null +++ b/cartest_manage.php @@ -0,0 +1,127 @@ +prepare($sql); +//Excute Query +$stmt->execute(); +//Get results +$messages = $stmt->fetchAll(PDO::FETCH_ASSOC); + +template_header('Buildtool', 'buildtool','view'); + +$view = ' +
+
+ +
+

'.$buildtool_h2 .'

+

'.$buildtool_p.'

+
+
+
'; + +$view .= ' +
+ '.$button_cancel.' +
+'; + +$view .= '
+
+ 25:00 +
+ + +
+
+ + + +
+
+
+
+
+
+
+

STATE: -5 = WAIT_CONNECT, 0 = DISCONNECTED, 3 = REACTIVATE, 5 = FULL_CONNECT

+
+ +
+
+
+
+ +'; + + +//OUTPUT +echo $view; + +//ADD JS FILES +echo ' + + + + + +'; + + + +template_footer(); +?> \ No newline at end of file diff --git a/cartests.php b/cartests.php index 3116c9b..9acf16a 100644 --- a/cartests.php +++ b/cartests.php @@ -76,7 +76,7 @@ $view .= '
$view .= '
'; if ($create_allowed ===1){ - $view .= ''.$button_create_cartest.''; + $view .= ''.$button_create_cartest.''; } $view .= '
diff --git a/communication.php b/communication.php index 4169a78..8d8d721 100644 --- a/communication.php +++ b/communication.php @@ -1,10 +1,7 @@ '.$button_back.'':''; + //Check if allowed -if (isAllowed('communications',$_SESSION['profile'],$_SESSION['permission'],'R') === 0){ +if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){ header('location: index.php'); exit; } @@ -64,6 +69,7 @@ $view = '

'.$communication_p.'

+ '.$back_btn_orgin.' '; if (isset($success_msg)){ diff --git a/contracts.php b/contracts.php index 1f4cff2..3330d12 100644 --- a/contracts.php +++ b/contracts.php @@ -9,8 +9,16 @@ if (debug && debug_id == $_SESSION['id']){ include_once './assets/functions.php'; include_once './settings/settings.php'; + +//SET PAGE ORIGIN FOR NAVIGATION AND SECURITY +$prev_page = ($_SESSION['origin'] == 'equipments') ? $_SESSION['prev_origin_equipment'] : (($_SESSION['origin'] == 'account')? $_SESSION['prev_origin'] :''); +$page = 'contracts'; + +//create backbutton to prev_origin +$back_btn_orgin = ($prev_page != '')? ''.$button_back.'':''; + //Check if allowed -if (isAllowed('contracts',$_SESSION['profile'],$_SESSION['permission'],'R') === 0){ +if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){ header('location: index.php'); exit; } @@ -58,6 +66,7 @@ $view = '

'.$contract_p .'

+ '.$back_btn_orgin.' '; if (isset($success_msg)){ diff --git a/equipment.php b/equipment.php index 69801fb..2cb65e5 100644 --- a/equipment.php +++ b/equipment.php @@ -10,6 +10,8 @@ if (debug && debug_id == $_SESSION['id']){ include_once './assets/functions.php'; include_once './settings/settings.php'; +//SET ORIGIN FOR NAVIGATION +$_SESSION['prev_origin_equipment'] = $_SERVER['REQUEST_URI']; $page = 'equipment'; //Check if allowed if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){ @@ -276,11 +278,31 @@ if ($update_allowed === 1){ '; } +//DISPLAY RELATED COMMUNICATION RECORDS +$soldto_id = explode("-",$partner_data->soldto) ?? ''; +$shipto_id = explode("-",$partner_data->shipto) ?? ''; + +$partner_users_id = ($shipto_id[0] != '')? $shipto_id[0] : (($soldto_id[0] != '')? $soldto_id[0] : 1); + +$view_communication = ''; +if ($partner_users_id != 1 && ($_SESSION['permission'] == 3 || $_SESSION['permission'] == 4)){ + $view_communication = ' '.$button_partner_assigned_communication.''; +} + +//DISPLAY RELATED USERS +$view_users =''; +if ($partner_users_id != 1 && ($_SESSION['permission'] == 3 || $_SESSION['permission'] == 4)){ + $view_users = ' '.$button_partner_assigned_users.''; +} + $view .= '
'.$view_asset_actions.'
- '.$button_history.''; + '.$button_history.' + '.$view_communication.' + '.$view_users.' + '; if ($update_allowed === 1){ diff --git a/settings/translations/translations_NL.php b/settings/translations/translations_NL.php index ea39450..1cc875e 100644 --- a/settings/translations/translations_NL.php +++ b/settings/translations/translations_NL.php @@ -73,6 +73,8 @@ $button_create_communication = 'Maak communicatie'; $button_create_account = 'Maak klant'; $button_partner_assigned_equipment = 'Gerelateerde activa'; $button_partner_assigned_contracts = 'Gerelateerde contracten'; +$button_partner_assigned_communication = 'Gerelateerde communicatie'; +$button_partner_assigned_users = 'Gerelateerde gebruikers'; $button_create_contract = 'Maak contract'; $button_create_communication_send = 'Firmware communicatie'; $button_create_cartest = 'Maak autotest'; diff --git a/settings/translations/translations_US.php b/settings/translations/translations_US.php index 588165a..b496405 100644 --- a/settings/translations/translations_US.php +++ b/settings/translations/translations_US.php @@ -73,6 +73,8 @@ $button_create_communication = 'Create communication'; $button_create_account = 'Create account'; $button_partner_assigned_equipment = 'Related assets'; $button_partner_assigned_contracts = 'Related contracts'; +$button_partner_assigned_communication = 'Related communication'; +$button_partner_assigned_users = 'Related users'; $button_create_contract = 'Create contract'; $button_create_communication_send = 'Firmware communication'; $button_create_cartest = 'Create cartest'; diff --git a/user.php b/user.php index 33e22a3..cda01ba 100644 --- a/user.php +++ b/user.php @@ -175,7 +175,7 @@ $view .= '
- + diff --git a/users.php b/users.php index e191556..b3a2595 100644 --- a/users.php +++ b/users.php @@ -8,7 +8,13 @@ defined(page_security_key) or exit; include_once './assets/functions.php'; include_once './settings/settings.php'; +//SET PAGE ORIGIN FOR NAVIGATION AND SECURITY +$prev_page = ($_SESSION['origin'] == 'equipments') ? $_SESSION['prev_origin_equipment'] : (($_SESSION['origin'] == 'account')?$_SESSION['prev_origin'] :''); $page = 'users'; + +//create backbutton to prev_origin +$back_btn_orgin = ($prev_page != '')? ''.$button_back.'':''; + //Check if allowed if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){ header('location: index.php'); @@ -64,6 +70,7 @@ $view = '

'.$users_p.'

+ '.$back_btn_orgin.' '; if (isset($success_msg)){