<?php
/**
 * HAVA75 Ortak Galeri Motoru
 * Bu dosya tek başına açılmaz. Galeri sayfaları tarafından çağrılır.
 */

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

function h75_e($value) {
    return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
}

function h75_user() {
    if (function_exists('current_user')) {
        $u = current_user();
        if (is_array($u)) return $u;
    }

    if (isset($_SESSION['user']) && is_array($_SESSION['user'])) {
        return $_SESSION['user'];
    }

    return [];
}

function h75_is_yonetici() {
    $u = h75_user();
    return isset($u['role']) && $u['role'] === 'yonetici';
}

function h75_gallery_paths($cfg) {
    $root = dirname(__DIR__);
    $dataFile = $root . '/' . ltrim($cfg['data_file'], '/');
    $uploadDir = $root . '/' . trim($cfg['upload_dir'], '/');

    return [$root, $dataFile, $uploadDir];
}

function h75_ensure_gallery_files($cfg) {
    [$root, $dataFile, $uploadDir] = h75_gallery_paths($cfg);

    if (!is_dir(dirname($dataFile))) {
        mkdir(dirname($dataFile), 0755, true);
    }

    if (!file_exists($dataFile)) {
        file_put_contents($dataFile, "[]");
    }

    if (!is_dir($uploadDir)) {
        mkdir($uploadDir, 0755, true);
    }

    // Upload klasöründe PHP çalışmasını ve dizin listelemeyi engellemek için.
    $htaccess = $uploadDir . '/.htaccess';
    if (!file_exists($htaccess)) {
        file_put_contents($htaccess, "Options -Indexes\nRemoveHandler .php .phtml .php3 .php4 .php5 .php7 .php8\nRemoveType .php .phtml .php3 .php4 .php5 .php7 .php8\n<FilesMatch \"\\.(php|phtml|phar)$\">\n    Require all denied\n</FilesMatch>\n");
    }
}

function h75_read_items($cfg) {
    h75_ensure_gallery_files($cfg);
    [, $dataFile] = h75_gallery_paths($cfg);

    $raw = file_get_contents($dataFile);
    $items = json_decode($raw, true);

    if (!is_array($items)) {
        $items = [];
    }

    usort($items, function($a, $b) {
        return strcmp($b['created_at'] ?? '', $a['created_at'] ?? '');
    });

    return $items;
}

function h75_write_items($cfg, $items) {
    h75_ensure_gallery_files($cfg);
    [, $dataFile] = h75_gallery_paths($cfg);

    $json = json_encode(array_values($items), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
    if ($json === false) {
        throw new RuntimeException('JSON verisi oluşturulamadı.');
    }

    file_put_contents($dataFile, $json, LOCK_EX);
}

function h75_csrf_token() {
    if (empty($_SESSION['h75_csrf'])) {
        $_SESSION['h75_csrf'] = bin2hex(random_bytes(32));
    }

    return $_SESSION['h75_csrf'];
}

function h75_check_csrf() {
    $posted = $_POST['csrf'] ?? '';
    return is_string($posted) && hash_equals($_SESSION['h75_csrf'] ?? '', $posted);
}

function h75_flash_set($type, $message) {
    $_SESSION['h75_flash'] = ['type' => $type, 'message' => $message];
}

function h75_flash_get() {
    $flash = $_SESSION['h75_flash'] ?? null;
    unset($_SESSION['h75_flash']);
    return $flash;
}

function h75_handle_upload($cfg) {
    if (!h75_is_yonetici()) {
        h75_flash_set('error', 'Bu işlem için yönetici yetkisi gerekir.');
        return;
    }

    if (!h75_check_csrf()) {
        h75_flash_set('error', 'Güvenlik doğrulaması başarısız oldu. Sayfayı yenileyip tekrar deneyin.');
        return;
    }

    if (!isset($_FILES['media_file']) || !is_array($_FILES['media_file'])) {
        h75_flash_set('error', 'Dosya seçilmedi.');
        return;
    }

    $file = $_FILES['media_file'];

    if (($file['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
        $err = $file['error'] ?? UPLOAD_ERR_NO_FILE;
        $messages = [
            UPLOAD_ERR_INI_SIZE => 'Dosya sunucu yükleme sınırını aşıyor.',
            UPLOAD_ERR_FORM_SIZE => 'Dosya form yükleme sınırını aşıyor.',
            UPLOAD_ERR_PARTIAL => 'Dosya tam yüklenemedi.',
            UPLOAD_ERR_NO_FILE => 'Dosya seçilmedi.',
            UPLOAD_ERR_NO_TMP_DIR => 'Geçici klasör bulunamadı.',
            UPLOAD_ERR_CANT_WRITE => 'Dosya diske yazılamadı.',
            UPLOAD_ERR_EXTENSION => 'Yükleme PHP uzantısı tarafından durduruldu.'
        ];
        h75_flash_set('error', $messages[$err] ?? 'Dosya yüklenemedi.');
        return;
    }

    $maxBytes = $cfg['max_bytes'] ?? (500 * 1024 * 1024); // 500 MB varsayılan
    if (($file['size'] ?? 0) > $maxBytes) {
        h75_flash_set('error', 'Dosya çok büyük. Sunucu/PHP limitlerini de kontrol etmek gerekebilir.');
        return;
    }

    $original = $file['name'] ?? 'dosya';
    $ext = strtolower(pathinfo($original, PATHINFO_EXTENSION));

    $allowedExt = [
        'jpg' => 'image',
        'jpeg' => 'image',
        'png' => 'image',
        'webp' => 'image',
        'gif' => 'image',
        'mp4' => 'video',
        'webm' => 'video',
        'mov' => 'video'
    ];

    if (!isset($allowedExt[$ext])) {
        h75_flash_set('error', 'Sadece JPG, PNG, WEBP, GIF, MP4, WEBM veya MOV yüklenebilir.');
        return;
    }

    $finfo = new finfo(FILEINFO_MIME_TYPE);
    $mime = $finfo->file($file['tmp_name']);

    $allowedMime = [
        'image/jpeg' => 'image',
        'image/png' => 'image',
        'image/webp' => 'image',
        'image/gif' => 'image',
        'video/mp4' => 'video',
        'video/webm' => 'video',
        'video/quicktime' => 'video'
    ];

    if (!isset($allowedMime[$mime])) {
        h75_flash_set('error', 'Dosya türü güvenli bulunmadı: ' . $mime);
        return;
    }

    $type = $allowedExt[$ext];
    if ($allowedMime[$mime] !== $type) {
        h75_flash_set('error', 'Dosya uzantısı ile içerik türü uyuşmuyor.');
        return;
    }

    [$root, , $uploadDir] = h75_gallery_paths($cfg);
    if (!is_dir($uploadDir)) {
        mkdir($uploadDir, 0755, true);
    }

    $newName = date('Ymd_His') . '_' . bin2hex(random_bytes(8)) . '.' . $ext;
    $target = rtrim($uploadDir, '/') . '/' . $newName;

    if (!move_uploaded_file($file['tmp_name'], $target)) {
        h75_flash_set('error', 'Dosya sunucuya taşınamadı.');
        return;
    }

    $relativeFile = trim($cfg['upload_dir'], '/') . '/' . $newName;
    $user = h75_user();

    $items = h75_read_items($cfg);
    $items[] = [
        'id' => bin2hex(random_bytes(12)),
        'title' => trim($_POST['title'] ?? '') ?: 'Başlıksız İçerik',
        'description' => trim($_POST['description'] ?? ''),
        'file' => $relativeFile,
        'type' => $type,
        'original_name' => $original,
        'uploaded_by' => $user['username'] ?? '',
        'created_at' => date('Y-m-d H:i:s')
    ];

    h75_write_items($cfg, $items);
    h75_flash_set('success', 'İçerik başarıyla eklendi.');
}

function h75_handle_delete($cfg) {
    if (!h75_is_yonetici()) {
        h75_flash_set('error', 'Bu işlem için yönetici yetkisi gerekir.');
        return;
    }

    if (!h75_check_csrf()) {
        h75_flash_set('error', 'Güvenlik doğrulaması başarısız oldu.');
        return;
    }

    $deleteId = $_POST['delete_id'] ?? '';
    if (!$deleteId) {
        h75_flash_set('error', 'Silinecek kayıt bulunamadı.');
        return;
    }

    [$root] = h75_gallery_paths($cfg);
    $items = h75_read_items($cfg);
    $newItems = [];
    $deleted = false;

    foreach ($items as $item) {
        if (($item['id'] ?? '') === $deleteId) {
            $file = $item['file'] ?? '';
            $safePrefix = trim($cfg['upload_dir'], '/') . '/';

            if ($file && str_starts_with($file, $safePrefix)) {
                $full = $root . '/' . $file;
                if (is_file($full)) {
                    @unlink($full);
                }
            }

            $deleted = true;
            continue;
        }

        $newItems[] = $item;
    }

    if ($deleted) {
        h75_write_items($cfg, $newItems);
        h75_flash_set('success', 'İçerik silindi.');
    } else {
        h75_flash_set('error', 'Kayıt bulunamadı.');
    }
}

function h75_process_gallery_post($cfg) {
    if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
        return;
    }

    $action = $_POST['action'] ?? '';

    if ($action === 'add_media') {
        h75_handle_upload($cfg);
    } elseif ($action === 'delete_media') {
        h75_handle_delete($cfg);
    }

    $self = strtok($_SERVER['REQUEST_URI'], '?');
    header('Location: ' . $self);
    exit;
}

function h75_render_gallery_page($cfg) {
    h75_ensure_gallery_files($cfg);
    h75_process_gallery_post($cfg);

    $items = h75_read_items($cfg);
    $user = h75_user();
    $isYonetici = h75_is_yonetici();
    $flash = h75_flash_get();
    $csrf = h75_csrf_token();

    $title = $cfg['title'] ?? 'Galeri';
    $subtitle = $cfg['subtitle'] ?? 'HAVA 75 Dijital Arşiv';
    $backUrl = $cfg['back_url'] ?? 'index.php';

    ?>
<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo h75_e($title); ?> - HAVA 75</title>
    <style>
        html, body {
            margin: 0;
            padding: 0;
            min-height: 100%;
            background: #000;
            color: #00ffff;
            font-family: 'Courier New', Courier, monospace;
            overflow-x: hidden;
        }

        body {
            padding-bottom: 40px;
        }

        .stars {
            position: fixed;
            inset: 0;
            background: url("https://www.transparenttextures.com/patterns/stardust.png");
            opacity: .45;
            z-index: 0;
            pointer-events: none;
        }

        .wrap {
            width: min(1100px, 92%);
            margin: 0 auto;
            position: relative;
            z-index: 1;
        }

        .topbar {
            margin-top: 18px;
            display: flex;
            justify-content: space-between;
            gap: 15px;
            align-items: center;
            flex-wrap: wrap;
        }

        .btn-cyber, .cyber-link, button {
            border: 1px solid #00ffff;
            color: #00ffff;
            background: rgba(0,0,0,.75);
            padding: 10px 16px;
            text-decoration: none;
            cursor: pointer;
            letter-spacing: 1.5px;
            font-family: inherit;
            transition: .25s;
        }

        .btn-cyber:hover, .cyber-link:hover, button:hover {
            background: #00ffff;
            color: #000;
            box-shadow: 0 0 18px #00ffff;
        }

        .hero {
            border: 1px solid rgba(0,255,255,.55);
            margin-top: 24px;
            padding: 28px;
            background: rgba(0,20,25,.45);
            box-shadow: 0 0 30px rgba(0,255,255,.09);
        }

        h1 {
            margin: 0;
            font-size: clamp(24px, 5vw, 44px);
            letter-spacing: 5px;
            text-shadow: 0 0 15px #00ffff;
        }

        .subtitle {
            margin-top: 10px;
            opacity: .75;
            line-height: 1.5;
        }

        .flash {
            margin-top: 20px;
            border: 1px solid;
            padding: 12px 14px;
            background: rgba(0,0,0,.8);
        }

        .flash.success { color: #00ff88; border-color: #00ff88; }
        .flash.error { color: #ff6060; border-color: #ff6060; }

        .admin-panel {
            margin-top: 24px;
            border: 1px solid rgba(0,255,255,.55);
            padding: 18px;
            background: rgba(0,255,255,.06);
        }

        .admin-panel h2 {
            margin-top: 0;
            font-size: 17px;
            letter-spacing: 2px;
        }

        .form-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 14px;
        }

        .full { grid-column: 1 / -1; }

        label {
            display: block;
            font-size: 12px;
            opacity: .8;
            margin-bottom: 7px;
        }

        input[type="text"], textarea, input[type="file"] {
            width: 100%;
            box-sizing: border-box;
            border: 1px solid rgba(0,255,255,.7);
            background: rgba(0,0,0,.75);
            color: #00ffff;
            padding: 12px;
            outline: none;
            font-family: inherit;
        }

        textarea { min-height: 90px; resize: vertical; }

        .gallery-info {
            margin: 25px 0 10px 0;
            opacity: .8;
            font-size: 13px;
        }

        .grid {
            display: grid;
            grid-template-columns: repeat(3, minmax(0, 1fr));
            gap: 18px;
            margin-top: 18px;
        }

        .card {
            border: 1px solid rgba(0,255,255,.58);
            background: rgba(0,0,0,.82);
            overflow: hidden;
            transition: .25s;
        }

        .card:hover {
            transform: translateY(-4px);
            box-shadow: 0 0 22px rgba(0,255,255,.4);
        }

        .thumb {
            height: 300px;
            background: #020c0f;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
    display: block;
}

       .video-thumb {
    height: 260px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle, rgba(0,255,255,0.12), rgba(0,0,0,0.95));
    border-bottom: 1px solid #00ffff;
    font-size: 58px;
    text-shadow: 0 0 18px #00ffff;
}

.video-thumb span {
    display: block;
    margin-top: 15px;
    font-size: 13px;
    letter-spacing: 3px;
    color: #00ffff;
}
        @media only screen and (max-width: 700px) {
    .thumb {
        height: 260px;
    }
}

        .card-body {
            padding: 14px;
        }

        .card h3 {
            margin: 0 0 8px 0;
            font-size: 16px;
            color: #fff;
        }

        .desc {
            white-space: pre-wrap;
            line-height: 1.5;
            opacity: .82;
            font-size: 13px;
            margin-bottom: 10px;
        }

        .meta {
            font-size: 11px;
            opacity: .55;
        }

        .delete-form {
            margin-top: 12px;
        }

        .delete-btn {
            border-color: #ff6060;
            color: #ff6060;
            padding: 8px 11px;
            font-size: 11px;
        }

        .delete-btn:hover {
            background: #ff6060;
            color: #000;
            box-shadow: 0 0 18px #ff6060;
        }

        .empty {
            border: 1px dashed rgba(0,255,255,.45);
            padding: 30px;
            margin-top: 20px;
            text-align: center;
            opacity: .8;
        }

        .lightbox {
            display: none;
            position: fixed;
            inset: 0;
            z-index: 9999;
            background: rgba(0,0,0,.96);
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

        .lightbox.active { display: flex; }

        .lb-content {
            width: min(1100px, 94vw);
            max-height: 88vh;
            text-align: center;
            position: relative;
        }

        .lb-media img, .lb-media video {
            max-width: 100%;
            max-height: 72vh;
            background: #000;
            border: 1px solid rgba(0,255,255,.6);
            box-shadow: 0 0 28px rgba(0,255,255,.3);
        }

        .lb-title {
            margin-top: 12px;
            color: #fff;
            font-size: 18px;
        }

        .lb-desc {
            margin: 8px auto 0 auto;
            max-width: 850px;
            opacity: .78;
            font-size: 13px;
            line-height: 1.45;
            white-space: pre-wrap;
        }

        .lb-close {
            position: fixed;
            top: 14px;
            right: 22px;
            font-size: 42px;
            color: #00ffff;
            cursor: pointer;
            z-index: 10000;
        }

        .lb-nav {
            position: fixed;
            top: 50%;
            transform: translateY(-50%);
            font-size: 45px;
            padding: 10px 18px;
            line-height: 1;
            z-index: 10000;
        }

        .lb-prev { left: 15px; }
        .lb-next { right: 15px; }

        .lb-count {
            position: fixed;
            left: 20px;
            top: 20px;
            font-size: 13px;
            opacity: .8;
        }

        @media (max-width: 850px) {
            .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
            .form-grid { grid-template-columns: 1fr; }
            .thumb { height: 190px; }
        }

        @media (max-width: 560px) {
            .grid { grid-template-columns: 1fr; }
            .hero { padding: 18px; }
            .topbar { align-items: flex-start; }
            .lb-nav {
                top: auto;
                bottom: 25px;
                transform: none;
                font-size: 34px;
            }
            .lb-prev { left: 22px; }
            .lb-next { right: 22px; }
            .lb-media img, .lb-media video { max-height: 62vh; }
        }
    </style>
</head>
<body>
<div class="stars"></div>

<div class="wrap">
    <div class="topbar">
        <a class="cyber-link" href="<?php echo h75_e($backUrl); ?>">⬅ ANA MENÜ</a>
        <div>
            <?php echo h75_e($user['full_name'] ?? $user['username'] ?? 'Kullanıcı'); ?>
            —
            <?php echo h75_e($user['role'] ?? ''); ?>
            &nbsp;
            <a class="cyber-link" href="logout.php">ÇIKIŞ</a>
        </div>
    </div>

    <section class="hero">
        <h1><?php echo h75_e($title); ?></h1>
        <div class="subtitle"><?php echo h75_e($subtitle); ?></div>
    </section>

    <?php if ($flash): ?>
        <div class="flash <?php echo h75_e($flash['type']); ?>">
            <?php echo h75_e($flash['message']); ?>
        </div>
    <?php endif; ?>

    <?php if ($isYonetici): ?>
        <section class="admin-panel">
            <h2>+ YÖNETİCİ İÇERİK EKLEME</h2>
            <form method="post" enctype="multipart/form-data">
                <input type="hidden" name="csrf" value="<?php echo h75_e($csrf); ?>">
                <input type="hidden" name="action" value="add_media">

                <div class="form-grid">
                    <div>
                        <label>Başlık</label>
                        <input type="text" name="title" maxlength="120" placeholder="Örn: 50. Yıl Buluşması">
                    </div>

                    <div>
                        <label>Fotoğraf / Video</label>
                        <input type="file" name="media_file" accept=".jpg,.jpeg,.png,.webp,.gif,.mp4,.webm,.mov,image/*,video/*" required>
                    </div>

                    <div class="full">
                        <label>Açıklama</label>
                        <textarea name="description" maxlength="2000" placeholder="Bu içerikle ilgili kısa not..."></textarea>
                    </div>

                    <div class="full">
                        <button type="submit">YÜKLE</button>
                    </div>
                </div>
            </form>
        </section>
    <?php endif; ?>

    <div class="gallery-info">
        Toplam içerik: <?php echo count($items); ?>
    </div>

    <?php if (!$items): ?>
        <div class="empty">Bu bölümde henüz içerik yok.</div>
    <?php else: ?>
        <section class="grid">
            <?php foreach ($items as $i => $item): ?>
                <article class="card">
                    <div class="thumb" onclick="openLightbox(<?php echo (int)$i; ?>)">
                        <?php if (($item['type'] ?? '') === 'image'): ?>
                            <img src="<?php echo h75_e($item['file']); ?>" alt="<?php echo h75_e($item['title'] ?? ''); ?>">
                        <?php else: ?>
                            <div class="video-thumb">▶<span>VİDEOYU AÇ</span></div>
                        <?php endif; ?>
                    </div>

                    <div class="card-body">
                        <h3><?php echo h75_e($item['title'] ?? 'Başlıksız'); ?></h3>

                        <?php if (!empty($item['description'])): ?>
                            <div class="desc"><?php echo h75_e($item['description']); ?></div>
                        <?php endif; ?>

                        <div class="meta">
                            <?php echo h75_e($item['created_at'] ?? ''); ?>
                            <?php if (!empty($item['uploaded_by'])): ?>
                                · Ekleyen: <?php echo h75_e($item['uploaded_by']); ?>
                            <?php endif; ?>
                        </div>

                        <?php if ($isYonetici): ?>
                            <form class="delete-form" method="post" onsubmit="return confirm('Bu içeriği silmek istediğine emin misin?');">
                                <input type="hidden" name="csrf" value="<?php echo h75_e($csrf); ?>">
                                <input type="hidden" name="action" value="delete_media">
                                <input type="hidden" name="delete_id" value="<?php echo h75_e($item['id'] ?? ''); ?>">
                                <button class="delete-btn" type="submit">SİL</button>
                            </form>
                        <?php endif; ?>
                    </div>
                </article>
            <?php endforeach; ?>
        </section>
    <?php endif; ?>
</div>

<div id="lightbox" class="lightbox">
    <div class="lb-count" id="lbCount"></div>
    <div class="lb-close" onclick="closeLightbox()">×</div>
    <button class="lb-nav lb-prev" onclick="prevLightbox()">‹</button>
    <button class="lb-nav lb-next" onclick="nextLightbox()">›</button>

    <div class="lb-content">
        <div class="lb-media" id="lbMedia"></div>
        <div class="lb-title" id="lbTitle"></div>
        <div class="lb-desc" id="lbDesc"></div>
    </div>
</div>

<script>
    const galleryItems = <?php echo json_encode($items, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>;
    let activeIndex = 0;

    function mediaHtml(item) {
        if (!item) return '';

        if (item.type === 'image') {
            return `<img src="${escapeAttr(item.file)}" alt="${escapeAttr(item.title || '')}">`;
        }

        return `
            <video controls autoplay playsinline preload="metadata">
                <source src="${escapeAttr(item.file)}">
                Tarayıcınız video oynatmayı desteklemiyor.
            </video>
        `;
    }

    function escapeAttr(value) {
        return String(value ?? '')
            .replaceAll('&', '&amp;')
            .replaceAll('"', '&quot;')
            .replaceAll('<', '&lt;')
            .replaceAll('>', '&gt;');
    }

    function escapeText(value) {
        return String(value ?? '')
            .replaceAll('&', '&amp;')
            .replaceAll('<', '&lt;')
            .replaceAll('>', '&gt;');
    }

    function openLightbox(index) {
        if (!galleryItems.length) return;

        activeIndex = index;
        renderLightbox();
        document.getElementById('lightbox').classList.add('active');
        document.body.style.overflow = 'hidden';
    }

    function closeLightbox() {
        document.getElementById('lightbox').classList.remove('active');
        document.getElementById('lbMedia').innerHTML = '';
        document.body.style.overflow = '';
    }

    function nextLightbox() {
        if (!galleryItems.length) return;
        activeIndex = (activeIndex + 1) % galleryItems.length;
        renderLightbox();
    }

    function prevLightbox() {
        if (!galleryItems.length) return;
        activeIndex = (activeIndex - 1 + galleryItems.length) % galleryItems.length;
        renderLightbox();
    }

    function renderLightbox() {
        const item = galleryItems[activeIndex];
        document.getElementById('lbMedia').innerHTML = mediaHtml(item);
        document.getElementById('lbTitle').innerHTML = escapeText(item.title || 'Başlıksız');
        document.getElementById('lbDesc').innerHTML = escapeText(item.description || '');
        document.getElementById('lbCount').innerText = `${activeIndex + 1} / ${galleryItems.length}`;
    }

    document.addEventListener('keydown', function(e) {
        const lb = document.getElementById('lightbox');
        if (!lb.classList.contains('active')) return;

        if (e.key === 'Escape') closeLightbox();
        if (e.key === 'ArrowRight') nextLightbox();
        if (e.key === 'ArrowLeft') prevLightbox();
    });

    document.getElementById('lightbox').addEventListener('click', function(e) {
        if (e.target.id === 'lightbox') closeLightbox();
    });
</script>
</body>
</html>
<?php
}
