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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
49 // Is the 'sub' parameter set?
50 if (isGetRequestElementSet('sub')) {
51 // Yes, then do some sanity-checks
52 switch (getRequestElement('sub')) {
54 if ((!isPostRequestElementSet('points_register')) || (!isPostRequestElementSet('points_ref'))) {
55 unsetPostRequestElement('ok');
60 if (isGetRequestElementSet('do')) {
61 if (((!isPostRequestElementSet('level')) || (!isPostRequestElementSet('percents'))) && (getRequestElement('do') == 'add')) {
62 unsetPostRequestElement('ok');
69 setGetRequestElement('sub', 'overview');
74 switch (getRequestElement('sub')) {
76 adminSaveSettingsFromPostData();
80 switch (getRequestElement('do')) {
82 addSql("INSERT INTO `{?_MYSQL_PREFIX?}_refdepths` (`level`,`percents`) VALUES ('".bigintval(postRequestElement('level'))."','".bigintval(postRequestElement('percents'))."')");
85 case 'edit': // Change entries
86 foreach (postRequestElement('level') as $id => $value) {
90 // Revert german commata
91 setPostRequestElement('percents', array($id => convertCommaToDot(postRequestElement('percents', $id))));
94 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refdepths` SET `level`=%s,`percents`=%s WHERE `id`=%s LIMIT 1",
95 array(bigintval($value), convertCommaToDot(postRequestElement('percents', $id)), $id), __FILE__, __LINE__);
97 $message = '{--ADMIN_REFERRAL_DEPTHS_SAVED--}';
101 foreach (postRequestElement('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 = '{--ADMIN_REFERRAL_DEPTHS_DELETED--}';
110 // @TODO Rewrite this to a filter
111 if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
112 if ($GLOBALS['cache_instance']->loadCacheFile('refdepths')) $GLOBALS['cache_instance']->removeCacheFile();
117 $REF = bigintval(postRequestElement('ref_payout'));
119 array('allow_direct_pay', 'ref_payout'),
120 array(postRequestElement('allow_direct_pay'), $REF)
122 if ((getRefPayout() == '0') && (postRequestElement('ref_payout') > 0)) {
123 // Update account's ref_payout for "must-confirm"
124 addSql(sprintf("UPDATE
125 `{?_MYSQL_PREFIX?}_user_data`
127 `ref_payout`=(%s - `mails_confirmed`)
129 `mails_confirmed` < %s", $REF, $REF));
130 } elseif ((getRefPayout() > 0) && (postRequestElement('ref_payout') == '0')) {
131 // Update account's ref_payout for "not-must-confirm"
132 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=0 WHERE `ref_payout` > 0");
133 // @TODO Rewrite these two lines for new user_points columns (e.g. locked_order_points) with a filter
134 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `points`=`points`+`locked_points` WHERE `locked_points` > 0");
135 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `locked_points`=0 WHERE `locked_points` > 0");
140 if ((isSqlsValid()) && (isSqlsValid())) {
142 if (isInString('INSERT', $GLOBALS['sqls'][0])) {
143 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level`=%s LIMIT 1",
144 array(bigintval(postRequestElement('level'))), __FILE__, __LINE__);
145 SQL_FREERESULT($result);
148 if (countSqls() > 0) {
149 // Run all SQL commands
150 runFilterChain('run_sqls');
153 $message = '{--SETTINGS_SAVED--}';
155 // Destroy config cache file here...
156 rebuildCache('config', 'config');
158 // Prepare failed-message
159 $message = '<span class="bad">{--SETTINGS_NOT_SAVED--}</span>';
162 // Remove SQL queries
166 // Shall we display a message?
167 if (!empty($message)) {
169 displayMessage($message);
171 } elseif (getRequestElement('sub') == 'settings') {
172 // Setup some settings like direct pay and so on
173 // Including new add-mode for one-time referral bonus
174 foreach (array('allow_direct_pay') as $entry) {
175 $content[$entry . '_y'] = '';
176 $content[$entry . '_n'] = '';
177 $content[$entry . '_' . strtolower(getConfig($entry))] = ' checked="checked"';
181 loadTemplate('admin_config_point_settings', false, $content);
182 } elseif (getRequestElement('sub') == 'ref') {
184 if ((isFormSent('delete')) && (ifPostContainsSelections())) {
187 foreach (postRequestElement('sel') as $id => $value) {
188 $result = SQL_QUERY_ESC("SELECT `id`,`level`,`percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
189 array(bigintval($id)), __FILE__, __LINE__);
190 $content = SQL_FETCHARRAY($result);
191 SQL_FREERESULT($result);
193 // Load row template and switch color
194 $OUT .= loadTemplate('admin_delete_reflevel_row', true, $content);
197 // Load main template
198 loadTemplate('admin_delete_reflevel', false, $OUT);
199 } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
202 foreach (postRequestElement('sel') as $id => $value) {
203 $result = SQL_QUERY_ESC("SELECT `id`,`level`,`percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
204 array(bigintval($id)), __FILE__, __LINE__);
205 $content = SQL_FETCHARRAY($result);
206 SQL_FREERESULT($result);
208 // Load row template and switch color
209 $OUT .= loadTemplate('admin_edit_reflevel_row', true, $content);
212 // Load main template
213 loadTemplate('admin_edit_reflevel', false, $OUT);
216 $result = SQL_QUERY("SELECT `id`,`level`,`percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY `level` ASC", __FILE__, __LINE__);
217 if (!SQL_HASZERONUMS($result)) {
218 // Make referral levels editable and deletable
221 // List already existing categories for editing
222 while ($content = SQL_FETCHARRAY($result)) {
223 // Load row template and switch color
224 $OUT .= loadTemplate('admin_list_reflevel_row', true, $content);
228 SQL_FREERESULT($result);
230 // Load main template
231 loadTemplate('admin_list_reflevel', false, $OUT);
234 // Form for adding new referral levels
235 loadTemplate('admin_add_reflevel');
237 } elseif (getRequestElement('sub') == 'points') {
239 loadTemplate('admin_config_sub_points');
241 // Display selection box
242 loadTemplate('admin_config_points');