ab6f753a30538dc3055a6088c942bbe3e5b2188c
[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 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.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 (isPostRequestParameterSet('withdraw')) {
49                 // Okay, let's prepare...
50                 $curr = getMonth() - 1;
51                 if (strlen($curr) == 1) $curr = '0' . $curr;
52                 updateConfiguration('last_month', $curr);
53                 displayMessage('{--ADMIN_BONUS_WITHDRAW_PREPARED--}');
54         } // END - if
55
56         if (isExtensionInstalledAndNewer('bonus', '0.6.9')) {
57                 // Add more bonus points here
58                 $USE = '(0';
59                 if (getConfig('bonus_click_yn') == 'Y') $USE .= ' + `turbo_bonus`';
60                 if (getConfig('bonus_login_yn') == 'Y') $USE .= ' + `login_bonus`';
61                 if (getConfig('bonus_order_yn') == 'Y') $USE .= ' + `bonus_order`';
62                 if (getConfig('bonus_stats_yn') == 'Y') $USE .= ' + `bonus_stats`';
63                 if (getConfig('bonus_ref_yn')   == 'Y') $USE .= ' + `bonus_ref`';
64                 $USE .= ')';
65         } else {
66                 // Old version ???
67                 $USE = '`turbo_bonus`';
68         }
69
70         // Init variables
71         $lastOnline = '';
72
73         // Autopurge installed?
74         if ((isExtensionActive('autopurge')) && ((getApInactiveSince() > 0))) {
75                 // Use last online timestamp to keep inactive members away from here
76                 $lastOnline = ' AND (UNIX_TIMESTAMP() - `last_online`) >= {?ap_inactive_since?}';
77         } // END - if
78
79         // Check if at least one is in the active rallye
80         $result = SQL_QUERY("SELECT
81         `userid`, `email`, `gender`, `surname`, `family`, ".$USE." AS `points`, `last_online`
82 FROM
83         `{?_MYSQL_PREFIX?}_user_data`
84 WHERE
85         `status`='CONFIRMED' AND
86         " . $USE . " > 0
87         " . $lastOnline . "
88 ORDER BY
89         `points` DESC,
90         `last_online` DESC,
91         `userid` ASC", __FILE__, __LINE__);
92
93         if (!SQL_HASZERONUMS($result)) {
94                 // List users
95                 $OUT = ''; $count = 1; $total = '0';
96                 while ($content = SQL_FETCHARRAY($result)) {
97                         // Add total points
98                         $total += $content['points'];
99
100                         // Generate array fore the dynamic template
101                         $WIN1 = ''; $WIN2 = '';
102                         if ($count <= getConfig('bonus_ranks')) {
103                                 // Maybe he can win his active bonus?
104                                 $WIN1 = '<strong>';
105                                 $WIN2 = '</strong>';
106                         } // END - if
107
108                         // Prepare content
109                         $content['email']       = generateEmailLink($content['email'], 'user_data');
110                         $content['last_online'] = generateDateTime($content['last_online'], 2);
111                         $content['win1']   = $WIN1;
112                         $content['win2']   = $WIN2;
113                         $content['count']  = $count;
114
115                         // Load template and add it
116                         $OUT .= loadTemplate('admin_list_bonus_rows', true, $content);
117                         $count++;
118                 } // END - while
119
120                 $content['rows']  = $OUT;
121                 $content['total_points'] = $total;
122
123                 // Check if we need to display form or not with manuel withdraw
124                 if (getLastMonth() == getMonth()) {
125                         // Load form
126                         $content['withdraw_form'] = loadTemplate('admin_list_bonus_form', true);
127                 } else {
128                         // Display message "no manual withdraw possible"
129                         $content['withdraw_form'] = loadTemplate('admin_settings_unsaved', true, '{--ADMIN_BONUS_ALREADY_WITHDRAW--}');
130                 }
131
132                 // Prepare constant for timemark
133                 // @TODO Can't this be moved into our expression language?
134                 if (isExtensionActive('autopurge')) {
135                         $content['autopurge_timeout'] = '{%message,ADMIN_BONUS_TIMEOUT=' . generateDateTime(time() - getApInactiveSince(), 2) . '%}';
136                 } else {
137                         $content['autopurge_timeout'] = '{%pipe,generateExtensionInactiveNotInstalledMessage=autopurge%}';
138                 }
139
140                 // Load final template
141                 loadTemplate('admin_list_bonus', false, $content);
142         } else {
143                 // No one has become an "activity bonus"...
144                 displayMessage('{--ADMIN_BONUS_NO_ACTIVE_RALLYE--}');
145         }
146 } else {
147         // Aktive-Rallye not activated
148         displayMessage('{--ADMIN_BONUS_RALLYE_DEACTIVATED--}');
149 }
150
151 // [EOF]
152 ?>