2fbfa978efbc7659349386b2e4afd17ebe96aed7
[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 - 2015 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 = padLeftZero(getMonth() - 1, 2);
51                 updateConfiguration('last_monthly', $curr);
52                 displayMessage('{--ADMIN_BONUS_WITHDRAW_PREPARED--}');
53         } // END - if
54
55         // Old version ???
56         $pointsColumns = '`turbo_bonus`';
57
58         // Run filter chain to find more columns
59         $add = runFilterChain('add_bonus_points_user_columns', '');
60
61         // Add them, if some where configured
62         if (!empty($add)) {
63                 // Add more bonus points here
64                 $pointsColumns = '(0' . $add . ')';
65         } // END - if
66
67         // Init variables
68         $lastOnline = '';
69
70         // Autopurge installed?
71         if ((isExtensionActive('autopurge')) && ((getApInactiveSince() > 0))) {
72                 // Use last online timestamp to keep inactive members away from here
73                 $lastOnline = ' AND (UNIX_TIMESTAMP() - `last_online`) < {?ap_inactive_since?}';
74         } // END - if
75
76         // Check if at least one is in the active rallye
77         $result = sqlQuery("SELECT
78         `userid`,
79         `email`,
80         " . $pointsColumns . " AS `points`,
81         `last_online`
82 FROM
83         `{?_MYSQL_PREFIX?}_user_data`
84 WHERE
85         `status`='CONFIRMED' AND
86         " . $pointsColumns . " > 0
87         " . $lastOnline . "
88         " . runFilterChain('user_exclusion_sql', ' ') . "
89 ORDER BY
90         `points` DESC,
91         `last_online` DESC,
92         `userid` ASC", __FILE__, __LINE__);
93
94         if (!ifSqlHasZeroNums($result)) {
95                 // List users
96                 $OUT   = '';
97                 $count = 1;
98                 $total = '0';
99                 while ($content = sqlFetchArray($result)) {
100                         // Add total points
101                         $total += $content['points'];
102
103                         // Generate array fore the dynamic template
104                         $WIN1 = ''; $WIN2 = '';
105                         if ($count <= getBonusRanks()) {
106                                 // Maybe he can win his active bonus?
107                                 $WIN1 = '<strong>';
108                                 $WIN2 = '</strong>';
109                         } // END - if
110
111                         // Prepare content
112                         $content['email']       = generateEmailLink($content['email'], 'user_data');
113                         $content['last_online'] = generateDateTime($content['last_online'], 2);
114                         $content['win1']        = $WIN1;
115                         $content['win2']        = $WIN2;
116                         $content['count']       = $count;
117
118                         // Load template and add it
119                         $OUT .= loadTemplate('admin_list_bonus_rows', TRUE, $content);
120                         $count++;
121                 } // END - while
122
123                 $content['rows']  = $OUT;
124                 $content['total_points'] = $total;
125
126                 // Check if we need to display form or not with manuel withdraw
127                 if (getLastMonthly() == getMonth()) {
128                         // Load form
129                         $content['withdraw_form'] = loadTemplate('admin_list_bonus_form', TRUE);
130                 } else {
131                         // Display message "no manual withdraw possible"
132                         $content['withdraw_form'] = returnErrorMessage('{--ADMIN_BONUS_ALREADY_WITHDRAW--}');
133                 }
134
135                 // Prepare constant for timemark
136                 // @TODO Can't this be moved into our expression language?
137                 if (isExtensionActive('autopurge')) {
138                         $content['autopurge_timeout'] = '{%message,ADMIN_BONUS_TIMEOUT=' . generateDateTime(time() - getApInactiveSince(), 2) . '%}';
139                 } else {
140                         $content['autopurge_timeout'] = '{%pipe,generateExtensionInactiveNotInstalledMessage=autopurge%}';
141                 }
142
143                 // Load final template
144                 loadTemplate('admin_list_bonus', FALSE, $content);
145         } else {
146                 // No one has become an "activity bonus"...
147                 displayMessage('{--ADMIN_BONUS_NO_ACTIVE_RALLYE--}');
148         }
149 } else {
150         // Aktive-Rallye not activated
151         displayMessage('{--ADMIN_BONUS_RALLYE_DEACTIVATED--}');
152 }
153
154 // [EOF]
155 ?>