-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaildemo.php
353 lines (344 loc) · 9.7 KB
/
maildemo.php
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
<?php require("database.php")?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Demo of mail function</title>
</head>
<body>
<?php
/*email for Watchlist and Outbid daily update*/
echo "Notification Email Demo:";
echo "<br>";
$username = "brainyFalcon4";
$user_email = "[email protected]";
/*Notification for outbid */
$querryOutbid = <<<QUERRYTEXT
SELECT *
FROM
(
SELECT
a.AuctionID,
a.ItemName,
a.StartingPrice,
MAX(b.BidPrice) AS 'bidPrice',
IF(
MAX(bidPrice) IS NULL,
a.StartingPrice,
MAX(bidPrice)
) AS 'CurrentPrice'
FROM
auctions a
LEFT JOIN bids b ON a.AuctionID = b.AuctionID
WHERE
(a.EndingTime - CURRENT_TIMESTAMP) > 0
AND a.AuctionID IN (
SELECT
AuctionID
FROM
bids
WHERE
UserName = '{$username}'
GROUP BY
AuctionID
)
GROUP BY
a.AuctionID,
a.ItemName,
a.ItemDescription,
a.StartingPrice,
a.EndingTime
) MaxPriceGlobal
INNER JOIN (
SELECT
AuctionID,
MAX(BidPrice) AS UserMax
FROM
bids
WHERE
UserName = '{$username}'
GROUP BY
AuctionID
) MaxPriceUser ON MaxPriceGlobal.AuctionID = MaxPriceUser.AuctionID
WHERE
MaxPriceGlobal.CurrentPrice != MaxPriceUser.UserMax
ORDER BY
MaxPriceGlobal.AuctionID
QUERRYTEXT;
$resultOutbid = mysqli_query($connectionView, $querryOutbid);
/*Extracting variable for the WatchList*/
$querryWatchList = <<<QUERRYTEXT
SELECT
a.AuctionID,
a.ItemName,
a.StartingPrice,
MAX(b.BidPrice) AS 'bidPrice',
IF(
MAX(bidPrice) IS NULL,
a.StartingPrice,
MAX(bidPrice)
) AS 'CurrentPrice'
FROM
auctions a
LEFT JOIN bids b ON a.AuctionID = b.AuctionID
WHERE
b.BidTime > CURDATE() - INTERVAL 1 DAY
AND b.Bidtime < CURDATE()
AND a.AuctionID IN (
SELECT
AuctionID
FROM
watchlist
WHERE
UserName = '{$username}'
)
GROUP BY
a.AuctionID,
a.ItemName,
a.ItemDescription,
a.StartingPrice,
a.EndingTime
ORDER BY
a.AuctionID
QUERRYTEXT;
$resultWatchList = mysqli_query($connectionView, $querryWatchList);
if (($resultWatchList->num_rows > 0) and ($resultOutbid->num_rows > 0)){
$subject = "Your WatchList and Outbid Update";
echo 'To: ';
echo $user_email;
echo "<br>";
echo 'Subject: ';
echo $subject;
echo "<br>";
$body = "Hello $username, \n";
$body .= "<br>";
if ($resultOutbid->num_rows > 0) {
$body .= "Some of the items you bidded is being outbidded by other user! \n";
$body .= "<br>";
while ($rowOutbid = mysqli_fetch_array($resultOutbid)){
$body .= "The Auction ID: {$rowOutbid['AuctionID']}, Item Name: {$rowOutbid['ItemName']}, Current Price: {$rowOutbid['CurrentPrice']}, Your Max Bid Price: {$rowOutbid['UserMax']} . \n";
$body .= "<br>";
}
}
if ($resultWatchList->num_rows > 0) {
$body .= "Update for Auctions in your watchlist in the last 24 hours \n";
$body .= "<br>";
while ($rowWatchList = mysqli_fetch_array($resultWatchList)){
$body .= "The Auction ID: {$rowWatchList['AuctionID']}, Item Name: {$rowWatchList['ItemName']}, Current Price: {$rowWatchList['CurrentPrice']} .\n";
$body .= "<br>";
}
}
$body .= "Regards, \n";
$body .= "<br>";
$body .= "Auction Team \n";
$body .= "<br>";
echo "body : \n";
echo "<br>";
echo $body;
}
echo "<br>";
echo "Auction Email Demo:";
echo "<br>";
/*email for auction finish daily update*/
/*retrieving all the auction finished yesterday*/
$querryTodayAuctionFinish = <<<QUERRYTEXT
SELECT
a.AuctionID,
a.UserName,
u.Email,
a.ItemName,
a.ReservePrice
FROM
auctions a
JOIN users u
ON u.UserName = a. UserName
WHERE
EndingTime > CURDATE() - INTERVAL 1 DAY
AND EndingTime < CURDATE()
QUERRYTEXT;
$resultTodayAuctionFinish = mysqli_query($connectionView, $querryTodayAuctionFinish);
if ($resultTodayAuctionFinish->num_rows > 0) {
while ($rowFinAuction = mysqli_fetch_array($resultTodayAuctionFinish)){
$Auction_ID = $rowFinAuction['AuctionID'];
$Item_Name = $rowFinAuction['ItemName'];
$Seller = $rowFinAuction['UserName'];
$Seller_Email = $rowFinAuction['Email'];
$Reserve_Price = $rowFinAuction['ReservePrice'];
$querryWinner = <<<QUERRYTEXT
SELECT
b.UserName,
b.bidPrice,
u.Email
FROM
bids b
JOIN users u
ON b.UserName = u.Username
WHERE
b.AuctionID = {$Auction_ID}
ORDER BY
b.BidPrice DESC,
b.BidTime ASC;
QUERRYTEXT;
$resultWinner = mysqli_query($connectionView, $querryWinner);
$rowWinner = mysqli_fetch_array($resultWinner);
$Final_Price = $rowWinner['bidPrice'];
$Buyer = $rowWinner['UserName'];
$Buyer_Email = $rowWinner['Email'];
/*NoBids*/
if ($Final_Price == "") {
/*email to seller if NoBids Occured*/
$subject = "The outcome of Item: {$Item_Name} ID: {$Auction_ID}";
$user_email = $Seller_Email;
echo "<br>";
echo "To Seller:";
echo "<br>";
echo 'To: ';
echo $user_email;
echo "<br>";
echo 'Subject: ';
echo $subject;
echo "<br>";
$body = "The Item: {$Item_Name} ID: {$Auction_ID} ended the auction with no Bids.\n";
$body .= "<br>";
$body .= "Regards, \n";
$body .= "<br>";
$body .= "Auction Team \n";
$body .= "<br>";
echo $body;
$Outcome = "NoBids";
}
/*if buying price is more than the reserve price*/
else if ($Final_Price >= $Reserve_Price) {
/*email to seller*/
$subject = "The outcome of Item: {$Item_Name} ID: {$Auction_ID}";
$user_email = $Seller_Email;
echo "<br>";
echo "To Seller:";
echo "<br>";
echo 'To: ';
echo $user_email;
echo "<br>";
echo 'Subject: ';
echo $subject;
echo "<br>";
$body = "The Item: {$Item_Name} ID: {$Auction_ID} is bidded by {$Buyer} at £{$Final_Price}. Please arrange payment and shipping as soon as possible with buyer's email: {$Buyer_Email}\n";
$body .= "<br>";
$body .= "Regards, \n";
$body .= "<br>";
$body .= "Auction Team \n";
$body .= "<br>";
echo $body;
/*email to buyer*/
$subject = "The outcome of Item: {$Item_Name} ID: {$Auction_ID}";
$user_email = $Buyer_Email;
echo "<br>";
echo "To buyer:";
echo "<br>";
echo 'To: ';
echo $user_email;
echo "<br>";
echo 'Subject: ';
echo $subject;
echo "<br>";
$body = "You win the Bid of The Item: {$Item_Name} ID: {$Auction_ID} from {$Seller} at £{$Final_Price}. Please arrange payment and shipping as soon as possible with seller's email: {$Seller_Email}\n";
$body .= "<br>";
$body .= "Regards, \n";
$body .= "<br>";
$body .= "Auction Team \n";
$body .= "<br>";
echo $body;
$Outcome = "Success";
}
else {
/*email to seller if it don't meet the reserve price*/
$subject = "The outcome of Item: {$Item_Name} ID: {$Auction_ID}";
$user_email = $Seller_Email;
echo "<br>";
echo "To Seller:";
echo "<br>";
echo 'To: ';
echo $user_email;
echo "<br>";
echo 'Subject: ';
echo $subject;
echo "<br>";
$body = "The Item: {$Item_Name} ID: {$Auction_ID} ended the auction at £{$Final_Price}. The bidders failed to meet the reserve price.\n";
$body .= "<br>";
$body .= "Regards, \n";
$body .= "<br>";
$body .= "Auction Team \n";
$body .= "<br>";
echo $body;
/*email to highest bidder beow reserve price*/
$subject = "The outcome of Item: {$Item_Name} ID: {$Auction_ID}";
$user_email = $Buyer_Email;
echo "<br>";
echo "To Lost Buyer:";
echo "<br>";
echo 'To: ';
echo $user_email;
echo "<br>";
echo 'Subject: ';
echo $subject;
echo "<br>";
$body = "You Failed to bid The Item: {$Item_Name} ID: {$Auction_ID}.\n";
$body .= "<br>";
$body .= "Regards, \n";
$body .= "<br>";
$body .= "Auction Team \n";
$body .= "<br>";
echo $body;
$Outcome = "BelowReserve";
}
$updateOucomeQuerry = <<<QUERRYTEXT
UPDATE auctions
SET
Outcome = "{$Outcome}"
WHERE AuctionID = {$Auction_ID};
QUERRYTEXT;
$resultUpdateOutcome = mysqli_query($connectionUpdateOutcome, $updateOucomeQuerry);
//echo $updateOucomeQuerry;
if ($resultUpdateOutcome){
//echo "Updated to Nobids";
}
/* Email To Loser*/
$querryloser = <<<QUERRYTEXT
SELECT
DISTINCT u.Email
FROM
bids b
JOIN users u
ON b.UserName = u.Username
WHERE
b.AuctionID = {$Auction_ID}
AND b.UserName != '{$Buyer}'
ORDER BY
b.BidPrice DESC,
b.BidTime ASC;
QUERRYTEXT;
$resultloser = mysqli_query($connectionView, $querryloser);
while ($rowloser = mysqli_fetch_array($resultloser)){
/*email to loser*/
$subject = "The outcome of Item: {$Item_Name} ID: {$Auction_ID}";
$user_email = $rowloser['Email'];
echo "<br>";
echo "To Lost Buyer:";
echo "<br>";
echo 'To: ';
echo $user_email;
echo "<br>";
echo 'Subject: ';
echo $subject;
echo "<br>";
$body = "You Failed to bid The Item: {$Item_Name} ID: {$Auction_ID}.\n";
$body .= "<br>";
$body .= "Regards, \n";
$body .= "<br>";
$body .= "Auction Team \n";
$body .= "<br>";
echo $body;
}
}
}
?>
</body>
</html>