<?php
if(!isset($_POST['action']))
{
echo "<div class=\"form\">\n";
echo "<form method=\"post\" action=\"admin.php?nocache=$nocache&amp;ver=html&amp;".SID."&amp;pass=$pass&amp;mod=announcement\">\n";
echo "Text:<br/>\n";
echo "<input name=\"text\" maxlength=\"300\" value=\"\" title=\"text\"/><br/>\n";

echo "Select:<br/>\n";
echo "Bold: <input type=\"checkbox\" name=\"bold\" value=\"true\" checked=\"true\"/><br/>\n";
echo "Underline: <input type=\"checkbox\" name=\"underline\" value=\"true\"/><br/>\n";
echo "Italic: <input type=\"checkbox\" name=\"italic\" value=\"true\"/><br/>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"add\"/>";
echo "<input type=\"submit\" value=\"Add\"/></form></div><br/>\n";
}
else
{
$text = htmlspecialchars(mysql_escape_string(trim($_POST['text'])));
$text = str_replace('$', '$$', $text);
$bold = $_POST['bold'];
$underline = $_POST['underline'];
$italic = $_POST['italic'];



if(empty($text))
{
echo "Empty text!<br/>\n";
break;
}

if($bold == "true")
{
$text = "<b>$text</b>";
}

if($underline == "true")
{
$text = "<u>$text</u>";
}

if($italic == "true")
{
$text = "<i>$text</i>";
}

$q = mysql_query("SELECT `id` FROM `chat_rooms`;");
while($rid = mysql_fetch_array($q))
{
$room = $rid['id'];
mysql_query("INSERT INTO `chat".$room."` VALUES(0, ".$id.", '".$nickname."', '".$text."', 0, '".$time."', ".time().");");
}

echo "The announcement successfully added to chat!<br/>\n";
}
?>