Re-added
[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", basename(__FILE__));
42
43 if ($_CONFIG['bonus_active'] == "Y") {
44         // Shall I withdraw now?
45         if (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, ADMIN_BONUS_WITHDRAW_PREPARED);
51                 OUTPUT_HTML("<br />");
52         }
53
54         if (GET_EXT_VERSION("bonus") >= "0.6.9") {
55                 // Add more bonus points here
56                 $USE = "(0";
57                 if ($_CONFIG['bonus_click_yn'] == "Y") $USE .= " + turbo_bonus";
58                 if ($_CONFIG['bonus_login_yn'] == "Y") $USE .= " + login_bonus";
59                 if ($_CONFIG['bonus_order_yn'] == "Y") $USE .= " + bonus_order";
60                 if ($_CONFIG['bonus_stats_yn'] == "Y") $USE .= " + bonus_stats";
61                 if ($_CONFIG['bonus_ref_yn']   == "Y") $USE .= " + bonus_ref";
62                 $USE .= ")";
63         } else {
64                 // Old version ???
65                 $USE = "turbo_bonus";
66         }
67
68         // Autopurge installed?
69         $LAST = "%s"; $ONLINE = "";
70         if (EXT_IS_ACTIVE("autopurge")) {
71                 // Use last online timestamp to keep inactive members away from here
72                 $LAST   = " AND last_online >= (UNIX_TIMESTAMP() - %s)";
73                 $ONLINE = $_CONFIG['ap_inactive_since'];
74         }
75
76         // Check if at least one is in the active rallye
77         $result = SQL_QUERY_ESC("SELECT userid, email, gender, surname, family, ".$USE." AS active_bonus, last_online
78 FROM "._MYSQL_PREFIX."_user_data
79 WHERE status='CONFIRMED' AND ".$USE." > 0".$LAST."
80 ORDER BY active_bonus DESC, last_online DESC, userid",
81          array($ONLINE), __FILE__, __LINE__);
82
83         if (SQL_NUMROWS($result) > 0) {
84                 // List users
85                 $OUT = "";$SW = 2; $cnt = 1; $total = 0;
86                 while(list($uid, $email, $gender, $sname, $fname, $turbo, $last) = SQL_FETCHROW($result)) {
87                         // Generate array fore the dynamic template
88                         $WIN1 = ""; $WIN2 = "";
89                         if ($cnt <= $_CONFIG['bonus_ranks']) {
90                                 // Maybe he can win his active bonus?
91                                 $WIN1 = "<STRONG>";
92                                 $WIN2 = "</STRONG>";
93                         }
94
95                         // Prepare content
96                         $content = array(
97                                 'uid'    => $uid,
98                                 'email'  => CREATE_EMAIL_LINK($email, "user_data"),
99                                 'gender' => TRANSLATE_GENDER($gender),
100                                 'sname'  => $sname,
101                                 'fname'  => $fname,
102                                 'turbo'  => TRANSLATE_COMMA($turbo),
103                                 'last'   => MAKE_DATETIME($last, "2"),
104                                 'sw'     => $SW,
105                                 'win1'   => $WIN1,
106                                 'win2'   => $WIN2,
107                                 'cnt'    => $cnt,
108                         );
109
110                         // Load template and add it
111                         $OUT .= LOAD_TEMPLATE("admin_list_bonus_rows", true, $content);
112                         $SW = 3 - $SW; $cnt++; $total += $turbo;
113                 }
114                 define('__BONUS_ROWS', $OUT);
115                 define('__TOTAL', TRANSLATE_COMMA($total));
116
117                 // Check if we need to display form or not with manuel withdraw
118                 if ($_CONFIG['last_month'] == date("m", time()))
119                 {
120                         // Load form
121                         define('__BONUS_WITHDRAW_FORM', LOAD_TEMPLATE("admin_list_bonus_form", true));
122                 }
123                  else
124                 {
125                         // Display message "no manual withdraw possible"
126                         define('__BONUS_WITHDRAW_FORM', "<FONT class=\"admin_failed\">".ADMIN_BONUS_ALREADY_WITHDRAW."</FONT>");
127                 }
128
129                 // Prepare constant for timemark
130                 if (EXT_IS_ACTIVE("autopurge")) {
131                         define('__AUTOPURGE_TIMEOUT', MAKE_DATETIME(time() - $_CONFIG['ap_inactive_since'], "2"));
132                 } else {
133                         define('__AUTOPURGE_TIMEOUT', sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "autopurge"));
134                 }
135
136                 // Load final template
137                 LOAD_TEMPLATE("admin_list_bonus");
138         }
139          else
140         {
141                 // No one has become an "activity bonus"...
142                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_BONUS_NO_ACTIVE_RALLYE);
143         }
144 }
145  else
146 {
147         // Aktive-Rallye not activated
148         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_BONUS_RALLYE_DEACTIVATED);
149 }
150
151 //
152 ?>