<?php


include "../inc/session.php";
include "../config.php";
include "../inc/memberfunctions.php";
include "../inc/functions.php";
include "../style.php";
preview();

$memtype=$userrecord["memtype"];
$userid=$userrecord["userid"];
$verified=$userrecord["verified"];
$usercredits=$userrecord["points"];
$lastmailing=$userrecord["lastmailing"];

if($memtype=="PRO") {
$mailhours=$promailhours;
$mailtoplimit=$prolimitmail;
$maillength=$promaillength;
} elseif($memtype=="JV Member") {
$mailhours=$jvmailhours;
$mailtoplimit=$jvlimitmail;
$maillength=$jvmaillength;
} elseif($memtype=="SUPER JV") {
$mailhours=$superjvmailhours;
$mailtoplimit=$superjvlimitmail;
$maillength=$superjvmaillength;
}

if (!is_numeric($usercredits)) {
$usercredits = 0;
}
$usercredits = floor($usercredits);

$count= mysql_query("select * from members WHERE verified='1' and userid!='$userid'");
$membercount = @ mysql_num_rows($count);

if ($verified != 1) {
include "../header.php";
include "navigation.php";
include "../banners2.php";
echo("<center><h4><b>Your Account Status Is: Not Verified</b></h4>");
echo("<p><font size=\"2\">If you believe this is a mistake, please contact support.</font></p>");
echo "</table>";
include "../footer.php";
exit;
}


// Count Members That User Can Mail
//status='1' and verified='1' and vacation='0'
//$canmail = "SELECT userid FROM `members` WHERE status='1' and verified='1' and vacation='0' ORDER BY RAND() LIMIT $mailtoplimit";
$canmail = "SELECT userid FROM `members` WHERE status='1' and verified='1' and vacation='0' LIMIT $mailtoplimit";
//$canmail = "SELECT userid FROM `members` WHERE userid != '".$userid."' and status='1' and verified='1' and vacation='0' ORDER BY RAND() LIMIT $mailtoplimit";
//Original code below. I changed to above code 11/29/24
//$canmail = "SELECT userid FROM `members` WHERE userid != '".$userid."' ORDER BY RAND() LIMIT $mailtoplimit";
$canmailresult = mysql_query($canmail);
$canmailtotal = mysql_num_rows($canmailresult);

// Send/Schedule Mail
if ($_GET['send'] == "yes") {

if (!check_number($_POST['credits'])) {
include "../header.php";
include "navigation.php";
include "../banners2.php";
echo("<p align=\"center\"><b>Assigned credits must be a positive whole number.</b></p>");
goback ();
echo "</table>";
include "../footer.php";
exit;
}

if ($_POST['credits'] < 1) {
include "../header.php";
include "navigation.php";
include "../banners2.php";
echo("<p align=\"center\"><b>Please enter a credits value.</b></p>");
goback ();
echo "</table>";
include "../footer.php";
exit;
}

if ($_POST['credits'] > $canmailtotal) {
include "../header.php";
include "navigation.php";
include "../banners2.php";
echo("<p align=\"center\"><b>You cannot mail to that many members.</b></p>");
goback ();
echo "</table>";
include "../footer.php";
exit;
}
if ($_POST['credits'] >= $usercredits) {
include "../header.php";
include "navigation.php";
include "../banners2.php";
echo("<p align=\"center\"><b>You don't have enough credits to mail that many members.</b></p>");
goback ();
echo "</table>";
include "../footer.php";
exit;
}
if (strlen($_POST['message']) > ($maillength+10)) {
include "../header.php";
include "navigation.php";
include "../banners2.php";
echo("<p align=\"center\"><b>Message body must be ".$maillength." characters or less.</b></p>");
goback ();
echo "</table>";
include "../footer.php";
exit;
}
if (empty($_POST['subject'])){
include "../header.php";
include "navigation.php";
include "../banners2.php";
echo("<p align=\"center\"><b>Subject must be filled in.</b></p>");
goback ();
echo "</table>";
include "../footer.php";
exit;
}
if (empty($_POST['url'])){
include "../header.php";
include "navigation.php";
include "../banners2.php";
echo("<p align=\"center\"><b>Url must be filled in.</b></p>");
goback ();
echo "</table>";
include "../footer.php";
exit;
} 

if($_POST['message'] AND $_POST['subject'] AND $_POST['url'] AND $_POST['credits']) {
checksubject($_POST['subject']);  
authorizeurl($_POST['message']);
banned_sites($_POST['url']); 
checkforworddoc ($_POST['message']);                    
mysql_query("INSERT INTO membermail_temp SET `date`='".time()."' , userid='".$userid."', url='".addslashes($_POST['url'])."', subject='".addslashes($_POST['subject'])."', message='".addslashes($_POST['message'])."', sendto='".addslashes($_POST['credits'])."'");
$adid = mysql_insert_id();
framecheck("membermail", $adid, $_POST['url']);
} 

} if($_GET['pageid'] == "stats") {
include "../header.php";
include "navigation.php";
include "../banners2.php";
?>
<h2 align=center>Credit Mailer Stats</h2>
<?php
$sql = mysql_query("SELECT * FROM membermail WHERE userid='$userid' ORDER BY timestamp");
if(@mysql_num_rows($sql)) {
//echo "<div align=center><a href=\"mailer.php\">Use Credit Mailer</a></div><br><br>";
echo "<table border=0 bgcolor=\"#000000\" cellpadding=5 width=\"90%\"><tr bgcolor=\"#CCCCCC\"><th>Subject</th><th>Date</th><th>Sent to</th><th>Clicks</th></tr>";

while($each = mysql_fetch_array($sql)) {
echo "<tr bgcolor=\"#FFFFFF\"><td><a href=\"".$each['url']."\" target=_NEW>".$each['subject']."</a></td><td align=center>".date('Y-m-d', $each['timestamp'])."</td><td align=center>".$each['sentto']."</td><td align=center>".$each['clicks']."</td></tr>";
}
echo "</table>";
}
} else {
include "../header.php";
include "navigation.php";
include "../banners2.php";

echo "<font size=2 face='$fonttype' color='$fontcolour'><p><center>";
echo "<H2 align=center>Credit Mailer</H2>";
$sql = mysql_query("SELECT * FROM membermail WHERE userid='$userid' LIMIT 1");
if(@mysql_num_rows($sql)) {
echo "<p align=center><font size=\"3\"><a href=\"mailer.php?pageid=stats\"><font size=\"3\">Click Here</a> To See The Stats Of Your Previous Emails.</font><br><br><br>";
}  
$postavailable = date('Y-m-d H:i:s',strtotime("-$mailhours hours"));
$datetime = $lastmailing;
$new_datetime = date('Y-m-d H:i:s', strtotime("+$mailhours hours", strtotime($datetime)));

if ($lastmailing >= $postavailable) {
echo "<p align=center><font size=\"3\"><b>Your membership level allows you to mail every ".$mailhours." hours</b></font></p>";
echo "<p align=center><font size=\"3\">You can mail again after <font color=red>".$new_datetime."</font></p>";
echo "</table>";	
include "../footer.php";
exit;
} # End if ($lastmailing >= $postavailable)

$count= mysql_query("select * from members WHERE verified='1' ORDER BY RAND() LIMIT $mailtoplimit");
$membercount = @ mysql_num_rows($count);
if($membercount>=$cmailmembers) {
echo "<table align=center width=600 border=0><tr><td><p align=left>";
?>
<div align=center><span style="background-color: #FFFF00"><font size="2"><b>PLEASE ADHERE TO THE FOLLOWING RULES</b></font></span></div>
<table align=center><tr><td>
<div align=left>
<font size="2">
1) Make sure your claims in your ads can be backed up with solid proof. 
<br><br>
2) No subject lines that are deceptive in nature. 
<br><br>
3) No adult, offensive, pyramid schemes, chainletters or illegal ads.</font>
</div>
</td></tr></table>
<br>
<div align=center><span style="background-color: #FFFF00"><font size="2"><b>Your Ad Will Be Processed & Fail Submission For The Following Reasons</b></font></span></div>
<table align=center><tr><td>
<div align=left>
<font size="2">
1) Special characters such as $(dollar signs) in your subject line. 
<br><br>
2) URLS in your ad message body. 
<!--<br><br>
3) If your website url is in our <a href="../bannedemails.php" target=_BLANK>banned site list</a>.-->
<br><br>
3) If your website url breaks frames.
</font>
</div>
</td></tr></table>

<br><br>
<form action="https://tinyurl.com/create.php" method="post" target="_blank">
<table align="center" cellpadding="5" bgcolor="#E7E7F7"><tr><td>
Enter a long URL to make <a href="https://tinyurl.com">tiny</a>:<br />
<input type="text" name="url" size="30"><input type="submit" name="submit" value="Make TinyURL!">
</td></tr></table><div align=center><b>To keep emails from bouncing, please cloak your URL.</b><br></div>
</form>
<center><font size="3" color="blue"><b>Try this FREE URL cloaker with stats! Join <a href="http://cloakeasy.com" target="_blank">Cloak Easy!</b></font></a></center>
<br>
<br>

<?php
echo "<div align=center><br>Use this tag: ~fname~ to call up the members first name in your email.<br><br></div>


</p></td></tr></table>";
echo("
<form style=\"margin:0px\" method=\"post\" action=\"mailer.php?send=yes\">
<table bgcolor=#FFFFFF width=500 border=0 bordercolor=black cellpadding=3 cellspacing=0>

<tr><td align=center>
<font size=2><b>Message Subject</b></font><br>
<input type=\"text\" name=\"subject\" value=\"".$subject."\" size=\"40\" maxlength=\"50\">
<br><br>
<font size=2><b>Message Body</b></font><br>
<textarea name=\"message\" id=\"message\" wrap=\"soft\" rows=\"20\" cols=\"50\" onkeypress=\"return checkKeyPress(this, ".$maillength.", event);\">".$message."</textarea><br><br>

</td></tr>

<tr><td align=center>
<font size=2><b>Site URL: </font>
<input type=\"text\" name=\"url\" value=\"".$url."\" size=\"40\" maxlength=\"200\">
</td></tr>

");
echo("<tr><td align=center><font size=2><b>Credits: </b></font><input type=\"text\" name=\"credits\" value=\"".$_POST['credits']."\" size=\"6\" maxlength=\"8\"><br><font size=2>Your message will be sent to 1 member for every credit used.</font><br><font size=2>You can use up to <span style=\"background-color: #FFFF00\"><b>".$canmailtotal."</b></span> credits.</font></td></tr>");
echo("<tr><td align=center><input type=\"submit\" value=\"Send\"></td></tr>
</table>
</form>
");
echo "<br><br>";
} else {
echo "<br><b>Mailers are disabled until we reach $cmailmembers members.</b>";
}		
}

echo "</font></td></tr></table>";
include "../footer.php";
?>
