2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 - 2009 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')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
50 // Quick actions on a rallye
51 if (isGetRequestElementSet('rallye')) {
55 if (isGetRequestElementSet('activate')) {
56 // Activate / deactivate
57 switch (getRequestElement('activate')) {
59 addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `is_active`='Y' WHERE `id`=%s AND `is_active`='N' LIMIT 1",
60 array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__, false)
64 case '0': // Deactivate
65 addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `is_active`='N' WHERE `id`=%s AND `is_active`='Y' LIMIT 1",
66 array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__, false)
70 } elseif (isGetRequestElementSet('notify')) {
71 // Automatic notification
72 switch (getRequestElement('notify')) {
74 addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `send_notify`='Y' WHERE `id`=%s AND `send_notify`='N' LIMIT 1",
75 array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__, false)
79 case '0': // Deactivate
80 addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `send_notify`='N' WHERE `id`=%s AND `send_notify`='Y' LIMIT 1",
81 array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__, false)
85 } elseif (isGetRequestElementSet('auto')) {
86 // Automatic adding of new members
87 switch (getRequestElement('auto')) {
89 addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `auto_add_new_user`='Y' WHERE `id`=%s AND `auto_add_new_user`='N' LIMIT 1",
90 array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__, false)
94 case '0': // Deactivate
95 addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `auto_add_new_user`='N' WHERE `id`=%s AND `auto_add_new_user`='Y' LIMIT 1",
96 array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__, false)
103 runFilterChain('run_sqls');
104 } elseif (isPostRequestElementSet('remove')) {
106 if (countPostSelection() > 0) {
110 // Delete selected rallyes and all it's data
111 foreach (postRequestElement('sel') as $id => $selected) {
112 // Remove selected rallye entirely...
113 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_data` WHERE `id`=%s LIMIT 1",
114 array(bigintval($id)), __FILE__, __LINE__, false));
115 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s",
116 array(bigintval($id)), __FILE__, __LINE__, false));
117 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_users` WHERE `rallye_id`=%s",
118 array(bigintval($id)), __FILE__, __LINE__, false));
122 runFilterChain('run_sqls');
125 $message = getMessage('RALLYE_DELETED');
127 // No rallye selected to delete!
128 $message = getMessage('RALLYE_DELETE_NOTHING_SELECTED');
130 } elseif (isPostRequestElementSet('change')) {
132 if (countSelection(postRequestElement('title')) > 0) {
136 // Change selected rallyes and all it's data
137 foreach (postRequestElement('title') as $id => $title) {
139 $id = bigintval($id);
141 // Generate timestamps
142 $START = mktime(postRequestElement('start_hour', $id), postRequestElement('start_min', $id), postRequestElement('start_sec', $id), postRequestElement('start_month', $id), postRequestElement('start_day', $id), postRequestElement('start_year', $id));
143 $END = mktime(postRequestElement('end_hour', $id) , postRequestElement('end_min', $id) , postRequestElement('end_sec', $id) , postRequestElement('end_month', $id) , postRequestElement('end_day', $id) , postRequestElement('end_year', $id) );
146 addSql(SQL_QUERY_ESC("UPDATE
147 `{?_MYSQL_PREFIX?}_rallye_data`
161 postRequestElement('descr', $id),
162 postRequestElement('templ', $id),
165 bigintval(postRequestElement('min_users', $id)),
166 bigintval(postRequestElement('min_prices', $id)),
168 ), __FILE__, __LINE__, false));
172 runFilterChain('run_sqls');
175 $message = getMessage('RALLYE_CHANGED');
179 if (isPostRequestElementSet('edit')) {
180 // Check for selections
181 if (countPostSelection() > 0) {
182 // Make all selected and deactivated rallyes editable
184 foreach (postRequestElement('sel') as $id => $selected) {
185 // Load rallye basic data
186 $result = SQL_QUERY_ESC("SELECT
187 `title`, `descr`, `template`, `start_time`, `end_time`, `min_users`, `min_prices`
189 `{?_MYSQL_PREFIX?}_rallye_data`
193 array(bigintval($id)), __FILE__, __LINE__);
195 $content = SQL_FETCHARRAY($result);
198 SQL_FREERESULT($result);
201 $content['s_sec'] = addSelectionBox('sec' , date('s', $content['start_time']), 'start', $id);
202 $content['s_min'] = addSelectionBox('min' , date('i', $content['start_time']), 'start', $id);
203 $content['s_hour'] = addSelectionBox('hour' , date('G', $content['start_time']), 'start', $id);
204 $content['s_day'] = addSelectionBox('day' , date('d', $content['start_time']), 'start', $id);
205 $content['s_month'] = addSelectionBox('month', date('m', $content['start_time']), 'start', $id);
206 $content['s_year'] = addSelectionBox('year' , date('Y', $content['start_time']), 'start', $id);
209 $content['e_sec'] = addSelectionBox('sec' , date('s', $content['end_time']) , 'end' , $id);
210 $content['e_min'] = addSelectionBox('min' , date('i', $content['end_time']) , 'end' , $id);
211 $content['e_hour'] = addSelectionBox('hour' , date('G', $content['end_time']) , 'end' , $id);
212 $content['e_day'] = addSelectionBox('day' , date('d', $content['end_time']) , 'end' , $id);
213 $content['e_month'] = addSelectionBox('month', date('m', $content['end_time']) , 'end' , $id);
214 $content['e_year'] = addSelectionBox('year' , date('Y', $content['end_time']) , 'end' , $id);
216 // Remember other values
217 $content['templ'] = addReferalRallyeTemplateSelection('templ['.$id.']', $content['template']);
218 $content['sw'] = $SW;
219 $content['id'] = $id;
222 $OUT .= loadTemplate('admin_edit_rallyes_row', true, $content);
228 // Load final template
229 loadTemplate('admin_edit_rallyes', false, $OUT);
231 // Nothing selected to edit
232 loadTemplate('admin_settings_saved', false, loadTemplate('admin_list_rallye_noselect', true));
234 } elseif ((getRequestElement('sub') == 'users') && (getRequestElement('rallye') > 0)) {
235 // List users and their refs before start and current
236 $result = SQL_QUERY_ESC("SELECT `userid`, `refs`, `curr_points` FROM `{?_MYSQL_PREFIX?}_rallye_users` WHERE `rallye_id`=%s ORDER BY `userid` ASC",
237 array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__);
238 if (SQL_NUMROWS($result) > 0) {
240 $content['rallye'] = getRequestElement('rallye');
241 while ($row = SQL_FETCHARRAY($result)) {
242 // Check for referal count
243 $cnt = getReferalRallyeRefsCount($row['userid'], $row['refs']);
250 if (($row['curr_points'] > 0) && ($cnt > 0)) { $bl = '<strong>'; $br = '</strong>'; }
253 $points = countSumTotalData($row['userid'], 'user_points', 'points', 'userid', false, " AND `ref_depth`=1 LIMIT 1");
254 //* DEBUG: */ outputHtml(basename(__FILE__).":userid={$row['userid']},points={$points},opoints={$row['curr_points']}<br />");
257 // @TODO Rewritings: opoints->curr_points,old->refs in template
260 'userid' => $row['userid'],
263 'old' => $row['refs'],
265 'opoints' => translateComma($points - $row['curr_points']),
268 // Load row template and switch color
269 $OUT .= loadTemplate('admin_list_rallye_usr_row', true, $row);
274 $content['rows'] = $OUT;
275 $content['rallye'] = getRequestElement('rallye');
278 SQL_FREERESULT($result);
281 loadTemplate('admin_list_rallye_usr', false, $content);
284 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ADMIN_USERS_404'));
287 // Start listing rallyes
288 $result = SQL_QUERY("SELECT
289 `id`, `admin_id`, `title`, `descr`, `template`, `start_time`, `end_time`, `auto_add_new_user`, `is_active`, `send_notify`, `notified`, `min_users`, `min_prices`
291 `{?_MYSQL_PREFIX?}_rallye_data`
293 `start_time` DESC", __FILE__, __LINE__);
296 if (SQL_NUMROWS($result) > 0) {
297 // List found rallyes
299 while ($data = SQL_FETCHARRAY($result)) {
301 $data['login'] = getAdminLogin($data['admin_id']);
303 // Count joined userids
304 $joined = countSumTotalData($data['id'], 'rallye_users', 'id', 'rallye_id', true);
306 // Did some users joined this rallye?
309 $joined = "<a href=\"{?URL?}/modules.php?module=admin&what=list_rallyes&sub=users&rallye=".$data['id']."\" title=\"{--RALLYE_LIST_USERS_TITLE--}\">".$joined."</a>";
312 // Alter some variables
313 if (empty($data['login'])) $data['login'] = '???';
314 if (empty($data['template'])) $data['template'] = '---';
315 if (empty($data['descr'])) $data['descr'] = '---';
317 // Transfer data into array for the template
319 'select' => "<input type=\"checkbox\" name=\"sel[".$data['id']."]\" class=\"admin_normal\" value=\"1\" />",
320 'admin_id' => $data['admin_id'],
321 'admin_link' => generateAdminLink($data['admin_id']),
322 'login' => $data['login'],
325 'title' => $data['title'],
326 'template' => $data['template'],
328 'start_date' => generateDateTime($data['start_time'], 2),
329 'end_date' => generateDateTime($data['end_time'] , 2),
330 'active_lnk' => translateYesNo($data['is_active']),
331 'notify_lnk' => translateYesNo($data['send_notify']),
332 'auto_lnk' => translateYesNo($data['auto_add_new_user']),
333 'notified' => translateYesNo($data['notified']),
334 'prices_cnt' => translateComma(countSumTotalData($data['id'], 'rallye_prices', 'id', 'rallye_id', true)),
335 'descr' => $data['descr'],
336 'min_users' => $data['min_users'],
337 'min_prices' => $data['min_prices'],
340 // Is the rallye active or not?
341 switch ($data['is_active']) {
343 // Rallye is active so do not edit it!
344 $row['select'] = "<div class=\"big\">".$row['id']."</div>";
345 $row['active_title'] = getMessage('RALLYE_DEACTIVATE_NOW');
346 $row['active'] = '0';
350 $row['active_title'] = getMessage('RALLYE_ACTIVATE_NOW');
355 // Notification to members?
356 switch ($data['send_notify']) {
358 $row['notify_title'] = getMessage('RALLYE_STOP_NOTIFY_NOW');
359 $row['notify'] = '0';
363 $row['notify_title'] = getMessage('RALLYE_START_NOTIFY_NOW');
368 // Auto-add of new joined members?
369 switch ($data['auto_add_new_user']) {
371 $row['auto_title'] = getMessage('RALLYE_STOP_AUTO_ADD_NOW');
376 $row['auto_title'] = getMessage('RALLYE_START_AUTO_ADD_NOW');
382 $OUT .= loadTemplate('admin_list_rallyes_row', true, $row);
387 SQL_FREERESULT($result);
389 // Remember rows in array
390 $content['rows'] = $OUT;
393 loadTemplate('admin_list_rallyes', false, $content);
395 // No rallyes setup so far
396 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_NO_RALLYES_SETUP'));