
<html>
<head>
<title>Utility to e-mail to customers</title>
</head>
<body bgcolor ="#ffffff">
<?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 "<p align=\"center\"><b><strong><font face = Verdana size = 5>Sorry you not the administrator!</strong></font></b><br>Click here to return to log in screen <a href='shop_showall.php'>here.</a><br><br><br><br><br><br></p>";
	include("./your-footer.inc");  
	exit();
}
 if ((session_is_registered("admin")) and ($_SESSION['admin'] != "admin"))
{
	 echo "<p align=\"center\"><b><strong><font face = Verdana size = 5>Sorry you not the administrator!</strong></font></b><br>Click here to return to log in screen <a href='shop_showall.php'>here.</a><br><br><br><br><br><br></p>";
	include("./your-footer.inc");  
	exit();
}
 if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $conlist = addslashes($_POST["conlist"]);
        $cutlist = addslashes($_POST["cutlist"]);
        $mailing = addslashes($_POST["mailing"]);
}
if ($conlist == "none" && $cutlist =="none")
{
	echo("<br><br><br><center><img src=images/gth.gif border=0>Opps...You cannot use the email utility since you have no contacts and no customers in your database.You can add contacts manually using the Add function in the Administration Panel.<br>Customers will be added to your customers list once an user registers their username and password.<br></center><br><br><br>");
	include("./your-footer.inc");
	exit();
}
if ($conlist != "none" && $mailing > 2 && $cutlist == "none")
{
	echo("<br><br><br><center><img src=images/gth.gif border=0>Opps...You can only send email to person(s) on your contact list. You selected option to send from customer list.If you wish to send from customer list, please re-select the option and begin again.</center><br><br><br><br>");
	include("./your-footer.inc");
	exit();
}
if ($cutlist != "none" && $mailing < 3 && $conlist == "none" )
{
	echo("<br><br><br><center><img src=images/gth.gif border=0>Opps...You can only send email to person(s) on your customer list. You selected option to send from contact list.If you wish to send from contact list, please re-select the option and begin again.</center><br><br><br><br>");
	include("./your-footer.inc");
	exit();
}
if ($cutlist != "none" or $conlist!= "none")
{
# Find no. of contacts and customers from sql database #
$table = "contacts";
$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.");
$sql = "select * from $table";
$rs = mysql_query($sql,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");
$num = mysql_numrows($rs);
$contacts = 0;
$customers = 0;
if ($num > 0)
{
	$contacts =$num;
}

$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 ($mailing == 1)
	$mode = "Mode: Single Email from Contact List";
if ($mailing == 2)
	$mode = "Mode: All Email from Contact List";
if ($mailing == 3)
	$mode = "Mode: Single Email from Customer List";
if ($mailing == 4)
	$mode = "Mode: All Email from Customer List";

echo "<center><img src=images/emails.gif border=0><font face=Verdana color=#0000CC>EMAIL UTILITY</font></center><br><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 color = #111111> Contacts:$contacts Customers:$customers $mode</font></td>
  </tr>
</table>";

$form = "<br><form action=sendemail.php method=POST><table border=0 cellpadding=2 cellspacing=0 align=center>";
$form.="<tr> <td align=right nowrap><font face=Verdana size=-1>From:</font></td>";
if ($usedata == "YES")
	$form.="<td><select name = from><option value = $siteemail>$sitecompany</option></td></tr>";
if ($usedata == "NO")
	$form.="<td><select name = from><option value = $site_email>$site_company</option></td></tr>";

$form.="<tr> <td align=right nowrap><font face=Verdana size=-1>To:</font></td>";
if ($mailing == 3)
{
$form.="<td><input name=to type=text size=50 maxlength=50 value=$cutlist></td></tr>";
}
if ($mailing == 1)
{
$form.="<td><input name=to type=text size=50 maxlength=50 value=$conlist></td></tr>";
}
# generate to list for customers
if ($mailing == 4)
{
$table = "users";
$sql1 = "select * from $table where username != 'Admin'";
$rs1 = @mysql_query($sql1,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");
	$form.="<td><select name = from>";
while ($getrow = mysql_fetch_array($rs1))
{	
	$firstname = $getrow["firstname"];
	$lastname = $getrow["lastname"];
	$email = $getrow["email"];
	$cfiller = $firstname;
	$cfiller.= " $lastname";
	$form.="<option value = $email>$cfiller</option>";
}
$form.="</select></td></tr>";
}
# generate to list for contacts
if ($mailing == 2)
{
$table = "contacts";
$sql2 = "select * from $table";
$rs2 = @mysql_query($sql2,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");
	$form.="<td><select name = from>";
while ($getrow = mysql_fetch_array($rs2))
{	
	$firstname = $getrow["cfirst"];
	$surname = $getrow["csurname"];
	$cemail = $getrow["cemail"];
	$dfiller = $firstname;
	$dfiller.= " $surname";
	$form.="<option value = $cemail>$dfiller</option>";
}
$form.="</select></td></tr>";
}
$form.="<tr> <td align=right nowrap><font face=Verdana size=-1>Subject:</font></td>";
$form.="<td><input name=subject type=text size=50 maxlength=50></td></tr>";
$form.="<tr><td align =right nowrap><font face=Verdana size=-1>Mail Message:</font></td>";
$form.="<td><textarea name=mail cols=50 rows=15></textarea></td></tr>";
$form.="<tr><td>&nbsp;</td>";
$form.="<input type = hidden name=mailing value=$mailing>";
if ($mailing == 1)
	$form.="<input type = hidden name=conlist value=$conlist>";
if ($mailing == 3)
	$form.="<input type = hidden name=cutlist value=$cutlist>";
$form.="<td><center><input name=send type=submit value='Send Email'></center></td></tr></table></form>";
echo($form);
echo("<br><center><p align = justify><font face = Verdana size =2 color =#0000CC>NOTES TO USERS: To use the email utility, you must type in the subject heading and message content. The To shows single user you wish to send email and also shows all users extracted from your contacts or customers list. When you press the 'Send Email' button, it will perform series of checks and then proceed to send your email. In the mutiple email send, the system will send email to all users shown in the TO pulldown list.Use HTML script language to create your email message.Put your message within <HTML> and </HTML> - use 'br' for new line incased with <> and use 'strong' style to make text bold. Start your email message using <HTML> and end your email message with </HTML></font></center></p>");
echo "<center><a href=javascript:history.back()><img src=images/exit.gif border = 0 alt=Exit></a></center>";
include("./your-footer.inc");
}
?>
</htm></body>