Файл: spuff.ru/panel/forum.php
Строк: 74
<?php
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>» '.$lang['forum']);
$cats_r = mysql_query("SELECT * FROM `forum_cats` ORDER BY `order`, `name`");
while ($cat = mysql_fetch_assoc($cats_r)) {
echo '<div class="rega"><a href="/forum/?act=cat&id='.$cat['id'].'">'.$cat['name'].'</a> (<a href="?act=cat_edit&id='.$cat['id'].'">ред</a>)</div>';
$subcats_r = mysql_query("SELECT * FROM `forum_subcats` WHERE `id_cat` = '$cat[id]' ORDER BY `order`, `name`");
while ($subcat = mysql_fetch_assoc($subcats_r)) {
echo '<div class="raz">» <a href="/forum/?act=subcat&id='.$subcat['id'].'">'.$subcat['name'].'</a> (<a href="?act=subcat_edit&id='.$subcat['id'].'">ред</a>)</div>';
}
}
echo '<div class="title">Создать</div><div class="body">
<form name="form" action="?act=cat_add" method="post" name="form">
<select name="cat">
<option value="0">Главная</option>';
$cats_r = mysql_query("SELECT * FROM `forum_cats` ORDER BY `order`");
while ($cat = mysql_fetch_assoc($cats_r)) {
echo '<option value="'.$cat['id'].'">'.$cat['name'].'</option>';
}
echo '</select><br />
Название (под)раздела:<br/><input name="name" type="text" maxlength="100" /><br />
<input name="submit" type="submit" value="Создать"></form></div>';
break;
case 'cat_add':
if ($_POST['name']) {
$cat = intval($_POST['cat']);
$name = check($_POST['name']);
if ($cat > 0) {
mysql_query("INSERT INTO `forum_subcats` SET `id_cat` = '$cat', `name` = '$name'");
} else {
mysql_query("INSERT INTO `forum_cats` SET `name` = '$name'");
}
}
redirect('?');
break;
case 'cat_edit':
$id = abs(intval($_GET['id']));
$cat = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_cats` WHERE `id` = '$id'"));
if ($cat['id']) {
if ($ok) {
if ($_POST['del']) {
$forum_subcat_r = mysql_query("SELECT `id` FROM `forum_subcats` WHERE `id_cat` = '$id'");
if (!mysql_num_rows($forum_subcat_r)) {
mysql_query("DELETE FROM `forum_cats` WHERE `id` = '$id'");
redirect('?');
} else {
error($lang['Delete_all_subcats_first']);
}
} else {
if ($_POST['name']) {
$name = check($_POST['name']);
mysql_query("UPDATE `forum_cats` SET `name` = '$name' WHERE `id` = '$id'");
redirect('?');
} else {
redirect('?act=cat_edit&id='.$id);
}
}
} else {
tp('<a href="?">Форум</a>» Ред-е названия');
echo '<div class="body"><form name="form" action="?act=cat_edit&id='.$id.'&ok=1" method="post">
Имя:<br /><input name="name" type="text" value="'.$cat['name'].'" /><br />
Удалить: <input name="del" type="checkbox" value="1" /><br />
<input name="submit" type="submit" value="Ok" />
</form></div>';
}
} else {
redirect('?');
}
break;
case 'subcat_edit':
$id = abs(intval($_GET['id']));
$subcat = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_subcats` WHERE `id` = '$id'"));
if ($subcat['id']) {
if ($ok) {
if ($_POST['del']) {
$forum_msg_r = mysql_query("SELECT `id` FROM `forum_msg` WHERE `id_subcat` = '$id'");
while ($forum_msg = mysql_fetch_assoc($forum_msg_r) ) {
mysql_query("DELETE FROM `voting` WHERE `type` = 'forum' and `id_for` = '$forum_msg[id]'");
}
mysql_query("DELETE FROM `forum_topics` WHERE `id_subcat` = '$id'");
mysql_query("DELETE FROM `forum_msg` WHERE `id_subcat` = '$id'");
mysql_query("DELETE FROM `forum_subcats` WHERE `id` = '$id'");
redirect('?');
} else {
if ($_POST['name']) {
$name = check($_POST['name']);
mysql_query("UPDATE `forum_subcats` SET `name` = '$name' WHERE `id` = '$id'");
redirect('?');
} else {
redirect('?act=subcat_edit&id='.$id);
}
}
} else {
tp('Редактировать');
echo '<div class="body"><form name="form" action="?act=subcat_edit&id='.$id.'&ok=1" method="post">
Имя:<br /><input name="name" type="text" maxlength="50" value="'.$subcat['name'].'" /><br />
Удалить: <input name="del" type="checkbox" value="1" /><br />
<input name="submit" type="submit" value="Ok" />
</form></div>';
}
} else {
redirect('?');
}
break;
}
require_once '../includes/tail.php';
?>