<?
require "include/bittorrent.php";

dbconn();

loggedinorreturn();

if (get_user_class() < UC_ADMINISTRATOR)stderr("Error", "Access denied.");

stdhead("Mass Mail");

if ($_POST['message'] != "")
{
	$num=0;
	foreach( array_keys($_POST) as $x)
	{ 
		if (substr($x,0,3) == "UC_")
		{  
			$querystring .= " OR class = ".constant($x);  
			$classnames .= substr($x,3).", ";  $num++; 
		}
	} 
	$res = mysql_query("SELECT id, username, email FROM users WHERE id = 1".
	$querystring) or sqlerr(__FILE__, __LINE__); 
	$from_email = "noreply@armyofhell.ath.cx"; //site email  
       $subject = substr(trim($_POST["subject"]), 0, 80); 
	if ($subject == "") $subject = "(No subject)"; 
	$subject = "Fw: $subject";  
	$msg = trim($_POST["message"]); 
	while($arr = mysql_fetch_array($res))
		{ 
 		$to = $arr[email]; 
		$message = $msg;
		$success = mail($to, $subject, $message, "From: noreply@armyofhell.ath.cx", "-f noreply@armyofhell.ath.cx");
	
 		}
	print("<b>Mass Mail succesfully sent.</b><br>");
}
?>
				
<h1>Massen E@Mail</h1><form method=post action="massmail.php"><table border=1 cellspacing=0 cellpadding=5 class="tablea" ><tr><td colspan=2 class="menu_clear_staff" height=23><div align=left><b>E@Mail an Mitglieder Rang (Die du anwählst):</b></div></td></tr><tr><td colspan=2>
        <?
        echo "<TABLE class=tabela CELLPADDING=0 CELLSPACING=0 WIDTH=100%>";
$numclasses=0;
$constants = get_defined_constants ();
foreach( array_keys($constants) as $x)
{
if (substr($x,0,3) == "UC_"){
echo "<td><input name=\"".$x."\" type=\"checkbox\" value=1>".substr($x,3)."</td>";
if ($numclasses==5)
echo "<tr></tr><tr></tr>";
$numclasses++;
  }
}
echo "</table>";
		?>
		<input type="hidden" name="numclasses" value="
		<? echo $numclasses; ?>
		"/></td></tr><tr><td class="tablea">Betreff</td><td><input type=text size=88 name="subject"></textarea></td></tr><tr><td class="tablea">Nachricht</td><td><textarea cols=88 rows=10 name="message"></textarea></td></tr><tr><td align="center" colspan=2><input type="submit" value="Okay" class="btn" /></td></tr></table></form>
		<? 
		stdfoot(); 
		?>