forked from DBnR1/EDTB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poi.php
256 lines (228 loc) · 8.94 KB
/
poi.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
<?php
/**
* Points of Interest and Bookmarks
*
* No description
*
* @package EDTB\Main
* @author Mauri Kujala <contact@edtb.xyz>
* @copyright Copyright (C) 2016, Mauri Kujala
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
*/
/*
* ED ToolBox, a companion web app for the video game Elite Dangerous
* (C) 1984 - 2016 Frontier Developments Plc.
* ED ToolBox or its creator are not affiliated with Frontier Developments Plc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** @var pagetitle */
$pagetitle = "Points of Interest & Bookmarks";
require_once("" . $_SERVER["DOCUMENT_ROOT"] . "/style/header.php");
require_once("" . $_SERVER["DOCUMENT_ROOT"] . "/add/Poi.php");
/*
* show item
*/
$usable = usable_coords();
$usex = $usable["x"];
$usey = $usable["y"];
$usez = $usable["z"];
/**
* Make items
*
* @param array $arr
* @param string $type
* @param int $i
* @return string
* @author Mauri Kujala <contact@edtb.xyz>
*/
function makeitem($arr, $type, &$i)
{
global $usex, $usey, $usez;
$item_id = $arr["id"];
$item_text = $arr["text"];
$item_name = $arr["item_name"];
$item_system_name = $arr["system_name"];
$item_system_id = $arr["system_id"];
$item_cat_name = $arr["catname"];
$item_coordx = $arr["item_coordx"];
$item_coordy = $arr["item_coordy"];
$item_coordz = $arr["item_coordz"];
if (valid_coordinates($item_coordx, $item_coordy, $item_coordz))
{
$distance = number_format(sqrt(pow(($item_coordx-($usex)), 2)+pow(($item_coordy-($usey)), 2)+pow(($item_coordz-($usez)), 2)), 1)." ly";
}
else
{
$distance = "n/a";
}
// if visited, change border color
$style_override = "";
$visited = mysqli_num_rows(mysqli_query($GLOBALS["___mysqli_ston"], " SELECT id
FROM user_visited_systems
WHERE system_name = '" . mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $item_system_name) . "'
LIMIT 1"));
if ($visited)
{
$style_override = ' style="border-left: 3px solid #3DA822"';
}
if ($i % 2)
{
$tdclass = "dark";
}
else
{
$tdclass = "light";
}
// check if system has screenshots
$screenshots = has_screenshots($item_system_name) ? '<a href="/Gallery.php?spgmGal=' . urlencode($item_system_name) . '" title="View image gallery"><img src="/style/img/image.png" alt="Gallery" style="margin-left:5px;vertical-align:top" /></a>' : "";
// check if system is logged
$loglink = is_logged($item_system_name) ? '<a href="log.php?system=' . urlencode($item_system_name) . '" style="color:inherit" title="System has log entries"><img src="/style/img/log.png" style="margin-left:5px;vertical-align:top" /></a>' : "";
echo '<tr>
<td class="' . $tdclass . '" style="min-width:420px;max-width:500px">
<div class="poi"' . $style_override . '>
<a href="javascript:void(0)" onclick="update_values(\'/get/get' . $type . 'EditData.php?' . $type . '_id=' . $item_id . '\',\'' . $item_id . '\');tofront(\'add' . $type . '\')" style="color:inherit" title="Click to edit entry">';
echo '(' . $distance . ')';
if (!empty($item_system_id))
{
echo '</a> <a title="System information" href="/System.php?system_id=' . $item_system_id . '" style="color:inherit">';
}
elseif ($item_system_name != "")
{
echo '</a> <a title="System information" href="/System.php?system_name=' . urlencode($item_system_name) . '" style="color:inherit">';
}
else
{
echo '</a> <a href="#" style="color:inherit">';
}
if (empty($item_name))
{
echo $item_system_name;
}
else
{
echo $item_name;
}
echo '</a>' . $loglink.$screenshots . '<span class="right" style="margin-left:5px">' . $item_cat_name . '</span><br />';
// make a link if text includes url
/*$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
if (preg_match($reg_exUrl, $item_text, $url))
{
if (mb_strlen($item_text) >= 60)
{
$urli = "" . substr($item_text, 0, 60) . "...";
}
else
{
$urli = $item_text;
}
$item_text = preg_replace($reg_exUrl, "<a href='" . $url[0] . "' target='_BLANK'>" . $urli . "</a> ", $item_text);
}*/
echo nl2br($item_text);
echo '</div></td></tr>';
$i++;
}
/**
* Make item table
*
* @param resource $res
* @param string $type
* @return string
* @author Mauri Kujala <contact@edtb.xyz>
*/
function maketable($res, $type)
{
global $curSys;
$num = mysqli_num_rows($res);
echo '<table>';
if ($num > 0)
{
if (!valid_coordinates($curSys["x"], $curSys["y"], $curSys["z"]))
{
echo "<tr><td class='dark' style='min-width:420px;max-width:500px;'><p><strong>No coordinates for current location, last known location used.</strong></p></td></tr>";
}
$i = 0;
$to_last = array();
while ($arr = mysqli_fetch_assoc($res))
{
echo makeitem($arr, $type, $i);
}
}
else
{
if ($type == "Poi")
{
echo '<tr><td class="dark" style="min-width:420px;max-width:500px"><strong>No points of interest.<br />Click the "Points of Interest" text to add one.</strong></td></tr>';
}
else
{
echo '<tr><td class="dark" style="min-width:420px;max-width:500px"><strong>No bookmarks.<br />Click the allegiance icon on the top left corner to add one.</strong></td></tr>';
}
}
echo '</table>';
}
?>
<div class="entries">
<div class="entries_inner">
<table>
<tr>
<td class="heading" style="min-width:400px"><a href="javascript:void(0)" onclick="tofront('addPoi');update_values('/get/getPoiEditData.php?Poi_id=0');$('#system_33').focus()" title="Add point of interest">Points of Interest</a></td>
<td class="heading" style="min-width:400px">Bookmarks</td>
</tr>
<tr>
<td style="vertical-align:top;padding:0">
<?php
// get poi in correct order
$poi_res = mysqli_query($GLOBALS["___mysqli_ston"], " SELECT SQL_CACHE user_poi.id, user_poi.poi_name AS item_name,
user_poi.system_name, user_poi.text,
IFNULL(user_poi.x, user_systems_own.x) AS item_coordx,
IFNULL(user_poi.y, user_systems_own.y) AS item_coordy,
IFNULL(user_poi.z, user_systems_own.z) AS item_coordz,
edtb_systems.id AS system_id,
user_poi_categories.name AS catname
FROM user_poi
LEFT JOIN edtb_systems ON user_poi.system_name = edtb_systems.name
LEFT JOIN user_poi_categories ON user_poi_categories.id = user_poi.category_id
LEFT JOIN user_systems_own ON user_poi.system_name = user_systems_own.name
ORDER BY -(sqrt(pow((item_coordx-(" . $usex . ")),2)+pow((item_coordy-(" . $usey . ")),2)+pow((item_coordz-(" . $usez . ")),2))) DESC, poi_name, system_name")
or write_log(mysqli_error($GLOBALS["___mysqli_ston"]), __FILE__, __LINE__);
echo maketable($poi_res, "Poi");
?>
</td>
<td style="vertical-align:top;padding:0">
<?php
// get bookmarks
$bm_res = mysqli_query($GLOBALS["___mysqli_ston"], " SELECT SQL_CACHE user_bookmarks.id, user_bookmarks.system_id, user_bookmarks.system_name,
user_bookmarks.comment as text, user_bookmarks.added_on,
IFNULL(edtb_systems.x, user_systems_own.x) AS item_coordx,
IFNULL(edtb_systems.y, user_systems_own.y) AS item_coordy,
IFNULL(edtb_systems.z, user_systems_own.z) AS item_coordz,
user_bm_categories.name AS catname
FROM user_bookmarks
LEFT JOIN edtb_systems ON user_bookmarks.system_name = edtb_systems.name
LEFT JOIN user_bm_categories ON user_bookmarks.category_id = user_bm_categories.id
LEFT JOIN user_systems_own ON user_bookmarks.system_name = user_systems_own.name
ORDER BY -(sqrt(pow((item_coordx-(" . $usex . ")),2)+pow((item_coordy-(" . $usey . ")),2)+pow((item_coordz-(" . $usez . ")),2))) DESC, system_name")
or write_log(mysqli_error($GLOBALS["___mysqli_ston"]), __FILE__, __LINE__);
$i = 0;
echo maketable($bm_res, "Bm");
?>
</td>
</tr>
</table>
</div>
</div>
<?php
require_once("" . $_SERVER["DOCUMENT_ROOT"] . "/style/footer.php");