This repository has been archived by the owner on Sep 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
times.php
280 lines (240 loc) · 9.95 KB
/
times.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?php
$category = "page";
$site = "times";
ini_set('session.gc_maxlifetime', 694201337);
session_set_cookie_params(694201337);
session_start();
include("generic.php");
require dirname(__FILE__) . '/api/database.php';
include("requirelogin.php");
?>
<script>
function createe() {
if (document.getElementById("create").classList.contains("open")) {
document.getElementById("create").classList.remove("open");
} else {
document.getElementById("create").classList.add("open");
}
}
</script>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>TimeHub • Times</title>
<meta name="author" content="name">
<meta name="description" content="none">
<meta name="keywords" content="none">
<link rel="stylesheet" href="<?php echo $category; ?>.css" type="text/css">
<link rel="stylesheet" href="<?php echo $site; ?>.css" type="text/css">
</head>
<body>
<div class="popup" id="create">
<div class="close">
<i class="far fa-times-circle closeb" onclick="createe()"></i>
</div>
<div class="popup-inner">
<h1 class="header">Create a timezone</h1>
<form action="/create" method="post">
<div class="label-cont">
<label class="label2">UTC Offset</label>
<div class="range-value" class="range-value" id="rangeV"></div>
</div>
<div class="range-cont">
<input class="range" type="range" id="offset" name="offset" min="-12" max="14" step="1" value="0">
</div>
<label class="label">Name</label>
<input class="oui-textbox oui-textbox-100 input" type="text" id="name" name="name">
<label class="label">Description</label>
<input class="oui-textbox oui-textbox-100 input" type="text" id="description" name="description">
<!--<div class="switchcont">
<h1 class="switchlabel">
Summer Time
</h1>
<label class="switch">
<input type="checkbox" name="summer">
<span class="slider round"></span>
</label>
</div>-->
<input class="oui-button submit" type="submit" value="Submit">
</form>
</div>
</div>
<div class="popup" id="edit">
<div class="close">
<i class="far fa-times-circle closeb" onclick="editzone(0,0)"></i>
</div>
<div class="popup-inner">
<h1 class="header" id="title">Edit Loading...</h1>
<form action="/edit" method="post">
<input type="hidden" id="id" name="id" value="-1">
<div class="label-cont">
<label class="label2" id="label-edit">UTC Offset</label>
<div class="range-value" class="range-value" id="rangeV-edit"></div>
</div>
<div class="range-cont">
<input class="range" type="range" id="offset-edit" name="offset" min="-12" max="14" step="1"
value="0">
</div>
<label class="label">Name</label>
<input class="oui-textbox oui-textbox-100 input" type="text" id="name-edit" name="name" value="Loading">
<label class="label">Description</label>
<input class="oui-textbox oui-textbox-100 input" type="text" id="description-edit" name="description"
value="Loading">
<!--<div class="switchcont">
<h1 class="switchlabel">
Summer Time
</h1>
<label class="switch">
<input type="checkbox" name="summer">
<span class="slider round"></span>
</label>
</div>-->
<input class="oui-button submit" type="submit" value="Update">
</form>
<form action="/delete" method="post">
<input type="hidden" id="id2" name="id" value="-1">
<div class="delete-nevermind">
<input class="oui-button warning delete submit" type="submit" value="Delete">
<button class="oui-button boredered delete submit" onclick="editzone(0,0); return false;" type="button">Cancel</button>
</div>
</forM>
</div>
</div>
<?php navbar(); ?>
<div class="main-content">
<div class="welcome">
<div class="left">
<h1 class="welcomeback">Welcome back to <span class="time">Time</span><span class="hub">Hub</span></h1>
<h1 class="utctime" id="utctime">It is currently Loading... in UTC.</h1>
</div>
<div class="right">
<i onclick="createe()" class="fas fa-plus-circle add"></i>
</div>
</div>
<div class="times">
<?php
$sql = $mysqli_conection->query("SELECT * FROM `times` WHERE owner = " . $_SESSION['id']);
while ($mp = $sql->fetch_assoc()) {
$id = $mp['id'];
$name = htmlspecialchars($mp['name']);
$desc = htmlspecialchars($mp['description']);
$offset = htmlspecialchars($mp['offset']);
$summer = htmlspecialchars($mp['summer']);
if($summer == 1){
$offset++;
}
?>
<div class="time-panel" id="time">
<div class="time-panel-inner">
<div class="info">
<p class="name large"><?php echo $name; ?></p>
<?php if($desc != ""){ ?>
<p class="desc small"><?php echo $desc; ?></p>
<?php } ?>
</div>
<div class="thetime">
<p class="time large paneltime" offset="<?php echo $offset; ?>">Loading...</p>
<p class="timezone small">UTC+<?php echo $offset; ?>
<?php if($summer == 1){
echo " (Summer)";
} ?></p>
</div>
</div>
<div class="edit" onclick="editzone(<?php echo $id; ?>, '<?php echo $_SESSION['wkey']; ?>');">
<div class="editbut">
<i class="fas fa-pen"></i>
</div>
</div>
</div>
<?php } ?>
</div>
<div class="footer">
<p class="footer-text">© UNTONE & Hubz, 2020</p>
</div>
</div>
</body>
<script>
function editzone(id, wkey) {
if (document.getElementById("edit").classList.contains("open")) {
document.getElementById("edit").classList.remove("open");
} else {
console.log("id:" + id);
console.log("wkey:" + id);
console.log("contacting api...");
var url = "https://timehub.hubza.co.uk/api/get_time?wkey=" + wkey + "&id=" + id;
var request = new XMLHttpRequest()
request.open('GET', url, true)
request.onload = function() {
var data = JSON.parse(this.response)
console.log(data.name);
offset = document.getElementById("offset-edit");
namee = document.getElementById("name-edit");
description = document.getElementById("description-edit");
title = document.getElementById("title");
ido = document.getElementById("id");
ido2 = document.getElementById("id2");
offset.value = parseInt(data.offset); //changes the value
namee.value = data.name; //changes the value
description.value = data.description; //changes the value
ido.value = id;
ido2.value = id;
title.innerHTML = "Edit " + data.name;
document.getElementById("edit").classList.add("open");
setValuee();
}
request.send();
}
}
const
range = document.getElementById('offset'),
rangeV = document.getElementById('rangeV'),
setValue = () => {
const
newValue = Number((range.value - range.min) * 100 / (range.max - range.min)),
newPosition = 10 - (newValue * 0.2);
rangeV.innerHTML = `<span>${range.value}</span>`;
rangeV.style.left = `calc(${newValue}% + (${newPosition}px))`;
};
document.addEventListener("DOMContentLoaded", setValue);
range.addEventListener('input', setValue);
const
rangee = document.getElementById('offset-edit'),
rangeVe = document.getElementById('rangeV-edit'),
setValuee = () => {
const
newValue = Number((rangee.value - rangee.min) * 100 / (rangee.max - rangee.min)),
newPosition = 10 - (newValue * 0.2);
rangeVe.innerHTML = `<span>${rangee.value}</span>`;
rangeVe.style.left = `calc(${newValue}% + (${newPosition}px))`;
};
document.addEventListener("DOMContentLoaded", setValuee);
rangee.addEventListener('input', setValuee);
function calcTime(offset) {
// create Date object for current location
var d = new Date();
// convert to msec
// subtract local time zone offset
// get UTC time in msec
var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
// create new Date object for different city
// using supplied offset
var nd = new Date(utc + (3600000 * offset));
// return time as a string
return nd.toLocaleString([], {
hour: '2-digit',
minute: '2-digit'
});
}
var times = document.getElementsByClassName("paneltime");
function go() {
document.getElementById("utctime").innerHTML = "It is currently " + calcTime(0) + " in UTC";
for (i = 0; i < times.length; i++) {
var offset = times[i].getAttribute('offset');
times[i].innerHTML = calcTime(offset);
}
}
go();
setInterval(function() {
go();
}, 5000);
</script>