forked from tectronics/ChristianFlatshare
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathemail-actions.php
More file actions
384 lines (328 loc) · 16.4 KB
/
email-actions.php
File metadata and controls
384 lines (328 loc) · 16.4 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<?php
use CFS\Mailer\CFSMailer;
// Autoloader
require_once 'web/global.php';
connectToDB();
$msg = NULL;
if (isset($_GET['id'])) { $id = $_GET['id']; } else { $id = NULL; }
if (isset($_GET['post_type'])) { $post_type = $_GET['post_type']; } else { $post_type = NULL; }
if (isset($_GET['ad_type'])) { $post_type = $_GET['ad_type']; } // backward compatibility; change of ad_type to post_Type
if (isset($_GET['action'])) { $action = $_GET['action']; } else { $action = NULL; }
// If there action we will be affecting a user login
if ($action == "keep_ad" || $action == "suspend_ad" || $action == "unsuspend_ad" || $action == "update_expiry" || $action == "send_controls" ) {
// Ensure we have a valid ad, get user_id & email and do the hash check.
if ($post_type != "offered" && $post_type != "wanted") { $post_type = "offered"; } // if someone toys with the GET string post_type, set to offered
$query = "select user_id from cf_".$post_type." where ".$post_type."_id = '".$id."'";
$result = mysqli_query($GLOBALS['mysql_conn'], $query) or die(mysqli_error());
// Ok, we have a valid user
if (mysqli_num_rows($result)) {
// HASH is the combination of the last_login and email_address
// If HASH is different it means that either the user did login
// or that they have changed their email address. In both cases,
// we do not continue.
$user_id = cfs_mysqli_result($result,0,0);
$query = "select * from cf_users where user_id = '".$user_id."'";
$result = mysqli_query($GLOBALS['mysql_conn'], $query);
$row = mysqli_fetch_assoc($result);
$hash = md5($row['password'].$row['email_address']);
$hash_send_controls = md5($row['password'].$row['email_address'].'send_controls');
if ($action == "send_controls" ) {
if ($hash_send_controls == $_GET['hash']) {
$msg = "PASS";
} else {$msg = "";}
}
else {
if ($hash == $_GET['hash']) {
$msg = "PASS";
} else {$msg = "";}
}
if ($msg != "PASS" ) {
$msg = "invalid_hash";
} else {
// Hash is correct.
if ($action == "keep_ad") {
// Unsuspend advert
$query = "UPDATE cf_".$post_type."
SET suspended = 0,
last_updated_date = NOW()
WHERE ".$post_type."_id = '".$id."'";
$result = mysqli_query($GLOBALS['mysql_conn'], $query);
// Set wanted from / available from to todays date
$query = "UPDATE cf_".$post_type."
SET available_date = DATE_ADD(NOW(),INTERVAL 2 day),
expiry_date = DATE_ADD(CURDATE(),INTERVAL 12 day)
WHERE ".$post_type."_id = '".$id."'
AND available_date < CURDATE()";
$result = mysqli_query($GLOBALS['mysql_conn'], $query);
// Simply change the "last_login" of the user
$query = "update cf_users set last_login = now(), last_updated_date = NOW() where user_id = '".$user_id."'";
$result = mysqli_query($GLOBALS['mysql_conn'], $query);
if ($result) {
$msg = "last_login_updated";
} else {
$msg = "error";
}
}
if ($action == "suspend_ad") {
// Update last login date
$query = "update cf_users set last_login = now(), last_updated_date = NOW() where user_id = '".$user_id."'";
$result = mysqli_query($GLOBALS['mysql_conn'], $query);
// Simply change the "last_login" of the user
$query = "update cf_".$post_type." set suspended = 1, last_updated_date = NOW() where ".$post_type."_id = '".$id."'";
$result = mysqli_query($GLOBALS['mysql_conn'], $query);
if ($result) {
$msg = "suspend_ad";
} else {
$msg = "error";
}
}
if ($action == "unsuspend_ad") {
// Update last login date
$query = "update cf_users set
last_login = NOW(),
last_updated_date = NOW()
where user_id = '".$user_id."'";
$result = mysqli_query($GLOBALS['mysql_conn'], $query);
// Set wanted from / available from to todays date
$query = "UPDATE cf_".$post_type."
SET available_date = DATE_ADD(CURDATE(),INTERVAL 2 day),
expiry_date = DATE_ADD(CURDATE(),INTERVAL 12 day)
WHERE ".$post_type."_id = '".$id."'
AND available_date < CURDATE()";
$result = mysqli_query($GLOBALS['mysql_conn'], $query);
// Unsuspend ad
$query = "update cf_".$post_type." set suspended = 0, last_updated_date = NOW() where ".$post_type."_id = '".$id."'";
$result = mysqli_query($GLOBALS['mysql_conn'], $query);
if ($result) {
$msg = "unsuspend_ad";
} else {
$msg = "error";
}
}
if ($action == "update_expiry") {
// Update last login date
$query = "update cf_users set last_login = now() where user_id = '".$user_id."'";
$result = mysqli_query($GLOBALS['mysql_conn'], $query);
// Simply change the "last_login" of the user
// RD 16-April-2008 changed available_date to SYSDATE+2, so ad look fresh
$query = "UPDATE cf_".$post_type." SET
available_date = DATE_ADD(NOW(),INTERVAL 2 day),
last_updated_date = NOW(),
expiry_date = DATE_ADD(NOW(),INTERVAL 12 day),
suspended = 0
WHERE ".$post_type."_id = '".$id."'";
$result = mysqli_query($GLOBALS['mysql_conn'], $query);
if ($result) {
$msg = "update_expiry";
} else {
$msg = "error";
}
} // End action == update_expiry
if ($action == "send_controls") {
// Send email with control actions
// Send an email to the user about the ad
if ($post_type == "offered") {
$query = "
select
date_format(o.expiry_date,'%M %D') as `expiry_date`,
o.offered_id,
o.postcode,
o.bedrooms_available,
o.bedrooms_total,
o.accommodation_type,
o.building_type,
o.street_name,
o.published,
(CASE IFNULL(o.town_chosen,'NULL')
WHEN 'NULL' THEN j.town
ELSE o.town_chosen
END) as town,
u.first_name,
u.surname,
u.password,
u.email_address
from cf_offered as `o`
left join cf_jibble_postcodes as `j` on j.postcode = SUBSTRING_INDEX(o.postcode,' ',1)
left join cf_users as `u` on u.user_id = o.user_id
where o.offered_id = '".$id."';
";
} else {
$query = "
select
date_format(w.expiry_date,'%M %D') as `expiry_date`,
w.wanted_id,
w.postcode,
w.bedrooms_required,
w.distance_from_postcode,
w.location,
w.published,
u.first_name,
u.surname,
u.password,
u.email_address
from cf_wanted as `w`
left join cf_users as `u` on u.user_id = w.user_id
where w.wanted_id = '".$id."';
";
} // End post type
$result = mysqli_query($GLOBALS['mysql_conn'], $query);
$ad = mysqli_fetch_assoc($result);
$ad_title = getAdTitle($ad, $post_type, FALSE);
$ad_url = getAdURL($ad, $post_type);
// Create the hash of last_login and email_address
$hash = md5($ad['password'].$ad['email_address']);
// Send Email
$CFSMailer = new CFSMailer();
// Get Body
$body = $twig->render('emails/send_controls.html.twig', array(
'first_name' => $ad['first_name'],
'advert' => array('title' => $ad_title, 'url' => $ad_url),
'keep_ad' => 'http://'.SITE.'email-actions.php?action=keep_ad&post_type='.$post_type.'&id='.$ad[$post_type."_id"].'&hash='.$hash,
'suspend_ad' => 'http://'.SITE.'email-actions.php?action=suspend_ad&post_type='.$post_type.'&id='.$ad[$post_type."_id"].'&hash='.$hash,
));
// Set variables
$subject = 'Christian Flatshare - Advert control links';
$to = $ad['email_address'];
$bcc = 'info@christianflatshare.org';
$msg = $CFSMailer->createMessage($subject, $body, $to);
$sent = $CFSMailer->sendMessage($msg);
if ($sent > 0) {
$msg = "advert_controls";
} else {
$msg = "error";
}
} // End action == send_controls
} // End msg != "PASS"
} // End if mysqli_num_rows($result))
} // End $action == "keep_ad" || $action == "suspend_ad" || $action == "unsuspend_ad" || $action == "update_expiry" || $action == "send_controls"
if (!$msg) {
header("Location:index.php"); exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/final-1024.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Christian Flatshare</title>
<!-- InstanceEndEditable -->
<link href="styles/web.css" rel="stylesheet" type="text/css" />
<link href="styles/headers.css" rel="stylesheet" type="text/css" />
<link href="css/global.css" rel="stylesheet" type="text/css" />
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<!-- jQUERY -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
//no conflict jquery
jQuery.noConflict();
</script>
<!-- MooTools -->
<script language="javascript" type="text/javascript" src="includes/mootools-1.2-core.js"></script>
<script language="javascript" type="text/javascript" src="includes/mootools-1.2-more.js"></script>
<script language="javascript" type="text/javascript" src="includes/icons.js"></script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<!-- InstanceParam name="mainContentClass" type="text" value="" -->
</head>
<body>
<div id="canvas">
<?php print $theme['superheader']; ?>
<div id="content">
<?php print $theme['header']; ?>
<div class="" id="mainContent">
<!-- InstanceBeginEditable name="mainContent" -->
<div id="columnLeft">
<?php if ($msg == "invalid_hash") { ?>
<h1 class="mt0 sucess">A problem occurred...</h1>
<p class="error"><br />We are unable to process this request</p>
<p>This incident has been automatically reported to CFS.</p>
<br /><br />
<?php
$CFSMailer = new CFSMailer();
$body = $twig->render('emails/send_controls.html.twig', array(
'first_name' => 'AN ERROR OCCURED - ID='.$id.', POST_TYPE='.$post_type.', AD_TYPE='.$post_type.', ACTION='.$action,
'advert' => array('title' => $ad_title, 'url' => $ad_url),
'keep_ad' => 'http://'.SITE.'email-actions.php?action=keep_ad&post_type='.$post_type.'&id='.$ad[$post_type."_id"].'&hash='.$hash,
'suspend_ad' => 'http://'.SITE.'email-actions.php?action=suspend_ad&post_type='.$post_type.'&id='.$ad[$post_type."_id"].'&hash='.$hash,
));
// Set variables
$subject = 'Christian Flatshare - ERROR';
$to = 'ryanwdavies@gmail.com';
$msg = $CFSMailer->createMessage($subject, $body, $to);
$sent = $CFSMailer->sendMessage($msg);
?>
<?php } else if ($msg == "last_login_updated") { ?>
<h1 class="mt0">Your advert will be kept live</h1>
<p><strong class="success">Your "Last logged in" date has been change to today</strong> </p>
<p><br /><b><?php echo getAdTitleByID($id, $post_type); ?></b></p>
<p>Logging into Christian Flatshare periodically helps to indicate to others that you are still using Christian Flatshare, as the number of days since you last logged in is shown on your advert.</p>
<p>Adverts are automatically suspended and assumed no longer needed when a member does not login for over 30 days.<br /><br /></p>
<!-- <p>You will receive a further "keep or suspend" email if you do not login for 20 days (if you have live adverts then).<br /></p> -->
<?php } else if ($msg == "suspend_ad") { ?>
<h1 class="mt0 sucess">Your advert has been suspended</h1>
<p><br /><b><?php echo getAdTitleByID($id, $post_type); ?></b></p>
<p>You can un-suspend, edit or delete your advert at anytime.</p><br /><br /><br />
<?php } else if ($msg == "advert_controls") { ?>
<h1 class="mt0 sucess">An email has been sent</h1>
<p class="success"><strong>An email has been sent with a link to suspend your advert</strong></p>
<p>You can un-suspend, edit or delete you advert by logging in and going to the "Your ads" page</p><br /><br /><br />
<?php } else if ($msg == "unsuspend_ad") { ?>
<h1 class="mt0 sucess">Your advert has been unsuspended</h1>
<p><br /><b><?php echo getAdTitleByID($id, $post_type); ?></b></p>
<p>You can suspend, edit or delete you advert at anytime when logged in.</p><br /><br /><br />
<?php } else if ($msg == "update_expiry") {
if ($post_type = "offered" ) { ?>
<h1 class="mt0 sucess">Your advert has been updated</h1>
<p><br /><b><?php echo getAdTitleByID($id, $post_type); ?></b></p>
<p class="success"><strong>Your advert's available from date is now today</strong></p>
<p>This helps to indicate that your accommodation is still available. You can edit or delete your advert anytime when logged in.</p><br /><br />
<?php } else if ($post_type = "wanted" ) { ?>
<h1 class="mt0 sucess">Your advert has been updated</h1>
<p class="success"><strong>Your advert's wanted from date is now today</strong></p>
<p>This help to indicate that you are still looking for accommodation. You can edit or delete your advert anytime whtn logged in.</p><br /><br />
<?php } ?>
<?php } else if ($msg == "error") { ?>
<h1 class="mt0">An error occured when updating the database</h1>
<p class="error">Please contact <?php print TECH_EMAIL?>.<br/>We apologise for the invonvenience.</p>
<?php } ?>
<p class="mb0"><a href="index.php">Return to the welcome page</a></p>
</div>
<div id="columnRight">
<?php if (!$_SESSION['u_id']) { ?>
<div class="box_grey mb10">
<div class="tr"><span class="l"></span><span class="r"></span></div>
<div class="mr">
<h2 class="m0">Member Login</h2>
<?php print createLoginForm($email,$password,$remember)?>
</div>
<div class="br"><span class="l"></span><span class="r"></span></div>
</div>
<?php } else { ?>
<?php print $theme['side']; ?>
<?php } ?>
</div>
<div class="cc0"><!----></div>
<!-- InstanceEndEditable -->
</div>
<div class="redMenu">
<ul>
<!--<li><a href="../flat-finding-tips.php">flat finding tips</a></li>-->
<li><a href="advertising.php">advertising</a></li>
<li><a href="where-does-all-the-money-go.php">where does the money go?</a></li>
<li><a href="glossary.php">glossary</a></li>
<li><a href="terms-and-conditions.php">terms & conditions</a></li>
<li><a href="privacy-policy.php">privacy policy</a></li>
<li><a href="contact-us.php">contact us</a></li>
<li class="noSeparator"><a href="resources.php">links & resources</a></li>
</ul>
</div>
<div id="footerText">
<p class="m0"><strong>Christian Flatshare... helping accommodation seekers connect with the local church community<br />
Finding homes, growing churches and building communities </strong>© ChristianFlatShare.org 2007-<?php print date("Y")?></p>
</div>
</div>
<div id="footer"><img src="images/spacer.gif" alt="*" width="1" height="12"/></div>
</div>
<?php if (DEBUG_QUERIES && $debug) { echo sprintf(DEBUG_FORMAT,$debug); }?>
<?php print getTrackingCode();?>
</body>
<!-- InstanceEnd --></html>