<?php

include '../system/sys.php';
include '../system/funcs.php';

if (!isset ($us)) {
        header ('location: /');
        exit;
}

if ($us['level']<4) {
        header ('location: /adm/');
        exit;
}

switch ($_GET['mod']) {

        default:
        H ('Загруз-центр', 'Загруз-центр');
        
        $query = DB :: $dbs -> query ("SELECT * FROM `zc_kat` ORDER BY `id`");
        while ($kat = $query -> fetch()) {
                echo '<a href="/adm/zc.php?mod=kat&id=' . $kat['id'] . '"><b>' . $kat['name'] . '</b></a><br/>';

                if (DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `zc_pk` WHERE (`id_kat`='" . $kat['id'] . "')") != 0) {
                        $q = DB :: $dbs -> query ("SELECT * FROM `zc_pk` WHERE (`id_kat`='" . $kat['id'] . "') ORDER BY `id`");
                        while ($pk = $q -> fetch ()) {
                                echo '- <a href="/adm/zc.php?mod=pk&id=' . $pk['id'] . '&kat=' . $kat['id'] . '">' . $pk['name'] . '</a><br/>';
                        }
                }

        }
        
        echo '<div class="list1"><a href="/adm/zc.php?mod=add_kat">Добавить раздел</a></div>';
        
        break;
        case add_kat:
H ('Добавления разделв');
 echo '
        <div class="list1">
                <form action="/adm/zc.php?mod=add_kat&id=' . $k['id'] . '&add" method="post">
                        Название подаздела:<br/>
                        <input name="name"/><br/>
Описание:</br>
                        <input name="opis"/><br/>
                        <input type="submit" value="Добавить"/>
                </form>   
        </div>
        ';
        
        if (isset ($_GET['add'])) {
                $_POST['name'] = htmlspecialchars (addslashes (trim ($_POST['name'])));
                if (empty ($_POST['name'])) {
                        echo '
                        <div class="list1">
                                <b>Вы не ввели название раздела..</b>
                        </div>
                        ';
                }
                else {
                        DB :: $dbs -> query ("INSERT INTO `zc_kat` (`id_k`, `name`) VALUES ('" . $k'id'] . "', ?)", array ($_POST['name']));
                        header('location: /adm/zc.php');
                }
        }

        
        break;
        
}

F ();

?>