mailer project continued:
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
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.                                  *
26  *                                                                      *
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.                         *
31  *                                                                      *
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,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if (isBonusRallyeActive()) {
47         // Shall I withdraw now?
48         if (isPostRequestElementSet('withdraw')) {
49                 // Okay, let's prepare...
50                 $curr = getMonth() - 1;
51                 if (strlen($curr) == 1) $curr = '0' . $curr;
52                 updateConfiguration('last_month', $curr);
53                 displayMessage('{--ADMIN_BONUS_WITHDRAW_PREPARED--}');
54         } // END - if
55
56         // Old version ???
57         $pointsColumns = '`turbo_bonus`';
58
59         // Run filter chain to find more columns
60         $add = runFilterChain('add_bonus_points_user_columns', '');
61
62         // Add them, if some where configured
63         if (!empty($add)) {
64                 // Add more bonus points here
65                 $pointsColumns = '(0' . $add . ')';
66         } // END - if
67
68         // Init variables
69         $lastOnline = '';
70
71         // Autopurge installed?
72         if ((isExtensionActive('autopurge')) && ((getApInactiveSince() > 0))) {
73                 // Use last online timestamp to keep inactive members away from here
74                 $lastOnline = ' AND (UNIX_TIMESTAMP() - `last_online`) < {?ap_inactive_since?}';
75         } // END - if
76
77         // Check if at least one is in the active rallye
78         $result = SQL_QUERY("SELECT
79         `userid`,
80         `email`,
81         " . $pointsColumns . " AS `points`,
82         `last_online`
83 FROM
84         `{?_MYSQL_PREFIX?}_user_data`
85 WHERE
86         `status`='CONFIRMED' AND
87         " . $pointsColumns . " > 0
88         " . $lastOnline . "
89         " . runFilterChain('user_exclusion_sql', ' ') . "
90 ORDER BY
91         `points` DESC,
92         `last_online` DESC,
93         `userid` ASC", __FILE__, __LINE__);
94
95         if (!SQL_HASZERONUMS($result)) {
96                 // List users
97                 $OUT   = '';
98                 $count = 1;
99                 $total = '0';
100                 while ($content = SQL_FETCHARRAY($result)) {
101                         // Add total points
102                         $total += $content['points'];
103
104                         // Generate array fore the dynamic template
105                         $WIN1 = ''; $WIN2 = '';
106                         if ($count <= getBonusRanks()) {
107                                 // Maybe he can win his active bonus?
108                                 $WIN1 = '<strong>';
109                                 $WIN2 = '</strong>';
110                         } // END - if
111
112                         // Prepare content
113                         $content['email']       = generateEmailLink($content['email'], 'user_data');
114                         $content['last_online'] = generateDateTime($content['last_online'], 2);
115                         $content['win1']        = $WIN1;
116                         $content['win2']        = $WIN2;
117                         $content['count']       = $count;
118
119                         // Load template and add it
120                         $OUT .= loadTemplate('admin_list_bonus_rows', true, $content);
121                         $count++;
122                 } // END - while
123
124                 $content['rows']  = $OUT;
125                 $content['total_points'] = $total;
126
127                 // Check if we need to display form or not with manuel withdraw
128                 if (getLastMonth() == getMonth()) {
129                         // Load form
130                         $content['withdraw_form'] = loadTemplate('admin_list_bonus_form', true);
131                 } else {
132                         // Display message "no manual withdraw possible"
133                         $content['withdraw_form'] = loadTemplate('admin_settings_unsaved', true, '{--ADMIN_BONUS_ALREADY_WITHDRAW--}');
134                 }
135
136                 // Prepare constant for timemark
137                 // @TODO Can't this be moved into our expression language?
138                 if (isExtensionActive('autopurge')) {
139                         $content['autopurge_timeout'] = '{%message,ADMIN_BONUS_TIMEOUT=' . generateDateTime(time() - getApInactiveSince(), 2) . '%}';
140                 } else {
141                         $content['autopurge_timeout'] = '{%pipe,generateExtensionInactiveNotInstalledMessage=autopurge%}';
142                 }
143
144                 // Load final template
145                 loadTemplate('admin_list_bonus', false, $content);
146         } else {
147                 // No one has become an "activity bonus"...
148                 displayMessage('{--ADMIN_BONUS_NO_ACTIVE_RALLYE--}');
149         }
150 } else {
151         // Aktive-Rallye not activated
152         displayMessage('{--ADMIN_BONUS_RALLYE_DEACTIVATED--}');
153 }
154
155 // [EOF]
156 ?>