-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
362 lines (330 loc) · 14 KB
/
index.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?php
/*
* Erstellt im Juni 2019 von Tim Weber (HSH, 1007)
* auf Grundlage der Statusseite von Daniel Frejek (HSH, 1525)
* Letzte Änderung: 05.09.2019
*/
$weekdays = ['so', 'mo', 'di', 'mi', 'do', 'fr', 'sa'];
$days_from_monday = [6, 0, 1, 2, 3, 4, 5];
include('sql_config.php');
$db = mysqli_connect($sql_host, $sql_username, $sql_password, $sql_dbname);
if(!$db) exit('Database connection error: '.mysqli_connect_error());
// Datenbankabfrage aktueller Wochenplan
$sql = 'SELECT * FROM schedules WHERE calendar_week = ? AND year = ?';
$sql_query = mysqli_prepare($db, $sql);
if (!$sql_query) die('ERROR: Failed to prepare SQL.');
mysqli_stmt_bind_param($sql_query, 'is', date('W'), date('Y'));
mysqli_stmt_execute($sql_query);
$current_schedule = mysqli_fetch_assoc(mysqli_stmt_get_result($sql_query));
mysqli_stmt_close($sql_query);
// Datenbankabfrage Mitarbeiter
$sql = 'SELECT id, first_name, display_name FROM employees WHERE deleted = 0';
$sql_query = mysqli_prepare($db, $sql);
if (!$sql_query) die('ERROR: Failed to prepare SQL.');
mysqli_stmt_execute($sql_query);
$employees = mysqli_stmt_get_result($sql_query);
mysqli_stmt_close($sql_query);
$employee_names = [];
foreach($employees as $employee){
if(!empty($employee['display_name']))
$employee_names[$employee['id']] = $employee['display_name'];
else
$employee_names[$employee['id']] = $employee['first_name'];
}
// Datenbankabfrage Settings
$sql = 'SELECT title, value FROM settings';
$sql_query = mysqli_prepare($db, $sql);
if (!$sql_query) die('ERROR: Failed to prepare SQL:<br>'.$sql);
mysqli_stmt_execute($sql_query);
$results = mysqli_stmt_get_result($sql_query);
mysqli_stmt_close($sql_query);
$settings = [];
foreach($results as $result){
$settings[$result['title']] = $result['value'];
}
// Datenbankabfrage Status Manhattan
$sql = 'SELECT date, status FROM openstatus ORDER BY date DESC LIMIT 1';
$sql_query = mysqli_prepare($db, $sql);
if (!$sql_query) die('ERROR: Failed to prepare SQL:<br>'.$sql);
mysqli_stmt_execute($sql_query);
$result = mysqli_stmt_get_result($sql_query);
if (mysqli_num_rows($result) == 0) die('db result empty!');
$row = mysqli_fetch_assoc($result);
mysqli_stmt_close($sql_query);
$status = $row['status'];
$lastrefreshed = $row['date'];
echo '<!--Last status: '. $status. ' updated: '. $lastrefreshed. ' -->';
$lrd = strtotime($lastrefreshed);
$diff = time() - $lrd;
if ($status != 0 && $diff > 43200){
echo '<!--WARNING: Assuming CLOSED because the last status update is older than twelve hours! -->';
$status = 0;
}
// Datenbankabfrage Limit der Bestellungen erreicht?
$sold_out = true;
// Prüfe Anzahl der Slots
$sql = "SELECT COUNT(DISTINCT slot) as slot_amount FROM orders WHERE deleted = 0 AND DATE(date) = '" . date('Y-m-d') . "'";
$sql_query = mysqli_prepare($db, $sql);
if (!$sql_query) die('ERROR: Failed to prepare SQL:<br>'.$sql);
mysqli_stmt_execute($sql_query);
$result = mysqli_stmt_get_result($sql_query);
$row = mysqli_fetch_assoc($result);
mysqli_stmt_close($sql_query);
$slot_amount = $row['slot_amount'];
$sql = "SELECT (COUNT(*) < ".$settings['order_max_slot'].") as free FROM orders WHERE deleted = 0 AND DATE(date) = '" . date('Y-m-d') . "' AND slot = ?";
for($i=0; $i<$slot_amount; $i++){
$sql_query = mysqli_prepare($db, $sql);
if (!$sql_query) die('ERROR: Failed to prepare SQL:<br>'.$sql);
mysqli_stmt_bind_param($sql_query, 'i', $i);
mysqli_stmt_execute($sql_query);
$result = mysqli_stmt_get_result($sql_query);
$row = mysqli_fetch_assoc($result);
mysqli_stmt_close($sql_query);
$slot_has_space = $row['free'];
if($slot_has_space)
$sold_out = false;
}
// Workaround for currently defunct switch
// Also works for cases in which employees forget to use switch
// Open between 19:00 and 00:00
if ($status == 0 && $current_schedule[$weekdays[date('w')].'_open'] && date('G')>=19){
$status = 3;
}
if ($status == 1){
$fcolor = '#000';
$titlestatus = 'Geöffnet';
$desc = 'Wir haben geöffnet!<br>Die Dachterrasse bleibt heute geschlossen.';
if(empty($current_schedule))
$desc .= '<br>Der aktuelle Plan kommt bald.<br><br><br><br>';
}
else if ($status == 2){
$fcolor = '#000';
$titlestatus = 'Dachterrasse geöffnet';
$desc = 'Die Dachterrasse ist geöffnet!';
if(empty($current_schedule))
$desc .= '<br>Der aktuelle Plan kommt bald.<br><br><br><br>';
}
else if ($status == 3){
$fcolor = '#000';
$titlestatus = 'Geöffnet';
$desc = 'Wir haben geöffnet!';
if(empty($current_schedule))
$desc .= '<br>Der aktuelle Plan kommt bald.<br><br><br><br>';
}
else{
$fcolor = '#B62B4C';
$titlestatus = 'Geschlossen';
$desc = 'Aktuell geschlossen.';
if(empty($current_schedule))
$desc .= '<br>Der aktuelle Plan kommt bald.<br><br><br><br>';
elseif($current_schedule[$weekdays[date('w')].'_open'])
$desc .= '<br>Wir öffnen heute um 19 Uhr.';
else
$desc = 'Heute bleiben wir geschlossen.';
}
// Ende der Datenbankabfrage
function calc_time(){
global $status;
// Vor 10 Uhr vormittags: Manhattan noch offen? -> Special von gestern noch aktuell, sonst heutiges
if($status != 0 && intval(date('G'))<10)
return time()-(24*60*60);
else
return time();
}
function get_event(){
global $current_schedule, $weekdays;
if (isset($current_schedule) && isset($current_schedule[$weekdays[date('w', calc_time())].'_event']))
return $current_schedule[$weekdays[date('w', calc_time())].'_event'];
else
return '';
}
function get_deal(){
global $current_schedule, $weekdays;
if (isset($current_schedule) && isset($current_schedule[$weekdays[date('w', calc_time())].'_deal']))
return $current_schedule[$weekdays[date('w', calc_time())].'_deal'];
else
return '';
}
function get_theke(){
global $current_schedule, $weekdays, $employee_names;
if (isset($current_schedule) && isset($current_schedule[$weekdays[date('w', calc_time())].'_theke']))
return $employee_names[$current_schedule[$weekdays[date('w', calc_time())].'_theke']];
else
return '';
}
function get_springer(){
global $current_schedule, $weekdays, $employee_names;
if (isset($current_schedule) && isset($current_schedule[$weekdays[date('w', calc_time())].'_springer']))
return $employee_names[$current_schedule[$weekdays[date('w', calc_time())].'_springer']];
else
return '';
}
function get_kueche(){
global $current_schedule, $weekdays, $employee_names;
if (isset($current_schedule) && isset($current_schedule[$weekdays[date('w', calc_time())].'_kueche']))
return $employee_names[$current_schedule[$weekdays[date('w', calc_time())].'_kueche']];
else
return '';
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="stylesheets/style.css" type="text/css" media="all">
<?php switch ($settings['stylesheet_id']) {
case '1': echo('<link rel="stylesheet" href="stylesheets/winter.css" type="text/css" media="all">');
break;
case '2': echo('<link rel="stylesheet" href="stylesheets/summer.css" type="text/css" media="all">');
break;
} ?>
<link rel="stylesheet" href="fonts/fork-awesome/css/fork-awesome.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>Manhattan - <?php echo($titlestatus); ?></title>
</head>
<body>
<div class="content">
<?php switch ($settings['stylesheet_id']) {
case '1': echo('<div class="snow" id="snow-down"></div><div class="snow" id="snow-left"></div><div class="snow" id="snow-right"></div>');
break;
case '2': echo('<div class="palmtree-spacer"></div><div class="palmtree"><img src="images/palmtree.png"></div>');
break;
} ?>
<div class="logo">
<img src="images/logo.png">
</div>
<!--
<div class="status textbox">
<h3 style='color: <?php echo($fcolor) ?>'><?php echo($desc) ?></h3>
</div>
-->
<?php if(!empty($current_schedule)){
if(!empty(get_event()) || !empty(get_deal())){ ?>
<div class="textbox subtitle">
<br><br>
<h4>Heute, ab 19 Uhr:</h4>
</div>
<div class="textbox title">
<?php
$acc1='';
if(!empty(get_event()))
$acc1.=get_event();
if(!empty(get_event()) && !empty(get_deal()))
$acc1.='<br>';
if(!empty(get_deal()))
$acc1.=get_deal();
echo('<h2>'.$acc1.'</h2>');
?>
</div>
<div class="textbox subtitle">
<?php
$acc2='';
if(!empty(get_theke()) || !empty(get_springer()) || !empty(get_kueche())){
$acc2.='mit ';
if(!empty(get_kueche()))
$acc2.=get_kueche();
if(!empty(get_kueche()) && !empty(get_theke()) && empty(get_springer()))
$acc2.=' & ';
if(!empty(get_kueche()) && !empty(get_theke()) && !empty(get_springer()))
$acc2.=', ';
if(!empty(get_theke()))
$acc2.=get_theke();
if(!empty(get_springer()))
$acc2.=' & '.get_springer();
echo('<h3>'.$acc2.'</h3>');
}
?>
</div>
<?php }
if (!$current_schedule['mo_open'] && !$current_schedule['di_open'] && !$current_schedule['mi_open'] && !$current_schedule['do_open'] && !$current_schedule['fr_open'] && !$current_schedule['sa_open'] && !$current_schedule['so_open']){ ?>
<div class="textbox subtitle" style="margin-top: 100px; margin-bottom: 200px;">
<h3><?php echo $settings['away_text'] ?></h3>
<?php if (date('w') == $settings['order_weekday'] && (date('H:i') >= date('H:i', strtotime($settings['order_opentime']))) && (date('H:i') < date('H:i', strtotime($settings['order_closetime'])))) { ?>
<?php // If sold out display inactive button
if ($sold_out){ ?>
<div class="sold-out-button">
<h3>Für heute ausverkauft <i class="fa fa-frown-o" aria-hidden="true"></i></h3>
</div>
<div class="textbox subtitle">
<h3>Heute haben wir bereits alle Hände voll zu tun. Danke für die vielen Bestellungen!</h3>
</div>
<?php } else { ?>
<div class="go-to-order-button" onclick="location.href='bestellen/'">
<h3>Zum Bestellformular <i class="fa fa-arrow-right" aria-hidden="true"></i></h3>
</div>
<?php } ?>
<?php } ?>
</div>
<?php } else { ?>
<div class="textbox wochenplan">
<table>
<?php for($i=1; $i<8; $i++){ ?>
<tr id="<?php echo($weekdays[$i%7]) ?>">
<td style="width: 40px">
<?php echo ucfirst($weekdays[$i%7]) ?><br>
<a style="font-size: 8pt">
<?php echo date('j.n.', time()-($days_from_monday[date('w')]*24*60*60)+($i-1)*24*60*60) ?>
</a>
</td>
<td id="<?php echo($weekdays[$i%7].'_daily') ?>">
<?php
if(!$current_schedule[$weekdays[$i%7].'_open']){
echo('<span class="closed">geschlossen</span>');
}else{
if(empty($current_schedule[$weekdays[$i%7].'_deal']) && empty($current_schedule[$weekdays[$i%7].'_event']))
echo('geöffnet');
if(!empty($current_schedule[$weekdays[$i%7].'_event']))
echo('<span id="'.$weekdays[$i%7].'_event">'.$current_schedule[$weekdays[$i%7].'_event'].'</span>');
if(!empty($current_schedule[$weekdays[$i%7].'_event']) && !empty($current_schedule[$weekdays[$i%7].'_deal']))
echo('<br>');
if(!empty($current_schedule[$weekdays[$i%7].'_deal']))
echo('<span id="'.$weekdays[$i%7].'_deal">'.$current_schedule[$weekdays[$i%7].'_deal'].'</span>');
}
?><br>
</td>
<td id="<?php echo($weekdays[$i%7].'_team') ?>">
<?php
if($current_schedule[$weekdays[$i%7].'_open']){
if(!empty($current_schedule[$weekdays[$i%7].'_kueche'])) echo($employee_names[$current_schedule[$weekdays[$i%7].'_kueche']]);
if(!empty($current_schedule[$weekdays[$i%7].'_kueche']) && !empty($current_schedule[$weekdays[$i%7].'_theke']) && !empty($current_schedule[$weekdays[$i%7].'_springer'])) echo(', <br>');
if(!empty($current_schedule[$weekdays[$i%7].'_kueche']) && !empty($current_schedule[$weekdays[$i%7].'_theke']) && empty($current_schedule[$weekdays[$i%7].'_springer'])) echo(' & ');
if(!empty($current_schedule[$weekdays[$i%7].'_theke'])) echo($employee_names[$current_schedule[$weekdays[$i%7].'_theke']]);
if(!empty($current_schedule[$weekdays[$i%7].'_springer'])) echo(' & '.$employee_names[$current_schedule[$weekdays[$i%7].'_springer']]);
}
?>
</td>
</tr>
<?php } ?>
</table>
</div>
<?php }
} ?>
<div class="skyline">
<div class="skyline-image-div">
<img class="wheel" src="images/wheel2.svg">
<img class="skyline-image" src="images/skyline_night.png">
</div>
<div class="skyline-spacer"></div>
</div>
</div>
<div class="footer">
<?php echo $settings['footer_text'] ?>
<div class="social-icons">
<?php if($settings['facebook_icon'] && !empty($settings['facebook_url'])){ ?>
<a title="Facebook" href="<?php echo $settings['facebook_url'] ?>"><i class="fa fa-facebook-official"></i></a>
<?php } ?>
<?php if($settings['messenger_icon'] && !empty($settings['messenger_url'])){ ?>
<a title="Facebook Messenger" href="<?php echo $settings['messenger_url'] ?>"><i class="fa fa-facebook-messenger"></i></a>
<?php } ?>
<?php if($settings['instagram_icon'] && !empty($settings['instagram_url'])){ ?>
<a title="Instagram" href="<?php echo $settings['instagram_url'] ?>"><i class="fa fa-instagram"></i></a>
<?php } ?>
<?php if($settings['email_icon'] && !empty($settings['email_url'])){ ?>
<a title="Mail" href="mailto:<?php echo $settings['email_url'] ?>"><i style="font-size:95%" class="fa fa-envelope"></i></a>
<?php } ?>
<?php if($settings['wiki_icon'] && !empty($settings['wiki_url'])){ ?>
<a title="StuStaNet-Wiki" href="<?php echo $settings['wiki_url'] ?>"><i class="fa fa-book"></i></a>
<?php } ?>
</div>
</div>
</body>
</html>