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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
50 // Is the 'sub' parameter set?
51 if (isGetRequestElementSet('sub')) {
52 // Yes, then do some sanity-checks
53 switch (getRequestElement('sub')) {
55 if ((!isPostRequestElementSet(('points_register'))) || (!isPostRequestElementSet(('points_ref')))) {
56 unsetPostRequestElement('ok');
61 if (isGetRequestElementSet('do')) {
62 if (((!isPostRequestElementSet(('level'))) || (!isPostRequestElementSet(('percents')))) && (getRequestElement('do') == 'add')) {
63 unsetPostRequestElement('ok');
70 setRequestGetElement('sub', 'overview');
75 switch (getRequestElement('sub')) {
77 updateConfiguration(array('points_register', 'points_ref'), array(postRequestElement('points_register'), postRequestElement('points_ref')));
81 switch (getRequestElement('do'))
84 addSql("INSERT INTO `{?_MYSQL_PREFIX?}_refdepths` (`level`, `percents`) VALUES ('".postRequestElement('level')."','".postRequestElement('percents')."')");
87 case 'edit': // Change entries
88 foreach (postRequestElement('level') as $id => $value) {
92 // Revert german commata
93 setRequestPostElement('percents', array($id => convertCommaToDot(postRequestElement('percents', $id))));
96 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refdepths` SET `level`='%s', `percents`='%s' WHERE `id`=%s LIMIT 1",
97 array(bigintval($value), postRequestElement('percents', $id), $id), __FILE__, __LINE__);
99 $message = getMessage('REF_DEPTHS_SAVED');
103 foreach (postRequestElement('id') as $id => $value) {
104 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
105 array(bigintval($id)), __FILE__, __LINE__);
107 $message = getMessage('REF_DEPTHS_DELETED');
112 if (getExtensionVersion('cache') >= '0.1.2') {
113 if ($GLOBALS['cache_instance']->loadCacheFile('refdepths')) $GLOBALS['cache_instance']->removeCacheFile();
118 $REF = bigintval(postRequestElement('ref_payout'));
120 array('allow_direct_pay', 'reg_points_mode', 'ref_payout'),
121 array(postRequestElement('allow_direct_pay'), postRequestElement('reg_points_mode'), $REF)
123 if ((getConfig('ref_payout') == 0) && (postRequestElement('ref_payout') > 0)) {
124 // Update account's ref_payout for "must-confirm"
125 addSql(sprintf("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=(%s - `mails_confirmed`)
126 WHERE `mails_confirmed` < %s", $REF, $REF));
127 } elseif ((getConfig('ref_payout') > 0) && (postRequestElement('ref_payout') == 0)) {
128 // Update account's ref_payout for "not-must-confirm"
129 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=0 WHERE `ref_payout` > 0");
130 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `points`=`points`+`locked_points` WHERE `locked_points` > 0");
131 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `locked_points`=0 WHERE `locked_points` > 0");
136 if ((isSqlsValid()) && (isSqlsValid())) {
137 if (strpos($GLOBALS['sqls'][0], 'INSERT') > -1) {
138 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level`='%s' LIMIT 1",
139 array(bigintval(postRequestElement('level'))), __FILE__, __LINE__);
140 SQL_FREERESULT($result);
143 if (countSqls() > 0) {
144 // Run all SQL commands
145 runFilterChain('run_sqls');
148 $message = getMessage('SETTINGS_SAVED');
150 // Destroy config cache file here...
151 rebuildCacheFile('config', 'config');
153 // Prepare failed-message
154 $message = "<span class=\"admin_failed\">{--SETTINGS_NOT_SAVED--}</span>";
157 // Remove SQL queries
161 // Shall we display a message?
162 if (!empty($message)) {
164 loadTemplate('admin_settings_saved', false, $message);
166 } elseif (getRequestElement('sub') == 'settings') {
167 // Setup some settings like direct pay and so on
168 // Including new add-mode for one-time referal bonus
169 foreach (array('allow_direct_pay') as $entry) {
170 $content[$entry . '_y'] = '';
171 $content[$entry . '_n'] = '';
172 $content[$entry . '_' . strtolower(getConfig($entry))] = ' checked="checked"';
175 // One-time referal bonus add-mode
176 foreach (array('reg_points_mode_ref','reg_points_mode_direct') as $entry) {
177 $content[$entry] = '';
179 $content['reg_points_mode_' . strtolower(getConfig('reg_points_mode'))] = ' checked="checked"';
182 loadTemplate('admin_config_point_settings', false, $content);
183 } elseif (getRequestElement('sub') == 'ref') {
184 // 12 3 32 2 3 32 2 3 4 43 21
185 if ((isPostRequestElementSet('del')) && (isPostRequestElementSet('sel')) && (countPostSelection() > 0)) {
188 foreach (postRequestElement('sel') as $id => $value) {
189 $result = SQL_QUERY_ESC("SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
190 array(bigintval($id)), __FILE__, __LINE__);
191 $content = SQL_FETCHARRAY($result);
192 SQL_FREERESULT($result);
194 // Prepare data for the row template
198 'level' => $content['level'],
199 'percents' => translateComma($content['percents']),
202 // Load row template and switch color
203 $OUT .= loadTemplate('admin_points_del_row', true, $content);
207 // Load main template
208 loadTemplate('admin_points_del', false, $OUT);
209 } elseif ((isPostRequestElementSet('edit')) && (isPostRequestElementSet('sel')) && (countPostSelection() > 0)) {
212 foreach (postRequestElement('sel') as $id => $value) {
213 $result = SQL_QUERY_ESC("SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
214 array(bigintval($id)), __FILE__, __LINE__);
215 $content = SQL_FETCHARRAY($result);
216 SQL_FREERESULT($result);
218 // Prepare data for the row template
222 'level' => $content['level'],
223 'percents' => translateComma($content['percents']),
226 // Load row template and switch color
227 $OUT .= loadTemplate('admin_points_edit_row', true, $content);
231 // Load main template
232 loadTemplate('admin_points_edit', false, $OUT);
235 $result = SQL_QUERY("SELECT `id`, `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY `level` ASC", __FILE__, __LINE__);
236 if (SQL_NUMROWS($result) > 0) {
237 // Make referal levels editable and deletable
240 // List already existing categories for editing
241 while ($content = SQL_FETCHARRAY($result)) {
242 // Prepare data for the row template
243 $content['sw'] = $SW;
244 $content['percents'] = translateComma($content['percents']);
246 // Load row template and switch color
247 $OUT .= loadTemplate('admin_points_row', true, $content);
252 SQL_FREERESULT($result);
254 // Load main template
255 loadTemplate('admin_points', false, $OUT);
258 // Form for adding new referal levels
259 loadTemplate('admin_add_reflevel');
261 } elseif (getRequestElement('sub') == 'points') {
263 loadTemplate('admin_config_sub_points');
265 // Display selection box
266 loadTemplate('admin_config_points');