All resets rewritten, missing svn:properties added
[mailer.git] / inc / modules / member / what-points.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/19/2003 *
4  * ===================                          Last change: 11/12/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-points.php                                  *
8  * -------------------------------------------------------------------- *
9  * Short description : All your collected points...                     *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Alle Ihrer gesammelten Punkte                    *
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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } elseif (!isMember()) {
44         redirectToIndexMemberOnlyModule();
45 }
46
47 // Add description as navigation point
48 addMenuDescription('member', __FILE__);
49
50 // Query for referal levels and percents
51 $result_depths = SQL_QUERY("SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY `level` ASC", __FILE__, __LINE__);
52 $depths = SQL_NUMROWS($result_depths);
53
54 // Add many more rows for the login/turbo/ref/order bonus
55 // @TODO Should we rewrite this to a filter?
56 if (!isExtensionActive('bonus')) $depths += 1;
57 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) $depths += 6;
58 if (isExtensionInstalledAndNewer('bonus', '0.4.4')) $depths += 4;
59
60 // Remember row count in constant
61 $content['rowspan'] = ($depths*2+15);
62
63 // Init some vars...
64 $totalPoints = '0';
65 $totalReferals = '0';
66 $totalLocked = '0';
67 $OUT = '';
68
69 // Load ref levels
70 while ($data = SQL_FETCHARRAY($result_depths)) {
71         // Merge it together
72         $content = merge_array($content, $data);
73
74         // Initialize array elements
75         $content['counter'] = '0';
76         $content['points'] = '0.00000';
77         $content['locked_points'] = '0.00000';
78
79         // Load referal points
80         $result_points = SQL_QUERY_ESC("SELECT `points`, `locked_points` FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s AND `ref_depth`='%s' LIMIT 1",
81                 array(
82                         getMemberId(),
83                         bigintval($content['level'])
84                 ), __FILE__, __LINE__);
85
86         // Do we have an entry?
87         if (SQL_NUMROWS($result_points) == 1) {
88                 // Load data
89                 $content = merge_array($content, SQL_FETCHARRAY($result_points));
90
91                 // Add both points
92                 $totalPoints += $content['points'];
93                 $totalLocked += $content['locked_points'];
94         } // END - if
95
96         // Free result
97         SQL_FREERESULT($result_points);
98
99         // Load referal counts
100         $result_refs = SQL_QUERY_ESC("SELECT `counter` FROM `{?_MYSQL_PREFIX?}_refsystem` WHERE `userid`=%s AND `level`='%s' LIMIT 1",
101                 array(
102                         getMemberId(),
103                         bigintval($content['level'])
104                 ), __FILE__, __LINE__);
105
106         // Do we have an entry?
107         if (SQL_NUMROWS($result_refs) == 1) {
108                 // Load data
109                 $content = merge_array($content, SQL_FETCHARRAY($result_refs));
110
111                 // Add them to total refs
112                 $totalReferals += $content['counter'];
113         } // END - if
114
115         // Free result
116         SQL_FREERESULT($result_refs);
117
118         // Output row
119         $OUT .= loadTemplate('member_points_row', true, $content);
120 } // END - while
121
122 // Free memory
123 SQL_FREERESULT($result_depths);
124
125 // Put rows to constant for the main template
126 $content['rows'] = $OUT;
127
128 // Initialize variables
129 $CONFIRMED = '---';
130 $SENT      = '---';
131 $RECEIVED  = '---';
132
133 // Only user >= v0.1.2: Fetch confirmed mails counter
134 if (isExtensionInstalledAndNewer('user', '0.1.2')) {
135         $add = '';
136         $CONFIRMED = getUserData('mails_confirmed');
137
138         if (isExtensionInstalledAndNewer('user', '0.1.4')) {
139                 $SENT     = getUserData('emails_sent');
140                 $RECEIVED = getUserData('emails_received');
141         } // END - if
142
143         // Please update the user extension if you see 3 dashes
144         if (empty($SENT))     $SENT     = '---';
145         if (empty($RECEIVED)) $RECEIVED = '---';
146 } else {
147         // Please update!
148         $CONFIRMED = '---';
149 }
150
151 // If TLOCK is 0 add 3 zeros for floating
152 if ($totalLocked == '0') $totalLocked = '0.00000';
153
154 // Remember several values in constants
155 $content['sum']   = ($totalPoints - getUserData('used_points'), false);
156 $content['tref']  = $totalReferals;
157 $content['tlock'] = $totalLocked;
158
159 // Fixes a bug when there is no bonus extension installed
160 if (isExtensionInstalledAndOlder('bonus', '0.4.4')) setConfigEntry('bonus_active', 'X');
161
162 // Members shall see no special rows here
163 $content['special_rows'] = '';
164
165 // Display login bonus and turbo-click bonus
166 if ((isExtensionInstalledAndNewer('bonus', '0.2.2')) && (isExtensionActive('bonus')) && (getConfig('bonus_active') == 'Y')) {
167         // Fetch some data and init others (to avoid a notice here)
168         $content['login'] = getUserData('login_bonus');
169         $content['turbo'] = getUserData('turbo_bonus');
170
171         // Get more data if ext-bonus is newer
172         if (isExtensionInstalledAndNewer('bonus', '0.4.4')) {
173                 $content['ref']   = getUserData('bonus_ref');
174                 $content['order'] = getUserData('bonus_order');
175                 $content['stats'] = getUserData('bonus_stats');
176         } // END - if
177
178         // Total bonus points
179         $content['ttotal'] = $content['turbo'] + $content['login'] + $content['ref'] + $content['order'] + $content['stats'];
180
181         // Output rows
182         $content['special_rows'] = loadTemplate('member_points_bonus_rows', true, $content);
183 } elseif ((isExtensionActive('bonus')) && (getConfig('bonus_active') != 'Y')) {
184         // Bonus active rallye deactivated
185         $content['special_rows'] = loadTemplate('member_points_bonus_disabled', true);
186 } elseif ((isAdmin()) && (isExtensionOlder('bonus', '0.2.2')) && (isExtensionActive('bonus'))) {
187         // Please upgrade your bonus extension to v0.2.2 or newer!
188         $content['special_rows'] = loadTemplate('member_points_upgrade');
189 }
190
191 // Remeber values for the final template
192 $content['receive']   = $RECEIVED;
193 $content['confirmed'] = $CONFIRMED;
194 $content['sent']      = $SENT;
195
196 // Load final template
197 if (isExtensionActive('user')) {
198         // Load template when required extension is there
199         loadTemplate('member_points', false, $content);
200 } elseif (isAdmin()) {
201         // Missing extension
202         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('user'));
203 } else {
204         // Message for user
205         loadTemplate('admin_settings_saved', false, getMessage('PROBLEM_POINTS_OVERVIEW_UNAVAILABLE'));
206 }
207
208 if (isExtensionActive('payout')) {
209         // Payput extension is installed and active so we can check if the user has enougth points
210         outputPayoutList(convertCommaToDot(($totalPoints - getUserData('used_points'))));
211 } // END - if
212
213 // [EOF]
214 ?>