HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/panomity.de/vr.panomity.com/api/lead.php
<?php
/**
 * Lead-Capture für den KI-Concierge.
 *
 * POST { name, email, phone, note, pano_id, language }
 * Speichert die Anfrage in vrm.db (Tabelle leads) und benachrichtigt
 * optional per Mail (config.gpuq.php: lead_notify_email).
 */

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
header('Content-Type: application/json; charset=utf-8');

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(200);
    exit;
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    echo json_encode(['ok' => false, 'error' => 'Method not allowed']);
    exit;
}

$raw = file_get_contents('php://input') ?: '';
$data = json_decode($raw, true);
if (!is_array($data)) {
    $data = $_POST;
}

$name = trim(mb_substr((string)($data['name'] ?? ''), 0, 200));
$email = trim(mb_substr((string)($data['email'] ?? ''), 0, 200));
$phone = trim(mb_substr((string)($data['phone'] ?? ''), 0, 60));
$note = trim(mb_substr((string)($data['note'] ?? ''), 0, 2000));
$panoId = (int)($data['pano_id'] ?? 0);
$language = preg_match('/^[a-z]{2}$/', (string)($data['language'] ?? '')) ? (string)$data['language'] : '';

if ($name === '' || ($email === '' && $phone === '')) {
    http_response_code(400);
    echo json_encode(['ok' => false, 'error' => 'name and email or phone required']);
    exit;
}
if ($email !== '' && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
    http_response_code(400);
    echo json_encode(['ok' => false, 'error' => 'invalid email']);
    exit;
}

$db = new SQLite3(__DIR__ . '/../admin/data/vrm.db');
$db->busyTimeout(10000);
$db->exec('CREATE TABLE IF NOT EXISTS leads (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    created_at TEXT NOT NULL,
    name TEXT NOT NULL,
    email TEXT,
    phone TEXT,
    note TEXT,
    pano_id INTEGER,
    language TEXT,
    source TEXT DEFAULT "ai-concierge"
)');

$stmt = $db->prepare('INSERT INTO leads (created_at, name, email, phone, note, pano_id, language)
    VALUES (:now, :name, :email, :phone, :note, :pano, :lang)');
$stmt->bindValue(':now', gmdate('c'), SQLITE3_TEXT);
$stmt->bindValue(':name', $name, SQLITE3_TEXT);
$stmt->bindValue(':email', $email, SQLITE3_TEXT);
$stmt->bindValue(':phone', $phone, SQLITE3_TEXT);
$stmt->bindValue(':note', $note, SQLITE3_TEXT);
$stmt->bindValue(':pano', $panoId, SQLITE3_INTEGER);
$stmt->bindValue(':lang', $language, SQLITE3_TEXT);
$stmt->execute();
$leadId = $db->lastInsertRowID();
$db->close();

// Optionale Mail-Benachrichtigung.
$cfgPath = __DIR__ . '/config.gpuq.php';
$notify = '';
if (is_file($cfgPath)) {
    $cfg = require $cfgPath;
    $notify = (string)($cfg['lead_notify_email'] ?? '');
}
if ($notify !== '' && filter_var($notify, FILTER_VALIDATE_EMAIL)) {
    $subject = '[VR-Tour] Neue Interessenten-Anfrage: ' . $name;
    $bodyMail = "Neue Anfrage über den KI-Concierge der VR-Tour\n\n"
        . "Name:    $name\n"
        . "E-Mail:  $email\n"
        . "Telefon: $phone\n"
        . "Szene:   p$panoId\n"
        . "Sprache: $language\n\n"
        . "Notiz:\n$note\n";
    @mail($notify, $subject, $bodyMail, 'From: vr-tour@vr.panomity.com');
}

echo json_encode(['ok' => true, 'lead_id' => $leadId]);