-
Notifications
You must be signed in to change notification settings - Fork 7
/
spotpokemon.php
148 lines (126 loc) · 3.94 KB
/
spotpokemon.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
<?php
$curl = curl_init();
ob_start();
require './config/config.php';
include'frontend/functions.php';
include("login/auth.php");
$pokemon = $conn->real_escape_string($_POST['pokemon']);
$cp = $conn->real_escape_string($_POST['cp']);
$iv = $conn->real_escape_string($_POST['moniv']);
if ($clock=="false"){
$hour = date('g');
$ampm = date('A');
} else {
$hour = date('H');
$ampm = '';
}
$min = date('i');
$latitude = $conn->real_escape_string($_POST['latitude']);
$longitude = $conn->real_escape_string($_POST['longitude']);
$address = $conn->real_escape_string($_POST['addressinput']);
$good = 0;
$bad = 0;
$spotter = $conn->real_escape_string($_SESSION['uname']);
// Start queries
if ($clock=="false"){
$sql = "INSERT INTO spots (pokemon, cp, iv, hour, min, ampm, latitude, longitude, fulladdress, good, bad, spotter) VALUES ('$pokemon','$cp','$iv','$hour','$min','$ampm','$latitude','$longitude','$address','$good','$bad', '$spotter')";
if(!mysqli_query($conn,$sql))
{
echo 'Not Inserted';
}
else
{
echo 'Inserted';
}
} else {
$sql = "INSERT INTO spots (pokemon, cp, iv, hour, min, ampm, latitude, longitude, fulladdress, good, bad, spotter) VALUES ('$pokemon','$cp','$iv','$hour','$min','','$latitude','$longitude','$address','$good','$bad', '$spotter')";
if(!mysqli_query($conn,$sql))
{
echo 'Not Inserted';
}
else
{
echo 'Inserted';
}
}
// Lookup Pokemon name for webhook
$monnamequery = "SELECT monster FROM pokedex WHERE id = '$pokemon'";
if(!mysqli_query($conn,$monnamequery))
{
echo 'Not Inserted';
}
else
{
echo 'Inserted';
}
$result = $conn->query($monnamequery);
$row = $result->fetch_array(MYSQLI_NUM);
$monname = $row[0];
$moncp = $cp."CP";
$siteurl = "[".$viewtitle."](".$viewurl."/?loc=$latitude,$longitude&zoom=19)";
if ($clock=="false"){
$date = date('g:i:s A');
} else {
$date = date('H:i:s');
}
$hookObject = json_encode([
"username" => "$monname spotted!",
"tts" => false,
"avatar_url" => "$viewurl/static/icons/$pokemon.png",
"embeds" => [
[
"type" => "rich",
"description" => "$siteurl",
"color" => hexdec( "FFFFFF" ),
"footer" => [
"text" => "Spotted by $spotter at $date",
"icon_url" => "$viewurl/static/icons/$pokemon.png"
],
"image" => [
"url" => "http://staticmap.openstreetmap.de/staticmap.php?center=".$latitude.",".$longitude."&zoom=17&size=400x400&maptype=mapnik&markers=".$latitude.",".$longitude.",red-pushpin",
],
"thumbnail" => [
"url" => "$viewurl/static/icons/$pokemon.png",
],
"author" => [
"name" => "$monname spotted by $spotter",
],
"fields" => [
[
"name" => "Found:",
"value" => "$hour:$min $ampm",
"inline" => true
],
[
"name" => "CP:",
"value" => "$cp",
"inline" => true
],
[
"name" => "IV:",
"value" => "$iv%",
"inline" => true
],
[
"name" => "Location",
"value" => "$address",
"inline" => true
]
]
]
]
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
$ch = curl_init();
curl_setopt_array( $ch, [
CURLOPT_URL => $pokemon_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='.$latitude.','.$longitude.'&zoom=19');
?>