<?
$page = "admin_broadcast.php";
include "admin_header.php";
if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "main"; }




if($task == "dopost") {
$title = str_replace("<", "&lt;", str_replace(">", "&gt;", str_replace("'", "&#39;", $_POST['title'])));
$contents = str_replace("'", "&#39;", $_POST['contents']);

$hour = $_POST['hour'];
$minute = $_POST['minute'];
$ampm = $_POST['ampm'];
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];

$date = strtotime("$hour:$minute $ampm $month $day $year");

$draft = "0";
$privacy = "3";
$comments = "1";

$weblogs = mysql_query("SELECT w_id, u_id FROM bhost_weblogs");
while($weblog = mysql_fetch_assoc($weblogs)) {
mysql_query("INSERT INTO bhost_entries (w_id, author_u_id, title, contents, draft, privacy, date, comments) VALUES ('$weblog[w_id]', '$weblog[u_id]', '$title', '$contents', '$draft', '$privacy', '$date', '$comments')");
mysql_query("UPDATE bhost_users SET num_entries=num_entries+1 WHERE u_id='$weblog[u_id]'");
mysql_query("UPDATE bhost_weblogs SET num_entries=num_entries+1 WHERE w_id='$weblog[w_id]'");
}


echo $head;
echo "
<h2>$admin_broadcast6</h2>
$admin_broadcast7
<br><br>
<form action='admin_broadcast.php' method='POST'>
<input type='submit' class='button' value='$admin_broadcast8'>
</form>
";
echo $foot;
exit();
}









if($task == "main") {
$thism = cdate("n", time());
$thisd = cdate("j", time());
$thisy = cdate("Y", time());
$thishour = cdate("g", time()); 
$thismin = cdate("i", time()); 
$thisampm = cdate("A", time()); 

echo $head;
echo "
<h2>$admin_broadcast1</h2>
$admin_broadcast2
<br><br>
<form action='admin_broadcast.php' method='POST'>
<table width='100%' cellpadding='5' cellspacing='0'>
<tr>
<td>
  <table cellpadding='0' cellspacing='0'>
  <tr>
  <td NOWRAP><b>$admin_broadcast3</b> &nbsp;</td>
  <td><input type='text' size='50' name='title' maxlength='250'></td>
  </tr>
  </table>
</td>
</tr>
<tr>
<td>
<textarea name='contents' rows='8' cols='60' style='width: 100%;'></textarea>
</td>
</tr>
<tr>
<td>
  <table cellpadding='0' cellspacing='0'>
  <tr>
  <td NOWRAP><b>$admin_broadcast4</b> &nbsp;<td>
  <td>
";


// HOUR BOX
$c = 0;
echo "<select name='hour'>";
while($c < 12) {
$c++;
echo "<option value='$c'"; if($thishour == $c) { echo " SELECTED"; } echo ">$c</option>";
}
echo "</select>";


echo "
  </td>
  <td>&nbsp;<img src='../images/colon.gif' border='0'>
";


// MINUTE BOX
$c = -1;
echo "<select name='minute'>";
while($c < 59) {
$z = "";
$c++;
if($c < 10) { $z = "0"; } else { $z = ""; }
echo "<option value='$c'"; if($thismin == "$z$c") { echo " SELECTED"; } echo ">".$z."$c</option>";
}
echo "</select>";


echo "
  </td>
  <td>
&nbsp;<select name='ampm'>
<option value='AM'"; if($thisampm == "AM") { echo " SELECTED"; } echo ">AM</option>
<option value='PM'"; if($thisampm == "PM") { echo " SELECTED"; } echo ">PM</option>
</select>&nbsp;&nbsp;
  </td>
  <td>
  </td>
  <td>&nbsp;
<select name='month'>
<option value='Jan'"; if($thism == "1") { echo " SELECTED"; } echo ">Jan</option>
<option value='Feb'"; if($thism == "2") { echo " SELECTED"; } echo ">Feb</option>
<option value='Mar'"; if($thism == "3") { echo " SELECTED"; } echo ">Mar</option>
<option value='Apr'"; if($thism == "4") { echo " SELECTED"; } echo ">Apr</option>
<option value='May'"; if($thism == "5") { echo " SELECTED"; } echo ">May</option>
<option value='Jun'"; if($thism == "6") { echo " SELECTED"; } echo ">Jun</option>
<option value='Jul'"; if($thism == "7") { echo " SELECTED"; } echo ">Jul</option>
<option value='Aug'"; if($thism == "8") { echo " SELECTED"; } echo ">Aug</option>
<option value='Sep'"; if($thism == "9") { echo " SELECTED"; } echo ">Sep</option>
<option value='Oct'"; if($thism == "10") { echo " SELECTED"; } echo ">Oct</option>
<option value='Nov'"; if($thism == "11") { echo " SELECTED"; } echo ">Nov</option>
<option value='Dec'"; if($thism == "12") { echo " SELECTED"; } echo ">Dec</option>
</select>
  </td>
  <td>
";


// DAY BOX
$c = 0;
echo "&nbsp;<select name='day'>";
while($c < 31) {
$c++;
echo "<option value='$c'"; if($thisd == $c) { echo " SELECTED"; } echo ">$c</option>";
}
echo "</select>";


echo "
  </td>
  <td>
";


// YEAR BOX
$c = 1999;
echo "&nbsp;<select name='year'>";
while($c < 2020) {
$c++;
echo "<option value='$c'"; if($thisy == $c) { echo " SELECTED"; } echo ">$c</option>";
}
echo "</select>";


echo "
  </td>
  </tr>
  </table>
</td>
</tr>
<tr>
<td colspan='2'>
<input type='submit' class='button' value='$admin_broadcast5'>
<input type='hidden' name='task' value='dopost'>
</td>
</form>
</tr>
</table>
";

echo $foot;
}
?>