<?php
declare(strict_types=1);

/**
ET-Chat Copyright by SEDesign | ET-Chat v3.x.x Lizenz: CCPL | Autor: Evgeni Tcherkasski (info@s-e-d.de)
ET-Chat_T-FISH-MOD Weiterentwicklungen, Optimierungen und Ergänzungen am Code sind das geistige Eigentum von Tommy (Thomas Kuhn) und Harlekin (Bernd Witte).

Die darauf folgende Optimierungen und Ergänzungen am Code sind das Geistige Eigentum von Powermen (Christian K.)
und wird unter der Namenserweiterung M.C.v.x.x.x. geführt. 
PHP 8/9 Ready, XML Parser, PDO Prepared Statements Get Set sicherheit usw.
 */

$csrf = (string)($_SESSION['etchat_' . $this->_prefix . 'csrf_token'] ?? '');

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

ob_start();
?>

<p>
    URL Code für Popup-Link:<br>
    <small>
        #" onclick="window.open('http://DEIN_LINK','','toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=900,height=600'); return false;
    </small>
</p>

<hr>

<?php if (!empty($feld) && is_array($feld)): 

    $id       = (int)($feld[0][0] ?? 0);
    $menu     = (int)($feld[0][1] ?? 1);
    $text     = $feld[0][2] ?? '';
    $imageOn  = (int)($feld[0][3] ?? 0);
    $image    = $feld[0][4] ?? '';
    $url      = $feld[0][5] ?? '';
    $target   = $feld[0][6] ?? '_blank';
    $gewicht  = (int)($feld[0][7] ?? 1);

    $menuMap = [
        1 => 'Chat',
        2 => 'Index',
        3 => 'Banner'
    ];
?>

<form method="post" action="./?AdminUpdateMenu" class="user-form">

    <input type="hidden" name="id" value="<?= $id ?>">
    <input type="hidden" name="csrf_token" value="<?= $csrf ?>">

    <label for="menu">Menü:</label>
    <select name="menu" id="menu">
        <?php foreach ($menuMap as $key => $label): ?>
            <option value="<?= $key ?>" <?= $menu === $key ? 'selected' : '' ?>>
                <?= e($label) ?>
            </option>
        <?php endforeach; ?>
    </select>

    <label for="gewicht">Gewichtung:</label>
    <input 
        type="number" 
        id="gewicht"
        name="gewicht" 
        min="1" 
        max="999" 
        value="<?= $gewicht ?>"
    >

    <label for="link_text">Link Name:</label>
    <input 
        type="text" 
        id="link_text"
        name="link_text" 
        value="<?= e($text) ?>"
    >

    <label for="image_active">Image:</label>
    <select name="image_active" id="image_active">
        <option value="1" <?= $imageOn === 1 ? 'selected' : '' ?>>Bild an</option>
        <option value="0" <?= $imageOn === 0 ? 'selected' : '' ?>>Bild aus</option>
    </select>

    <label for="image">Dateiname PIC:</label>
    <input 
        type="text" 
        id="image"
        name="image" 
        value="<?= e($image) ?>"
    >
    <small>(liegt in /img/menu)</small>

    <label for="url">URL:</label>
    <textarea name="url" id="url" class="admin-textarea-medium"><?= e($url) ?></textarea>

    <label for="target">Ziel Fenster:</label>
    <select name="target" id="target">
        <option value="_blank" <?= $target === '_blank' ? 'selected' : '' ?>>Neues Fenster</option>
        <option value="_top" <?= $target === '_top' ? 'selected' : '' ?>>Selbes Fenster</option>
    </select>

    <button type="submit">Speichern</button>

</form>

<?php endif; ?>

<?php
$content = ob_get_clean();

$pageTitle  = 'Menü bearbeiten';
$backLink   = './?AdminMenusIndex';
$footerNote = $lang->note[0]->tagData ?? '';

include __DIR__ . '/admin_master_template.php';