A lot has been rewritten, ext-teams added, ext-forced continued:
[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 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.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         die();
41 } elseif (!isMember()) {
42         redirectToIndexMemberOnlyModule();
43 }
44
45 // Add description as navigation point
46 addYouAreHereLink('member', __FILE__);
47
48 // Query for referal levels and percents
49 $result_depths = SQL_QUERY('SELECT `level`,`percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY `level` ASC', __FILE__, __LINE__);
50
51 // Get total depths
52 $numDepths = 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')) $numDepths += 1;
57 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) $numDepths += 6;
58 if (isExtensionInstalledAndNewer('bonus', '0.4.4')) $numDepths += 4;
59
60 // Remember row count in constant
61 $content['rowspan'] = ($numDepths * 2 + 15);
62
63 // Initialize array elements
64 $content['part_points']         = '0.00000';
65 $content['part_referals']       = '0';
66 $content['part_locked']         = '0.00000';
67 $content['part_order']          = '0.00000';
68 $content['part_locked_order']   = '0.00000';
69
70 // And output variable
71 $OUT = '';
72
73 // Load ref levels
74 while ($data = SQL_FETCHARRAY($result_depths)) {
75         // Init points and counter here
76         $content['counter']             = '0';
77         $content['points']              = '0.00000';
78         $content['order_points']        = '0.00000';
79         $content['locked_points']       = '0.00000';
80         $content['locked_order_points'] = '0.00000';
81
82         // Merge it together
83         $content = merge_array($content, $data);
84
85         // Default for referal level > 0
86         $depth = 'p.`ref_depth`=%s';
87         if (is_null($content['level'])) {
88                 $depth = 'p.`ref_depth` IS NULL';
89         } // END - if
90
91         // Load referal points
92         $result_points = SQL_QUERY_ESC("SELECT
93         p.`points`,
94         p.`order_points`,
95         p.`locked_points`,
96         p.`locked_order_points`,
97         r.`counter`
98 FROM
99         `{?_MYSQL_PREFIX?}_user_points` AS p
100 LEFT JOIN
101         `{?_MYSQL_PREFIX?}_refsystem` AS r
102 ON
103         p.`userid`=r.`userid` AND
104         p.`ref_depth`=r.`level`
105 WHERE
106         p.`userid`=%s AND
107         ".$depth."
108 LIMIT 1",
109                 array(
110                         getMemberId(),
111                         makeZeroToNull($content['level'])
112                 ), __FILE__, __LINE__);
113
114         // Do we have an entry?
115         if (SQL_NUMROWS($result_points) == 1) {
116                 // Load data
117                 $content = merge_array($content, SQL_FETCHARRAY($result_points));
118
119                 // Add all entries
120                 $content['part_points']       += $content['points'];
121                 $content['part_order']        += $content['order_points'];
122                 $content['part_locked']       += $content['locked_points'];
123                 $content['part_locked_order'] += $content['locked_order_points'];
124                 $content['part_referals']     += $content['counter'];
125         } // END - if
126
127         // Free result
128         SQL_FREERESULT($result_points);
129
130         // Output row
131         $OUT .= loadTemplate('member_points_row', true, $content);
132 } // END - while
133
134 // Free memory
135 SQL_FREERESULT($result_depths);
136
137 // Add userid
138 $content['userid'] = getMemberId();
139
140 // Put rows to constant for the main template
141 $content['rows'] = $OUT;
142
143 // Fixes a bug when there is no bonus extension installed
144 if (isExtensionInstalledAndOlder('bonus', '0.4.4')) {
145         setConfigEntry('bonus_active', 'X');
146 } // END - if
147
148 // Members shall see no special rows here
149 $content['special_rows'] = '';
150
151 // Display login bonus and turbo-click bonus
152 if ((isExtensionInstalledAndNewer('bonus', '0.2.2')) && (isExtensionActive('bonus')) && (isBonusRallyeActive())) {
153         // Total bonus points
154         $content['bonus_total_points'] = getUserData('turbo_bonus') + getUserData('login_bonus') + getUserData('bonus_ref') + getUserData('bonus_order') + getUserData('bonus_stats');
155
156         // Output rows
157         $content['special_rows'] = loadTemplate('member_points_bonus_rows', true, $content);
158 } elseif ((isExtensionActive('bonus')) && (!isBonusRallyeActive())) {
159         // Bonus active rallye deactivated
160         $content['special_rows'] = loadTemplate('member_points_bonus_disabled', true);
161 } elseif ((isAdmin()) && (isExtensionInstalledAndOlder('bonus', '0.2.2')) && (isExtensionActive('bonus'))) {
162         // Please upgrade your bonus extension to v0.2.2 or newer!
163         $content['special_rows'] = loadTemplate('member_points_upgrade');
164 }
165
166 // Load final template
167 if (isExtensionActive('user')) {
168         // Load template when required extension is there
169         loadTemplate('member_points', false, $content);
170 } elseif (isAdmin()) {
171         // Missing extension
172         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=user%}');
173 } else {
174         // Message for user
175         displayMessage('{--PROBLEM_POINTS_OVERVIEW_UNAVAILABLE--}');
176 }
177
178 if (isExtensionActive('payout')) {
179         // Payput extension is installed and active so we can check if the user has enougth points
180         outputPayoutList($content['part_points'] - getUserData('used_points'));
181 } // END - if
182
183 // [EOF]
184 ?>