Files
musadaq-saas/public/index.php
2026-05-15 21:55:17 +03:00

154 lines
6.8 KiB
PHP

<?php
/**
* Simple Router & Entry Point
*/
// 1. Load Bootstrap
require_once __DIR__ . '/../app/bootstrap/init.php';
// Public Verification Bypass (Top Priority)
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$route = $_GET['route'] ?? str_replace('/api/', '', $uri);
$route = trim($route, '/');
if ($route === 'verify' || $route === 'v.php' || $route === 'v1/verify') {
$id = $_GET['id'] ?? null;
require_once APP_PATH . '/modules_app/invoices/verify_public.php';
exit;
}
// Route map: route => [allowed_method, module_file]
$routes = [
'v.php' => ['GET', '../public/v.php'],
'verify' => ['GET', 'invoices/verify_public.php'],
'v1/auth/login' => ['POST', 'auth/login.php'],
'v1/auth/refresh' => ['POST', 'auth/refresh.php'],
'v1/auth/logout' => ['POST', 'auth/logout.php'],
'v1/users' => ['GET', 'users/index.php'],
'v1/users/create' => ['POST', 'users/create.php'],
'v1/users/update' => ['POST', 'users/update.php'],
'v1/users/delete' => ['POST', 'users/delete.php'],
'v1/companies' => ['GET', 'companies/index.php'],
'v1/companies/create' => ['POST', 'companies/create.php'],
'v1/companies/update' => ['POST', 'companies/update.php'],
'v1/companies/delete' => ['POST', 'companies/delete.php'],
'v1/invoices' => ['GET', 'invoices/index.php'],
'v1/invoices/view' => ['GET', 'invoices/view.php'],
'v1/verify' => ['GET', 'invoices/verify_public.php'],
'v1/invoices/file' => ['GET', 'invoices/file.php'],
'v1/invoices/approve' => ['POST', 'invoices/approve.php'],
'v1/invoices/upload' => ['POST', 'invoices/upload.php'],
'v1/invoices/download_xml' => ['GET', 'invoices/download_xml.php'],
'v1/invoices/submit-jofotara' => ['POST', 'invoices/submit_jofotara.php'],
'v1/invoices/update' => ['POST', 'invoices/update.php'],
'v1/invoices/reject' => ['POST', 'invoices/reject.php'],
'v1/invoices/delete' => ['POST', 'invoices/delete.php'],
'v1/invoices/bulk-approve' => ['POST', 'invoices/bulk_approve.php'],
'v1/invoices/export' => ['GET', 'invoices/export.php'],
'v1/invoices/export-excel' => ['GET', 'invoices/export_excel.php'],
'v1/invoices/check-duplicate' => ['POST', 'invoices/check_duplicate.php'],
'v1/reports/tax-summary' => ['GET', 'reports/tax_summary.php'],
'v1/audit-log' => ['GET', 'audit/index.php'],
'v1/notifications' => ['GET', 'notifications/index.php'],
'v1/notifications/read' => ['POST', 'notifications/read.php'],
'v1/referral/my-code' => ['GET', 'referral/my_code.php'],
'v1/companies/stats' => ['GET', 'companies/stats.php'],
'v1/companies/connect' => ['POST', 'companies/connect_jofotara.php'],
'v1/dashboard/stats' => ['GET', 'dashboard/stats.php'],
'v1/dashboard/recent-activity' => ['GET', 'dashboard/recent_activity.php'],
'v1/dashboard/ai-usage' => ['GET', 'dashboard/ai_usage.php'],
'v1/tenants' => ['GET', 'tenants/index.php'],
'v1/tenants/create' => ['POST', 'tenants/create.php'],
'v1/tenants/update' => ['POST', 'tenants/update.php'],
'v1/tenants/delete' => ['POST', 'tenants/delete.php'],
'v1/tenants/stats' => ['GET', 'tenants/stats.php'],
'v1/subscriptions/plans' => ['GET', 'subscriptions/plans.php'],
'v1/subscriptions/current' => ['GET', 'subscriptions/current.php'],
'v1/subscriptions/assign' => ['POST', 'subscriptions/assign.php'],
'v1/subscriptions/usage' => ['GET', 'subscriptions/usage.php'],
// Mobile Auth & Device Routes
'v1/auth/mobile/request-otp' => ['POST', 'auth/mobile_request_otp.php'],
'v1/auth/mobile/verify-otp' => ['POST', 'auth/mobile_verify_otp.php'],
'v1/auth/mobile/register-device' => ['POST', 'auth/register_device.php'],
// Batch Scanning Routes
'v1/batches/create' => ['POST', 'batches/create.php'],
'v1/batches/upload-image' => ['POST', 'batches/upload_image.php'],
'v1/batches/finalize' => ['POST', 'batches/finalize.php'],
'v1/batches/status' => ['GET', 'batches/status.php'],
// Payment System (CliQ-based)
'v1/payments/create' => ['POST', 'payments/create.php'],
'v1/payments/verify-reference' => ['POST', 'payments/verify_reference.php'],
'v1/payments/bot-webhook' => ['POST', 'payments/bot_webhook.php'],
'v1/payments/list' => ['GET', 'payments/list.php'],
'v1/payments/my-requests' => ['GET', 'payments/my_requests.php'],
'v1/payments/review' => ['POST', 'payments/review.php'],
'v1/payments/stats' => ['GET', 'payments/stats.php'],
'v1/payments/delete' => ['POST', 'payments/delete.php'],
// Voice Assistant Proxies
'v1/voice/transcribe' => ['POST', 'voice/transcribe.php'],
'v1/voice/parse-intent' => ['POST', 'voice/parse_intent.php'],
'v1/voice/parse-intent-grok' => ['POST', 'voice/grok_intent.php'],
// Referral System
'v1/referral/apply' => ['POST', 'referral/apply.php'],
// AI Reports
'v1/reports/company-health' => ['GET', 'reports/company_health.php'],
// Payment Upload
'v1/payments/upload-receipt' => ['POST', 'payments/upload_receipt.php'],
// WhatsApp Bot
'v1/whatsapp/webhook' => ['POST', 'whatsapp/webhook.php'],
'v1/whatsapp/link-code' => ['GET', 'whatsapp/link_code.php'],
// Gamification
'v1/gamification/profile' => ['GET', 'gamification/profile.php'],
// AI Chatbot
'v1/chatbot/ask' => ['POST', 'chatbot/ask.php'],
'v1/chatbot/history' => ['GET', 'chatbot/history.php'],
// Academy
'v1/academy/articles' => ['GET', 'academy/articles.php'],
// Excel Import (was missing!)
'v1/excel/import' => ['POST', 'excel/import.php'],
// SMS Bank Integration
'v1/sms/receive' => ['POST', 'sms/receive.php'],
// Marketplace
'v1/marketplace/listings' => ['GET', 'marketplace/listings.php'],
'v1/marketplace/my-listing' => ['POST', 'marketplace/my_listing.php'],
];
if (isset($routes[$route])) {
[$allowedMethod, $moduleFile] = $routes[$route];
// H1 Fix: Enforce HTTP Method
if ($_SERVER['REQUEST_METHOD'] !== $allowedMethod) {
header("Allow: {$allowedMethod}");
json_error("Method Not Allowed. Use {$allowedMethod}.", 405);
}
$file = APP_PATH . '/modules_app/' . $moduleFile;
if (file_exists($file)) {
require_once $file;
} else {
error_log("Router: Missing module file for route '{$route}': {$moduleFile}");
json_error('خدمة غير متوفرة حالياً', 500);
}
} else {
if (str_starts_with($route, 'v1/')) {
json_error('المسار المطلوب غير موجود', 404);
} else {
include __DIR__ . '/shell.php';
exit;
}
}