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 ADD_SQL("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 ADD_SQL("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_SET_POST(array('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 = getMessage('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 = getMessage('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 ADD_SQL(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 ADD_SQL(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 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET ref_payout=0 WHERE ref_payout > 0");
133 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_user_points` SET points=points+locked_points WHERE locked_points>0");
134 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_user_points` SET locked_points=0 WHERE locked_points>0");
139 if ((IS_SQLS_VALID()) && (IS_SQLS_VALID())) {
140 if (strpos($GLOBALS['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 runFilterChain('run_sqls');
151 $message = getMessage('SETTINGS_SAVED');
153 // Destroy config cache file here...
154 rebuildCacheFiles("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 // 12 3 32 2 3 32 2 3 4 43 21
197 if ((REQUEST_ISSET_POST('del')) && (REQUEST_ISSET_POST('sel')) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
200 foreach (REQUEST_POST('sel') as $id => $value) {
201 $result = SQL_QUERY_ESC("SELECT level, percents FROM `{!_MYSQL_PREFIX!}_refdepths` WHERE id=%s LIMIT 1",
202 array(bigintval($id)), __FILE__, __LINE__);
203 list($lvl, $perc) = SQL_FETCHROW($result);
204 SQL_FREERESULT($result);
206 // Prepare data for the row template
211 'per' => TRANSLATE_COMMA($perc),
214 // Load row template and switch color
215 $OUT .= LOAD_TEMPLATE("admin_points_del_row", true, $content);
218 define('__LEVEL_ROWS', $OUT);
220 // Load main template
221 LOAD_TEMPLATE("admin_points_del");
222 } elseif ((REQUEST_ISSET_POST('edit')) && (REQUEST_ISSET_POST('sel')) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
225 foreach (REQUEST_POST('sel') as $id => $value) {
226 $result = SQL_QUERY_ESC("SELECT level, percents FROM `{!_MYSQL_PREFIX!}_refdepths` WHERE id=%s LIMIT 1",
227 array(bigintval($id)), __FILE__, __LINE__);
228 list($lvl, $perc) = SQL_FETCHROW($result);
229 SQL_FREERESULT($result);
231 // Prepare data for the row template
236 'per' => TRANSLATE_COMMA($perc),
239 // Load row template and switch color
240 $OUT .= LOAD_TEMPLATE("admin_points_edit_row", true, $content);
243 define('__LEVEL_ROWS', $OUT);
245 // Load main template
246 LOAD_TEMPLATE("admin_points_edit");
249 $result = SQL_QUERY("SELECT id, level, percents FROM `{!_MYSQL_PREFIX!}_refdepths` ORDER BY level", __FILE__, __LINE__);
250 if (SQL_NUMROWS($result) > 0) {
251 // Make referal levels editable and deletable
254 // List already existing categories for editing
255 while ($content = SQL_FETCHARRAY($result)) {
256 // Prepare data for the row template
257 // @TODO Rewritings: lvl->level, per->percents in template
260 'id' => $content['id'],
261 'lvl' => $content['level'],
262 'per' => TRANSLATE_COMMA($content['percents']),
265 // Load row template and switch color
266 $OUT .= LOAD_TEMPLATE("admin_points_row", true, $content);
271 SQL_FREERESULT($result);
272 define('__LEVEL_ROWS', $OUT);
274 // Load main template
275 LOAD_TEMPLATE("admin_points");
278 // Form for adding new referal levels
279 LOAD_TEMPLATE("admin_add_reflvl");
281 } elseif (REQUEST_GET('sub') == "points") {
282 // First points for registration and other fixed points including new add-mode for one-time referal bonus...
283 define('P_REG_VALUE', getConfig('points_register'));
284 define('P_REF_VALUE', getConfig('points_ref'));
287 LOAD_TEMPLATE("admin_config_sub_points");
289 // Display selection box
290 LOAD_TEMPLATE("admin_config_points");