<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();
}
# 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;

echo "<br><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=75% height=20 bgcolor=#DDE6FE align = center>
  <tr>
    <td width=100% height=25>
    <p align=center><b><font color = #111111> Contacts:$contacts Customers:$customers</font></td>
  </tr>
</table>";

# build a form with the customer/contact names
$list="<br><table width=50% cellpadding=2 cellspacing=0 border=0 bgcolor=$backcolor align = center>";
$list.="<tr><form action = create_email.php method = post>";
$list.="<td>Contacts List:</td>";
if ($contacts == 0)
{
	$list.="<td><select name = conlist>";
	$list.="<option value = none>--NO CONTACTS--</option></select></td></tr>";
}
if ($contacts > 0)
{
	$table = "contacts";
	$sql = "select * from $table";
	$rs = mysql_query($sql,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");	
	$cons = array();
	$list.="<td><select name = conlist>";
	while ($row = mysql_fetch_array($rs))
	{
		$cons = $row["cemail"];
		$ctitle = $row["ctitle"];
		$cfirst = $row["cfirst"];
		$csurname = $row["csurname"];
		$filler = $ctitle;
		$filler.= " $cfirst $csurname";
		$list.="<option value = $cons>$filler</option>";
	}
	$list.="</select></td></tr>";
}
$list.="<td>Customers List:</td>";
if ($customers == 0)
{
	$list.="<td><select name = cutlist>";
	$list.="<option value = none>--NO CUSTOMERS--</option></select></td>";
}
if ($customers > 0)
{
	$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();
	$list.="<td><select name = cutlist>";
	while ($rows = mysql_fetch_array($rss))
	{
		
		$firstname = $rows["firstname"];
		$lastname = $rows["lastname"];
		$email = $rows["email"];
		$fillers = $firstname;
		$fillers.= " $lastname";
		$list.="<option value = $email>$fillers</option>";
	}
	$list.="</select></td></tr>";
}
$list.="<tr><td>Send email from which list:</td>";
$list.="<td><select name = mailing><option value = 1>Contacts List Single Email</option>";
$list.="<option value = 2>Contacts List Email All</option>";
$list.="<option value =3>Customers List Single Email</option>";
$list.="<option value=4>Customers List Email All</option>";
$list.="</select></td>";
$list.="<center><input type = submit value = 'Proceed to Create Email'></center></form></table>";
echo($list);
echo("<br><center><p align = justify><font face = Verdana size =2 color =#0000CC>NOTES TO USERS: To use the email utility, you must select the name of the person you wish to send email from the contact list or customer list. Next select the mode of sending. There are 4 modes of sending email. The 1st is to send single email to person on contact list. The 2nd is to send email to all persons on contact list. The 3rd is to send email to person on customer list. The 4th is to send email to all persons on customer list.</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");
?>
</body></html>