Login procedure rewritten to filters (internal TODO)
[mailer.git] / inc / modules / admin / what-list_bonus.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 02/04/2005 *
4  * ===================                          Last change: 11/19/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_bonus.php                              *
8  * -------------------------------------------------------------------- *
9  * Short description : List members in active-rallye                    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Mitglieder in Aktiv-Rallye 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 (getConfig('bonus_active') == 'Y') {
48         // Shall I withdraw now?
49         if (isPostRequestElementSet(('withdraw'))) {
50                 // Okay, let's prepare...
51                 $curr = date('m', time()) - 1;
52                 if (strlen($curr) == 1) $curr = '0' . $curr;
53                 updateConfiguration('last_month', $curr);
54                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_BONUS_WITHDRAW_PREPARED'));
55         } // END - if
56
57         if (getExtensionVersion('bonus') >= '0.6.9') {
58                 // Add more bonus points here
59                 $USE = '(0';
60                 if (getConfig('bonus_click_yn') == 'Y') $USE .= ' + `turbo_bonus`';
61                 if (getConfig('bonus_login_yn') == 'Y') $USE .= ' + `login_bonus`';
62                 if (getConfig('bonus_order_yn') == 'Y') $USE .= ' + `bonus_order`';
63                 if (getConfig('bonus_stats_yn') == 'Y') $USE .= ' + `bonus_stats`';
64                 if (getConfig('bonus_ref_yn')   == 'Y') $USE .= ' + `bonus_ref`';
65                 $USE .= ')';
66         } else {
67                 // Old version ???
68                 $USE = 'turbo_bonus';
69         }
70
71         // Autopurge installed?
72         $lastOnline = "%s"; $ONLINE = '';
73         if (isExtensionActive('autopurge')) {
74                 // Use last online timestamp to keep inactive members away from here
75                 $lastOnline   = " AND `last_online` >= (UNIX_TIMESTAMP() - %s)";
76                 $ONLINE = getConfig('ap_inactive_since');
77         }
78
79         // Check if at least one is in the active rallye
80         $result = SQL_QUERY_ESC("SELECT `userid`, `email`, `gender`, `surname`, `family`, ".$USE." AS points, `last_online`
81 FROM `{?_MYSQL_PREFIX?}_user_data`
82 WHERE `status`='CONFIRMED' AND ".$USE." > 0".$lastOnline."
83 ORDER BY `points` DESC, `last_online` DESC, `userid` ASC",
84         array($ONLINE), __FILE__, __LINE__);
85
86         if (SQL_NUMROWS($result) > 0) {
87                 // List users
88                 $OUT = '';$SW = 2; $cnt = 1; $total = '0';
89                 while ($content = SQL_FETCHARRAY($result)) {
90                         // Add total points
91                         $total += $content['points'];
92
93                         // Generate array fore the dynamic template
94                         $WIN1 = ''; $WIN2 = '';
95                         if ($cnt <= getConfig('bonus_ranks')) {
96                                 // Maybe he can win his active bonus?
97                                 $WIN1 = "<strong>";
98                                 $WIN2 = "</strong>";
99                         }
100
101                         // Prepare content
102                         $content['userid']    = generateUserProfileLink($content['userid']);
103                         $content['email']  = generateEmailLink($content['email'], 'user_data');
104                         $content['gender'] = translateGender($content['gender']);
105                         $content['points'] = translateComma($content['points']);
106                         $content['last_online']   = generateDateTime($content['last_online'], 2);
107                         $content['sw']     = $SW;
108                         $content['win1']   = $WIN1;
109                         $content['win2']   = $WIN2;
110                         $content['cnt']    = $cnt;
111
112                         // Load template and add it
113                         $OUT .= loadTemplate('admin_list_bonus_rows', true, $content);
114                         $SW = 3 - $SW; $cnt++;
115                 } // END - while
116
117                 $content['rows']  = $OUT;
118                 $content['total'] = translateComma($total);
119
120                 // Check if we need to display form or not with manuel withdraw
121                 if (getConfig('last_month') == date('m', time())) {
122                         // Load form
123                         $content['withdraw_form'] = loadTemplate('admin_list_bonus_form', true);
124                 } else {
125                         // Display message "no manual withdraw possible"
126                         $content['withdraw_form'] = loadTemplate('admin_settings_saved', true, "<div class=\"admin_failed\">{--ADMIN_BONUS_ALREADY_WITHDRAW--}</div>");
127                 }
128
129                 // Prepare constant for timemark
130                 if (isExtensionActive('autopurge')) {
131                         $content['autopurge_timeout'] = generateDateTime(time() - getConfig('ap_inactive_since'), 2);
132                 } else {
133                         $content['autopurge_timeout'] = loadTemplate('admin_settings_saved', true, sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'autopurge'));
134                 }
135
136                 // Load final template
137                 loadTemplate('admin_list_bonus', false, $content);
138         } else {
139                 // No one has become an "activity bonus"...
140                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_BONUS_NO_ACTIVE_RALLYE'));
141         }
142 } else {
143         // Aktive-Rallye not activated
144         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_BONUS_RALLYE_DEACTIVATED'));
145 }
146
147 // [EOF]
148 ?>