نسخة كاملة من مستودع سيرو عند ecfe7568 لتكون أساس تطبيق «انطلق». نُسخ المتعقَّب في git فقط (12,509 ملفاً / 302 م.ب) بـ git archive، لا `cp -r` — فاستُثنيت تلقائياً مخلفات البناء (build · node_modules · .dart_tool · .gradle · Pods ≈ 10.7 غ.ب) وكل ما يستثنيه .gitignore. هذا الكوميت **بلا أي تعديل عمداً** حتى يكون كل ما يليه فرقاً مقروءاً مقابل سيرو الأصلي. سيرو نفسه لم يُمسّ. ⚠️ لا يبني بعد: `.env` و`lib/env/env.g.dart` غير متعقَّبين في سيرو (وهذا صحيح — أسرار لكل مستأجر). كل تطبيق فلاتر هنا يحتاج .env خاصاً بانطلق ثم توليد env.g.dart عبر build_runner. لا تُنسخ أسرار سيرو. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
76 lines
3.1 KiB
PHP
76 lines
3.1 KiB
PHP
<?php
|
|
// Admin/transit/org/update.php — تعديل بيانات مؤسسة + إدارة حالة العقد
|
|
// POST: org_id, [contract_status], [city], [contact_email], [website], [trial_ends_at]
|
|
//
|
|
// عند التعليق (suspended) أو الإنهاء (terminated):
|
|
// يُبطل جميع جلسات مشرفي المؤسسة فوراً (Redis + MySQL)
|
|
|
|
require_once __DIR__ . '/../../../connect.php';
|
|
|
|
if ($role !== 'admin' && $role !== 'super_admin') {
|
|
jsonError('Unauthorized: Admin access required', 403);
|
|
}
|
|
|
|
try { $transit_con = Database::get('transit'); }
|
|
catch (Exception $e) { jsonError('Transit service unavailable', 503); }
|
|
|
|
require_once __DIR__ . '/../../../transit/functions.php';
|
|
|
|
$orgId = filterRequest('org_id', 'int');
|
|
if (!$orgId) jsonError('org_id is required', 400);
|
|
|
|
$st = $transit_con->prepare("SELECT id, contract_status FROM transit_orgs WHERE id=? LIMIT 1");
|
|
$st->execute([$orgId]);
|
|
$org = $st->fetch();
|
|
if (!$org) jsonError('Organization not found', 404);
|
|
|
|
$updates = [];
|
|
$params = [];
|
|
|
|
// حقول يمكن تحديثها
|
|
if (($v = filterRequest('city')) !== null) { $updates[] = 'city=?'; $params[] = $v; }
|
|
if (($v = filterRequest('contact_email')) !== null) { $updates[] = 'contact_email=?'; $params[] = $v; }
|
|
if (($v = filterRequest('website')) !== null) { $updates[] = 'website=?'; $params[] = $v; }
|
|
if (($v = filterRequest('trial_ends_at')) !== null) { $updates[] = 'trial_ends_at=?'; $params[] = $v; }
|
|
|
|
$newStatus = null;
|
|
if (($v = filterRequest('contract_status')) !== null) {
|
|
$allowed = ['active', 'trial', 'suspended', 'terminated'];
|
|
if (!in_array($v, $allowed)) {
|
|
jsonError('Invalid contract_status. Allowed: ' . implode(', ', $allowed), 400);
|
|
}
|
|
$newStatus = $v;
|
|
$updates[] = 'contract_status=?';
|
|
$params[] = $v;
|
|
}
|
|
|
|
if (empty($updates)) jsonError('No fields to update', 400);
|
|
|
|
$updates[] = 'updated_at=NOW()';
|
|
$params[] = $orgId;
|
|
|
|
$transit_con->prepare(
|
|
"UPDATE transit_orgs SET " . implode(', ', $updates) . " WHERE id=?"
|
|
)->execute($params);
|
|
|
|
// إبطال جلسات المشرفين عند التعليق أو الإنهاء
|
|
if ($newStatus && in_array($newStatus, ['suspended', 'terminated'])) {
|
|
$admins = $transit_con->prepare("SELECT id FROM transit_org_admins WHERE org_id=?");
|
|
$admins->execute([$orgId]);
|
|
|
|
foreach ($admins->fetchAll(PDO::FETCH_COLUMN) as $adminId) {
|
|
$sessions = $transit_con->prepare("SELECT token_hash FROM transit_sessions WHERE admin_id=?");
|
|
$sessions->execute([$adminId]);
|
|
foreach ($sessions->fetchAll(PDO::FETCH_COLUMN) as $hash) {
|
|
if ($redis) $redis->del("transit:session:{$hash}");
|
|
}
|
|
$transit_con->prepare("DELETE FROM transit_sessions WHERE admin_id=?")->execute([$adminId]);
|
|
}
|
|
|
|
appLog("[ADMIN][TRANSIT][ORG][update] org={$orgId} contract_status={$newStatus} — all admin sessions invalidated");
|
|
} else {
|
|
appLog("[ADMIN][TRANSIT][ORG][update] org={$orgId} updated=" . implode(',', $updates));
|
|
}
|
|
|
|
jsonSuccess(['org_id' => $orgId, 'contract_status' => $newStatus ?? $org['contract_status']]);
|