forked from kestasjk/webDiplomacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamelistings.php
executable file
·253 lines (196 loc) · 6.5 KB
/
gamelistings.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
<?php
/*
Copyright (C) 2004-2010 Kestas J. Kuliukas
This file is part of webDiplomacy.
webDiplomacy is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
webDiplomacy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with webDiplomacy. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @package Base
* @subpackage Game
*/
require_once('header.php');
require_once(l_r('gamesearch/search.php'));
require_once(l_r('pager/pagergame.php'));
require_once(l_r('objects/game.php'));
require_once(l_r('gamepanel/game.php'));
libHTML::starthtml();
print '<div class="content">';
if ( isset($_REQUEST['find']) )
{
libAuth::resourceLimiter('search games',5);
if(isset($_REQUEST['find']['game']))
$game = $DB->escape($_REQUEST['find']['game']);
if(isset($_REQUEST['find']['member']))
$member = $DB->escape($_REQUEST['find']['member']);
if (isset($_REQUEST['find']['type']) && $_REQUEST['find']['type'] == 'id' )
{
$useID = true;
$game = (int)$game;
$member = (int)$member;
}
else
{
$useID = false;
}
$tabl = $DB->sql_tabl(
'SELECT g.id, g.variantID FROM wD_Games g
INNER JOIN wD_Members m ON ( m.gameID = g.id )
INNER JOIN wD_Users u ON ( u.id = m.userID )
WHERE '.($useID ? 'g.id = '.$game.' AND m.id = '.$member : 'g.name = "'.$game.'" AND u.username = "'.$member.'"' ));
while(list($id, $variantID)=$DB->tabl_row($tabl))
{
$Variant=libVariant::loadFromVariantID($variantID);
$Game = $Variant->Game($id);
print $Game->summary();
print '<div class="hr"></div>';
}
}
function printAndFindTab()
{
global $User, $Misc;
$tabs = array();
if($User->type['User'])
$tabs['My games']=l_t("Active games which you have joined");
$tabs['New']=l_t("Games which haven't yet started");
$tabs['Joinable']=l_t("Games which have open spaces");
$tabs['Active']=l_t("Games which are going on now");
$tabs['Finished']=l_t("Games which have ended");
$tabs['Search']=l_t("The full game listing search panel");
$tab = 'Active';
$tabNames = array_keys($tabs);
if( isset($_REQUEST['gamelistType']) && in_array($_REQUEST['gamelistType'], $tabNames) )
{
$tab = $_SESSION['gamelistType'] = $_REQUEST['gamelistType'];
}
elseif( isset($_SESSION['gamelistType']) && in_array($_SESSION['gamelistType'], $tabNames) )
{
$tab = $_SESSION['gamelistType'];
}
print '<div class="gamelistings-tabs">';
foreach($tabs as $tabChoice=>$tabTitle)
{
print '<a title="'.$tabTitle.'" href="gamelistings.php?page-games=1&gamelistType='.$tabChoice;
if ( $tab == $tabChoice )
{
if ( !isset($_REQUEST['searchOn']) )
print '&searchOn=on';
print '" class="current"';
}
else
print '"';
print '>'.l_t($tabChoice);
switch($tabChoice)
{
case 'New':
case 'Joinable':
case 'Active':
case 'Finished':
print ' (~'.$Misc->{'Games'.$tabChoice}.')';
if ( $tab == $tabChoice ) {
print (isset($_REQUEST['searchOn']) ? ' [click for default]' : ' [click for search]');
}
}
print '</a> ';
}
print '</div>';
return $tab;
}
$tab = printAndFindTab();
$search = new search($tab);
if ( $tab != 'My games' && $tab != 'Search' )
$Pager = new PagerGames('gamelistings.php', $Misc->{'Games'.$tab});
else
$Pager = new PagerGames('gamelistings.php');
$Pager->addArgs('gamelistType='.$tab);
if ( $tab=='Search' or isset($_REQUEST['searchOn']) or isset($_REQUEST['search']) )
{
$Pager->addArgs('searchOn=on');
if ( isset($_REQUEST['search']) )
{
$_SESSION['search-gamelistings.php']=$_REQUEST['search'];
$search->filterInput($_REQUEST['search']);
}
elseif( isset($_SESSION['search-gamelistings.php']) )
$search->filterInput($_SESSION['search-gamelistings.php']);
print '<div style="margin:30px">';
print '<form action="gamelistings.php?gamelistType='.$tab.'&page=1#top" method="post">';
$search->formHTML();
print '</form>';
print '<p><a href="gamelistings.php?page=1" class="light">'.l_t('Close search').'</a></p>';
print '</div>';
libHTML::pagebreak();
print $Pager->pagerBar('top', '<h4>'.l_t('Results:').'</h4>');
print '<div class="hr"></div>';
$gameCount = $search->printGamesList($Pager);
if( $gameCount == 0 )
{
print '<p class="notice">';
if( $Pager->currentPage > 1 )
print l_t('The set of returned games has finished; use the search tab to find specific games.');
else
print l_t('No games found for the given search parameters, try broadening your search.');
print '</p>';
}
}
else
{
libHTML::pagebreak();
print $Pager->pagerBar('top');
print '<div class="hr"></div>';
$gameCount = $search->printGamesList($Pager);
if( $gameCount == 0 )
{
print '<p class="notice">';
if( $Pager->currentPage > 1 )
{
print l_t('The set of returned games has finished; use the search tab to find specific games.');
}
else
{
switch($tab)
{
case 'My games':
print l_t('You are not in any active games, select the "New" tab '.
'to view games that you can join, or if you can\'t find a game you want '.
'to join select "New game" in the menu to create your own.');
break;
case 'New':
print l_t('No new games on the server.').' ';
if($User->type['User'])
print l_t('Select "New game" in the menu to create your own.');
break;
case 'Joinable':
print l_t('No active games with open slots on the server.');
break;
case 'Active':
print l_t('No active games on the server.').' ';
if($User->type['User'])
print l_t('Click the "New" tab to look for new games, '.
'or select "New game" in the menu to create your own.');
break;
case 'Finished':
print l_t('No finished games on the server.');
break;
default:
print l_t('No games were found.');
}
}
print '</p>';
}
}
if ( $gameCount > 1 )
print $Pager->pagerBar('bottom','<a href="#top">'.l_t('Back to top').'</a>');
else
print '<a name="bottom"></a>';
print '</div>';
libHTML::footer();
?>