Files
assetmgt/softwaretool.php
“VeLiTi” 543f0b3cac feat: Add software licenses management page and update payment handling
- Introduced a new licenses management page with functionality to create, update, and view software licenses.
- Updated payment return handling in softwaretool.php to check payment status from the database and display appropriate modals for success, pending, and failure states.
- Enhanced webhook_mollie.php to log webhook calls, handle payment status updates directly in the database, and generate invoices based on payment status.
- Improved CSS styles for better alignment of buttons and modal components.
- Added JavaScript for modal interactions and bulk license creation functionality.
2025-12-24 14:07:28 +01:00

252 lines
12 KiB
PHP

<?php
defined(page_security_key) or exit;
if (debug && debug_id == $_SESSION['id']){
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
}
$page = 'softwaretool';
//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
$bearertoken = createCommunicationToken($_SESSION['userkey']);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
// PAYMENT RETURN DETECTION
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
$payment_return = isset($_GET['order_id']) ? $_GET['order_id'] : null;
$payment_return_status = isset($_GET['payment_return']) ? $_GET['payment_return'] : null;
template_header('Softwaretool', 'softwaretool','view');
// Show payment return message if returning from payment
$view = '';
$payment_modal = '';
if ($payment_return && $payment_return_status) {
// Check actual payment status in database
$pdo = dbConnect($dbname);
$sql = 'SELECT payment_status FROM transactions WHERE txn_id = ?';
$stmt = $pdo->prepare($sql);
$stmt->execute([$payment_return]);
$transaction = $stmt->fetch(PDO::FETCH_ASSOC);
if ($transaction) {
if ($transaction['payment_status'] == 1) {
// Payment confirmed as paid
$payment_modal = '
<div id="paymentModal" class="modal" style="display: flex; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center;">
<div class="modal-content" style="background: white; border-radius: 12px; max-width: 500px; margin: 20px; box-shadow: 0 10px 40px rgba(0,0,0,0.3); position: relative;">
<span class="close" onclick="closePaymentModal()" style="position: absolute; top: 15px; right: 20px; font-size: 28px; font-weight: bold; color: #999; cursor: pointer;">&times;</span>
<div style="text-align: center; padding: 40px 30px;">
<i class="fa-solid fa-check-circle" style="font-size: 64px; color: #28a745; margin-bottom: 20px;"></i>
<h2 style="color: #155724; margin-bottom: 15px;">Payment Successful!</h2>
<p style="margin-bottom: 10px; color: #333;">Your payment has been processed. Please reconnect your device to apply the software upgrade.</p>
<p style="font-size: 12px; color: #666; margin-bottom: 25px;">Order ID: '.htmlspecialchars($payment_return).'</p>
<button onclick="closePaymentModal()" class="btn" style="padding: 12px 30px;">Continue</button>
</div>
</div>
</div>';
} else if ($transaction['payment_status'] == 0 || $transaction['payment_status'] == 101) {
// Payment pending
$payment_modal = '
<div id="paymentModal" class="modal" style="display: flex; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center;">
<div class="modal-content" style="background: white; border-radius: 12px; max-width: 500px; margin: 20px; box-shadow: 0 10px 40px rgba(0,0,0,0.3);">
<div style="text-align: center; padding: 40px 30px;">
<i class="fa-solid fa-clock" style="font-size: 64px; color: #ffc107; margin-bottom: 20px;"></i>
<h2 style="color: #856404; margin-bottom: 15px;">Payment Processing...</h2>
<p style="margin-bottom: 10px; color: #333;">Your payment is being processed. This page will update automatically when confirmed.</p>
<p style="font-size: 12px; color: #666; margin-bottom: 25px;">Order ID: '.htmlspecialchars($payment_return).'</p>
<i class="fa-solid fa-spinner fa-spin" style="font-size: 32px; color: #ffc107;"></i>
</div>
</div>
</div>
<script>
// Auto-refresh every 3 seconds to check payment status
setTimeout(function() { location.reload(); }, 3000);
</script>';
} else {
// Payment failed/cancelled
$payment_modal = '
<div id="paymentModal" class="modal" style="display: flex; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center;">
<div class="modal-content" style="background: white; border-radius: 12px; max-width: 500px; margin: 20px; box-shadow: 0 10px 40px rgba(0,0,0,0.3); position: relative;">
<span class="close" onclick="closePaymentModal()" style="position: absolute; top: 15px; right: 20px; font-size: 28px; font-weight: bold; color: #999; cursor: pointer;">&times;</span>
<div style="text-align: center; padding: 40px 30px;">
<i class="fa-solid fa-exclamation-circle" style="font-size: 64px; color: #dc3545; margin-bottom: 20px;"></i>
<h2 style="color: #721c24; margin-bottom: 15px;">Payment Failed</h2>
<p style="margin-bottom: 10px; color: #333;">Your payment could not be processed. Please try again.</p>
<p style="font-size: 12px; color: #666; margin-bottom: 25px;">Order ID: '.htmlspecialchars($payment_return).'</p>
<button onclick="closePaymentModal()" class="btn" style="padding: 12px 30px;">Close</button>
</div>
</div>
</div>';
}
}
}
$view .= '
<div class="content-title">
<div class="title">
<i class="fa-solid fa-box-open"></i>
<div class="txt">
<h2>'.$softwaretool_h2 .'</h2>
<p>'.$softwaretool_p.'</p>
</div>
</div>';
if (isset($_GET['equipmentID'])){$returnpage = 'equipment&equipmentID='.$_GET['equipmentID']; } else {$returnpage = 'dashboard';}
//SHOW BACK BUTTON ONLY FOR PORTAL USERS
if (isAllowed('dashboard',$_SESSION['profile'],$_SESSION['permission'],'R') != 0){
$view .= '
<div class="title-actions">
<a href="index.php?page='.$returnpage.'" class="btn alt mar-right-2"><i class="fa-solid fa-arrow-left"></i></a>
<button class="btn" onclick="showInstructions()" style="">
<i class="fa-solid fa-circle-question"></i>
</button>
</div>
';
}
$view .= '
</div>';
$view .= '<div class="content-block">
<p id="servicetoken" value="" hidden>'.$bearertoken.'</p>
<div id="connectdevice" style="display:flex; gap: 10px; margin-bottom: 20px;">
<button class="btn" id="connectButton" onClick="connectDeviceForSoftware()" style="min-width: 150px;">
<i class="fa-solid fa-plug"></i>Connect
</button>
<div id="readStatus" style="flex: 1; background-color: #f1f1f1; border-radius: 4px; overflow: hidden;">
<div id="readBar" style="height: 100%; transition: width 0.3s ease;"></div>
</div>
</div>
<div id="Device_output" style="display:none;">
<div id="serialResults" style="font-family: monospace;white-space: pre;padding: 10px;background-color:#f1f1f1;display:none;"></div>
<div id="softwareCheckStatus" style="margin: 20px 0; padding: 20px; background-color:#f8f9fa; border-radius: 8px; text-align: center; display:none;">
<i class="fa-solid fa-spinner fa-spin" style="font-size: 24px; color: #04AA6D; margin-bottom: 10px;"></i>
<p id="checkingMessage" style="margin: 0; font-size: 16px;">'.$softwaretool_checking.'</p>
</div>
<div id="softwareOptions" style="margin-top: 20px; display:none;">
<h3 style="margin-bottom: 20px; color: #333;">'.$softwaretool_select_upgrade.'</h3>
<div id="softwareOptionsGrid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; justify-content: center; max-width: 1200px; margin: 0 auto;">
</div>
</div>
<div id="noUpdatesMessage" style="margin: 20px 0; padding: 30px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 12px; text-align: center; display:none;">
<i class="fa-solid fa-check-circle" style="font-size: 48px; margin-bottom: 15px;"></i>
<p style="margin: 0; font-size: 18px; font-weight: 500;"><strong>'.$softwaretool_no_updates.'</strong></p>
<p style="margin: 10px 0 0 0; opacity: 0.9;">Your device is up to date</p>
</div>
<div id="uploadSection" style="margin-top: 10px; display:none;">
<button class="btn" id="uploadSoftware" style="display:none;"
emergencyPlug-update verify
board="emergencyPlug"
port-filters= "[{usbVendorId: 1027, usbProductId: 24597}];"
disabled>Install Software
<span class="upload-progress"></span>
</button>
</div>
</div>
</div>
<!-- Help Modal -->
<div id="helpModal" style="display:none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center;">
<div style="background: white; border-radius: 12px; max-width: 600px; max-height: 80vh; overflow-y: auto; margin: 20px; box-shadow: 0 10px 40px rgba(0,0,0,0.3);">
<div style="padding: 25px; border-bottom: 1px solid #e0e0e0; display: flex; justify-content: space-between; align-items: center;">
<h3 style="margin: 0; color: #333;"><i class="fa-solid fa-circle-question"></i> '.$softwaretool_step.'</h3>
<button onclick="closeInstructions()" style="background: transparent; border: none; font-size: 20px; cursor: pointer; color: #666;"><i class="fa-solid fa-times"></i></button>
</div>
<div style="padding: 25px;">
<ol style="line-height: 1.8; color: #555;">
<li style="margin-bottom: 15px;">'.$softwaretool_step_1.'</li>
<li style="margin-bottom: 15px;">'.$softwaretool_step_2.'</li>
<li style="margin-bottom: 15px;">'.$softwaretool_step_3.'</li>
<li style="margin-bottom: 15px;">'.$softwaretool_step_4.'</li>
<li style="margin-bottom: 15px;">'.$softwaretool_step_5.'</li>
<li style="margin-bottom: 15px;">'.$softwaretool_step_6.'</li>
<li style="margin-bottom: 15px;">'.$softwaretool_step_7.'</li>
<li style="margin-bottom: 15px;">'.$softwaretool_step_8.'</li>
</ol>
</div>
</div>
</div>
';
$view .= '
</div>
</div>
';
$view .= '</div>';
//OUTPUT
echo $view;
// Output payment modal if exists
echo $payment_modal;
echo '
<script src="assets/upload.js?'.script_version.'"></script>
<script src="assets/softwaretool.js?'.script_version.'"></script>
<script>
var link = "'.$baseurl.'";
var DEBUG = '.(debug ? 'true' : 'false').';
var port, textEncoder, writableStreamClosed, writer, historyIndex = -1;
const lineHistory = [];
// Modal functions - defined globally for inline onclick
window.showInstructions = function() {
const modal = document.getElementById("helpModal");
if (modal) {
modal.style.display = "flex";
}
};
window.closeInstructions = function() {
const modal = document.getElementById("helpModal");
if (modal) {
modal.style.display = "none";
}
};
// Payment modal functions
window.closePaymentModal = function() {
const modal = document.getElementById("paymentModal");
if (modal) {
modal.style.display = "none";
// Clean URL by removing payment_return and order_id parameters
const url = new URL(window.location);
url.searchParams.delete("payment_return");
url.searchParams.delete("order_id");
window.history.replaceState({}, document.title, url);
}
};
// Close modal on background click
document.addEventListener("click", function(e) {
const helpModal = document.getElementById("helpModal");
if (helpModal && e.target === helpModal) {
closeInstructions();
}
const paymentModal = document.getElementById("paymentModal");
if (paymentModal && e.target === paymentModal) {
closePaymentModal();
}
});
</script>';
template_footer();
?>