$dbcnx = @mysql_connect('mysql.plainhost.com','ecosmar_ecosmart','ecoman1');
$freshID = $_GET['newID'];
if($freshID != ""){
$usrn = $_GET['usrn'];
mysql_select_db('ecosmar_friendly', $dbcnx);
$listem = @mysql_query("SELECT ID FROM messages WHERE usrn='$usrn' AND status='unread'");
if (!$listem) {
echo("Problem counting messages.");
}
$num_rows = mysql_num_rows($listem);
$num = $num_rows;
if($num_rows == 0 or $num_rows == ""){
$comdot = "
";
$cmdt = 0;
}else{
$comdot = "
";
$cmdt = 1;
}
$econ[] = $freshID;
}else{
//ifnotfreshid
$usrn = $_POST['usrn'];
$cmdt = $_POST['cmdt'];
$num = $_POST['num'];
if($num == 0){
$comdot = "
";
$cmdt = 0;
}else{
$comdot = "
";
$cmdt = 1;
}
$dtnum = date(Ymd);
$memrep = $_POST[memrep];
$memcount = count($memrep);
$econ = $_POST[econ];
$erep = $_POST[erep];
}
$econcount = count($econ);
$erepcount = count($erep);
$etot = $econcount + $erepcount;
if($econcount == 0 and $erepcount == 0 and $memcount == 0){
echo("Please Go Back and chose recipient.
");
exit();
}
if($etot > 15){
echo("In order to abide by anti-spam rules. Your email may only be sent to 15 recipients at a time. Please Go Back and cull the list.
");
exit();
}
$mtou = array();
$etou = array();
$mtoe = array();
$etoe = array();
mysql_select_db('ecosmar_website', $dbcnx);
$from = @mysql_query("SELECT email FROM psw WHERE usrn='$usrn'");
if (!$from) {
echo("Problem retrieving From Email.
Error: ". mysql_error());
}else{
$rowf = mysql_fetch_array($from);
$fremail = $rowf['email'];
}
$getphone = @mysql_query("SELECT phone FROM repcon WHERE email='$fremail'");
if (!$getphone) {
echo("Problem getting phone number.
Error: ". mysql_error());
}else{
$rowp = mysql_fetch_row($getphone);
$phone = $rowp['phone'];
}
$mcount = count($memrep);
if($mcount > 0){
$i = 0;
while($i < $mcount){
$listem = @mysql_query("SELECT usrn,email FROM psw WHERE ID='$memrep[$i]'");
if (!$listem) {
echo("Problem retrieving Rep Listing.
Error: ". mysql_error());
}else{
$row = mysql_fetch_array($listem);
$mtousrn[] = $row['usrn'];
$mtoemail[] = $row['email'];
}
$i = $i+1;
}
if($mcount > 1){
$mlist = implode(",", $mtousrn);
$mlert = "Send Memo to: " . $mlist ."
";
}elseif($mcount == 1){
$mlert = "Send Memo to: " . $mtousrn[0] ."
";
}else{
$mlert = "";
}
}
$ercount = count($erep);
if($ercount > 0){
$i = 0;
while($i < $ercount){
$listem = @mysql_query("SELECT usrn,email FROM psw WHERE ID='$erep[$i]'");
if (!$listem) {
echo("Problem retrieving Rep Listing.
Error: ". mysql_error());
}else{
$row = mysql_fetch_array($listem);
$tonames[] = $row['usrn'];
$toemail[] = $row['email'];
}
$i = $i+1;
}
}
$ecount = count($econ);
if($ecount > 0){
mysql_select_db('ecosmar_contacts', $dbcnx);
$i = 0;
while($i < $ecount){
$listemb = @mysql_query("SELECT first_Name,Name,email FROM con_main WHERE ID='$econ[$i]'");
if (!$listemb) {
echo("Problem retrieving Rep Listing.
Error: ". mysql_error());
}else{
$row = mysql_fetch_array($listemb);
$name1 = $row['first_Name'];
$name2 = $row['Name'];
$allname = $name1." ".$name2;
$tonames[] = $allname;
$toemail[] = $row['email'];
}
$i = $i+1;
}
}
$tcount = count($tonames);
if($tcount > 1){
$elist = implode(",", $tonames);
$elert = "Send Email to: " . $elist;
}elseif($tcount == 1){
$elert = "Send Email to: " . $tonames[0];
}else{
$elert = "";
}
?>