-
Notifications
You must be signed in to change notification settings - Fork 7
/
spotegg.php
162 lines (141 loc) · 4.17 KB
/
spotegg.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
<?php
$curl = curl_init();
ob_start();
require './config/config.php';
include'frontend/functions.php';
include("login/auth.php");
$gname = $conn->real_escape_string($_POST['gname']);
$egg = $conn->real_escape_string($_POST['egg']);
$minutes = $conn->real_escape_string($_POST['etime']);
$pulltime = date('H:i:s');
$timeuntilegg = strtotime("+$minutes minutes", strtotime($pulltime));
$newtime = date('Y-m-d H:i:s', $timeuntilegg);
if ($clock=="false"){
$rhour = date('g', $timeuntilegg);
$rampm = date('A');
} else {
$rhour = date('H', $timeuntilegg);
$rampm = '';
}
$rmin = date('i', $timeuntilegg);
$eggby = $conn->real_escape_string($_SESSION['uname']);
// Start queries
// Check if active raid
$checkraid = "SELECT actraid,egg FROM gyms WHERE gid='$gname'";
if(!mysqli_query($conn,$checkraid))
{
echo 'Not Inserted';
}
else
{
echo 'Inserted';
}
$checkresult = $conn->query($checkraid);
$checkrow = $checkresult->fetch_array(MYSQLI_NUM);
$checkactraid = $checkrow[0];
$checkactegg = $checkrow[1];
if($checkactraid == "1") {
echo '<script language="javascript">';
echo 'alert("Cannot submit an Egg while there is an active raid")';
echo '</script>';
header('Refresh: 0; URL=submit-egg.php');
} elseif($checkactegg!=0) {
echo '<script language="javascript">';
echo 'alert("Cannot submit multiple eggs on the same gym")';
echo '</script>';
header('Refresh: 0; URL=submit-egg.php');
} else {
if ($clock=="false"){
$sql = "UPDATE gyms SET egg='$egg',hour='$rhour',min='$rmin',ampm='$rampm',eggby='$eggby',date='$newtime' WHERE gid='$gname'";
if(!mysqli_query($conn,$sql))
{
echo 'Not Inserted';
}
else
{
echo 'Inserted';
}
} else {
$sql = "UPDATE gyms SET egg='$egg',hour='$rhour',min='$rmin',ampm='',eggby='$eggby',date='$newtime' WHERE gid='$gname'";
if(!mysqli_query($conn,$sql))
{
echo 'Not Inserted';
}
else
{
echo 'Inserted';
}
}
// Lookup gymname for webhook
$gymquery = "SELECT gname,glatitude,glongitude FROM gyms WHERE gid = '$gname'";
if(!mysqli_query($conn,$gymquery))
{
echo 'Not Inserted';
}
else
{
echo 'Inserted';
}
$result = $conn->query($gymquery);
$row = $result->fetch_array(MYSQLI_NUM);
$gymname = $row[0];
$gymlat = $row[1];
$gymlon = $row[2];
$siteurl = "[".$viewtitle."](".$viewurl."/?loc=$gymlat,$gymlon&zoom=19)";
if ($clock=="false"){
$date = date('g:i:s A');
} else {
$date = date('H:i:s');
}
$hookObject = json_encode([
"username" => "Egg spotted!",
"tts" => false,
"avatar_url" => "$viewurl/static/eggs/$egg.png",
"embeds" => [
[
"type" => "rich",
"description" => "$siteurl",
"color" => hexdec( "FFFFFF" ),
"footer" => [
"text" => "Spotted at by $eggby at $date",
"icon_url" => "$viewurl/static/eggs/$egg.png"
],
"image" => [
"url" => "http://staticmap.openstreetmap.de/staticmap.php?center=".$gymlat.",".$gymlon."&zoom=17&size=400x400&maptype=mapnik&markers=".$gymlat.",".$gymlon.",red-pushpin",
],
"thumbnail" => [
"url" => "$viewurl/static/eggs/$egg.png",
],
"author" => [
"name" => "Level $egg egg spotted by $eggby",
],
"fields" => [
[
"name" => "Hatches at:",
"value" => "$rhour:$rmin $rampm",
"inline" => true
],
[
"name" => "Gym:",
"value" => "$gymname",
"inline" => true
]
]
]
]
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
$ch = curl_init();
curl_setopt_array( $ch, [
CURLOPT_URL => $egg_webhook_url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $hookObject,
CURLOPT_HTTPHEADER => [
"Length" => strlen( $hookObject ),
"Content-Type" => "application/json"
]
]);
$response = curl_exec( $ch );
curl_close( $ch );
header('Location:index.php?loc='.$gymlat.','.$gymlon.'&zoom=19');
}
?>