Files
Siro/backend/serviceapp/getdriverstotalMonthly.php
T
Hamza-AyedandClaude Opus 5 2135edcf43 Close the remaining ciphertext joins and a SQL injection in email verification
- Customer-service notes joined to the account by comparing encrypted phone
  columns. Both notes tables now carry phone_key, written when a note is
  saved, and the three joins match on it.
- The email_verifications join was comparing a plaintext column against an
  encrypted one, so it never matched and `verified` was always NULL in both
  passenger and driver sign-in. It is now resolved in PHP against the
  decrypted address, which fixes a pre-existing bug rather than only
  preparing for GCM.
- auth/sendVerifyEmail.php built all three of its statements by interpolating
  the request values into SQL. Any caller could inject through the email or
  token field. Now parameterised.
- serviceapp/register.php duplicate detection consults the users indexes and
  writes them with the row.

Sweep confirms no join or lookup compares two encrypted columns any more.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-25 16:48:10 +03:00

103 lines
2.8 KiB
PHP

<?php
require_once __DIR__ . '/../connect.php';
// منع الأخطاء النصية وضبط الترويسة
error_reporting(0);
header('Content-Type: application/json');
// 1. استقبال التواريخ
if (isset($_POST['start_date']) && isset($_POST['end_date'])) {
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
} else {
// Fallback
$current_month = isset($_POST['month']) ? str_pad($_POST['month'], 2, "0", STR_PAD_LEFT) : date('m');
$current_year = isset($_POST['year']) ? $_POST['year'] : date('Y');
$start_date = date('Y-m-d', strtotime("$current_year-$current_month-01"));
$end_date = date('Y-m-t', strtotime($start_date));
}
$end_date_full = $end_date . ' 23:59:59';
$sql = "
WITH RECURSIVE date_series AS (
SELECT :start_date AS DATE
UNION ALL
SELECT DATE_ADD(DATE, INTERVAL 1 DAY)
FROM date_series
WHERE DATE < :end_date
)
SELECT
date_series.date AS day,
(SELECT COUNT(*) FROM driver) AS totalDrivers,
(
SELECT COUNT(*)
FROM driver
WHERE DATE(driver.created_at) = date_series.date
) AS dailyTotalDrivers,
(
SELECT COUNT(*)
FROM notesForDriverService
WHERE DATE(notesForDriverService.createdAt) = date_series.date
) AS dailyTotalCallingDrivers,
(
SELECT COUNT(*)
FROM notesForDriverService n
JOIN driver d ON n.phone_key = d.phone_key
WHERE DATE(n.createdAt) = date_series.date
) AS dailyMatchingNotes,
(
SELECT COUNT(*)
FROM driver
WHERE driver.created_at BETWEEN :start_date1 AND :end_date1
) AS totalMonthlyDrivers,
(
SELECT COUNT(*)
FROM notesForDriverService
WHERE notesForDriverService.createdAt BETWEEN :start_date2 AND :end_date2
) AS totalMonthlyCallingDrivers,
(
SELECT COUNT(*)
FROM notesForDriverService n
JOIN driver d ON n.phone_key = d.phone_key
WHERE n.createdAt BETWEEN :start_date3 AND :end_date3
) AS totalMonthlyMatchingNotes
FROM
date_series
GROUP BY
date_series.date
ORDER BY
date_series.date ASC";
try {
$stmt = $con->prepare($sql);
$stmt->execute([
':start_date' => $start_date,
':end_date' => $end_date,
':start_date1' => $start_date,
':end_date1' => $end_date_full,
':start_date2' => $start_date,
':end_date2' => $end_date_full,
':start_date3' => $start_date,
':end_date3' => $end_date_full
]);
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($data) {
echo json_encode(array("status" => "success", "message" => $data));
} else {
echo json_encode(array("status" => "success", "message" => []));
}
} catch (PDOException $e) {
echo json_encode(array("status" => "failure", "message" => "An internal error occurred"));
}
?>