Files
wevads-platform/public/hamid-admin.php
2026-04-07 03:04:16 +02:00

749 lines
29 KiB
PHP

<?php
require_once('/opt/wevads/config/credentials.php');
error_reporting(E_ALL);
$pdo = get_pdo('adx_system');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Tables dédiées WEVAL MIND
$pdo->exec("CREATE TABLE IF NOT EXISTS admin.hamid_config (
id SERIAL PRIMARY KEY, config_key VARCHAR(100) UNIQUE NOT NULL, config_value TEXT
)");
// Sauvegarder
$msg = '';
if ($_POST && isset($_POST['save'])) {
$fields = ['bot_name','welcome_message','color1','color2','groq_api_key','system_prompt'];
foreach ($fields as $k) {
if (isset($_POST[$k])) {
$stmt = $pdo->prepare("INSERT INTO admin.hamid_config (config_key, config_value) VALUES (?, ?)
ON CONFLICT (config_key) DO UPDATE SET config_value = EXCLUDED.config_value");
$stmt->execute([$k, $_POST[$k]]);
}
}
$msg = '✅ Configuration WEVAL MIND sauvegardée!';
}
// Test Groq API
if (isset($_GET['test_groq'])) {
header('Content-Type: application/json');
$config = [];
$stmt = $pdo->query("SELECT config_key, config_value FROM admin.hamid_config");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) $config[$row['config_key']] = $row['config_value'];
$apiKey = $config['groq_api_key'] ?? '';
if (empty($apiKey)) {
echo json_encode(['status' => 'error', 'message' => 'API Key manquante']);
exit;
}
$start = microtime(true);
$ch = curl_init('https://api.groq.com/openai/v1/chat/completions');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Authorization: Bearer ' . $apiKey],
CURLOPT_POSTFIELDS => json_encode(['model' => 'llama-3.3-70b-versatile', 'messages' => [['role' => 'user', 'content' => 'Hi']], 'max_tokens' => 5])
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$latency = round((microtime(true) - $start) * 1000);
if ($httpCode == 200) {
echo json_encode(['status' => 'ok', 'message' => "✅ Groq OK - {$latency}ms", 'latency' => $latency]);
} else {
echo json_encode(['status' => 'error', 'message' => "❌ Erreur HTTP $httpCode"]);
}
exit;
}
// Charger config WEVAL MIND
$config = [];
$stmt = $pdo->query("SELECT config_key, config_value FROM admin.hamid_config");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) $config[$row['config_key']] = $row['config_value'];
// Defaults
$d = [
'bot_name' => 'Hamid Esmart',
'welcome_message' => 'Bonjour! 👋 Je suis Hamid Esmart, votre expert WEVAL.',
'color1' => '#06b6d4', 'color2' => '#0891b2',
'groq_api_key' => '',
'system_prompt' => 'Tu es Hamid Esmart, assistant IA expert WEVAL. Tu connais PowerMTA, Office365, Tracking, et toute l\'infrastructure email marketing.'
];
foreach ($d as $k => $v) if (empty($config[$k])) $config[$k] = $v;
// Stats
$kbCount = $pdo->query("SELECT COUNT(*) FROM admin.chatbot_knowledge")->fetchColumn() ?: 0;
$catCount = $pdo->query("SELECT COUNT(DISTINCT category) FROM admin.chatbot_knowledge")->fetchColumn() ?: 0;
$memCount = $pdo->query("SELECT COUNT(*) FROM admin.chatbot_memory")->fetchColumn() ?: 0;
// Gestion KB
$kbMsg = '';
if ($_POST && isset($_POST['add_kb'])) {
$stmt = $pdo->prepare("INSERT INTO admin.chatbot_knowledge (question, answer, category) VALUES (?, ?, ?)");
$stmt->execute([$_POST['question'], $_POST['answer'], $_POST['category']]);
$kbMsg = '✅ Entrée KB ajoutée!';
}
if (isset($_GET['delete_kb'])) {
$pdo->prepare("DELETE FROM admin.chatbot_knowledge WHERE id = ?")->execute([$_GET['delete_kb']]);
header('Location: hamid-admin.php?tab=kb&deleted=1');
exit;
}
$tab = $_GET['tab'] ?? 'config';
// Charger KB
$search = $_GET['search'] ?? '';
$catFilter = $_GET['cat'] ?? '';
$sql = "SELECT * FROM admin.chatbot_knowledge WHERE 1=1";
if ($search) $sql .= " AND (question ILIKE '%" . addslashes($search) . "%' OR answer ILIKE '%" . addslashes($search) . "%')";
if ($catFilter) $sql .= " AND category = '" . addslashes($catFilter) . "'";
$sql .= " ORDER BY id DESC LIMIT 50";
$kbEntries = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$categories = $pdo->query("SELECT DISTINCT category FROM admin.chatbot_knowledge ORDER BY category")->fetchAll(PDO::FETCH_COLUMN);
?>
<!DOCTYPE html>
<html data-theme="dark" lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🧠 WEVAL MIND Admin</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Segoe UI', sans-serif;
background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
min-height: 100vh;
color: #e2e8f0;
}
/* Header */
.header {
background: linear-gradient(135deg, rgba(6,182,212,0.15), rgba(6,182,212,0.05));
border-bottom: 1px solid rgba(6,182,212,0.3);
padding: 0 30px;
display: flex;
justify-content: space-between;
align-items: center;
height: 65px;
backdrop-filter: blur(10px);
position: sticky;
top: 0;
z-index: 100;
}
.header-left {
display: flex;
align-items: center;
gap: 15px;
}
.logo {
width: 45px;
height: 45px;
background: linear-gradient(135deg, #06b6d4, #0891b2);
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-size: 22px;
box-shadow: 0 4px 15px rgba(6,182,212,0.4);
}
.header h1 {
font-size: 20px;
font-weight: 600;
}
.header h1 span { color: #06b6d4; }
.header-links {
display: flex;
gap: 10px;
}
.header-links a {
padding: 10px 18px;
background: rgba(6,182,212,0.1);
color: #06b6d4;
text-decoration: none;
border-radius: 10px;
font-size: 13px;
font-weight: 500;
transition: all 0.3s;
display: flex;
align-items: center;
gap: 8px;
}
.header-links a:hover { background: rgba(6,182,212,0.2); transform: translateY(-2px); }
.header-links a.primary { background: linear-gradient(135deg, #06b6d4, #0891b2); color: white; }
/* Container */
.container { max-width: 1300px; margin: 0 auto; padding: 30px; }
/* Alert */
.alert {
padding: 15px 20px;
border-radius: 12px;
margin-bottom: 25px;
display: flex;
align-items: center;
gap: 12px;
font-size: 14px;
animation: slideDown 0.3s ease;
}
@keyframes slideDown {
from { opacity: 0; transform: translateY(-10px); }
to { opacity: 1; transform: translateY(0); }
}
.alert-success { background: linear-gradient(135deg, rgba(34,197,94,0.2), rgba(34,197,94,0.05)); border: 1px solid rgba(34,197,94,0.4); color: #22c55e; }
.alert-info { background: linear-gradient(135deg, rgba(6,182,212,0.2), rgba(6,182,212,0.05)); border: 1px solid rgba(6,182,212,0.4); color: #06b6d4; }
/* Note Box */
.note-box {
background: linear-gradient(135deg, rgba(251,191,36,0.1), rgba(251,191,36,0.02));
border: 1px solid rgba(251,191,36,0.3);
border-radius: 12px;
padding: 15px 20px;
margin-bottom: 25px;
font-size: 13px;
color: #fbbf24;
display: flex;
align-items: center;
gap: 12px;
}
.note-box a { color: #06b6d4; font-weight: 600; }
/* Tabs */
.tabs {
display: flex;
gap: 8px;
margin-bottom: 25px;
background: rgba(30,41,59,0.5);
padding: 8px;
border-radius: 14px;
width: fit-content;
}
.tab {
padding: 12px 24px;
background: transparent;
border: none;
color: #94a3b8;
cursor: pointer;
border-radius: 10px;
font-size: 14px;
font-weight: 500;
transition: all 0.3s;
text-decoration: none;
display: flex;
align-items: center;
gap: 8px;
}
.tab:hover { color: #e2e8f0; background: rgba(255,255,255,0.05); }
.tab.active {
background: linear-gradient(135deg, #06b6d4, #0891b2);
color: white;
box-shadow: 0 4px 15px rgba(6,182,212,0.3);
}
/* Stats Cards */
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.stat-card {
background: linear-gradient(135deg, rgba(30,41,59,0.8), rgba(30,41,59,0.4));
border: 1px solid rgba(255,255,255,0.08);
border-radius: 16px;
padding: 25px;
text-align: center;
transition: all 0.3s;
}
.stat-card:hover { transform: translateY(-5px); border-color: rgba(6,182,212,0.3); }
.stat-card .icon {
width: 50px;
height: 50px;
background: linear-gradient(135deg, rgba(6,182,212,0.2), rgba(6,182,212,0.05));
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-size: 22px;
margin: 0 auto 15px;
}
.stat-card .number { font-size: 32px; font-weight: 700; color: #06b6d4; }
.stat-card .label { font-size: 13px; color: #64748b; margin-top: 5px; }
/* Panel */
.panel {
background: linear-gradient(135deg, rgba(30,41,59,0.8), rgba(30,41,59,0.4));
border: 1px solid rgba(255,255,255,0.08);
border-radius: 20px;
padding: 30px;
margin-bottom: 25px;
}
.panel-header {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 25px;
padding-bottom: 20px;
border-bottom: 1px solid rgba(255,255,255,0.08);
}
.panel-header .icon {
width: 45px;
height: 45px;
background: linear-gradient(135deg, #06b6d4, #0891b2);
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
}
.panel-header h2 { font-size: 18px; font-weight: 600; }
.panel-header p { font-size: 13px; color: #64748b; margin-top: 3px; }
/* Form */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.form-group { margin-bottom: 20px; }
.form-group label {
display: block;
font-size: 12px;
font-weight: 600;
color: #94a3b8;
margin-bottom: 8px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.form-group input, .form-group textarea, .form-group select {
width: 100%;
padding: 14px 16px;
background: rgba(15,23,42,0.6);
border: 1px solid rgba(255,255,255,0.1);
border-radius: 12px;
color: white;
font-size: 14px;
transition: all 0.3s;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
outline: none;
border-color: #06b6d4;
box-shadow: 0 0 0 3px rgba(6,182,212,0.1);
}
.form-group textarea { min-height: 100px; resize: vertical; }
.form-group input[type="color"] { height: 50px; padding: 5px; cursor: pointer; }
.form-group small { display: block; margin-top: 6px; font-size: 11px; color: #64748b; }
.form-group small a { color: #06b6d4; }
.input-with-btn {
display: flex;
gap: 10px;
}
.input-with-btn input { flex: 1; }
.color-preview {
display: flex;
gap: 15px;
align-items: center;
}
.color-preview input[type="color"] { width: 80px; }
.color-sample {
flex: 1;
height: 50px;
border-radius: 12px;
background: linear-gradient(135deg, var(--c1), var(--c2));
}
/* Buttons */
.btn {
padding: 12px 24px;
border: none;
border-radius: 10px;
cursor: pointer;
font-weight: 600;
font-size: 14px;
display: inline-flex;
align-items: center;
gap: 8px;
transition: all 0.3s;
}
.btn-primary {
background: linear-gradient(135deg, #06b6d4, #0891b2);
color: white;
box-shadow: 0 4px 15px rgba(6,182,212,0.3);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(6,182,212,0.4); }
.btn-success { background: linear-gradient(135deg, #22c55e, #16a34a); color: white; }
.btn-success:hover { transform: translateY(-2px); }
.btn-danger { background: rgba(239,68,68,0.2); color: #ef4444; border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.3); }
.btn-sm { padding: 8px 16px; font-size: 12px; }
/* Groq Box */
.groq-box {
background: linear-gradient(135deg, rgba(34,197,94,0.1), rgba(34,197,94,0.02));
border: 1px solid rgba(34,197,94,0.3);
border-radius: 16px;
padding: 25px;
margin-bottom: 25px;
}
.groq-header {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 20px;
}
.groq-header .icon {
width: 40px;
height: 40px;
background: linear-gradient(135deg, #22c55e, #16a34a);
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
}
.groq-header h3 { font-size: 16px; color: #22c55e; }
.groq-status {
display: flex;
align-items: center;
gap: 10px;
margin-top: 15px;
padding: 12px 15px;
background: rgba(0,0,0,0.2);
border-radius: 10px;
}
.status-dot {
width: 12px;
height: 12px;
border-radius: 50%;
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.status-dot.ok { background: #22c55e; box-shadow: 0 0 10px #22c55e; }
.status-dot.err { background: #ef4444; box-shadow: 0 0 10px #ef4444; }
.status-dot.unk { background: #64748b; }
/* KB Table */
.kb-search {
display: flex;
gap: 15px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.kb-search input, .kb-search select {
padding: 12px 16px;
background: rgba(15,23,42,0.6);
border: 1px solid rgba(255,255,255,0.1);
border-radius: 10px;
color: white;
font-size: 13px;
}
.kb-search input { flex: 1; min-width: 200px; }
.kb-search select { min-width: 150px; }
.kb-table {
width: 100%;
border-collapse: collapse;
}
.kb-table th {
background: linear-gradient(135deg, rgba(6,182,212,0.2), rgba(6,182,212,0.05));
padding: 15px;
text-align: left;
font-size: 12px;
font-weight: 600;
color: #06b6d4;
text-transform: uppercase;
}
.kb-table td {
padding: 15px;
border-bottom: 1px solid rgba(255,255,255,0.05);
font-size: 13px;
}
.kb-table tr:hover { background: rgba(6,182,212,0.05); }
.kb-cat {
display: inline-block;
padding: 4px 10px;
background: linear-gradient(135deg, rgba(139,92,246,0.2), rgba(139,92,246,0.05));
color: #a78bfa;
border-radius: 6px;
font-size: 11px;
font-weight: 600;
}
/* Add KB Form */
.add-kb-toggle {
display: flex;
align-items: center;
gap: 10px;
padding: 15px 20px;
background: rgba(6,182,212,0.1);
border: 1px dashed rgba(6,182,212,0.3);
border-radius: 12px;
margin-bottom: 20px;
cursor: pointer;
color: #06b6d4;
font-weight: 500;
transition: all 0.3s;
}
.add-kb-toggle:hover { background: rgba(6,182,212,0.15); }
.add-kb-form {
background: rgba(15,23,42,0.6);
border-radius: 12px;
padding: 20px;
margin-bottom: 20px;
}
/* Responsive */
@media (max-width: 768px) {
.header { padding: 0 15px; }
.container { padding: 15px; }
.form-grid { grid-template-columns: 1fr; }
.stats-grid { grid-template-columns: repeat(2, 1fr); }
}
</style>
</head>
<body>
<div class="header">
<div class="header-left">
<div class="logo">🧠</div>
<h1><span>WEVAL MIND</span> Admin</h1>
</div>
<div class="header-links">
<a href="/hamid-fullscreen.php" class="primary"><i class="fas fa-comments"></i> Chat Hamid</a>
<a href="/widget-admin.php"><i class="fas fa-puzzle-piece"></i> Widget Admin</a>
<a href="/"><i class="fas fa-home"></i> WEVAL</a>
</div>
</div>
<div class="container">
<?php if ($msg): ?><div class="alert alert-success"><i class="fas fa-check-circle"></i> <?= $msg ?></div><?php endif; ?>
<?php if ($kbMsg): ?><div class="alert alert-success"><i class="fas fa-check-circle"></i> <?= $kbMsg ?></div><?php endif; ?>
<?php if (isset($_GET['deleted'])): ?><div class="alert alert-success"><i class="fas fa-trash"></i> Entrée supprimée!</div><?php endif; ?>
<div class="note-box">
<i class="fas fa-info-circle" style="font-size:20px;"></i>
<div>Cette page configure uniquement <strong>WEVAL MIND</strong> (hamid-fullscreen.php). Pour configurer le Widget popup, utilisez <a href="/widget-admin.php">Widget Admin</a>.</div>
</div>
<div class="tabs">
<a href="?tab=config" class="tab <?= $tab=='config'?'active':'' ?>"><i class="fas fa-cog"></i> Configuration</a>
<a href="?tab=kb" class="tab <?= $tab=='kb'?'active':'' ?>"><i class="fas fa-database"></i> Base de Connaissances (<?= $kbCount ?>)</a>
</div>
<?php if ($tab == 'config'): ?>
<!-- Stats -->
<div class="stats-grid">
<div class="stat-card">
<div class="icon">📚</div>
<div class="number"><?= $kbCount ?></div>
<div class="label">KB Entries</div>
</div>
<div class="stat-card">
<div class="icon">📁</div>
<div class="number"><?= $catCount ?></div>
<div class="label">Catégories</div>
</div>
<div class="stat-card">
<div class="icon">🧠</div>
<div class="number"><?= $memCount ?></div>
<div class="label">Mémoires</div>
</div>
<div class="stat-card">
<div class="icon">⚡</div>
<div class="number">GROQ</div>
<div class="label">Provider</div>
</div>
</div>
<form method="POST">
<!-- Groq API -->
<div class="groq-box">
<div class="groq-header">
<div class="icon">⚡</div>
<div>
<h3>Groq API (Provider WEVAL MIND)</h3>
<small style="color:#64748b;">LLama 3.3 70B - Ultra rapide</small>
</div>
</div>
<div class="form-group">
<label>API Key Groq</label>
<div class="input-with-btn">
<input type="text" name="groq_api_key" value="<?= htmlspecialchars($config['groq_api_key']) ?>" placeholder="gsk_...">
<button type="button" class="btn btn-success btn-sm" onclick="testGroq()"><i class="fas fa-play"></i> Tester</button>
</div>
<small>Obtenir: <a href="https://console.groq.com/keys" target="_blank">console.groq.com/keys</a> (gratuit)</small>
</div>
<div class="groq-status">
<span class="status-dot unk" id="groqDot"></span>
<span id="groqStatus">Cliquez sur Tester pour vérifier la connexion</span>
</div>
</div>
<!-- Personality -->
<div class="panel">
<div class="panel-header">
<div class="icon">🤖</div>
<div>
<h2>Personnalité WEVAL MIND</h2>
<p>Configurez l'apparence et le comportement de Hamid</p>
</div>
</div>
<div class="form-grid">
<div class="form-group">
<label>Nom du Bot</label>
<input type="text" name="bot_name" value="<?= htmlspecialchars($config['bot_name']) ?>">
</div>
<div class="form-group">
<label>Message d'Accueil</label>
<input type="text" name="welcome_message" value="<?= htmlspecialchars($config['welcome_message']) ?>">
</div>
</div>
<div class="form-group">
<label>System Prompt (Personnalité IA)</label>
<textarea name="system_prompt" rows="4"><?= htmlspecialchars($config['system_prompt']) ?></textarea>
<small>Définit comment Hamid se comporte et répond aux questions</small>
</div>
<div class="form-group">
<label>Couleurs du thème</label>
<div class="color-preview" style="--c1: <?= $config['color1'] ?>; --c2: <?= $config['color2'] ?>;">
<input type="color" name="color1" value="<?= $config['color1'] ?>" id="c1">
<input type="color" name="color2" value="<?= $config['color2'] ?>" id="c2">
<div class="color-sample" id="colorSample"></div>
</div>
</div>
<button type="submit" name="save" value="1" class="btn btn-primary">
<i class="fas fa-save"></i> Sauvegarder Configuration WEVAL MIND
</button>
</div>
</form>
<?php else: ?>
<!-- KB Tab -->
<div class="panel">
<div class="panel-header">
<div class="icon">📚</div>
<div>
<h2>Base de Connaissances</h2>
<p><?= $kbCount ?> entrées dans <?= $catCount ?> catégories</p>
</div>
</div>
<div class="kb-search">
<input type="text" id="searchInput" placeholder="🔍 Rechercher une question..." value="<?= htmlspecialchars($search) ?>">
<select id="catFilter">
<option value="">Toutes catégories</option>
<?php foreach ($categories as $cat): ?>
<option value="<?= htmlspecialchars($cat) ?>" <?= $catFilter==$cat?'selected':'' ?>><?= htmlspecialchars($cat) ?></option>
<?php endforeach; ?>
</select>
<button class="btn btn-primary btn-sm" onclick="filterKB()"><i class="fas fa-search"></i> Filtrer</button>
</div>
<details>
<summary class="add-kb-toggle"><i class="fas fa-plus-circle"></i> Ajouter une nouvelle entrée</summary>
<form method="POST" class="add-kb-form">
<div class="form-grid">
<div class="form-group">
<label>Question</label>
<input type="text" name="question" required placeholder="Ex: Comment configurer PowerMTA ?">
</div>
<div class="form-group">
<label>Catégorie</label>
<input type="text" name="category" list="cats" required placeholder="Ex: PowerMTA">
<datalist id="cats">
<?php foreach ($categories as $cat): ?>
<option value="<?= htmlspecialchars($cat) ?>">
<?php endforeach; ?>
</datalist>
</div>
</div>
<div class="form-group">
<label>Réponse</label>
<textarea name="answer" required placeholder="La réponse détaillée..."></textarea>
</div>
<button type="submit" name="add_kb" class="btn btn-success"><i class="fas fa-plus"></i> Ajouter à la KB</button>
</form>
</details>
<table class="kb-table">
<thead>
<tr>
<th style="width:50px;">ID</th>
<th>Question</th>
<th style="width:120px;">Catégorie</th>
<th style="width:80px;">Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($kbEntries as $kb): ?>
<tr>
<td><?= $kb['id'] ?></td>
<td title="<?= htmlspecialchars($kb['answer']) ?>"><?= htmlspecialchars(mb_substr($kb['question'], 0, 70)) ?><?= strlen($kb['question']) > 70 ? '...' : '' ?></td>
<td><span class="kb-cat"><?= htmlspecialchars($kb['category']) ?></span></td>
<td>
<a href="?tab=kb&delete_kb=<?= $kb['id'] ?>" class="btn btn-danger btn-sm" onclick="return confirm('Supprimer cette entrée ?')">
<i class="fas fa-trash"></i>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
<script>
// Test Groq
async function testGroq() {
const dot = document.getElementById('groqDot');
const status = document.getElementById('groqStatus');
dot.className = 'status-dot unk';
status.textContent = '⏳ Test en cours...';
try {
const r = await fetch('?test_groq=1');
const d = await r.json();
dot.className = 'status-dot ' + (d.status === 'ok' ? 'ok' : 'err');
status.textContent = d.message;
} catch(e) {
dot.className = 'status-dot err';
status.textContent = '❌ Erreur: ' + e.message;
}
}
// Color preview
document.getElementById('c1')?.addEventListener('input', updateColors);
document.getElementById('c2')?.addEventListener('input', updateColors);
function updateColors() {
const c1 = document.getElementById('c1').value;
const c2 = document.getElementById('c2').value;
document.getElementById('colorSample').style.background = `linear-gradient(135deg, ${c1}, ${c2})`;
}
// KB Filter
function filterKB() {
const search = document.getElementById('searchInput').value;
const cat = document.getElementById('catFilter').value;
window.location.href = '?tab=kb&search=' + encodeURIComponent(search) + '&cat=' + encodeURIComponent(cat);
}
document.getElementById('searchInput')?.addEventListener('keypress', e => { if (e.key === 'Enter') filterKB(); });
</script>
</body>
</html>