<?
//
//  cP Account Creator Version 0.4 Beta Build 01
//  Copyright (C) 2004 Brian Freeman
//  All Rights Reserved.
//  EMAIL Mod
//  This script set is distributed as is with absolutely no warranty.
//  Users of this script set agree to use at their own risk.
//  Questions or comments?  Contact webmaster@freemans-web.com
//
//
include("../config.php");
if ($email_type==""){
$email_type="email";
}




$conn  = mysql_connect($dbhost, $dbusername, $dbpass) or die(mysql_error( ));
mysql_select_db($dbname,$conn) or die(mysql_error( ));
include("header.php");
?>
<table width="700">
<tr>
<td>
<table width="250">
<tr>
<td>
&nbsp
</td>
</tr>
</table>
</td>
<td>

<table class=mtext width=400>
<tr>
<td   colspan=2 class=mtable>
To send email to <?echo $domain;?> email addresses <a href=cust_cont.php?email_type=cp_email> Click Here</a><br>
To send email to alternate email addresses <a href=cust_cont.php> Click Here</a><br><br>
</td><td>

</td></tr><tr><td>

<form method="POST" action="cust_cont.php">

<?
$get_items="SELECT * FROM email_users WHERE id>1";
$get_items_res=mysql_query($get_items)  or die(mysql_error( ));
if (mysql_num_rows($get_items_res)<1) {

echo   "<h1>No Records</h1>";
} else {
echo "<select name=user>";
	while ($items = mysql_fetch_array ($get_items_res)) {
echo "<option>$items[$email_type]</option>";

}

echo "<option>ALL</option>";
echo "</select>";
}
?>
</td>
</tr>
<tr>
<td colspan=2 class=mtext>
Subject:
<input type="text" name="subject" size=50>
</td>
</tr>
<tr>
<td colspan=2 class=mtext>
Message:
<textarea name="msg" cols=50 rows=10></textarea>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<input type="hidden" name="contuser" value="1">
<input type="hidden" name="email_type" value="<?echo $email_type;?>">
<tr>
<td align=right><input type="submit" value="Email User"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
<td>
<table width=200>
<tr>
<td>
&nbsp
</td>
</tr>
</table>
</td>
</tr>
</table>
<?
include("footer.php");
?>








<?


if(($user!="ALL")&&($contuser==1)){

if($subject==""){
    echo "Email not sent, subject blank.  User your browsers Back button to enter a Subject.<br><br>";
}else{
$get_items="SELECT * FROM email_users WHERE $email_type='$user'";
$get_items_res=mysql_query($get_items)  or die(mysql_error( ));
	while ($items = mysql_fetch_array ($get_items_res)) {
       $fname=$items[first_name];
}



$recipient=$user;
$mailheaders="From:  Site Admin <admin@$domain>\n";
$msgc="Dear $fname,\n\n$msg\n\n$signature";
mail ($recipient, $subject, $msgc, $mailheaders);
echo "mail sent to $user<br><br>";
}
}



if(($user=="ALL")&&($contuser==1)){
if($subject==""){
    echo "Email not sent, subject blank.  User your browsers Back button to enter a Subject.<br><br>";
}else{
if($email_type=="email"){
$get_items="SELECT * FROM email_users WHERE id>1";
$get_items_res=mysql_query($get_items)  or die(mysql_error( ));
	while ($items = mysql_fetch_array ($get_items_res)) {
$contact=contactall($items[email],$items[first_name],$subject,$msg);
}
}
if($email_type=="cp_email"){
$get_items="SELECT * FROM email_users WHERE id>1";
$get_items_res=mysql_query($get_items)  or die(mysql_error( ));
	while ($items = mysql_fetch_array ($get_items_res)) {
$contact=contactall($items[cp_email],$items[first_name],$subject,$msg);
}
}
}
}

end;

function contactall($recipient,$first_name,$subject,$msg){
    global $domain;
$msgc="Dear $first_name,\n\n$msg\n\n$signature";
$mailheaders="From:  Site Admin <admin@$domain>\n";
mail ($recipient, $subject, $msgc, $mailheaders);
echo "mail sent to $recipient</br>";
}
?>
