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/ollama-starters.php
<?php
/**
 * Ollama Conversation Starters API für CMS4VR
 * 
 * Gibt Konversationsstarter für eine Scene zurück
 */

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
header('Content-Type: application/json');

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(200);
    exit;
}

if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
    http_response_code(405);
    echo json_encode(['error' => 'Method not allowed']);
    exit;
}

// Datenbank-Verbindung
$dbPath = __DIR__ . '/../admin/data/vrm.db';
if (!file_exists($dbPath)) {
    http_response_code(500);
    echo json_encode(['error' => 'Database not found']);
    exit;
}

$db = new SQLite3($dbPath);

// Parameter
$panoId = isset($_GET['pano_id']) ? (int)$_GET['pano_id'] : 0;
$language = isset($_GET['language']) ? $_GET['language'] : 'de';

if ($panoId <= 0) {
    http_response_code(400);
    echo json_encode(['error' => 'Invalid pano_id']);
    exit;
}

// Category-ID ermitteln
$categoryId = null;
$stmt = $db->prepare('SELECT category_id FROM pano_category_connections WHERE pano_id = :pano_id LIMIT 1');
$stmt->bindValue(':pano_id', $panoId, SQLITE3_INTEGER);
$result = $stmt->execute();
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
    $categoryId = $row['category_id'];
}

// Starter abrufen
$starters = [];
$stmt = $db->prepare('
    SELECT id, starter_text, position
    FROM ollama_conversation_starters
    WHERE active = 1 AND language = :language
    AND ((pano_id = :pano_id) OR (category_id = :category_id AND :category_id IS NOT NULL))
    ORDER BY position ASC
    LIMIT 4
');
$stmt->bindValue(':pano_id', $panoId, SQLITE3_INTEGER);
$stmt->bindValue(':category_id', $categoryId, SQLITE3_INTEGER);
$stmt->bindValue(':language', $language, SQLITE3_TEXT);
$result = $stmt->execute();

while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
    $starters[] = [
        'id' => $row['id'],
        'text' => $row['starter_text'],
        'position' => $row['position']
    ];
}

$db->close();

echo json_encode([
    'starters' => $starters
]);