SQL fix and double->single
[mailer.git] / inc / modules / member / what-bonus.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/19/2003 *
4  * ===============                              Last change: 11/19/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-bonus.php                                   *
8  * -------------------------------------------------------------------- *
9  * Short description : Bonus pages for some extra points                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Bonusseiten fuer ein paar Extrapunkte            *
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  * 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')) {
41         die();
42 } elseif (!isMember()) {
43         redirectToIndexMemberOnlyModule();
44 }
45
46 // Add description as navigation point
47 addMenuDescription('member', __FILE__);
48
49 if ((!isExtensionActive('bonus')) && (!isAdmin())) {
50         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('bonus'));
51         return;
52 } // END - if
53
54 if (getExtensionVersion('bonus') >= '0.6.9') {
55         // Add more bonus points here
56         // @TODO Rewrite this to a filter
57         $USE = '(0';
58         if (getConfig('bonus_click_yn') == 'Y') $USE .= ' + `turbo_bonus`';
59         if (getConfig('bonus_login_yn') == 'Y') $USE .= ' + `login_bonus`';
60         if (getConfig('bonus_order_yn') == 'Y') $USE .= ' + `bonus_order`';
61         if (getConfig('bonus_stats_yn') == 'Y') $USE .= ' + `bonus_stats`';
62         if (getConfig('bonus_ref_yn')   == 'Y') $USE .= ' + `bonus_ref`';
63         $USE .= ')';
64 } else {
65         // Old version ???
66         $USE = '`turbo_bonus`';
67 }
68
69 // Autopurge installed?
70 $lastOnline = "%s"; $ONLINE = '';
71 if (isExtensionActive('autopurge')) {
72         // Use last online timestamp to keep inactive members away from here
73         $lastOnline   = " AND `last_online` >= (UNIX_TIMESTAMP() - %s)";
74         $ONLINE = getConfig('ap_inactive_since');
75 }
76
77 // Let's check if there are some points left we can 'pay'...
78 $result = SQL_QUERY_ESC("SELECT
79         `userid`, ".$USE." AS points, `last_online`
80 FROM
81         `{?_MYSQL_PREFIX?}_user_data`
82 WHERE
83         ".$USE." > 0 AND `status`='CONFIRMED'".$lastOnline."
84 ORDER BY
85         `points` DESC,
86         last_online DESC,
87         userid ASC
88 LIMIT %s",
89         array(
90                 $ONLINE,
91                 getConfig('bonus_ranks')
92         ), __FILE__, __LINE__);
93
94 // Reset temporary variable and check for users
95 $OUT = '';
96 if (SQL_NUMROWS($result) > 0) {
97         // Load our winners...
98         $SW = 2; $cnt = 1;
99         while ($content = SQL_FETCHARRAY($result)) {
100                 // Prepare data for the template
101                 $content = array(
102                         'sw'     => $SW,
103                         'cnt'    => $cnt,
104                         'userid'    => bigintval($content['userid']),
105                         'points' => translateComma($content['points']),
106                         'last_online'   => generateDateTime($content['last_online'], '2')
107                 );
108
109                 // Load row template
110                 $OUT .= loadTemplate('member_bonus_row', true, $content);
111
112                 // Count one up and switch colors
113                 $cnt++; $SW = 3 - $SW;
114         }
115 } else {
116         // No one is interested in our "active rallye" ! :-(
117         $OUT = loadTemplate('member_bonus_404', true);
118 }
119
120 // Free memory
121 SQL_FREERESULT($result);
122
123 // Prepare content array
124 $content['rows'] = $OUT;
125
126 // Load final template
127 loadTemplate('member_bonus', false, $content);
128
129 // [EOF]
130 ?>