Removed comment introduced by Profi-Concept, this comment should fine (in a much...
[mailer.git] / inc / modules / admin / what-config_points.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
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.                                  *
26  *                                                                      *
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.                         *
31  *                                                                      *
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,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addMenuDescription('admin', __FILE__);
45
46 // Init variables
47 $message = '';
48
49 // Is the 'sub' parameter set?
50 if (isGetRequestParameterSet('sub')) {
51         // Yes, then do some sanity-checks
52         switch (getRequestParameter('sub')) {
53                 case 'points':
54                         if ((!isPostRequestParameterSet('points_register')) || (!isPostRequestParameterSet('points_ref'))) {
55                                 unsetPostRequestParameter('ok');
56                         } // END - if
57                         break;
58
59                 case 'ref':
60                         if (isGetRequestParameterSet('do')) {
61                                 if (((!isPostRequestParameterSet('level')) || (!isPostRequestParameterSet('percents'))) && (getRequestParameter('do') == 'add')) {
62                                         unsetPostRequestParameter('ok');
63                                 }
64                         }
65                         break;
66         } // END - switch
67 } else {
68         // Display overview
69         setGetRequestParameter('sub', 'overview');
70 }
71
72 if (isFormSent()) {
73         initSqls();
74         switch (getRequestParameter('sub')) {
75                 case 'points':
76                         adminSaveSettingsFromPostData();
77                         break;
78
79                 case 'ref':
80                         switch (getRequestParameter('do'))
81                         {
82                                 case 'add':
83                                         addSql("INSERT INTO `{?_MYSQL_PREFIX?}_refdepths` (`level`, `percents`) VALUES ('".postRequestParameter('level')."','".postRequestParameter('percents')."')");
84                                         break;
85
86                                 case 'edit': // Change entries
87                                         foreach (postRequestParameter('level') as $id => $value) {
88                                                 // Secure id
89                                                 $id = bigintval($id);
90
91                                                 // Revert german commata
92                                                 setPostRequestParameter('percents', array($id => convertCommaToDot(postRequestParameter('percents', $id))));
93
94                                                 // Update entry
95                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refdepths` SET `level`=%s, `percents`=%s WHERE `id`=%s LIMIT 1",
96                                                         array(bigintval($value), convertCommaToDot(postRequestParameter('percents', $id)), $id), __FILE__, __LINE__);
97                                         }
98                                         $message = '{--ADMIN_REFERAL_DEPTHS_SAVED--}';
99                                         break;
100
101                                 case 'delete':
102                                         foreach (postRequestParameter('id') as $id => $value) {
103                                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
104                                                 array(bigintval($id)), __FILE__, __LINE__);
105                                         }
106                                         $message = '{--ADMIN_REFERAL_DEPTHS_DELETED--}';
107                                         break;
108                         }
109
110                         // Update cache file
111                         // @TODO Rewrite this to a filter
112                         if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
113                                 if ($GLOBALS['cache_instance']->loadCacheFile('refdepths')) $GLOBALS['cache_instance']->removeCacheFile();
114                         } // END - if
115                         break;
116
117                 case 'settings':
118                         $REF = bigintval(postRequestParameter('ref_payout'));
119                         updateConfiguration(
120                                 array('allow_direct_pay', 'reg_points_mode', 'ref_payout'),
121                                 array(postRequestParameter('allow_direct_pay'), postRequestParameter('reg_points_mode'), $REF)
122                         );
123                         if ((getConfig('ref_payout') == '0') && (postRequestParameter('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
127         `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");
133                         }
134                         break;
135         } // END - switch
136
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);
142                 } // END - if
143
144                 if (countSqls() > 0) {
145                         // Run all SQL commands
146                         runFilterChain('run_sqls');
147
148                         // Entry saved...
149                         $message = '{--SETTINGS_SAVED--}';
150
151                         // Destroy config cache file here...
152                         rebuildCache('config', 'config');
153                 } else {
154                         // Prepare failed-message
155                         $message = '<span class="notice">{--SETTINGS_NOT_SAVED--}</span>';
156                 }
157
158                 // Remove SQL queries
159                 unsetSqls();
160         }
161
162         // Shall we display a message?
163         if (!empty($message)) {
164                 // When do so...
165                 loadTemplate('admin_settings_saved', false, $message);
166         } // END - if
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"';
174         } // END - foreach
175
176         // One-time referal bonus add-mode
177         foreach (array('reg_points_mode_ref','reg_points_mode_direct') as $entry) {
178                 $content[$entry] = '';
179         } // END - foreach
180         $content['reg_points_mode_' . strtolower(getConfig('reg_points_mode'))] = ' checked="checked"';
181
182         // Load template
183         loadTemplate('admin_config_point_settings', false, $content);
184 } elseif (getRequestParameter('sub') == 'ref') {
185         // 12          3     32    2                        3321
186         if ((isFormSent('delete')) && (ifPostContainsSelections())) {
187                 // Delete entries
188                 $OUT = '';
189                 foreach (postRequestParameter('sel') as $id => $value) {
190                         $result = SQL_QUERY_ESC("SELECT `id`, `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);
194
195                         // Load row template and switch color
196                         $OUT .= loadTemplate('admin_delete_reflevel_row', true, $content);
197                 } // END - foreach
198
199                 // Load main template
200                 loadTemplate('admin_delete_reflevel', false, $OUT);
201         } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
202                 // Edit entries
203                 $OUT = '';
204                 foreach (postRequestParameter('sel') as $id => $value) {
205                         $result = SQL_QUERY_ESC("SELECT `id`, `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
206                                 array(bigintval($id)), __FILE__, __LINE__);
207                         $content = SQL_FETCHARRAY($result);
208                         SQL_FREERESULT($result);
209
210                         // Load row template and switch color
211                         $OUT .= loadTemplate('admin_edit_reflevel_row', true, $content);
212                 } // END - foreach
213
214                 // Load main template
215                 loadTemplate('admin_edit_reflevel', false, $OUT);
216         } else {
217                 // Referal levels
218                 $result = SQL_QUERY("SELECT `id`, `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY `level` ASC", __FILE__, __LINE__);
219                 if (!SQL_HASZERONUMS($result)) {
220                         // Make referal levels editable and deletable
221                         $OUT = '';
222
223                         // List already existing categories for editing
224                         while ($content = SQL_FETCHARRAY($result)) {
225                                 // Prepare data for the row template
226                                 $content['percents'] = translateComma($content['percents']);
227
228                                 // Load row template and switch color
229                                 $OUT .= loadTemplate('admin_list_reflevel_row', true, $content);
230                         } // END - while
231
232                         // Free memory
233                         SQL_FREERESULT($result);
234
235                         // Load main template
236                         loadTemplate('admin_list_reflevel', false, $OUT);
237                 }
238
239                 // Form for adding new referal levels
240                 loadTemplate('admin_add_reflevel');
241         }
242 } elseif (getRequestParameter('sub') == 'points') {
243         // Load template
244         loadTemplate('admin_config_sub_points');
245 } else {
246         // Display selection box
247         loadTemplate('admin_config_points');
248 }
249
250 // [EOF]
251 ?>