Compilation time added, some compileCode() calles removed, ADMIN_WHAT_404 added
[mailer.git] / inc / modules / admin / what-list_rallyes.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 06/29/2004 *
4  * ================                             Last change: 02/11/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_rallyes.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : List existing rallyes                            *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Bestehende Rallyes auflisten                     *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 }
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 if (!isGetRequestElementSet('sub')) setRequestGetElement('sub', '');
48 $message = '';
49
50 // Quick actions on a rallye
51 if (isGetRequestElementSet(('rallye'))) {
52         // Init SQL queries
53         initSqls();
54
55         if (isGetRequestElementSet(('activate'))) {
56                 // Activate / deactivate
57                 switch (getRequestElement('activate'))
58                 {
59                         case 1: // Activate
60                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET is_active='Y' WHERE `id`=%s AND is_active='N' LIMIT 1");
61                                 break;
62
63                         case 0: // Deactivate
64                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET is_active='N' WHERE `id`=%s AND is_active='Y' LIMIT 1");
65                                 break;
66                 }
67         } elseif (isGetRequestElementSet('notify')) {
68                 // Automatic notification
69                 switch (getRequestElement('notify'))
70                 {
71                         case 1: // Activate
72                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET send_notify='Y' WHERE `id`=%s AND send_notify='N' LIMIT 1");
73                                 break;
74
75                         case 0: // Deactivate
76                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET send_notify='N' WHERE `id`=%s AND send_notify='Y' LIMIT 1");
77                                 break;
78                 }
79         } elseif (isGetRequestElementSet(('auto'))) {
80                 // Automatic adding of new members
81                 switch (getRequestElement('auto'))
82                 {
83                         case 1: // Activate
84                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET auto_add_new_user='Y' WHERE `id`=%s AND auto_add_new_user='N' LIMIT 1");
85                                 break;
86
87                         case 0: // Deactivate
88                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET auto_add_new_user='N' WHERE `id`=%s AND auto_add_new_user='Y' LIMIT 1");
89                                 break;
90                 }
91         }
92
93         // Run SQL command
94         runFilterChain('run_sqls');
95 } elseif (isPostRequestElementSet('remove')) {
96         // Delete rallyes
97         $SEL = countPostSelection();
98         if ($SEL > 0) {
99                 // Init SQLs
100                 initSqls();
101
102                 // Delete selected rallyes and all it's data
103                 foreach (postRequestElement('sel') as $id => $selected) {
104                         // Remove selected rallye entirely...
105                         addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_data` WHERE `id`=%s LIMIT 1",
106                         array(bigintval($id)), __FILE__, __LINE__, false));
107                         addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE rallye_id=%s",
108                         array(bigintval($id)), __FILE__, __LINE__, false));
109                         addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_users` WHERE rallye_id=%s",
110                         array(bigintval($id)), __FILE__, __LINE__, false));
111                 } // END - foreach
112
113                 // Run SQLS
114                 runFilterChain('run_sqls');
115
116                 // Output message
117                 $message = getMessage('RALLYE_DELETED');
118         } else {
119                 // No rallye selected to delete!
120                 $message = getMessage('RALLYE_DELETE_NOTHING_SELECTED');
121         }
122 } elseif (isPostRequestElementSet('change')) {
123         // Change rallye
124         $SEL = countSelection(postRequestElement('title'));
125         if ($SEL > 0) {
126                 // Init SQLs
127                 initSqls();
128
129                 // Change selected rallyes and all it's data
130                 foreach (postRequestElement('title') as $id => $title) {
131                         // Secure id number
132                         $id = bigintval($id);
133
134                         // Generate timestamps
135                         $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));
136                         $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)  );
137
138                         // Update entry
139                         addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET
140 title='%s',
141 descr='%s',
142 template='%s',
143 start_time='%s',
144 end_time='%s',
145 min_users='%s',
146 min_prices='%s'
147 WHERE `id`='".$id."' LIMIT 1",
148                         array(
149                         $title,
150                         postRequestElement('descr', $id),
151                         postRequestElement('templ', $id),
152                         bigintval($START),
153                         bigintval($END),
154                         bigintval(postRequestElement('min_users', $id)),
155                         bigintval(postRequestElement('min_prices', $id)),
156                         $id
157                         ), __FILE__, __LINE__, false));
158                 }
159
160                 // Run SQLS
161                 runFilterChain('run_sqls');
162
163                 // Output message
164                 $message = getMessage('RALLYE_CHANGED');
165         }
166 }
167
168 if (isPostRequestElementSet('edit')) {
169         // Check for selections
170         $SEL = countPostSelection();
171         if ($SEL > 0) {
172                 // Make all selected and deactivated rallyes editable
173                 $OUT = ''; $SW = 2;
174                 foreach (postRequestElement('sel') as $id => $selected) {
175                         // Load rallye basic data
176                         $result = SQL_QUERY_ESC("SELECT title, descr, template, start_time, end_time, min_users, min_prices
177 FROM `{?_MYSQL_PREFIX?}_rallye_data`
178 WHERE `id`=%s
179 LIMIT 1",
180                         array(bigintval($id)), __FILE__, __LINE__);
181                         // Fetch an array
182                         $content = SQL_FETCHARRAY($result);
183
184                         // Free result
185                         SQL_FREERESULT($result);
186
187                         // Starting day
188                         $content['s_sec']   = addSelectionBox('sec'  , date('s', $content['start_time']), 'start', $id);
189                         $content['s_min']   = addSelectionBox('min'  , date('i', $content['start_time']), 'start', $id);
190                         $content['s_hour']  = addSelectionBox('hour' , date('G', $content['start_time']), 'start', $id);
191                         $content['s_day']   = addSelectionBox('day'  , date('d', $content['start_time']), 'start', $id);
192                         $content['s_month'] = addSelectionBox('month', date('m', $content['start_time']), 'start', $id);
193                         $content['s_year']  = addSelectionBox('year' , date('Y', $content['start_time']), 'start', $id);
194
195                         // Ending day
196                         $content['e_sec']   = addSelectionBox('sec'  , date('s', $content['end_time'])  , 'end'  , $id);
197                         $content['e_min']   = addSelectionBox('min'  , date('i', $content['end_time'])  , 'end'  , $id);
198                         $content['e_hour']  = addSelectionBox('hour' , date('G', $content['end_time'])  , 'end'  , $id);
199                         $content['e_day']   = addSelectionBox('day'  , date('d', $content['end_time'])  , 'end'  , $id);
200                         $content['e_month'] = addSelectionBox('month', date('m', $content['end_time'])  , 'end'  , $id);
201                         $content['e_year']  = addSelectionBox('year' , date('Y', $content['end_time'])  , 'end'  , $id);
202
203                         // Remember other values
204                         $content['templ']      = addReferalRallyeTemplateSelection('templ['.$id.']', $content['template']);
205                         $content['sw']         = $SW;
206                         $content['id']         = $id;
207
208                         // Output row
209                         $OUT .= loadTemplate('admin_edit_rallyes_row', true, $content);
210
211                         // Color switching
212                         $SW = 3 - $SW;
213                 }
214
215                 // Load final template
216                 loadTemplate('admin_edit_rallyes', false, $OUT);
217         } else {
218                 // Nothing selected to edit
219                 loadTemplate('admin_settings_saved', false, loadTemplate('admin_list_rallye_noselect', true));
220         }
221 } elseif ((getRequestElement('sub') == 'users') && (getRequestElement('rallye') > 0)) {
222         // List users and their refs before start and current
223         $result = SQL_QUERY_ESC("SELECT userid, refs, curr_points FROM `{?_MYSQL_PREFIX?}_rallye_users` WHERE rallye_id=%s ORDER BY `userid` ASC",
224         array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__);
225         if (SQL_NUMROWS($result) > 0) {
226                 $OUT = ''; $SW = 2;
227                 $content['rallye'] = getRequestElement('rallye');
228                 while ($row = SQL_FETCHARRAY($result)) {
229                         // Check for referal count
230                         $cnt = getReferalRallyeRefsCount($row['userid'], $row['refs']);
231
232                         // Init variables
233                         $bl = '';
234                         $br = '';
235
236                         // Output row
237                         if (($row['curr_points'] > 0) && ($cnt > 0)) { $bl = "<strong>"; $br = "</strong>"; }
238                         if (($row['refs'] > 0) || ($cnt > 0)) {
239                                 // Insert link to referal list
240                                 //* DEBUG: */ outputHtml('-'.$row['userid'].'/'.$cnt.'/'.$row['refs']."-<br />");
241                                 $cnt = generateUserProfileLink($row['userid'], $cnt, 'list_refs');
242                                 $row['refs'] = generateUserProfileLink($row['userid'], $row['refs'], 'list_refs');
243                         } // END - if
244
245                         // Get user points
246                         $points = countSumTotalData($row['userid'], 'user_points', 'points', 'userid', false, " AND `ref_depth`=1 LIMIT 1");
247                         //* DEBUG: */ outputHtml(basename(__FILE__).":userid={$row['userid']},points={$points},opoints={$row['curr_points']}<br />");
248
249                         // Prepare content
250                         // @TODO Rewritings: userid->userid,opoints->curr_points,old->refs in template
251                         $row = array(
252                                 'sw'      => $SW ,
253                                 'userid'     => $row['userid'],
254                                 'bold_l'  => $bl ,
255                                 'bold_r'  => $br ,
256                                 'old'     => $row['refs'],
257                                 'cnt'     => $cnt,
258                                 'opoints' => translateComma($points - $row['curr_points']),
259                         );
260
261                         // Load row template and switch color
262                         $OUT .= loadTemplate('admin_list_rallye_usr_row', true, $row);
263                         $SW = 3 - $SW;
264                 } // END - while
265
266                 // Free memory
267                 SQL_FREERESULT($result);
268
269                 // Load template
270                 loadTemplate('admin_list_rallye_usr', false, $OUT);
271         } else {
272                 // No entries found?
273                 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_ADMIN_USERS_404'));
274         }
275 } else {
276         // Start listing rallyes
277         $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
278 FROM `{?_MYSQL_PREFIX?}_rallye_data`
279 ORDER BY start_time DESC",
280         __FILE__, __LINE__);
281         if (SQL_NUMROWS($result) > 0) {
282                 // List found rallyes
283                 $OUT = ''; $SW = 2;
284                 while ($row = SQL_FETCHARRAY($result)) {
285                         // Load admin login
286                         $row['login'] = getAdminLogin($row['admin_id']);
287
288                         // Count joined userids
289                         $joined = countSumTotalData($row['id'], "rallye_users", 'id', "rallye_id", true);
290
291                         // Did some users joined this rallye?
292                         if ($joined > 0) {
293                                 // List joined users
294                                 $joined = "<a href=\"{?URL?}/modules.php?module=admin&amp;what=list_rallyes&amp;sub=users&amp;rallye=".$row['id']."\" title=\"{--RALLYE_LIST_USERS_TITLE--}\">".$joined."</a>";
295                         } // END - if
296
297                         // Alter some variables
298                         if (empty($row['login']))   $row['login']    = '???';
299                         if (empty($row['template'])) $row['template']  = '---';
300                         if (empty($row['descr']))    $row['descr']     = '---';
301
302                         // Transfer data into array for the template
303                         // @TODO Rewritings: admin_id->admin_id in template
304                         $row = array(
305                                 'select'     => "<input type=\"checkbox\" name=\"sel[".$row['id']."]\" class=\"admin_normal\" value=\"1\" />",
306                                 'admin_id'        => $row['admin_id'],
307                                 'email_link' => generateEmailLink($row['admin_id']),
308                                 'login'      => $row['login'],
309                                 'id'         => $row['id'],
310                                 'sw'         => $SW,
311                                 'title'      => $row['title'],
312                                 'template'   => $row['template'],
313                                 'joined'     => $joined,
314                                 'start_date' => generateDateTime($row['start_time'], 2),
315                                 'end_date'   => generateDateTime($row['end_time']  , 2),
316                                 'active_lnk' => translateYesNo($row['is_active']),
317                                 'notify_lnk' => translateYesNo($row['send_notify']),
318                                 'auto_lnk'   => translateYesNo($row['auto_add_new_user']),
319                                 'notified'   => translateYesNo($row['notified']),
320                                 'prices_cnt' => translateComma(countSumTotalData($row['id'], 'rallye_prices', 'id', 'rallye_id', true)),
321                                 'descr'      => $row['descr'],
322                                 'min_users'  => $row['min_users'],
323                                 'min_prices' => $row['min_prices'],
324                         );
325
326                         // Is the rallye active or not?
327                         switch ($row['is_active'])
328                         {
329                                 case 'Y':
330                                         // Rallye is active so do not edit it!
331                                         $row['select'] = "<div class=\"big\">".$row['id']."</div>";
332                                         $row['active_title'] = getMessage('RALLYE_DEACTIVATE_NOW');
333                                         $row['active'] = 0;
334                                         break;
335
336                                 case 'N':
337                                         $row['active_title'] = getMessage('RALLYE_ACTIVATE_NOW');
338                                         $row['active'] = 1;
339                                         break;
340                         }
341
342                         // Notification to members?
343                         switch ($row['send_notify'])
344                         {
345                                 case 'Y':
346                                         $row['notify_title'] = getMessage('RALLYE_STOP_NOTIFY_NOW');
347                                         $row['notify'] = 0;
348                                         break;
349
350                                 case 'N':
351                                         $row['notify_title'] = getMessage('RALLYE_START_NOTIFY_NOW');
352                                         $row['notify'] = 1;
353                                         break;
354                         }
355
356                         // Auto-add of new joined members?
357                         switch ($row['auto_add_new_user'])
358                         {
359                                 case 'Y':
360                                         $row['auto_title'] = getMessage('RALLYE_STOP_AUTO_ADD_NOW');
361                                         $row['auto'] = 0;
362                                         break;
363
364                                 case 'N':
365                                         $row['auto_title'] = getMessage('RALLYE_START_AUTO_ADD_NOW');
366                                         $row['auto'] = 1;
367                                         break;
368                         }
369
370                         // Output row
371                         $OUT .= loadTemplate('admin_list_rallyes_row', true, $row);
372                         $SW = 3 - $SW;
373                 }
374
375                 // Free memory
376                 SQL_FREERESULT($result);
377
378                 // Remember rows in array
379                 $content['rows'] = $OUT;
380
381                 // Load template
382                 loadTemplate('admin_list_rallyes', false, $content);
383         } else {
384                 // No rallyes setup so far
385                 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_NO_RALLYES_SETUP'));
386         }
387 }
388
389 // [EOF]
390 ?>