Hotfix: a comment added to the dashboard SQL contained double quotes inside
the double-quoted PHP string, terminating it and making dashbord.php fail to
parse. Production was returning a parse error for every dashboard request.
Authorisation gaps closed — connect.php only proves a token is valid, it does
not check what the caller is allowed to do:
- Admin/ggg.php decrypts any database field and was authorised solely by an
admin phone number sent in the request body. Anyone who knew a listed
number could decrypt platform data without signing in. It now runs behind
connect.php, requires super_admin, keeps the phone list as a second factor,
and records every use.
- ride/kazan/update.php, kazan/add.php and ride/promo/{add,update,delete}.php
changed live pricing and discount codes with no role check at all, so any
valid token — including a driver's or passenger's — could rewrite the fare
table. All now require super_admin.
Staff/pending.php: adminUser has no `status` column in this deployment, so
the query failed with an opaque "unavailable". It now checks for the column
and reports the actual reason.
Console: Kazan tariff editor for super admins — sends only changed fields,
shows an old → new confirmation before saving, and stays read-only with an
explanatory notice for plain admins.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
84 lines
3.2 KiB
PHP
84 lines
3.2 KiB
PHP
<?php
|
|
/**
|
|
* Admin/Staff/pending.php
|
|
* جلب الحسابات المعلقة للإداريين والخدمة
|
|
*/
|
|
// connect.php يفرض JWT — بدونه كانت هذه النقطة تكشف أسماء وأرقام
|
|
// المشرفين المعلقين لأي زائر بلا أي مصادقة.
|
|
require_once __DIR__ . '/../../connect.php';
|
|
|
|
if ($role !== 'admin' && $role !== 'super_admin') {
|
|
http_response_code(403);
|
|
echo json_encode(['error' => 'Unauthorized: Admin access required']);
|
|
exit;
|
|
}
|
|
|
|
$allPending = [];
|
|
$sources = [];
|
|
|
|
// كل مصدر يُجلب على حدة: غياب جدول users في بعض عمليات النشر كان يُفشل
|
|
// الطلب بالكامل ويخفي طلبات المشرفين المعلقة أيضاً.
|
|
/**
|
|
* بعض عمليات النشر أنشأت adminUser بلا عمود status (انظر schema_primary.sql)،
|
|
* وعندها لا يمكن تمييز الحسابات المعلقة أصلاً. نفحص العمود أولاً لنُرجع سبباً
|
|
* واضحاً بدل فشل عام.
|
|
*/
|
|
function columnExists(PDO $con, string $table, string $column): bool
|
|
{
|
|
try {
|
|
$stmt = $con->prepare("SELECT COUNT(*) FROM information_schema.COLUMNS
|
|
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?");
|
|
$stmt->execute([$table, $column]);
|
|
return (int) $stmt->fetchColumn() > 0;
|
|
} catch (Throwable $e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
try {
|
|
if (!columnExists($con, 'adminUser', 'status')) {
|
|
throw new RuntimeException("adminUser.status column is missing — admin approvals cannot be tracked until it is added.");
|
|
}
|
|
|
|
$stmt1 = $con->query("SELECT id, name, phone, role, created_at, 'admin' as type FROM adminUser WHERE status = 'pending'");
|
|
$admins = $stmt1->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
foreach ($admins as &$admin) {
|
|
$admin['name'] = $encryptionHelper->decryptData($admin['name']) ?: $admin['name'];
|
|
$admin['phone'] = $encryptionHelper->decryptData($admin['phone']) ?: $admin['phone'];
|
|
}
|
|
unset($admin);
|
|
|
|
$allPending = array_merge($allPending, $admins);
|
|
$sources['admins'] = 'ok';
|
|
} catch (Throwable $e) {
|
|
error_log("[Staff Pending] adminUser query failed: " . $e->getMessage());
|
|
$sources['admins'] = 'unavailable: ' . $e->getMessage();
|
|
}
|
|
|
|
try {
|
|
$stmt2 = $con->query("SELECT id, first_name, last_name, phone, user_type as role, created_at, 'service' as type FROM users WHERE status = 'pending' AND user_type = 'service'");
|
|
$services = $stmt2->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
foreach ($services as &$service) {
|
|
$service['name'] = trim(
|
|
($encryptionHelper->decryptData($service['first_name']) ?: $service['first_name']) . ' ' .
|
|
($encryptionHelper->decryptData($service['last_name']) ?: $service['last_name'])
|
|
);
|
|
$service['phone'] = $encryptionHelper->decryptData($service['phone']) ?: $service['phone'];
|
|
}
|
|
unset($service);
|
|
|
|
$allPending = array_merge($allPending, $services);
|
|
$sources['service_staff'] = 'ok';
|
|
} catch (Throwable $e) {
|
|
error_log("[Staff Pending] users query failed: " . $e->getMessage());
|
|
$sources['service_staff'] = 'unavailable';
|
|
}
|
|
|
|
printSuccess([
|
|
"data" => $allPending,
|
|
"sources" => $sources,
|
|
]);
|
|
exit();
|