33 lines
1.2 KiB
PHP
33 lines
1.2 KiB
PHP
<?php
|
|
// transit/broadcast/send.php — المشرف يرسل إعلاناً للطلاب عبر FCM
|
|
|
|
require_once __DIR__ . '/../../transit/connect_admin.php';
|
|
|
|
requireTransitFields(['body_ar']);
|
|
|
|
$bodyAr = filterRequest('body_ar');
|
|
$titleAr = filterRequest('title_ar') ?: 'إعلان من الجامعة';
|
|
$targetType = filterRequest('target_type') ?: 'all';
|
|
$targetId = filterRequest('target_id', 'int') ?: null;
|
|
|
|
if (!in_array($targetType, ['all', 'route'])) $targetType = 'all';
|
|
|
|
$fcmTopic = ($targetType === 'route' && $targetId)
|
|
? transitRouteTopic($targetId)
|
|
: transitOrgTopic($transit_org_id);
|
|
|
|
$transit_con->prepare(
|
|
"INSERT INTO transit_broadcasts
|
|
(org_id, sent_by, target_type, target_id, title_ar, body_ar, fcm_topic, sent_at)
|
|
VALUES (?,?,?,?,?,?,?,NOW())"
|
|
)->execute([$transit_org_id, $transit_admin_id, $targetType, $targetId, $titleAr, $bodyAr, $fcmTopic]);
|
|
|
|
$broadcastId = (int)$transit_con->lastInsertId();
|
|
|
|
transitSendTopicNotification(
|
|
$fcmTopic, $titleAr, $bodyAr,
|
|
['type' => 'transit_broadcast', 'broadcast_id' => (string)$broadcastId]
|
|
);
|
|
|
|
jsonSuccess(['broadcast_id' => $broadcastId, 'fcm_topic' => $fcmTopic], 'Broadcast sent');
|