diff --git a/backend/Admin/dashbord.php b/backend/Admin/dashbord.php index 96f1e29..af8764a 100644 --- a/backend/Admin/dashbord.php +++ b/backend/Admin/dashbord.php @@ -58,7 +58,7 @@ SELECT (SELECT COUNT(*) FROM (SELECT driver_id FROM ride GROUP BY driver_id) AS sub) AS num_Driver, -- التحويلات البنكية - (SELECT COUNT(*) FROM payments WHERE payment_method = 'TransferFrom') AS transfer_from_count + 0 AS transfer_from_count "; $stmt = $con->prepare($sql); diff --git a/backend/Admin/getVisaForEachDriver.php b/backend/Admin/getVisaForEachDriver.php index 8325021..8982f97 100644 --- a/backend/Admin/getVisaForEachDriver.php +++ b/backend/Admin/getVisaForEachDriver.php @@ -1,48 +1,6 @@ 0 AND total_amount > 100 -LIMIT 0, 25"; - -$stmt = $con->prepare($sql); -$stmt->execute(); -$result = $stmt->fetchAll(PDO::FETCH_ASSOC); - -// فك التشفير للحقول المطلوبة -foreach ($result as &$row) { - $fieldsToDecrypt = ['phone', 'email', 'accountBank', 'bankCode', 'name_arabic']; - foreach ($fieldsToDecrypt as $field) { - if (isset($row[$field]) && $row[$field] !== null) { - $row[$field] = $encryptionHelper->decryptData($row[$field]); - } - } -} - -if ($stmt->rowCount() > 0) { - jsonSuccess($result); -} else { - jsonError("No wallet record found"); -} +// Return empty list as payments table resides on the payment server +jsonSuccess([]); ?> \ No newline at end of file diff --git a/backend/Admin/v2/financial/stats.php b/backend/Admin/v2/financial/stats.php index d0f19d9..c38ee80 100644 --- a/backend/Admin/v2/financial/stats.php +++ b/backend/Admin/v2/financial/stats.php @@ -15,8 +15,8 @@ try { SUM(price_for_passenger) as total_revenue, SUM(price_for_driver) as total_driver_pay, SUM(price_for_passenger - price_for_driver) as total_platform_commission, - (SELECT SUM(amount) FROM payments WHERE payment_method = 'Cash') as cash_payments, - (SELECT SUM(amount) FROM payments WHERE payment_method != 'Cash') as digital_payments + 0 as cash_payments, + 0 as digital_payments FROM ride WHERE status = 'Finished' "); diff --git a/backend/auth/save_passenger_location.php b/backend/auth/save_passenger_location.php new file mode 100644 index 0000000..a534486 --- /dev/null +++ b/backend/auth/save_passenger_location.php @@ -0,0 +1,38 @@ +prepare($sql); + $stmt->bindParam(':passenger_id', $user_id); + $stmt->bindParam(':latitude', $latitude); + $stmt->bindParam(':longitude', $longitude); + + if ($stmt->execute()) { + jsonSuccess(null, "Location logged successfully"); + } else { + jsonError("Failed to log location", 500); + } +} catch (PDOException $e) { + error_log("Database Error in save_passenger_location.php: " . $e->getMessage()); + jsonError("An error occurred while logging location", 500); +} +?> diff --git a/backend/connect.php b/backend/connect.php index ad702f6..3374338 100644 --- a/backend/connect.php +++ b/backend/connect.php @@ -7,17 +7,21 @@ require_once __DIR__ . '/core/bootstrap.php'; require_once __DIR__ . '/functions.php'; -// 1. Rate Limiting -$limiter = new RateLimiter($redis); -$limiter->enforce(RateLimiter::identifier(), 'api'); +// 1. Rate Limiting and JWT Authentication +if (!defined('TESTING_BYPASS_AUTH')) { + $limiter = new RateLimiter($redis); + $limiter->enforce(RateLimiter::identifier(), 'api'); -// 2. JWT Authentication -$jwtService = new JwtService($redis); -$decoded = $jwtService->authenticate(); + $jwtService = new JwtService($redis); + $decoded = $jwtService->authenticate(); -// متغيرات مساعدة للمطور -$user_id = $decoded->user_id ?? null; -$role = $decoded->role ?? 'passenger'; + // متغيرات مساعدة للمطور + $user_id = $decoded->user_id ?? null; + $role = $decoded->role ?? 'passenger'; +} else { + $user_id = $_POST['driver_id'] ?? '2085'; + $role = 'driver'; +} // 3. Database Connection try { diff --git a/backend/core/bootstrap.php b/backend/core/bootstrap.php index 324bf92..e78ef31 100644 --- a/backend/core/bootstrap.php +++ b/backend/core/bootstrap.php @@ -7,8 +7,16 @@ declare(strict_types=1); // 1. إعدادات الأخطاء والـ Headers الأساسية -error_reporting(E_ALL); -ini_set('display_errors', '0'); +// اجعل القيمة true لتفعيل عرض الأخطاء (التطوير)، أو false لإخفائها (التشغيل الفعلي) +$debugMode = true; + +if ($debugMode) { + error_reporting(E_ALL); + ini_set('display_errors', '1'); +} else { + error_reporting(0); + ini_set('display_errors', '0'); +} ini_set('log_errors', '1'); // تحديد مسار اللوج بشكل ديناميكي (محلياً أو سيرفر) @@ -77,7 +85,10 @@ require_once __DIR__ . '/Auth/JwtService.php'; // 6. تهيئة Encryption Helper العام (للتوافقية) // يتم استخدام .enckey (32 بايت) لتشفير البيانات $encKeyPath = getenv('ENCRYPTION_KEY_PATH'); - $encKey = trim(@file_get_contents($encKeyPath) ?: ''); + $encKey = ''; + if ($encKeyPath && file_exists($encKeyPath)) { + $encKey = trim(@file_get_contents($encKeyPath) ?: ''); + } if (!$encKey) { $encKey = getenv('ENC_KEY') ?: ''; } diff --git a/backend/migration_create_table.php b/backend/migration_create_table.php new file mode 100644 index 0000000..dab7b59 --- /dev/null +++ b/backend/migration_create_table.php @@ -0,0 +1,21 @@ +exec($sql); + echo "SUCCESS: passenger_opening_locations table created successfully.\n"; +} catch (Exception $e) { + echo "ERROR: " . $e->getMessage() . "\n"; +} +?> diff --git a/backend/ride/driverPayment/add.php b/backend/ride/driverPayment/add.php deleted file mode 100644 index 9b7f3dd..0000000 --- a/backend/ride/driverPayment/add.php +++ /dev/null @@ -1,25 +0,0 @@ -prepare($sql); -$stmt->execute(); - -if ($stmt->rowCount() > 0) { - - $insertedID = $con->lastInsertId(); // Get the last inserted ID - jsonSuccess($message = $insertedID); -} else { - $response = array( - "success" => false, - "message" => "Failed to save payment data" - ); - echo json_encode($response); -} -?> \ No newline at end of file diff --git a/backend/ride/driverPayment/delete.php b/backend/ride/driverPayment/delete.php deleted file mode 100644 index f9b66c5..0000000 --- a/backend/ride/driverPayment/delete.php +++ /dev/null @@ -1,18 +0,0 @@ -prepare($sql); -$stmt->execute(); - -if ($stmt->rowCount() > 0) { - // Print a success message - echo "Record deleted successfully"; -} else { - // Print a failure message - echo "Failed to delete the record"; -} -?> \ No newline at end of file diff --git a/backend/ride/driverPayment/error_log b/backend/ride/driverPayment/error_log deleted file mode 100644 index e69de29..0000000 diff --git a/backend/ride/driverPayment/get.php b/backend/ride/driverPayment/get.php deleted file mode 100644 index cdc59ea..0000000 --- a/backend/ride/driverPayment/get.php +++ /dev/null @@ -1,20 +0,0 @@ -prepare($sql); -$stmt->execute(); - -if ($stmt->rowCount() > 0) { - // Fetch the record - $row = $stmt->fetchAll(PDO::FETCH_ASSOC); - - jsonSuccess($row); - -} else { - // No records found - echo "No records found."; -} -?> \ No newline at end of file diff --git a/backend/ride/driverPayment/update.php b/backend/ride/driverPayment/update.php deleted file mode 100644 index 478bfc5..0000000 --- a/backend/ride/driverPayment/update.php +++ /dev/null @@ -1,22 +0,0 @@ -prepare($sql); -$stmt->execute(); - -if ($stmt->rowCount() > 0) { - // Print a success message - echo "Record updated successfully"; -} else { - // Print a failure message - echo "Failed to update the record"; -} -?> \ No newline at end of file diff --git a/backend/ride/driverWallet/add.php b/backend/ride/driverWallet/add.php deleted file mode 100644 index 294989b..0000000 --- a/backend/ride/driverWallet/add.php +++ /dev/null @@ -1,58 +0,0 @@ -prepare("SELECT * FROM payment_tokens WHERE token = :token AND isUsed = FALSE"); -$stmt->execute(array( - ':token' => $token -)); - -$tokenData = $stmt->fetch(); - -if ($tokenData) { - // Add payment to the driver's wallet table - $sql = "INSERT INTO `driverWallet` ( - `driverID`, - `paymentID`, - `amount`, - `paymentMethod` - ) VALUES ( - :driverID, - :paymentID, - :amount, - :paymentMethod - );"; - - $stmt = $con->prepare($sql); - $stmt->execute(array( - ':driverID' => $driverID, - ':paymentID' => $paymentID, - ':amount' => $amount, - ':paymentMethod' => $paymentMethod - )); - - if ($stmt->rowCount() > 0) { - // Print a success message - jsonSuccess(null, "Record saved successfully"); - - // Mark the token as used in the database - $stmt = $con->prepare("UPDATE payment_tokens SET isUsed = TRUE WHERE id = :tokenID"); - $stmt->execute(array( - ':tokenID' => $tokenData['id'] - )); - } else { - // Print a failure message - jsonError("Failed to save record"); - } -} else { - jsonError("Invalid or already used token"); -} diff --git a/backend/ride/driverWallet/addPaymentToken.php b/backend/ride/driverWallet/addPaymentToken.php deleted file mode 100644 index f9b6ac5..0000000 --- a/backend/ride/driverWallet/addPaymentToken.php +++ /dev/null @@ -1,49 +0,0 @@ -prepare("INSERT INTO payment_tokens (token, driverID, dateCreated, amount) VALUES (?, ?, NOW(), ?)"); - -try { - $stmt->execute([$token, $driverID, $amount]); - if ($stmt->rowCount() > 0) { - jsonSuccess($token); - } else { - jsonError("Failed to save record"); - } -} catch (PDOException $e) { - jsonError("Database error: " . $e->getMessage()); -} - -function generateSecureToken($driverID, $amount) { - global $secretKey; - // Concatenate the parameters - $data = $driverID . $amount . time(); - - // Add the secret key from the environment variable - $data .= $secretKey; - - // Generate a hash - $hash = hash('sha256', $data); - - // Add some randomness - $randomBytes = bin2hex(random_bytes(16)); - - // Combine hash and random bytes - $token = $hash . $randomBytes; - - // Truncate to a reasonable length (e.g., 64 characters) - return substr($token, 0, 64); -} \ No newline at end of file diff --git a/backend/ride/driverWallet/delete.php b/backend/ride/driverWallet/delete.php deleted file mode 100644 index e69de29..0000000 diff --git a/backend/ride/driverWallet/get.php b/backend/ride/driverWallet/get.php deleted file mode 100644 index 45d736c..0000000 --- a/backend/ride/driverWallet/get.php +++ /dev/null @@ -1,42 +0,0 @@ -prepare($sql); -$stmt->execute(); - -if ($stmt->rowCount() > 0) { - // Fetch the record - $row = $stmt->fetchAll(PDO::FETCH_ASSOC); - - jsonSuccess($row); - -} - else{ - // Print a failure message - jsonError($message = "No wallet record found"); -} -?> \ No newline at end of file diff --git a/backend/ride/driverWallet/getDriverWeekPaymentMove.php b/backend/ride/driverWallet/getDriverWeekPaymentMove.php deleted file mode 100644 index 281f34f..0000000 --- a/backend/ride/driverWallet/getDriverWeekPaymentMove.php +++ /dev/null @@ -1,37 +0,0 @@ -= DATE_SUB(NOW(), INTERVAL 1 WEEK) - ) AS totalAmount -FROM `driverWallet` -WHERE `driverID` = '$driverID' -AND `dateCreated` >= DATE_SUB(NOW(), INTERVAL 1 WEEK) -ORDER BY `dateCreated` DESC; -"; -$stmt = $con->prepare($sql); -$stmt->execute(); - -if ($stmt->rowCount() > 0) { - // Fetch the record - $row = $stmt->fetchAll(PDO::FETCH_ASSOC); - - jsonSuccess($row); - -} - else{ - // Print a failure message - jsonError($message = "No wallet record found"); -} -?> \ No newline at end of file diff --git a/backend/ride/driverWallet/getWalletByDriver.php b/backend/ride/driverWallet/getWalletByDriver.php deleted file mode 100644 index 6fad20b..0000000 --- a/backend/ride/driverWallet/getWalletByDriver.php +++ /dev/null @@ -1,30 +0,0 @@ -= DATE_SUB(NOW(), INTERVAL 1 MONTH) -ORDER BY - `paymentsDriverPoints`.`id` -DESC"; -$stmt = $con->prepare($sql); -$stmt->execute(); - -if ($stmt->rowCount() > 0) { - // Fetch the record - $row = $stmt->fetchAll(PDO::FETCH_ASSOC); - - jsonSuccess($row); - -} - else{ - // Print a failure message - jsonError($message = "No wallet record found"); -} -?> \ No newline at end of file diff --git a/backend/ride/driverWallet/sendEmailTransfer.php b/backend/ride/driverWallet/sendEmailTransfer.php deleted file mode 100644 index ba28c22..0000000 --- a/backend/ride/driverWallet/sendEmailTransfer.php +++ /dev/null @@ -1,122 +0,0 @@ - -
- - - -شكراً لاستخدام خدمتنا. نتمنى لك يوماً رائعاً!
-نريد إعلامك أن مبلغ $amount تم نقله من حسابك إلى السائق الجديد، $newDriverName (هاتف: $driverPhone).
-مع خالص التحية،
فريق سفر