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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2015 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
49 // Quick actions on a rallye
50 if (isGetRequestElementSet('rallye_id')) {
54 if (isGetRequestElementSet('activate')) {
55 // Activate / deactivate
56 switch (getRequestElement('activate')) {
58 addSql(sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `is_active`='Y' WHERE `id`=%s AND `is_active`='N' LIMIT 1",
59 array(bigintval(getRequestElement('rallye_id'))), __FILE__, __LINE__, FALSE)
63 case '0': // Deactivate
64 addSql(sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `is_active`='N' WHERE `id`=%s AND `is_active`='Y' LIMIT 1",
65 array(bigintval(getRequestElement('rallye_id'))), __FILE__, __LINE__, FALSE)
69 } elseif (isGetRequestElementSet('notify')) {
70 // Automatic notification
71 switch (getRequestElement('notify')) {
73 addSql(sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `send_notify`='Y' WHERE `id`=%s AND `send_notify`='N' LIMIT 1",
74 array(bigintval(getRequestElement('rallye_id'))), __FILE__, __LINE__, FALSE)
78 case '0': // Deactivate
79 addSql(sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `send_notify`='N' WHERE `id`=%s AND `send_notify`='Y' LIMIT 1",
80 array(bigintval(getRequestElement('rallye_id'))), __FILE__, __LINE__, FALSE)
84 } elseif (isGetRequestElementSet('auto')) {
85 // Automatic adding of new members
86 switch (getRequestElement('auto')) {
88 addSql(sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `auto_add_new_user`='Y' WHERE `id`=%s AND `auto_add_new_user`='N' LIMIT 1",
89 array(bigintval(getRequestElement('rallye_id'))), __FILE__, __LINE__, FALSE)
93 case '0': // Deactivate
94 addSql(sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `auto_add_new_user`='N' WHERE `id`=%s AND `auto_add_new_user`='Y' LIMIT 1",
95 array(bigintval(getRequestElement('rallye_id'))), __FILE__, __LINE__, FALSE)
102 runFilterChain('run_sqls');
103 } elseif (isFormSent('do_delete')) {
105 if (ifPostContainsSelections()) {
109 // Delete selected rallyes and all it's data
110 foreach (postRequestElement('sel') as $id => $selected) {
111 // Remove selected rallye entirely...
112 addSql(sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_data` WHERE `id`=%s LIMIT 1",
113 array(bigintval($id)), __FILE__, __LINE__, FALSE));
114 addSql(sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s",
115 array(bigintval($id)), __FILE__, __LINE__, FALSE));
116 addSql(sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_users` WHERE `rallye_id`=%s",
117 array(bigintval($id)), __FILE__, __LINE__, FALSE));
121 runFilterChain('run_sqls');
124 $message = '{--ADMIN_RALLYE_DELETED--}';
126 // No rallye selected to delete!
127 $message = '{--ADMIN_RALLYE_DELETE_NOTHING_SELECTED--}';
129 } elseif (isFormSent('do_edit')) {
131 if (ifPostContainsSelections('title')) {
135 // Change selected rallyes and all it's data
136 foreach (postRequestElement('title') as $id => $title) {
138 $id = bigintval($id);
140 // Generate timestamps
141 $START = mktime(postRequestElement('start_time_ho', $id), postRequestElement('start_time_mi', $id), 0, postRequestElement('start_time_mo', $id), postRequestElement('start_time_da', $id), postRequestElement('start_time_ye', $id));
142 $END = mktime(postRequestElement('end_time_ho', $id) , postRequestElement('end_time_mi', $id) , 0, postRequestElement('end_time_mo', $id) , postRequestElement('end_time_da', $id) , postRequestElement('end_time_ye', $id) );
145 addSql(sqlQueryEscaped("UPDATE
146 `{?_MYSQL_PREFIX?}_rallye_data`
160 postRequestElement('descr', $id),
161 postRequestElement('templ', $id),
164 bigintval(postRequestElement('min_users', $id)),
165 bigintval(postRequestElement('min_prices', $id)),
167 ), __FILE__, __LINE__, FALSE));
171 runFilterChain('run_sqls');
174 $message = '{--ADMIN_RALLYE_CHANGED--}';
178 // edit/delete are both handled the same way
179 if ((isFormSent('edit')) || (isFormSent('delete'))) {
183 // Is delete button used?
184 if (isFormSent('delete')) {
189 // Check for selections
190 if (ifPostContainsSelections()) {
191 // Make all selected and deactivated rallyes editable
193 foreach (postRequestElement('sel') as $id => $selected) {
194 // Load rallye basic data
195 $result = sqlQueryEscaped("SELECT
204 `{?_MYSQL_PREFIX?}_rallye_data`
208 array(bigintval($id)), __FILE__, __LINE__);
211 $content = sqlFetchArray($result);
214 sqlFreeResult($result);
216 // Only for editing ...
217 if ($mode == 'edit') {
219 $content['s_min'] = addSelectionBox('mi', getMinute($content['start_time']) , 'start_time', $id);
220 $content['s_hour'] = addSelectionBox('ho', getShortHour($content['start_time']), 'start_time', $id);
221 $content['s_day'] = addSelectionBox('da', getDay($content['start_time']) , 'start_time', $id);
222 $content['s_month'] = addSelectionBox('mo', getMonth($content['start_time']) , 'start_time', $id);
223 $content['s_year'] = addSelectionBox('ye', getYear($content['start_time']) , 'start_time', $id);
226 $content['e_min'] = addSelectionBox('mi', getMinute($content['end_time']) , 'end_time' , $id);
227 $content['e_hour'] = addSelectionBox('ho', getShortHour($content['end_time']) , 'end_time' , $id);
228 $content['e_day'] = addSelectionBox('da', getDay($content['end_time']) , 'end_time' , $id);
229 $content['e_month'] = addSelectionBox('mo', getMonth($content['end_time']) , 'end_time' , $id);
230 $content['e_year'] = addSelectionBox('ye', getYear($content['end_time']) , 'end_time' , $id);
232 // Remember other values
233 $content['templ'] = addReferralRallyeTemplateSelection('templ[' . $id . ']', $content['template']);
235 // Convert timestamps into human-readable
236 $content['start_time'] = generateDateTime($content['start_time'], '2');
237 $content['end_time'] = generateDateTime($content['end_time'] , '2');
240 // Remember id number
241 $content['rallye_id'] = bigintval($id);
244 $OUT .= loadTemplate('admin_' . $mode . '_rallyes_row', TRUE, $content);
247 // Load final template
248 loadTemplate('admin_' . $mode . '_rallyes', FALSE, $OUT);
250 // Nothing selected to edit
251 displayMessage('{--ADMIN_RALLYE_NO_RALLYES_SELECTED--}');
253 } elseif ((getRequestElement('sub') == 'users') && (getRequestElement('rallye_id') > 0)) {
254 // List users and their refs before start and current
255 $result = sqlQueryEscaped("SELECT
260 `{?_MYSQL_PREFIX?}_rallye_users`
265 array(bigintval(getRequestElement('rallye_id'))), __FILE__, __LINE__);
266 if (!ifSqlHasZeroNums($result)) {
268 $content['rallye_id'] = bigintval(getRequestElement('rallye_id'));
269 while ($row = sqlFetchArray($result)) {
270 // Check for referral count
271 $count = getReferralRallyeRefsCount($row['userid'], $row['refs']);
278 if (($row['curr_points'] > 0) && ($count > 0)) {
284 $points = countSumTotalData($row['userid'], 'user_points', 'points', 'userid', FALSE, " AND `ref_depth`=1");
285 //* DEBUG: */ debugOutput(basename(__FILE__).':userid='.$row['userid'].',points='.$points.',opoints='.$row['curr_points']);
289 'userid' => $row['userid'],
292 'refs' => $row['refs'],
294 'opoints' => ($points - $row['curr_points']),
297 // Load row template and switch color
298 $OUT .= loadTemplate('admin_list_rallye_usr_row', TRUE, $row);
302 $content['rows'] = $OUT;
303 $content['rallye_id'] = bigintval(getRequestElement('rallye_id'));
306 sqlFreeResult($result);
309 loadTemplate('admin_list_rallye_usr', FALSE, $content);
312 displayMessage('{--ADMIN_RALLYE_USERS_404--}');
315 // Start listing rallyes
316 $result = sqlQuery("SELECT
331 `{?_MYSQL_PREFIX?}_rallye_data`
333 `start_time` DESC", __FILE__, __LINE__);
336 if (!ifSqlHasZeroNums($result)) {
337 // List found rallyes
339 while ($data = sqlFetchArray($result)) {
340 // Count joined userids
341 $users = countSumTotalData($data['rallye_id'], 'rallye_users', 'rallye_id', 'rallye_id', TRUE);
343 // Did some users joined this rallye?
346 $users = '<a href="{%url=modules.php?module=admin&what=list_rallyes&sub=users&rallye_id=' . $data['rallye_id'] . '%}" title="{--ADMIN_LIST_RALLYE_USERS_TITLE--}">{%pipe,translateComma=' . $users . '%}</a>';
349 // Transfer data into array for the template
351 'select' => '<input type="checkbox" name="sel[' . $data['rallye_id'] . ']" class="form_field" value="1" />',
352 'admin_id' => $data['admin_id'],
353 'rallye_id' => $data['rallye_id'],
354 'title' => $data['title'],
355 'template' => $data['template'],
356 'users_content' => $users,
357 'start_date' => generateDateTime($data['start_time'], 2),
358 'end_date' => generateDateTime($data['end_time'] , 2),
359 'is_active' => $data['is_active'],
360 'send_notify' => $data['send_notify'],
361 'auto_add_new_user' => $data['auto_add_new_user'],
362 'notified' => $data['notified'],
363 'prices_cnt' => countSumTotalData($data['rallye_id'], 'rallye_prices', 'rallye_id', 'rallye_id', TRUE),
364 'descr' => $data['descr'],
365 'min_users' => $data['min_users'],
366 'min_prices' => $data['min_prices'],
369 // Is the rallye active or not?
370 switch ($data['is_active']) {
372 // Rallye is active so do not edit it!
373 $row['select'] = '<div class="big">' . $row['rallye_id'] . '</div>';
374 $row['active_title'] = '{--ADMIN_RALLYE_DEACTIVATE_NOW--}';
375 $row['active'] = '0';
379 $row['active_title'] = '{--ADMIN_RALLYE_ACTIVATE_NOW--}';
384 // Notification to members?
385 switch ($data['send_notify']) {
387 $row['notify_title'] = '{--ADMIN_RALLYE_STOP_NOTIFY_NOW--}';
388 $row['notify'] = '0';
392 $row['notify_title'] = '{--ADMIN_RALLYE_START_NOTIFY_NOW--}';
397 // Auto-add of new joined members?
398 switch ($data['auto_add_new_user']) {
400 $row['auto_title'] = '{--ADMIN_RALLYE_STOP_AUTO_ADD_NOW--}';
405 $row['auto_title'] = '{--ADMIN_RALLYE_START_AUTO_ADD_NOW--}';
411 $OUT .= loadTemplate('admin_list_rallyes_row', TRUE, $row);
415 sqlFreeResult($result);
417 // Remember rows in array
418 $content['rows'] = $OUT;
421 loadTemplate('admin_list_rallyes', FALSE, $content);
423 // No rallyes setup so far
424 displayMessage('{--ADMIN_RALLYE_NO_RALLYES_SETUP--}');