File size: 2.07Kb
<?php
// by mides, 1da.su
require_once '../system/sys.php';
require_once '../system/auth_a.php';
require_once '../system/header.php';
if ($u['access'] < 3) header('location: ../');
switch ($_GET['act']) {
default:
tp('Раздела блогов');
$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&id='.$cat['id'].'">'.$cat['name'].'</a> (<a href="?act=cat_edit&id='.$cat['id'].'">ред</a>)<br />';
}
echo '<br /><form action="?act=cat_add" method="post" name="form">
Название раздела:<br/><input name="name" type="text" maxlength="50" /><br />
<input name="submit" type="submit" value="Добавить"></form>';
nav('./');
break;
case 'cat_add':
if ($_POST['name']) {
$name = check($_POST['name']);
mysql_query("INSERT INTO `blogs_cats` SET `name` = '$name'");
}
header('location: ?');
break;
case 'cat_edit':
$id = intval($_REQUEST['id']);
$cat = mysql_fetch_assoc(mysql_query("SELECT * FROM `blogs_cats` WHERE `id` = '$id'"));
if ($cat['id']) {
if ($_REQUEST['ok']) {
if ($_POST['del']) {
mysql_query("DELETE FROM `blogs_cats` WHERE `id` = '$id'");
header('location: ?');
} else {
if ($_POST['name']) {
$name = check($_POST['name']);
mysql_query("UPDATE `blogs_cats` SET `name` = '$name' WHERE `id` = '$id'");
header('location: ?');
} else {
header('location: ?act=cat_edit&id='.$id);
}
}
} else {
tp('Редактировать раздел');
echo '<form action="?act=cat_edit&id='.$id.'&ok=1" method="post">
Название:<br /><input name="name" type="text" maxlength="50" value="'.$cat['name'].'" /><br />
<input name="del" type="checkbox" value="1" /> удалить<br />
<input name="submit" type="submit" value="Ok" />
</form>';
}
} else {
error('Раздел не существует.');
}
nav('?');
break;
}
require_once '../system/tail_p.php';
?>