2 /************************************************************************
3 * MXChange v0.2.1 Start: 10/12/2003 *
4 * =============== Last change: 12/12/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-config_points.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Setup welcome-points for registration etc. *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Einstellen der Willkommensgutschrift usw. *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
32 ************************************************************************/
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
46 // Is the 'sub' parameter set?
47 if (REQUEST_ISSET_GET(('sub'))) {
48 // Yes, then do some sanity-checks
49 switch (REQUEST_GET('sub'))
52 if ((!REQUEST_ISSET_POST(('points_register'))) || (!REQUEST_ISSET_POST(('points_ref')))) {
53 REQUEST_UNSET_POST('ok');
58 if (REQUEST_ISSET_GET(('do'))) {
59 if (((!REQUEST_ISSET_POST(('lvl'))) || (!REQUEST_ISSET_POST(('perc')))) && (REQUEST_GET('do') == "add")) {
60 REQUEST_UNSET_POST('ok');
67 REQUEST_SET_GET('sub', "overview");
72 switch (REQUEST_GET('sub'))
75 $SQLs[] = "UPDATE `{!_MYSQL_PREFIX!}_config` SET points_register='".REQUEST_POST('points_register')."', points_ref='".REQUEST_POST('points_ref')."' WHERE config=0 LIMIT 1";
79 switch (REQUEST_GET('do'))
82 $SQLs[] = "INSERT INTO `{!_MYSQL_PREFIX!}_refdepths` (level, percents) VALUES ('".REQUEST_POST('lvl')."','".REQUEST_POST('perc')."')";
85 case "edit": // Change entries
86 foreach (REQUEST_POST('lvl') as $id => $value) {
90 // Revert german commata
91 REQUEST_POST('perc', $id) = REVERT_COMMA(REQUEST_POST('perc', $id));
94 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_refdepths` SET level='%s', percents='%s' WHERE id=%s LIMIT 1",
95 array(bigintval($value), REQUEST_POST('perc', $id), $id), __FILE__, __LINE__);
97 $message = REF_DEPTHS_SAVED;
101 foreach (REQUEST_POST('id') as $id => $value) {
102 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_refdepths` WHERE id=%s LIMIT 1",
103 array(bigintval($id)), __FILE__, __LINE__);
105 $message = REF_DEPTHS_DELETED;
110 if (GET_EXT_VERSION("cache") >= "0.1.2") {
111 if ($GLOBALS['cache_instance']->loadCacheFile("refdepths")) $GLOBALS['cache_instance']->destroyCacheFile();
116 $REF = bigintval(REQUEST_POST('ref_payout'));
117 $SQLs[] = sprintf("UPDATE `{!_MYSQL_PREFIX!}_config` SET
118 allow_direct_pay='%s',
119 reg_points_mode='%s',
121 WHERE config=0 LIMIT 1",
122 REQUEST_POST('allow_direct_pay'),
123 REQUEST_POST('reg_points_mode'),
126 if ((getConfig('ref_payout') == 0) && (REQUEST_POST('ref_payout') > 0)) {
127 // Update account's ref_payout for "must-confirm"
128 $SQLs[] = sprintf("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET ref_payout=(%s - mails_confirmed)
129 WHERE mails_confirmed < %s", $REF, $REF);
130 } elseif ((getConfig('ref_payout') > 0) && (REQUEST_POST('ref_payout') == 0)) {
131 // Update account's ref_payout for "not-must-confirm"
132 $SQLs[] = "UPDATE `{!_MYSQL_PREFIX!}_user_data` SET ref_payout=0 WHERE ref_payout > 0";
133 $SQLs[] = "UPDATE `{!_MYSQL_PREFIX!}_user_points` SET points=points+locked_points WHERE locked_points>0";
134 $SQLs[] = "UPDATE `{!_MYSQL_PREFIX!}_user_points` SET locked_points=0 WHERE locked_points>0";
139 if ((isset($SQLs)) && (is_array($SQLs)) && (!empty($SQLs[0]))) {
140 if (strpos($SQLs[0], "INSERT") > -1) {
141 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_refdepths` WHERE level='%s' LIMIT 1",
142 array(bigintval(REQUEST_POST('lvl'))), __FILE__, __LINE__);
143 SQL_FREERESULT($result);
146 if (count($SQLs) > 0) {
147 // Run all SQL commands
148 RUN_FILTER('run_sqls', array('dry_run' => false, 'sqls' => $SQLs));
151 $message = SETTINGS_SAVED;
153 // Destroy config cache file here...
154 REBUILD_CACHE("config", "config");
156 // Prepare failed-message
157 $message = "<span class=\"admin_failed\">{--SETTINGS_NOT_SAVED--}</span>";
160 // Remove SQL queries
164 // Shall we display a message?
165 if (!empty($message)) {
167 LOAD_TEMPLATE("admin_settings_saved", false, $message);
169 } elseif (REQUEST_GET('sub') == "settings") {
170 // Setup some settings like direct pay and so on
171 // Including new add-mode for one-time referal bonus
172 switch (getConfig('allow_direct_pay')) {
174 define('__DIRECT_Y', " checked=\"checked\"");
175 define('__DIRECT_N', "");
179 define('__DIRECT_Y', "");
180 define('__DIRECT_N', " checked=\"checked\"");
184 // One-time referal bonus add-mode
185 switch (getConfig('reg_points_mode')) {
186 case "ref" : define('__MODE_REF', " checked=\"checked\""); define('__MODE_DIRECT', ""); break;
187 case "direct": define('__MODE_REF', ""); define('__MODE_DIRECT', " checked=\"checked\""); break;
190 // Referal payout value
191 define('__REF_PAYOUT', round(getConfig('ref_payout')));
194 LOAD_TEMPLATE("admin_config_point_settings");
195 } elseif (REQUEST_GET('sub') == "ref") {
196 if ((REQUEST_ISSET_POST(('del'))) && (REQUEST_ISSET_POST(('sel'))) && ((SELECTION_COUNT(REQUEST_POST('sel')) > 0) || (REQUEST_ISSET_POST(('sel', 0))))) {
199 foreach (REQUEST_POST('sel') as $id => $value) {
200 $result = SQL_QUERY_ESC("SELECT level, percents FROM `{!_MYSQL_PREFIX!}_refdepths` WHERE id=%s LIMIT 1",
201 array(bigintval($id)), __FILE__, __LINE__);
202 list($lvl, $perc) = SQL_FETCHROW($result);
203 SQL_FREERESULT($result);
205 // Prepare data for the row template
210 'per' => TRANSLATE_COMMA($perc),
213 // Load row template and switch color
214 $OUT .= LOAD_TEMPLATE("admin_points_del_row", true, $content);
217 define('__LEVEL_ROWS', $OUT);
219 // Load main template
220 LOAD_TEMPLATE("admin_points_del");
221 } elseif ((REQUEST_ISSET_POST(('edit'))) && (REQUEST_ISSET_POST(('sel'))) && ((SELECTION_COUNT(REQUEST_POST('sel')) > 0) || (REQUEST_ISSET_POST(('sel', 0))))) {
224 foreach (REQUEST_POST('sel') as $id => $value) {
225 $result = SQL_QUERY_ESC("SELECT level, percents FROM `{!_MYSQL_PREFIX!}_refdepths` WHERE id=%s LIMIT 1",
226 array(bigintval($id)), __FILE__, __LINE__);
227 list($lvl, $perc) = SQL_FETCHROW($result);
228 SQL_FREERESULT($result);
230 // Prepare data for the row template
235 'per' => TRANSLATE_COMMA($perc),
238 // Load row template and switch color
239 $OUT .= LOAD_TEMPLATE("admin_points_edit_row", true, $content);
242 define('__LEVEL_ROWS', $OUT);
244 // Load main template
245 LOAD_TEMPLATE("admin_points_edit");
248 $result = SQL_QUERY("SELECT id, level, percents FROM `{!_MYSQL_PREFIX!}_refdepths` ORDER BY level", __FILE__, __LINE__);
249 if (SQL_NUMROWS($result) > 0) {
250 // Make referal levels editable and deletable
253 // List already existing categories for editing
254 while (list($id, $lvl, $perc) = SQL_FETCHROW($result)) {
255 // Prepare data for the row template
260 'per' => TRANSLATE_COMMA($perc),
263 // Load row template and switch color
264 $OUT .= LOAD_TEMPLATE("admin_points_row", true, $content);
269 SQL_FREERESULT($result);
270 define('__LEVEL_ROWS', $OUT);
272 // Load main template
273 LOAD_TEMPLATE("admin_points");
276 // Form for adding new referal levels
277 LOAD_TEMPLATE("admin_add_reflvl");
279 } elseif (REQUEST_GET('sub') == "points") {
280 // First points for registration and other fixed points including new add-mode for one-time referal bonus...
281 define('P_REG_VALUE', getConfig('points_register'));
282 define('P_REF_VALUE', getConfig('points_ref'));
285 LOAD_TEMPLATE("admin_config_sub_points");
287 // Display selection box
288 LOAD_TEMPLATE("admin_config_points");