This commit is contained in:
Flatlogic Bot 2026-04-29 07:11:28 +00:00
parent f74316a661
commit 37e7f940e8
4 changed files with 96 additions and 241 deletions

View File

@ -180,6 +180,8 @@ CREATE TABLE `tbl_scwebhooks` (
`cl_scwebhook_id` int(11) NOT NULL AUTO_INCREMENT,
`cl_scwebhook_name` varchar(255) NOT NULL,
`cl_scwebhook_url` text NOT NULL,
`cl_scwebhook_image_url` text NOT NULL,
`cl_scwebhook_border_color` varchar(20) NOT NULL DEFAULT '#ffae00',
`cl_scwebhook_is_forum` tinyint(1) DEFAULT 0,
PRIMARY KEY (`cl_scwebhook_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

View File

@ -17,11 +17,25 @@ function scdiscord_bootstrap(): void
cl_scwebhook_id INT(11) NOT NULL AUTO_INCREMENT,
cl_scwebhook_name VARCHAR(255) NOT NULL,
cl_scwebhook_url TEXT NOT NULL,
cl_scwebhook_image_url TEXT NOT NULL,
cl_scwebhook_border_color VARCHAR(20) NOT NULL DEFAULT '#ffae00',
cl_scwebhook_is_forum TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (cl_scwebhook_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"
);
$columns_stmt = $db->query("SHOW COLUMNS FROM tbl_scwebhooks LIKE 'cl_scwebhook_image_url'");
$has_webhook_image = (bool) $columns_stmt->fetch();
if (!$has_webhook_image) {
$db->exec("ALTER TABLE tbl_scwebhooks ADD COLUMN cl_scwebhook_image_url TEXT NOT NULL AFTER cl_scwebhook_url");
}
$columns_stmt = $db->query("SHOW COLUMNS FROM tbl_scwebhooks LIKE 'cl_scwebhook_border_color'");
$has_webhook_border_color = (bool) $columns_stmt->fetch();
if (!$has_webhook_border_color) {
$db->exec("ALTER TABLE tbl_scwebhooks ADD COLUMN cl_scwebhook_border_color VARCHAR(20) NOT NULL DEFAULT '#ffae00' AFTER cl_scwebhook_image_url");
}
$db->exec(
"CREATE TABLE IF NOT EXISTS tbl_scbanners (
cl_scbanner_id INT(11) NOT NULL AUTO_INCREMENT,
@ -38,6 +52,20 @@ function scdiscord_bootstrap(): void
$db->exec("ALTER TABLE tbl_scbanners ADD COLUMN cl_scbanner_border_color VARCHAR(20) NOT NULL DEFAULT '#ffae00' AFTER cl_scbanner_url");
}
$db->exec(
"UPDATE tbl_scwebhooks w
LEFT JOIN tbl_scbanners b ON b.cl_scbanner_name = w.cl_scwebhook_name
SET
w.cl_scwebhook_image_url = CASE
WHEN (w.cl_scwebhook_image_url IS NULL OR w.cl_scwebhook_image_url = '') AND b.cl_scbanner_url IS NOT NULL THEN b.cl_scbanner_url
ELSE w.cl_scwebhook_image_url
END,
w.cl_scwebhook_border_color = CASE
WHEN (w.cl_scwebhook_border_color IS NULL OR w.cl_scwebhook_border_color = '' OR w.cl_scwebhook_border_color = '#ffae00') AND b.cl_scbanner_border_color IS NOT NULL THEN b.cl_scbanner_border_color
ELSE w.cl_scwebhook_border_color
END"
);
$db->exec(
"CREATE TABLE IF NOT EXISTS tbl_scnotifications (
cl_scnotification_id INT(11) NOT NULL AUTO_INCREMENT,

View File

@ -37,9 +37,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$cl_scnotification_webhook_id = (int) $matches[1];
}
$cl_scnotification_banner_id = (int) ($_POST['cl_scnotification_banner_id'] ?? 0);
$use_custom_banner = isset($_POST['cl_scnotification_use_custom_banner']) || isset($_POST['use_custom_banner']);
$cl_scnotification_custom_banner_url = trim((string) ($_POST['cl_scnotification_custom_banner_url'] ?? ($_POST['custom_banner'] ?? '')));
$notify_here = isset($_POST['cl_scnotification_notify_here']) || isset($_POST['ping_here']);
$notify_everyone = isset($_POST['cl_scnotification_notify_everyone']) || isset($_POST['ping_everyone']);
$cl_scnotification_title = trim((string) ($_POST['cl_scnotification_title'] ?? ($_POST['title'] ?? '')));
@ -92,18 +89,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
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', 'LURL de bannière personnalisée est invalide.');
header('Location: scnotification.php');
exit;
}
foreach ([
'URL canal Discord' => [$show_channel_url, $cl_scnotification_channel_url],
@ -119,10 +104,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
$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');
$banner_image_url = (string) ($webhook['cl_scwebhook_image_url'] ?? '');
$border_color = (string) ($webhook['cl_scwebhook_border_color'] ?? '#ffae00');
$fields = [];
@ -249,7 +232,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$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,
@ -258,7 +240,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
cl_scnotification_created_by
) VALUES (
:webhook_id,
:banner_id,
:title,
:message,
:payload,
@ -269,7 +250,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
);
$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),
@ -298,8 +278,6 @@ 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;
@ -737,25 +715,11 @@ function scnotification_old_checked(array $old, string $key, bool $default = fal
</section>
<section class="section-card">
<h2 class="section-title">Bannière et Couleur de bordure</h2>
<div class="field-row">
<select class="control" name="cl_scnotification_banner_id" id="cl_scnotification_banner_id">
<option value="">Aucune bannière</option>
<?php foreach ($banners as $banner): ?>
<?php $selected = (string) $banner['cl_scbanner_id'] === scnotification_old_value($old, 'cl_scnotification_banner_id'); ?>
<option value="<?php echo (int) $banner['cl_scbanner_id']; ?>" <?php echo $selected ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($banner['cl_scbanner_name'] . ' [' . scdiscord_normalize_hex_color((string) ($banner['cl_scbanner_border_color'] ?? '#ffae00')) . ']', ENT_QUOTES, 'UTF-8'); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<label class="check">
<input type="checkbox" name="cl_scnotification_use_custom_banner" id="cl_scnotification_use_custom_banner" value="1" <?php echo scnotification_old_checked($old, 'cl_scnotification_use_custom_banner') ? 'checked' : ''; ?>>
<span>Utiliser une bannière personnalisée</span>
</label>
<div class="field-row">
<input type="url" class="control" name="cl_scnotification_custom_banner_url" id="cl_scnotification_custom_banner_url" placeholder="URL personnalisée https://.../png" value="<?php echo htmlspecialchars(scnotification_old_value($old, 'cl_scnotification_custom_banner_url'), ENT_QUOTES, 'UTF-8'); ?>">
</div>
<h2 class="section-title">Prévisualisation et Couleur</h2>
<p style="margin:0; color: var(--text-muted); line-height:1.6;">
Limage de prévisualisation et la couleur de bordure sont maintenant prises automatiquement depuis le canal Discord sélectionné.
Pour les modifier, va dans la page de configuration Discord du webhook correspondant.
</p>
</section>
<section class="section-card">
@ -939,7 +903,6 @@ function scnotification_old_checked(array $old, string $key, bool $default = fal
}
function syncStates() {
toggleByCheckbox('cl_scnotification_use_custom_banner', '#cl_scnotification_custom_banner_url');
toggleByCheckbox('cl_scnotification_show_footer', '.footer-toggle');
toggleByCheckbox('cl_scnotification_show_org', '.org-toggle');
toggleByCheckbox('cl_scnotification_show_pvp', '.pvp-toggle');
@ -963,7 +926,6 @@ function scnotification_old_checked(array $old, string $key, bool $default = fal
messageField.addEventListener('input', updateCounter);
[
'cl_scnotification_use_custom_banner',
'cl_scnotification_show_footer',
'cl_scnotification_show_org',
'cl_scnotification_show_pvp',

View File

@ -30,10 +30,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$webhook_id = (int) ($_POST['webhook_id'] ?? 0);
$cl_scwebhook_name = trim((string) ($_POST['cl_scwebhook_name'] ?? ''));
$cl_scwebhook_url = trim((string) ($_POST['cl_scwebhook_url'] ?? ''));
$cl_scwebhook_image_url = trim((string) ($_POST['cl_scwebhook_image_url'] ?? ''));
$cl_scwebhook_border_color = scdiscord_normalize_hex_color((string) ($_POST['cl_scwebhook_border_color'] ?? ''));
$cl_scwebhook_is_forum = 0;
if ($cl_scwebhook_name === '' || $cl_scwebhook_url === '') {
auth_flash_set('error', 'Le nom et lURL du webhook sont obligatoires.');
if ($cl_scwebhook_name === '' || $cl_scwebhook_url === '' || $cl_scwebhook_image_url === '') {
auth_flash_set('error', 'Le nom, lURL du webhook et limage sont obligatoires.');
header('Location: scwebhook.php');
exit;
}
@ -44,28 +46,38 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
exit;
}
if (!filter_var($cl_scwebhook_image_url, FILTER_VALIDATE_URL)) {
auth_flash_set('error', 'LURL de limage Discord est invalide.');
header('Location: scwebhook.php');
exit;
}
try {
if ($action === 'add_webhook') {
$stmt = $db->prepare('INSERT INTO tbl_scwebhooks (cl_scwebhook_name, cl_scwebhook_url, cl_scwebhook_is_forum) VALUES (:name, :url, :is_forum)');
$stmt = $db->prepare('INSERT INTO tbl_scwebhooks (cl_scwebhook_name, cl_scwebhook_url, cl_scwebhook_image_url, cl_scwebhook_border_color, cl_scwebhook_is_forum) VALUES (:name, :url, :image_url, :border_color, :is_forum)');
$stmt->execute([
'name' => $cl_scwebhook_name,
'url' => $cl_scwebhook_url,
'image_url' => $cl_scwebhook_image_url,
'border_color' => $cl_scwebhook_border_color,
'is_forum' => $cl_scwebhook_is_forum,
]);
auth_flash_set('success', 'Webhook Discord ajouté avec succès.');
auth_flash_set('success', 'Canal Discord ajouté avec succès.');
} else {
if ($webhook_id <= 0) {
throw new RuntimeException('ID de webhook invalide.');
}
$stmt = $db->prepare('UPDATE tbl_scwebhooks SET cl_scwebhook_name = :name, cl_scwebhook_url = :url, cl_scwebhook_is_forum = :is_forum WHERE cl_scwebhook_id = :id');
$stmt = $db->prepare('UPDATE tbl_scwebhooks SET cl_scwebhook_name = :name, cl_scwebhook_url = :url, cl_scwebhook_image_url = :image_url, cl_scwebhook_border_color = :border_color, cl_scwebhook_is_forum = :is_forum WHERE cl_scwebhook_id = :id');
$stmt->execute([
'name' => $cl_scwebhook_name,
'url' => $cl_scwebhook_url,
'image_url' => $cl_scwebhook_image_url,
'border_color' => $cl_scwebhook_border_color,
'is_forum' => $cl_scwebhook_is_forum,
'id' => $webhook_id,
]);
auth_flash_set('success', 'Webhook Discord mis à jour.');
auth_flash_set('success', 'Canal Discord mis à jour.');
}
} catch (Throwable $e) {
auth_flash_set('error', 'Erreur webhook : ' . $e->getMessage());
@ -89,7 +101,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} else {
$stmt = $db->prepare('DELETE FROM tbl_scwebhooks WHERE cl_scwebhook_id = :id');
$stmt->execute(['id' => $webhook_id]);
auth_flash_set('success', 'Webhook Discord supprimé.');
auth_flash_set('success', 'Canal Discord supprimé.');
}
} catch (Throwable $e) {
auth_flash_set('error', 'Erreur suppression webhook : ' . $e->getMessage());
@ -99,86 +111,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
header('Location: scwebhook.php');
exit;
}
if ($action === 'add_banner' || $action === 'update_banner') {
$banner_id = (int) ($_POST['banner_id'] ?? 0);
$cl_scbanner_name = trim((string) ($_POST['cl_scbanner_name'] ?? ''));
$cl_scbanner_url = trim((string) ($_POST['cl_scbanner_url'] ?? ''));
$cl_scbanner_border_color = scdiscord_normalize_hex_color((string) ($_POST['cl_scbanner_border_color'] ?? ''));
if ($cl_scbanner_name === '' || $cl_scbanner_url === '') {
auth_flash_set('error', 'Le nom et le lien dimage de la bannière sont obligatoires.');
header('Location: scwebhook.php');
exit;
}
if (!filter_var($cl_scbanner_url, FILTER_VALIDATE_URL)) {
auth_flash_set('error', 'LURL de la bannière est invalide.');
header('Location: scwebhook.php');
exit;
}
try {
if ($action === 'add_banner') {
$stmt = $db->prepare('INSERT INTO tbl_scbanners (cl_scbanner_name, cl_scbanner_url, cl_scbanner_border_color) VALUES (:name, :url, :border_color)');
$stmt->execute([
'name' => $cl_scbanner_name,
'url' => $cl_scbanner_url,
'border_color' => $cl_scbanner_border_color,
]);
auth_flash_set('success', 'Bannière Discord ajoutée avec succès.');
} else {
if ($banner_id <= 0) {
throw new RuntimeException('ID de bannière invalide.');
}
$stmt = $db->prepare('UPDATE tbl_scbanners SET cl_scbanner_name = :name, cl_scbanner_url = :url, cl_scbanner_border_color = :border_color WHERE cl_scbanner_id = :id');
$stmt->execute([
'name' => $cl_scbanner_name,
'url' => $cl_scbanner_url,
'border_color' => $cl_scbanner_border_color,
'id' => $banner_id,
]);
auth_flash_set('success', 'Bannière Discord mise à jour.');
}
} catch (Throwable $e) {
auth_flash_set('error', 'Erreur bannière : ' . $e->getMessage());
}
header('Location: scwebhook.php');
exit;
}
if ($action === 'delete_banner') {
$banner_id = (int) ($_POST['banner_id'] ?? 0);
if ($banner_id > 0) {
try {
$stmt = $db->prepare('DELETE FROM tbl_scbanners WHERE cl_scbanner_id = :id');
$stmt->execute(['id' => $banner_id]);
auth_flash_set('success', 'Bannière Discord supprimée.');
} catch (Throwable $e) {
auth_flash_set('error', 'Erreur suppression bannière : ' . $e->getMessage());
}
}
header('Location: scwebhook.php');
exit;
}
}
$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();
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SC Webhook | R.E.A.C.T. Admin</title>
<title>SC Discord | R.E.A.C.T. Admin</title>
<link rel="stylesheet" type="text/css" href="css/styles.css">
<link rel="stylesheet" type="text/css" href="css/default.css">
<style>
@ -568,16 +512,16 @@ $banners = $stmt_banners->fetchAll();
<div class="page-grid">
<aside class="stack">
<section class="glass-card">
<h2 id="webhookFormTitle">Nouveau webhook Discord</h2>
<p class="section-note">Ajoute la nomination du webhook et son URL. Tous les webhooks enregistrés ici sont traités comme des webhooks Discord génériques.</p>
<h2 id="webhookFormTitle">Nouveau canal Discord</h2>
<p class="section-note">Configure ici toute la logique centralisée du canal Discord : nomination, URL du webhook, image de prévisualisation et couleur de bordure.</p>
<form method="post" id="webhookForm" class="form-grid">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrf_token, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="action" id="webhookAction" value="add_webhook">
<input type="hidden" name="webhook_id" id="webhookId" value="">
<div class="form-group">
<label for="cl_scwebhook_name">Nomination du webhook</label>
<input type="text" id="cl_scwebhook_name" name="cl_scwebhook_name" class="form-control" required placeholder="Ex : news-bops-cig">
<label for="cl_scwebhook_name">Nomination du canal</label>
<input type="text" id="cl_scwebhook_name" name="cl_scwebhook_name" class="form-control" required placeholder="Ex : Code 4">
</div>
<div class="form-group">
@ -585,53 +529,36 @@ $banners = $stmt_banners->fetchAll();
<input type="url" id="cl_scwebhook_url" name="cl_scwebhook_url" class="form-control" required placeholder="https://discord.com/api/webhooks/...">
</div>
<div class="form-group">
<label for="cl_scwebhook_image_url">Lien image / prévisualisation</label>
<input type="url" id="cl_scwebhook_image_url" name="cl_scwebhook_image_url" class="form-control" required placeholder="https://.../banniere.png">
</div>
<button type="submit" class="btn-modern" id="webhookSubmitBtn">Ajouter le webhook</button>
<div class="form-group">
<label for="cl_scwebhook_border_color">Couleur de bordure</label>
<input type="color" id="cl_scwebhook_border_color" name="cl_scwebhook_border_color" class="form-control" value="#ffae00">
</div>
<button type="submit" class="btn-modern" id="webhookSubmitBtn">Ajouter le canal</button>
<button type="button" class="btn-modern secondary" id="webhookCancelBtn" style="display:none;" onclick="resetWebhookForm()">Annuler lédition</button>
</form>
</section>
<section class="glass-card">
<h2 id="bannerFormTitle">Nouvelle bannière</h2>
<p class="section-note">Chaque bannière stocke un nom, un lien dimage et une couleur de bordure utilisée dans lembed Discord.</p>
<form method="post" id="bannerForm" class="form-grid">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrf_token, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="action" id="bannerAction" value="add_banner">
<input type="hidden" name="banner_id" id="bannerId" value="">
<div class="form-group">
<label for="cl_scbanner_name">Nom de la bannière</label>
<input type="text" id="cl_scbanner_name" name="cl_scbanner_name" class="form-control" required placeholder="Ex : Alerte Rouge">
</div>
<div class="form-group">
<label for="cl_scbanner_url">Lien image</label>
<input type="url" id="cl_scbanner_url" name="cl_scbanner_url" class="form-control" required placeholder="https://.../banniere.png">
</div>
<div class="form-group">
<label for="cl_scbanner_border_color">Couleur de bordure</label>
<input type="color" id="cl_scbanner_border_color" name="cl_scbanner_border_color" class="form-control" value="#ffae00">
</div>
<button type="submit" class="btn-modern" id="bannerSubmitBtn">Ajouter la bannière</button>
<button type="button" class="btn-modern secondary" id="bannerCancelBtn" style="display:none;" onclick="resetBannerForm()">Annuler lédition</button>
</form>
</section>
</aside>
<main class="list-grid">
<section class="glass-card">
<h2>Webhooks Discord enregistrés</h2>
<h2>Canaux Discord enregistrés</h2>
<?php if (empty($webhooks)): ?>
<div class="empty-state">Aucun webhook configuré pour le moment.</div>
<div class="empty-state">Aucun canal Discord configuré pour le moment.</div>
<?php else: ?>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Nomination</th>
<th>URL</th>
<th>Webhook</th>
<th>Prévisualisation</th>
<th>Couleur</th>
<th style="text-align:right;">Actions</th>
</tr>
</thead>
@ -644,6 +571,15 @@ $banners = $stmt_banners->fetchAll();
<td>
<span class="muted"><?php echo htmlspecialchars(scdiscord_mask_webhook_url((string) $webhook['cl_scwebhook_url']), ENT_QUOTES, 'UTF-8'); ?></span>
</td>
<td>
<img class="banner-preview" src="<?php echo htmlspecialchars((string) ($webhook['cl_scwebhook_image_url'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>" alt="Prévisualisation webhook">
</td>
<td>
<?php $webhookBorderColor = scdiscord_normalize_hex_color((string) ($webhook['cl_scwebhook_border_color'] ?? '#ffae00')); ?>
<span class="color-chip" style="--chip-color: <?php echo htmlspecialchars($webhookBorderColor, ENT_QUOTES, 'UTF-8'); ?>;">
<?php echo htmlspecialchars($webhookBorderColor, ENT_QUOTES, 'UTF-8'); ?>
</span>
</td>
<td>
<div class="actions-inline">
<button
@ -653,9 +589,11 @@ $banners = $stmt_banners->fetchAll();
'id' => (int) $webhook['cl_scwebhook_id'],
'name' => (string) $webhook['cl_scwebhook_name'],
'url' => (string) $webhook['cl_scwebhook_url'],
'image_url' => (string) ($webhook['cl_scwebhook_image_url'] ?? ''),
'border_color' => (string) ($webhook['cl_scwebhook_border_color'] ?? '#ffae00'),
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>)'
>Éditer</button>
<form method="post" onsubmit="return confirm('Supprimer ce webhook Discord ?');">
<form method="post" onsubmit="return confirm('Supprimer ce canal Discord ?');">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrf_token, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="action" value="delete_webhook">
<input type="hidden" name="webhook_id" value="<?php echo (int) $webhook['cl_scwebhook_id']; ?>">
@ -670,109 +608,34 @@ $banners = $stmt_banners->fetchAll();
</div>
<?php endif; ?>
</section>
<section class="glass-card">
<h2>Bannières disponibles</h2>
<?php if (empty($banners)): ?>
<div class="empty-state">Aucune bannière enregistrée pour le moment.</div>
<?php else: ?>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Nom</th>
<th>Prévisualisation</th>
<th>Couleur</th>
<th style="text-align:right;">Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($banners as $banner): ?>
<tr>
<td>
<strong><?php echo htmlspecialchars($banner['cl_scbanner_name'], ENT_QUOTES, 'UTF-8'); ?></strong>
</td>
<td>
<img class="banner-preview" src="<?php echo htmlspecialchars($banner['cl_scbanner_url'], ENT_QUOTES, 'UTF-8'); ?>" alt="Prévisualisation bannière">
</td>
<td>
<span class="color-chip" style="--chip-color: <?php echo htmlspecialchars(scdiscord_normalize_hex_color((string) ($banner['cl_scbanner_border_color'] ?? '#ffae00')), ENT_QUOTES, 'UTF-8'); ?>;">
<?php echo htmlspecialchars(scdiscord_normalize_hex_color((string) ($banner['cl_scbanner_border_color'] ?? '#ffae00')), ENT_QUOTES, 'UTF-8'); ?>
</span>
</td>
<td>
<div class="actions-inline">
<button
type="button"
class="btn-modern btn-mini"
onclick='editBanner(<?php echo json_encode([
'id' => (int) $banner['cl_scbanner_id'],
'name' => (string) $banner['cl_scbanner_name'],
'url' => (string) $banner['cl_scbanner_url'],
'border_color' => (string) ($banner['cl_scbanner_border_color'] ?? '#ffae00'),
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>)'
>Éditer</button>
<form method="post" onsubmit="return confirm('Supprimer cette bannière ?');">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrf_token, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="action" value="delete_banner">
<input type="hidden" name="banner_id" value="<?php echo (int) $banner['cl_scbanner_id']; ?>">
<button type="submit" class="btn-modern btn-mini danger">Supprimer</button>
</form>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</section>
</main>
</div>
</div>
<script>
function editWebhook(webhook) {
document.getElementById('webhookFormTitle').textContent = 'Modifier le webhook Discord';
document.getElementById('webhookFormTitle').textContent = 'Modifier le canal Discord';
document.getElementById('webhookAction').value = 'update_webhook';
document.getElementById('webhookId').value = webhook.id || '';
document.getElementById('cl_scwebhook_name').value = webhook.name || '';
document.getElementById('cl_scwebhook_url').value = webhook.url || '';
document.getElementById('webhookSubmitBtn').textContent = 'Mettre à jour le webhook';
document.getElementById('cl_scwebhook_image_url').value = webhook.image_url || '';
document.getElementById('cl_scwebhook_border_color').value = webhook.border_color || '#ffae00';
document.getElementById('webhookSubmitBtn').textContent = 'Mettre à jour le canal';
document.getElementById('webhookCancelBtn').style.display = 'inline-flex';
}
function resetWebhookForm() {
document.getElementById('webhookFormTitle').textContent = 'Nouveau webhook Discord';
document.getElementById('webhookFormTitle').textContent = 'Nouveau canal Discord';
document.getElementById('webhookAction').value = 'add_webhook';
document.getElementById('webhookId').value = '';
document.getElementById('cl_scwebhook_name').value = '';
document.getElementById('cl_scwebhook_url').value = '';
document.getElementById('webhookSubmitBtn').textContent = 'Ajouter le webhook';
document.getElementById('cl_scwebhook_image_url').value = '';
document.getElementById('cl_scwebhook_border_color').value = '#ffae00';
document.getElementById('webhookSubmitBtn').textContent = 'Ajouter le canal';
document.getElementById('webhookCancelBtn').style.display = 'none';
}
function editBanner(banner) {
document.getElementById('bannerFormTitle').textContent = 'Modifier la bannière';
document.getElementById('bannerAction').value = 'update_banner';
document.getElementById('bannerId').value = banner.id || '';
document.getElementById('cl_scbanner_name').value = banner.name || '';
document.getElementById('cl_scbanner_url').value = banner.url || '';
document.getElementById('cl_scbanner_border_color').value = banner.border_color || '#ffae00';
document.getElementById('bannerSubmitBtn').textContent = 'Mettre à jour la bannière';
document.getElementById('bannerCancelBtn').style.display = 'inline-flex';
}
function resetBannerForm() {
document.getElementById('bannerFormTitle').textContent = 'Nouvelle bannière';
document.getElementById('bannerAction').value = 'add_banner';
document.getElementById('bannerId').value = '';
document.getElementById('cl_scbanner_name').value = '';
document.getElementById('cl_scbanner_url').value = '';
document.getElementById('cl_scbanner_border_color').value = '#ffae00';
document.getElementById('bannerSubmitBtn').textContent = 'Ajouter la bannière';
document.getElementById('bannerCancelBtn').style.display = 'none';
}
</script>
</body>
</html>