<?php
echo '<h1>Kalender-Einstellungen</h1>';
if (isset($_POST['submit'])) {
    echo '<div id="bdp_success">Die Einstellungen wurden gespeichert.</div>';
    update_option('bdp_calendar_categories', json_encode($_POST['category']));
    update_option('bdp_calendar_source_url', $_POST['ical_url']);
}

$categories =  get_option('bdp_calendar_categories', null);
if (null !== $categories) {
    $categories = json_decode($categories, true);
} else {
    $categories = [
        'yellow' => 'Meute',
        'blue'  => 'Sippe',
        'red' => 'Runde',
        'green' => 'Stammesführung',
        'fuchsia' => '',
        'orange' => ''
    ];
}
?>
<form method="post" action="admin.php?page=bdp-kompass%2Fmodules%2Findex.php&loadmodule=calendar">
        <fieldset class="bdp_cal_inner">
            <legend>Datenabfrage</legend>

            <table>
                <tr style="vertical-align: top;">
                    <td>Kalender-URL:</td>
                    <td><input class="long_text" type="text" name="ical_url" id="ical_url" required
                               value = "<?php echo get_option('bdp_calendar_source_url', ''); ?>"
                        ><br />
                        <label style="font-weight: normal; color: #a0a0a0; font-style: italic">
                            Bitte gib hier die URL zur .ics - Datei eures Kalenbders im Wiki ein.
                        </label>
                    </td>
                </tr>
            </table>
        </fieldset>

        <fieldset class="bdp_cal_inner">
            <legend>Labels</legend>
            <table>
                <tr>
                    <td>Gelb:</td>
                    <td><input type="text" name="category[yellow]" value="<?php echo $categories['yellow']; ?>" /></td>
                    <td class="bdp_cal_event_yellow"></td>
                </tr>

                <tr>
                    <td>Blau:</td>
                    <td><input type="text" name="category[blue]" value="<?php echo $categories['blue']; ?>" /></td>
                    <td class="bdp_cal_event_blue"></td>
                </tr>

                <tr>
                    <td>Rot:</td>
                    <td><input type="text" name="category[red]" value="<?php echo $categories['red']; ?>" /></td>
                    <td class="bdp_cal_event_red"></td>
                </tr>

                <tr>
                    <td>Grün:</td>
                    <td><input type="text" name="category[green]" value="<?php echo $categories['green']; ?>" /></td>
                    <td class="bdp_cal_event_green"></td>
                </tr>

                <tr>
                    <td>Fuchsia:</td>
                    <td><input type="text" name="category[fuchsia]" value="<?php echo $categories['fuchsia']; ?>" /></td>
                    <td class="bdp_cal_event_fuchsia"></td>
                </tr>

                <tr>
                    <td>Orange:</td>
                    <td><input type="text" name="category[orange]" value="<?php echo $categories['orange']; ?>" /></td>
                    <td class="bdp_cal_event_orange"></td>
                </tr>
                <tr>
                    <td>Grau:</td>
                    <td>Standard</td>
                    <td class="bdp_cal_event_grey"></td>
                </tr>
            </table>
    <input class="button" type="submit" name="submit" value="Einstellungen speichern">
</form>
