Complete rewrite of and , wrapper functions added, see bug #101
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 if (getConfig('bonus_active') == "Y") {
44         // Shall I withdraw now?
45         if (REQUEST_ISSET_POST(('withdraw'))) {
46                 // Okay, let's prepare...
47                 $curr = date("m", time()) - 1;
48                 if (strlen($curr) == 1) $curr = "0".$curr;
49                 UPDATE_CONFIG("last_month", $curr);
50                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_BONUS_WITHDRAW_PREPARED'));
51         }
52
53         if (GET_EXT_VERSION("bonus") >= "0.6.9") {
54                 // Add more bonus points here
55                 $USE = "(0";
56                 if (getConfig('bonus_click_yn') == "Y") $USE .= " + turbo_bonus";
57                 if (getConfig('bonus_login_yn') == "Y") $USE .= " + login_bonus";
58                 if (getConfig('bonus_order_yn') == "Y") $USE .= " + bonus_order";
59                 if (getConfig('bonus_stats_yn') == "Y") $USE .= " + bonus_stats";
60                 if (getConfig('bonus_ref_yn')   == "Y") $USE .= " + bonus_ref";
61                 $USE .= ")";
62         } else {
63                 // Old version ???
64                 $USE = "turbo_bonus";
65         }
66
67         // Autopurge installed?
68         $lastOnline = "%s"; $ONLINE = "";
69         if (EXT_IS_ACTIVE("autopurge")) {
70                 // Use last online timestamp to keep inactive members away from here
71                 $lastOnline   = " AND last_online >= (UNIX_TIMESTAMP() - %s)";
72                 $ONLINE = getConfig('ap_inactive_since');
73         }
74
75         // Check if at least one is in the active rallye
76         $result = SQL_QUERY_ESC("SELECT userid AS uid, email, gender, surname, family, ".$USE." AS points, last_online AS last
77 FROM `{!_MYSQL_PREFIX!}_user_data`
78 WHERE `status`='CONFIRMED' AND ".$USE." > 0".$lastOnline."
79 ORDER BY points DESC, last_online DESC, userid",
80          array($ONLINE), __FILE__, __LINE__);
81
82         if (SQL_NUMROWS($result) > 0) {
83                 // List users
84                 $OUT = "";$SW = 2; $cnt = 1; $total = 0;
85                 while ($content = SQL_FETCHARRAY($result)) {
86                         // Add total points
87                         $total += $content['points'];
88
89                         // Generate array fore the dynamic template
90                         $WIN1 = ""; $WIN2 = "";
91                         if ($cnt <= getConfig('bonus_ranks')) {
92                                 // Maybe he can win his active bonus?
93                                 $WIN1 = "<strong>";
94                                 $WIN2 = "</strong>";
95                         }
96
97                         // Prepare content
98                         $content['uid']    = ADMIN_USER_PROFILE_LINK($content['uid']);
99                         $content['email']  = CREATE_EMAIL_LINK($content['email'], "user_data");
100                         $content['gender'] = TRANSLATE_GENDER($content['gender']);
101                         $content['points'] = TRANSLATE_COMMA($content['points']);
102                         $content['last']   = MAKE_DATETIME($content['last'], "2");
103                         $content['sw']     = $SW;
104                         $content['win1']   = $WIN1;
105                         $content['win2']   = $WIN2;
106                         $content['cnt']    = $cnt;
107
108                         // Load template and add it
109                         $OUT .= LOAD_TEMPLATE("admin_list_bonus_rows", true, $content);
110                         $SW = 3 - $SW; $cnt++;
111                 }
112                 define('__BONUS_ROWS', $OUT);
113                 define('__TOTAL', TRANSLATE_COMMA($total));
114
115                 // Check if we need to display form or not with manuel withdraw
116                 if (getConfig('last_month') == date("m", time())) {
117                         // Load form
118                         define('__BONUS_WITHDRAW_FORM', LOAD_TEMPLATE("admin_list_bonus_form", true));
119                 } else {
120                         // Display message "no manual withdraw possible"
121                         define('__BONUS_WITHDRAW_FORM', "<div class=\"admin_failed\">{--ADMIN_BONUS_ALREADY_WITHDRAW--}</div>");
122                 }
123
124                 // Prepare constant for timemark
125                 if (EXT_IS_ACTIVE("autopurge")) {
126                         define('__AUTOPURGE_TIMEOUT', MAKE_DATETIME(time() - getConfig('ap_inactive_since'), "2"));
127                 } else {
128                         define('__AUTOPURGE_TIMEOUT', sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), "autopurge"));
129                 }
130
131                 // Load final template
132                 LOAD_TEMPLATE("admin_list_bonus");
133         } else {
134                 // No one has become an "activity bonus"...
135                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_BONUS_NO_ACTIVE_RALLYE'));
136         }
137 } else {
138         // Aktive-Rallye not activated
139         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_BONUS_RALLYE_DEACTIVATED'));
140 }
141
142 //
143 ?>