<?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 length='32' type='text' value='' class='form-control'>";
    echo lang('Описание') . "<br />";
    echo "<textarea name='desc' maxlength='100' length='100' class='form-control'></textarea>";

    echo '<br/>';
    $doc->Button('btn btn-success btn-sm', 'ok', 'pencil', 'Опубликовать');
    $doc->Link('btn btn-secondary btn-sm', '?', null, 'Отмена');
    echo '</form>';
} else {
    $doc->Link('list-group-item-null list-group-item-grey', '?add', 'plus', 'Добавить категорию');
}
if (isset($_GET['edit']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `diary_cat` WHERE `id` = '" . intval($_GET['edit']) . "' LIMIT 1"), 0) == 1) {
    $edit = mysql_fetch_assoc(mysql_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 length='32' type='text' value='$edit[name]' class='form-control'>";
    echo lang('Описание') . "<br />";
    echo "<textarea name='desc' maxlength='100' length='100' class='form-control'>$edit[desc]</textarea>";

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