021a2e86384e6ea80c4cca1668b48f2d6dd05541
[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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 if (getConfig('bonus_active') == 'Y') {
49         // Shall I withdraw now?
50         if (isPostRequestParameterSet('withdraw')) {
51                 // Okay, let's prepare...
52                 $curr = date('m', time()) - 1;
53                 if (strlen($curr) == 1) $curr = '0' . $curr;
54                 updateConfiguration('last_month', $curr);
55                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_BONUS_WITHDRAW_PREPARED'));
56         } // END - if
57
58         if (isExtensionInstalledAndNewer('bonus', '0.6.9')) {
59                 // Add more bonus points here
60                 $USE = '(0';
61                 if (getConfig('bonus_click_yn') == 'Y') $USE .= ' + `turbo_bonus`';
62                 if (getConfig('bonus_login_yn') == 'Y') $USE .= ' + `login_bonus`';
63                 if (getConfig('bonus_order_yn') == 'Y') $USE .= ' + `bonus_order`';
64                 if (getConfig('bonus_stats_yn') == 'Y') $USE .= ' + `bonus_stats`';
65                 if (getConfig('bonus_ref_yn')   == 'Y') $USE .= ' + `bonus_ref`';
66                 $USE .= ')';
67         } else {
68                 // Old version ???
69                 $USE = 'turbo_bonus';
70         }
71
72         // Autopurge installed?
73         $lastOnline = "%s"; $ONLINE = '';
74         if (isExtensionActive('autopurge')) {
75                 // Use last online timestamp to keep inactive members away from here
76                 $lastOnline   = " AND `last_online` >= (UNIX_TIMESTAMP() - %s)";
77                 $ONLINE = getConfig('ap_inactive_since');
78         }
79
80         // Check if at least one is in the active rallye
81         $result = SQL_QUERY_ESC("SELECT
82         `userid`, `email`, `gender`, `surname`, `family`, ".$USE." AS points, `last_online`
83 FROM
84         `{?_MYSQL_PREFIX?}_user_data`
85 WHERE
86         `status`='CONFIRMED' AND
87         ".$USE." > 0
88         ".$lastOnline."
89 ORDER BY
90         `points` DESC,
91         `last_online` DESC,
92         `userid` ASC",
93                 array($ONLINE), __FILE__, __LINE__);
94
95         if (SQL_NUMROWS($result) > 0) {
96                 // List users
97                 $OUT = '';$SW = 2; $cnt = 1; $total = '0';
98                 while ($content = SQL_FETCHARRAY($result)) {
99                         // Add total points
100                         $total += $content['points'];
101
102                         // Generate array fore the dynamic template
103                         $WIN1 = ''; $WIN2 = '';
104                         if ($cnt <= getConfig('bonus_ranks')) {
105                                 // Maybe he can win his active bonus?
106                                 $WIN1 = '<strong>';
107                                 $WIN2 = '</strong>';
108                         } // END - if
109
110                         // Prepare content
111                         $content['email']       = generateEmailLink($content['email'], 'user_data');
112                         $content['last_online'] = generateDateTime($content['last_online'], 2);
113                         $content['sw']     = $SW;
114                         $content['win1']   = $WIN1;
115                         $content['win2']   = $WIN2;
116                         $content['cnt']    = $cnt;
117
118                         // Load template and add it
119                         $OUT .= loadTemplate('admin_list_bonus_rows', true, $content);
120                         $SW = 3 - $SW; $cnt++;
121                 } // END - while
122
123                 $content['rows']  = $OUT;
124                 $content['total'] = translateComma($total);
125
126                 // Check if we need to display form or not with manuel withdraw
127                 if (getConfig('last_month') == date('m', time())) {
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'] = loadTemplate('admin_settings_saved', true, '<div class="admin_failed">{--ADMIN_BONUS_ALREADY_WITHDRAW--}</div>');
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'] = generateDateTime(time() - getConfig('ap_inactive_since'), 2);
139                 } else {
140                         $content['autopurge_timeout'] = getMaskedMessage('EXTENSION_PROBLEM_EXTENSION_NOT_INSTALLED', '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                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_BONUS_NO_ACTIVE_RALLYE'));
148         }
149 } else {
150         // Aktive-Rallye not activated
151         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_BONUS_RALLYE_DEACTIVATED'));
152 }
153
154 // [EOF]
155 ?>