/
SportAlert.php
121 lines (64 loc) · 2.17 KB
/
SportAlert.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
<?php
include 'connect.php';
include 'GameDataMiner.php';
# Global parameters
date_default_timezone_set('UTC');
$myTeam = "Warriors";
$link = mysqli_connect("localhost", "ostaton", "Takarajima1", "DB_SportAlert");
# Global email settings
$to = "";
$subject = 'Sport Alert';
$message = "";
makeConnection();
// teamNameInTable($myTeam);
// $array = getAllGamesForTeam($myTeam);
// $array = gamesToday($array);
// print("Today there is a ".$array[0]["TeamName"]." game in ".$array[0]["Location"]."!<br/>");
// print("Be sure to tune in for the game at ".$array[0]["Time"].".<br/>");
# TODO: GET USER PREFERENCES
# For each user
# Check user preference
# Check team data
# Respond if appropriate
$queryUsers = "SELECT * FROM `Users`";
# For each User:
if($resultUsers = mysqli_query($link, $queryUsers)) {
while($userData = mysqli_fetch_array($resultUsers)) {
# Update email info
$to = $userData["Email"];
$message = "Hello ".$userData["UserName"].",\n";
# For each setting ID:
$queryUserSettings = "SELECT * FROM `UserSettings` WHERE `SettingID`='".$userData["SettingID"]."'";
if($resultUserSettings = mysqli_query($link, $queryUserSettings)) {
while($userSettingData = mysqli_fetch_array($resultUserSettings)) {
# Get game information
$tName = $userSettingData["TeamName"];
if(teamNameInTable($tName)) {
$array = getAllGamesForTeam($tName);
if($array[0]["TeamName"] != "") {
$message = $message."Today there is a ".$array[0]["TeamName"]." game in ".$array[0]["Location"]."!\n";
$message = $message."Be sure to tune in for the game at ".$array[0]["Time"].".\n";
}
}
}
}
else {
die("ERROR: unable to access user settings db<br/>");
}
// # Send Notification
// TODO: ENABLE BELOW - production purposes
// if( mail ( $to , $subject , $message)) {
// print "Successfully sent email";
// }
// else {
// die("ERROR: unable to send email");
// }
// TODO: DISABLE BELOW - only for test purposes
print($to."<br/>");
print($message."<br/>");
}
}
else {
die("ERROR: unable to access user db<br/>");
}
?>