Huge script change, see http://forum.mxchange.org/topic-458.html for details:
[mailer.git] / inc / modules / member / what-points.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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 (getExtensionVersion('bonus') >= '0.2.2') $depths += 6;
57 if (getExtensionVersion('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; $TREF = 0; $TLOCK = 0; $OUT = '';
64
65 // Load ref levels
66 while ($data = SQL_FETCHARRAY($result_depths)) {
67         // Merge it together
68         $content = merge_array($content, $data);
69
70         // Initialize ref-count
71         $REFS = 0;
72
73         // Load referal points
74         $result_points = SQL_QUERY_ESC("SELECT points, locked_points FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s AND `ref_depth`='%s' LIMIT 1", array(getUserId(), bigintval($content['level'])), __FILE__, __LINE__);
75         if (SQL_NUMROWS($result_points) == 1) {
76                         list($points, $locked) = SQL_FETCHROW($result_points);
77                 // Also count locked points
78                 $totalPoints += $points; $TLOCK += $locked;
79         } else {
80                 $points = '0.00000'; $locked = '0.00000';
81         }
82
83         // Free result
84         SQL_FREERESULT($result_points);
85
86         // Load referal counts
87         $result_refs = SQL_QUERY_ESC("SELECT counter FROM `{?_MYSQL_PREFIX?}_refsystem` WHERE `userid`=%s AND level='%s' LIMIT 1",
88                 array(getUserId(), bigintval($content['level'])), __FILE__, __LINE__);
89         if (SQL_NUMROWS($result_refs) == 1) {
90                 list($REFS) = SQL_FETCHROW($result_refs);
91                 $TREF += $REFS;
92         } else {
93                 $REFS = 0;
94         }
95
96         // Free result
97         SQL_FREERESULT($result_refs);
98
99         // Transfer data to array for template
100         $row = array(
101                 'level'   => $content['level'],
102                 'percents' => translateComma($content['percents']),
103                 'points'  => translateComma($points),
104                 'refs'    => translateComma($REFS),
105         );
106
107         // Output row
108         $OUT .= loadTemplate('member_points_row', true, $row);
109 } // END - while
110
111 // Free memory
112 SQL_FREERESULT($result_depths);
113
114 // Put rows to constant for the main template
115 $content['rows'] = $OUT;
116
117 $result = SQL_QUERY_ESC("SELECT `used_points`, `ref_payout` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
118         array(getUserId()), __FILE__, __LINE__);
119 list($usedPoints, $PAY) = SQL_FETCHROW($result);
120 SQL_FREERESULT($result);
121
122 // Initialize variables
123 $CONFIRMED = '---'; $SENT = '---'; $RECEIVED = '---';
124
125 // Only user >= v0.1.2: Fetch confirmed mails counter
126 if (getExtensionVersion('user') >= '0.1.2') {
127         $add = '';
128         if (getExtensionVersion('user') >= '0.1.4') {
129                 $add = ", `emails_sent`, `emails_received`";
130         }
131         $result = SQL_QUERY_ESC("SELECT `mails_confirmed`".$add." FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
132         list($CONFIRMED, $SENT, $RECEIVED) = SQL_FETCHROW($result);
133         SQL_FREERESULT($result);
134
135         // Please update the user extension if you see 3 dashes
136         if (empty($SENT))     $SENT     = '---';
137         if (empty($RECEIVED)) $RECEIVED = '---';
138 } else {
139         // Please update!
140         $CONFIRMED = '---';
141 }
142
143 // If TLOCK is 0 add 3 zeros for floating
144 if ($TLOCK == '0') $TLOCK = '0.00000';
145
146 // Remember several values in constants
147 $content['used']  = translateComma($usedPoints);
148 $content['tpts']  = translateComma($totalPoints - $usedPoints);
149 $content['tref']  = $TREF;
150 $content['tlock'] = translateComma($TLOCK);
151
152 // Fixes a bug when there is no bonus extension installed
153 if (isExtensionOlder('bonus', '0.4.4')) setConfigEntry('bonus_active', "X");
154
155 // Members shall see no special rows here
156 $content['special_rows'] = '';
157
158 // Display login bonus and turbo-click bonus
159 if ((getExtensionVersion('bonus') >= '0.2.2') && (isExtensionActive('bonus')) && (getConfig('bonus_active') == 'Y')) {
160         $add = ", 0, 0, 0";
161         if (getExtensionVersion('bonus') >= '0.4.4') $add = ", `bonus_ref`, `bonus_order`, `bonus_stats`";
162
163         // Load data
164         $result = SQL_QUERY_ESC("SELECT `login_bonus`, `turbo_bonus`".$add." FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
165                 array(getUserId()), __FILE__, __LINE__);
166
167         // We don't add this points now. This will be done after each month
168         list($login, $turbo, $ref, $order, $stats) = SQL_FETCHROW($result);
169
170         // Free result
171         SQL_FREERESULT($result);
172
173         // Prepare constants
174         $content['turbo'] = translateComma($turbo);
175         $content['login'] = translateComma($login);
176
177         if (getExtensionVersion('bonus') >= '0.4.4') {
178                 // Add referal, stats and order bonys
179                 $content['ref']   =  translateComma($ref);
180                 $content['order'] = translateComma($order);
181                 $content['stats'] = translateComma($stats);
182         } // END - if
183
184         // Total bonus points
185         $content['ttotal'] = translateComma($turbo + $login + $ref + $order + $stats);
186
187         // Output rows
188         $content['special_rows'] = loadTemplate('member_points_bonus_rows', true, $content);
189 } elseif (getConfig('bonus_active') != 'Y') {
190         // Bonus active rallye deactivated
191         $content['special_rows'] = loadTemplate('member_points_bonus_disabled', true);
192 } elseif ((isAdmin()) && (isExtensionOlder('bonus', '0.2.2')) && (isExtensionActive('bonus'))) {
193         // Please upgrade your bonus extension to v0.2.2 or newer!
194         $content['special_rows'] = loadTemplate('member_points_upgrade');
195 }
196
197 // Remeber values for the final template
198 $content['receive']   = $RECEIVED;
199 $content['pay']       = $PAY;
200 $content['confirmed'] = $CONFIRMED;
201 $content['sent']      = $SENT;
202
203 // Load final template
204 if (isExtensionActive('user')) {
205         // Load template when required extension is there
206         loadTemplate('member_points', false, $content);
207 } elseif (isAdmin()) {
208         // Missing extension
209         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('user'));
210 } else {
211         // Message for user
212         loadTemplate('admin_settings_saved', false, getMessage('PROBLEM_POINTS_OVERVIEW_UNAVAILABLE'));
213 }
214
215 if (isExtensionActive('payout')) {
216         // Payput extension is installed and active so we can check if the user has enougth points
217         outputPayoutList(convertCommaToDot(($totalPoints - $usedPoints)));
218 } // END - if
219
220 // [EOF]
221 ?>