-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.php
297 lines (244 loc) · 9.43 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
<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of Nevertable .
# Copyright (c) 2004 Francois Guillet and contributors. All rights
# reserved.
#
# Nevertable is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Nevertable 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 General Public License
# along with Nevertable; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ***** END LICENSE BLOCK *****
define('ROOT_PATH', "./");
define('NVRTBL', '1');
include_once ROOT_PATH ."config.inc.php";
include_once ROOT_PATH ."includes/common.php";
include_once ROOT_PATH ."includes/classes.php";
//args process
$args = get_arguments($_POST, $_GET);
if (isset($args['folder']))
$args['folder'] = (integer)$args['folder'];
if (isset($args['sort']))
$args['sort'] = (integer)$args['sort'];
if (isset($args['folder']))
$args['type'] = (integer)$args['type'];
// default values
if(!isset($args['filter']))
$args['filter']='none';
if(isset($args['filter']) && !isset($args['filterval']))
$args['filter']='none';
if(!isset($args['type']))
$args['type'] = get_type_by_name("all");
if(!isset($args['diffview']))
$args['diffview'] = "off";
if(!isset($args['bestonly']))
$args['bestonly'] = "off";
if(!isset($args['newonly']))
$args['newonly'] = get_newonly_by_name("off");
if(!isset($args['levelset_f']))
$args['levelset_f'] = 0; // all by default
if(!isset($args['level_f']))
$args['level_f'] = 0; // all by default
if(!isset($args['folder']))
$args['folder'] = get_folder_by_name("all");
$table = new Nvrtbl();
try {
if(isset($args['link']))
{
$tpl_params['redirect'] = "record.php?id=". $args['link'];
$tpl_params['delay'] = 1;
$table->template->Show('redirect', $tpl_params);
$table->Close();
exit;
}
if(isset($args['to']) && $args['to'] == 'showlinklist')
{
header("Content-Type: text/plain");
echo $_SESSION['download_list'];
exit;
}
/* Configuration of page title */
$tpl_params = array(
"title" => "Nevertable - Neverball Hall of Fame",
);
/* Check permissions */
if (($args['folder'] == get_folder_by_name("incoming")) && !Auth::Check(get_userlevel_by_name("admin")))
throw new Exception($lang['NOT_ADMIN']);
/* Manage events */
if (isset($args['rectocontest']))
{
if ( !Auth::Check(get_userlevel_by_name("admin")) )
throw new Exception($lang['NOT_ADMIN']);
$id=$args['id'];
if (empty($id))
throw new Exception("URL error");
$tpl_params['message_array'] = array();
$rec = new Record($table->db);
$rec->LoadFromId($id);
/* Deplacement */
$ret = $rec->Move(get_folder_by_name("contest"));
/* gestion des records, qqsoit le resultat, des erreurs de $rec->Move etant */
/* non critiques, il peut y avoir modification quand même */
if($rec->GetType()!=get_type_by_name("freestyle"))
{
/* Gestion */
$ret = $table->ManageBestRecords($rec->GetFields(), $rec->GetType());
if ($ret['isbest'])
{
array_push( $tpl_params['message_array'], "This is a new best record !");
array_push( $tpl_params['message_array'], $ret['nb']." record(s) are best records for this level/levelset/type now.");
array_push( $tpl_params['message_array'], $ret['beaten']." record(s) are obsolete.");
}
else
{
array_push( $tpl_params['message_array'], "This record is not the best one ! moved in \"oldones\" !");
}
}
else
{
array_push( $tpl_params['message_array'], "Record moved to contest.");
}
$tpl_params['redirect'] = "index.php?folder=". get_folder_by_name("incoming");
$tpl_params['delay'] = 5;
$table->template->Show('redirect', $tpl_params);
}
else if (isset($args['rectotrash']))
{
if ( !Auth::Check(get_userlevel_by_name("admin")) )
throw new Exception($lang['NOT_ADMIN']);
$id=$args['id'];
$tpl_params['message_array'] = array();
if (empty($id))
throw new Exception("URL error");
$rec = new Record($table->db);
$rec->LoadFromId($id);
/* garde en mémoire l'état du record avant déplacement */
$wasbest = $rec->IsBest();
!$rec->Move(get_folder_by_name("trash"));
/* gestion des records, qqsoit le résultat, des erreurs de $rec->Move étant */
/* non critiques, il peut y avoir modification quand même */
if($rec->GetType()!=get_type_by_name("freestyle"))
{
/* Gestion */
$ret = $table->ManageBestRecords($rec->GetFields(), $rec->GetType());
if ($wasbest)
{
array_push( $tpl_params['message_array'], "This was a best record...");
array_push( $tpl_params['message_array'], $ret['nb']." record(s) are best records for this level/levelset/type now.");
array_push( $tpl_params['message_array'], $ret['imports']." record(s) imported from \"oldones\".");
}
}
array_push( $tpl_params['message_array'], "Record trashed.");
$tpl_params['redirect'] = "index.php?folder=". $args['folder'];
$tpl_params['delay'] = 5;
$table->template->Show('redirect', $tpl_params);
}
else if (isset($args['recdelete']))
{
if ( !Auth::Check(get_userlevel_by_name("admin")) )
throw new Exception($lang['NOT_ADMIN']);
$id=$args['id'];
$tpl_params['message_array'] = array();
if (empty($id))
throw new Exception("URL error");
$rec = new Record($table->db);
$rec->LoadFromId($id);
/* effacement de l'enregistrement de la bdd, plus le fichier */
$rec->Purge(true);
array_push( $tpl_params['message_array'], "Record deleted");
$tpl_params['redirect'] = "index.php?folder=". get_folder_by_name("trash");
$tpl_params['delay'] = 5;
$table->template->Show('redirect', $tpl_params);
}
else
{
$mode_level = false;
/* Level mode */
if (isset($args['level_f']) && isset($args['levelset_f'])
&& ($args['level_f'] > 0) && ($args['levelset_f'] > 0))
{
$mode_level = true;
}
/* Check selection */
if (!($mode_level && ($args['type'] > 0)))
{
$args['diffview'] = "off";
}
else
{
if ( $args['diffview'] == "on")
{
}
}
/* Keep filters */
$nextargs = "index.php?";
if (isset($args['type'])) $nextargs .= "&type=".$args['type'];
if (isset($args['sort'])) $nextargs .= "&sort=".$args['sort'];
if (isset($args['diffview'])) $nextargs .= "&diffview=".$args['diffview'];
if (isset($args['newonly'])) $nextargs .= "&newonly=".$args['newonly'];
if (isset($args['filter'])) $nextargs .= "&filter=".$args['filter'];
if (isset($args['filterval'])) $nextargs .= "&filterval=".$args['filterval'];
if (isset($args['levelset_f'])) $nextargs .= "&levelset_f=".$args['levelset_f'];
if (isset($args['level_f'])) $nextargs .= "&level_f=".$args['level_f'];
if (isset($args['folder'])) $nextargs .= "&folder=".$args['folder'];
$sort = $args['sort'];
/* Récupération de l'option utilisateur de l'ordre de tri par défaut */
if (empty($args['sort']) && !Auth::Check(get_userlevel_by_name("member")))
$sort = get_sort_by_name("old");
else if (empty($args['sort']) && Auth::Check(get_userlevel_by_name("member")))
$sort = $config['opt_user_sort'];
else
$sort = $args['sort'];
$args['sort'] = $sort;
/* Keep list of links */
$_SESSION['download_list'] = "";
$tpl_params['last_comments'] = $table->db->helper->GetLastComments();
/* Affichage normal */
/* ---------------- */
if (!$mode_level)
{
$total = $table->db->helper->CountFilteredRecords($args);
$tpl_params['records'] = $table->db->helper->GetFilteredRecords($args);
$tpl_params['total'] = $total;
/* Configuration of navigation bar */
$tpl_params['page'] = empty($args['page']) ? 1 : $args['page'];
if ($config['limit'] > 0)
$tpl_params['nb_pages'] = ceil($total / $config['limit']);
else
$tpl_params['nb_pages']=1;
$table->template->Show("index", $tpl_params);
}
/* Mode fiche de niveau */
/* -------------------- */
else
{
//$results = $table->db->helper->GetFilteredRecordsLevel($args);
$results = $table->db->helper->GetFilteredRecords($args);
$tpl_params['rec_contest'] = $results;
//$tpl_params['rec_contest'] = $results['rec_contest'];
//$tpl_params['rec_oldones'] = $results['rec_oldones'];
$tpl_params['diffview'] = $args['diffview']=="on" ? true : false;
$tpl_params['level_shot'] = $table->db->helper->GetLevelShot($args['level_f'], $args['levelset_f']);
$table->template->Show("level", $tpl_params);
}
}
//$_SESSION['download_list'] .= replay_link($fields['folder'], $fields['replay'])
}
catch (DBException $ex) {
$table->template->Show('error', array("exception" => $ex));
}
catch (Exception $ex) {
$table->template->Show('error', array("exception" => $ex));
}
$table->Close();
?>