index.php

Code Hygiene Score: 98

Issues 2

Zeile Typ Beschreibung
74 magic_number Magic Number gefunden: 24
74 magic_number Magic Number gefunden: 24

Versionen 58

Code

<?php
/**
 * Chat - Redesign
 * Clean, minimalist, professional
 */
$currentModel = $session['model'] ?? $defaultModel ?? 'claude-opus-4-5-20251101';
$selected = json_decode($session['collections'] ?? '["documents"]', true) ?: ['documents'];
$currentLimit = (int) ($session['context_limit'] ?? 5);
$currentProfileId = (int) ($session['author_profile_id'] ?? 0);
$currentPromptId = (int) ($session['system_prompt_id'] ?? 1);
$currentTemperature = (float) ($session['temperature'] ?? 0.5);
$currentMaxTokens = (int) ($session['max_tokens'] ?? 4096);
?>
<!DOCTYPE html>
<html lang="de" data-theme="light">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= htmlspecialchars($session['title'] ?? 'KI-Chat') ?> - Campus</title>
    <link rel="icon" type="image/png" href="https://campus-am-see.de/wp-content/uploads/menu-logo.png">
    <link rel="stylesheet" href="/css/chat-redesign.css">
    <script src="/js/htmx.min.js"></script>
</head>
<body>
<div class="chat-layout">
    <!-- Sidebar -->
    <aside class="chat-sidebar" id="sidebar">
        <div class="chat-sidebar__header">
            <a href="/chat" class="chat-sidebar__new">+ Neuer Chat</a>
            <button class="chat-sidebar__delete-all" hx-delete="/chat" hx-headers='{"X-CSRF-TOKEN": "<?= $csrfToken ?>"}' hx-confirm="Alle <?= count($sessions ?? []) ?> Chats löschen?" title="Alle löschen">&times; Alle</button>
        </div>
        <div class="chat-sidebar__list" id="session-list">
            <?php foreach ($sessions ?? [] as $s):
                $totalTokens = (int) ($s['total_input_tokens'] ?? 0) + (int) ($s['total_output_tokens'] ?? 0);
                $totalCost = ((int) ($s['total_input_tokens'] ?? 0) * 0.000015) + ((int) ($s['total_output_tokens'] ?? 0) * 0.000075);
                $isOllama = str_starts_with($s['model'] ?? '', 'ollama:');
                $createdAt = $s['created_at'] ?? null;
                $dateStr = $createdAt ? (new DateTime($createdAt))->format('d.m. H:i') : '';
                ?>
            <a href="/chat/<?= $s['uuid'] ?>"
               class="chat-session <?= ($session['uuid'] ?? '') === $s['uuid'] ? 'chat-session--active' : '' ?>"
               data-uuid="<?= $s['uuid'] ?>">
                <div class="chat-session__title" id="title-<?= $s['uuid'] ?>"><?= htmlspecialchars($s['title'] ?? 'Neuer Chat') ?></div>
                <div class="chat-session__meta">
                    <span class="chat-session__date"><?= $dateStr ?></span>
                    <span><?= $s['message_count'] ?? 0 ?> Nachr.</span>
                    <?php if (!$isOllama && $totalTokens > 0): ?>
                    <span class="chat-session__cost">~$<?= number_format($totalCost, 2) ?></span>
                    <?php elseif ($isOllama): ?>
                    <span class="chat-session__local">lokal</span>
                    <?php endif; ?>
                </div>
                <div class="chat-session__actions">
                    <button class="chat-session__edit" onclick="event.preventDefault(); event.stopPropagation(); editTitle('<?= $s['uuid'] ?>');" title="Bearbeiten">&#9998;</button>
                    <button class="chat-session__delete" hx-delete="/chat/<?= $s['uuid'] ?>" hx-headers='{"X-CSRF-TOKEN": "<?= $csrfToken ?>"}' hx-confirm="Session löschen?" onclick="event.preventDefault(); event.stopPropagation();">&times;</button>
                </div>
            </a>
            <?php endforeach; ?>
            <?php if (empty($sessions)): ?>
            <div class="chat-session chat-session--empty">Keine Sessions</div>
            <?php endif; ?>
        </div>
    </aside>

<?php include __DIR__ . '/partials/_config_panel.php'; ?>

    <div class="chat-overlay" id="overlay"></div>

    <!-- Main -->
    <main class="chat-main">
        <!-- Header -->
        <header class="chat-header">
            <button class="chat-toggle" id="toggle" title="Sidebar">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 12h18M3 6h18M3 18h18"/></svg>
            </button>
            <a href="/" class="chat-header__logo" title="Zur Startseite">
                <img src="https://campus-am-see.de/wp-content/uploads/menu-logo.png" alt="Campus">
            </a>
            <div class="chat-header__title">
                <h1 id="page-title"><?= htmlspecialchars($session['title'] ?? 'KI-Chat') ?></h1>
            </div>
        </header>

        <!-- Messages -->
        <div class="chat-messages" id="messages">
            <div class="chat-messages__inner">
                <?php if (empty($messages)): ?>
                <div class="chat-welcome">
                    <img src="https://campus-am-see.de/wp-content/uploads/menu-logo.png" alt="Campus am See" class="chat-welcome__logo">
                    <h2 class="chat-welcome__title">Campus am See KI</h2>
                    <p class="chat-welcome__subtitle">Wie kann ich dir helfen?</p>
                </div>
                <?php endif; ?>

                <?php foreach ($messages ?? [] as $msg): ?>
                <div class="chat-msg chat-msg--<?= $msg['role'] ?>">
                    <div class="chat-msg__content">
                        <?php if ($msg['role'] === 'user'): ?>
                            <?= htmlspecialchars($msg['content']) ?>
                        <?php else: ?>
                            <?= nl2br(htmlspecialchars($msg['content'])) ?>

                            <?php if (!empty($msg['sources'])): ?>
                            <?php $sources = json_decode($msg['sources'], true) ?: []; ?>
                            <?php if (!empty($sources)): ?>
                            <div class="chat-sources" id="sources-<?= $msg['id'] ?>">
                                <button type="button" class="chat-sources__toggle" onclick="this.parentElement.classList.toggle('chat-sources--open')">
                                    <?= count($sources) ?> Quelle<?= count($sources) > 1 ? 'n' : '' ?> &#9662;
                                </button>
                                <div class="chat-sources__list">
                                    <?php foreach ($sources as $source): ?>
                                    <div class="chat-source">
                                        <div class="chat-source__header">
                                            <?php if (!empty($source['collection'])): ?>
                                            <span class="chat-source__collection">[<?= htmlspecialchars($source['collection']) ?>]</span>
                                            <?php endif; ?>
                                            <span class="chat-source__title"><?= htmlspecialchars($source['title'] ?? 'Unbekannt') ?></span>
                                            <span class="chat-source__score"><?= round(($source['score'] ?? 0) * \Domain\Constants::PERCENT_FULL) ?>%</span>
                                        </div>
                                        <?php if (!empty($source['content'])): ?>
                                        <div class="chat-source__content">"<?= htmlspecialchars(mb_substr($source['content'], 0, 200)) ?><?= mb_strlen($source['content']) > 200 ? '...' : '' ?>"</div>
                                        <?php endif; ?>
                                    </div>
                                    <?php endforeach; ?>
                                </div>
                            </div>
                            <?php endif; ?>
                            <?php endif; ?>

                            <?php
                                $inputTokens = (int) ($msg['tokens_input'] ?? 0);
                    $outputTokens = (int) ($msg['tokens_output'] ?? 0);
                    $msgCost = ($inputTokens * 0.000015) + ($outputTokens * 0.000075);
                    $msgModel = $msg['model'] ?? 'claude-opus-4-5-20251101';
                    $msgIsOllama = str_starts_with($msgModel, 'ollama:');
                    ?>
                            <div class="chat-msg__meta">
                                <span><?= $msgIsOllama ? substr($msgModel, 7) : $msgModel ?></span>
                                <?php if (!$msgIsOllama && ($inputTokens > 0 || $outputTokens > 0)): ?>
                                <span class="chat-msg__tokens">&darr;<?= number_format($inputTokens) ?> &uarr;<?= number_format($outputTokens) ?></span>
                                <span class="chat-msg__cost">~$<?= number_format($msgCost, 4) ?></span>
                                <?php elseif ($msgIsOllama): ?>
                                <span class="chat-msg__local">lokal</span>
                                <?php endif; ?>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
        </div>

        <!-- Input Area -->
        <div class="chat-input-area">
            <div class="chat-input-wrapper">
                <form class="chat-form" id="chatForm">

                    <!-- Hidden inputs (synced from Config Panel) -->
                    <input type="hidden" name="model" id="hiddenModel" value="<?= $currentModel ?>">
                    <input type="hidden" name="context_limit" id="hiddenContextLimit" value="<?= $currentLimit ?>">
                    <input type="hidden" name="temperature" id="hiddenTemperature" value="<?= $currentTemperature ?>">
                    <input type="hidden" name="max_tokens" id="hiddenMaxTokens" value="<?= $currentMaxTokens ?>">
                    <input type="hidden" name="author_profile_id" id="hiddenAuthorProfile" value="<?= $currentProfileId ?>">
                    <input type="hidden" name="system_prompt_id" id="hiddenSystemPrompt" value="<?= $currentPromptId ?>">
                    <input type="hidden" name="structure_id" id="hiddenStructure" value="0">
                    <div id="hiddenCollections"></div>

                    <div class="chat-input-row">
                        <input type="text" name="message" class="chat-input" placeholder="Nachricht eingeben..." autocomplete="off" required>
                        <button type="submit" class="chat-send" id="sendBtn">
                            <span class="chat-send__text">Senden</span>
                            <span class="chat-send__loading"><span></span><span></span><span></span></span>
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </main>
</div>

<script src="/js/chat.js"></script>
<script>
initChatForm('<?= $session['uuid'] ?? '' ?>', '<?= $csrfToken ?>');
initConfigEditors('<?= $csrfToken ?>');
</script>
</body>
</html>
← Übersicht