<?php
if(!isset($_POST['action']))
{
echo "<div class=\"form\">\n";
echo "<form method=\"post\" action=\"arnab.php?nocache=$nocache&amp;ver=html&amp;".SID."&amp;pass=$pass&amp;mod=pm2all\">\n";
echo "TO WHOM:<select name=\"who\"><br/>";
 echo "<option value=\"admin\">Admins Only</option>";
   echo "<option value=\"staff\">All Staff</option>";
     echo "<option value=\"all\">All Members</option>";
  echo "</select><br/>";
echo "Title:<br/>\n";
echo "<input name=\"title\" maxlength=\"100\" value=\"\" title=\"text\"/><br/>\n";
echo "Text:<br/>\n";
echo "<input name=\"text\" maxlength=\"300\" value=\"\" title=\"text\"/><br/>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"add\"/>";
echo "<input type=\"submit\" value=\"SEND\"/></form></div><br/>\n";
}
else
{
$title = mysql_real_escape_string($_POST['title']);
$text1 = mysql_real_escape_string($_POST['text']);
$text = "<b>:: Public Announcement :: </b><br/> $text1 <br/><i><b>Note:</b>This Is An Automated PM.No Need To Reply.</i><br/>";
$who = mysql_real_escape_string($_POST['who']);

if ($who == admin){
echo "A PM Has Been Sent To All Admins<br/>";
$pms = mysql_query("SELECT id, name FROM `chat_users` WHERE level>3");
while($pm=mysql_fetch_array($pms))
{
mysql_query("INSERT INTO `chat_letters` VALUES(0, '".$pm[0]."', '".$pm[0]."', '".$id."', '".$title."', '".$text."', '".date("d-m-Y")."', '".time()."', 0);");
}
}
else if ($who == staff){
echo "A PM Has Been Sent To All Staffs<br/>";
$pms = mysql_query("SELECT id, name FROM `chat_users` WHERE level>0");
while($pm=mysql_fetch_array($pms))
{
mysql_query("INSERT INTO `chat_letters` VALUES(0, '".$pm[0]."', '".$pm[0]."', '".$id."', '".$title."', 'Hello $pm[1],".$text."', '".date("d-m-Y")."', '".time()."', 0);");
}
}
else if ($who == all){
$pms = mysql_query("SELECT id, name FROM `chat_users`");
echo "A PM Has Been Sent To All Users<br/>";
while($pm=mysql_fetch_array($pms))
{
mysql_query("INSERT INTO `chat_letters` VALUES(0, '".$pm[0]."', '".$pm[0]."', '".$id."', '".$title."', '".$text."', '".date("d-m-Y")."', '".time()."', 0);");
}
}
}
?>