prepare('SELECT * FROM tbl_scwebhooks WHERE cl_scwebhook_id = :id LIMIT 1'); $stmt_webhook->execute(['id' => $cl_scnotification_webhook_id]); $webhook = $stmt_webhook->fetch(); if (!$webhook) { auth_flash_set('error', 'Webhook Discord introuvable.'); header('Location: scnotification.php'); exit; } $banner = null; if ($cl_scnotification_banner_id > 0) { $stmt_banner = $db->prepare('SELECT * FROM tbl_scbanners WHERE cl_scbanner_id = :id LIMIT 1'); $stmt_banner->execute(['id' => $cl_scnotification_banner_id]); $banner = $stmt_banner->fetch(); } if ($use_custom_banner && $cl_scnotification_custom_banner_url !== '' && !filter_var($cl_scnotification_custom_banner_url, FILTER_VALIDATE_URL)) { auth_flash_set('error', 'L’URL de bannière personnalisée est invalide.'); header('Location: scnotification.php'); exit; } foreach ([ 'URL canal Discord' => [$show_channel_url, $cl_scnotification_channel_url], 'URL inventaire' => [$show_inventory_url, $cl_scnotification_inventory_url], 'URL source' => [$show_source_url, $cl_scnotification_source_url], 'Icône du footer' => [$show_footer && $cl_scnotification_footer_icon_url !== '', $cl_scnotification_footer_icon_url], ] as $label => [$enabled, $value]) { if ($enabled && $value !== '' && !filter_var($value, FILTER_VALIDATE_URL)) { auth_flash_set('error', $label . ' invalide.'); header('Location: scnotification.php'); exit; } } $mentions = scdiscord_build_mentions($notify_here, $notify_everyone); $banner_image_url = $use_custom_banner && $cl_scnotification_custom_banner_url !== '' ? $cl_scnotification_custom_banner_url : (string) ($banner['cl_scbanner_url'] ?? ''); $border_color = (string) ($banner['cl_scbanner_border_color'] ?? '#ffae00'); $fields = []; if ($show_org && $cl_scnotification_org_value !== '' && mb_strtolower($cl_scnotification_org_value) !== 'non') { $fields[] = [ 'name' => 'Tenue d’organisation', 'value' => mb_substr($cl_scnotification_org_value, 0, 1024), 'inline' => true, ]; } if ($show_pvp && $cl_scnotification_pvp_value !== '' && mb_strtolower($cl_scnotification_pvp_value) !== 'inexistant') { $fields[] = [ 'name' => 'Risques PvP', 'value' => mb_substr($cl_scnotification_pvp_value, 0, 1024), 'inline' => true, ]; } if ($include_schedule) { if ($cl_scnotification_location !== '') { $fields[] = ['name' => 'Lieu de ralliement', 'value' => mb_substr($cl_scnotification_location, 0, 1024), 'inline' => false]; } if ($cl_scnotification_start_date !== '') { $fields[] = ['name' => 'Date de début', 'value' => mb_substr($cl_scnotification_start_date, 0, 1024), 'inline' => true]; } if ($cl_scnotification_departure_time !== '') { $fields[] = ['name' => 'Heure de départ', 'value' => mb_substr($cl_scnotification_departure_time, 0, 1024), 'inline' => true]; } if ($include_briefing_time && $cl_scnotification_briefing_time !== '') { $fields[] = ['name' => 'Heure de briefing', 'value' => mb_substr($cl_scnotification_briefing_time, 0, 1024), 'inline' => true]; } if ($include_end_date && $cl_scnotification_end_date !== '') { $fields[] = ['name' => 'Date de fin', 'value' => mb_substr($cl_scnotification_end_date, 0, 1024), 'inline' => true]; } if ($include_end_time && $cl_scnotification_end_time !== '') { $fields[] = ['name' => 'Heure de fin', 'value' => mb_substr($cl_scnotification_end_time, 0, 1024), 'inline' => true]; } } if ($show_channel_url && $cl_scnotification_channel_url !== '') { $fields[] = ['name' => 'Canal Discord', 'value' => '[Ouvrir le canal](' . $cl_scnotification_channel_url . ')', 'inline' => false]; } if ($show_inventory_url && $cl_scnotification_inventory_url !== '') { $fields[] = ['name' => 'Inventaire A.R.I.A', 'value' => '[Consulter l’inventaire](' . $cl_scnotification_inventory_url . ')', 'inline' => false]; } if ($show_source_url && $cl_scnotification_source_url !== '') { $fields[] = ['name' => 'Source', 'value' => '[Ouvrir la source](' . $cl_scnotification_source_url . ')', 'inline' => false]; } if ($show_reactions) { $fields[] = ['name' => 'Réactions', 'value' => '👍 / ⏳ / ❓ / 👎', 'inline' => false]; } $embed = [ 'description' => mb_substr($cl_scnotification_message, 0, 4096), 'color' => scdiscord_hex_to_decimal($border_color), ]; if ($cl_scnotification_title !== '') { $embed['title'] = mb_substr($cl_scnotification_title, 0, 256); } if (!empty($fields)) { $embed['fields'] = $fields; } if ($banner_image_url !== '') { $embed['image'] = ['url' => $banner_image_url]; } if ($show_footer && ($cl_scnotification_footer_text !== '' || $cl_scnotification_footer_icon_url !== '')) { $embed['footer'] = []; if ($cl_scnotification_footer_text !== '') { $embed['footer']['text'] = mb_substr($cl_scnotification_footer_text, 0, 2048); } if ($cl_scnotification_footer_icon_url !== '') { $embed['footer']['icon_url'] = $cl_scnotification_footer_icon_url; } } $payload = [ 'embeds' => [$embed], ]; if (!empty($mentions)) { $payload['content'] = implode(' ', $mentions); $payload['allowed_mentions'] = ['parse' => ['everyone']]; } $is_forum_webhook = ((int) ($webhook['cl_scwebhook_is_forum'] ?? 0) === 1); if ($is_forum_webhook) { $payload['thread_name'] = scdiscord_build_thread_name( $cl_scnotification_title, $cl_scnotification_location, $cl_scnotification_start_date ); } elseif ($show_thread) { $embed['fields'][] = [ 'name' => 'Fil de discussion', 'value' => 'Le webhook sélectionné n’est pas de type forum.', 'inline' => false, ]; $payload['embeds'] = [$embed]; } $result = scdiscord_post_webhook((string) $webhook['cl_scwebhook_url'], $payload); $stmt_log = $db->prepare( 'INSERT INTO tbl_scnotifications ( cl_scnotification_webhook_id, cl_scnotification_banner_id, cl_scnotification_title, cl_scnotification_message, cl_scnotification_payload, cl_scnotification_response, cl_scnotification_success, cl_scnotification_created_by ) VALUES ( :webhook_id, :banner_id, :title, :message, :payload, :response, :success, :created_by )' ); $stmt_log->execute([ 'webhook_id' => $cl_scnotification_webhook_id, 'banner_id' => $cl_scnotification_banner_id > 0 ? $cl_scnotification_banner_id : null, 'title' => $cl_scnotification_title, 'message' => $cl_scnotification_message, 'payload' => json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), 'response' => (string) ($result['response'] ?? ''), 'success' => !empty($result['success']) ? 1 : 0, 'created_by' => $current_session_user !== '' ? $current_session_user : 'Inconnu', ]); if (!empty($result['success'])) { unset($_SESSION['scnotification_old']); auth_flash_set('success', 'Notification Discord envoyée avec succès.'); } else { auth_flash_set('error', 'Échec de l’envoi Discord (HTTP ' . (int) ($result['http_code'] ?? 0) . ').'); } header('Location: scnotification.php'); exit; } } $old = $_SESSION['scnotification_old'] ?? []; unset($_SESSION['scnotification_old']); $stmt_webhooks = $db->query('SELECT * FROM tbl_scwebhooks ORDER BY cl_scwebhook_name ASC'); $webhooks = $stmt_webhooks->fetchAll(); $stmt_banners = $db->query('SELECT * FROM tbl_scbanners ORDER BY cl_scbanner_name ASC'); $banners = $stmt_banners->fetchAll(); function scnotification_old_value(array $old, string $key, string $default = ''): string { $value = $old[$key] ?? $default; return is_string($value) ? $value : $default; } function scnotification_old_checked(array $old, string $key, bool $default = false): bool { if (empty($old)) { return $default; } return array_key_exists($key, $old); } ?> SC Notification | R.E.A.C.T. Admin

R.E.A.C.T. SC Notification

Niveau d'accès : | Session :

Envoi d'une notification sur Discord

Canal de notification

Bannière et Couleur de bordure

Message

2500 caractères restants

Options Footer

Réactions & Fils

Tenue d'organisation & PvP

Lieu, Date et Heure

URL externes