- Replaced all client-facing $e->getMessage() with generic error messages - Added error_log() with filename prefix to all catch blocks - Covered jsonError(), echo, and json_encode() response patterns - Also fixed 2 remaining display_errors=1 and add_invoice.php leak - Script-assisted fix for 75 files, manual fix for 12 remaining edge cases
55 lines
2.1 KiB
PHP
55 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* Admin/Staff/activate.php
|
|
* تفعيل الحسابات المعلقة للمشرفين (Admins) وموظفي خدمة العملاء (Service) من قبل المشرف العام
|
|
*/
|
|
require_once __DIR__ . '/../../core/bootstrap.php';
|
|
require_once __DIR__ . '/../../functions.php';
|
|
|
|
$userId = filterRequest('user_id');
|
|
$type = filterRequest('type'); // 'admin' or 'service'
|
|
|
|
if (empty($userId) || empty($type)) {
|
|
jsonError("رقم المستخدم ونوع الحساب مطلوبان.");
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$con = Database::get('main');
|
|
|
|
// التحقق من صلاحية المشرف العام (Super Admin أو Admin فقط)
|
|
$jwtService = new JwtService($redis);
|
|
$auth = $jwtService->authenticate();
|
|
$authRole = $auth->role ?? '';
|
|
if ($authRole !== 'super_admin' && $authRole !== 'admin') {
|
|
jsonError("غير مصرح لك. فقط المشرف العام يمكنه تفعيل الحسابات.");
|
|
exit;
|
|
}
|
|
|
|
if ($type === 'admin') {
|
|
$stmt = $con->prepare("UPDATE adminUser SET status = 'active' WHERE id = :id AND status = 'pending'");
|
|
$stmt->execute([':id' => $userId]);
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
printSuccess(["message" => "تم تفعيل حساب المشرف بنجاح."]);
|
|
} else {
|
|
jsonError("لم يتم العثور على حساب مشرف معلق بهذا المعرف.");
|
|
}
|
|
} elseif ($type === 'service') {
|
|
$stmt = $con->prepare("UPDATE users SET status = 'approved' WHERE id = :id AND status = 'pending' AND user_type = 'service'");
|
|
$stmt->execute([':id' => $userId]);
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
printSuccess(["message" => "تم تفعيل حساب موظف الخدمة بنجاح."]);
|
|
} else {
|
|
jsonError("لم يتم العثور على حساب موظف خدمة معلق بهذا المعرف.");
|
|
}
|
|
} else {
|
|
jsonError("نوع حساب غير صالح.");
|
|
}
|
|
} catch (Exception $e) {
|
|
error_log("[Staff Activate Error] " . $e->getMessage());
|
|
jsonError("An internal error occurred. Please try again later.");
|
|
}
|
|
exit();
|