Huge rewrite of default parameters, ext-network continued:
[mailer.git] / inc / modules / admin / what-config_points.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/12/2003 *
4  * ===============                              Last change: 12/12/2004 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 }
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 // Init variables
48 $message = '';
49
50 // Is the 'sub' parameter set?
51 if (isGetRequestElementSet('sub')) {
52         // Yes, then do some sanity-checks
53         switch (getRequestElement('sub')) {
54                 case 'points':
55                         if ((!isPostRequestElementSet(('points_register'))) || (!isPostRequestElementSet(('points_ref')))) {
56                                 unsetPostRequestElement('ok');
57                         }
58                         break;
59
60                 case 'ref':
61                         if (isGetRequestElementSet('do')) {
62                                 if (((!isPostRequestElementSet(('level'))) || (!isPostRequestElementSet(('percents')))) && (getRequestElement('do') == 'add')) {
63                                         unsetPostRequestElement('ok');
64                                 }
65                         }
66                         break;
67         }
68 } else {
69         // Display overview
70         setRequestGetElement('sub', 'overview');
71 }
72
73 if (isFormSent()) {
74         initSqls();
75         switch (getRequestElement('sub')) {
76                 case 'points':
77                         updateConfiguration(array('points_register', 'points_ref'), array(postRequestElement('points_register'), postRequestElement('points_ref')));
78                         break;
79
80                 case 'ref':
81                         switch (getRequestElement('do'))
82                         {
83                                 case 'add':
84                                         addSql("INSERT INTO `{?_MYSQL_PREFIX?}_refdepths` (`level`, `percents`) VALUES ('".postRequestElement('level')."','".postRequestElement('percents')."')");
85                                         break;
86
87                                 case 'edit': // Change entries
88                                         foreach (postRequestElement('level') as $id => $value) {
89                                                 // Secure id
90                                                 $id = bigintval($id);
91
92                                                 // Revert german commata
93                                                 setRequestPostElement('percents', array($id => convertCommaToDot(postRequestElement('percents', $id))));
94
95                                                 // Update entry
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__);
98                                         }
99                                         $message = getMessage('REF_DEPTHS_SAVED');
100                                         break;
101
102                                 case 'del':
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__);
106                                         }
107                                         $message = getMessage('REF_DEPTHS_DELETED');
108                                         break;
109                         }
110
111                         // Update cache file
112                         if (getExtensionVersion('cache') >= '0.1.2') {
113                                 if ($GLOBALS['cache_instance']->loadCacheFile('refdepths')) $GLOBALS['cache_instance']->removeCacheFile();
114                         }
115                         break;
116
117                 case 'settings':
118                         $REF = bigintval(postRequestElement('ref_payout'));
119                         updateConfiguration(
120                                 array('allow_direct_pay', 'reg_points_mode', 'ref_payout'),
121                                 array(postRequestElement('allow_direct_pay'), postRequestElement('reg_points_mode'), $REF)
122                         );
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");
132                         }
133                         break;
134         }
135
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);
141                 } // END - if
142
143                 if (countSqls() > 0) {
144                         // Run all SQL commands
145                         runFilterChain('run_sqls');
146
147                         // Entry saved...
148                         $message = getMessage('SETTINGS_SAVED');
149
150                         // Destroy config cache file here...
151                         rebuildCacheFile('config', 'config');
152                 } else {
153                         // Prepare failed-message
154                         $message = "<span class=\"admin_failed\">{--SETTINGS_NOT_SAVED--}</span>";
155                 }
156
157                 // Remove SQL queries
158                 unsetSqls();
159         }
160
161         // Shall we display a message?
162         if (!empty($message)) {
163                 // When do so...
164                 loadTemplate('admin_settings_saved', false, $message);
165         }
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"';
173         } // END - foreach
174
175         // One-time referal bonus add-mode
176         foreach (array('reg_points_mode_ref','reg_points_mode_direct') as $entry) {
177                 $content[$entry] = '';
178         } // END - if
179         $content['reg_points_mode_' . strtolower(getConfig('reg_points_mode'))] = ' checked="checked"';
180
181         // Load template
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)) {
186                 // Delete entries
187                 $OUT = ''; $SW = 2;
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);
193
194                         // Prepare data for the row template
195                         $content = array(
196                                 'sw'       => $SW,
197                                 'id'       => $id,
198                                 'level'    => $content['level'],
199                                 'percents' => translateComma($content['percents']),
200                         );
201
202                         // Load row template and switch color
203                         $OUT .= loadTemplate('admin_points_del_row', true, $content);
204                         $SW = 3 - $SW;
205                 }
206
207                 // Load main template
208                 loadTemplate('admin_points_del', false, $OUT);
209         } elseif ((isPostRequestElementSet('edit')) && (isPostRequestElementSet('sel')) && (countPostSelection() > 0)) {
210                 // Edit entries
211                 $OUT = ''; $SW = 2;
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);
217
218                         // Prepare data for the row template
219                         $content = array(
220                                 'sw'       => $SW,
221                                 'id'       => $id,
222                                 'level'    => $content['level'],
223                                 'percents' => translateComma($content['percents']),
224                         );
225
226                         // Load row template and switch color
227                         $OUT .= loadTemplate('admin_points_edit_row', true, $content);
228                         $SW = 3 - $SW;
229                 }
230
231                 // Load main template
232                 loadTemplate('admin_points_edit', false, $OUT);
233         } else {
234                 // Referal levels
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
238                         $OUT = ''; $SW = 2;
239
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']);
245
246                                 // Load row template and switch color
247                                 $OUT .= loadTemplate('admin_points_row', true, $content);
248                                 $SW = 3 - $SW;
249                         }
250
251                         // Free memory
252                         SQL_FREERESULT($result);
253
254                         // Load main template
255                         loadTemplate('admin_points', false, $OUT);
256                 }
257
258                 // Form for adding new referal levels
259                 loadTemplate('admin_add_reflevel');
260         }
261 } elseif (getRequestElement('sub') == 'points') {
262         // Load template
263         loadTemplate('admin_config_sub_points');
264 } else {
265         // Display selection box
266         loadTemplate('admin_config_points');
267 }
268
269 // [EOF]
270 ?>