Implement downgrade prevention for paid software versions and update invoice templates with new contact details

This commit is contained in:
“VeLiTi”
2026-02-03 12:46:59 +01:00
parent e97d2e5ef2
commit 5223f6bdfd
7 changed files with 100 additions and 36 deletions

View File

@@ -238,6 +238,7 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
$available_upgrades = 0;
$has_priced_options = false;
$has_latest_version_different = false;
$version_details = []; // Track version details for downgrade prevention
if (debug) {
$debug['version_checks'] = [];
@@ -319,7 +320,7 @@ 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
@@ -342,6 +343,12 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
}
}
// Store version details for downgrade prevention check (after license application)
$version_details[] = [
'show_version' => true,
'final_price' => $final_price
];
// Check for priced options
if ($final_price > 0) {
$has_priced_options = true;
@@ -364,6 +371,48 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
}
}
//PREVENT DOWNGRADE FROM PAID VERSION TO FREE VERSION (if config enabled)
if (defined('PREVENT_PAID_VERSION_DOWNGRADE') && PREVENT_PAID_VERSION_DOWNGRADE && $current_sw_version) {
// Check if user is currently on a paid version (check if there was a paid upgrade path TO current version)
$sql = 'SELECT COUNT(*) as paid_to_current
FROM products_software_upgrade_paths pup
JOIN products_software_versions to_ver ON pup.to_version_id = to_ver.rowID
WHERE LOWER(TRIM(LEADING "0" FROM to_ver.version)) = ?
AND pup.price > 0
AND pup.is_active = 1';
$stmt = $pdo->prepare($sql);
$stmt->execute([$current_sw_version]);
$paid_check = $stmt->fetch(PDO::FETCH_ASSOC);
$is_current_paid_version = ($paid_check['paid_to_current'] > 0);
if (debug) {
$debug['downgrade_prevention'] = [
'enabled' => true,
'current_version' => $current_sw_version,
'is_current_paid_version' => $is_current_paid_version
];
}
// If current version is paid, recalculate available_upgrades excluding free versions
if ($is_current_paid_version) {
$available_upgrades_before = $available_upgrades;
$available_upgrades = 0;
// Recount only paid upgrades (exclude free versions)
foreach ($version_details as $detail) {
if ($detail['show_version'] && floatval($detail['final_price']) > 0) {
$available_upgrades++;
}
}
if (debug) {
$debug['downgrade_prevention']['available_upgrades_before'] = $available_upgrades_before;
$debug['downgrade_prevention']['available_upgrades_after'] = $available_upgrades;
$debug['downgrade_prevention']['message'] = 'Excluded free versions to prevent downgrade from paid version';
}
}
}
// Simple logic: if any upgrades are available to show, return "yes"
if ($available_upgrades > 0) {
$software_available = "yes";

View File

@@ -441,6 +441,46 @@ if (isset($criterias['sn']) && $criterias['sn'] != ''){
}
}
//PREVENT DOWNGRADE FROM PAID VERSION TO FREE VERSION (if config enabled)
if (defined('PREVENT_PAID_VERSION_DOWNGRADE') && PREVENT_PAID_VERSION_DOWNGRADE && $current_sw_version) {
// Check if user is currently on a paid version (check if there was a paid upgrade path TO current version)
$sql = 'SELECT COUNT(*) as paid_to_current
FROM products_software_upgrade_paths pup
JOIN products_software_versions to_ver ON pup.to_version_id = to_ver.rowID
WHERE LOWER(TRIM(LEADING "0" FROM to_ver.version)) = ?
AND pup.price > 0
AND pup.is_active = 1';
$stmt = $pdo->prepare($sql);
$stmt->execute([$current_sw_version]);
$paid_check = $stmt->fetch(PDO::FETCH_ASSOC);
$is_current_paid_version = ($paid_check['paid_to_current'] > 0);
if (debug) {
$debug['downgrade_prevention'] = [
'enabled' => true,
'current_version' => $current_sw_version,
'is_current_paid_version' => $is_current_paid_version
];
}
// If current version is paid, remove all free versions from the output (except current)
if ($is_current_paid_version) {
$output = array_filter($output, function($option) {
$price = floatval($option['price']);
$is_current = $option['is_current'];
// Keep if it's the current version OR if it's a paid version
return $is_current || $price > 0;
});
// Re-index array after filtering
$output = array_values($output);
if (debug) {
$debug['downgrade_prevention']['filtered_count'] = count($output);
$debug['downgrade_prevention']['message'] = 'Removed free versions to prevent downgrade from paid version';
}
}
}
//GENERATE DOWNLOAD TOKENS FOR EACH OPTION
foreach ($output as &$option) {
// Generate time-based download token