Updated copyright notice as there are changes in this year
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://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')) {
40         exit();
41 } elseif (!isMember()) {
42         redirectToIndexMemberOnlyModule();
43 }
44
45 // Add description as navigation point
46 addYouAreHereLink('member', __FILE__);
47
48 // Extension ext-user is highly required
49 if ((!isExtensionActive('user')) && (!isAdmin())) {
50         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=user%}');
51         return;
52 } // END - if
53
54 // Query for referral levels and percents
55 $result_depths = SQL_QUERY('SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY `level` ASC', __FILE__, __LINE__);
56
57 // Get total depths
58 $numDepths = SQL_NUMROWS($result_depths);
59
60 // Add many more rows for the login/turbo/ref/order bonus
61 // @TODO Should we rewrite this to a filter?
62 if (isExtensionActive('bonus')) {
63         // Extension ext-bonus is there, okay
64         if (isExtensionInstalledAndNewer('bonus', '0.2.2')) $numDepths += 6;
65         if (isExtensionInstalledAndNewer('bonus', '0.4.4')) $numDepths += 4;
66 } else {
67         // Not installed ext-bonus
68         $numDepths += 1;
69 }
70
71 // Remember row count in constant
72 $content['rowspan'] = ($numDepths * 2 + 15);
73
74 // Initialize array elements
75 $content['part_points']         = '0.00000';
76 $content['part_referrals']      = '0';
77 $content['part_locked']         = '0.00000';
78 $content['part_order']          = '0.00000';
79 $content['part_locked_order']   = '0.00000';
80
81 // And output variable
82 $OUT = '';
83
84 // Load ref levels
85 while ($data = SQL_FETCHARRAY($result_depths)) {
86         // Init points and counter here
87         $content['counter']             = '0';
88         $content['points']              = '0.00000';
89         $content['order_points']        = '0.00000';
90         $content['locked_points']       = '0.00000';
91         $content['locked_order_points'] = '0.00000';
92
93         // Merge it together
94         $content = merge_array($content, $data);
95
96         // Default for referral level > 0
97         $depth = '`p`.`ref_depth`=%s';
98         if (is_null($content['level'])) {
99                 $depth = '`p`.`ref_depth` IS NULL';
100         } // END - if
101
102         // Load referral points
103         $result_points = SQL_QUERY_ESC('SELECT
104         ' . getAllPointColumns('p.', ',') . '
105         `r`.`counter`
106 FROM
107         `{?_MYSQL_PREFIX?}_user_points` AS `p`
108 LEFT JOIN
109         `{?_MYSQL_PREFIX?}_refsystem` AS `r`
110 ON
111         `p`.`userid`=`r`.`userid` AND
112         `p`.`ref_depth`=`r`.`level`
113 WHERE
114         `p`.`userid`=%s AND
115         ' . $depth . '
116 LIMIT 1',
117                 array(
118                         getMemberId(),
119                         convertZeroToNull($content['level'])
120                 ), __FILE__, __LINE__);
121
122         // Is there an entry?
123         if (SQL_NUMROWS($result_points) == 1) {
124                 // Load data
125                 $content = merge_array($content, SQL_FETCHARRAY($result_points));
126
127                 // Add locked-/points
128                 $content['part_points']       += $content['points'];
129                 $content['part_locked']       += $content['locked_points'];
130
131                 // For these columns, ext-order must be installed as well
132                 if (isExtensionInstalled('order')) {
133                         $content['part_order']        += $content['order_points'];
134                         $content['part_locked_order'] += $content['locked_order_points'];
135                 } // END - if
136
137                 // Add referral counter
138                 $content['part_referrals']    += $content['counter'];
139         } // END - if
140
141         // Free result
142         SQL_FREERESULT($result_points);
143
144         // Output row
145         $OUT .= loadTemplate('member_points_row', TRUE, $content);
146 } // END - while
147
148 // Free memory
149 SQL_FREERESULT($result_depths);
150
151 // Add userid
152 $content['userid'] = getMemberId();
153
154 // Put rows to constant for the main template
155 $content['rows'] = $OUT;
156
157 // Fixes a bug when there is no bonus extension installed
158 if (isExtensionInstalledAndOlder('bonus', '0.4.4')) {
159         setConfigEntry('bonus_active', 'X');
160 } // END - if
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')) && (isBonusRallyeActive())) {
167         // Total bonus points
168         $content['bonus_total_points'] = getUserData('turbo_bonus') + getUserData('login_bonus') + getUserData('bonus_ref') + getUserData('bonus_order') + getUserData('bonus_stats');
169
170         // Output rows
171         $content['special_rows'] = loadTemplate('member_points_bonus_rows', TRUE, $content);
172 } elseif ((isExtensionActive('bonus')) && (!isBonusRallyeActive())) {
173         // Bonus active rallye deactivated
174         $content['special_rows'] = loadTemplate('member_points_bonus_disabled', TRUE);
175 } elseif ((isAdmin()) && (isExtensionInstalledAndOlder('bonus', '0.2.2')) && (isExtensionActive('bonus'))) {
176         // Please upgrade your bonus extension to v0.2.2 or newer!
177         $content['special_rows'] = loadTemplate('member_points_upgrade');
178 }
179
180 // Load final template
181 if (isExtensionActive('user')) {
182         // Load template when required extension is there
183         loadTemplate('member_points', FALSE, $content);
184 } elseif (isAdmin()) {
185         // Missing extension
186         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=user%}');
187 } else {
188         // Message for user
189         displayMessage('{--PROBLEM_POINTS_OVERVIEW_UNAVAILABLE--}');
190 }
191
192 // Is ext-payout installed?
193 if (isExtensionActive('payout')) {
194         // Payput extension is installed and active so we can check if the user has enougth points
195         outputPayoutList($content['part_points'] - getUserData('used_points'));
196 } // END - if
197
198 // [EOF]
199 ?>