<?php
if(!isset($_POST['action']))
{
echo "Текст:<br/>\n";
echo "<input name=\"text$nocache\" maxlength=\"300\" value=\"\" title=\"joke\"/><br/>\n";
echo "Транслитировать:<br/>\n";
echo "<select multiple=\"false\" name=\"translit$nocache\" value=\"no\">\n";
echo "<option value=\"no\">Нет</option>\n";
echo "<option value=\"yes\">Да</option></select><br/>\n";
echo "Начертание:<br/>\n";
echo "<select multiple=\"true\" name=\"tt$nocache\">\n";
echo "<option value=\"bold\">Жирный</option>\n";
echo "<option value=\"underline\">Подчеркнутый</option>\n";
echo "<option value=\"italic\">Курсив</option></select><br/>\n";
echo "<anchor>[Добавить]<go href=\"admin.php?nocache=$nocache&amp;ver=wml&amp;".SID."&amp;pass=$pass&amp;mod=announcement\" method=\"post\">\n";
echo "<postfield name=\"text\" value=\"$(text$nocache)\"/>\n";
echo "<postfield name=\"translit\" value=\"$(translit$nocache)\"/>\n";
echo "<postfield name=\"tt\" value=\"$(tt$nocache)\"/>\n";
echo "<postfield name=\"action\" value=\"announcement\"/>\n";
echo "</go></anchor><br/>\n";
}
else
{
$text = htmlspecialchars(mysql_escape_string(trim($_POST['text'])));
$text = str_replace('$', '$$', $text);
$tt = $_POST['tt'];

if($_POST['translit'] == "yes")
{
$lat = array("J", "j", "Zh", "zh", "Ch", "ch", "Ye", "ye", "Yu", "yu", "Ya", "ya", "Shc", "shc", "Sh", "sh", "Yo", "yo", "Q", "q", "'", "A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h", "I", "i", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", "P", "p", "R", "r", "S", "s", "T", "t", "U", "u", "V", "v", "X", "x", "Z", "z");
$rus = array("Й", "й", "Ж", "ж", "Ч", "ч", "Э", "э", "Ю", "ю", "Я", "я", "Щ", "щ", "Ш", "ш", "Ё", "ё", "Ь", "ь", "ъ", "А", "а", "Б", "б", "Ц", "ц", "Д", "д", "Е", "е", "Ф", "ф", "Г", "г", "Х", "х", "И", "и", "К", "к", "Л", "л", "М", "м", "Н", "н", "О", "о", "П", "п", "Р", "р", "С", "с", "Т", "т", "У", "у", "В", "в", "Х", "х", "З", "з");
$text = str_replace($lat, $rus, $text);
}

if(empty($text))
{
echo "Вы не ввели текст!<br/>\n";
break;
}

if(substr_count($tt, "bold") != 0)
{
$text = "<b>$text</b>";
}

if(substr_count($tt, "underline") != 0)
{
$text = "<u>$text</u>";
}

if(substr_count($tt, "italic") != 0)
{
$text = "<i>$text</i>";
}

$q = mysql_query("SELECT `nickname` FROM `chat_users` WHERE `id` = '".$id."';");
$nickname = mysql_result($q, 0);
$time = date("H:i:s");

$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, '".date("H:i")."', ".time().",0);");
}

echo "Объявление успешно добавлено в чат!<br/>\n";
}
?>