$c) { // Check 1: ID based (New) if ($url_id !== null && (string)$id === (string)$url_id) { $authorized_client = $c; break; } // Check 2: Name/Token based (Legacy) if (strcasecmp($c['name'], $url_client) == 0 && $c['token'] === $url_token) { $authorized_client = $c; break; } } } } if (!$authorized_client) { http_response_code(403); die("

⛔ ACCÈS REFUSÉ

"); } // --- 2. ANALYSE DE L'ÉTAT --- $client_folder = 'clients/' . $authorized_client['name']; $images = is_dir($client_folder) ? glob($client_folder . "/*.jpg") : []; array_multisort(array_map('filemtime', $images), SORT_DESC, $images); // État par défaut (SAFE) $state = 'SAFE'; $banner_color = '#10b981'; // Vert $banner_text = '✅ SURVEILLANCE ACTIVE'; $status_text = 'R.A.S — Tout va bien'; $current_image = 'placeholder.jpg'; $alert_time = "--/--/----"; // DÉTECTION INTELLIGENTE if (!empty($images)) { $current_image = $images[0]; $alert_time = date("d/m/Y à H:i:s", filemtime($current_image)); // On demande à la Base de Données ce qu'en pense l'IA $is_real_alert = $authorized_client['alerte'] ?? false; // Lire le verdict RÉEL de l'IA depuis le sidecar JSON de l'image la plus récente $sidecar_file = $current_image . ".json"; $sidecar_data = null; $ia_was_urgent = null; // null = pas de données, true = IA a dit urgence, false = IA a dit RAS if (file_exists($sidecar_file)) { $sidecar_data = json_decode(file_get_contents($sidecar_file), true); if ($sidecar_data && isset($sidecar_data['urgence'])) { $ia_was_urgent = $sidecar_data['urgence']; } } // SÉCURITÉ CRITIQUE : Détecter si la DB est en retard sur les alertes réelles // Compare le timestamp de l'image vs la dernière mise à jour de la DB $image_timestamp = filemtime($current_image); $db_last_update = strtotime($authorized_client['last_update'] ?? '2000-01-01'); $db_is_stale = ($image_timestamp > $db_last_update + 60); // +60s de marge // Est-ce que quelqu'un s'en occupe déjà ? $handler = $authorized_client['handled_by'] ?? null; $handler_time = $authorized_client['handled_at'] ?? ''; if ($handler) { // ÉTAT ORANGE : PRIS EN CHARGE $state = 'HANDLED'; $banner_color = '#f59e0b'; $banner_text = "🟠 PRISE EN CHARGE PAR " . strtoupper($handler); $status_text = "⚠️ Intervention en cours par $handler depuis $handler_time"; } elseif ($is_real_alert === true) { // ÉTAT ROUGE : DB dit alerte active $state = 'DANGER'; $banner_color = '#ef4444'; $banner_text = '🚨 ALERTE EN COURS'; $status_text = '⚠️ Chute Détectée — Intervention Requise'; } elseif ($ia_was_urgent === true && $db_is_stale) { // ÉTAT ROUGE : Le sidecar dit URGENCE mais la DB n'a pas été mise à jour // → L'alerte n'a JAMAIS été traitée, la DB est en retard $state = 'DANGER'; $banner_color = '#ef4444'; $banner_text = '🚨 ALERTE NON TRAITÉE'; $status_text = '⚠️ Alerte détectée — Aucune prise en charge enregistrée !'; } elseif ($is_real_alert === false && $ia_was_urgent === true) { // ÉTAT VERT : Alerte RÉELLE qui a été traitée et archivée // La DB a été mise à jour APRÈS l'image → quelqu'un a géré l'incident $state = 'RESOLVED'; $banner_color = '#10b981'; $banner_text = "✅ INCIDENT TRAITÉ & ARCHIVÉ"; $status_text = "L'alerte a été prise en charge et archivée."; } elseif ($is_real_alert === false) { // FAUSSE ALERTE : L'IA a dit "pas d'urgence" (sidecar urgence=false ou absent) $state = 'FALSE_POSITIVE'; $banner_color = '#3b82f6'; $banner_text = "🛡️ FAUSSE ALERTE ANNULÉE PAR IA"; $status_text = "ℹ️ Mouvement détecté, mais l'IA confirme que tout va bien."; } else { // ÉTAT ROUGE : Fallback sécurité $state = 'DANGER'; $banner_color = '#ef4444'; $banner_text = '🚨 ALERTE EN COURS'; $status_text = '⚠️ Chute Détectée — Intervention Requise'; } } ?> LUCAS - Supervision
LUCAS
HORODATAGE
🕒
🤖 ANALYSE IA

Système Connecté

Aucune anomalie détectée.

Historique des captures ()
$img): $timestamp = filemtime($img); $date_str = date("d/m H:i", $timestamp); // DATA ARCHIVED Check $json_sidecar = $img . ".json"; $archived_data = null; if (file_exists($json_sidecar)) { $archived_data = json_decode(file_get_contents($json_sidecar), true); } // Prepare JS attributes $safe_message = htmlspecialchars($archived_data['message'] ?? '', ENT_QUOTES); $safe_urgence = $archived_data['urgence'] ?? null; // null if no archive // If no archive, we pass 'null' to indicate "Unknown/Legacy" $js_urgence = json_encode($safe_urgence); ?>
", this, , "")'>
📞 112

L'IA a invalidé l'alerte du capteur.

Cet incident a été traité et archivé.

L'alerte est maintenue visible pour les autres.