-
Notifications
You must be signed in to change notification settings - Fork 0
/
xar.php
155 lines (140 loc) · 4.1 KB
/
xar.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
<?php
require('init.php');
if (isset($_POST['action'])) {
if ($_POST['action'] == 'snaps' && $_POST['user_id'] == 'omgang') {
$users = $db->select('users');
foreach ($users as $u) {
$db->insert('events', array(
'type' => 'snaps',
'user_id' => $u['user_id'],
'description' => $u['name'] . ' har drukket en snaps',
'snaps' => 1,
'created' => time(),
));
}
echo '{}';
} else if ($_POST['action'] == 'snaps' && $_POST['user_id']) {
$user = $db->selectRow('users', array('user_id' => $_POST['user_id']));
$db->insert('events', array(
'type' => 'snaps',
'user_id' => $_POST['user_id'],
'description' => $user['name'] . ' har drukket en snaps',
'snaps' => 1,
'created' => time(),
));
echo '{}';
} else if ($_POST['action'] == 'custom' && $_POST['user_id']) {
$user = $db->selectRow('users', array('user_id' => $_POST['user_id']));
$db->insert('events', array(
'type' => 'custom',
'user_id' => $_POST['user_id'],
'description' => $user['name'] .' '. $_POST['description'],
'snaps' => (int)$_POST['snaps'],
'beers' => (int)$_POST['beer'],
'created' => time(),
));
echo '{}';
} else if ($_POST['action'] == 'deleteEvent') {
$db->delete('events', array('event_id' => $_POST['event_id']));
echo '{}';
}
error_log($_POST['action'].' kaldt fra admin af sessionId: ' . $sessionId .' fra IP '.$_SERVER['REMOTE_ADDR']);
exit;
}
?><!doctype html>
<html>
<head>
<title>Admin</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
<script>
jQuery(document).ready(function($) {
$('#snaps').submit(function() {
jQuery.post(window.location.pathname, jQuery(this).serializeArray(), function(result) {
if (result.error) {
alert('Error: ' + result.error);
} else {
window.location.reload(true);
}
}, "json");
return false;
});
$('#custom').submit(function() {
jQuery.post(window.location.pathname, jQuery(this).serializeArray(), function(result) {
if (result.error) {
alert('Error: ' + result.error);
} else {
window.location.reload(true);
}
}, "json");
return false;
});
});
function deleteEvent(event_id) {
jQuery.post(window.location.pathname, {'event_id': event_id, 'action':'deleteEvent'}, function(result) {
if (result.error) {
alert('Error: ' + result.error);
} else {
window.location.reload(true);
}
}, "json");
}
</script>
<h1>Admin</h1>
<h3>Tildel snaps</h3>
<form id="snaps">
<input type="hidden" name="action" value="snaps" />
<select name="user_id">
<option value="">-</option>
<option value="omgang">Omgang</option>
<?
$users = $db->select('users');
foreach ($users as $u) { ?>
<option value="<?=$u['user_id']?>"><?=$u['name']?></option>
<?
}
?>
</select>
<input type="submit" value="Tildel" />
</form>
<h3>Opret freestyle event</h3>
<form id="custom">
<input type="hidden" name="action" value="custom" />
<div>User + description:</div>
<div><select name="user_id">
<option value="">-</option>
<?
$users = $db->select('users');
foreach ($users as $u) { ?>
<option value="<?=$u['user_id']?>"><?=$u['name']?></option>
<?
}
?>
</select>
<input type="text" name="description" autocapitalize="off" /></div>
<div>Beers:</div>
<div><input type="text" name="beer" /></div>
<div>Snaps:</div>
<div><input type="text" name="snaps" /></div>
<div></div>
<input type="submit" value="Opret" />
</form>
<h3>Events</h3>
<table border="1">
<?
$events = $db->query('SELECT * FROM events ORDER BY event_id DESC');
foreach ($events as $e) { ?>
<tr>
<td><?=DateAndTime::formatDateAndTime($e['created'])?></td>
<td><?=$e['description']?></td>
<td><input type="button" value="Slet" onclick="deleteEvent(<?=$e['event_id']?>)" /></td>
</tr>
<?
}
?>
</table>
</body>
</html>