Merge branch 'development'
This commit is contained in:
@@ -65,7 +65,7 @@ if(isset($get_content) && $get_content!=''){
|
||||
$v = explode("=", $y);
|
||||
//INCLUDE VARIABLES IN ARRAY
|
||||
$criterias[$v[0]] = $v[1];
|
||||
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='history' || $v[0] =='target' || $v[0] =='success_msg'){
|
||||
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='between' || $v[0] =='totals' || $v[0] =='history' || $v[0] =='target' || $v[0] =='success_msg'){
|
||||
//do nothing
|
||||
}
|
||||
elseif ($v[0] == 'serialnumber') {
|
||||
@@ -89,15 +89,42 @@ if(isset($get_content) && $get_content!=''){
|
||||
$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].')';
|
||||
}
|
||||
}
|
||||
elseif ($v[0] == 'ignore') {
|
||||
//build up serialnumbers to ignore
|
||||
//check if multiple serialnumbers are provided
|
||||
if (str_contains($v[1], ',')){
|
||||
$inputs = explode(",",$v[1]);
|
||||
$x=0;
|
||||
foreach($inputs as $input){
|
||||
//create key
|
||||
$new_key = $v[0].'_'.$x;
|
||||
//inject new key/value to array
|
||||
$criterias[$new_key] = '%serialnumber%'.$input.'%';
|
||||
$clause .= ' AND h.description not like :'.$new_key.'';
|
||||
$x++;
|
||||
}
|
||||
//remove original key/value from array
|
||||
unset($criterias[$v[0]]);
|
||||
}
|
||||
else {
|
||||
$criterias[$v[0]] = '%serialnumber%'.$v[1].'%';
|
||||
$clause .= ' AND h.description not like :'.$v[0].'';
|
||||
}
|
||||
}
|
||||
else {//create clause
|
||||
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
||||
}
|
||||
}
|
||||
if (isset($criterias['between']) && $criterias['between'] !=''){
|
||||
//ADD BETWEEN STATEMENT IF BETWEEN IS IN URL
|
||||
//BETWEEN delim ||
|
||||
$clause .= ' AND (h.created BETWEEN :start AND :end)';
|
||||
}
|
||||
if ($whereclause == '' && $clause !=''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
} else {
|
||||
@@ -221,6 +248,13 @@ if (!empty($criterias)){
|
||||
if (str_contains($whereclause, $key_condition)){
|
||||
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
||||
}
|
||||
//CHECK IF BETWEEN STATEMENT IS SENT
|
||||
if (str_contains($whereclause, ':start') && str_contains($whereclause, ':end')){
|
||||
//DATES ARE DELIM WITH ||
|
||||
$dates = explode("||", $value);
|
||||
$stmt->bindValue('start', $dates[0], PDO::PARAM_STR);
|
||||
$stmt->bindValue('end', $dates[1], PDO::PARAM_STR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,11 @@ if (isset($post_content['assigned_users'])){
|
||||
$post_content['assigned_users'] = array_map('trim', $post_content['assigned_users']);
|
||||
$post_content['assigned_users'] = array_filter($post_content['assigned_users'], 'strlen');
|
||||
}
|
||||
if (isset($post_content['ignore_list'])){
|
||||
$post_content['ignore_list'] = array_map('trim', $post_content['ignore_list']);
|
||||
$post_content['ignore_list'] = array_filter($post_content['ignore_list'], 'strlen');
|
||||
}
|
||||
|
||||
if ($id != ''){
|
||||
|
||||
//DEFINE ACCOUNTHIERARCHY
|
||||
@@ -165,6 +170,13 @@ if ($command == 'insert' && !isset($post_content['delete'])){
|
||||
if (isset($post_content['servicetool'])){
|
||||
$post_content['servicetool'] = json_encode($post_content['servicetool'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
if (isset($post_content['ignore_list'])){
|
||||
$post_content['ignore_list'] = json_encode($post_content['ignore_list'], JSON_UNESCAPED_UNICODE);
|
||||
//ONLY ADMINS ARE ALLOWED TO UPDATE IGNORE LIST
|
||||
if ($permission != 3 && $permission != 4){
|
||||
unset($post_content['ignore_list']);
|
||||
}
|
||||
}
|
||||
if (isset($post_content['assigned_users'])){
|
||||
//Check for all users in array if exist then update service or create
|
||||
foreach ($post_content['assigned_users'] as $user_assigned){
|
||||
@@ -177,10 +189,16 @@ if (isset($post_content['assigned_users'])){
|
||||
if (count($response) != 0){
|
||||
$id_exist_user = $response[0]['id'];
|
||||
$generate_service = bin2hex(random_bytes(25));
|
||||
//Remove serviceflag from user
|
||||
$sql = 'UPDATE users SET service = ? WHERE id = ? ';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$generate_service,$id_exist_user]);
|
||||
if (isset($post_content['status']) && $post_content['status'] != 2){
|
||||
//Add serviceflag from user
|
||||
$stmt->execute([$generate_service,$id_exist_user]);
|
||||
}
|
||||
else {
|
||||
//Remove serviceflag from user when status is Closed
|
||||
$stmt->execute(['',$id_exist_user]);
|
||||
}
|
||||
} else {
|
||||
//Decode the account structure of the contract and create user
|
||||
$ah_array = json_decode($post_content['accounthierarchy'],true);
|
||||
|
||||
310
api/v2/get/application.php
Normal file
310
api/v2/get/application.php
Normal file
@@ -0,0 +1,310 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Application related calls
|
||||
//------------------------------------------
|
||||
$action = $request[3] ?? '';
|
||||
|
||||
//------------------------------------------
|
||||
// Check for action & start application API
|
||||
//------------------------------------------
|
||||
if ($action !=''){
|
||||
|
||||
//------------------------------------------
|
||||
//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] =='between' || $v[0] =='totals' || $v[0] =='history' || $v[0] =='target' || $v[0] =='success_msg'){
|
||||
//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].')';
|
||||
}
|
||||
}
|
||||
elseif ($v[0] == 'ignore') {
|
||||
//build up serialnumbers to ignore
|
||||
//check if multiple serialnumbers are provided
|
||||
if (str_contains($v[1], ',')){
|
||||
$inputs = explode(",",$v[1]);
|
||||
$x=0;
|
||||
foreach($inputs as $input){
|
||||
//create key
|
||||
$new_key = $v[0].'_'.$x;
|
||||
//inject new key/value to array
|
||||
$criterias[$new_key] = '%serialnumber%'.$input.'%';
|
||||
$clause .= ' AND h.description not like :'.$new_key.'';
|
||||
$x++;
|
||||
}
|
||||
//remove original key/value from array
|
||||
unset($criterias[$v[0]]);
|
||||
}
|
||||
else {
|
||||
$criterias[$v[0]] = '%serialnumber%'.$v[1].'%';
|
||||
$clause .= ' AND h.description not like :'.$v[0].'';
|
||||
}
|
||||
}
|
||||
else {//create clause
|
||||
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
||||
}
|
||||
}
|
||||
if (isset($criterias['between']) && $criterias['between'] !=''){
|
||||
//ADD BETWEEN STATEMENT IF BETWEEN IS IN URL
|
||||
//BETWEEN delim ||
|
||||
$clause .= ' AND (h.created BETWEEN :start AND :end)';
|
||||
}
|
||||
if ($whereclause == '' && $clause !=''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
} else {
|
||||
$whereclause .= $clause;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// QUERY define query
|
||||
//------------------------------------------
|
||||
switch ($action) {
|
||||
case 'get_rowID':
|
||||
$sql = 'SELECT e.rowID, p.productcode, p.productname from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.'';
|
||||
break;
|
||||
|
||||
|
||||
case 'firmwareCommunication':
|
||||
if (isset($criterias['hw_version']) && $criterias['hw_version'] != ''){
|
||||
|
||||
include './settings/systemfirmware.php';
|
||||
|
||||
$target = $criterias['target'] ?? '0';
|
||||
|
||||
//FILTER VARIABLES FOR SQL
|
||||
$filter1 = 'soldto":"';
|
||||
$filter2 = '","shipto';
|
||||
$filter3 = 'shipto":"';
|
||||
$filter4 = '","location';
|
||||
|
||||
//ADD additional createria to whereclause (Firmware and Active)
|
||||
$whereclause .= " AND c.type_1='1' AND c.status='1' AND e.status != 5 AND (e.sw_version != '$FirmwarenameR06' OR e.sw_version != '$FirmwarenameR06A' OR e.sw_version != '$FirmwarenameR07A' OR e.sw_version != '$FirmwarenameR07B' OR e.sw_version != '$FirmwarenameR07' OR e.sw_version != '$FirmwarenameR08')";
|
||||
|
||||
//get target
|
||||
switch ($target) {
|
||||
case '0': // Both
|
||||
$onclause ="SUBSTRING_INDEX(SUBSTRING_INDEX(e.accounthierarchy, '$filter1', -1),'$filter2',1) = c.partnerID or SUBSTRING_INDEX(SUBSTRING_INDEX(e.accounthierarchy, '$filter3', -1),'$filter4',1) = c.partnerID";
|
||||
break;
|
||||
|
||||
case '1': // SoldTO only
|
||||
$onclause ="SUBSTRING_INDEX(SUBSTRING_INDEX(e.accounthierarchy, '$filter1', -1),'$filter2',1) = c.partnerID";
|
||||
break;
|
||||
|
||||
case '2': // ShipTO only
|
||||
$onclause =" SUBSTRING_INDEX(SUBSTRING_INDEX(e.accounthierarchy, '$filter3', -1),'$filter4',1) = c.partnerID";
|
||||
break;
|
||||
}
|
||||
|
||||
$sql = "SELECT e.sw_version, c.email from equipment e join communication c on $onclause $whereclause group by c.email";
|
||||
|
||||
}
|
||||
else {
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'serviceforecast':
|
||||
|
||||
$sql = 'SELECT YEAR(e.service_date) AS year, QUARTER(e.service_date) AS quarter, count(e.rowID) AS count FROM equipment e '.$whereclause.' GROUP BY YEAR(e.service_date), QUARTER(e.service_date)';
|
||||
|
||||
break;
|
||||
|
||||
case 'warrantyforecast':
|
||||
|
||||
$sql = 'SELECT YEAR(e.warranty_date) AS year, QUARTER(e.warranty_date) AS quarter, count(e.rowID) AS count FROM equipment e '.$whereclause.' GROUP BY YEAR(e.warranty_date), QUARTER(e.warranty_date)';
|
||||
|
||||
break;
|
||||
|
||||
case 'geolocation':
|
||||
|
||||
if ($whereclause == ''){
|
||||
$whereclause = 'WHERE geolocation is not null OR geolocation != "["",""]"';
|
||||
} else {
|
||||
$whereclause .= ' AND geolocation is not null OR geolocation != "["",""]';
|
||||
}
|
||||
$sql = 'SELECT distinct(geolocation) FROM equipment e '.$whereclause.'';
|
||||
|
||||
break;
|
||||
|
||||
case 'report_usage_servicereports':
|
||||
$sql = 'SELECT YEAR(h.created) AS year, QUARTER(h.created) AS quarter, MONTH(h.created) as month, count(h.rowID) AS count FROM history h LEFT JOIN equipment e ON h.equipmentid = e.rowID where h.type = "ServiceReport" AND NOT e.productrowid = "31" GROUP BY YEAR(h.created), QUARTER(h.created), MONTH(h.created)';
|
||||
break;
|
||||
|
||||
case 'contract_usage_servicereports':
|
||||
$sql = 'SELECT YEAR(h.created) AS year, QUARTER(h.created) AS quarter, MONTH(h.created) as month, count(h.rowID) AS count FROM history h LEFT JOIN equipment e ON h.equipmentid = e.rowID '.$whereclause.' GROUP BY YEAR(h.created), QUARTER(h.created), MONTH(h.created)';
|
||||
break;
|
||||
|
||||
case 'report_usage_firmware':
|
||||
$sql = 'SELECT YEAR(h.created) AS year,QUARTER(h.created) AS quarter, MONTH(h.created) as month, count(h.rowID) AS count FROM history h LEFT JOIN equipment e ON h.equipmentid=e.rowID where h.type="Firmware" AND NOT e.productrowid="31" GROUP BY YEAR(h.created),QUARTER(h.created), MONTH(h.created)';
|
||||
break;
|
||||
|
||||
case 'report_usage_warranty':
|
||||
$sql = 'SELECT YEAR(h.created) AS year, QUARTER(h.created) AS quarter, MONTH(h.created) as month, count(h.rowID) AS count FROM history h LEFT JOIN equipment e ON h.equipmentid = e.rowID where h.type = "Warranty" AND NOT e.productrowid = "31" GROUP BY YEAR(h.created), QUARTER(h.created), MONTH(h.created)';
|
||||
break;
|
||||
|
||||
case 'report_usage_other':
|
||||
$sql = 'SELECT YEAR(h.created) AS year, QUARTER(h.created) AS quarter, MONTH(h.created) as month, count(h.rowID) AS count FROM history h LEFT JOIN equipment e ON h.equipmentid = e.rowID where NOT h.type = "Warranty" OR NOT h.type = "Firmware" OR NOT h.type = "ServiceReport" GROUP BY YEAR(h.created), QUARTER(h.created), MONTH(h.created)';
|
||||
break;
|
||||
|
||||
case 'report_usage_equipment':
|
||||
$sql = 'SELECT YEAR(created) AS year, QUARTER(created) AS quarter, MONTH(created) as month, count(rowID) AS count FROM equipment GROUP BY YEAR(created), QUARTER(created), MONTH(created)';
|
||||
break;
|
||||
|
||||
case 'report_usage_changes':
|
||||
$sql = 'SELECT YEAR(created) AS year, QUARTER(created) AS quarter, MONTH(created) as month, count(rowID) AS count FROM changelog GROUP BY YEAR(created), QUARTER(created), MONTH(created)';
|
||||
break;
|
||||
|
||||
case 'report_usage_users':
|
||||
$sql = 'SELECT count(id) AS count FROM users WHERE NOT view = "3"';
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
//------------------------------------------
|
||||
// BIND VARIABELS
|
||||
//------------------------------------------
|
||||
if (!empty($criterias)){
|
||||
foreach ($criterias as $key => $value){
|
||||
$key_condition = ':'.$key;
|
||||
if (str_contains($whereclause, $key_condition)){
|
||||
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
||||
}
|
||||
//CHECK IF BETWEEN STATEMENT IS SENT
|
||||
if (str_contains($whereclause, ':start') && str_contains($whereclause, ':end')){
|
||||
//DATES ARE DELIM WITH ||
|
||||
$dates = explode("||", $value);
|
||||
$stmt->bindValue('start', $dates[0], PDO::PARAM_STR);
|
||||
$stmt->bindValue('end', $dates[1], PDO::PARAM_STR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//Excute Query
|
||||
//------------------------------------------
|
||||
$stmt->execute();
|
||||
|
||||
//------------------------------------------
|
||||
//Get results
|
||||
//------------------------------------------
|
||||
switch ($action) {
|
||||
case 'get_rowID':
|
||||
$messages = $stmt->fetch();
|
||||
break;
|
||||
|
||||
case 'report_usage_users':
|
||||
$messages = $stmt->fetch();
|
||||
break;
|
||||
|
||||
case 'firmwareCommunication':
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($result) {
|
||||
$messages = json_encode(array("firmware_scope"=> count($result)));
|
||||
}
|
||||
else {
|
||||
$messages = json_encode(array("firmware_scope"=> '0'));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
break;
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_ENCODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//Send results
|
||||
echo $messages;
|
||||
|
||||
|
||||
//------------------------------------------
|
||||
// END APPLICATION API
|
||||
//------------------------------------------
|
||||
}
|
||||
else
|
||||
{
|
||||
echo null;
|
||||
}
|
||||
|
||||
141
api/v2/get/history.php
Normal file
141
api/v2/get/history.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// History
|
||||
//------------------------------------------
|
||||
|
||||
//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;
|
||||
case '2':
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||
$whereclause = 'WHERE e.accounthierarchy like :condition AND (type = "'.$type1.'" or type = "'.$type2.'" or type = "'.$type3.'" or type = "'.$type9.'" or type = "'.$type14.'" or type = "'.$type16.'")';
|
||||
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 AND (type = "'.$type1.'" or type = "'.$type2.'" or type = "'.$type3.'" or type = "'.$type14.'" or type = "'.$type16.'")';
|
||||
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] =='history'){
|
||||
//do nothing
|
||||
}
|
||||
elseif ($v[0] == 'equipmentid' || $v[0] == 'equipmentID') {
|
||||
//build up search
|
||||
$clause .= ' AND e.rowID = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'historyid') {
|
||||
//build up search
|
||||
$clause .= ' AND h.rowID = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'status') {
|
||||
//Update status based on status
|
||||
$clause .= ' AND e.'.$v[0].' = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'search') {
|
||||
//build up search
|
||||
$clause .= ' AND (h.rowID like :'.$v[0].' OR h.createdby like :'.$v[0].')';
|
||||
}
|
||||
elseif ($v[0] == 'type' && $v[1] == 'servicereport') {
|
||||
//Filter out only relevant servicereports
|
||||
$filter_key_1 = '"%serialnumber%"';
|
||||
$filter_key_2 = '"ServiceReport"';
|
||||
$clause .= ' AND h.type = '.$filter_key_2.' AND h.description like '.$filter_key_1;
|
||||
}
|
||||
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(h.rowID) as historyID from history h LEFT JOIN equipment e ON h.equipmentid = e.rowID '.$whereclause.'';
|
||||
}
|
||||
else {
|
||||
//request history
|
||||
$sql ='SELECT h.rowID as historyID, e.rowID as equipmentID, e.serialnumber, h.type, h.description, h.created, h.createdby from history h LEFT JOIN equipment e ON h.equipmentid = e.rowID '.$whereclause.' ORDER BY h.created DESC LIMIT :page,:num_products';
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
//Bind to query
|
||||
if (str_contains($whereclause, ':status')){
|
||||
$stmt->bindValue('status', $status, PDO::PARAM_INT);
|
||||
}
|
||||
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];
|
||||
}
|
||||
else {
|
||||
$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
|
||||
$stmt->bindValue('page', ($current_page - 1) * $page_rows_history, PDO::PARAM_INT);
|
||||
$stmt->bindValue('num_products', $page_rows_history, 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;
|
||||
?>
|
||||
@@ -53,6 +53,11 @@ if (isset($post_content['assigned_users'])){
|
||||
$post_content['assigned_users'] = array_map('trim', $post_content['assigned_users']);
|
||||
$post_content['assigned_users'] = array_filter($post_content['assigned_users'], 'strlen');
|
||||
}
|
||||
if (isset($post_content['ignore_list'])){
|
||||
$post_content['ignore_list'] = array_map('trim', $post_content['ignore_list']);
|
||||
$post_content['ignore_list'] = array_filter($post_content['ignore_list'], 'strlen');
|
||||
}
|
||||
|
||||
if ($id != ''){
|
||||
|
||||
//DEFINE ACCOUNTHIERARCHY
|
||||
@@ -165,6 +170,14 @@ if ($command == 'insert' && !isset($post_content['delete'])){
|
||||
if (isset($post_content['servicetool'])){
|
||||
$post_content['servicetool'] = json_encode($post_content['servicetool'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
if (isset($post_content['ignore_list'])){
|
||||
$post_content['ignore_list'] = json_encode($post_content['ignore_list'], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//ONLY ADMINS ARE ALLOWED TO UPDATE IGNORE LIST
|
||||
if ($permission != 3 && $permission != 4){
|
||||
unset($post_content['ignore_list']);
|
||||
}
|
||||
}
|
||||
if (isset($post_content['assigned_users'])){
|
||||
//Check for all users in array if exist then update service or create
|
||||
foreach ($post_content['assigned_users'] as $user_assigned){
|
||||
@@ -177,10 +190,17 @@ if (isset($post_content['assigned_users'])){
|
||||
if (count($response) != 0){
|
||||
$id_exist_user = $response[0]['id'];
|
||||
$generate_service = bin2hex(random_bytes(25));
|
||||
//Remove serviceflag from user
|
||||
|
||||
$sql = 'UPDATE users SET service = ? WHERE id = ? ';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$generate_service,$id_exist_user]);
|
||||
if (isset($post_content['status']) && $post_content['status'] != 2){
|
||||
//Add serviceflag from user
|
||||
$stmt->execute([$generate_service,$id_exist_user]);
|
||||
}
|
||||
else {
|
||||
//Remove serviceflag from user when status is Closed
|
||||
$stmt->execute(['',$id_exist_user]);
|
||||
}
|
||||
} else {
|
||||
//Decode the account structure of the contract and create user
|
||||
$ah_array = json_decode($post_content['accounthierarchy'],true);
|
||||
|
||||
10
assets/analytics.js
Normal file
10
assets/analytics.js
Normal file
@@ -0,0 +1,10 @@
|
||||
var _paq = window._paq = window._paq || [];
|
||||
_paq.push(['trackPageView']);
|
||||
_paq.push(['enableLinkTracking']);
|
||||
(function() {
|
||||
var u="//analytics.veliti.nl/";
|
||||
_paq.push(['setTrackerUrl', u+'matomo.php']);
|
||||
_paq.push(['setSiteId', '3']);
|
||||
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
||||
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
|
||||
})();
|
||||
@@ -225,6 +225,11 @@ function template_header($title, $selected = 'assets', $selected_child = 'view')
|
||||
$profile = $general_profile;
|
||||
$logout = $general_logout;
|
||||
|
||||
$veliti_analytics = '';
|
||||
if (veliti_analytics){
|
||||
$veliti_analytics = '<script src="./assets/analytics.js"></script>';
|
||||
}
|
||||
|
||||
echo <<<EOT
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
@@ -238,6 +243,7 @@ echo <<<EOT
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.6.0/css/all.css">
|
||||
<script src="./assets/leaflet.js"></script>
|
||||
<script src="./assets/charts.js"></script>
|
||||
$veliti_analytics
|
||||
</head>
|
||||
<body class="admin">
|
||||
<aside class="responsive-width-100 responsive-hidden">
|
||||
@@ -2337,7 +2343,90 @@ function usageView($messages){
|
||||
|
||||
$view .='</ul>
|
||||
</div>
|
||||
';
|
||||
';
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// overview of service events per servicekit ++++++++++++++
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function usageBilling($messages){
|
||||
// Create an array to store sums by year, quarter, and month
|
||||
$totals = [];
|
||||
|
||||
// Loop through the data and aggregate the counts by year, quarter, and month
|
||||
foreach ($messages as $entry) {
|
||||
$year = $entry['year'];
|
||||
$quarter = $entry['quarter'];
|
||||
$dateObj = DateTime::createFromFormat('!m', $entry['month']);
|
||||
$month = $dateObj->format('F');
|
||||
$count = $entry['count'];
|
||||
|
||||
// Initialize arrays if not already set for year, quarter, and month
|
||||
if (!isset($totals[$year])) {
|
||||
$totals[$year] = ['total' => 0, 'quarters' => []];
|
||||
}
|
||||
|
||||
if (!isset($totals[$year]['quarters'][$quarter])) {
|
||||
$totals[$year]['quarters'][$quarter] = ['total' => 0, 'months' => []];
|
||||
}
|
||||
|
||||
if (!isset($totals[$year]['quarters'][$quarter]['months'][$month])) {
|
||||
$totals[$year]['quarters'][$quarter]['months'][$month] = 0;
|
||||
}
|
||||
|
||||
// Add count to the corresponding year, quarter, and month
|
||||
$totals[$year]['total'] += $count;
|
||||
$totals[$year]['quarters'][$quarter]['total'] += $count;
|
||||
$totals[$year]['quarters'][$quarter]['months'][$month] += $count;
|
||||
}
|
||||
|
||||
return $totals;
|
||||
}
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// close contract when expired +++++++++++++++
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function closeContract(){
|
||||
|
||||
include dirname(__FILE__,2).'/settings/settings.php';
|
||||
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//SELECT ALL ACTIVE CONTRACTS
|
||||
$sql = 'SELECT * FROM contracts WHERE status = 1';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($messages as $message){
|
||||
//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
|
||||
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
|
||||
foreach (json_decode($message['assigned_users']) as $user_assigned){
|
||||
|
||||
//check user exist
|
||||
$sql = 'SELECT * FROM users WHERE username = ?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$user_assigned]);
|
||||
$user_assigned = $stmt->fetch();
|
||||
|
||||
if (!empty($user_assigned)){
|
||||
$id_exist_user = $user_assigned['id'];
|
||||
$sql = 'UPDATE users SET service = ? WHERE id = ? ';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
//Remove serviceflag from user when status is Closed
|
||||
$stmt->execute(['',$id_exist_user]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
116
contract.php
116
contract.php
@@ -48,8 +48,11 @@ $responses = $responses[0];
|
||||
//------------------------------
|
||||
$contract_status_text = 'contract_status'.$responses->status ?? '';
|
||||
$contract_type_text = 'contract_type'.$responses->type ?? '';
|
||||
$contract_billingplan_text = 'contract_billing'.$responses->billing_plan ?? '';
|
||||
|
||||
$servicetools = json_decode($responses->servicetool,true) ?? '';
|
||||
$assigned_users = json_decode($responses->assigned_users,true) ?? '';
|
||||
$ignore_lists = json_decode($responses->ignore_list,true) ?? '';
|
||||
|
||||
//Partnerdata
|
||||
$partner_data = json_decode($responses->accounthierarchy);
|
||||
@@ -114,7 +117,11 @@ $view .= ' <div class="content-block order-details">
|
||||
<h3>'.$contract_type.'</h3>
|
||||
<p><span class="status id'.$responses->type.'">'.$$contract_type_text.'</span></p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<div class="order-detail">
|
||||
<h3>'.$contract_billinglabel.'</h3>
|
||||
<p><span class="status id'.$responses->billing_plan.'">'.($$contract_billingplan_text ?? '').'</span></p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$contract_start_date.'</h3>
|
||||
<p>'.$responses->start_date.'</p>
|
||||
</div>
|
||||
@@ -130,7 +137,13 @@ $view .= ' <div class="content-block order-details">
|
||||
<div class="order-detail">
|
||||
<h3>'.$contract_end_date.'</h3>
|
||||
<p>'.$date.'</p>
|
||||
</div>';
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$contract_service.'</h3>
|
||||
<p>'.$responses->service_count.'</p>
|
||||
</div>
|
||||
';
|
||||
|
||||
}
|
||||
|
||||
$view .='
|
||||
@@ -165,22 +178,30 @@ $view .='<div class="content-block order-details">
|
||||
</div>';
|
||||
$view .= '</div>';
|
||||
|
||||
|
||||
//Usageview
|
||||
|
||||
//get all assigned serialnumbers
|
||||
$url_input = '';
|
||||
foreach($servicetools as $service_tool){
|
||||
$url_input .= $service_tool.',';
|
||||
}
|
||||
//get ignore list
|
||||
$ignored_serialnumbers = '';
|
||||
if (!empty($ignore_lists) || $ignore_lists != ''){
|
||||
foreach($ignore_lists as $list){
|
||||
$ignored_serialnumbers .= $list.',';
|
||||
}
|
||||
$ignored_serialnumbers = '&ignore='.substr($ignored_serialnumbers,0,-1);
|
||||
}
|
||||
|
||||
//Return report_usage_servicereports
|
||||
$api_url = '/v1/application/type=ServiceReport&serialnumber='.substr($url_input,0,-1).'/contract_usage_servicereports';
|
||||
$api_url = '/v1/application/type=ServiceReport&serialnumber='.substr($url_input,0,-1).$ignored_serialnumbers.'&between='.$responses->start_date.'||'.$date.'/contract_usage_servicereports';
|
||||
$contract_usage_servicereports = ioServer($api_url,'');
|
||||
|
||||
//Decode Payload
|
||||
if (!empty($contract_usage_servicereports)){$contract_usage_servicereports = decode_payload($contract_usage_servicereports);}else{$contract_usage_servicereports = null;}
|
||||
|
||||
$service_events = usageView(json_decode(json_encode($contract_usage_servicereports),true));
|
||||
$contract_usage_servicereports = json_decode(json_encode($contract_usage_servicereports),true);
|
||||
|
||||
$service_events = usageView($contract_usage_servicereports);
|
||||
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
@@ -192,6 +213,68 @@ $view .= '<div class="content-block">
|
||||
</div>
|
||||
';
|
||||
|
||||
$usage_billing = usageBilling($contract_usage_servicereports);
|
||||
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-bars fa-sm"></i>'.$contract_billinglabel.'
|
||||
</div>
|
||||
<div class="table order-table">
|
||||
<table>
|
||||
<head>
|
||||
<tr>
|
||||
<th>'.$general_year.'</th>
|
||||
<th>'.$general_total.'</th>
|
||||
<th '.(($responses->billing_plan && $responses->billing_plan == 2) ? '' :'style="display:none;"').'>'.$general_quarter.'</th>
|
||||
<th '.(($responses->billing_plan && $responses->billing_plan == 2) ? '' :'style="display:none;"').'>'.$general_total.'</th>
|
||||
<th '.(($responses->billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'>'.$general_month.'</th>
|
||||
<th '.(($responses->billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'>'.$general_total.'</th>
|
||||
</tr>
|
||||
</head>
|
||||
<tbody>';
|
||||
|
||||
foreach($usage_billing as $key => $value){
|
||||
$view .= '
|
||||
<tr>
|
||||
<td>'.$key.'</td>
|
||||
<td>'.$value['total'].'</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
';
|
||||
foreach ($value['quarters'] as $key => $value){
|
||||
$view .= '
|
||||
<tr '.(($responses->billing_plan && $responses->billing_plan == 2) ? '' :'style="display:none;"').'>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>'.$key.'</td>
|
||||
<td>'.$value['total'].'</td>
|
||||
<td '.(($responses->billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'></td>
|
||||
<td '.(($responses->billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'></td>
|
||||
</tr>
|
||||
';
|
||||
|
||||
foreach($value['months'] as $key => $value){
|
||||
$view .= '
|
||||
<tr '.(($responses->billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td '.(($responses->billing_plan && $responses->billing_plan == 2) ? '' :'style="display:none;"').'></td>
|
||||
<td '.(($responses->billing_plan && $responses->billing_plan == 2) ? '' :'style="display:none;"').'></td>
|
||||
<td '.(($responses->billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'>'.$key.'</td>
|
||||
<td '.(($responses->billing_plan && $responses->billing_plan == 1) ? '' :'style="display:none;"').'>'.$value.'</td>
|
||||
</tr>
|
||||
';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$view .= '</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
@@ -229,6 +312,25 @@ $view .= '
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-bars fa-sm"></i>'. $contract_ignore_serial.'
|
||||
</div>
|
||||
<div class="table order-table">
|
||||
<table class="sortable">
|
||||
<tbody>';
|
||||
//Check for ignore list
|
||||
foreach ($ignore_lists as $list){
|
||||
$view .= '<tr><td>'.$list.'</td><tr>';
|
||||
}
|
||||
$view .= '
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-bars fa-sm"></i>'.$tab3.'
|
||||
|
||||
@@ -29,7 +29,8 @@ $contract = [
|
||||
'reference' => '',
|
||||
'servicetool' => [],
|
||||
'assigned_users' => [],
|
||||
'accounthierarchy' => $_SESSION['partnerhierarchy']
|
||||
'accounthierarchy' => $_SESSION['partnerhierarchy'],
|
||||
'ignore_list' => []
|
||||
];
|
||||
|
||||
$contract_ID = $_GET['rowID'] ?? '';
|
||||
@@ -146,6 +147,15 @@ $view .='<div class="content-block tab-content active">
|
||||
<option value="1" '.($contract['type']==1?' selected':'').'>'.$contract_type1.'</option>
|
||||
<option value="2" '.($contract['type']==2?' selected':'').'>'.$contract_type2.'</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_billinglabel.'</label>
|
||||
<select name="billing_plan">
|
||||
<option value="0" '.($contract['billing_plan']==0?' selected':'').'>'.$contract_billing0.'</option>
|
||||
<option value="1" '.($contract['billing_plan']==1?' selected':'').'>'.$contract_billing1.'</option>
|
||||
<option value="2" '.($contract['billing_plan']==2?' selected':'').'>'.$contract_billing2.'</option>
|
||||
<option value="3" '.($contract['billing_plan']==3?' selected':'').'>'.$contract_billing3.'</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_start_date.'</label>
|
||||
@@ -165,6 +175,10 @@ $view .= '<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_duration.'</label>
|
||||
<input type="number" name="duration" value="'.$contract['duration'].'" required>
|
||||
</div>
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_service.'</label>
|
||||
<input type="number" name="service_count" value="'.$contract['service_count'].'">
|
||||
</div>
|
||||
<div class="form responsive-width-100">
|
||||
<label for="">'.$contract_reference.'</label>
|
||||
<input type="text" name="reference" value="'.$contract['reference'].'" >
|
||||
@@ -200,6 +214,22 @@ $assigned_users = (empty($contract['assigned_users']))? '' :json_decode($contrac
|
||||
$view .= '<input id="assigned_users" type="text" name="assigned_users[]" placeholder="'.$contract_assigned_users.'" value="">';
|
||||
}
|
||||
|
||||
$view .=' </div>';
|
||||
|
||||
$view .=' <div class="form responsive-width-100">
|
||||
<label for="">'.$contract_ignore_serial.' <button type="button" class="btn2" onclick="addField(\'ignore_lists\',\'ignore_list[]\');" style="width:5%;background-color:#bed4ea;"> + </button></label>';
|
||||
|
||||
//Check for assigned users
|
||||
$ignore_lists = (empty($contract['ignore_list']))? '' :json_decode($contract['ignore_list'],true);
|
||||
|
||||
if (!empty($ignore_lists) || $ignore_lists != ''){
|
||||
foreach ($ignore_lists as $list){
|
||||
$view .= '<input id="ignore_lists" type="text" name="ignore_list[]" placeholder="'.$contract_ignore_serial.'" value="'.$list.'">';
|
||||
}
|
||||
} else {
|
||||
$view .= '<input id="ignore_lists" type="text" name="ignore_list[]" placeholder="'.$contract_ignore_serial.'" value="">';
|
||||
}
|
||||
|
||||
$view .=' </div>
|
||||
|
||||
</div>';
|
||||
|
||||
@@ -22,6 +22,8 @@ if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
|
||||
header('location: index.php');
|
||||
exit;
|
||||
}
|
||||
//Close Contracts when end_date expired
|
||||
closeContract();
|
||||
|
||||
//GET PARAMETERS
|
||||
$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
|
||||
|
||||
79
maintenance.php
Normal file
79
maintenance.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
defined(page_security_key) or exit;
|
||||
|
||||
$page = 'maintenance';
|
||||
//Check if allowed
|
||||
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
|
||||
header('location: index.php');
|
||||
exit;
|
||||
}
|
||||
//PAGE Security
|
||||
$update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'U');
|
||||
$delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'D');
|
||||
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
|
||||
|
||||
if ($update_allowed === 1){
|
||||
if (isset($_POST['geoupdate'])){
|
||||
//GEOLOCATION UPDATE
|
||||
geolocationUpdate($_SESSION['userkey']);
|
||||
}
|
||||
|
||||
if (isset($_POST['closeContract'])){
|
||||
//GEOLOCATION UPDATE
|
||||
closeContract();
|
||||
}
|
||||
if (isset($_POST['updatecartest'])){
|
||||
//GEOLOCATION UPDATE
|
||||
convertCartest();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle success messages
|
||||
if (isset($_GET['success_msg'])) {
|
||||
if ($_GET['success_msg'] == 1) {
|
||||
$success_msg = 'Settings updated successfully!';
|
||||
}
|
||||
}
|
||||
|
||||
//EMPTY VIEW
|
||||
$view = '';
|
||||
|
||||
template_header('Maintenance', 'maintenance', 'manage');
|
||||
|
||||
if (isset($success_msg)){
|
||||
$view .= ' <div class="msg error">
|
||||
<i class="fas fa-check-circle"></i>
|
||||
<p>'.$success_msg.'</p>
|
||||
<i class="fas fa-times"></i>
|
||||
</div>';
|
||||
}
|
||||
|
||||
$view .='
|
||||
<form action="" method="post">
|
||||
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
||||
<h2 class="responsive-width-100">Maintenance</h2>
|
||||
</div>';
|
||||
|
||||
$view .= '<div class="tabs">
|
||||
<a href="#" class="active">'.$general_actions .'</a>
|
||||
</div>
|
||||
';
|
||||
|
||||
if ($update_allowed === 1){
|
||||
$view .= '<div class="content-block tab-content active">
|
||||
<div class="form responsive-width-100">
|
||||
<label for="service">Expired contract closure</label>
|
||||
<input type="submit" name="closeContract" style="width: 15%;" value="closeContract" class="btn">
|
||||
<label for="service">CarTestUpdate</label>
|
||||
<input type="submit" name="updatecartest" style="width: 15%;" value="CarTestUpdate" class="btn">
|
||||
<label for="service">GeoUpdate</label>
|
||||
<input type="submit" name="geoupdate" style="width: 15%;" value="GeoUpdate" class="btn">
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
$view .= '</form>';
|
||||
|
||||
//Output
|
||||
echo $view;
|
||||
template_footer()
|
||||
?>
|
||||
@@ -128,8 +128,6 @@ $view .= '
|
||||
|
||||
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
||||
<h2 class="responsive-width-100">Settings</h2>
|
||||
<input type="submit" name="updatecartest" value="CarTestUpdate" class="btn">
|
||||
<input type="submit" name="geoupdate" value="GeoUpdate" class="btn">
|
||||
<input type="submit" name="submit" value="Save" class="btn">
|
||||
</div>
|
||||
';
|
||||
|
||||
@@ -16,7 +16,7 @@ $equipments_sub = array('equipments','servicereports','histories','firmwaretool'
|
||||
$sales_sub = array('accounts','contracts');
|
||||
$admin_sub = array('users','communications','partners');
|
||||
$reporting_sub = array('report_build','report_usage');
|
||||
$settings_sub = array('config','language','log');
|
||||
$settings_sub = array('config','language','log','maintenance');
|
||||
|
||||
//URLS
|
||||
$urls = array(
|
||||
@@ -63,8 +63,8 @@ $urls = array(
|
||||
"name" => "menu_products"
|
||||
),
|
||||
"sales" => array(
|
||||
"url" => "accounts",
|
||||
"selected" => "accounts",
|
||||
"url" => "contracts",
|
||||
"selected" => "contracts",
|
||||
"icon" => "fa-solid fa-bars",
|
||||
"name" => "menu_sales"
|
||||
),
|
||||
@@ -128,6 +128,12 @@ $urls = array(
|
||||
"icon" => "fas fa-tachometer-alt",
|
||||
"name" => "menu_log"
|
||||
),
|
||||
"maintenance" => array(
|
||||
"url" => "maintenance",
|
||||
"selected" => "maintenance",
|
||||
"icon" => "fas fa-tachometer-alt",
|
||||
"name" => "menu_maintenance"
|
||||
),
|
||||
"marketing" => array(
|
||||
"url" => "marketing&product_group=Emergency_Plug&product_content=Images",
|
||||
"selected" => "marketing",
|
||||
|
||||
@@ -24,6 +24,8 @@ $menu_cartest = 'Fahrzeugdatenbank';
|
||||
$menu_report_main = 'Berichte';
|
||||
$menu_report_build = 'Bestand und Produktion';
|
||||
$menu_report_usage = 'Systemnutzung';
|
||||
$menu_maintenance = 'Maintenance';
|
||||
|
||||
|
||||
//TABS
|
||||
$tab1 = 'Allgemein';
|
||||
@@ -32,6 +34,11 @@ $tab3 = 'Protokoll';
|
||||
$tab4 = 'Einstellungen';
|
||||
|
||||
//Global
|
||||
$general_year = 'Jahr';
|
||||
$general_quarter = 'Quartal';
|
||||
$general_month = 'Monat';
|
||||
$general_total = 'Gesamtanzahl';
|
||||
|
||||
$general_salesid = 'Verkaufs-ID';
|
||||
$general_soldto = 'Verkauft an';
|
||||
$general_shipto = 'Lieferadresse';
|
||||
@@ -478,6 +485,14 @@ $contract_type0 = 'Fest';
|
||||
$contract_type1 = 'Abonnement';
|
||||
$contract_type2 = 'Pay-per-Use';
|
||||
|
||||
$contract_billinglabel = 'Billing';
|
||||
$contract_billing0 = 'One-time after';
|
||||
$contract_billing1 = 'Monthly';
|
||||
$contract_billing2 = 'Quarterly';
|
||||
$contract_billing3 = 'Annual';
|
||||
|
||||
$contract_service = 'Number of service events based on billingplan';
|
||||
|
||||
$contract_id = 'Vertrags-ID';
|
||||
$contract_account = 'Konto';
|
||||
$contract_type = 'Typ';
|
||||
@@ -486,6 +501,7 @@ $contract_end_date = 'Enddatum';
|
||||
$contract_reference = 'Referenz';
|
||||
$contract_duration = 'Dauer (in Monaten)';
|
||||
$contract_servicetool = 'Servicetool';
|
||||
$contract_ignore_serial = 'Seriennummern ignorieren';
|
||||
$contract_assigned_users = 'Zugewiesene Benutzer';
|
||||
$contract_assigned_users_add = 'Benutzer hinzufügen';
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ $menu_cartest = 'Auto database';
|
||||
$menu_report_main = 'Rapporten';
|
||||
$menu_report_build = 'Voorraad en Productie';
|
||||
$menu_report_usage = 'Systeemgebruik';
|
||||
$menu_maintenance = 'Maintenance';
|
||||
|
||||
|
||||
//TABS
|
||||
$tab1 = 'Algemeen';
|
||||
@@ -32,6 +34,11 @@ $tab3 = 'Log';
|
||||
$tab4 = 'Settings';
|
||||
|
||||
//Global
|
||||
$general_year = 'Jaar';
|
||||
$general_quarter = 'Kwartaal';
|
||||
$general_month = 'Maand';
|
||||
$general_total = 'Totaal';
|
||||
|
||||
$general_salesid = 'Verkoper';
|
||||
$general_soldto = 'Verkocht aan';
|
||||
$general_shipto = 'Verzonden aan';
|
||||
@@ -482,6 +489,14 @@ $contract_type0 = 'Vast';
|
||||
$contract_type1 = 'Abonnement';
|
||||
$contract_type2 = 'Bij gebruik';
|
||||
|
||||
$contract_billinglabel = 'Betaalschema';
|
||||
$contract_billing0 = 'Eenmalig achteraf';
|
||||
$contract_billing1 = 'Maandelijks';
|
||||
$contract_billing2 = 'Kwartaal';
|
||||
$contract_billing3 = 'Jaarlijks';
|
||||
|
||||
$contract_service = 'Aantal service events obv betaalschema';
|
||||
|
||||
$contract_id = 'Contractnummer';
|
||||
$contract_account = 'Klant';
|
||||
$contract_type = 'Type';
|
||||
@@ -491,6 +506,7 @@ $contract_reference = 'Referentie';
|
||||
$contract_duration = 'Contract duur (in maanden)';
|
||||
$contract_servicetool = 'Servicetool';
|
||||
$contract_assigned_users = 'Gekoppelde gebruikers';
|
||||
$contract_ignore_serial = 'Negeer serienummers';
|
||||
$contract_assigned_users_add = 'Gebruiker toevoegen';
|
||||
|
||||
//=================================================================
|
||||
|
||||
@@ -24,6 +24,7 @@ $menu_cartest = 'Car database';
|
||||
$menu_report_main = 'Reports';
|
||||
$menu_report_build = 'Stock and Production';
|
||||
$menu_report_usage = 'System usage';
|
||||
$menu_maintenance = 'Maintenance';
|
||||
|
||||
//TABS
|
||||
$tab1 = 'General';
|
||||
@@ -32,6 +33,11 @@ $tab3 = 'Log';
|
||||
$tab4 = 'Settings';
|
||||
|
||||
//Global
|
||||
$general_year = 'Year';
|
||||
$general_quarter = 'Quarter';
|
||||
$general_month = 'Month';
|
||||
$general_total = 'Total';
|
||||
|
||||
$general_salesid = 'SalesID';
|
||||
$general_soldto = 'SoldTo';
|
||||
$general_shipto = 'ShipTo';
|
||||
@@ -478,6 +484,14 @@ $contract_type0 = 'Fixed';
|
||||
$contract_type1 = 'Subscription';
|
||||
$contract_type2 = 'Pay per use';
|
||||
|
||||
$contract_billinglabel = 'Billingplan';
|
||||
$contract_billing0 = 'One-time after';
|
||||
$contract_billing1 = 'Monthly';
|
||||
$contract_billing2 = 'Quarterly';
|
||||
$contract_billing3 = 'Annual';
|
||||
|
||||
$contract_service = 'Number of service events based on billingplan';
|
||||
|
||||
$contract_id = 'Contract ID';
|
||||
$contract_account = 'Account';
|
||||
$contract_type = 'Type';
|
||||
@@ -486,6 +500,7 @@ $contract_end_date = 'End date';
|
||||
$contract_reference = 'Reference';
|
||||
$contract_duration = 'Duration (in months)';
|
||||
$contract_servicetool = 'Servicetool';
|
||||
$contract_ignore_serial = 'Ignore serialnumbers';
|
||||
$contract_assigned_users = 'Assigned users';
|
||||
$contract_assigned_users_add = 'Add user';
|
||||
|
||||
|
||||
172
test.php
172
test.php
@@ -8,148 +8,42 @@ include './settings/settings.php';
|
||||
include './settings/config.php';
|
||||
include_once './settings/translations/translations_US.php';
|
||||
include_once './settings/systemfirmware.php';
|
||||
/*
|
||||
//------------------------------------------
|
||||
// Get DATA from API
|
||||
//------------------------------------------
|
||||
$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
|
||||
//$input = json_decode(file_get_contents('php://input'),true);
|
||||
$post_data_curl = fopen('php://input', 'r');
|
||||
$input = stream_get_contents($post_data_curl);
|
||||
|
||||
//------------------------------------------
|
||||
// Include functions
|
||||
//------------------------------------------
|
||||
require_once './assets/functions.php';
|
||||
include './settings/settings.php';
|
||||
$pdo = dbConnect($dbname);
|
||||
$sql = 'SELECT * FROM contracts WHERE status = 1';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
//------------------------------------------
|
||||
// Retrieve API version and Collection
|
||||
// api.php/(v)ersion/{get/post}/collection/
|
||||
//------------------------------------------
|
||||
$version = (isset($request[0])) ? strtolower($request[0]) : '';
|
||||
$collection = (isset($request[1])) ? strtolower($request[1]) : '';
|
||||
$get_content = (isset($request[2])) ? strtolower($request[2]) : '';
|
||||
foreach ($messages as $message){
|
||||
//Calculate contract end date
|
||||
$end_date = date('Y-m-d', strtotime('+'.$message['duration'].' months', strtotime($message['start_date'])));
|
||||
|
||||
///------------------------------------------
|
||||
// Application related calls
|
||||
//------------------------------------------
|
||||
$action = $request[2] ?? '';
|
||||
//Validate if contract end date is in the past change contact status to closed and set users to not active
|
||||
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
|
||||
foreach (json_decode($message['assigned_users']) as $user_assigned){
|
||||
|
||||
$user_data['service'] = '';
|
||||
$token = createCommunicationToken($user_data['service']);
|
||||
echo $token;
|
||||
*/
|
||||
//CALL TO API FOR General information
|
||||
$clientsecret = createCommunicationToken($_SESSION['userkey']);
|
||||
$responses = ioApi('/v2/users/username='.$user_assigned,'',$clientsecret);
|
||||
|
||||
|
||||
$tags = ['test1','test2','test3'];
|
||||
|
||||
echo '
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
.multiselect {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-flow: wrap;
|
||||
border-bottom: 1px solid #dedfe1;
|
||||
padding-bottom: 10px;
|
||||
margin: 15px 0 25px 0;
|
||||
margin-bottom: 25px;
|
||||
if (!empty($responses)){
|
||||
$response = json_decode($responses,true);
|
||||
//If response is not null update the service flag of the user
|
||||
if (count($response) != 0){
|
||||
$id_exist_user = $response[0]['id'];
|
||||
$sql = 'UPDATE users SET service = ? WHERE id = ? ';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
//Remove serviceflag from user when status is Closed
|
||||
$stmt->execute(['',$id_exist_user]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.multiselect > .item {
|
||||
display: inline-flex;
|
||||
border: 1px solid #dedfe1;
|
||||
padding: 0 10px;
|
||||
height: 40px;
|
||||
margin: 0 5px 5px 0;
|
||||
font-size: 14px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.multiselect > .item .remove {
|
||||
font-style: normal;
|
||||
cursor: pointer;
|
||||
font-size: 19px;
|
||||
margin-right: 3px;
|
||||
margin-top: -2px;
|
||||
color: #b5b9bd;
|
||||
}
|
||||
|
||||
.multiselect > .item .remove:hover {
|
||||
color: #9aa0a5;
|
||||
}
|
||||
|
||||
.multiselect input {
|
||||
height: 40px;
|
||||
width: 80px;
|
||||
flex-grow: 1;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
outline: 0;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.multiselect input:hover {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.multiselect .list {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
width: 100%;
|
||||
flex-flow: column;
|
||||
background-color: #fff;
|
||||
box-shadow: 0px 0px 5px 1px rgba(0, 0, 0, 0.1);
|
||||
max-height: 100px;
|
||||
overflow-y: auto;
|
||||
z-index: 1000000000;
|
||||
}
|
||||
|
||||
.multiselect .list span {
|
||||
display: flex;
|
||||
padding: 5px 7px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.multiselect .list span:hover {
|
||||
background-color: #f3f4f4;
|
||||
}
|
||||
|
||||
.multiselect:hover, main .multiselect:active {
|
||||
border-bottom: 1px solid #b5b9bd;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<form action="" method="post">
|
||||
<label for="category">Categories</label>
|
||||
<div class="multiselect" data-name="tags[]">';
|
||||
|
||||
foreach ($tags as $tag){
|
||||
echo '
|
||||
<span class="item" data-value="'.$tag.'" onclick="remove(this)">
|
||||
<i class="remove" >×</i>'.$tag.'
|
||||
<input type="hidden" name="tags[]" value="'.$tag.'">
|
||||
</span>
|
||||
';
|
||||
}
|
||||
echo' <input type="text" name="tags[]" placeholder="Categories">
|
||||
<input type="submit" value="test">
|
||||
</div>
|
||||
|
||||
</form>
|
||||
<script>
|
||||
function remove(tag) {
|
||||
var element = tag;
|
||||
element.remove();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
';
|
||||
var_dump($_POST);
|
||||
?>
|
||||
}
|
||||
Reference in New Issue
Block a user