<?php
$room = intval($_POST['room']);
$q = mysql_query("SELECT `id` FROM `chat_rooms` WHERE `id` = '".$room."';");
if(mysql_num_rows($q) == 0)
{
echo "room does not exist.<br/>\n";
break;
}
$name = trim(mysql_escape_string(htmlspecialchars($_POST['name'])));
$name = str_replace('$', '$$', $name);
$topic = trim(mysql_escape_string(htmlspecialchars($_POST['topic'])));
$topic = str_replace('$', '$$', $topic);


if(empty($name))
{
echo "Empty name!<br/>\n";
break;
}
$query = mysql_query("SELECT `id` FROM `chat_rooms` WHERE `name` = '".$name."' AND `id` != '".$room."';");

if(mysql_num_rows($query) != 0)
{
echo "A room with the same name already exist!<br/>\n";
break;
}

if(empty($topic))
{
$topic = $name;
}
$position = intval($_POST['position']);
if($postion < 0) $postion = 0;
if($postion > 100) $postion = 100;
$type = intval($_POST['type']);
if($type < 0) $type = 0;
if($type > 2) $type = 0;
$q = mysql_query("UPDATE `chat_rooms` SET `name` = '".$name."', `position` = '".$position."', `topic` = '".$topic."', `type` = '".$type."' WHERE `id` = '".$room."';");
echo "Settings rooms reserved!<br/>\n";
?>