Configuration of advertisement networks prepared, CSS cleaned up, HTML rewritten:
[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  * 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                  *
23  *                                                                      *
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.                                  *
28  *                                                                      *
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.                         *
33  *                                                                      *
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,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 // Init variables
49 $message = '';
50
51 // Is the 'sub' parameter set?
52 if (isGetRequestParameterSet('sub')) {
53         // Yes, then do some sanity-checks
54         switch (getRequestParameter('sub')) {
55                 case 'points':
56                         if ((!isPostRequestParameterSet('points_register')) || (!isPostRequestParameterSet('points_ref'))) {
57                                 unsetPostRequestParameter('ok');
58                         } // END - if
59                         break;
60
61                 case 'ref':
62                         if (isGetRequestParameterSet('do')) {
63                                 if (((!isPostRequestParameterSet('level')) || (!isPostRequestParameterSet('percents'))) && (getRequestParameter('do') == 'add')) {
64                                         unsetPostRequestParameter('ok');
65                                 }
66                         }
67                         break;
68         } // END - switch
69 } else {
70         // Display overview
71         setGetRequestParameter('sub', 'overview');
72 }
73
74 if (isFormSent()) {
75         initSqls();
76         switch (getRequestParameter('sub')) {
77                 case 'points':
78                         adminSaveSettingsFromPostData();
79                         break;
80
81                 case 'ref':
82                         switch (getRequestParameter('do'))
83                         {
84                                 case 'add':
85                                         addSql("INSERT INTO `{?_MYSQL_PREFIX?}_refdepths` (`level`, `percents`) VALUES ('".postRequestParameter('level')."','".postRequestParameter('percents')."')");
86                                         break;
87
88                                 case 'edit': // Change entries
89                                         foreach (postRequestParameter('level') as $id => $value) {
90                                                 // Secure id
91                                                 $id = bigintval($id);
92
93                                                 // Revert german commata
94                                                 setPostRequestParameter('percents', array($id => convertCommaToDot(postRequestParameter('percents', $id))));
95
96                                                 // Update entry
97                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refdepths` SET `level`=%s, `percents`=%s WHERE `id`=%s LIMIT 1",
98                                                         array(bigintval($value), convertCommaToDot(postRequestParameter('percents', $id)), $id), __FILE__, __LINE__);
99                                         }
100                                         $message = '{--ADMIN_REFERAL_DEPTHS_SAVED--}';
101                                         break;
102
103                                 case 'delete':
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__);
107                                         }
108                                         $message = '{--ADMIN_REFERAL_DEPTHS_DELETED--}';
109                                         break;
110                         }
111
112                         // Update cache file
113                         // @TODO Rewrite this to a filter
114                         if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
115                                 if ($GLOBALS['cache_instance']->loadCacheFile('refdepths')) $GLOBALS['cache_instance']->removeCacheFile();
116                         } // END - if
117                         break;
118
119                 case 'settings':
120                         $REF = bigintval(postRequestParameter('ref_payout'));
121                         updateConfiguration(
122                                 array('allow_direct_pay', 'reg_points_mode', 'ref_payout'),
123                                 array(postRequestParameter('allow_direct_pay'), postRequestParameter('reg_points_mode'), $REF)
124                         );
125                         if ((getConfig('ref_payout') == '0') && (postRequestParameter('ref_payout') > 0)) {
126                                 // Update account's ref_payout for "must-confirm"
127                                 addSql(sprintf("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=(%s - `mails_confirmed`)
128 WHERE
129         `mails_confirmed` < %s", $REF, $REF));
130                         } elseif ((getConfig('ref_payout') > 0) && (postRequestParameter('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                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `points`=`points`+`locked_points` WHERE `locked_points` > 0");
134                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `locked_points`=0 WHERE `locked_points` > 0");
135                         }
136                         break;
137         } // END - switch
138
139         if ((isSqlsValid()) && (isSqlsValid())) {
140                 if (strpos($GLOBALS['sqls'][0], 'INSERT') > -1) {
141                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level`='%s' LIMIT 1",
142                                 array(bigintval(postRequestParameter('level'))), __FILE__, __LINE__);
143                         SQL_FREERESULT($result);
144                 } // END - if
145
146                 if (countSqls() > 0) {
147                         // Run all SQL commands
148                         runFilterChain('run_sqls');
149
150                         // Entry saved...
151                         $message = '{--SETTINGS_SAVED--}';
152
153                         // Destroy config cache file here...
154                         rebuildCache('config', 'config');
155                 } else {
156                         // Prepare failed-message
157                         $message = '<span class="notice">{--SETTINGS_NOT_SAVED--}</span>';
158                 }
159
160                 // Remove SQL queries
161                 unsetSqls();
162         }
163
164         // Shall we display a message?
165         if (!empty($message)) {
166                 // When do so...
167                 loadTemplate('admin_settings_saved', false, $message);
168         } // END - if
169 } elseif (getRequestParameter('sub') == 'settings') {
170         // Setup some settings like direct pay and so on
171         // Including new add-mode for one-time referal bonus
172         foreach (array('allow_direct_pay') as $entry) {
173                 $content[$entry . '_y'] = '';
174                 $content[$entry . '_n'] = '';
175                 $content[$entry . '_' . strtolower(getConfig($entry))] = ' checked="checked"';
176         } // END - foreach
177
178         // One-time referal bonus add-mode
179         foreach (array('reg_points_mode_ref','reg_points_mode_direct') as $entry) {
180                 $content[$entry] = '';
181         } // END - foreach
182         $content['reg_points_mode_' . strtolower(getConfig('reg_points_mode'))] = ' checked="checked"';
183
184         // Load template
185         loadTemplate('admin_config_point_settings', false, $content);
186 } elseif (getRequestParameter('sub') == 'ref') {
187         // 12          3     32    2                        3321
188         if ((isFormSent('delete')) && (ifPostContainsSelections())) {
189                 // Delete entries
190                 $OUT = '';
191                 foreach (postRequestParameter('sel') as $id => $value) {
192                         $result = SQL_QUERY_ESC("SELECT `id`, `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
193                                 array(bigintval($id)), __FILE__, __LINE__);
194                         $content = SQL_FETCHARRAY($result);
195                         SQL_FREERESULT($result);
196
197                         // Load row template and switch color
198                         $OUT .= loadTemplate('admin_delete_reflevel_row', true, $content);
199                 } // END - foreach
200
201                 // Load main template
202                 loadTemplate('admin_delete_reflevel', false, $OUT);
203         } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
204                 // Edit entries
205                 $OUT = '';
206                 foreach (postRequestParameter('sel') as $id => $value) {
207                         $result = SQL_QUERY_ESC("SELECT `id`, `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
208                                 array(bigintval($id)), __FILE__, __LINE__);
209                         $content = SQL_FETCHARRAY($result);
210                         SQL_FREERESULT($result);
211
212                         // Load row template and switch color
213                         $OUT .= loadTemplate('admin_edit_reflevel_row', true, $content);
214                 } // END - foreach
215
216                 // Load main template
217                 loadTemplate('admin_edit_reflevel', false, $OUT);
218         } else {
219                 // Referal levels
220                 $result = SQL_QUERY("SELECT `id`, `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY `level` ASC", __FILE__, __LINE__);
221                 if (!SQL_HASZERONUMS($result)) {
222                         // Make referal levels editable and deletable
223                         $OUT = '';
224
225                         // List already existing categories for editing
226                         while ($content = SQL_FETCHARRAY($result)) {
227                                 // Prepare data for the row template
228                                 $content['percents'] = translateComma($content['percents']);
229
230                                 // Load row template and switch color
231                                 $OUT .= loadTemplate('admin_list_reflevel_row', true, $content);
232                         } // END - while
233
234                         // Free memory
235                         SQL_FREERESULT($result);
236
237                         // Load main template
238                         loadTemplate('admin_list_reflevel', false, $OUT);
239                 }
240
241                 // Form for adding new referal levels
242                 loadTemplate('admin_add_reflevel');
243         }
244 } elseif (getRequestParameter('sub') == 'points') {
245         // Load template
246         loadTemplate('admin_config_sub_points');
247 } else {
248         // Display selection box
249         loadTemplate('admin_config_points');
250 }
251
252 // [EOF]
253 ?>