New naming convention applied to many functions, see #118 for details
[mailer.git] / inc / modules / admin / what-list_bonus.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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 - 2008 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')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
47
48 if (getConfig('bonus_active') == 'Y') {
49         // Shall I withdraw now?
50         if (REQUEST_ISSET_POST(('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                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_BONUS_WITHDRAW_PREPARED'));
56         } // END - if
57
58         if (GET_EXT_VERSION('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 (EXT_IS_ACTIVE('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 userid AS uid, email, gender, surname, family, ".$USE." AS points, last_online AS last
82 FROM `{!_MYSQL_PREFIX!}_user_data`
83 WHERE `status`='CONFIRMED' AND ".$USE." > 0".$lastOnline."
84 ORDER BY points DESC, last_online DESC, userid",
85          array($ONLINE), __FILE__, __LINE__);
86
87         if (SQL_NUMROWS($result) > 0) {
88                 // List users
89                 $OUT = '';$SW = 2; $cnt = 1; $total = 0;
90                 while ($content = SQL_FETCHARRAY($result)) {
91                         // Add total points
92                         $total += $content['points'];
93
94                         // Generate array fore the dynamic template
95                         $WIN1 = ''; $WIN2 = '';
96                         if ($cnt <= getConfig('bonus_ranks')) {
97                                 // Maybe he can win his active bonus?
98                                 $WIN1 = "<strong>";
99                                 $WIN2 = "</strong>";
100                         }
101
102                         // Prepare content
103                         $content['uid']    = generateUserProfileLink($content['uid']);
104                         $content['email']  = generateMemberEmailLink($content['email'], "user_data");
105                         $content['gender'] = translateGender($content['gender']);
106                         $content['points'] = translateComma($content['points']);
107                         $content['last']   = generateDateTime($content['last'], "2");
108                         $content['sw']     = $SW;
109                         $content['win1']   = $WIN1;
110                         $content['win2']   = $WIN2;
111                         $content['cnt']    = $cnt;
112
113                         // Load template and add it
114                         $OUT .= LOAD_TEMPLATE("admin_list_bonus_rows", true, $content);
115                         $SW = 3 - $SW; $cnt++;
116                 }
117                 define('__BONUS_ROWS', $OUT);
118                 define('__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                         define('__BONUS_WITHDRAW_FORM', LOAD_TEMPLATE("admin_list_bonus_form", true));
124                 } else {
125                         // Display message "no manual withdraw possible"
126                         define('__BONUS_WITHDRAW_FORM', "<div class=\"admin_failed\">{--ADMIN_BONUS_ALREADY_WITHDRAW--}</div>");
127                 }
128
129                 // Prepare constant for timemark
130                 if (EXT_IS_ACTIVE('autopurge')) {
131                         define('__AUTOPURGE_TIMEOUT', generateDateTime(time() - getConfig('ap_inactive_since'), "2"));
132                 } else {
133                         define('__AUTOPURGE_TIMEOUT', sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'autopurge'));
134                 }
135
136                 // Load final template
137                 LOAD_TEMPLATE("admin_list_bonus");
138         } else {
139                 // No one has become an "activity bonus"...
140                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_BONUS_NO_ACTIVE_RALLYE'));
141         }
142 } else {
143         // Aktive-Rallye not activated
144         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_BONUS_RALLYE_DEACTIVATED'));
145 }
146
147 //
148 ?>