From 80416b952b3da7ee3d38d1072a16a2b50ef49cd0 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 3 May 2026 10:26:26 +0000 Subject: [PATCH] update1111 --- cron_wablas.php | 18 ++++- index.php | 170 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 186 insertions(+), 2 deletions(-) diff --git a/cron_wablas.php b/cron_wablas.php index 2b5922a..3d3704c 100644 --- a/cron_wablas.php +++ b/cron_wablas.php @@ -14,7 +14,23 @@ if (PHP_SAPI !== 'cli') { require_once __DIR__ . '/db/config.php'; require_once __DIR__ . '/includes/DatabaseInstaller.php'; -require_once __DIR__ . '/includes/wablas_helper.php'; + +$wablasHelperPath = __DIR__ . '/includes/wablas_helper.php'; +if (!is_file($wablasHelperPath)) { + $message = 'Wablas helper is missing from this deployment: includes/wablas_helper.php'; + @file_put_contents( + __DIR__ . '/runtime_debug.log', + date('Y-m-d H:i:s') . " || [cron_wablas_missing_helper] || {$message}" . PHP_EOL, + FILE_APPEND + ); + if (PHP_SAPI !== 'cli') { + http_response_code(503); + header('Content-Type: text/plain; charset=utf-8'); + header('X-Robots-Tag: noindex, nofollow'); + } + exit($message . PHP_EOL); +} +require_once $wablasHelperPath; DatabaseInstaller::ensureCurrentSchema(); diff --git a/index.php b/index.php index 41aec08..76a6e99 100644 --- a/index.php +++ b/index.php @@ -301,11 +301,179 @@ if (isset($_GET['action']) && $_GET['action'] === 'download_items_template') { if ($_SERVER['REQUEST_METHOD'] === 'POST') { app_debug_file_log('post_debug.log', date('Y-m-d H:i:s') . " - POST: " . json_encode($_POST)); } + +if (!function_exists('wablas_helper_missing_message')) { + function wablas_helper_missing_message(): string { + return 'Wablas integration is temporarily unavailable because includes/wablas_helper.php is missing from this deployment.'; + } +} + +if (!function_exists('register_wablas_helper_fallback')) { + function register_wablas_helper_fallback(string $missingPath): void { + $GLOBALS['app_wablas_helper_missing'] = $missingPath; + + runtime_debug_boot_mark('boot:wablas_helper_fallback', [ + 'missing' => basename($missingPath), + ]); + + @file_put_contents( + __DIR__ . '/runtime_debug.log', + date('Y-m-d H:i:s') . " || [wablas_helper_fallback] || Missing include={$missingPath} || uri=" . ($_SERVER['REQUEST_URI'] ?? 'cli') . PHP_EOL, + FILE_APPEND + ); + + if (!function_exists('wablasHelperAvailable')) { + function wablasHelperAvailable(): bool { + return false; + } + } + + if (!function_exists('wablasSettingValue')) { + function wablasSettingValue(string $key, ?string $default = null): ?string { + return $default; + } + } + + if (!function_exists('wablasNumbersFromText')) { + function wablasNumbersFromText(string $rawNumbers, string $defaultCountryCode = ''): array { + $parts = preg_split('/[\s,;]+/', str_replace(["\r", "\n", "\t"], ' ', $rawNumbers)) ?: []; + $normalized = []; + $defaultCountryCode = preg_replace('/[^0-9]/', '', $defaultCountryCode); + + foreach ($parts as $part) { + $candidate = trim((string)$part); + if ($candidate === '') { + continue; + } + + $candidate = preg_replace('/[^0-9+]/', '', $candidate); + if ($candidate === '') { + continue; + } + + if (str_starts_with($candidate, '00')) { + $candidate = '+' . substr($candidate, 2); + } + + if ($candidate[0] !== '+' && $defaultCountryCode !== '') { + $candidate = '+' . $defaultCountryCode . ltrim($candidate, '0'); + } + + $normalized[] = $candidate; + } + + return array_values(array_unique(array_filter($normalized))); + } + } + + if (!function_exists('wablasNow')) { + function wablasNow(): DateTimeImmutable { + return new DateTimeImmutable('now', new DateTimeZone(date_default_timezone_get())); + } + } + + if (!function_exists('wablasSendManualTest')) { + function wablasSendManualTest(array $numbers, string $message): array { + return [ + 'success' => false, + 'error' => wablas_helper_missing_message(), + ]; + } + } + + if (!function_exists('wablasQueueDailySummaryIfDue')) { + function wablasQueueDailySummaryIfDue(?DateTimeImmutable $now = null): array { + return [ + 'queued' => false, + 'reason' => 'helper_missing', + 'error' => wablas_helper_missing_message(), + ]; + } + } + + if (!function_exists('wablasProcessDueDispatches')) { + function wablasProcessDueDispatches(int $limit = 20): array { + return [ + 'success' => false, + 'checked' => 0, + 'sent' => 0, + 'failed' => 0, + 'skipped' => 0, + 'messages' => [wablas_helper_missing_message()], + ]; + } + } + + if (!function_exists('wablasQueueInvoiceNotification')) { + function wablasQueueInvoiceNotification(int $invoiceId): array { + return [ + 'success' => false, + 'notice' => ' WhatsApp notification was skipped because includes/wablas_helper.php is missing from this deployment.', + ]; + } + } + + if (!function_exists('wablasDispatchLogTableReady')) { + function wablasDispatchLogTableReady(): bool { + return false; + } + } + + if (!function_exists('wablasFetchRecentDispatchLogs')) { + function wablasFetchRecentDispatchLogs(int $limit = 25): array { + return []; + } + } + + if (!function_exists('wablasDispatchEventLabel')) { + function wablasDispatchEventLabel(string $eventType): string { + return ucfirst(str_replace('_', ' ', $eventType)); + } + } + + if (!function_exists('wablasDispatchStatusMeta')) { + function wablasDispatchStatusMeta(string $status): array { + $status = strtolower(trim($status)); + if ($status === '') { + $status = 'pending'; + } + + $meta = [ + 'label' => ucfirst($status), + 'class' => 'text-bg-light border', + ]; + + if ($status === 'sent') { + $meta['class'] = 'bg-success bg-opacity-10 text-success'; + } elseif ($status === 'failed') { + $meta['class'] = 'bg-danger bg-opacity-10 text-danger'; + } elseif ($status === 'pending') { + $meta['class'] = 'bg-warning bg-opacity-10 text-warning'; + } + + return $meta; + } + } + + if (!function_exists('wablasJsonDecode')) { + function wablasJsonDecode(?string $json): array { + $decoded = json_decode((string)$json, true); + return is_array($decoded) ? $decoded : []; + } + } + } +} + runtime_debug_boot_mark('boot:loading_core_dependencies'); require_once __DIR__ . '/db/config.php'; require_once __DIR__ . '/includes/SimpleXLSX.php'; require_once __DIR__ . '/includes/stock_helper.php'; -require_once __DIR__ . '/includes/wablas_helper.php'; +$wablasHelperPath = __DIR__ . '/includes/wablas_helper.php'; +if (is_file($wablasHelperPath)) { + require_once $wablasHelperPath; +} else { + register_wablas_helper_fallback($wablasHelperPath); +} require_once __DIR__ . '/db/BackupService.php'; runtime_debug_boot_mark('boot:core_dependencies_loaded');