2 /************************************************************************
3 * MXChange v0.2.1 Start: 06/29/2004 *
4 * ================ Last change: 02/11/2005 *
6 * -------------------------------------------------------------------- *
7 * File : what-list_rallyes.php *
8 * -------------------------------------------------------------------- *
9 * Short description : List existing rallyes *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Bestehende Rallyes auflisten *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
43 if (!REQUEST_ISSET_GET(('sub'))) REQUEST_SET_GET('sub', "");
46 // Quick actions on a rallye
47 if (REQUEST_ISSET_GET(('rallye'))) {
51 if (REQUEST_ISSET_GET(('activate'))) {
52 // Activate / deactivate
53 switch (REQUEST_GET('activate'))
56 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET is_active='Y' WHERE id=%s AND is_active='N' LIMIT 1");
59 case "0": // Deactivate
60 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET is_active='N' WHERE id=%s AND is_active='Y' LIMIT 1");
63 } elseif (REQUEST_ISSET_GET(('notify'))) {
64 // Automatic notification
65 switch (REQUEST_GET('notify'))
68 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET send_notify='Y' WHERE id=%s AND send_notify='N' LIMIT 1");
71 case "0": // Deactivate
72 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET send_notify='N' WHERE id=%s AND send_notify='Y' LIMIT 1");
75 } elseif (REQUEST_ISSET_GET(('auto'))) {
76 // Automatic adding of new members
77 switch (REQUEST_GET('auto'))
80 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET auto_add_new_user='Y' WHERE id=%s AND auto_add_new_user='N' LIMIT 1");
83 case "0": // Deactivate
84 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET auto_add_new_user='N' WHERE id=%s AND auto_add_new_user='Y' LIMIT 1");
90 runFilterChain('run_sqls');
91 } elseif (REQUEST_ISSET_POST(('remove'))) {
93 $SEL = SELECTION_COUNT(REQUEST_POST('sel'));
98 // Delete selected rallyes and all it's data
99 foreach (REQUEST_POST('sel') as $id => $selected) {
100 // Remove selected rallye entirely...
101 ADD_SQL(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_rallye_data` WHERE id=%s LIMIT 1",
102 array(bigintval($id)), __FILE__, __LINE__, false));
103 ADD_SQL(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE rallye_id=%s",
104 array(bigintval($id)), __FILE__, __LINE__, false));
105 ADD_SQL(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_rallye_users` WHERE rallye_id=%s",
106 array(bigintval($id)), __FILE__, __LINE__, false));
110 runFilterChain('run_sqls');
113 $MSG = getMessage('RALLYE_DELETED');
115 // No rallye selected to delete!
116 $MSG = getMessage('RALLYE_DELETE_NOTHING_SELECTED');
118 } elseif (REQUEST_ISSET_POST(('change'))) {
120 $SEL = SELECTION_COUNT(REQUEST_POST('title'));
125 // Change selected rallyes and all it's data
126 foreach (REQUEST_POST('title') as $id => $title) {
128 $id = bigintval($id);
130 // Generate timestamps
131 $START = mktime(REQUEST_POST('start_hour', $id), REQUEST_POST('start_min', $id), REQUEST_POST('start_sec', $id), REQUEST_POST('start_month', $id), REQUEST_POST('start_day', $id), REQUEST_POST('start_year', $id));
132 $END = mktime(REQUEST_POST('end_hour', $id) , REQUEST_POST('end_min', $id) , REQUEST_POST('end_sec', $id) , REQUEST_POST('end_month', $id) , REQUEST_POST('end_day', $id) , REQUEST_POST('end_year', $id) );
135 ADD_SQL(SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET
143 WHERE id='".$id."' LIMIT 1",
146 REQUEST_POST('descr', $id),
147 REQUEST_POST('templ', $id),
150 bigintval(REQUEST_POST('min_users', $id)),
151 bigintval(REQUEST_POST('min_prices', $id)),
153 ), __FILE__, __LINE__, false));
157 runFilterChain('run_sqls');
160 $MSG = getMessage('RALLYE_CHANGED');
164 if (REQUEST_ISSET_POST('edit')) {
165 // Check for selections
166 $SEL = SELECTION_COUNT(REQUEST_POST('sel'));
168 // Make all selected and deactivated rallyes editable
170 foreach (REQUEST_POST('sel') as $id => $selected) {
171 // Load rallye basic data
172 $result = SQL_QUERY_ESC("SELECT title, descr, template, start_time, end_time, min_users, min_prices
173 FROM `{!_MYSQL_PREFIX!}_rallye_data`
176 array(bigintval($id)), __FILE__, __LINE__);
178 $content = SQL_FETCHARRAY($result);
181 SQL_FREERESULT($result);
184 $content['s_sec'] = ADD_SELECTION("sec" , date("s", $content['start_time']), "start", $id);
185 $content['s_min'] = ADD_SELECTION("min" , date("i", $content['start_time']), "start", $id);
186 $content['s_hour'] = ADD_SELECTION("hour" , date("G", $content['start_time']), "start", $id);
187 $content['s_day'] = ADD_SELECTION("day" , date("d", $content['start_time']), "start", $id);
188 $content['s_month'] = ADD_SELECTION("month", date("m", $content['start_time']), "start", $id);
189 $content['s_year'] = ADD_SELECTION("year" , date('Y', $content['start_time']), "start", $id);
192 $content['e_sec'] = ADD_SELECTION("sec" , date("s", $content['end_time']) , "end" , $id);
193 $content['e_min'] = ADD_SELECTION("min" , date("i", $content['end_time']) , "end" , $id);
194 $content['e_hour'] = ADD_SELECTION("hour" , date("G", $content['end_time']) , "end" , $id);
195 $content['e_day'] = ADD_SELECTION("day" , date("d", $content['end_time']) , "end" , $id);
196 $content['e_month'] = ADD_SELECTION("month", date("m", $content['end_time']) , "end" , $id);
197 $content['e_year'] = ADD_SELECTION("year" , date('Y', $content['end_time']) , "end" , $id);
199 // Remember other values
200 $content['templ'] = RALLYE_TEMPLATE_SELECTION("templ[".$id."]", $content['template']);
201 $content['sw'] = $SW;
202 $content['id'] = $id;
205 $OUT .= LOAD_TEMPLATE("admin_edit_rallyes_row", true, $content);
211 // Remember rows in constant
212 define('__RALLYE_ROWS', $OUT);
214 // Load final template
215 LOAD_TEMPLATE("admin_edit_rallyes");
217 // Nothing selected to edit
218 LOAD_TEMPLATE("admin_settings_saved", false, LOAD_TEMPLATE("admin_list_rallye_noselect", true));
220 } elseif ((REQUEST_GET('sub') == "users") && (REQUEST_GET('rallye') > 0)) {
221 // List users and their refs before start and current
222 $result = SQL_QUERY_ESC("SELECT userid, refs, curr_points FROM `{!_MYSQL_PREFIX!}_rallye_users` WHERE rallye_id=%s ORDER BY userid",
223 array(bigintval(REQUEST_GET('rallye'))), __FILE__, __LINE__);
224 if (SQL_NUMROWS($result) > 0) {
226 // @TODO Rewrite this constant
227 define('__RALLYE_VALUE', REQUEST_GET('rallye'));
228 while ($content = SQL_FETCHARRAY($result)) {
229 // Check for referal count
230 $cnt = RALLYE_GET_REFCOUNT($content['userid'], $content['refs']);
237 if (($content['curr_points'] > 0) && ($cnt > 0)) { $bl = "<strong>"; $br = "</strong>"; }
238 if (($content['refs'] > 0) || ($cnt > 0)) {
239 // Insert link to referal list
240 //* DEBUG: */ echo "-".$content['userid']."/".$cnt."/".$content['refs']."-<br />";
241 $cnt = ADMIN_USER_PROFILE_LINK($content['userid'], $cnt, "list_refs");
242 $content['refs'] = ADMIN_USER_PROFILE_LINK($content['userid'], $content['refs'], "list_refs");
246 $points = GET_TOTAL_DATA($content['userid'], "user_points", "points", "userid", false, " AND ref_depth=1 LIMIT 1");
247 //* DEBUG: */ echo basename(__FILE__).":uid={$content['userid']},points={$points},opoints={$content['curr_points']}<br />\n";
250 // @TODO Rewritings: uid->userid,opoints->curr_points,old->refs in template
253 'uid' => $content['userid'],
256 'old' => $content['refs'],
258 'opoints' => TRANSLATE_COMMA($points - $content['curr_points']),
261 // Load row template and switch color
262 $OUT .= LOAD_TEMPLATE("admin_list_rallye_usr_row", true, $content);
267 SQL_FREERESULT($result);
268 define('__RALLYE_USER_ROWS', $OUT);
271 LOAD_TEMPLATE("admin_list_rallye_usr");
274 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('RALLYE_ADMIN_USERS_404'));
277 // Start listing rallyes
278 $result = SQL_QUERY("SELECT id, admin_id, title, descr, template, start_time, end_time, auto_add_new_user, is_active, send_notify, notified, min_users, min_prices
279 FROM `{!_MYSQL_PREFIX!}_rallye_data`
280 ORDER BY start_time DESC",
282 if (SQL_NUMROWS($result) > 0) {
283 // List found rallyes
285 while ($content = SQL_FETCHARRAY($result)) {
287 $content['alogin'] = GET_ADMIN_LOGIN($content['admin_id']);
289 // Count joined userids
290 $joined = GET_TOTAL_DATA($content['id'], "rallye_users", "id", "rallye_id", true);
292 // Did some users joined this rallye?
295 $joined = "<a href=\"{!URL!}/modules.php?module=admin&what=list_rallyes&sub=users&rallye=".$content['id']."\" title=\"{--RALLYE_LIST_USERS_TITLE--}\">".$joined."</a>";
298 // Alter some variables
299 if (empty($content['alogin'])) $content['alogin'] = "???";
300 if (empty($content['template'])) $content['template'] = "---";
301 if (empty($content['descr'])) $content['descr'] = "---";
303 // Transfer data into array for the template
304 // @TODO Rewritings: aid->admin_id in template
306 'select' => "<input type=\"checkbox\" name=\"sel[".$content['id']."]\" class=\"admin_normal\" value=\"1\" />",
307 'aid' => $content['admin_id'],
308 'email_link' => CREATE_EMAIL_LINK($content['admin_id']),
309 'alogin' => $content['alogin'],
310 'id' => $content['id'],
312 'title' => $content['title'],
313 'template' => $content['template'],
315 'start_date' => MAKE_DATETIME($content['start_time'], "2"),
316 'end_date' => MAKE_DATETIME($content['end_time'] , "2"),
317 'active_lnk' => TRANSLATE_YESNO($content['is_active']),
318 'notify_lnk' => TRANSLATE_YESNO($content['send_notify']),
319 'auto_lnk' => TRANSLATE_YESNO($content['auto_add_new_user']),
320 'notified' => TRANSLATE_YESNO($content['notified']),
321 'prices_cnt' => GET_TOTAL_DATA($content['id'], "rallye_prices", "id", "rallye_id", true),
322 'descr' => COMPILE_CODE($content['descr']),
323 'min_users' => $content['min_users'],
324 'min_prices' => $content['min_prices'],
327 // Is the rallye active or not?
328 switch ($content['is_active'])
331 // Rallye is active so do not edit it!
332 $content['select'] = "<div class=\"big\">".$content['id']."</div>";
333 $content['active_title'] = getMessage('RALLYE_DEACTIVATE_NOW');
334 $content['active'] = 0;
338 $content['active_title'] = getMessage('RALLYE_ACTIVATE_NOW');
339 $content['active'] = "1";
343 // Notification to members?
344 switch ($content['send_notify'])
347 $content['notify_title'] = getMessage('RALLYE_STOP_NOTIFY_NOW');
348 $content['notify'] = 0;
352 $content['notify_title'] = getMessage('RALLYE_START_NOTIFY_NOW');
353 $content['notify'] = "1";
357 // Auto-add of new joined members?
358 switch ($content['auto_add_new_user'])
361 $content['auto_title'] = getMessage('RALLYE_STOP_AUTO_ADD_NOW');
362 $content['auto'] = 0;
366 $content['auto_title'] = getMessage('RALLYE_START_AUTO_ADD_NOW');
367 $content['auto'] = "1";
372 $OUT .= LOAD_TEMPLATE("admin_list_rallyes_row", true, $content);
377 SQL_FREERESULT($result);
378 define('__RALLYE_ROWS', $OUT);
381 LOAD_TEMPLATE("admin_list_rallyes");
383 // No rallyes setup so far
384 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('RALLYE_NO_RALLYES_SETUP'));