View file panel/blogs.php

File size: 2.71Kb
<?php
// by Mike O. (mides), coolcms.org
require_once '../includes/sys.php';
require_once '../includes/auth_a.php';
require_once '../includes/header.php';

if (!access(3)) {
    redirect(HTTPHOME);
}

switch ($act) {
    default:
        tp('<a href="./">АДМ</a>&raquo; '.$lang['Blogs_categories']);
		echo '<div class="body">';
        note();
        $cats_r = mysql_query("SELECT * FROM `blogs_cats` ORDER BY `name`");
        while ($cat = mysql_fetch_assoc($cats_r)) {
                echo '<a href="../blogs.php?act=cat&amp;id='.$cat['id'].'">'.$cat['name'].'</a> (<a href="?act=cat_edit&amp;id='.$cat['id'].'">ред</a>)<br />';
        }
        echo '<br /><form name="form" action="?act=cat_add" method="post" name="form">
        '.$lang['Category_name'].':<br/><input name="name" type="text" maxlength="50" /><br />
        <input name="submit" type="submit" value="OK"></form>';
        nav('./');
    break;

    case 'cat_add':
        if ($_POST['name']) {
            $name = check($_POST['name']);
            mysql_query("INSERT INTO `blogs_cats` SET `name` = '$name'");
        }
        redirect('?');
    break;

    case 'cat_edit':
        $cat = mysql_fetch_assoc(mysql_query("SELECT * FROM `blogs_cats` WHERE `id` = '$id'"));
        if ($cat['id']) {
            if ($ok) {
                if ($_POST['del']) {
                    mysql_query("DELETE FROM `blogs` WHERE `id_cat` = '$id'");
                    mysql_query("DELETE FROM `blogs_cats` WHERE `id` = '$id'");
                    redirect('?');
                } else {
                    if ($_POST['name']) {
                        $name = check($_POST['name']);
                        mysql_query("UPDATE `blogs_cats` SET `name` = '$name' WHERE `id` = '$id'");
                        $_SESSION['note'] = $lang['all_changes_saved'];
                        redirect('?');
                    } else {
                        redirect('?act=cat_edit&id='.$id);
                    }
                }
            } else {
                tp($lang['Edit_cat']);
				echo '<div class="body">';
                echo '<form name="form" action="?act=cat_edit&amp;id='.$id.'&amp;ok=1" method="post">
                '.$lang['name'].':<br /><input name="name" type="text" maxlength="50" value="'.$cat['name'].'" /><br />
                <input name="del" type="checkbox" value="1" /> '.$lang['delete'].' ('.$lang['all_notes_related_to_the_category_will_be_deleted_as_well'].')<br />
                <input name="submit" type="submit" value="Ok" />
                </form>';
            }
        } else {
            redirect('?');
        }
        nav('?');
    break;
		
}

require_once '../includes/tail.php';
?>