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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2008 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
48 if (!REQUEST_ISSET_GET('sub')) REQUEST_SET_GET('sub', '');
51 // Quick actions on a rallye
52 if (REQUEST_ISSET_GET(('rallye'))) {
56 if (REQUEST_ISSET_GET(('activate'))) {
57 // Activate / deactivate
58 switch (REQUEST_GET('activate'))
61 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET is_active='Y' WHERE id=%s AND is_active='N' LIMIT 1");
64 case "0": // Deactivate
65 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET is_active='N' WHERE id=%s AND is_active='Y' LIMIT 1");
68 } elseif (REQUEST_ISSET_GET(('notify'))) {
69 // Automatic notification
70 switch (REQUEST_GET('notify'))
73 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET send_notify='Y' WHERE id=%s AND send_notify='N' LIMIT 1");
76 case "0": // Deactivate
77 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET send_notify='N' WHERE id=%s AND send_notify='Y' LIMIT 1");
80 } elseif (REQUEST_ISSET_GET(('auto'))) {
81 // Automatic adding of new members
82 switch (REQUEST_GET('auto'))
85 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET auto_add_new_user='Y' WHERE id=%s AND auto_add_new_user='N' LIMIT 1");
88 case "0": // Deactivate
89 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET auto_add_new_user='N' WHERE id=%s AND auto_add_new_user='Y' LIMIT 1");
95 runFilterChain('run_sqls');
96 } elseif (REQUEST_ISSET_POST('remove')) {
98 $SEL = SELECTION_COUNT(REQUEST_POST('sel'));
103 // Delete selected rallyes and all it's data
104 foreach (REQUEST_POST('sel') as $id => $selected) {
105 // Remove selected rallye entirely...
106 ADD_SQL(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_rallye_data` WHERE id=%s LIMIT 1",
107 array(bigintval($id)), __FILE__, __LINE__, false));
108 ADD_SQL(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE rallye_id=%s",
109 array(bigintval($id)), __FILE__, __LINE__, false));
110 ADD_SQL(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_rallye_users` WHERE rallye_id=%s",
111 array(bigintval($id)), __FILE__, __LINE__, false));
115 runFilterChain('run_sqls');
118 $message = getMessage('RALLYE_DELETED');
120 // No rallye selected to delete!
121 $message = getMessage('RALLYE_DELETE_NOTHING_SELECTED');
123 } elseif (REQUEST_ISSET_POST('change')) {
125 $SEL = SELECTION_COUNT(REQUEST_POST('title'));
130 // Change selected rallyes and all it's data
131 foreach (REQUEST_POST('title') as $id => $title) {
133 $id = bigintval($id);
135 // Generate timestamps
136 $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));
137 $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) );
140 ADD_SQL(SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_rallye_data` SET
148 WHERE id='".$id."' LIMIT 1",
151 REQUEST_POST('descr', $id),
152 REQUEST_POST('templ', $id),
155 bigintval(REQUEST_POST('min_users', $id)),
156 bigintval(REQUEST_POST('min_prices', $id)),
158 ), __FILE__, __LINE__, false));
162 runFilterChain('run_sqls');
165 $message = getMessage('RALLYE_CHANGED');
169 if (REQUEST_ISSET_POST('edit')) {
170 // Check for selections
171 $SEL = SELECTION_COUNT(REQUEST_POST('sel'));
173 // Make all selected and deactivated rallyes editable
175 foreach (REQUEST_POST('sel') as $id => $selected) {
176 // Load rallye basic data
177 $result = SQL_QUERY_ESC("SELECT title, descr, template, start_time, end_time, min_users, min_prices
178 FROM `{!_MYSQL_PREFIX!}_rallye_data`
181 array(bigintval($id)), __FILE__, __LINE__);
183 $content = SQL_FETCHARRAY($result);
186 SQL_FREERESULT($result);
189 $content['s_sec'] = ADD_SELECTION("sec" , date("s", $content['start_time']), "start", $id);
190 $content['s_min'] = ADD_SELECTION("min" , date("i", $content['start_time']), "start", $id);
191 $content['s_hour'] = ADD_SELECTION("hour" , date("G", $content['start_time']), "start", $id);
192 $content['s_day'] = ADD_SELECTION("day" , date("d", $content['start_time']), "start", $id);
193 $content['s_month'] = ADD_SELECTION("month", date("m", $content['start_time']), "start", $id);
194 $content['s_year'] = ADD_SELECTION("year" , date('Y', $content['start_time']), "start", $id);
197 $content['e_sec'] = ADD_SELECTION("sec" , date("s", $content['end_time']) , "end" , $id);
198 $content['e_min'] = ADD_SELECTION("min" , date("i", $content['end_time']) , "end" , $id);
199 $content['e_hour'] = ADD_SELECTION("hour" , date("G", $content['end_time']) , "end" , $id);
200 $content['e_day'] = ADD_SELECTION("day" , date("d", $content['end_time']) , "end" , $id);
201 $content['e_month'] = ADD_SELECTION("month", date("m", $content['end_time']) , "end" , $id);
202 $content['e_year'] = ADD_SELECTION("year" , date('Y', $content['end_time']) , "end" , $id);
204 // Remember other values
205 $content['templ'] = RALLYE_TEMPLATE_SELECTION("templ[".$id."]", $content['template']);
206 $content['sw'] = $SW;
207 $content['id'] = $id;
210 $OUT .= LOAD_TEMPLATE("admin_edit_rallyes_row", true, $content);
216 // Remember rows in constant
217 define('__RALLYE_ROWS', $OUT);
219 // Load final template
220 LOAD_TEMPLATE("admin_edit_rallyes");
222 // Nothing selected to edit
223 LOAD_TEMPLATE('admin_settings_saved', false, LOAD_TEMPLATE("admin_list_rallye_noselect", true));
225 } elseif ((REQUEST_GET('sub') == "users") && (REQUEST_GET('rallye') > 0)) {
226 // List users and their refs before start and current
227 $result = SQL_QUERY_ESC("SELECT userid, refs, curr_points FROM `{!_MYSQL_PREFIX!}_rallye_users` WHERE rallye_id=%s ORDER BY userid",
228 array(bigintval(REQUEST_GET('rallye'))), __FILE__, __LINE__);
229 if (SQL_NUMROWS($result) > 0) {
231 // @TODO Rewrite this constant
232 define('__RALLYE_VALUE', REQUEST_GET('rallye'));
233 while ($content = SQL_FETCHARRAY($result)) {
234 // Check for referal count
235 $cnt = RALLYE_GET_REFCOUNT($content['userid'], $content['refs']);
242 if (($content['curr_points'] > 0) && ($cnt > 0)) { $bl = "<strong>"; $br = "</strong>"; }
243 if (($content['refs'] > 0) || ($cnt > 0)) {
244 // Insert link to referal list
245 //* DEBUG: */ echo "-".$content['userid']."/".$cnt."/".$content['refs']."-<br />";
246 $cnt = ADMIN_USER_PROFILE_LINK($content['userid'], $cnt, "list_refs");
247 $content['refs'] = ADMIN_USER_PROFILE_LINK($content['userid'], $content['refs'], "list_refs");
251 $points = GET_TOTAL_DATA($content['userid'], "user_points", "points", 'userid', false, " AND ref_depth=1 LIMIT 1");
252 //* DEBUG: */ echo basename(__FILE__).":uid={$content['userid']},points={$points},opoints={$content['curr_points']}<br />\n";
255 // @TODO Rewritings: uid->userid,opoints->curr_points,old->refs in template
258 'uid' => $content['userid'],
261 'old' => $content['refs'],
263 'opoints' => TRANSLATE_COMMA($points - $content['curr_points']),
266 // Load row template and switch color
267 $OUT .= LOAD_TEMPLATE("admin_list_rallye_usr_row", true, $content);
272 SQL_FREERESULT($result);
273 define('__RALLYE_USER_ROWS', $OUT);
276 LOAD_TEMPLATE("admin_list_rallye_usr");
279 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_ADMIN_USERS_404'));
282 // Start listing rallyes
283 $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
284 FROM `{!_MYSQL_PREFIX!}_rallye_data`
285 ORDER BY start_time DESC",
287 if (SQL_NUMROWS($result) > 0) {
288 // List found rallyes
290 while ($content = SQL_FETCHARRAY($result)) {
292 $content['alogin'] = GET_ADMIN_LOGIN($content['admin_id']);
294 // Count joined userids
295 $joined = GET_TOTAL_DATA($content['id'], "rallye_users", "id", "rallye_id", true);
297 // Did some users joined this rallye?
300 $joined = "<a href=\"{!URL!}/modules.php?module=admin&what=list_rallyes&sub=users&rallye=".$content['id']."\" title=\"{--RALLYE_LIST_USERS_TITLE--}\">".$joined."</a>";
303 // Alter some variables
304 if (empty($content['alogin'])) $content['alogin'] = "???";
305 if (empty($content['template'])) $content['template'] = "---";
306 if (empty($content['descr'])) $content['descr'] = "---";
308 // Transfer data into array for the template
309 // @TODO Rewritings: aid->admin_id in template
311 'select' => "<input type=\"checkbox\" name=\"sel[".$content['id']."]\" class=\"admin_normal\" value=\"1\" />",
312 'aid' => $content['admin_id'],
313 'email_link' => CREATE_EMAIL_LINK($content['admin_id']),
314 'alogin' => $content['alogin'],
315 'id' => $content['id'],
317 'title' => $content['title'],
318 'template' => $content['template'],
320 'start_date' => MAKE_DATETIME($content['start_time'], "2"),
321 'end_date' => MAKE_DATETIME($content['end_time'] , "2"),
322 'active_lnk' => TRANSLATE_YESNO($content['is_active']),
323 'notify_lnk' => TRANSLATE_YESNO($content['send_notify']),
324 'auto_lnk' => TRANSLATE_YESNO($content['auto_add_new_user']),
325 'notified' => TRANSLATE_YESNO($content['notified']),
326 'prices_cnt' => TRANSLATE_COMMA(GET_TOTAL_DATA($content['id'], "rallye_prices", "id", "rallye_id", true)),
327 'descr' => COMPILE_CODE($content['descr']),
328 'min_users' => $content['min_users'],
329 'min_prices' => $content['min_prices'],
332 // Is the rallye active or not?
333 switch ($content['is_active'])
336 // Rallye is active so do not edit it!
337 $content['select'] = "<div class=\"big\">".$content['id']."</div>";
338 $content['active_title'] = getMessage('RALLYE_DEACTIVATE_NOW');
339 $content['active'] = 0;
343 $content['active_title'] = getMessage('RALLYE_ACTIVATE_NOW');
344 $content['active'] = "1";
348 // Notification to members?
349 switch ($content['send_notify'])
352 $content['notify_title'] = getMessage('RALLYE_STOP_NOTIFY_NOW');
353 $content['notify'] = 0;
357 $content['notify_title'] = getMessage('RALLYE_START_NOTIFY_NOW');
358 $content['notify'] = "1";
362 // Auto-add of new joined members?
363 switch ($content['auto_add_new_user'])
366 $content['auto_title'] = getMessage('RALLYE_STOP_AUTO_ADD_NOW');
367 $content['auto'] = 0;
371 $content['auto_title'] = getMessage('RALLYE_START_AUTO_ADD_NOW');
372 $content['auto'] = "1";
377 $OUT .= LOAD_TEMPLATE("admin_list_rallyes_row", true, $content);
382 SQL_FREERESULT($result);
383 define('__RALLYE_ROWS', $OUT);
386 LOAD_TEMPLATE("admin_list_rallyes");
388 // No rallyes setup so far
389 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('RALLYE_NO_RALLYES_SETUP'));