diff options
author | Patrick Davison <snapwilliam@gmail.com> | 2013-02-09 14:22:22 -0800 |
---|---|---|
committer | Patrick Davison <snapwilliam@gmail.com> | 2013-02-09 14:22:22 -0800 |
commit | f8d48c412670381356f2f28b826a8f9f57e1094e (patch) | |
tree | 045b247d0b33ecfbe7465d67c59afda6643fd8c9 /pages/massemail.php | |
parent | d05712a7ceeaccb060212fa4d81c67b619899180 (diff) | |
download | pathery-f8d48c412670381356f2f28b826a8f9f57e1094e.tar.xz |
Emails!! go to /massemail as an admin.
Diffstat (limited to 'pages/massemail.php')
-rw-r--r-- | pages/massemail.php | 320 |
1 files changed, 193 insertions, 127 deletions
diff --git a/pages/massemail.php b/pages/massemail.php index d45588b..4bbd26b 100644 --- a/pages/massemail.php +++ b/pages/massemail.php @@ -1,5 +1,9 @@ <?php
-htmlHeader();
+htmlHeader(
+ array('stats'), 'Admin, Mass email',
+ 'Admin Mass email Pathery.com',
+ array('scores', 'dateformat')
+);
?>
<body>
<?php
@@ -7,176 +11,239 @@ topbar($Links); include('./includes/datas.php');
include('./includes/sqlEmbedded.php');
+include('./includes/emails.php');
+if (!$accepted) exit;
-if (isset($_POST['massemail']) AND isset($_SESSION['accepted'])) {
- if (!$accepted)
- return;
+
+$emailFooter = "This email was sent to %email
+To unsubscribe: %mydomaincp
+Questions? Email us! snap@pathery.com";
+
+
+if ($_POST['queueMassEmail'] == 'true') {
+ echo "Action started...<br/>";
if ($_SESSION['isAdmin'] !== true)
return;
-
- $data = $_POST;
- $data['session'] = print_r($_SESSION, true);
-
$userID = $_SESSION['userID'] * 1;
if (!is_int($userID))
return;
- include_once "includes/sqlEmbedded.php";
- $sql = "SELECT `email` FROM `users`
- WHERE `ID` = '$userID'";
- $result = mysql_query($sql);
+ //lol because I tink dis is cool...
+ echo "Validated permissions...<br/>";
+
+ $data = $_POST;
+
+ //Sanitize
+ $selections = $_POST['selections'];
+ foreach ($selections as $selectedID=>&$value) {
+ $value = intval($selectedID);
+ if (!is_int($selectedID)) die("Sanitization of userID's failed");
+ }
+
+ $in = implode(',', $selections);
- $email = mysql_result($result, 0, 'email');
+ $sql = "SELECT `id`, `displayName`, `dateJoined`, `dateLogin`, `email`
+ FROM `users`
+ WHERE `ID` IN ( $in )
+ ";
+ echo "SQL: $sql <br/>";
- $data['email'] = $email;
+ $result = mysql_query($sql) or die(mysql_error());
- EmailError($data, "Pathery Feedback");
- DoRedirect("<b>Thank you for your feedback!</b> <br />
- I'm Reading this right now.<br />
- Well, obviously I'm not reading it right NOW.<br />
- I guess what I meant to say is that I'll be reading it soon.<br />
- Wow this redirect is taking a while.. Sorry<br />
- Are you still here?<br />
- Something must be wrong, you should really have been redirected by now", $mydomain, 5);
+ while (list($tmpID, $tmpDisplay, $tmpJoined, $tmpLastLogon, $tmpEmail) = mysql_fetch_row($result)) {
+ //Replacements are done in order;
+ $replacements = array(
+ '%footer' => $emailFooter,
+ '%display' => $tmpDisplay,
+ '%id' => $tmpID,
+ '%email' => $tmpEmail,
+ '%mydomain' => $mydomain,
+ '%joined' => relative_date(strtotime($tmpJoined)),
+ '%lastLogin' => relative_date(strtotime($tmpLastLogon))
+ );
+
+ $tmpBody = stripslashes($_POST['body']);
+ $tmpTitle = stripslashes($_POST['title']);
+ $tmpBody = replaceByArray($tmpBody, $replacements);
+ $tmpTitle = replaceByArray($tmpTitle, $replacements);
+ echo "$tmpBody <br />";
+ //This Sanitizes data - so no worries!
+ QueueEmail(0, $tmpEmail, $tmpTitle, $tmpBody, 100, true);
+ }
+
+ echo "Complete!...<br/>";
+ DoRedirect("Emails processed!");
exit;
}
+include_once('./includes/sqli.php');
-include('./includes/sqli.php');
-
-$res = mysqli_query($mysqli, "SELECT count(*) as _msg FROM `users`");
+$res = mysqli_query($mysqli, "SELECT count(*) as count FROM `emailQueue`");
$row = mysqli_fetch_assoc($res);
-echo $row['_msg'];
+$count = $row['count'];
+
+//QueueEmail(3, "snapwilliam@gmail.com", "hi,testing", "this is a body", 20, true);
+//echo "<br />QUEUED!<br />";
-exit;
-function QueueEmail($unsanitizeduserID, $unsanitizedto, $unsanitizedSubject, $unsanitizedBody) {
+//$time_start = microtime(true);
+//Loop It
+// for ($i = 1; $i <= 10000; $i++) {
+ // SendQueuedEmail();
+// }
+//$time_end = microtime(true);
+//$time = $time_end - $time_start;
+//echo "<br>Script execution: $time seconds XX\n <br>";
- //Check if there's something in the queue already:
- $sql = "SELECT `userID` FROM emailQueue WHERE '$userID' = ";
+$where = '';
+if ($_POST['selectResultSet'] == 'true') {
+ // CLAUSES:
+ $clause1 = $_POST['clause1'];
+ $clauseOptions = array('ID', 'displayName', 'dateJoined', 'dateLogin', 'email', 'isAdmin');
+ if (!in_array($clause1, $clauseOptions)) die("clause1 fail");
+ $operatorOptions = array('LessThan' => '<', 'GreaterThan' => '>', 'EqualTo' => '=');
+ $operator1 = $operatorOptions[$_POST['operator1']];
+ $value1 = mysql_escape_string($_POST['value1']);
+ $where = "AND $clause1 $operator1 '$value1'";
}
-//new table
-// emailQueue ID, userID, sent, to, subject, body, dateSubmited, dateSent
-
-$sql = "SELECT `ID`, `displayName`, `dateJoined`, `dateLogin`, `email`, `isAdmin` FROM `users`";
+$sql = "SELECT `ID`, `displayName`, `dateJoined`, `dateLogin`, `email`, `isAdmin`
+FROM `users`
+WHERE `isOptedOutOfEmails` = '0'
+$where
+";
$result = mysql_query($sql);
-echo "
+?>
+
<div class='wrapper'>
- <center>
- <h3>MASS EMAIL</h3>
- </center>
-";
+<h2>Mass Email</h2>
+<h3>There are <? echo $count; ?> emails in emailQueue.</h3>
-?>
+<p>Modify the WHERE clause first to get the users you want selected.</p>
+
+<p><b>Varriables available</b></p>
+<ul>
+<li>%display</li>
+<li>%id</li>
+<li>%email</li>
+<li>%footer :<? echo $emailFooter; ?></li>
+<li>%mydomain :<? echo $mydomain; ?> (Dynamic)</li>
+<li>%joined</li>
+<li>%lastJoined</li>
+</ul>
<form action="massemail" method="post" name="massemail">
-<select id='Regarding' name='regarding'>
- <option value='Feedback' selected='selected'>General Feedback</option>
- <option value='Bug'>Bug report</option>
- <option value='Suggestion'>Suggestion</option>
- <option value='Question'>Question</option>
- <option value='Hi'>Just saying Hi</option>
- <option value='Other'>Other</option>
+ <input type='hidden' name='selectResultSet' value='true'>
+
+ <b>WHERE</b>
+<select id='clause1' name='clause1'>
+ <option value='dateLogin' selected='selected'>dateLogin</option>
+ <option value='dateJoined'>dateJoined</option>
+ <option value='ID'>user.ID</option>
+ <option value='email'>email</option>
+ <option value='isAdmin'>isAdmin</option>
</select>
-<br /><br />
+ <b>IS</b>
+<select id='operator1' name='operator1'>
+ <option value='LessThan' selected='selected'>Less Than</option>
+ <option value='GreaterThan'>Greater Than</option>
+ <option value='EqualTo'>Equal To</option>
+</select>
+ <b>TO</b>
+<input id='value1' type="text" size="25" maxlength="60" value="" name="value1" class="forminput" />
-Title: <input type="text" size="25" maxlength="60" value="" name="title" class="forminput" /><br />
-<textarea name='body' rows="10" cols="30"></textarea><br />
-<input type="checkbox" name="emailback" value="yes" /> Please email me back
-<br /><br />
-<input type="submit" value="Submit" />
+ <input type="submit" value="Get Result:" />
</form>
+<br /><br />
-<h3> EXAMPLE SET </h3>
+<form action='massemail' method='post' name='massemail'>
+<fieldset>
+ <legend>Email to send</legend>
+ Title: <input type="text" size="25" maxlength="60" value="" name="title" class="forminput" /><br />
+ <textarea name='body' rows="15" cols="70"></textarea><br />
+ Sends emails to all selected users. <input type="submit" value="SEND EMAILS" />
+</fieldset>
+
+<h3> RESULT SET </h3>
+<b>
+ WHERE `isOptedOutOfEmails` = '0'
+ <br /><? echo $where; ?>
+</b>
+<br />
+ <input type='hidden' name='queueMassEmail' value='true'>
<?
-echo "<table style='padding-left:20px;'>
-<tr>
-<th>ID</th><th>Display name:</th><th>Joined On:</th><th>Last Logon</th><th>Email</th><th>Administrator</th>
-</tr>
-";
-
-while (list($CUID, $CUsername, $Joined, $LastLogon, $email, $isAdmin) = mysql_fetch_row($result)) {
-
- //$Joined = Date("d/m/y - g:ia", $Joined);
- $Joined = strtotime($Joined);
- //$Joined = relative_date($Joined);
- $Joined = date("Y-m-d", $Joined);
-
- $LastLogon = strtotime($LastLogon);
- //$LastLogon = relative_date($LastLogon);
- $LastLogon = date("Y-m-d", $LastLogon);
+echo displayUserResultSet($result);
- if ($isAdmin == 1)
- $isAdmin = "Yes";
- else
- $isAdmin = "No";
-
+echo "</form>";
- Echo "<tr>
-<td>$CUID</td>
-<td><a href='javascript:;'>$CUsername</a></td>
-<td>$Joined</td>
-<td>$LastLogon</td>
-<td>$email</td>
-<td>$isAdmin</td>
-</tr>";
+htmlFooter();
+function displayUserResultSet($result) {
+
+ $r = "
+ <table style='padding-left:20px;'>
+ <tr>
+ <th>ID</th><th>Display name:</th><th>Joined On:</th><th>Last Logon</th><th>Email</th><th>Administrator</th>
+ </tr>
+ ";
+ $i = 0;
+ while (list($CUID, $CUsername, $Joined, $LastLogon, $email, $isAdmin) = mysql_fetch_row($result)) {
+ $i++;
+ //$Joined = Date("d/m/y - g:ia", $Joined);
+ $Joined = strtotime($Joined);
+ //$Joined = relative_date($Joined);
+ $Joined = date("Y-m-d", $Joined);
+
+ $LastLogon = strtotime($LastLogon);
+ //$LastLogon = relative_date($LastLogon);
+ $LastLogon = date("Y-m-d", $LastLogon);
+
+ if ($isAdmin == 1)
+ $isAdmin = "Yes";
+ else
+ $isAdmin = "No";
+
+ $r .= "<tr>
+ <td>$CUID
+ <input type='checkbox' name='selections[$CUID]' value='true' checked='yes'>
+ </td>
+ <td><a href='javascript:;'>$CUsername</a></td>
+ <td>$Joined</td>
+ <td>$LastLogon</td>
+ <td>$email</td>
+ <td>$isAdmin</td>
+ </tr>";
+
+ }
+ $r .= "
+ </table>
+ <br />
+ <br />
+ </td>
+ </tr>
+ </table>
+ <!-- end wrapper --!>
+ </div>
+ ";
+ $r = "<h3>$i Users Returned</h3>$r";
+ return $r;
}
-Echo "
- </table>
- <br />
- <br />
- </td>
- </tr>
-</table>
-<!-- end wrapper --!>
-</div>
-";
-
-
-function SendEmail($body, $subject = "Pathery Newsletter", $to = 'snapwilliam@gmail.com') {
- // !! TODO
- $to = 'snapwilliam@gmail.com';
- $mycompany = "Pathery";
-
- $fromemail = "snap@pathery.com";
- $replyemail = "snap@pathery.com";
-
- # -=-=-=- MIME BOUNDARY
- $mime_boundary = "----$mycompany----".md5(time());
- # -=-=-=- MAIL HEADERS
- $headers = "From: $mycompany <$fromemail>\n";
- $headers .= "Reply-To: $mycompany <$replyemail>\n";
- $headers .= "MIME-Version: 1.0\n";
- $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
-
- # -=-=-=- TEXT EMAIL PART
- $message = "--$mime_boundary\n";
- $message .= "Content-Type: text/plain; charset=UTF-8\n";
- $message .= "Content-Transfer-Encoding: 8bit\n\n";
- $message .= $body;
-
- # -=-=-=- HTML EMAIL PART
- //None
- # -=-=-=- FINAL BOUNDARY
- $message .= "--$mime_boundary--\n\n";
- # -=-=-=- SEND MAIL
- $mail_sent = @mail( $to, $subject, $message, $headers );
- Return $mail_sent;
+function replaceByArray($text, $replacements) {
+ foreach ($replacements as $search=>$replace) {
+ $text = str_replace($search, $replace, $text);
+ }
+ return $text;
}
-
-
//Thank you:
//http://snippets.dzone.com/posts/show/196
function relative_date($time) {
@@ -205,5 +272,4 @@ function relative_date($time) { }
}
-htmlFooter();
?>
\ No newline at end of file |