Naming convention applied, ext-network menu resorted:
[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
53 // Get total depths
54 $numDepths = SQL_NUMROWS($result_depths);
55
56 // Add many more rows for the login/turbo/ref/order bonus
57 // @TODO Should we rewrite this to a filter?
58 if (!isExtensionActive('bonus')) $numDepths += 1;
59 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) $numDepths += 6;
60 if (isExtensionInstalledAndNewer('bonus', '0.4.4')) $numDepths += 4;
61
62 // Remember row count in constant
63 $content['rowspan'] = ($numDepths * 2 + 15);
64
65 // Init some vars...
66 $content['total_points'] = '0';
67 $content['total_referals'] = '0';
68 $content['total_locked'] = '0';
69 $OUT = '';
70
71 // Load ref levels
72 while ($data = SQL_FETCHARRAY($result_depths)) {
73         // Merge it together
74         $content = merge_array($content, $data);
75
76         // Initialize array elements
77         $content['counter'] = '0';
78         $content['points'] = '0.00000';
79         $content['locked_points'] = '0.00000';
80
81         // Load referal points
82         $result_points = SQL_QUERY_ESC("SELECT `points`, `locked_points` FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s AND `ref_depth`='%s' LIMIT 1",
83                 array(
84                         getMemberId(),
85                         bigintval($content['level'])
86                 ), __FILE__, __LINE__);
87
88         // Do we have an entry?
89         if (SQL_NUMROWS($result_points) == 1) {
90                 // Load data
91                 $content = merge_array($content, SQL_FETCHARRAY($result_points));
92
93                 // Add both points
94                 $content['total_points'] += $content['points'];
95                 $content['total_locked'] += $content['locked_points'];
96         } // END - if
97
98         // Free result
99         SQL_FREERESULT($result_points);
100
101         // Load referal counts
102         $result_refs = SQL_QUERY_ESC("SELECT `counter` FROM `{?_MYSQL_PREFIX?}_refsystem` WHERE `userid`=%s AND `level`='%s' LIMIT 1",
103                 array(
104                         getMemberId(),
105                         bigintval($content['level'])
106                 ), __FILE__, __LINE__);
107
108         // Do we have an entry?
109         if (SQL_NUMROWS($result_refs) == 1) {
110                 // Load data
111                 $content = merge_array($content, SQL_FETCHARRAY($result_refs));
112
113                 // Add them to total refs
114                 $content['total_referals'] += $content['counter'];
115         } // END - if
116
117         // Free result
118         SQL_FREERESULT($result_refs);
119
120         // Output row
121         $OUT .= loadTemplate('member_points_row', true, $content);
122 } // END - while
123
124 // Free memory
125 SQL_FREERESULT($result_depths);
126
127 // Put rows to constant for the main template
128 $content['rows'] = $OUT;
129
130 // Remember several values in constants
131 $content['total_points']  = ($content['total_points'] - getUserData('used_points'));
132
133 // Fixes a bug when there is no bonus extension installed
134 if (isExtensionInstalledAndOlder('bonus', '0.4.4')) setConfigEntry('bonus_active', 'X');
135
136 // Members shall see no special rows here
137 $content['special_rows'] = '';
138
139 // Display login bonus and turbo-click bonus
140 if ((isExtensionInstalledAndNewer('bonus', '0.2.2')) && (isExtensionActive('bonus')) && (isBonusRallyeActive())) {
141         // Total bonus points
142         $content['total'] = getUserData('turbo_bonus') + getUserData('login_bonus') + getUserData('bonus_ref') + getUserData('bonus_order') + getUserData('bonus_stats');
143
144         // Output rows
145         $content['special_rows'] = loadTemplate('member_points_bonus_rows', true, $content);
146 } elseif ((isExtensionActive('bonus')) && (!isBonusRallyeActive())) {
147         // Bonus active rallye deactivated
148         $content['special_rows'] = loadTemplate('member_points_bonus_disabled', true);
149 } elseif ((isAdmin()) && (isExtensionOlder('bonus', '0.2.2')) && (isExtensionActive('bonus'))) {
150         // Please upgrade your bonus extension to v0.2.2 or newer!
151         $content['special_rows'] = loadTemplate('member_points_upgrade');
152 }
153
154 // Load final template
155 if (isExtensionActive('user')) {
156         // Load template when required extension is there
157         loadTemplate('member_points', false, $content);
158 } elseif (isAdmin()) {
159         // Missing extension
160         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('user'));
161 } else {
162         // Message for user
163         loadTemplate('admin_settings_saved', false, '{--PROBLEM_POINTS_OVERVIEW_UNAVAILABLE--}');
164 }
165
166 if (isExtensionActive('payout')) {
167         // Payput extension is installed and active so we can check if the user has enougth points
168         outputPayoutList($content['total_points'] - getUserData('used_points'));
169 } // END - if
170
171 // [EOF]
172 ?>