Add user roles management page and update user permissions handling
- Created a new `user_roles.php` file for managing user roles and permissions. - Implemented pagination, filtering, and sorting for user roles. - Updated `users.php` to use the new authorization structure for permissions. - Changed API version from v1 to v2 in `users.php` for user data retrieval. - Modified `webhook_mollie.php` to include account hierarchy in license creation. - Refactored invoice generation and email sending logic in `webhook_mollie.php`. - Introduced a new `webhook_paypal.php` file to handle PayPal webhook notifications. - Implemented payment status updates and license creation logic in `webhook_paypal.php`. - Added helper functions for PayPal webhook signature verification and access token retrieval.
This commit is contained in:
BIN
api/v2/get/.DS_Store
vendored
BIN
api/v2/get/.DS_Store
vendored
Binary file not shown.
158
api/v2/get/access_elements.php
Normal file
158
api/v2/get/access_elements.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Access Elements
|
||||
//------------------------------------------
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//------------------------------------------
|
||||
//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] =='success_msg' || $v[0] =='sort' || $v[0] =='all'){
|
||||
//do nothing
|
||||
}
|
||||
elseif ($v[0] == 'rowid') {
|
||||
//build up search by ID
|
||||
$clause .= ' AND a.rowID = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'status') {
|
||||
//Update status based on status
|
||||
$clause .= ' AND a.is_active = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'search') {
|
||||
//build up search
|
||||
$clause .= ' AND (a.access_name LIKE :'.$v[0].' OR a.access_path LIKE :'.$v[0].' OR a.description LIKE :'.$v[0].')';
|
||||
}
|
||||
elseif ($v[0] == 'access_path') {
|
||||
//build up path search
|
||||
$clause .= ' AND a.access_path = :'.$v[0];
|
||||
}
|
||||
else {
|
||||
//create clause
|
||||
$clause .= ' AND a.'.$v[0].' = :'.$v[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Build WHERE clause
|
||||
$whereclause = '';
|
||||
if ($clause != ''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
}
|
||||
|
||||
// GET SORT INDICATOR
|
||||
$sort_indicator = $criterias['sort'] ?? '';
|
||||
|
||||
switch ($sort_indicator){
|
||||
case 1:
|
||||
$sort = ' a.access_name ASC ';
|
||||
break;
|
||||
case 2:
|
||||
$sort = ' a.access_name DESC ';
|
||||
break;
|
||||
case 3:
|
||||
$sort = ' a.access_path ASC ';
|
||||
break;
|
||||
case 4:
|
||||
$sort = ' a.access_path DESC ';
|
||||
break;
|
||||
default:
|
||||
$sort = ' a.access_name ASC ';
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||
//Request for total rows
|
||||
$sql = 'SELECT count(*) as count FROM access_elements a '.$whereclause;
|
||||
}
|
||||
elseif (isset($criterias['all']) && $criterias['all'] ==''){
|
||||
//Return all records (no paging)
|
||||
$sql = 'SELECT a.* FROM access_elements a '.$whereclause.' ORDER BY '.$sort;
|
||||
}
|
||||
else {
|
||||
//SQL
|
||||
$sql = 'SELECT a.* FROM access_elements a '.$whereclause.' ORDER BY '.$sort.' LIMIT :page,:num_rows';
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
//------------------------------------------
|
||||
//Bind to query
|
||||
//------------------------------------------
|
||||
if (!empty($criterias)){
|
||||
foreach ($criterias as $key => $value){
|
||||
$key_condition = ':'.$key;
|
||||
if (str_contains($sql, $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
|
||||
//------------------------------------------
|
||||
$page_rows = $page_rows_equipment ?? 20;
|
||||
|
||||
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetch();
|
||||
$messages = $messages[0];
|
||||
}
|
||||
elseif(isset($criterias['all']) && $criterias['all']==''){
|
||||
//Return all records (no paging)
|
||||
$stmt->execute();
|
||||
$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, PDO::PARAM_INT);
|
||||
$stmt->bindValue('num_rows', $page_rows, PDO::PARAM_INT);
|
||||
//Execute Query
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_EnCODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
//------------------------------------------
|
||||
//Send results
|
||||
//------------------------------------------
|
||||
echo $messages;
|
||||
|
||||
?>
|
||||
@@ -17,19 +17,25 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el
|
||||
//default whereclause
|
||||
$whereclause = '';
|
||||
|
||||
switch ($permission) {
|
||||
case '4':
|
||||
$hierarchy_level = getHierarchyLevel($partner);
|
||||
|
||||
switch ($hierarchy_level) {
|
||||
case '0':
|
||||
$whereclause = '';
|
||||
break;
|
||||
case '3':
|
||||
case '1':
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___%';
|
||||
$whereclause = 'WHERE accounthierarchy like :condition AND u.view IN (4,5)';
|
||||
break;
|
||||
case '2':
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||
$whereclause = 'WHERE accounthierarchy like :condition AND u.view IN (1,2,3)';
|
||||
break;
|
||||
case '3':
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%';
|
||||
$whereclause = 'WHERE accounthierarchy like :condition AND u.view IN (1,2,3)';
|
||||
break;
|
||||
default:
|
||||
case '4':
|
||||
$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 accounthierarchy like :condition AND u.view IN (1,2,3)';
|
||||
break;
|
||||
|
||||
116
api/v2/get/equipment_history.php
Normal file
116
api/v2/get/equipment_history.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
// Database connection
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
// ============================================
|
||||
// Input Validation & Sanitization
|
||||
// ============================================
|
||||
|
||||
$filters = [
|
||||
'serialnumber' => isset($_GET['serialnumber']) ? trim($_GET['serialnumber']) : null,
|
||||
'type' => isset($_GET['type']) ? trim($_GET['type']) : null,
|
||||
'start' => isset($_GET['start']) ? trim($_GET['start']) : date("Y-m-d", strtotime("-270 days")),
|
||||
'end' => isset($_GET['end']) ? trim($_GET['end']) : date("Y-m-d", strtotime("+1 days"))
|
||||
];
|
||||
|
||||
// ============================================
|
||||
// Build Query with Prepared Statements
|
||||
// ============================================
|
||||
|
||||
$whereClauses = [];
|
||||
$params = [];
|
||||
|
||||
// Serial Number Filter
|
||||
if ($filters['serialnumber']) {
|
||||
$whereClauses[] = 'h.description LIKE :serialnumber';
|
||||
$params[':serialnumber'] = "%historycreated%SN%:" . $filters['serialnumber'] . "%";
|
||||
$whereClauses[] = 'h.type != :excluded_type';
|
||||
$params[':excluded_type'] = 'SRIncluded';
|
||||
}
|
||||
|
||||
// Type Filter
|
||||
if ($filters['type']) {
|
||||
if ($filters['type'] === 'latest') {
|
||||
// Get only the latest record per equipment
|
||||
if ($filters['serialnumber']) {
|
||||
$whereClauses[] = 'h.rowID IN (
|
||||
SELECT MAX(h2.rowID)
|
||||
FROM equipment_history h2
|
||||
GROUP BY h2.equipmentid
|
||||
)';
|
||||
} else {
|
||||
$whereClauses[] = "h.description LIKE '%historycreated%'";
|
||||
$whereClauses[] = 'h.rowID IN (
|
||||
SELECT MAX(h2.rowID)
|
||||
FROM equipment_history h2
|
||||
WHERE h2.description LIKE :history_created
|
||||
GROUP BY h2.equipmentid
|
||||
)';
|
||||
$params[':history_created'] = '%historycreated%';
|
||||
}
|
||||
} else {
|
||||
// Specific type filter
|
||||
$whereClauses[] = 'h.type = :type';
|
||||
$params[':type'] = $filters['type'];
|
||||
}
|
||||
}
|
||||
|
||||
// Default filter if no other filters applied
|
||||
if (empty($whereClauses)) {
|
||||
$whereClauses[] = "h.description LIKE '%historycreated%'";
|
||||
}
|
||||
|
||||
// Date Range Filter
|
||||
$whereClauses[] = 'h.created BETWEEN :start_date AND :end_date';
|
||||
$params[':start_date'] = $filters['start'];
|
||||
$params[':end_date'] = $filters['end'];
|
||||
|
||||
// ============================================
|
||||
// Execute Query
|
||||
// ============================================
|
||||
|
||||
$whereClause = 'WHERE ' . implode(' AND ', $whereClauses);
|
||||
$sql = "SELECT h.rowID, h.description
|
||||
FROM equipment_history h
|
||||
$whereClause
|
||||
ORDER BY h.created DESC";
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// ============================================
|
||||
// Format Response
|
||||
// ============================================
|
||||
|
||||
$results = [];
|
||||
foreach ($messages as $message) {
|
||||
$record = json_decode($message['description'], true);
|
||||
|
||||
// Handle JSON decode errors
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
continue; // Skip invalid JSON
|
||||
}
|
||||
|
||||
$record['historyID'] = (int)$message['rowID'];
|
||||
$results[] = $record;
|
||||
}
|
||||
|
||||
// Set proper headers
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($results, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
// Log error (don't expose to client in production)
|
||||
error_log("Database error: " . $e->getMessage());
|
||||
|
||||
//header('Content-Type: application/json; charset=utf-8', true, 500);
|
||||
echo json_encode([
|
||||
'error' => 'An error occurred while processing your request'
|
||||
]);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -143,6 +143,10 @@ if(isset($get_content) && $get_content!=''){
|
||||
$clause .= ' AND e.serialnumber IN (:'.$v[0].')';
|
||||
}
|
||||
}
|
||||
elseif ($v[0] == 'validate') {
|
||||
// Set validation mode flag
|
||||
$validation_mode = true;
|
||||
}
|
||||
elseif ($v[0] == 'firmware') {
|
||||
//Assets with firmaware upgrade = 0 (1=latest version, 2=No software)
|
||||
$clause .= ' AND e.status != 5 AND e.sw_version_latest = 0';
|
||||
@@ -161,7 +165,7 @@ if(isset($get_content) && $get_content!=''){
|
||||
}
|
||||
}
|
||||
|
||||
if ($sw_version_latest_update == 1){
|
||||
if ($sw_version_latest_update == 1 || $clause == ''){
|
||||
//------------------------------------------
|
||||
//UPDATE SW_STATUS
|
||||
//------------------------------------------
|
||||
@@ -175,6 +179,10 @@ if (isset($criterias['download']) && $criterias['download'] ==''){
|
||||
//Request for download
|
||||
$sql = 'SELECT e.rowID as equipmentID, e.*, p.productcode, p.productname from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY equipmentID';
|
||||
}
|
||||
elseif (isset($validation_mode) && $validation_mode === true) {
|
||||
// Validation mode - return count only for serial validation
|
||||
$sql = "SELECT count(rowID) as rowID from equipment e $whereclause";
|
||||
}
|
||||
elseif (isset($criterias['totals']) && $criterias['totals'] =='' && !isset($criterias['type'])){
|
||||
//Request for total rows
|
||||
$sql = 'SELECT count(*) as count from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.'';
|
||||
@@ -267,7 +275,7 @@ else {
|
||||
}
|
||||
|
||||
//SQL for Paging
|
||||
$sql = 'SELECT e.rowID as equipmentID, e.*, p.productcode, p.productname, p.product_media from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY '.$sort.' LIMIT :page,:num_products';
|
||||
$sql = 'SELECT e.rowID as equipmentID, e.*, p.productcode, p.productname, p.product_media, psl.starts_at,psl.expires_at,psl.status as license_status from equipment e LEFT JOIN products p ON e.productrowid = p.rowID LEFT JOIN products_software_licenses psl ON e.sw_version_license = psl.license_key '.$whereclause.' ORDER BY '.$sort.' LIMIT :page,:num_products';
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
@@ -314,7 +322,19 @@ if (debug){
|
||||
//------------------------------------------
|
||||
//Add paging details
|
||||
//------------------------------------------
|
||||
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
if (isset($validation_mode) && $validation_mode === true) {
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetch();
|
||||
|
||||
if ($messages[0] == 1) {
|
||||
echo json_encode(array('SN'=> TRUE));
|
||||
}
|
||||
else {
|
||||
echo json_encode(array('SN'=> FALSE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
elseif(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetch();
|
||||
$messages = $messages[0];
|
||||
|
||||
@@ -13,27 +13,34 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el
|
||||
|
||||
//default whereclause
|
||||
$whereclause = '';
|
||||
$hierarchy_level = getHierarchyLevel($partner);
|
||||
|
||||
switch ($permission) {
|
||||
case '4':
|
||||
switch ($hierarchy_level) {
|
||||
case '0':
|
||||
$whereclause = '';
|
||||
break;
|
||||
case '3':
|
||||
case '1':
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___%';
|
||||
$whereclause = 'WHERE e.accounthierarchy like :condition';
|
||||
$whereclause = 'WHERE e.accounthierarchy like :condition ';
|
||||
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:
|
||||
case '3':
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.$soldto_search;
|
||||
$whereclause = 'WHERE e.accounthierarchy like :condition AND (type = "'.$type1.'" or type = "'.$type2.'" or type = "'.$type3.'" or type = "'.$type14.'" or type = "'.$type16.'")';
|
||||
break;
|
||||
case '4':
|
||||
$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 = '';
|
||||
$type_check = false;
|
||||
|
||||
//Check for $_GET variables and build up clause
|
||||
if(isset($get_content) && $get_content!=''){
|
||||
@@ -64,11 +71,65 @@ if(isset($get_content) && $get_content!=''){
|
||||
//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 NOT e.productrowid = "31" AND h.description like '.$filter_key_1;
|
||||
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] == 'type') {
|
||||
if ($v[1] == 'servicereport') {
|
||||
//Filter out only relevant servicereports
|
||||
$filter_key_1 = '"%serialnumber%"';
|
||||
$filter_key_2 = '"ServiceReport"';
|
||||
$clause .= ' AND h.type = '.$filter_key_2.' AND NOT e.productrowid = "31" AND h.description like '.$filter_key_1;
|
||||
//remove from criterias to prevent double binding
|
||||
unset($criterias[$v[0]]);
|
||||
}
|
||||
elseif (str_contains($v[1], ',')) {
|
||||
//check if multiple types are provided
|
||||
$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 h.type IN ('.$new_querystring.')';
|
||||
//remove original key/value from array
|
||||
$type_check = true;
|
||||
unset($criterias[$v[0]]);
|
||||
}
|
||||
else {
|
||||
$clause .= ' AND h.type = :'.$v[0];
|
||||
}
|
||||
}
|
||||
elseif ($v[0] == 'created') {
|
||||
//build up search
|
||||
@@ -89,6 +150,9 @@ if(isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||
//Request for total rows
|
||||
$sql ='SELECT count(h.rowID) as historyID FROM equipment_history h LEFT JOIN equipment e ON h.equipmentid = e.rowID '.$whereclause.'';
|
||||
}
|
||||
elseif($type_check){
|
||||
$sql ='SELECT h.rowID as historyID, e.rowID as equipmentID, e.serialnumber, h.type, h.description, h.created, h.createdby FROM equipment_history h LEFT JOIN equipment e ON h.equipmentid = e.rowID '.$whereclause.' ORDER BY h.created DESC';
|
||||
}
|
||||
else {
|
||||
//request history
|
||||
$sql ='SELECT h.rowID as historyID, e.rowID as equipmentID, e.serialnumber, h.type, h.description, h.created, h.createdby FROM equipment_history h LEFT JOIN equipment e ON h.equipmentid = e.rowID '.$whereclause.' ORDER BY h.created DESC LIMIT :page,:num_products';
|
||||
@@ -125,6 +189,12 @@ if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
$messages = $stmt->fetch();
|
||||
$messages = $messages[0];
|
||||
}
|
||||
elseif($type_check){
|
||||
//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_history, PDO::PARAM_INT);
|
||||
@@ -136,10 +206,22 @@ else {
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// Clean up nested JSON in description fields before final encoding
|
||||
if (!isset($criterias['totals']) || $criterias['totals'] != '') {
|
||||
foreach ($messages as &$message) {
|
||||
if (isset($message['description']) && is_string($message['description'])) {
|
||||
$decoded = json_decode($message['description'], true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$message['description'] = json_encode($decoded, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_ENCODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
//Send results
|
||||
echo $messages;
|
||||
|
||||
@@ -51,7 +51,7 @@ elseif (isset($criterias['list']) && $criterias['list'] =='invoice'){
|
||||
//SQL for Paging
|
||||
$sql = 'SELECT tx.*, txi.item_id as item_id,txi.item_price as item_price, txi.item_quantity as item_quantity, txi.item_options as item_options, p.productcode, p.productname, inv.id as invoice, inv.created as invoice_created, i.language as user_language
|
||||
FROM transactions tx
|
||||
left join invoice inv ON tx.id = inv.txn_id
|
||||
left join invoice inv ON tx.txn_id = inv.txn_id
|
||||
left join transactions_items txi ON tx.id = txi.txn_id
|
||||
left join products p ON p.rowID = txi.item_id
|
||||
left join identity i ON i.userkey = tx.account_id '.$whereclause;
|
||||
|
||||
152
api/v2/get/marketing_files.php
Normal file
152
api/v2/get/marketing_files.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Marketing Files
|
||||
//------------------------------------------
|
||||
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//SoldTo is empty
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
$whereclause = '';
|
||||
|
||||
//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] == 'action' || $v[0] =='success_msg' || $v[0] == '_t'){
|
||||
//do nothing
|
||||
}
|
||||
elseif ($v[0] == 'folder_id') {
|
||||
if ($v[1] === 'null' || $v[1] === '') {
|
||||
$clause .= ' AND folder_id IS NULL';
|
||||
} else {
|
||||
$clause .= ' AND folder_id = :folder_id';
|
||||
}
|
||||
}
|
||||
elseif ($v[0] == 'search') {
|
||||
$clause .= ' AND (title LIKE :search OR original_filename LIKE :search)';
|
||||
}
|
||||
elseif ($v[0] == 'tag') {
|
||||
$clause .= ' AND EXISTS (SELECT 1 FROM marketing_file_tags ft JOIN marketing_tags t ON ft.tag_id = t.id WHERE ft.file_id = mf.id AND t.tag_name = :tag)';
|
||||
}
|
||||
elseif ($v[0] == 'file_type') {
|
||||
$clause .= ' AND file_type = :file_type';
|
||||
}
|
||||
else {
|
||||
// Ignore unknown parameters
|
||||
}
|
||||
}
|
||||
if ($whereclause == '' && $clause !=''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
} else {
|
||||
$whereclause .= $clause;
|
||||
}
|
||||
}
|
||||
|
||||
//Set page
|
||||
$pagina = 1;
|
||||
if(isset($criterias['p']) && $criterias['p'] !='') {
|
||||
$pagina = $criterias['p'];
|
||||
}
|
||||
|
||||
//Set limit
|
||||
$limit = 50;
|
||||
if(isset($criterias['limit']) && $criterias['limit'] !='') {
|
||||
$limit = intval($criterias['limit']);
|
||||
}
|
||||
$offset = ($pagina - 1) * $limit;
|
||||
|
||||
//check for totals call
|
||||
if(isset($criterias['totals'])){
|
||||
$sql = 'SELECT COUNT(*) as found FROM marketing_files mf '.$whereclause.' ';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
// Bind parameters
|
||||
if (!empty($criterias)) {
|
||||
foreach ($criterias as $key => $value) {
|
||||
if ($key !== 'totals' && $key !== 'page' && $key !== 'p' && $key !== 'limit' && $key !== 'action') {
|
||||
if ($key == 'search') {
|
||||
$stmt->bindValue(':'.$key, '%'.$value.'%');
|
||||
} elseif ($key == 'folder_id' && ($value === 'null' || $value === '')) {
|
||||
continue;
|
||||
} else {
|
||||
$stmt->bindValue(':'.$key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$stmt->execute();
|
||||
$found = $stmt->fetchColumn();
|
||||
echo $found;
|
||||
exit;
|
||||
}
|
||||
|
||||
// Main query
|
||||
$sql = "SELECT
|
||||
mf.*,
|
||||
GROUP_CONCAT(mt.tag_name) as tags
|
||||
FROM marketing_files mf
|
||||
LEFT JOIN marketing_file_tags mft ON mf.id = mft.file_id
|
||||
LEFT JOIN marketing_tags mt ON mft.tag_id = mt.id
|
||||
" . $whereclause . "
|
||||
GROUP BY mf.id
|
||||
ORDER BY mf.created DESC
|
||||
LIMIT " . $limit . " OFFSET " . $offset;
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
// Bind parameters
|
||||
if (!empty($criterias)) {
|
||||
foreach ($criterias as $key => $value) {
|
||||
if ($key !== 'totals' && $key !== 'page' && $key !== 'p' && $key !== 'limit') {
|
||||
if ($key == 'search') {
|
||||
$stmt->bindValue(':'.$key, '%'.$value.'%');
|
||||
} elseif ($key == 'folder_id' && ($value === 'null' || $value === '')) {
|
||||
continue;
|
||||
} else {
|
||||
$stmt->bindValue(':'.$key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$stmt->execute();
|
||||
$marketing_files = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Process each file
|
||||
foreach ($marketing_files as &$file) {
|
||||
// Process tags
|
||||
$file['tags'] = $file['tags'] ? explode(',', $file['tags']) : [];
|
||||
|
||||
// Format file size
|
||||
$bytes = $file['file_size'];
|
||||
if ($bytes >= 1073741824) {
|
||||
$file['file_size_formatted'] = number_format($bytes / 1073741824, 2) . ' GB';
|
||||
} elseif ($bytes >= 1048576) {
|
||||
$file['file_size_formatted'] = number_format($bytes / 1048576, 2) . ' MB';
|
||||
} elseif ($bytes >= 1024) {
|
||||
$file['file_size_formatted'] = number_format($bytes / 1024, 2) . ' KB';
|
||||
} else {
|
||||
$file['file_size_formatted'] = $bytes . ' B';
|
||||
}
|
||||
}
|
||||
|
||||
// Return result
|
||||
echo json_encode($marketing_files, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
165
api/v2/get/marketing_folders.php
Normal file
165
api/v2/get/marketing_folders.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
//------------------------------------------
|
||||
// Marketing Folders
|
||||
//------------------------------------------
|
||||
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
// Function to build hierarchical tree structure
|
||||
function buildFolderTree($folders, $parentId = null) {
|
||||
$tree = [];
|
||||
|
||||
foreach ($folders as $folder) {
|
||||
if ($folder['parent_id'] == $parentId) {
|
||||
$children = buildFolderTree($folders, $folder['id']);
|
||||
$folder['children'] = $children; // Always include children array, even if empty
|
||||
$tree[] = $folder;
|
||||
}
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
//SoldTo is empty
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
$whereclause = '';
|
||||
|
||||
//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] =='success_msg' || $v[0] == 'action' || $v[0] == 'tree'){
|
||||
//do nothing - these are not SQL parameters
|
||||
}
|
||||
elseif ($v[0] == 'parent_id') {
|
||||
if ($v[1] === 'null' || $v[1] === '') {
|
||||
$clause .= ' AND parent_id IS NULL';
|
||||
} else {
|
||||
$clause .= ' AND parent_id = :parent_id';
|
||||
}
|
||||
}
|
||||
elseif ($v[0] == 'search') {
|
||||
$clause .= ' AND (folder_name LIKE :search OR description LIKE :search)';
|
||||
}
|
||||
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 marketing_folders '.$whereclause.'';
|
||||
}
|
||||
elseif (isset($criterias['list']) && $criterias['list'] =='') {
|
||||
//SQL for list (no paging)
|
||||
$sql = "SELECT
|
||||
mf.*,
|
||||
(SELECT COUNT(*) FROM marketing_files WHERE folder_id = mf.id) as file_count,
|
||||
(SELECT COUNT(*) FROM marketing_folders WHERE parent_id = mf.id) as subfolder_count,
|
||||
CASE
|
||||
WHEN mf.parent_id IS NOT NULL THEN
|
||||
(SELECT folder_name FROM marketing_folders WHERE id = mf.parent_id)
|
||||
ELSE NULL
|
||||
END as parent_folder_name
|
||||
FROM marketing_folders mf
|
||||
" . $whereclause . "
|
||||
ORDER BY mf.folder_name ASC";
|
||||
}
|
||||
else {
|
||||
//SQL for paging
|
||||
$sql = "SELECT
|
||||
mf.*,
|
||||
(SELECT COUNT(*) FROM marketing_files WHERE folder_id = mf.id) as file_count,
|
||||
(SELECT COUNT(*) FROM marketing_folders WHERE parent_id = mf.id) as subfolder_count,
|
||||
CASE
|
||||
WHEN mf.parent_id IS NOT NULL THEN
|
||||
(SELECT folder_name FROM marketing_folders WHERE id = mf.parent_id)
|
||||
ELSE NULL
|
||||
END as parent_folder_name
|
||||
FROM marketing_folders mf
|
||||
" . $whereclause . "
|
||||
ORDER BY mf.folder_name ASC
|
||||
LIMIT :page,:num_folders";
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
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 == 'parent_id' && ($value === 'null' || $value === '')) {
|
||||
// Skip binding for NULL parent_id
|
||||
continue;
|
||||
}
|
||||
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']==''){
|
||||
//Execute 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_folders, PDO::PARAM_INT);
|
||||
$stmt->bindValue('num_folders', $page_rows_folders, PDO::PARAM_INT);
|
||||
|
||||
//Execute Query
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// Check if tree structure is requested
|
||||
if (isset($criterias['tree']) && isset($messages) && is_array($messages)) {
|
||||
// Build hierarchical tree structure
|
||||
$messages = buildFolderTree($messages);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_ENCODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//Send results
|
||||
echo $messages;
|
||||
112
api/v2/get/marketing_tags.php
Normal file
112
api/v2/get/marketing_tags.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Marketing Tags
|
||||
//------------------------------------------
|
||||
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//SoldTo is empty
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
$whereclause = '';
|
||||
|
||||
//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] =='success_msg' || $v[0] == 'action'){
|
||||
//do nothing
|
||||
}
|
||||
elseif ($v[0] == 'search') {
|
||||
$clause .= ' AND tag_name LIKE :search';
|
||||
}
|
||||
elseif ($v[0] == 'used_only') {
|
||||
if ($v[1] === 'true') {
|
||||
$clause .= ' AND id IN (SELECT DISTINCT tag_id FROM marketing_file_tags)';
|
||||
}
|
||||
}
|
||||
else {//create clause
|
||||
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
||||
}
|
||||
}
|
||||
if ($whereclause == '' && $clause !=''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
} else {
|
||||
$whereclause .= $clause;
|
||||
}
|
||||
}
|
||||
|
||||
//Set page
|
||||
$pagina = 1;
|
||||
if(isset($criterias['p']) && $criterias['p'] !='') {
|
||||
$pagina = $criterias['p'];
|
||||
}
|
||||
|
||||
//check for totals call
|
||||
if(isset($criterias['totals'])){
|
||||
$sql = 'SELECT COUNT(*) as found FROM marketing_tags mt '.$whereclause.' ';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
// Bind parameters
|
||||
if (!empty($criterias)) {
|
||||
foreach ($criterias as $key => $value) {
|
||||
if ($key !== 'totals' && $key !== 'page' && $key !== 'p' && $key !== 'used_only') {
|
||||
if ($key == 'search') {
|
||||
$stmt->bindValue(':'.$key, '%'.$value.'%');
|
||||
} else {
|
||||
$stmt->bindValue(':'.$key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$stmt->execute();
|
||||
$found = $stmt->fetchColumn();
|
||||
echo $found;
|
||||
exit;
|
||||
}
|
||||
|
||||
// Main query
|
||||
$sql = "SELECT
|
||||
mt.*,
|
||||
COUNT(mft.file_id) as usage_count
|
||||
FROM marketing_tags mt
|
||||
LEFT JOIN marketing_file_tags mft ON mt.id = mft.tag_id
|
||||
" . $whereclause . "
|
||||
GROUP BY mt.id
|
||||
ORDER BY mt.tag_name ASC";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
// Bind parameters
|
||||
if (!empty($criterias)) {
|
||||
foreach ($criterias as $key => $value) {
|
||||
if ($key !== 'totals' && $key !== 'page' && $key !== 'p' && $key !== 'used_only') {
|
||||
if ($key == 'search') {
|
||||
$stmt->bindValue(':'.$key, '%'.$value.'%');
|
||||
} else {
|
||||
$stmt->bindValue(':'.$key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$stmt->execute();
|
||||
$marketing_tags = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Return result
|
||||
echo json_encode($marketing_tags, JSON_UNESCAPED_UNICODE);
|
||||
@@ -49,7 +49,7 @@ if (!$transaction) {
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
$sql = 'SELECT * FROM transactions_items WHERE txn_id = ? LIMIT 1';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$payment_id]);
|
||||
$stmt->execute([$transaction['id']]);
|
||||
$item = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$item) {
|
||||
|
||||
@@ -12,7 +12,7 @@ $pdo = dbConnect($dbname);
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
list($whereclause,$condition) = getWhereclauselvl2("software_upgrade_paths",$permission,$partner,'get');
|
||||
list($whereclause,$condition) = getWhereclauselvl2("",$permission,$partner,'get');
|
||||
|
||||
//NEW ARRAY
|
||||
$criterias = [];
|
||||
|
||||
@@ -12,7 +12,7 @@ $pdo = dbConnect($dbname);
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
list($whereclause,$condition) = getWhereclauselvl2("software_versions",$permission,$partner,'get');
|
||||
list($whereclause,$condition) = getWhereclauselvl2("",$permission,$partner,'get');
|
||||
|
||||
//NEW ARRAY
|
||||
$criterias = [];
|
||||
|
||||
152
api/v2/get/report_builder.php
Normal file
152
api/v2/get/report_builder.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Report Builder - GET Endpoints
|
||||
//------------------------------------------
|
||||
|
||||
// Set content type to JSON
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
// Get the action parameter from URL
|
||||
$criterias = [];
|
||||
if (isset($get_content) && $get_content != '') {
|
||||
$requests = explode("&", $get_content);
|
||||
foreach ($requests as $y) {
|
||||
$v = explode("=", $y);
|
||||
if (isset($v[1])) {
|
||||
$criterias[$v[0]] = urldecode($v[1]);
|
||||
} else {
|
||||
$criterias[$v[0]] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$action = strtolower($criterias['action'] ?? '');
|
||||
|
||||
/**
|
||||
* Validate table name - only allow alphanumeric, underscores, hyphens
|
||||
*/
|
||||
function sanitizeTableName($table) {
|
||||
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $table)) {
|
||||
return false;
|
||||
}
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of tables
|
||||
*/
|
||||
if ($action === 'gettables') {
|
||||
try {
|
||||
$result = $pdo->query("SHOW TABLES");
|
||||
$tables = [];
|
||||
while ($row = $result->fetch(PDO::FETCH_NUM)) {
|
||||
$tables[] = $row[0];
|
||||
}
|
||||
|
||||
$messages = json_encode([
|
||||
'success' => true,
|
||||
'tables' => $tables
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
$messages = json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Failed to fetch tables'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get columns for a specific table
|
||||
*/
|
||||
elseif ($action === 'getcolumns') {
|
||||
$table = sanitizeTableName($criterias['table'] ?? '');
|
||||
|
||||
if (!$table) {
|
||||
http_response_code(400);
|
||||
$messages = json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Invalid table name'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
try {
|
||||
$result = $pdo->query("SHOW COLUMNS FROM `$table`");
|
||||
$columns = [];
|
||||
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
||||
$columns[] = $row['Field'];
|
||||
}
|
||||
|
||||
$messages = json_encode([
|
||||
'success' => true,
|
||||
'columns' => $columns
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
$messages = json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Failed to fetch columns'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get table schema information
|
||||
*/
|
||||
elseif ($action === 'gettableschema') {
|
||||
$table = sanitizeTableName($criterias['table'] ?? '');
|
||||
|
||||
if (!$table) {
|
||||
http_response_code(400);
|
||||
$messages = json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Invalid table name'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
try {
|
||||
$result = $pdo->query("DESCRIBE `$table`");
|
||||
$schema = [];
|
||||
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
||||
$schema[] = [
|
||||
'field' => $row['Field'],
|
||||
'type' => $row['Type'],
|
||||
'null' => $row['Null'],
|
||||
'key' => $row['Key'],
|
||||
'default' => $row['Default'],
|
||||
'extra' => $row['Extra']
|
||||
];
|
||||
}
|
||||
|
||||
$messages = json_encode([
|
||||
'success' => true,
|
||||
'schema' => $schema
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
$messages = json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Failed to fetch table schema'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid or missing action
|
||||
*/
|
||||
else {
|
||||
http_response_code(400);
|
||||
$messages = json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Invalid or missing action parameter'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
// Send results
|
||||
echo $messages;
|
||||
?>
|
||||
123
api/v2/get/role_access_permissions.php
Normal file
123
api/v2/get/role_access_permissions.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Role Access Permissions
|
||||
//------------------------------------------
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//------------------------------------------
|
||||
//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] =='success_msg'){
|
||||
//do nothing
|
||||
}
|
||||
elseif ($v[0] == 'rowid') {
|
||||
//build up search by ID
|
||||
$clause .= ' AND rap.rowID = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'role_id') {
|
||||
//build up search by role_id
|
||||
$clause .= ' AND rap.role_id = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'access_id') {
|
||||
//build up search by access_id
|
||||
$clause .= ' AND rap.access_id = :'.$v[0];
|
||||
}
|
||||
else {
|
||||
//create clause
|
||||
$clause .= ' AND rap.'.$v[0].' = :'.$v[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Build WHERE clause
|
||||
$whereclause = '';
|
||||
if ($clause != ''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
}
|
||||
|
||||
if (isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||
//Request for total rows
|
||||
$sql = 'SELECT count(*) as count FROM role_access_permissions rap '.$whereclause;
|
||||
}
|
||||
else {
|
||||
//SQL with joined tables for names
|
||||
$sql = 'SELECT rap.*,
|
||||
r.name as role_name,
|
||||
ae.access_name,
|
||||
ae.access_path
|
||||
FROM role_access_permissions rap
|
||||
LEFT JOIN user_roles r ON rap.role_id = r.rowID
|
||||
LEFT JOIN access_elements ae ON rap.access_id = ae.rowID
|
||||
'.$whereclause.'
|
||||
ORDER BY ae.access_name ASC';
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
//------------------------------------------
|
||||
//Bind to query
|
||||
//------------------------------------------
|
||||
if (!empty($criterias)){
|
||||
foreach ($criterias as $key => $value){
|
||||
$key_condition = ':'.$key;
|
||||
if (str_contains($sql, $key_condition)){
|
||||
if ($key == 'p'){
|
||||
//Do nothing (bug)
|
||||
}
|
||||
else {
|
||||
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// Debuglog
|
||||
//------------------------------------------
|
||||
if (debug){
|
||||
$message = $date.';'.$sql.';'.$username;
|
||||
debuglog($message);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//Execute Query
|
||||
//------------------------------------------
|
||||
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetch();
|
||||
$messages = $messages[0];
|
||||
}
|
||||
else {
|
||||
//Execute Query
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_EnCODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
//------------------------------------------
|
||||
//Send results
|
||||
//------------------------------------------
|
||||
echo $messages;
|
||||
|
||||
?>
|
||||
82
api/v2/get/service.php
Normal file
82
api/v2/get/service.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
//Connect to DB
|
||||
//------------------------------------------
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//------------------------------------------
|
||||
// Application related calls
|
||||
//------------------------------------------
|
||||
$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
|
||||
$action = $request[2] ?? '';
|
||||
|
||||
if ($action == 'init'){
|
||||
include './settings/systemservicetool_init.php';
|
||||
echo json_encode($init);
|
||||
}
|
||||
elseif ($action == 'questions' && (isset($_GET['type']) && $_GET['type'] != '')){
|
||||
|
||||
include './settings/systemservicetool.php';
|
||||
|
||||
//build questions
|
||||
switch ($_GET['type']) {
|
||||
case 'visual':
|
||||
$arrayQuestions = $arrayQuestions_visual;
|
||||
break;
|
||||
|
||||
case 'final':
|
||||
$arrayQuestions = $arrayQuestions_finalize;
|
||||
break;
|
||||
|
||||
case 'cartest':
|
||||
include './settings/systemcartest.php';
|
||||
$arrayQuestions = $arrayQuestions_cartest;
|
||||
break;
|
||||
}
|
||||
//Return JSON
|
||||
echo json_encode($arrayQuestions);
|
||||
}
|
||||
elseif ($action == 'products') {
|
||||
|
||||
$sql = "SELECT * FROM products";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode($messages);
|
||||
|
||||
}
|
||||
elseif ($action == 'equipments' && (isset($_GET['serialnumber']) && $_GET['serialnumber'] != '' && !isset($_GET['validate']))) {
|
||||
|
||||
$sql = "SELECT e.rowID as equipmentID, e.*, p.productcode, p.productname, p.product_media, psl.starts_at,psl.expires_at,psl.status as license_status from equipment e LEFT JOIN products p ON e.productrowid = p.rowID LEFT JOIN products_software_licenses psl ON e.sw_version_license = psl.license_key WHERE e.serialnumber = ?";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$_GET['serialnumber']]);
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode($messages);
|
||||
|
||||
}
|
||||
elseif ($action == 'equipments' && (isset($_GET['serialnumber']) && $_GET['serialnumber'] != '' && isset($_GET['validate']))){
|
||||
|
||||
$sql = "SELECT count(rowID) as rowID from equipment e WHERE e.serialnumber = ?";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$_GET['serialnumber']]);
|
||||
$messages = $stmt->fetch();
|
||||
|
||||
if ($messages[0] == 1) {
|
||||
echo json_encode(array('SN'=> TRUE));
|
||||
}
|
||||
else {
|
||||
echo json_encode(array('SN'=> FALSE));
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -62,6 +62,7 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
e.sw_version as current_sw_version,
|
||||
e.hw_version,
|
||||
e.sw_version_license,
|
||||
e.sw_version_upgrade,
|
||||
e.rowID as equipment_rowid
|
||||
FROM equipment e
|
||||
JOIN products p ON e.productrowid = p.rowID
|
||||
@@ -78,6 +79,7 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
$current_sw_version = $equipment_data['current_sw_version'];
|
||||
$hw_version = $equipment_data['hw_version'];
|
||||
$sw_version_license = $equipment_data['sw_version_license'];
|
||||
$sw_version_upgrade = $equipment_data['sw_version_upgrade'];
|
||||
$equipment_rowid = $equipment_data['equipment_rowid'];
|
||||
|
||||
if (debug) {
|
||||
@@ -85,7 +87,8 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
'product_rowid' => $product_rowid,
|
||||
'productcode' => $productcode,
|
||||
'current_sw_version_raw' => $current_sw_version,
|
||||
'hw_version' => $hw_version
|
||||
'hw_version' => $hw_version,
|
||||
'sw_version_upgrade' => $sw_version_upgrade
|
||||
];
|
||||
}
|
||||
|
||||
@@ -119,6 +122,77 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check if sw_version_upgrade is set - this overrides normal availability check
|
||||
if (!empty($sw_version_upgrade)) {
|
||||
if (debug) {
|
||||
$debug['sw_version_upgrade_check'] = [
|
||||
'sw_version_upgrade_id' => $sw_version_upgrade,
|
||||
'checking_override' => true
|
||||
];
|
||||
}
|
||||
|
||||
// Check if this version exists and is active
|
||||
$sql = 'SELECT
|
||||
psv.rowID as version_id,
|
||||
psv.version,
|
||||
psv.name,
|
||||
psv.description,
|
||||
psv.mandatory,
|
||||
psv.latest,
|
||||
psv.hw_version,
|
||||
psv.file_path,
|
||||
psv.status
|
||||
FROM products_software_versions psv
|
||||
WHERE psv.rowID = ?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$sw_version_upgrade]);
|
||||
$upgrade_version = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($upgrade_version && $upgrade_version['status'] == 1) {
|
||||
// Valid override found - check if different from current version
|
||||
$normalized_upgrade_version = strtolower(ltrim($upgrade_version['version'], '0'));
|
||||
|
||||
if (debug) {
|
||||
$debug['sw_version_upgrade_check']['found_version'] = [
|
||||
'version' => $upgrade_version['version'],
|
||||
'name' => $upgrade_version['name'],
|
||||
'normalized' => $normalized_upgrade_version,
|
||||
'status' => $upgrade_version['status'],
|
||||
'is_different_from_current' => ($current_sw_version != $normalized_upgrade_version)
|
||||
];
|
||||
}
|
||||
|
||||
if ($current_sw_version && $normalized_upgrade_version == $current_sw_version) {
|
||||
// Override version is same as current - no upgrade available
|
||||
$software_available = "no";
|
||||
if (debug) {
|
||||
$debug['sw_version_upgrade_check']['decision'] = 'Override version is same as current version';
|
||||
}
|
||||
} else {
|
||||
// Override version is different - upgrade is available
|
||||
$software_available = "yes";
|
||||
if (debug) {
|
||||
$debug['sw_version_upgrade_check']['decision'] = 'Override version is available';
|
||||
}
|
||||
}
|
||||
|
||||
$messages = ["software_available" => $software_available];
|
||||
|
||||
if (debug) {
|
||||
debuglog(json_encode($debug));
|
||||
}
|
||||
|
||||
echo json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
} else {
|
||||
// Override version not found or inactive - fall back to standard check
|
||||
if (debug) {
|
||||
$debug['sw_version_upgrade_check']['found_version'] = $upgrade_version ? 'found but inactive' : 'not found';
|
||||
$debug['sw_version_upgrade_check']['decision'] = 'Falling back to standard check';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//GET ALL ACTIVE SOFTWARE ASSIGNMENTS for this product with matching HW version
|
||||
$sql = 'SELECT
|
||||
psv.rowID as version_id,
|
||||
@@ -161,6 +235,7 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
$debug['decision'] = 'No active software assignments found';
|
||||
}
|
||||
} else {
|
||||
$available_upgrades = 0;
|
||||
$has_priced_options = false;
|
||||
$has_latest_version_different = false;
|
||||
|
||||
@@ -219,8 +294,9 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
FROM products_software_upgrade_paths pup
|
||||
JOIN products_software_versions from_ver ON pup.from_version_id = from_ver.rowID
|
||||
WHERE pup.to_version_id = ?
|
||||
AND LOWER(TRIM(LEADING "0" FROM from_ver.version)) = ?
|
||||
AND pup.is_active = 1';
|
||||
AND (LOWER(TRIM(LEADING "0" FROM from_ver.version)) = ?
|
||||
OR pup.from_version_id = 9999999)
|
||||
AND pup.is_active = 1';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$version['version_id'], $current_sw_version]);
|
||||
$upgrade_path = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
@@ -242,6 +318,8 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
}
|
||||
|
||||
if ($show_version) {
|
||||
$available_upgrades++;
|
||||
|
||||
//Check if there's a valid license for this upgrade
|
||||
if ($final_price > 0 && $sw_version_license) {
|
||||
//Check if the license is valid
|
||||
@@ -286,23 +364,18 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
}
|
||||
}
|
||||
|
||||
// Apply the logic:
|
||||
// 1. If there are priced options -> "yes"
|
||||
// 2. If no priced options but current version != latest flagged version -> "yes"
|
||||
// 3. Default -> "no"
|
||||
if ($has_priced_options) {
|
||||
// Simple logic: if any upgrades are available to show, return "yes"
|
||||
if ($available_upgrades > 0) {
|
||||
$software_available = "yes";
|
||||
$availability_reason = "Has priced upgrade options available";
|
||||
} elseif ($has_latest_version_different) {
|
||||
$software_available = "yes";
|
||||
$availability_reason = "Has free latest version available";
|
||||
$availability_reason = "Software upgrades available";
|
||||
} else {
|
||||
$software_available = "no";
|
||||
$availability_reason = "No upgrades available or already on latest";
|
||||
$availability_reason = "No upgrades available";
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
$debug['final_decision'] = [
|
||||
'available_upgrades' => $available_upgrades,
|
||||
'has_priced_options' => $has_priced_options,
|
||||
'has_latest_version_different' => $has_latest_version_different,
|
||||
'software_available' => $software_available,
|
||||
|
||||
@@ -55,16 +55,20 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
}
|
||||
|
||||
//GET EQUIPMENT AND PRODUCT DATA BASED ON SERIAL NUMBER
|
||||
$sql = 'SELECT
|
||||
$sql = "SELECT
|
||||
p.rowID as product_rowid,
|
||||
p.productcode,
|
||||
e.sw_version as current_sw_version,
|
||||
e.hw_version,
|
||||
e.sw_version_license,
|
||||
e.rowID as equipment_rowid
|
||||
e.sw_version_upgrade,
|
||||
e.rowID as equipment_rowid,
|
||||
partner.*
|
||||
FROM equipment e
|
||||
JOIN products p ON e.productrowid = p.rowID
|
||||
WHERE e.serialnumber = ?';
|
||||
LEFT JOIN partner ON partner.partnerID = SUBSTRING_INDEX(JSON_UNQUOTE(JSON_EXTRACT(e.accounthierarchy, '$.soldto')), '-', 1)
|
||||
AND partner.is_dealer = 1 AND partner.status = 1
|
||||
WHERE e.serialnumber = ?";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$criterias['sn']]);
|
||||
$equipment_data = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
@@ -77,15 +81,28 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
$current_sw_version = $equipment_data['current_sw_version'];
|
||||
$hw_version = $equipment_data['hw_version'];
|
||||
$sw_version_license = $equipment_data['sw_version_license'];
|
||||
$sw_version_upgrade = $equipment_data['sw_version_upgrade'];
|
||||
$equipment_rowid = $equipment_data['equipment_rowid'];
|
||||
|
||||
$dealer_info = [
|
||||
'is_dealer' => $equipment_data['is_dealer'] ?? 0,
|
||||
'name' => $equipment_data['name'] ?? '',
|
||||
'address' => $equipment_data['address'] ?? '',
|
||||
'city' => $equipment_data['city'] ?? '',
|
||||
'postalcode' => $equipment_data['postalcode'] ?? '',
|
||||
'country' => $equipment_data['country'] ?? '',
|
||||
'email' => $equipment_data['email'] ?? '',
|
||||
'phone' => $equipment_data['phone'] ?? ''
|
||||
];
|
||||
|
||||
if (debug) {
|
||||
$debug['equipment_data'] = [
|
||||
'product_rowid' => $product_rowid,
|
||||
'productcode' => $productcode,
|
||||
'current_sw_version_raw' => $current_sw_version,
|
||||
'hw_version' => $hw_version,
|
||||
'sw_version_license' => $sw_version_license
|
||||
'sw_version_license' => $sw_version_license,
|
||||
'sw_version_upgrade' => $sw_version_upgrade
|
||||
];
|
||||
}
|
||||
|
||||
@@ -119,6 +136,95 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check if sw_version_upgrade is set - this overrides normal availability check
|
||||
if (!empty($sw_version_upgrade)) {
|
||||
if (debug) {
|
||||
$debug['sw_version_upgrade_check'] = [
|
||||
'sw_version_upgrade_id' => $sw_version_upgrade,
|
||||
'checking_override' => true
|
||||
];
|
||||
}
|
||||
|
||||
// Check if this version exists and is active
|
||||
$sql = 'SELECT
|
||||
psv.rowID as version_id,
|
||||
psv.version,
|
||||
psv.name,
|
||||
psv.description,
|
||||
psv.mandatory,
|
||||
psv.latest,
|
||||
psv.hw_version,
|
||||
psv.file_path,
|
||||
psv.status
|
||||
FROM products_software_versions psv
|
||||
WHERE psv.rowID = ?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$sw_version_upgrade]);
|
||||
$upgrade_version = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($upgrade_version && $upgrade_version['status'] == 1) {
|
||||
// Valid override found - check if different from current version
|
||||
$normalized_upgrade_version = strtolower(ltrim($upgrade_version['version'], '0'));
|
||||
|
||||
if (debug) {
|
||||
$debug['sw_version_upgrade_check']['found_version'] = [
|
||||
'version' => $upgrade_version['version'],
|
||||
'name' => $upgrade_version['name'],
|
||||
'normalized' => $normalized_upgrade_version,
|
||||
'status' => $upgrade_version['status'],
|
||||
'is_different_from_current' => ($current_sw_version != $normalized_upgrade_version)
|
||||
];
|
||||
}
|
||||
|
||||
if (!$current_sw_version || $current_sw_version == '' || $normalized_upgrade_version != $current_sw_version) {
|
||||
// Override version is different from current (or no current) - return only this upgrade
|
||||
$output[] = [
|
||||
"productcode" => $productcode,
|
||||
"name" => $upgrade_version['name'] ?? '',
|
||||
"version" => $upgrade_version['version'],
|
||||
"version_id" => $upgrade_version['version_id'],
|
||||
"description" => $upgrade_version['description'] ?? '',
|
||||
"hw_version" => $upgrade_version['hw_version'] ?? '',
|
||||
"mandatory" => $upgrade_version['mandatory'] ?? '',
|
||||
"latest" => $upgrade_version['latest'] ?? '',
|
||||
"software" => $upgrade_version['file_path'] ?? '',
|
||||
"source" => '',
|
||||
"source_type" => '',
|
||||
"price" => '0.00',
|
||||
"currency" => '',
|
||||
"is_current" => false
|
||||
];
|
||||
|
||||
// Generate download token
|
||||
$download_token = create_download_url_token($criterias['sn'], $upgrade_version['version_id']);
|
||||
$download_url = 'https://'.$_SERVER['SERVER_NAME'].'/api.php/v2/software_download?token='.$download_token;
|
||||
$output[0]['source'] = $download_url;
|
||||
$output[0]['source_type'] = 'token_url';
|
||||
|
||||
if (debug) {
|
||||
$debug['sw_version_upgrade_check']['decision'] = 'Override version returned as only upgrade';
|
||||
$output[0]['_debug'] = $debug;
|
||||
}
|
||||
} else {
|
||||
// Override version is same as current - no upgrades
|
||||
if (debug) {
|
||||
$debug['sw_version_upgrade_check']['decision'] = 'Override version is same as current version - no upgrades';
|
||||
$output = ['message' => 'No upgrades available', 'debug' => $debug];
|
||||
}
|
||||
}
|
||||
|
||||
$messages = $output;
|
||||
echo json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
} else {
|
||||
// Override version not found or inactive - fall back to standard check
|
||||
if (debug) {
|
||||
$debug['sw_version_upgrade_check']['found_version'] = $upgrade_version ? 'found but inactive' : 'not found';
|
||||
$debug['sw_version_upgrade_check']['decision'] = 'Falling back to standard check';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//GET ALL ACTIVE SOFTWARE ASSIGNMENTS for this product with matching HW version
|
||||
$sql = 'SELECT
|
||||
psv.rowID as version_id,
|
||||
@@ -212,16 +318,13 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
$decision_reason = 'Skipped - is current version but no upgrades scenario';
|
||||
}
|
||||
} else {
|
||||
//Check if this is the current version and should be shown as disabled
|
||||
if ($is_current_version && $has_paid_upgrade_from_current && $version['latest'] == 1) {
|
||||
//Show current version as disabled only if it's the latest AND there's a paid upgrade available
|
||||
//Check if this is the current version - always show it
|
||||
if ($is_current_version) {
|
||||
$show_version = true;
|
||||
$is_current = true;
|
||||
$final_price = '0.00';
|
||||
$final_currency = '';
|
||||
$decision_reason = 'Showing as CURRENT - is latest version with paid upgrade available';
|
||||
} else if ($is_current_version && !($has_paid_upgrade_from_current && $version['latest'] == 1)) {
|
||||
$decision_reason = 'Skipped - is current version but not (latest + has_paid_upgrade)';
|
||||
$decision_reason = 'Showing as CURRENT - always show current version';
|
||||
} else if (!$is_current_version) {
|
||||
//Check if this version is part of ANY upgrade path system (either FROM or TO)
|
||||
$sql = 'SELECT COUNT(*) as path_count
|
||||
@@ -242,26 +345,28 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
} else {
|
||||
//Part of an upgrade path system
|
||||
//Only show if there's an explicit path FROM current version TO this version
|
||||
// OR a wildcard path (from_version_id = 9999999)
|
||||
$sql = 'SELECT pup.price, pup.currency
|
||||
FROM products_software_upgrade_paths pup
|
||||
JOIN products_software_versions from_ver ON pup.from_version_id = from_ver.rowID
|
||||
WHERE pup.to_version_id = ?
|
||||
AND LOWER(TRIM(LEADING "0" FROM from_ver.version)) = ?
|
||||
AND pup.is_active = 1';
|
||||
AND (LOWER(TRIM(LEADING "0" FROM from_ver.version)) = ?
|
||||
OR pup.from_version_id = 9999999)
|
||||
AND pup.is_active = 1';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$version['version_id'], $current_sw_version]);
|
||||
$upgrade_path = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($upgrade_path) {
|
||||
//Valid upgrade path found FROM current version
|
||||
//Valid upgrade path found FROM current version or wildcard
|
||||
$show_version = true;
|
||||
$final_price = $upgrade_path['price'] ?? '0.00';
|
||||
$final_currency = $upgrade_path['currency'] ?? '';
|
||||
$decision_reason = 'Showing - found upgrade path FROM current (' . $current_sw_version . ') with price: ' . $final_price . ' ' . $final_currency;
|
||||
$decision_reason = 'Showing - found upgrade path FROM current (' . $current_sw_version . ') or wildcard with price: ' . $final_price . ' ' . $final_currency;
|
||||
} else {
|
||||
$decision_reason = 'Skipped - has upgrade paths but none FROM current version (' . $current_sw_version . ')';
|
||||
$decision_reason = 'Skipped - has upgrade paths but none FROM current version (' . $current_sw_version . ') or wildcard';
|
||||
}
|
||||
//If no path from current version exists, don't show (show_version stays false)
|
||||
//If no path from current version or wildcard exists, don't show (show_version stays false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -310,7 +415,7 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
}
|
||||
}
|
||||
|
||||
$output[] = [
|
||||
$entry = [
|
||||
"productcode" => $productcode,
|
||||
"name" => $version['name'] ?? '',
|
||||
"version" => $version['version'],
|
||||
@@ -324,8 +429,11 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
"source_type" => '',
|
||||
"price" => $final_price,
|
||||
"currency" => $final_currency,
|
||||
"is_current" => $is_current
|
||||
"is_current" => $is_current,
|
||||
"dealer_info" => $dealer_info
|
||||
];
|
||||
|
||||
$output[] = $entry;
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
@@ -360,6 +468,16 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
|
||||
];
|
||||
}
|
||||
|
||||
// Sort output: is_current = true first, then by price low to high
|
||||
usort($output, function($a, $b) {
|
||||
// First priority: is_current (true comes before false)
|
||||
if ($a['is_current'] !== $b['is_current']) {
|
||||
return $b['is_current'] - $a['is_current'];
|
||||
}
|
||||
// Second priority: price (low to high)
|
||||
return floatval($a['price']) - floatval($b['price']);
|
||||
});
|
||||
|
||||
$messages = $output;
|
||||
|
||||
if (debug && !empty($output)) {
|
||||
|
||||
@@ -19,7 +19,7 @@ if ($stmt->rowCount() == 1) {
|
||||
//Define User data
|
||||
$partnerhierarchy = $user_data['partnerhierarchy'];
|
||||
$permission = userRights($user_data['view']);
|
||||
$profile= getProfile($user_data['settings'],$permission);
|
||||
$profile= getUserPermissions($pdo, $user_data['id']); //getProfile($user_data['settings'],$permission);
|
||||
$username = $user_data['username'];
|
||||
$useremail = $user_data['email'];
|
||||
$servicekey = $user_data['service'];
|
||||
|
||||
70
api/v2/get/user_permissions.php
Normal file
70
api/v2/get/user_permissions.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// User Role Assignments
|
||||
//------------------------------------------
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//------------------------------------------
|
||||
//NEW ARRAY
|
||||
//------------------------------------------
|
||||
$criterias = [];
|
||||
$user_permissions = [];
|
||||
|
||||
//------------------------------------------
|
||||
//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];
|
||||
}
|
||||
}
|
||||
|
||||
$user_key = $criterias['userkey'] ?? null;
|
||||
|
||||
if (!$user_key) {
|
||||
http_response_code(400);
|
||||
exit(json_encode(['error_code' => 'API_INPUT_1','error' => 'user_key is required']));
|
||||
}
|
||||
|
||||
//GET USER_DATA
|
||||
$stmt = $pdo->prepare('SELECT * FROM users WHERE userkey = ?');
|
||||
$stmt->execute([$user_key]);
|
||||
|
||||
if ($stmt->rowCount() == 1) {
|
||||
//Get results
|
||||
$user_data = $stmt->fetch();
|
||||
|
||||
//GET DATA
|
||||
$user_permissions['id'] = $user_data['id'];
|
||||
$user_permissions['email'] = $user_data['email'];
|
||||
$user_permissions['partnerhierarchy'] = $user_data['partnerhierarchy']; //clean;
|
||||
$user_permissions['permission'] = userRights($user_data['view']);
|
||||
$user_permissions['profile'] = getProfile($user_data['settings'],userRights($user_data['view']));
|
||||
|
||||
//NEW DATA REPLACING PROFILE AND LATER PERMISSION ABOVE
|
||||
$user_permissions['permissions'] = getUserPermissions($pdo, $user_data['id']);
|
||||
|
||||
if (!$user_permissions['permissions']) {
|
||||
http_response_code(404);
|
||||
exit(json_encode(['error_code' => 'API_NOT_FOUND','error' => 'No permissions found']));
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++
|
||||
//Return as JSON
|
||||
//+++++++++++++++++++++++++++++++++++++++++++
|
||||
echo json_encode($user_permissions);
|
||||
}
|
||||
else {
|
||||
http_response_code(404);
|
||||
exit(json_encode(['error_code' => 'API_NOT_FOUND','error' => 'User not found']));
|
||||
}
|
||||
|
||||
?>
|
||||
128
api/v2/get/user_role_assignments.php
Normal file
128
api/v2/get/user_role_assignments.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// User Role Assignments
|
||||
//------------------------------------------
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//------------------------------------------
|
||||
//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] =='success_msg'){
|
||||
//do nothing
|
||||
}
|
||||
elseif ($v[0] == 'rowid') {
|
||||
//build up search by ID
|
||||
$clause .= ' AND ura.rowID = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'role_id') {
|
||||
//build up search by role_id
|
||||
$clause .= ' AND ura.role_id = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'user_id') {
|
||||
//build up search by user_id
|
||||
$clause .= ' AND ura.user_id = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'status') {
|
||||
//Update status based on status
|
||||
$clause .= ' AND ura.is_active = :'.$v[0];
|
||||
}
|
||||
else {
|
||||
//create clause
|
||||
$clause .= ' AND ura.'.$v[0].' = :'.$v[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Build WHERE clause
|
||||
$whereclause = '';
|
||||
if ($clause != ''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
}
|
||||
|
||||
if (isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||
//Request for total rows
|
||||
$sql = 'SELECT count(*) as count FROM user_role_assignments ura '.$whereclause;
|
||||
}
|
||||
else {
|
||||
//SQL with joined tables for names
|
||||
$sql = 'SELECT ura.*,
|
||||
u.username,
|
||||
u.email,
|
||||
r.name as role_name,
|
||||
r.description as role_description
|
||||
FROM user_role_assignments ura
|
||||
LEFT JOIN users u ON ura.user_id = u.id
|
||||
LEFT JOIN user_roles r ON ura.role_id = r.rowID
|
||||
'.$whereclause.'
|
||||
ORDER BY u.username ASC';
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
//------------------------------------------
|
||||
//Bind to query
|
||||
//------------------------------------------
|
||||
if (!empty($criterias)){
|
||||
foreach ($criterias as $key => $value){
|
||||
$key_condition = ':'.$key;
|
||||
if (str_contains($sql, $key_condition)){
|
||||
if ($key == 'p'){
|
||||
//Do nothing (bug)
|
||||
}
|
||||
else {
|
||||
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// Debuglog
|
||||
//------------------------------------------
|
||||
if (debug){
|
||||
$message = $date.';'.$sql.';'.$username;
|
||||
debuglog($message);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//Execute Query
|
||||
//------------------------------------------
|
||||
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetch();
|
||||
$messages = $messages[0];
|
||||
}
|
||||
else {
|
||||
//Execute Query
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_EnCODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
//------------------------------------------
|
||||
//Send results
|
||||
//------------------------------------------
|
||||
echo $messages;
|
||||
|
||||
?>
|
||||
167
api/v2/get/user_roles.php
Normal file
167
api/v2/get/user_roles.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// User Roles
|
||||
//------------------------------------------
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//------------------------------------------
|
||||
//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] =='success_msg' || $v[0] =='sort' || $v[0] =='all'){
|
||||
//do nothing
|
||||
}
|
||||
elseif ($v[0] == 'rowid') {
|
||||
//build up search by ID
|
||||
$clause .= ' AND r.rowID = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'status') {
|
||||
//Update status based on status
|
||||
$clause .= ' AND r.is_active = :'.$v[0];
|
||||
}
|
||||
elseif ($v[0] == 'search') {
|
||||
//build up search
|
||||
$clause .= ' AND (r.name LIKE :'.$v[0].' OR r.description LIKE :'.$v[0].')';
|
||||
}
|
||||
elseif ($v[0] == 'name') {
|
||||
//build up name search
|
||||
$clause .= ' AND r.name = :'.$v[0];
|
||||
}
|
||||
else {
|
||||
//create clause
|
||||
$clause .= ' AND r.'.$v[0].' = :'.$v[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Filter system roles for users without delete permission on user_roles
|
||||
if (isAllowed('user_roles', $profile, $permission, 'D') !== 1) {
|
||||
$clause .= ' AND r.is_system != 1';
|
||||
}
|
||||
|
||||
//Build WHERE clause
|
||||
$whereclause = '';
|
||||
if ($clause != ''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
}
|
||||
|
||||
// GET SORT INDICATOR
|
||||
$sort_indicator = $criterias['sort'] ?? '';
|
||||
|
||||
switch ($sort_indicator){
|
||||
case 1:
|
||||
$sort = ' r.name ASC ';
|
||||
break;
|
||||
case 2:
|
||||
$sort = ' r.name DESC ';
|
||||
break;
|
||||
case 3:
|
||||
$sort = ' r.created ASC ';
|
||||
break;
|
||||
case 4:
|
||||
$sort = ' r.created DESC ';
|
||||
break;
|
||||
default:
|
||||
$sort = ' r.rowID ';
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||
//Request for total rows
|
||||
$sql = 'SELECT count(*) as count FROM user_roles r '.$whereclause;
|
||||
}
|
||||
elseif (isset($criterias['all']) && $criterias['all'] ==''){
|
||||
//Return all records (no paging)
|
||||
$sql = 'SELECT r.*,
|
||||
(SELECT COUNT(*) FROM role_access_permissions WHERE role_id = r.rowID) as permission_count
|
||||
FROM user_roles r '.$whereclause.' ORDER BY '.$sort;
|
||||
}
|
||||
else {
|
||||
//SQL with permission count
|
||||
$sql = 'SELECT r.*,
|
||||
(SELECT COUNT(*) FROM role_access_permissions WHERE role_id = r.rowID) as permission_count
|
||||
FROM user_roles r '.$whereclause.' ORDER BY '.$sort.' LIMIT :page,:num_rows';
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
//------------------------------------------
|
||||
//Bind to query
|
||||
//------------------------------------------
|
||||
if (!empty($criterias)){
|
||||
foreach ($criterias as $key => $value){
|
||||
$key_condition = ':'.$key;
|
||||
if (str_contains($sql, $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
|
||||
//------------------------------------------
|
||||
$page_rows = $page_rows_equipment ?? 20;
|
||||
|
||||
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetch();
|
||||
$messages = $messages[0];
|
||||
}
|
||||
elseif(isset($criterias['all']) && $criterias['all']==''){
|
||||
//Return all records (no paging)
|
||||
$stmt->execute();
|
||||
$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, PDO::PARAM_INT);
|
||||
$stmt->bindValue('num_rows', $page_rows, PDO::PARAM_INT);
|
||||
//Execute Query
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_EnCODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
//------------------------------------------
|
||||
//Send results
|
||||
//------------------------------------------
|
||||
echo $messages;
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user