Code style changed, ext-user continued:
[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 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://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 addYouAreHereLink('admin', __FILE__);
45
46 // Init variables
47 $message = '';
48
49 // Is the 'sub' parameter set?
50 if (isGetRequestElementSet('sub')) {
51         // Yes, then do some sanity-checks
52         switch (getRequestElement('sub')) {
53                 case 'points':
54                         if ((!isPostRequestElementSet('points_register')) || (!isPostRequestElementSet('points_ref'))) {
55                                 unsetPostRequestElement('ok');
56                         } // END - if
57                         break;
58
59                 case 'ref':
60                         if (isGetRequestElementSet('do')) {
61                                 if (((!isPostRequestElementSet('level')) || (!isPostRequestElementSet('percents'))) && (getRequestElement('do') == 'add')) {
62                                         unsetPostRequestElement('ok');
63                                 }
64                         }
65                         break;
66         } // END - switch
67 } else {
68         // Display overview
69         setGetRequestElement('sub', 'overview');
70 }
71
72 if (isFormSent()) {
73         initSqls();
74         switch (getRequestElement('sub')) {
75                 case 'points':
76                         adminSaveSettingsFromPostData();
77                         break;
78
79                 case 'ref':
80                         switch (getRequestElement('do')) {
81                                 case 'add':
82                                         addSql("INSERT INTO `{?_MYSQL_PREFIX?}_refdepths` (`level`, `percents`) VALUES ('".bigintval(postRequestElement('level'))."','".bigintval(postRequestElement('percents'))."')");
83                                         break;
84
85                                 case 'edit': // Change entries
86                                         foreach (postRequestElement('level') as $id => $value) {
87                                                 // Secure id
88                                                 $id = bigintval($id);
89
90                                                 // Revert german commata
91                                                 setPostRequestElement('percents', array($id => convertCommaToDot(postRequestElement('percents', $id))));
92
93                                                 // Update entry
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__);
96                                         } // END - foreach
97                                         $message = '{--ADMIN_REFERRAL_DEPTHS_SAVED--}';
98                                         break;
99
100                                 case 'delete':
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__);
104                                         } // END - foreach
105                                         $message = '{--ADMIN_REFERRAL_DEPTHS_DELETED--}';
106                                         break;
107                         } // END - switch
108
109                         // Update cache file
110                         rebuildCache('refdepths', 'refdepths');
111                         break;
112
113                 case 'settings':
114                         $REF = bigintval(postRequestElement('ref_payout'));
115                         updateConfiguration(
116                                 array('allow_direct_pay', 'ref_payout'),
117                                 array(postRequestElement('allow_direct_pay'), $REF)
118                         );
119                         if ((getRefPayout() == '0') && (postRequestElement('ref_payout') > 0)) {
120                                 // Update account's ref_payout for "must-confirm"
121                                 addSql(sprintf("UPDATE
122         `{?_MYSQL_PREFIX?}_user_data`
123 SET
124         `ref_payout`=(%s - `mails_confirmed`)
125 WHERE
126         `mails_confirmed` < %s", $REF, $REF));
127                         } elseif ((getRefPayout() > 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                                 // @TODO Rewrite these two lines for new user_points columns (e.g. locked_order_points) with a filter
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         // Is there an array?
138         if ((getRequestElement('sub') != 'points') && (isSqlsValid())) {
139                 // Default is failed-message
140                 $message = '<span class="bad">{--SETTINGS_NOT_SAVED--}</span>';
141
142                 if (countSqls() > 0) {
143                         // Run all SQL commands
144                         runFilterChain('run_sqls');
145
146                         // Entry saved...
147                         $message = '{--SETTINGS_SAVED--}';
148
149                         // Destroy config cache file here...
150                         rebuildCache('config', 'config');
151                 } // END - if
152
153                 // Remove SQL queries
154                 unsetSqls();
155         } // END - if
156
157         // Shall we display a message?
158         if (!empty($message)) {
159                 // When do so...
160                 displayMessage($message);
161         } // END - if
162 } elseif (getRequestElement('sub') == 'settings') {
163         // Setup some settings like direct pay and so on
164         // Including new add-mode for one-time referral bonus
165         foreach (array('allow_direct_pay') as $entry) {
166                 $content[$entry . '_y'] = '';
167                 $content[$entry . '_n'] = '';
168                 $content[$entry . '_' . strtolower(getConfig($entry))] = ' checked="checked"';
169         } // END - foreach
170
171         // Load template
172         loadTemplate('admin_config_point_settings', FALSE, $content);
173 } elseif (getRequestElement('sub') == 'ref') {
174         // 12          3     32    2                        3321
175         if ((isFormSent('delete')) && (ifPostContainsSelections())) {
176                 // Delete entries
177                 $OUT = '';
178                 foreach (postRequestElement('sel') as $id => $value) {
179                         $result = SQL_QUERY_ESC("SELECT `id`, `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
180                                 array(bigintval($id)), __FILE__, __LINE__);
181                         $content = SQL_FETCHARRAY($result);
182                         SQL_FREERESULT($result);
183
184                         // Load row template and switch color
185                         $OUT .= loadTemplate('admin_delete_reflevel_row', TRUE, $content);
186                 } // END - foreach
187
188                 // Load main template
189                 loadTemplate('admin_delete_reflevel', FALSE, $OUT);
190         } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
191                 // Edit entries
192                 $OUT = '';
193                 foreach (postRequestElement('sel') as $id => $value) {
194                         $result = SQL_QUERY_ESC("SELECT `id`, `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
195                                 array(bigintval($id)), __FILE__, __LINE__);
196                         $content = SQL_FETCHARRAY($result);
197                         SQL_FREERESULT($result);
198
199                         // Load row template and switch color
200                         $OUT .= loadTemplate('admin_edit_reflevel_row', TRUE, $content);
201                 } // END - foreach
202
203                 // Load main template
204                 loadTemplate('admin_edit_reflevel', FALSE, $OUT);
205         } else {
206                 // Referral levels
207                 $result = SQL_QUERY("SELECT `id`, `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY `level` ASC", __FILE__, __LINE__);
208                 if (!SQL_HASZERONUMS($result)) {
209                         // Make referral levels editable and deletable
210                         $OUT = '';
211
212                         // List already existing categories for editing
213                         while ($content = SQL_FETCHARRAY($result)) {
214                                 // Load row template and switch color
215                                 $OUT .= loadTemplate('admin_list_reflevel_row', TRUE, $content);
216                         } // END - while
217
218                         // Free memory
219                         SQL_FREERESULT($result);
220
221                         // Load main template
222                         loadTemplate('admin_list_reflevel', FALSE, $OUT);
223                 }
224
225                 // Form for adding new referral levels
226                 loadTemplate('admin_add_reflevel');
227         }
228 } elseif (getRequestElement('sub') == 'points') {
229         // Load template
230         loadTemplate('admin_config_sub_points');
231 } else {
232         // Display selection box
233         loadTemplate('admin_config_points');
234 }
235
236 // [EOF]
237 ?>