-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.php
211 lines (192 loc) · 7.37 KB
/
add.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
<?php
$mysqli = new mysqli('localhost', 'db_username', 'db_password', 'db_name');
$map_id = 0;
if (isset($_GET['map']) && intval($_GET['map']) >= 0) {
$map_id = intval($_GET['map']);
}
$marker_x = -1;
if (isset($_GET['lat']) && intval($_GET['lat']) >= 0) {
$marker_x = intval($_GET['lat']);
}
$marker_y = -1;
if (isset($_GET['lng']) && intval($_GET['lng']) >= 0) {
$marker_y = intval($_GET['lng']);
}
$map = null;
$query = "SELECT * FROM `maps` WHERE `id` = '".$map_id."' OR `id` = '0'";
$result = $mysqli->query($query);
if ($result -> num_rows != 0) {
while ($line = $result->fetch_assoc()) {
$map = $line;
}
}
/* Определение языка страницы */
$lang = "en";
$availableLangs = array("en", "ru");
if (isset($_GET['lang'])) {
if (in_array($_GET['lang'], $availableLangs)) {
setcookie("lang", $_GET['lang'], strtotime( '+30 days' ), '/', "phasmomap.online");
$lang = $_GET['lang'];
} else {
$lang = getLangFromCookie($availableLangs);
}
} else { $lang = getLangFromCookie($availableLangs); }
function getLangFromCookie($availableLangs) {
if (!isset($_COOKIE['lang'])) {
$lang = 'en';
$sites = array(
"en" => "en",
"ru" => "ru",
"be" => "ru",
"uk" => "ru",
"ky" => "ru",
"ab" => "ru",
"mo" => "ru",
"et" => "ru",
"lv" => "ru"
);
// получаем язык
$lang = !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? strtok(strip_tags($_SERVER['HTTP_ACCEPT_LANGUAGE']), ',') : '';
$lang = substr($lang, 0,2);
// проверяем язык
if (!in_array($lang, array_keys($sites))){
$lang = 'en';
}
if (in_array($sites[$lang], $availableLangs)) {
$lang = $sites[$lang];
}
setcookie("lang", $lang, strtotime( '+30 days' ), '/', "phasmomap.online");
return $lang;
} else {
$lang = "en";
if (isset($_COOKIE['lang']) && in_array($_COOKIE['lang'], $availableLangs)) {
$lang = $_COOKIE['lang'];
}
return $lang;
}
}
// Строки локализации
$strings = null;
if (file_exists("tools/langs.json") == 1) {
$strings = json_decode(file_get_contents("tools/langs.json"), true);
} else { exit(); }
$types = array();
$query = "SELECT * FROM `types` WHERE 1";
$result = $mysqli->query($query);
if ($result -> num_rows != 0) {
while ($line = $result->fetch_assoc()) {
array_push($types, $line);
}
}
$maps = array();
$query = "SELECT * FROM `maps` WHERE 1";
$result = $mysqli->query($query);
if ($result -> num_rows != 0) {
while ($line = $result->fetch_assoc()) {
array_push($maps, $line);
}
}
if (isset($_POST['submit'])) {
$lat = $_POST['lat'];
$lng = $_POST['lng'];
$author = $_POST['author'];
$description = $_POST['description'];
$map_id = $_POST['map'];
$type = $_POST['marker'];
$video = $_POST['video'];
$image = $_POST['image'];
$query3 = "INSERT INTO `markers_suggested`(`x`, `y`, `map_id`, `description`, `type`, `image`, `youtube`, `author`) VALUES ('$lat', '$lng', '$map_id', '$description', '$type', '$image', '$video', '$author')";
$result3 = $mysqli->query($query3);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Phasmophobia Interactive Map</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="shortcut icon" href="/tools/images/favicon.ico">
<meta http-equiv="Last-Modified" content="<?php echo file_get_contents('../timestamp.txt');?>">
<meta name="robots" content="noindex" />
<meta name="googlebot" content="noindex" />
<script src="/tools/leaflet/js/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="/tools/css/main.css" />
<link rel="stylesheet" type="text/css" href="/tools/css/custom.css" />
<?php if (isset($_POST['submit'])) { ?><meta http-equiv="refresh" content="5;URL=http://phasmomap.online" /> <? } ?>
<script> top.history.pushState(null, null, `http://phasmomap.online`); </script>
</head>
<body>
<div id="main">
<!-- One -->
<section id="one">
<header class="major">
<h2><?php echo $strings['add_title'][$lang];?></h2>
</header>
<p><?php echo $strings['add_descr_1'][$lang];?></p>
</section>
<?php if (!isset($_POST['submit'])) { ?>
<section>
<form method="post" action="add.php?lat=<?php echo $marker_x;?>&lng=<?php echo $marker_y;?>&map=<?php echo $map_id;?>">
<h4><?php echo $strings['add_position'][$lang];?></h4>
<div class="row gtr-uniform gtr-50">
<div class="col-12">
<select name="map" required="">
<option value="">- <?php echo $strings['add_map'][$lang];?> -</option><?php
foreach ($maps as & $map) {
echo '<option value="'.$map['id'].'"'.($map['id'] == $map_id ? ' selected=""' : '').'>'.json_decode($map['title'], true)[$lang].'</option>';
}
?>
</select>
</div>
<div class="col-6 col-12-xsmall">
<input type="hidden" name="lat" value="<?php echo $marker_x;?>">
<input type="text" value="Lat: <?php echo $marker_x;?>" disabled="">
</div>
<div class="col-6 col-12-xsmall">
<input type="hidden" name="lng" value="<?php echo $marker_y;?>">
<input type="text" value="Lng: <?php echo $marker_y;?>" disabled="">
</div>
<div class="col-12">
<textarea name="description" placeholder="<?php echo $strings['add_field_description'][$lang];?>" rows="3" maxlength="250"></textarea>
</div>
<h4><?php echo $strings['add_info'][$lang];?></h4>
<div class="col-12">
<select name="marker" id="viewSelector" required="">
<option value="">- <?php echo $strings['add_type'][$lang];?> -</option><?php
foreach ($types as & $type) {
echo '<option value="'.$type['id'].'">'.json_decode($type['title'], true)[$lang].'</option>';
}
?>
</select>
</div>
<div class="col-6 col-12-xsmall">
<input type="url" name="image" placeholder="<?php echo $strings['add_field_image'][$lang];?>">
</div>
<div class="col-6 col-12-xsmall">
<input type="url" name="video" placeholder="<?php echo $strings['add_field_video'][$lang];?>">
</div>
<div class="col-12">
<input type="hidden" name="author_id" value="0">
<input type="text" name="author" placeholder="<?php echo $strings['add_field_name'][$lang];?>" required="">
</div>
<div class="col-12">
<ul class="actions">
<li><input type="submit" name="submit" value="<?php echo $strings['add_submit'][$lang];?>" class="primary"></li>
<li><input type="reset" value="Сброс"></li>
</ul>
</div>
</div>
</form>
</section>
<?php } else { ?>
<section>
<header>
<h2><?php echo $strings['add_submit_title'][$lang];?></h2>
</header>
<p><?php echo $strings['add_submit_descr'][$lang];?></p>
</section>
<?php } ?>
</div>
</body>
</html>