/** * AI Chat Widget Setup – Kopieer embed code voor je website * Klanten kunnen deze widget op hun site embedden zodat bezoekers kunnen chatten met AI */ if (!ob_get_level()) { ob_start(); } require_once __DIR__ . '/inc/base.php'; if (!isset($_SESSION['customer_logged_in']) || $_SESSION['customer_logged_in'] !== true) { header('Location: /customer_portal/login.php?redirect=' . urlencode('/customer_portal/ai-chat-widget-setup.php')); exit; } $customer_id = (int)($_SESSION['customer_info']['id'] ?? $_SESSION['customer_id'] ?? 0); if (!$customer_id) { header('Location: /customer_portal/login.php'); exit; } $page_title = 'AI Chat Widget Setup'; $page_extra_styles = ''; include __DIR__ . '/layout-start.php'; // Genereer of haal widget token op $conn = @new mysqli('localhost', 'cyberpanel', 'OAmPGf6r10dTYR', 'itlive_portal'); if ($conn && $conn->connect_error) { $conn = @new mysqli('localhost', 'root', 'root', 'itlive_portal'); } if ($conn && $conn->connect_error) { $conn = @new mysqli('localhost', 'root', '', 'itlive_portal'); } $widget_token = ''; $widget_config = null; if ($conn && !$conn->connect_error) { $conn->set_charset('utf8mb4'); // Maak tabel aan als die niet bestaat @$conn->query("CREATE TABLE IF NOT EXISTS customer_chat_widgets ( id INT AUTO_INCREMENT PRIMARY KEY, customer_id INT NOT NULL, public_token VARCHAR(64) NOT NULL UNIQUE, token VARCHAR(64) NULL, use_rag TINYINT(1) DEFAULT 1, system_prompt TEXT, title VARCHAR(255) DEFAULT 'AI Assistent', welcome_message TEXT DEFAULT 'Hallo! Hoe kan ik helpen?', company_name VARCHAR(255), display_name VARCHAR(255), color VARCHAR(20) DEFAULT '#667eea', icon VARCHAR(10) DEFAULT '💬', project_path VARCHAR(255), quick_links JSON, is_active TINYINT(1) DEFAULT 1, enabled TINYINT(1) DEFAULT 1, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, INDEX idx_customer (customer_id), INDEX idx_token (public_token) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"); // Check of er al een widget config is $stmt = $conn->prepare("SELECT id, COALESCE(public_token, token) AS token, use_rag, system_prompt, title, welcome_message, company_name, display_name, color, icon FROM customer_chat_widgets WHERE customer_id = ? LIMIT 1"); $stmt->bind_param('i', $customer_id); $stmt->execute(); $res = $stmt->get_result(); if ($row = $res->fetch_assoc()) { $widget_token = $row['token'] ?? ''; $widget_config = $row; // Vul ontbrekende bedrijfsnaam/display_name uit customers (zodat widget overal dezelfde naam toont) $need_sync = (trim($row['company_name'] ?? '') === '' || trim($row['display_name'] ?? '') === ''); if ($need_sync) { $st_c = $conn->prepare("SELECT company, first_name, last_name FROM customers WHERE id = ? LIMIT 1"); if ($st_c) { $st_c->bind_param('i', $customer_id); $st_c->execute(); $st_c->bind_result($c_company, $c_first, $c_last); if ($st_c->fetch()) { $sync_company = trim($c_company ?? ''); $sync_display = trim(($c_first ?? '') . ' ' . ($c_last ?? '')); $st_up = $conn->prepare("UPDATE customer_chat_widgets SET company_name = COALESCE(NULLIF(TRIM(company_name), ''), ?), display_name = COALESCE(NULLIF(TRIM(display_name), ''), ?) WHERE customer_id = ?"); if ($st_up) { $st_up->bind_param('ssi', $sync_company, $sync_display, $customer_id); $st_up->execute(); $st_up->close(); } } $st_c->close(); } } } else { // Maak nieuwe widget config – bedrijfsnaam uit session (komt uit customers bij login) $token = bin2hex(random_bytes(16)); $company = trim($_SESSION['customer_info']['company'] ?? ''); $display = trim(($_SESSION['customer_info']['first_name'] ?? '') . ' ' . ($_SESSION['customer_info']['last_name'] ?? '')); if ($company === '' || $display === '') { $st_c = $conn->prepare("SELECT company, first_name, last_name FROM customers WHERE id = ? LIMIT 1"); if ($st_c) { $st_c->bind_param('i', $customer_id); $st_c->execute(); $st_c->bind_result($c_company, $c_first, $c_last); if ($st_c->fetch()) { if ($company === '') $company = trim($c_company ?? ''); if ($display === '') $display = trim(($c_first ?? '') . ' ' . ($c_last ?? '')); } $st_c->close(); } } $stmt2 = $conn->prepare("INSERT INTO customer_chat_widgets (customer_id, public_token, token, use_rag, title, welcome_message, company_name, display_name, color, icon) VALUES (?, ?, ?, 1, 'AI Assistent', 'Hallo! Hoe kan ik helpen?', ?, ?, '#667eea', '💬')"); $stmt2->bind_param('issss', $customer_id, $token, $token, $company, $display); if ($stmt2->execute()) { $widget_token = $token; $widget_config = ['token' => $token, 'use_rag' => 1, 'title' => 'AI Assistent', 'welcome_message' => 'Hallo! Hoe kan ik helpen?', 'company_name' => $company, 'display_name' => $display]; } $stmt2->close(); } $stmt->close(); $conn->close(); } $base_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . '://' . ($_SERVER['HTTP_HOST'] ?? 'portal.itlive.nl'); $widget_url = $base_url . '/customer_portal/ai-chat-widget.js?token=' . urlencode($widget_token); $embed_code = ''; ?>

📦 AI Chat Widget Setup

Kopieer deze code en plak hem in de <head> of <body> van je website. Bezoekers kunnen dan direct chatten met AI over je bedrijf, diensten en producten.

⚠️ Kon widget token niet aanmaken. Probeer het later opnieuw of neem contact op met support.