Password reset for admin login added (still buggy if cache is installed and sql_patch...
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!IS_LOGGED_IN()) {
39         LOAD_URL("modules.php?module=index");
40 }
41
42 // Add description as navigation point
43 ADD_DESCR("member", basename(__FILE__));
44
45 OPEN_TABLE("100%", "member_content member_content_align", "");
46 $result_depths = SQL_QUERY("SELECT level, percents FROM "._MYSQL_PREFIX."_refdepths ORDER BY level", __FILE__, __LINE__);
47 $depths = SQL_NUMROWS($result_depths);
48
49 // Add many more rows for the login/turbo/ref/order bonus
50 if (!EXT_IS_ACTIVE("bonus")) $depths += 1;
51 if (GET_EXT_VERSION("bonus") >= "0.2.2") $depths += 6;
52 if (GET_EXT_VERSION("bonus") >= "0.4.4") $depths += 4;
53
54 // Remember row count in constant
55 define('__ROWS_VALUE', ($depths*2+15));
56
57 // Init some vars...
58 $TPTS = "0"; $TREF = "0"; $TLOCK = "0"; $OUT = "";
59
60 // Load ref levels
61 while (list($lvl, $per) = SQL_FETCHROW($result_depths)) {
62         // Initialize ref-count
63         $REFS = "0";
64
65         // Load referral points
66         $result_points = SQL_QUERY_ESC("SELECT points, locked_points FROM "._MYSQL_PREFIX."_user_points WHERE userid=%d AND ref_depth=%d LIMIT 1", array($GLOBALS['userid'], bigintval($lvl)), __FILE__, __LINE__);
67         if (SQL_NUMROWS($result_points) == 1) {
68                 list($points, $LOCKED) = SQL_FETCHROW($result_points);
69                 SQL_FREERESULT($result_points);
70                 // Also count locked points
71                 $TPTS += $points; $TLOCK += $LOCKED;
72         } else {
73                 $points = "0.00000"; $LOCKED = "0.00000";
74         }
75
76         // Load referral counts
77         $result_refs = SQL_QUERY_ESC("SELECT counter FROM "._MYSQL_PREFIX."_refsystem WHERE userid=%d AND level='%s' LIMIT 1", array($GLOBALS['userid'], bigintval($lvl)), __FILE__, __LINE__);
78         if (SQL_NUMROWS($result_refs) == 1) {
79                 list($REFS) = SQL_FETCHROW($result_refs);
80                 SQL_FREERESULT($result_refs);
81                 $TREF += $REFS;
82         } else {
83                 $REFS = "0";
84         }
85
86         // Transfer data to array for template
87         $content = array(
88                 'lvl'    => $lvl,
89                 'per'    => $per,
90                 'points' => TRANSLATE_COMMA($points),
91                 'refs'   => $REFS,
92         );
93
94         // Output row
95         $OUT .= LOAD_TEMPLATE("member_points_row", true, $content);
96 }
97
98 // Free memory
99 SQL_FREERESULT($result_depths);
100
101 // Put rows to constant for the main template
102 define('__REF_LEVEL_ROWS', $OUT);
103
104 $result = SQL_QUERY_ESC("SELECT used_points, ref_payout FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
105  array($GLOBALS['userid']), __FILE__, __LINE__);
106 list($USED, $PAY) = SQL_FETCHROW($result);
107 SQL_FREERESULT($result);
108
109 // Initialize variables
110 $CONFIRMED = "---"; $SENT = "---"; $RECEIVED = "---";
111
112 // Only user >= v0.1.2: Fetch confirmed mails counter
113 if (GET_EXT_VERSION("user") >= "0.1.2") {
114         $ADD = "";
115         if (GET_EXT_VERSION("user") >= "0.1.4") {
116                 $ADD = ", emails_sent, emails_received";
117         }
118         $result = SQL_QUERY_ESC("SELECT mails_confirmed".$ADD." FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__);
119         list($CONFIRMED, $SENT, $RECEIVED) = SQL_FETCHROW($result);
120         SQL_FREERESULT($result);
121
122         // Please update the user extension if you see 3 dashes
123         if (empty($SENT))     $SENT     = "---";
124         if (empty($RECEIVED)) $RECEIVED = "---";
125 } else {
126         // Please update!
127         $CONFIRMED = "---";
128 }
129
130 // If TLOCK is 0 add 3 zeros for floating
131 if ($TLOCK == "0") $TLOCK = "0.00000";
132
133 // Remember several values in constants
134 define('__USED_VALUE' , TRANSLATE_COMMA($USED));
135 define('__TPTS_VALUE' , TRANSLATE_COMMA($TPTS - $USED));
136 define('__TREF_VALUE' , $TREF);
137 define('__TLOCK_VALUE', TRANSLATE_COMMA($TLOCK));
138
139 // Fixes a bug when there is no bonus extension installed
140 if (GET_EXT_VERSION("bonus") < "0.4.4") $_CONFIG['bonus_active'] = "X";
141
142 // Display login bonus and turbo-click bonus
143 if ((GET_EXT_VERSION("bonus") >= "0.2.2") && (EXT_IS_ACTIVE("bonus")) && ($_CONFIG['bonus_active'] == "Y")) {
144         $ADD = ", 0, 0, 0";
145         if (GET_EXT_VERSION("bonus") >= "0.4.4") $ADD = ", bonus_ref, bonus_order, bonus_stats";
146
147         // Load data
148         $result = SQL_QUERY_ESC("SELECT login_bonus, turbo_bonus".$ADD." FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
149          array($GLOBALS['userid']), __FILE__, __LINE__);
150
151         // We don't add this points now. This will be done after each month
152         list($login, $turbo, $ref, $order, $stats) = SQL_FETCHROW($result);
153         SQL_FREERESULT($result);
154
155         // Prepare constants
156         define('__TURBO_VALUE',  TRANSLATE_COMMA($turbo));
157         define('__LOGIN_VALUE',  TRANSLATE_COMMA($login));
158
159         if (GET_EXT_VERSION("bonus") >= "0.4.4") {
160                 // Add referral, stats and order bonys
161                 define('__REF_VALUE'  ,  TRANSLATE_COMMA($ref));
162                 define('__ORDER_VALUE',  TRANSLATE_COMMA($order));
163                 define('__STATS_VALUE',  TRANSLATE_COMMA($stats));
164         }
165
166         // Total bonus points
167         define('__TTOTAL_VALUE', TRANSLATE_COMMA($turbo + $login + $ref + $order + $stats));
168
169         // Output rows
170         define('__SPECIAL_ROWS', LOAD_TEMPLATE("member_points_bonus_rows", true));
171 } elseif ($_CONFIG['bonus_active'] == "N") {
172         // Bonus active rallye deactivated
173         define('__SPECIAL_ROWS', LOAD_TEMPLATE("member_points_bonus_disabled", true));
174 } elseif ((IS_ADMIN()) && (GET_EXT_VERSION("bonus") < "0.2.2") && (EXT_IS_ACTIVE("bonus"))) {
175         // Please upgrade your bonus extension to v0.2.2 or newer!
176         define('__SPECIAL_ROWS', LOAD_TEMPLATE("member_points_upgrade"));
177 } else {
178         // Members shall see no special rows here
179         define('__SPECIAL_ROWS', "");
180 }
181
182 // Remeber values for the final template
183 define('__PAY_VALUE'      , $PAY);
184 define('__CONFIRMED_VALUE', $CONFIRMED);
185 define('__RECEIVE_VALUE'  , $RECEIVED);
186 define('__SENT_VALUE'     , $SENT);
187
188 // Load final template
189 if (EXT_IS_ACTIVE("user")) {
190         // Load template when required extension is there
191         LOAD_TEMPLATE("member_points");
192 } elseif (IS_ADMIN()) {
193         // Missing extension
194         ADD_FATAL(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "user"));
195 } else {
196         // Message for user
197         LOAD_TEMPLATE("admin_settings_saved", false, PROBLEM_POINTS_OVERVIEW_UNAVAILABLE);
198 }
199
200 if (EXT_IS_ACTIVE("payout")) {
201         // Payput extension is installed and active so we can check if the user has enougth points
202         PAYOUT_OUTPUT_PAYOUT_LIST(str_replace(",", ".", ($TPTS - $USED)));
203 }
204
205 CLOSE_TABLE();
206 //
207 ?>