
<html>
<head>
<title>Utility to e-mail to customers</title>
</head>
<body bgcolor ="#f9f9f9">
<?php
/***************************************************************************
 *		admin/email.php			                           *
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~	                   *
 *   File Info:		  Utility to e-mail all customers                  *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
 ***************************************************************************/
include ("./tests.php");
include ("./your-header.inc");
?>
<?php
include ("./config.php");
if ($_SESSION['admin'] == NULL)
{
echo "<br><br><center><img src=images/line.gif border=0 height=1 width=400></center><p align=\"center\"><img src=images/keybord1.gif border=0><b><strong><font face = Verdana size = 3>   Sorry you are not the administrator!</strong></font></b><br>Click here to return to log in screen  <a href='shop_showall.php'>here.</a>
<br><br><img src=images/line.gif border=0 height=1 width=400><br><br><br><br></p>";
	include("./your-footer.inc");  
	exit();
}
 if ((session_is_registered("admin")) and ($_SESSION['admin'] != "admin"))
{
echo "<br><br><center><img src=images/line.gif border=0 height=1 width=400></center><p align=\"center\"><img src=images/keybord1.gif border=0><b><strong><font face = Verdana size = 3>   Sorry you are not the administrator!</strong></font></b><br>Click here to return to log in screen  <a href='reglog.php'>here.</a>
<br><br><img src=images/line.gif border=0 height=1 width=400><br><br><br><br></p>";
	include("./your-footer.inc");  
	exit();
}
 if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
          $mailing = addslashes($_POST["mailing"]);
          $mail = addslashes($_POST["mail"]);
          $subject = addslashes($_POST["subject"]);
         if ($mailing == 1)
	$conlist = addslashes($_POST["conlist"]);
          if ($mailing == 3)
	$cutlist = addslashes($_POST["cutlist"]);
	
}
# send email using customer and mail contact
if ($mailing == 3)
{
	$to = $cutlist;
	$from = "$admin_name <$admin_mail>";
	$extraheader = "From: $admin_name<$admin_mail>\r\n";
    	$extraheader.="Reply-To: $admin_mail\r\n";
    	$extraheader.="X-Mailer: 128 Concepts Sales [sales@128concepts.com]";
	echo "<table border=0 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=85% height=20 bgcolor=#DDE6FE align = center>
  	<tr><td width=100% height=25>
    	<p align=center><b><font face=Verdana color=#0000CC>EMAIL UTILITY -</font><font color = #111111> Sending email message to $to</font></td>
  	</tr></table>";
	$display = "<br><font face = Verdana size = 3>";
	if (strlen($conlist) > 0)
		$display.="<strong>To:</strong> $conlist<br>";
	if (strlen($cutlist) > 0)
		$display.="<strong>To:</strong> $cutlist<br>";
	$display.="<strong>Subject:</strong>$subject<br>";
	$display.="<strong>Mail Content:</strong>$mail<br><br><hr width=400>";
	echo($display);
	$send = "<br><br><center>";
	$send.= "<img src =./images/email.gif>Sent email to '$to' completed.....</center>";
	echo($send);
	@mail($to,$subject,$mail,$extraheader);
	
}
# send email using contact and mail contact
if ($mailing == 1)
{
	$to = $conlist;
	$from = "$admin_name <$admin_mail>";
	$extraheader = "From: $admin_name<$admin_mail>\r\n";
    	$extraheader.="Reply-To: $admin_mail\r\n";
    	$extraheader.="X-Mailer: 128 Concepts Sales [sales@128concepts.com]";
	echo "<table border=0 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=85% height=20 bgcolor=#DDE6FE align = center>
  	<tr><td width=100% height=25>
    	<p align=center><b><font face=Verdana color=#0000CC>EMAIL UTILITY -</font><font color = #111111> Sending email message to $to</font></td>
  	</tr></table><br>";
	$display = "<br><font face = Verdana size = 3>";
	if (strlen($conlist) > 0)
		$display.="<strong>To:</strong> $conlist<br>";
	if (strlen($cutlist) > 0)
		$display.="<strong>To:</strong> $cutlist<br>";
	$display.="<strong>Subject:</strong>$subject<br>";
	$display.="<strong>Mail Content:</strong>$mail<br><br><hr width=400>";
	echo($display);
	$send = "<br><br><center>";
	$send.= "<img src =./images/email.gif>Sent email to '$to' completed.....</center>";
	echo($send);
	@mail($to,$subject,$mail,$extraheader);
	
}
# send email to all contacts in customer list.

if ($mailing == 4)
{
$conn = @mysql_connect($server,$user,$password)
	or die("Unable to connect to SQL database...");

$rs = @mysql_select_db($database,$conn) 
	or die("Unable to select the database 'mydata'...Please press 'Create Database' to create new database.");
$table = "users";
$sqls = "select * from $table";
$rss = mysql_query($sqls,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");
$nums = mysql_numrows($rss);
$customers = $nums;

if ($customers > 0) # do multiple sending
{
	echo "<table border=0 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=85% height=20 bgcolor=#DDE6FE align = center>
  	<tr><td width=100% height=25>
    	<p align=center><b><font face=Verdana color=#0000CC>EMAIL UTILITY -</font><font color = #111111> Sending email message to all users</font></td>
  	</tr></table><br>";
	$table = "users";
	$sqls = "select * from $table";
	$rss = mysql_query($sqls,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");	
	$cust = array();
	$display = "<br><font face = Verdana size = 3>";
	if (strlen($conlist) > 0)
		$display.="<strong>To:</strong> $conlist<br>";
	if (strlen($cutlist) > 0)
		$display.="<strong>To:</strong> $cutlist<br>";
	$display.="<strong>Subject:</strong>$subject<br>";
	$display.="<strong>Mail Content:</strong>$mail<br><br><hr width=400>";
	echo($display);
	echo("<br><br>");
	echo "<table border=0 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=85% height=20 bgcolor=#DDE6FE align = center>
  	<tr><td width=100% height=25>
    	<p align=center><b><font face=Verdana color=#0000CC>EMAIL UTILITY -</font><font color = #111111> Sending email messages to all users</font></td>
  	</tr></table><br>";
	while ($rows = mysql_fetch_array($rss))
	{
		$username = $rows["username"];
		if ($username != "admin")
		{
			$firstname = $rows["firstname"];
			$lastname = $rows["lastname"];
			$email = $rows["email"];
			$fillers = $firstname;
			$fillers.= " $lastname";
			$from = "$admin_name <$admin_mail>";
			$to = "$fillers <$email>";
			$extraheader = "From: $admin_name<$admin_mail>\r\n";
    			$extraheader.="Reply-To: $admin_mail\r\n";
    			$extraheader.="X-Mailer: 128 Concepts Sales [sales@128concepts.com]";
			$send= "<center><img src =./images/email.gif>Sent email to '$to' completed.....</center>";
			echo $send;
			@mail($to,$subject,$mail,$extraheader);
		}
	}

include("./your-footer.inc");
}
}

# send email to all contacts in contacts list.
if ($mailing == 2)
{
$conn = @mysql_connect($server,$user,$password)
	or die("Unable to connect to SQL database...");

$rs = @mysql_select_db($database,$conn) 
	or die("Unable to select the database 'mydata'...Please press 'Create Database' to create new database.");
$table = "contacts";
$sql = "select * from $table";
$rs = mysql_query($sql,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");
$nums = mysql_numrows($rs);
$contacts = $nums;
if ($contacts> 0) # do multiple sending
{
	echo "<table border=0 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=85% height=20 bgcolor=#DDE6FE align = center>
  	<tr><td width=100% height=25>
    	<p align=center><b><font face=Verdana color=#0000CC>EMAIL UTILITY -</font><font color = #111111> Sending email message to all users</font></td>
  	</tr></table><br>";
	$table = "contacts";
	$sqls = "select * from $table";
	$rss = mysql_query($sqls,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");	
	$cust = array();
	$display = "<br><font face = Verdana size = 3>";
	if (strlen($conlist) > 0)
		$display.="<strong>To:</strong> $conlist<br>";
	if (strlen($cutlist) > 0)
		$display.="<strong>To:</strong> $cutlist<br>";
	$display.="<strong>Subject:</strong>$subject<br>";
	$display.="<strong>Mail Content:</strong>$mail<br><br><hr width=400>";
	echo($display);
	echo("<br><br>");
	
	while ($rows = mysql_fetch_array($rs))
	{
		
		$cemail = $rows["cemail"];
		$ctitle = $rows["ctitle"];
		$cfirst = $rows["cfirst"];
		$csurname = $rows["csurname"];
		$filler = $ctitle;
		$filler.= " $cfirst $csurname";
		$from = "$admin_name <$admin_mail>";
		$to = "$filler <$cemail>";
		$extraheader = "From: $admin_name<$admin_mail>\r\n";
    		$extraheader.="Reply-To: $admin_mail\r\n";
    		$extraheader.="X-Mailer: 128 Concepts Sales [sales@128concepts.com]";			
		$send= "<center><img src =./images/email.gif>Sent email to '$to' completed.....</center>";
		echo($send);
		@mail($to,$subject,$mail,$extraheader);	
	}
include("./your-footer.inc");
}}
?>
</body>
</html>