<?
if ($user['level']>2 && isset($_GET['set']) && is_numeric($_GET['set']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_rooms` WHERE `id` = '".intval($_GET['set'])."'"),0)==1)
{

$room=mysql_fetch_array(mysql_query("SELECT * FROM `chat_rooms` WHERE `id` = '".intval($_GET['set'])."' LIMIT 1"));

echo "<form class=\"foot\" action=\"?set=$room[id]&amp;ok\" method=\"post\">";
echo "Название комнаты:<br />\n";
echo "<input type='text' name='name' value='$room[name]' /><br />\n";

echo "Позиция:<br />\n";
echo "<input type='text' name='pos' value='$room[pos]' /><br />\n";


echo "Описание:<br />\n";
echo "<input type='text' name='opis' value='$room[opis]' /><br />\n";

echo "Боты:<br />\n<select name=\"bots\">\n";
if ($room['umnik']==0 && $room['shutnik']==0)$sel=' selected="selected"';else $sel=NULL;
echo "<option value='0'$sel>Нет</option>\n";
if ($room['umnik']==1 && $room['shutnik']==0)$sel=' selected="selected"';else $sel=NULL;
echo "<option value='1'$sel>Умник</option>\n";
if ($room['umnik']==0 && $room['shutnik']==1)$sel=' selected="selected"';else $sel=NULL;
echo "<option value='2'$sel>Шутник</option>\n";
if ($room['umnik']==1 && $room['shutnik']==1)$sel=' selected="selected"';else $sel=NULL;
echo "<option value='3'$sel>Умник и шутник</option>\n";
if ($room['umnik']==0 && $room['shutnik']==0 && $room['anagrama']==1)$sel=' selected="selected"';else $sel=NULL;
echo "<option value='4'$sel>Анаграмма</option>\n";
echo "</select><br />\n";

echo "<input class=\"submit\" type=\"submit\" value=\"Применить\" /><br />\n";
echo "<a href=\"?delete=$room[id]\">Удалить</a><br />\n";
echo "<a href=\"?\">Отмена</a><br />\n";
echo "</form>";
}

if (isset($_GET['act']) && $_GET['act']=='create')
{

echo "<div class=\"err\">";

echo "Очистить чат?<br />\n";
echo "<a href=\"?act=create2\">Да</a> \n";
echo "<a href=\"?\">Нет</a><br />\n";
echo "</div>";
}

if ($user['level']>2 && (isset($_GET['act']) && $_GET['act']=='add_room' || mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_rooms`"),0)==0))
{
echo "<form class=\"foot\" action=\"?act=add_room&amp;ok\" method=\"post\">";
echo "Название комнаты:<br />\n";
echo "<input type='text' name='name' value='' /><br />\n";

$pos=mysql_result(mysql_query("SELECT MAX(`pos`) FROM `chat_rooms`"), 0)+1;
echo "Позиция:<br />\n";
echo "<input type='text' name='pos' value='$pos' /><br />\n";


echo "Описание:<br />\n";
echo "<input type='text' name='opis' value='' /><br />\n";

echo "Боты:<br />\n<select name=\"bots\">\n";

echo "<option value='0'>Нет</option>\n";
echo "<option value='1'>Умник</option>\n";
echo "<option value='2'>Шутник</option>\n";
echo "<option value='3'>Умник и шутник</option>\n";
echo "<option value='4'>Анаграмма</option>\n";
echo "</select><br />\n";

echo "<input class=\"submit\" type=\"submit\" value=\"Создать комнату\" /><br />\n";
echo "&laquo;<a href=\"?\">Отмена</a><br />\n";
echo "</form>";
}

echo "<div class=\"foot\">\n";
echo "&raquo;<a href=\"?act=create\">Очистить чат от сообщений</a><br />\n";
if ($user['level']>2 && mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_rooms`"),0)>0)
echo "&raquo;<a href=\"?act=add_room\">Создать комнату</a><br />\n";
echo "</div>\n";
?>