2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
38 ************************************************************************/
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
51 // Is the 'sub' parameter set?
52 if (isGetRequestParameterSet('sub')) {
53 // Yes, then do some sanity-checks
54 switch (getRequestParameter('sub')) {
56 if ((!isPostRequestParameterSet(('points_register'))) || (!isPostRequestParameterSet(('points_ref')))) {
57 unsetPostRequestParameter('ok');
62 if (isGetRequestParameterSet('do')) {
63 if (((!isPostRequestParameterSet(('level'))) || (!isPostRequestParameterSet(('percents')))) && (getRequestParameter('do') == 'add')) {
64 unsetPostRequestParameter('ok');
71 setGetRequestParameter('sub', 'overview');
76 switch (getRequestParameter('sub')) {
78 updateConfiguration(array('points_register', 'points_ref'), array(postRequestParameter('points_register'), postRequestParameter('points_ref')));
82 switch (getRequestParameter('do'))
85 addSql("INSERT INTO `{?_MYSQL_PREFIX?}_refdepths` (`level`, `percents`) VALUES ('".postRequestParameter('level')."','".postRequestParameter('percents')."')");
88 case 'edit': // Change entries
89 foreach (postRequestParameter('level') as $id => $value) {
93 // Revert german commata
94 setPostRequestParameter('percents', array($id => convertCommaToDot(postRequestParameter('percents', $id))));
97 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refdepths` SET `level`='%s', `percents`='%s' WHERE `id`=%s LIMIT 1",
98 array(bigintval($value), postRequestParameter('percents', $id), $id), __FILE__, __LINE__);
100 $message = getMessage('REF_DEPTHS_SAVED');
104 foreach (postRequestParameter('id') as $id => $value) {
105 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
106 array(bigintval($id)), __FILE__, __LINE__);
108 $message = getMessage('REF_DEPTHS_DELETED');
113 if (getExtensionVersion('cache') >= '0.1.2') {
114 if ($GLOBALS['cache_instance']->loadCacheFile('refdepths')) $GLOBALS['cache_instance']->removeCacheFile();
119 $REF = bigintval(postRequestParameter('ref_payout'));
121 array('allow_direct_pay', 'reg_points_mode', 'ref_payout'),
122 array(postRequestParameter('allow_direct_pay'), postRequestParameter('reg_points_mode'), $REF)
124 if ((getConfig('ref_payout') == '0') && (postRequestParameter('ref_payout') > 0)) {
125 // Update account's ref_payout for "must-confirm"
126 addSql(sprintf("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=(%s - `mails_confirmed`)
127 WHERE `mails_confirmed` < %s", $REF, $REF));
128 } elseif ((getConfig('ref_payout') > 0) && (postRequestParameter('ref_payout') == '0')) {
129 // Update account's ref_payout for "not-must-confirm"
130 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=0 WHERE `ref_payout` > 0");
131 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `points`=`points`+`locked_points` WHERE `locked_points` > 0");
132 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `locked_points`=0 WHERE `locked_points` > 0");
137 if ((isSqlsValid()) && (isSqlsValid())) {
138 if (strpos($GLOBALS['sqls'][0], 'INSERT') > -1) {
139 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level`='%s' LIMIT 1",
140 array(bigintval(postRequestParameter('level'))), __FILE__, __LINE__);
141 SQL_FREERESULT($result);
144 if (countSqls() > 0) {
145 // Run all SQL commands
146 runFilterChain('run_sqls');
149 $message = getMessage('SETTINGS_SAVED');
151 // Destroy config cache file here...
152 rebuildCache('config', 'config');
154 // Prepare failed-message
155 $message = '<span class="admin_failed">{--SETTINGS_NOT_SAVED--}</span>';
158 // Remove SQL queries
162 // Shall we display a message?
163 if (!empty($message)) {
165 loadTemplate('admin_settings_saved', false, $message);
167 } elseif (getRequestParameter('sub') == 'settings') {
168 // Setup some settings like direct pay and so on
169 // Including new add-mode for one-time referal bonus
170 foreach (array('allow_direct_pay') as $entry) {
171 $content[$entry . '_y'] = '';
172 $content[$entry . '_n'] = '';
173 $content[$entry . '_' . strtolower(getConfig($entry))] = ' checked="checked"';
176 // One-time referal bonus add-mode
177 foreach (array('reg_points_mode_ref','reg_points_mode_direct') as $entry) {
178 $content[$entry] = '';
180 $content['reg_points_mode_' . strtolower(getConfig('reg_points_mode'))] = ' checked="checked"';
183 loadTemplate('admin_config_point_settings', false, $content);
184 } elseif (getRequestParameter('sub') == 'ref') {
185 // 12 3 32 2 3 32 2 3 4 43 21
186 if ((isPostRequestParameterSet('del')) && (isPostRequestParameterSet('sel')) && (countPostSelection() > 0)) {
189 foreach (postRequestParameter('sel') as $id => $value) {
190 $result = SQL_QUERY_ESC("SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
191 array(bigintval($id)), __FILE__, __LINE__);
192 $content = SQL_FETCHARRAY($result);
193 SQL_FREERESULT($result);
195 // Prepare data for the row template
199 'level' => $content['level'],
200 'percents' => translateComma($content['percents']),
203 // Load row template and switch color
204 $OUT .= loadTemplate('admin_points_del_row', true, $content);
208 // Load main template
209 loadTemplate('admin_points_del', false, $OUT);
210 } elseif ((isPostRequestParameterSet('edit')) && (isPostRequestParameterSet('sel')) && (countPostSelection() > 0)) {
213 foreach (postRequestParameter('sel') as $id => $value) {
214 $result = SQL_QUERY_ESC("SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
215 array(bigintval($id)), __FILE__, __LINE__);
216 $content = SQL_FETCHARRAY($result);
217 SQL_FREERESULT($result);
219 // Prepare data for the row template
223 'level' => $content['level'],
224 'percents' => translateComma($content['percents']),
227 // Load row template and switch color
228 $OUT .= loadTemplate('admin_points_edit_row', true, $content);
232 // Load main template
233 loadTemplate('admin_points_edit', false, $OUT);
236 $result = SQL_QUERY("SELECT `id`, `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY `level` ASC", __FILE__, __LINE__);
237 if (SQL_NUMROWS($result) > 0) {
238 // Make referal levels editable and deletable
241 // List already existing categories for editing
242 while ($content = SQL_FETCHARRAY($result)) {
243 // Prepare data for the row template
244 $content['sw'] = $SW;
245 $content['percents'] = translateComma($content['percents']);
247 // Load row template and switch color
248 $OUT .= loadTemplate('admin_points_row', true, $content);
253 SQL_FREERESULT($result);
255 // Load main template
256 loadTemplate('admin_points', false, $OUT);
259 // Form for adding new referal levels
260 loadTemplate('admin_add_reflevel');
262 } elseif (getRequestParameter('sub') == 'points') {
264 loadTemplate('admin_config_sub_points');
266 // Display selection box
267 loadTemplate('admin_config_points');