-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathevent_games.php
255 lines (231 loc) · 8.33 KB
/
event_games.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
<?php
require_once 'include/event.php';
require_once 'include/club.php';
require_once 'include/pages.php';
require_once 'include/checkbox_filter.php';
require_once 'include/datetime.php';
define('PAGE_SIZE', GAMES_PAGE_SIZE);
define('FLAG_FILTER_VIDEO', 0x0001);
define('FLAG_FILTER_NO_VIDEO', 0x0002);
define('FLAG_FILTER_RATING', 0x0004);
define('FLAG_FILTER_NO_RATING', 0x0008);
define('FLAG_FILTER_CANCELED', 0x0010);
define('FLAG_FILTER_NO_CANCELED', 0x0020);
define('FLAG_FILTER_DEFAULT', FLAG_FILTER_NO_CANCELED);
class Page extends EventPageBase
{
protected function show_body()
{
global $_page, $_lang;
$result_filter = -1;
if (isset($_REQUEST['results']))
{
$result_filter = (int)$_REQUEST['results'];
if ($result_filter == 0 && !$this->is_manager)
{
$result_filter = -1;
}
}
$filter = FLAG_FILTER_DEFAULT;
if (isset($_REQUEST['filter']))
{
$filter = (int)$_REQUEST['filter'];
}
echo '<p><table class="transp" width="100%"><tr><td>';
echo '<select id="results" onChange="filterChanged()">';
show_option(-1, $result_filter, get_label('All games'));
show_option(1, $result_filter, get_label('Town wins'));
show_option(2, $result_filter, get_label('Mafia wins'));
if ($this->is_manager)
{
show_option(0, $result_filter, get_label('Unfinished games'));
}
echo '</select>';
echo '  ';
show_date_filter();
echo '  ';
show_checkbox_filter(array(get_label('with video'), get_label('rating games'), get_label('canceled games')), $filter, 'filterChanged');
echo '</td></tr></table></p>';
$condition = new SQL(' WHERE g.event_id = ?', $this->event->id);
if ($result_filter < 0)
{
$condition->add(' AND g.result <> 0');
}
else
{
$condition->add(' AND g.result = ?', $result_filter);
}
if ($filter & FLAG_FILTER_VIDEO)
{
$condition->add(' AND g.video_id IS NOT NULL');
}
if ($filter & FLAG_FILTER_NO_VIDEO)
{
$condition->add(' AND g.video_id IS NULL');
}
if ($filter & FLAG_FILTER_RATING)
{
$condition->add(' AND g.is_rating <> 0');
}
if ($filter & FLAG_FILTER_NO_RATING)
{
$condition->add(' AND g.is_rating = 0');
}
if ($filter & FLAG_FILTER_CANCELED)
{
$condition->add(' AND g.is_canceled <> 0');
}
if ($filter & FLAG_FILTER_NO_CANCELED)
{
$condition->add(' AND g.is_canceled = 0');
}
if (isset($_REQUEST['from']) && !empty($_REQUEST['from']))
{
$condition->add(' AND g.start_time >= ?', get_datetime($_REQUEST['from'])->getTimestamp());
}
if (isset($_REQUEST['to']) && !empty($_REQUEST['to']))
{
$condition->add(' AND g.start_time < ?', get_datetime($_REQUEST['to'])->getTimestamp() + 86200);
}
list ($count) = Db::record(get_label('game'), 'SELECT count(*) FROM games g', $condition);
show_pages_navigation(PAGE_SIZE, $count);
$referee_pic =
new Picture(USER_EVENT_PICTURE,
new Picture(USER_TOURNAMENT_PICTURE,
new Picture(USER_CLUB_PICTURE,
new Picture(USER_PICTURE))));
$is_user = is_permitted(PERMISSION_USER);
echo '<table class="bordered light" width="100%">';
echo '<tr class="th darker" align="center"><td width="48"></td><td';
if ($is_user)
{
echo ' colspan="3"';
}
else
{
echo ' colspan="2"';
}
echo '> </td><td width="48">'.get_label('Referee').'</td><td width="48">'.get_label('Result').'</td></tr>';
$query = new DbQuery(
'SELECT g.id, g.user_id, ct.timezone, m.id, nm.name, m.flags, g.start_time, g.end_time - g.start_time, g.result, g.video_id, g.is_rating, g.is_canceled,' .
' t.id, t.name, t.flags,' .
' eu.nickname, eu.flags, tu.flags, cu.flags FROM games g' .
' JOIN clubs c ON c.id = g.club_id' .
' LEFT OUTER JOIN users m ON m.id = g.moderator_id' .
' LEFT OUTER JOIN names nm ON nm.id = m.name_id AND (nm.langs & '.$_lang.') <> 0'.
' JOIN events e ON e.id = g.event_id' .
' LEFT OUTER JOIN tournaments t ON t.id = g.tournament_id' .
' LEFT OUTER JOIN event_users eu ON eu.user_id = m.id AND eu.event_id = g.event_id' .
' LEFT OUTER JOIN tournament_users tu ON tu.user_id = m.id AND tu.tournament_id = g.tournament_id' .
' LEFT OUTER JOIN club_users cu ON cu.user_id = m.id AND cu.club_id = g.club_id' .
' JOIN cities ct ON ct.id = c.city_id',
$condition);
$query->add(' ORDER BY g.end_time DESC, g.id DESC LIMIT ' . ($_page * PAGE_SIZE) . ',' . PAGE_SIZE);
$num = $_page * PAGE_SIZE;
while ($row = $query->next())
{
list (
$game_id, $game_user_id, $timezone, $referee_id, $referee_name, $referee_flags, $start, $duration, $game_result, $video_id, $is_rating, $is_canceled,
$tournament_id, $tournament_name, $tournament_flags,
$event_referee_nickname, $event_referee_flags, $tournament_referee_flags, $club_referee_flags) = $row;
echo '<tr align="center"';
if ($is_canceled || !$is_rating)
{
echo ' class="dark"';
}
echo '>';
echo '<td>' . ++$num . '</td>';
if ($this->is_manager || is_permitted(PERMISSION_OWNER, $game_user_id))
{
echo '<td class="dark" width="90">';
echo '<button class="icon" onclick="mr.deleteGame(' . $game_id . ', \'' . get_label('Are you sure you want to delete the game [0]?', $game_id) . '\')" title="' . get_label('Delete game [0]', $game_id) . '"><img src="images/delete.png" border="0"></button>';
echo '<button class="icon" onclick="mr.editGame(' . $game_id . ')" title="' . get_label('Edit game [0]', $game_id) . '"><img src="images/edit.png" border="0"></button>';
if ($video_id == NULL)
{
echo '<button class="icon" onclick="mr.setGameVideo(' . $game_id . ')" title="' . get_label('Add game [0] video', $game_id) . '"><img src="images/film-add.png" border="0"></button>';
}
else
{
echo '<button class="icon" onclick="mr.deleteVideo(' . $video_id . ', \'' . get_label('Are you sure you want to remove video from the game [0]?', $game_id) . '\')" title="' . get_label('Remove game [0] video', $game_id) . '"><img src="images/film-delete.png" border="0"></button>';
}
echo '</td>';
}
else if ($is_user)
{
echo '<td class="dark" width="30">';
echo '</td>';
}
if ($is_canceled || !$is_rating)
{
echo '<td align="left" style="padding-left:12px;">';
}
else
{
echo '<td align="left" colspan="2" style="padding-left:12px;">';
}
if ($video_id != NULL)
{
echo '<table class="transp" width="100%"><tr><td>';
}
echo '<a href="view_game.php?id=' . $game_id . '&event_id=' . $this->event->id . '&bck=1"><b>' . get_label('Game #[0]', $game_id);
echo '</b><br>' . format_date($start, $timezone, true) . '</a>';
if ($video_id != NULL)
{
echo '</td><td align="right"><a href="javascript:mr.watchGameVideo(' . $game_id . ')" title="' . get_label('Watch game [0] video', $game_id) . '"><img src="images/video.png" width="40" height="40"></a>';
echo '</td></tr></table>';
}
if ($is_canceled)
{
echo '</td><td width="100" class="darker"><b>' . get_label('Canceled');
if (!$is_rating)
{
echo '<br>' . get_label('Non-rating');
}
echo '</b></td>';
}
else if (!$is_rating)
{
echo '</td><td width="100" class="darker"><b>' . get_label('Non-rating') . '</b></td>';
}
echo '</td>';
echo '<td>';
$referee_pic->
set($referee_id, $event_referee_nickname, $event_referee_flags, 'e' . $this->event->id)->
set($referee_id, $referee_name, $tournament_referee_flags, 't' . $this->event->tournament_id)->
set($referee_id, $referee_name, $club_referee_flags, 'c' . $this->event->club_id)->
set($referee_id, $referee_name, $referee_flags);
$referee_pic->show(ICONS_DIR, true, 48);
echo '</td>';
echo '<td>';
switch ($game_result)
{
case GAME_RESULT_PLAYING:
break;
case GAME_RESULT_TOWN:
echo '<img src="images/civ.png" title="' . get_label('town\'s vicory') . '" style="opacity: 0.5;">';
break;
case GAME_RESULT_MAFIA:
echo '<img src="images/maf.png" title="' . get_label('mafia\'s vicory') . '" style="opacity: 0.5;">';
break;
case GAME_RESULT_TIE:
echo '<img src="images/transp.png" width="24" title="' . get_label('tie') . '">';
break;
}
echo '</td></tr>';
}
echo '</table>';
show_pages_navigation(PAGE_SIZE, $count);
}
protected function js()
{
?>
function filterChanged()
{
goTo({results: $('#results').val(), filter: checkboxFilterFlags(), page: 0 });
}
<?php
}
}
$page = new Page();
$page->run(get_label('Games'));
?>