Template improved, old lost code removed, some fixes
[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  * 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 // Query for referal levels and percents
50 $result_depths = SQL_QUERY("SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY `level` ASC", __FILE__, __LINE__);
51 $depths = SQL_NUMROWS($result_depths);
52
53 // Add many more rows for the login/turbo/ref/order bonus
54 // @TODO Should we rewrite this to a filter?
55 if (!isExtensionActive('bonus')) $depths += 1;
56 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) $depths += 6;
57 if (isExtensionInstalledAndNewer('bonus', '0.4.4')) $depths += 4;
58
59 // Remember row count in constant
60 $content['rowspan'] = ($depths*2+15);
61
62 // Init some vars...
63 $totalPoints = '0';
64 $totalReferals = '0';
65 $totalLocked = '0';
66 $OUT = '';
67
68 // Load ref levels
69 while ($data = SQL_FETCHARRAY($result_depths)) {
70         // Merge it together
71         $content = merge_array($content, $data);
72
73         // Initialize array elements
74         $content['counter'] = '0';
75         $content['points'] = '0.00000';
76         $content['locked_points'] = '0.00000';
77
78         // Load referal points
79         $result_points = SQL_QUERY_ESC("SELECT `points`, `locked_points` FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s AND `ref_depth`='%s' LIMIT 1",
80                 array(
81                         getMemberId(),
82                         bigintval($content['level'])
83                 ), __FILE__, __LINE__);
84
85         // Do we have an entry?
86         if (SQL_NUMROWS($result_points) == 1) {
87                 // Load data
88                 $content = merge_array($content, SQL_FETCHARRAY($result_points));
89
90                 // Add both points
91                 $totalPoints += $content['points'];
92                 $totalLocked += $content['locked_points'];
93         } // END - if
94
95         // Free result
96         SQL_FREERESULT($result_points);
97
98         // Load referal counts
99         $result_refs = SQL_QUERY_ESC("SELECT `counter` FROM `{?_MYSQL_PREFIX?}_refsystem` WHERE `userid`=%s AND `level`='%s' LIMIT 1",
100                 array(
101                         getMemberId(),
102                         bigintval($content['level'])
103                 ), __FILE__, __LINE__);
104
105         // Do we have an entry?
106         if (SQL_NUMROWS($result_refs) == 1) {
107                 // Load data
108                 $content = merge_array($content, SQL_FETCHARRAY($result_refs));
109
110                 // Add them to total refs
111                 $totalReferals += $content['counter'];
112         } // END - if
113
114         // Free result
115         SQL_FREERESULT($result_refs);
116
117         // Transfer data to array for template
118         $row = array(
119                 'level'    => $content['level'],
120                 'percents' => translateComma($content['percents']),
121                 'points'   => translateComma($content['points']),
122                 'refs'     => translateComma($content['counter']),
123         );
124
125         // Output row
126         $OUT .= loadTemplate('member_points_row', true, $row);
127 } // END - while
128
129 // Free memory
130 SQL_FREERESULT($result_depths);
131
132 // Put rows to constant for the main template
133 $content['rows'] = $OUT;
134
135 // Initialize variables
136 $CONFIRMED = '---'; $SENT = '---'; $RECEIVED = '---';
137
138 // Only user >= v0.1.2: Fetch confirmed mails counter
139 if (isExtensionInstalledAndNewer('user', '0.1.2')) {
140         $add = '';
141         $CONFIRMED = getUserData('mails_confirmed');
142
143         if (getExtensionVersion('user') >= '0.1.4') {
144                 $SENT     = getUserData('emails_sent');
145                 $RECEIVED = getUserData('emails_received');
146         } // END - if
147
148         // Please update the user extension if you see 3 dashes
149         if (empty($SENT))     $SENT     = '---';
150         if (empty($RECEIVED)) $RECEIVED = '---';
151 } else {
152         // Please update!
153         $CONFIRMED = '---';
154 }
155
156 // If TLOCK is 0 add 3 zeros for floating
157 if ($totalLocked == '0') $totalLocked = '0.00000';
158
159 // Remember several values in constants
160 $content['sum']   = translateComma($totalPoints - getUserData('used_points'), false);
161 $content['tref']  = translateComma($totalReferals);
162 $content['tlock'] = translateComma($totalLocked);
163
164 // Fixes a bug when there is no bonus extension installed
165 if (isExtensionInstalledAndOlder('bonus', '0.4.4')) setConfigEntry('bonus_active', 'X');
166
167 // Members shall see no special rows here
168 $content['special_rows'] = '';
169
170 // Display login bonus and turbo-click bonus
171 if ((isExtensionInstalledAndNewer('bonus', '0.2.2')) && (isExtensionActive('bonus')) && (getConfig('bonus_active') == 'Y')) {
172         // Fetch some data and init others (to avoid a notice here)
173         $content['login'] = getUserData('login_bonus');
174         $content['turbo'] = getUserData('turbo_bonus');
175         $content['ref']   = '0.00000';
176         $content['order'] = '0.00000';
177         $content['stats'] = '0.00000';
178
179         // Get more data if ext-bonus is newer
180         if (getExtensionVersion('bonus') >= '0.4.4') {
181                 $content['ref']   = getUserData('bonus_ref');
182                 $content['order'] = getUserData('bonus_order');
183                 $content['stats'] = getUserData('bonus_stats');
184         } // END - if
185
186         // Total bonus points
187         $content['ttotal'] = translateComma($content['turbo'] + $content['login'] + $content['ref'] + $content['order'] + $content['stats'], false);
188
189         // Translate more data
190         $content['turbo'] = translateComma($content['turbo']);
191         $content['login'] = translateComma($content['login']);
192
193         if (getExtensionVersion('bonus') >= '0.4.4') {
194                 // Add referal, stats and order bonys
195                 $content['ref']   = translateComma($content['ref']);
196                 $content['order'] = translateComma($content['order']);
197                 $content['stats'] = translateComma($content['stats']);
198         } // END - if
199
200         // Output rows
201         $content['special_rows'] = loadTemplate('member_points_bonus_rows', true, $content);
202 } elseif ((isExtensionActive('bonus')) && (getConfig('bonus_active') != 'Y')) {
203         // Bonus active rallye deactivated
204         $content['special_rows'] = loadTemplate('member_points_bonus_disabled', true);
205 } elseif ((isAdmin()) && (isExtensionOlder('bonus', '0.2.2')) && (isExtensionActive('bonus'))) {
206         // Please upgrade your bonus extension to v0.2.2 or newer!
207         $content['special_rows'] = loadTemplate('member_points_upgrade');
208 }
209
210 // Remeber values for the final template
211 $content['receive']   = translateComma($RECEIVED);
212 $content['confirmed'] = translateComma($CONFIRMED);
213 $content['sent']      = translateComma($SENT);
214
215 // Load final template
216 if (isExtensionActive('user')) {
217         // Load template when required extension is there
218         loadTemplate('member_points', false, $content);
219 } elseif (isAdmin()) {
220         // Missing extension
221         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('user'));
222 } else {
223         // Message for user
224         loadTemplate('admin_settings_saved', false, getMessage('PROBLEM_POINTS_OVERVIEW_UNAVAILABLE'));
225 }
226
227 if (isExtensionActive('payout')) {
228         // Payput extension is installed and active so we can check if the user has enougth points
229         outputPayoutList(convertCommaToDot(($totalPoints - getUserData('used_points'))));
230 } // END - if
231
232 // [EOF]
233 ?>