<?php

require '../system/start.php';
require '../system/functions.php';
only_level(3);
$str['mesto'] = 'Сообщества';
$str['block'] = $set['site'].' / Панель управления / Сообщества';
include '../style/'.$style.'/head.php';
switch($act)
{
	default:
	echo '<div class="where"><a href="community.php?act=add">Добавить</a></div>';
	$query = mysql_query("select * from `community_selections` order by `id`");
    if(mysql_num_rows($query) == 0)
    {
        echo '<div class="forum1">Разделы еще не созданы!</div>';
    }
    else
    {
	   while($row = mysql_fetch_assoc($query))
	   {
		echo '<div class="on">'.$row['title'].'<br /><a href="community.php?act=edit&amp;id='.$row['id'].'">[ред]</a> <a href="community.php?act=delete&amp;id='.$row['id'].'">[удл]</a></div>';
	   }
    }
	break;
	case 'add':
	if(isset($_POST['title']) && !empty($_POST['title']))
	{
		mysql_query ("INSERT INTO `community_selections` (title) VALUES ('".protect($_POST['title'])."')");
		echo '<div class="where">Раздел успешно создан!</div>';
	}
	echo '<div class="on"><form method="post" action="community.php?act=add">
	<div>
	Название:<br />
	<input type="text" name="title" maxlength="32" value="" /><br />
	<input type="submit" value="Добавить" />
	</div></form></div><div class="where"><a href="index.php">Админ-панель</a></div>';
	break;
	case 'edit':
	$query = mysql_fetch_assoc(mysql_query("select * from `community_selections` where `id` = ".int($_GET['id']).""));
	if(empty($query['title']))
	{
		echo '<div class="on">Раздел не найден!</div>';
		include '../style/'.$style.'/foot.php';
		exit;
	}
	if(isset($_POST['title']) && !empty($_POST['title']))
	{
		mysql_query ("UPDATE `community_selections` SET `title` = '".protect($_POST['title'])."' WHERE `id` = ".$query['id']."");
		echo '<div class="on">Раздел успешно обновлен!</div>
		<div class="where"><a href="index.php">Админ-панель</a></div>';
		include '../style/'.$style.'/foot.php';
		exit;
	}
	echo '<div class="on"><form method="post" action="community.php?act=edit&amp;id='.$query['id'].'">
	<div>
	Название:<br />
	<input type="text" name="title" maxlength="32" value="'.$query['title'].'" /><br />
	<input type="submit" value="Обновить" />
	</div></form></div><div class="where"><a href="index.php">Админ-панель</a></div>';
	break;
	case 'delete':
	$query = mysql_fetch_assoc(mysql_query("select * from `community_selections` where `id` = ".int($_GET['id']).""));
	if(empty($query['title']))
	{
		echo '<div class="on">Раздел не найден!</div>';
		include '../style/'.$style.'/foot.php';
		exit;
	}
	mysql_query ("DELETE FROM `community_selections` WHERE `id` = ".$query['id']."");
	echo '<div class="on">Комната успешно удалена!</div>
	<div class="where"><a href="index.php">Админ-панель</a></div>';
	break;
}
include '../style/'.$style.'/foot.php';
?>