CMXX - First candidate

This commit is contained in:
“VeLiTi”
2025-03-05 20:45:35 +01:00
parent 3a52632d61
commit faf5a5156b
29 changed files with 588 additions and 1053 deletions

View File

@@ -293,9 +293,112 @@ echo <<<EOT
<link href="./assets/fontawesome/css/solid.css" rel="stylesheet" />
<script src="./assets/leaflet.js"></script>
<script src="./assets/charts.js"></script>
<script>
// Wait for DOM to be ready before accessing elements
document.addEventListener('DOMContentLoaded', function() {
// Get loading screen element
const loadingScreen = document.getElementById('loadingScreen');
// Only proceed if the element exists
if (!loadingScreen) {
console.error('Loading screen element not found!');
return;
}
// Show loading screen
function showLoading() {
loadingScreen.classList.add('active');
}
// Hide loading screen
function hideLoading() {
loadingScreen.classList.remove('active');
}
// Show loading when page initially loads
showLoading();
// Hide loading when everything is loaded
window.addEventListener('load', hideLoading);
// In case the page loads very quickly
setTimeout(hideLoading, 500);
// Intercept form submissions
setupFormInterception();
// Intercept fetch and XMLHttpRequest
interceptNetworkRequests();
// Intercept all form submissions
function setupFormInterception() {
const forms = document.querySelectorAll('form');
forms.forEach(form => {
form.addEventListener('submit', function(e) {
// Show loading screen before form submission
showLoading();
});
});
}
// Intercept all network requests (fetch and XMLHttpRequest)
function interceptNetworkRequests() {
// Track active requests
let activeRequests = 0;
// Intercept fetch API
const originalFetch = window.fetch;
window.fetch = function() {
showLoading();
activeRequests++;
return originalFetch.apply(this, arguments)
.then(response => {
activeRequests--;
if (activeRequests === 0) hideLoading();
return response;
})
.catch(error => {
activeRequests--;
if (activeRequests === 0) hideLoading();
throw error;
});
};
// Intercept XMLHttpRequest
const originalXHROpen = XMLHttpRequest.prototype.open;
const originalXHRSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.open = function() {
return originalXHROpen.apply(this, arguments);
};
XMLHttpRequest.prototype.send = function() {
showLoading();
activeRequests++;
this.addEventListener('loadend', function() {
activeRequests--;
if (activeRequests === 0) hideLoading();
});
return originalXHRSend.apply(this, arguments);
};
}
});
</script>
$veliti_analytics
</head>
<body class="admin">
<!-- Loading Bar -->
<div class="loading-container" id="loadingScreen">
<div class="loading-bar">
<div class="progress"></div>
</div>
<div class="loading-text">Loading, please wait...</div>
</div>
<aside class="responsive-width-100 responsive-hidden">
<h1></h1>
$admin_links
@@ -702,7 +805,11 @@ function getWhereclause($table_name,$permission,$partner,$method){
"equipment" => "e.accounthierarchy",
"products" => "p.accounthierarchy",
"profile" => "partnerhierarchy",
"text_variables" => "tv.accounthierarchy"
"text_variables" => "tv.accounthierarchy",
"products_attributes_items" => "pat.accounthierarchy",
"products_attributes_groups" => "pag.accounthierarchy",
"pricelists" => "pls.accounthierarchy",
"pricelists_items" => "pli.accounthierarchy"
];
$table = ($table_name != '') ? $table[$table_name] : 'accounthierarchy';
@@ -3604,7 +3711,8 @@ function transformOrderData(array $orderData): array {
'state' => $firstRow['address_state'],
'city' => $firstRow['address_city'],
'country' => $firstRow['address_country'],
'phone' => $firstRow['address_phone']
'phone' => $firstRow['address_phone'],
'language' => $firstRow['user_language'],
],
'products' => [],
'invoice' => [
@@ -3654,6 +3762,49 @@ function transformOrderData(array $orderData): array {
return $result;
}
function transformOrders($inputData){
// Define which fields are item-specific (will go into the items array)
$itemFields = ['item_id', 'item_name', 'item_price', 'item_quantity', 'item_options', 'full_path'];
// Process the data
$combinedData = [];
foreach ($inputData as $row) {
$txnId = $row['txn_id'];
// Create header and item arrays for the current row
$headerData = [];
$itemData = [];
foreach ($row as $key => $value) {
if (in_array($key, $itemFields)) {
// This is an item field
$itemData[$key] = $value;
} else {
// This is a header field
$headerData[$key] = $value;
}
}
// Check if this transaction ID already exists in our result array
if (!isset($combinedData[$txnId])) {
// First occurrence of this transaction - create the structure
$combinedData[$txnId] = [
'header' => $headerData,
'items' => [$itemData]
];
} else {
// Transaction already exists - just add the item data
$combinedData[$txnId]['items'][] = $itemData;
}
}
// Convert associative array to indexed array if needed
$finalResult = array_values($combinedData);
return $finalResult;
}
//=============================================
// Use giftcart
//=============================================