summaryrefslogtreecommitdiffstats
path: root/pages/massemail.php
blob: a86150087b58595e3cf6442bc6f7c3af7a65cb09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
htmlHeader();
?>
<body>
<?php
topbar($Links);

include('./includes/datas.php');
include('./includes/db.inc.php');


if (isset($_POST['massemail']) AND isset($_SESSION['accepted'])) {
	if (!$accepted)
		return;	
	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/db.inc.php";
	$sql = "SELECT `email` FROM `users` 
   WHERE `ID` = '$userID'";
   $result = mysql_query($sql);
	
   $email = mysql_result($result, 0, 'email');
	
	$data['email'] = $email;
	
	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);
	exit;
}


include('./includes/sqli.php');

$res = mysqli_query($mysqli, "SELECT count(*) as _msg FROM `users`");
$row = mysqli_fetch_assoc($res);
echo $row['_msg'];

exit;

function QueueEmail($unsanitizeduserID, $unsanitizedto, $unsanitizedSubject, $unsanitizedBody) {
	
	//Check if there's something in the queue already:
	$sql = "SELECT `userID` FROM emailQueue WHERE '$userID' = ";
	
}

//new table
// emailQueue ID, userID, sent, to, subject, body, dateSubmited, dateSent

$sql = "SELECT `ID`, `displayName`, `dateJoined`, `dateLogin`, `email`, `isAdmin` FROM `users`";
$result = mysql_query($sql);

echo "
<div class='wrapper'>
	<center>
	<h3>MASS EMAIL</h3>
	</center>
";


?>

<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>
</select>
<br /><br />

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" />
</form>


<h3> EXAMPLE SET </h3>

<?

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);

	if ($isAdmin == 1)
		$isAdmin = "Yes";
	else
		$isAdmin = "No";
   

   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>";

}

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;
}



//Thank you:
//http://snippets.dzone.com/posts/show/196
function relative_date($time) {
    $today = strtotime(date('M j, Y'));
    $reldays = ($time - $today)/86400;
    if ($reldays >= 0 && $reldays < 1) {
        return 'Today';
    } else if ($reldays >= 1 && $reldays < 2) {
        return 'Tomorrow';
    } else if ($reldays >= -1 && $reldays < 0) {
        return 'Yesterday';
    }
    if (abs($reldays) < 7) {
        if ($reldays > 0) {
            $reldays = floor($reldays);
            return 'in ' . $reldays . ' day' . ($reldays != 1 ? 's' : '');
        } else {
            $reldays = abs(floor($reldays));
            return $reldays . ' day'  . ($reldays != 1 ? 's' : '') . ' ago';
        }
    }
    if (abs($reldays) < 182) {
        return date('l, F j',$time ? $time : time());
    } else {
        return date('l, F j, Y',$time ? $time : time());
    }
}

htmlFooter();
?>