<?php

if (isset($_GET['add'])) {
    echo '<form method="post" class="list-group-item-null" action="?">';
    echo lang('Название') . "<br />";
    echo "<input name='name' maxlength='32' required type='text' value='' class='form-control'>";
    echo lang('Иконка') . "<br />";
    echo "<input name='icon' maxlength='32' type='text' value='book' class='form-control'>";
    echo lang('Описание') . "<br />";
    echo "<textarea name='desc' maxlength='100' class='form-control'></textarea>";

    echo "<br /><a href='http://fontawesome.io/icons/'><i class='fa fa-fa fa-fw'></i> <b>" . lang('Список иконок') . "</b></a><br /><br />";

    $doc->Button('btn btn-success btn-sm', 'ok', 'pencil', 'Опубликовать');
    $doc->Link('btn btn-secondary btn-sm', '?', null, 'Отмена');
    echo '</form>';
} else {
    echo "<div class='list-group-item-null'>";
    $doc->Link('btn btn-secondary btn-sm', '?add', 'plus', 'Добавить категорию');
    echo "</div>";
}
if (isset($_GET['edit'])) {
    $q = $db->super_query("SELECT COUNT(*) as count FROM diary_cat WHERE id = '" . intval($_GET['edit']) . "' LIMIT 1");
    if ($q['count'] == 1) {

        $edit = $db->get_row($db->query("SELECT * FROM `diary_cat` WHERE `id` = '" . intval($_GET['edit']) . "' LIMIT 1"));
        echo'<form method="post" class="list-group-item-null" action="?edit=' . $edit['id'] . '">';

        echo lang('Название') . "<br />";
        echo "<input name='name' maxlength='32' required type='text' value='$edit[name]' class='form-control'>";
        echo lang('Иконка') . "<br />";
        echo "<input name='icon' maxlength='32' type='text' value='$edit[icon]' class='form-control'>";
        echo lang('Описание') . "<br />";
        echo "<textarea name='desc' maxlength='100' class='form-control'>$edit[desc]</textarea>";
        echo "<br /><a href='http://fontawesome.io/icons/'><i class='fa fa-fa fa-fw'></i> <b>" . lang('Список иконок') . "</b></a><br /><br />";

        $doc->Button('btn btn-success btn-sm', null, 'save', 'Сохранить');
        $doc->Link('btn btn-secondary btn-sm', '?', null, 'Отмена');
        echo '</form>';
    }
}
