diff --git a/account_manage.php b/account_manage.php index 9af1788..2e822c1 100644 --- a/account_manage.php +++ b/account_manage.php @@ -140,7 +140,7 @@ if ($delete_allowed === 1){ $view .= ''; } if ($update_allowed === 1){ - $view .= ''; + $view .= ''; } $view .= ''; diff --git a/api/v2/post/history.php b/api/v2/post/history.php index b24d723..5290e69 100644 --- a/api/v2/post/history.php +++ b/api/v2/post/history.php @@ -155,7 +155,6 @@ if (isset($post_content['sn']) && (isset($post_content['payload']) || isset($pos case 'customer': //update from Portal $historytype = 'Customer'; - $equipmentUpdate = 1; break; default: diff --git a/api/v2/post/payment.php b/api/v2/post/payment.php index e9e559e..1e79ad0 100644 --- a/api/v2/post/payment.php +++ b/api/v2/post/payment.php @@ -1,8 +1,5 @@ fetch(PDO::FETCH_ASSOC); $has_upgrade_paths = ($path_count_result['path_count'] > 0); if (!$has_upgrade_paths) { - // No upgrade paths defined = FREE (lines 240-242 in software_update.php) + // No upgrade paths defined = FREE (lines 328-331 in software_update.php) $final_price = '0.00'; + if (debug) { + debuglog("DEBUG: No upgrade paths defined for version_id $version_id - upgrade is FREE"); + } } else { - // Check for valid upgrade path FROM current version + // Check for valid upgrade path FROM current version (same logic as software_update.php lines 335-353) $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 @@ -93,14 +94,28 @@ if (!$has_upgrade_paths) { $stmt->execute([$version_id, $current_sw_version]); $upgrade_path = $stmt->fetch(PDO::FETCH_ASSOC); + if (debug) { + debuglog("DEBUG: Looking for upgrade path TO version_id=$version_id FROM current_sw_version='$current_sw_version'"); + debuglog("DEBUG: Upgrade path result: " . json_encode($upgrade_path)); + } + if ($upgrade_path) { $final_price = $upgrade_path['price'] ?? '0.00'; $final_currency = $upgrade_path['currency'] ?? 'EUR'; + if (debug) { + debuglog("DEBUG: Found upgrade path - price: $final_price $final_currency"); + } } else { // No upgrade path FROM current version - + if (debug) { + debuglog("ERROR: No valid upgrade path from current version '$current_sw_version' to version_id $version_id"); + } http_response_code(400); - echo json_encode(['error' => 'No valid upgrade path from current version'], JSON_UNESCAPED_UNICODE); + echo json_encode([ + 'error' => 'No valid upgrade path from current version', + 'current_version' => $current_sw_version, + 'target_version_id' => $version_id + ], JSON_UNESCAPED_UNICODE); exit; } } diff --git a/api/v2/post/products_software_licenses.php b/api/v2/post/products_software_licenses.php index 1b3a6fe..1282504 100644 --- a/api/v2/post/products_software_licenses.php +++ b/api/v2/post/products_software_licenses.php @@ -22,7 +22,7 @@ $command = ($id == '')? 'insert' : 'update'; //IF rowID = empty then INSERT if (isset($post_content['delete'])){$command = 'delete';} //change command to delete // Check for bulk creation -$is_bulk = isset($post_content['bulk']) && $post_content['bulk'] === true; +$is_bulk = isset($post_content['bulk']) && ($post_content['bulk'] === "true" || $post_content['bulk'] === true); $date = date('Y-m-d H:i:s'); @@ -37,12 +37,24 @@ $input_insert = ''; if ($command == 'insert' && $is_bulk && isAllowed('products_software_licenses',$profile,$permission,'C') === 1){ $version_id = $post_content['version_id'] ?? ''; - $serials = $post_content['serials'] ?? []; + $serials_input = $post_content['serials'] ?? ''; + + // Convert comma-separated string to array and trim whitespace + if (is_string($serials_input)) { + $serials = array_map('trim', explode(',', $serials_input)); + } elseif (is_array($serials_input)) { + $serials = $serials_input; + } else { + $serials = []; + } + $transaction_id = $post_content['transaction_id'] ?? ''; $license_type = $post_content['license_type'] ?? 0; - $status = $post_content['status'] ?? 0; + $status = $post_content['status'] ?? 1; + $starts_at = $post_content['starts_at'] ?? date('Y-m-d H:i:s'); + $expires_at = $post_content['expires_at'] ?? '2099-12-31 23:59:59'; // effectively permanent - if (empty($version_id) || empty($serials) || !is_array($serials)) { + if (empty($version_id) || empty($serials)) { http_response_code(400); echo json_encode(['error' => 'Invalid parameters for bulk creation']); exit; @@ -51,8 +63,8 @@ if ($command == 'insert' && $is_bulk && isAllowed('products_software_licenses',$ $accounthierarchy = json_encode(array("salesid"=>$partner->salesid,"soldto"=>$partner->soldto), JSON_UNESCAPED_UNICODE); // Prepare statement for bulk insert - $sql = 'INSERT INTO products_software_licenses (version_id, license_key, license_type, status, transaction_id, accounthierarchy, created, createdby) - VALUES (?, ?, ?, ?, ?, ?, ?, ?)'; + $sql = 'INSERT INTO products_software_licenses (version_id, license_key, license_type, status, starts_at, expires_at, transaction_id, accounthierarchy, created, createdby) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; $stmt = $pdo->prepare($sql); $created_count = 0; @@ -60,13 +72,7 @@ if ($command == 'insert' && $is_bulk && isAllowed('products_software_licenses',$ if (empty($serial)) continue; // Generate UUID for license key - $license_key = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', - mt_rand(0, 0xffff), mt_rand(0, 0xffff), - mt_rand(0, 0xffff), - mt_rand(0, 0x0fff) | 0x4000, - mt_rand(0, 0x3fff) | 0x8000, - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) - ); + $license_key = generateUniqueLicenseKey(); try { $stmt->execute([ @@ -74,6 +80,8 @@ if ($command == 'insert' && $is_bulk && isAllowed('products_software_licenses',$ $license_key, $license_type, $status, + $starts_at, + $expires_at, $transaction_id, $accounthierarchy, $date, @@ -81,9 +89,9 @@ if ($command == 'insert' && $is_bulk && isAllowed('products_software_licenses',$ ]); // Assign license to equipment if serial number exists - $eq_sql = 'UPDATE equipment SET sw_version_license = ? WHERE serialnumber = ? AND accounthierarchy LIKE ?'; + $eq_sql = 'UPDATE equipment SET sw_version_license = ? WHERE serialnumber = ? '; $eq_stmt = $pdo->prepare($eq_sql); - $eq_stmt->execute([$license_key, $serial, '%'.$partner->soldto.'%']); + $eq_stmt->execute([$license_key, $serial]); $created_count++; } catch (Exception $e) { @@ -104,17 +112,8 @@ if ($command == 'update'){ $post_content['updatedby'] = $username; } elseif ($command == 'insert'){ - // Generate UUID for license key if not provided - if (empty($post_content['license_key'])) { - $post_content['license_key'] = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', - mt_rand(0, 0xffff), mt_rand(0, 0xffff), - mt_rand(0, 0xffff), - mt_rand(0, 0x0fff) | 0x4000, - mt_rand(0, 0x3fff) | 0x8000, - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) - ); - } - + // Generate UUID for license key + $post_content['license_key'] = generateUniqueLicenseKey(); $post_content['created'] = $date; $post_content['createdby'] = $username; $post_content['accounthierarchy'] = json_encode(array("salesid"=>$partner->salesid,"soldto"=>$partner->soldto), JSON_UNESCAPED_UNICODE); diff --git a/assets/functions.php b/assets/functions.php index 77ec17a..b9ed30c 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -83,7 +83,9 @@ function send_mail($to, $subject, $message, $attachment, $attachment_name){ if( !$mail->send() ){ // render error if it is $tab = array('error' => 'Mailer Error: '.$mail->ErrorInfo ); - debuglog(json_encode($tab)); + if(debug){ + debuglog(json_encode($tab)); + } exit; } else{ @@ -157,7 +159,9 @@ function sendIcsCalendar($appointment, $to, $subject = 'Appointment Confirmation if (!$mail->send()) { $tab = array('error' => 'Mailer Error: ' . $mail->ErrorInfo); - debuglog(json_encode($tab)); + if(debug){ + debuglog(json_encode($tab)); + } return false; } else { return true; @@ -1067,7 +1071,9 @@ function validate_secure_download_token($token, $secret_key = null) { // Check JSON parsing with detailed error info if ($header === null) { $json_error = json_last_error_msg(); - debuglog("JSON decode failed for header. Raw JSON: " . $header_json . " Error: " . $json_error); + if(debug){ + debuglog("JSON decode failed for header. Raw JSON: " . $header_json . " Error: " . $json_error); + } return ['error' => 'INVALID_TOKEN', 'message' => 'Failed to decode token header JSON: ' . $json_error]; } if ($payload === null) { @@ -1227,6 +1233,11 @@ function log_download($params) { function ioServer($api_call, $data){ include dirname(__FILE__,2).'/settings/settings_redirector.php'; + + if(debug){ + $data_log = is_array($data) ? json_encode($data) : $data; + debuglog($date." - ioServer incoming call: api_call=$api_call, data=" . $data_log); + } $token = $_SESSION['userkey'] ?? 'authorization_request'; $bearertoken = createCommunicationToken($token); @@ -1252,7 +1263,11 @@ function ioServer($api_call, $data){ $resp = curl_exec($curl); $http_status = curl_getinfo($curl) ?? '200'; curl_close($curl); - + + if(debug){ + debuglog($date." - ioServer: URL=$url, HTTP Code=$http_status, Response=" . substr($resp, 0, 500) . (strlen($resp) > 500 ? '...' : '')); + } + //Check If errorcode is returned if($http_status['http_code'] == '403' || $http_status['http_code'] == '400') {$resp = generate_payload('NOK');} @@ -1533,6 +1548,8 @@ function getProfile($profile, $permission){ 'software_update' => 'R', 'software_download' => 'R', 'software_available' => 'R', + 'history' => 'U', + 'payment' => 'U', 'marketing_files' => 'CRUD', 'marketing_folders' => 'CRUD', 'marketing_tags' => 'CRUD', @@ -1553,11 +1570,16 @@ function getProfile($profile, $permission){ ]; // Debug log - debuglog("isAllowed called: page=$page, permission=$permission, action=$action"); - + if(debug){ + debuglog("isAllowed called: page=$page, permission=$permission, action=$action"); + } // 1. Check always allowed if (isset($always_allowed[$page]) && str_contains($always_allowed[$page], $action)) { - debuglog("Allowed by always_allowed"); + + if(debug){ + debuglog("Allowed by always_allowed"); + } + return 1; } @@ -1568,11 +1590,15 @@ function getProfile($profile, $permission){ $page_action = str_contains($user_permission,$action) > 0 ? 1 : 0; //CHECK IF USER IS ALLOWED TO DO THE ACTION $page_access = str_contains($profile,$page) > 0 ? 1 : 0; //CHECK USER IS ALLOWED TO ACCESS PAGE - debuglog("user_permission=$user_permission, page_action=$page_action, page_access=$page_access"); + if(debug){ + debuglog("user_permission=$user_permission, page_action=$page_action, page_access=$page_access"); + } // 2. Check user permissions (standard) if ($page_access == 1 && $page_action == 1){ - debuglog("Allowed by user permissions"); + if(debug){ + debuglog("Allowed by user permissions"); + } return 1; } @@ -1580,16 +1606,22 @@ function getProfile($profile, $permission){ if ($page_access == 0) { foreach ($group_permissions as $granting_page => $grants) { if (str_contains($profile, $granting_page)) { - debuglog("Found granting_page: $granting_page"); + if(debug){ + debuglog("Found granting_page: $granting_page"); + } if (isset($grants[$page]) && str_contains($grants[$page], $action)) { - debuglog("Allowed by group permissions"); + if(debug){ + debuglog("Allowed by group permissions"); + } return 1; } } } } - debuglog("Not allowed"); + if(debug){ + debuglog("Not allowed"); + } // Not allowed return 0; } @@ -5209,7 +5241,7 @@ function updateSoftwareVersionStatus($pdo, $serialnumber = null) { SET e.sw_version_latest = 1 WHERE psv.latest = 1 AND psv.status = 1 - AND lower(e.sw_version) = lower(psv.version) + AND LOWER(TRIM(LEADING "0" FROM e.sw_version)) = lower(psv.version) AND (lower(psv.hw_version) = lower(e.hw_version) OR lower(psv.hw_version) IS NULL OR lower(psv.hw_version) = "") AND e.sw_version_latest = 0' . $sn_clause; diff --git a/assets/softwaretool.js b/assets/softwaretool.js index be93872..280feaf 100644 --- a/assets/softwaretool.js +++ b/assets/softwaretool.js @@ -1034,8 +1034,8 @@ function showPaymentModal(option) { diff --git a/cartest_manage.php b/cartest_manage.php index ed7a1e7..e410d5a 100644 --- a/cartest_manage.php +++ b/cartest_manage.php @@ -181,7 +181,7 @@ if ($delete_allowed === 1){ $view .= ''; } if ($update_allowed === 1){ - $view .= ''; + $view .= ''; } $view .= ''; diff --git a/category.php b/category.php index c0544b0..63396e5 100644 --- a/category.php +++ b/category.php @@ -104,7 +104,7 @@ if ($delete_allowed === 1){ $view .= ''; } if ($update_allowed === 1){ - $view .= ''; + $view .= ''; } $view .= ''; diff --git a/communication.php b/communication.php index 9fb97e3..5c3334e 100644 --- a/communication.php +++ b/communication.php @@ -106,7 +106,7 @@ if ($delete_allowed === 1){ $view .= ''; } if ($update_allowed === 1){ - $view .= ''; + $view .= ''; } $view .= ''; diff --git a/contract_manage.php b/contract_manage.php index f2a6042..032dfae 100644 --- a/contract_manage.php +++ b/contract_manage.php @@ -121,7 +121,7 @@ if ($delete_allowed === 1){ $view .= ''; } if ($update_allowed === 1){ - $view .= ''; + $view .= ''; } $view .= ''; diff --git a/dealer_manage.php b/dealer_manage.php index 395e7f2..23798f8 100644 --- a/dealer_manage.php +++ b/dealer_manage.php @@ -148,7 +148,7 @@ if ($delete_allowed === 1){ $view .= ''; } if ($update_allowed === 1){ - $view .= ''; + $view .= ''; } $view .= ''; diff --git a/discount.php b/discount.php index 6945376..67b87ba 100644 --- a/discount.php +++ b/discount.php @@ -120,7 +120,7 @@ if ($delete_allowed === 1){ $view .= ''; } if ($update_allowed === 1){ - $view .= ''; + $view .= ''; } $view .= ''; diff --git a/equipment_manage.php b/equipment_manage.php index f6edc7f..3c179a8 100644 --- a/equipment_manage.php +++ b/equipment_manage.php @@ -152,7 +152,7 @@ if ($delete_allowed === 1 || $equipment_owner === 1){ $view .= ''; } if ($update_allowed === 1 || $equipment_owner === 1){ - $view .= ''; + $view .= ''; } $view .= ''; diff --git a/equipments_mass_update.php b/equipments_mass_update.php index 13ff1f8..9f37425 100644 --- a/equipments_mass_update.php +++ b/equipments_mass_update.php @@ -171,7 +171,7 @@ $view = ' if ($update_allowed === 1){ $print_btn_class = ($output_excel_display != '') ? 'btn' : 'btn alt'; $view .= ''; - $view .= ''; + $view .= ''; } $view .= ''; diff --git a/factuur.php b/factuur.php index f394609..713af31 100644 --- a/factuur.php +++ b/factuur.php @@ -59,9 +59,9 @@ if (!empty($invoice_data['customer']['language'])) { // Generate invoice HTML //+++++++++++++++++++++++++++++++++++++++++++++++++++++ -var_dump($invoice_data); list($data, $customer_email, $order_id) = generateSoftwareInvoice($invoice_data, $order_number, $invoice_language); + //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // Check for HTML output request //+++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -92,6 +92,7 @@ $dompdf->render(); $file_name = 'Factuur - ' . $order_id; + //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // Handle different actions //+++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -124,7 +125,7 @@ if (isset($_POST['email_invoice_to_admin'])) { $header_redirect = 'Location: index.php?page=order&id=' . $order_id . '&success=invoice_sent_admin'; // Send to bookkeeping if configured - if (defined('invoice_bookkeeping') && invoice_bookkeeping && defined('email_bookkeeping') && email_bookkeeping) { + if (invoice_bookkeeping && email_bookkeeping) { send_mail(email_bookkeeping, $subject, $message, $attachment, $attachment_name); } @@ -133,7 +134,7 @@ if (isset($_POST['email_invoice_to_admin'])) { } // Show invoice in browser -if (isset($_POST['show_invoice'])) { +if (isset($_GET['show_invoice'])) { // Clean output buffer to prevent corrupted PDF if (ob_get_level()) { ob_end_clean(); diff --git a/history_manage.php b/history_manage.php index 2403cae..d169369 100644 --- a/history_manage.php +++ b/history_manage.php @@ -108,7 +108,7 @@ if ($delete_allowed === 1){ $view .= ''; } if ($update_allowed === 1){ - $view .= ''; + $view .= ''; } $view .= ''; diff --git a/language.php b/language.php index 1837706..ede9d33 100644 --- a/language.php +++ b/language.php @@ -33,7 +33,7 @@ if (isset($_GET['success_msg'])) {
' . htmlspecialchars($order['customer']['phone'], ENT_QUOTES) . '
+' . htmlspecialchars($order['customer']['phone'] ?? '-', ENT_QUOTES) . '
The order is not associated with an account.
'; @@ -223,14 +224,14 @@ $view .='' . htmlspecialchars($order['customer']['street'], ENT_QUOTES) . '
- ' . htmlspecialchars($order['customer']['city'], ENT_QUOTES) . '
- ' . htmlspecialchars($order['customer']['state'], ENT_QUOTES) . '
- ' . htmlspecialchars($order['customer']['zip'], ENT_QUOTES) . '
- ' . htmlspecialchars($order['customer']['country'], ENT_QUOTES) . '
' . htmlspecialchars($order['customer']['phone'], ENT_QUOTES) . '
+' . htmlspecialchars($order['customer']['phone'] ?? '-', ENT_QUOTES) . '
| - - |