Fixes + asserts
[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 - 2013 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         } // END - switch
59 } else {
60         // Display overview
61         setGetRequestElement('sub', 'overview');
62 }
63
64 // Is a form sent?
65 if ((isFormSent('do_delete')) || (isFormSent('do_edit')) || (isFormSent('do_add')) || (isFormSent('save_config'))) {
66         // Init SQLs
67         initSqls();
68         switch (getRequestElement('sub')) {
69                 case 'points':
70                         adminSaveSettingsFromPostData();
71                         break;
72
73                 case 'settings':
74                         $REF = bigintval(postRequestElement('ref_payout'));
75                         updateConfiguration(
76                                 array('allow_direct_pay', 'ref_payout'),
77                                 array(postRequestElement('allow_direct_pay'), $REF)
78                         );
79                         if ((getRefPayout() == '0') && (postRequestElement('ref_payout') > 0)) {
80                                 // Update account's ref_payout for "must-confirm"
81                                 addSql(sprintf("UPDATE
82         `{?_MYSQL_PREFIX?}_user_data`
83 SET
84         `ref_payout`=(%s - `mails_confirmed`)
85 WHERE
86         `mails_confirmed` < %s", $REF, $REF));
87                         } elseif ((getRefPayout() > 0) && (postRequestElement('ref_payout') == '0')) {
88                                 // Update account's ref_payout for "not-must-confirm"
89                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=0 WHERE `ref_payout` > 0");
90                                 // @TODO Rewrite these two lines for new user_points columns (e.g. locked_order_points) with a filter
91                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `points`=`points`+`locked_points` WHERE `locked_points` > 0");
92                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `locked_points`=0 WHERE `locked_points` > 0");
93                         }
94                         break;
95         } // END - switch
96
97         // Is there an array?
98         if ((getRequestElement('sub') != 'points') && (ifSqlsRegistered())) {
99                 // Default is failed-message
100                 $message = '<span class="bad">{--SETTINGS_NOT_SAVED--}</span>';
101
102                 if (countSqls() > 0) {
103                         // Run all SQL commands
104                         runFilterChain('run_sqls');
105
106                         // Entry saved...
107                         $message = '{--SETTINGS_SAVED--}';
108
109                         // Destroy config cache file here...
110                         rebuildCache('config', 'config');
111                 } // END - if
112
113                 // Remove SQL queries
114                 unsetSqls();
115         } // END - if
116
117         // Shall we display a message?
118         if (!empty($message)) {
119                 // When do so...
120                 displayMessage($message);
121         } // END - if
122 } elseif (getRequestElement('sub') == 'settings') {
123         // Setup some settings like direct pay and so on
124         // Including new add-mode for one-time referral bonus
125         foreach (array('allow_direct_pay') as $entry) {
126                 $content[$entry . '_y'] = '';
127                 $content[$entry . '_n'] = '';
128                 $content[$entry . '_' . strtolower(getConfig($entry))] = ' checked="checked"';
129         } // END - foreach
130
131         // Load template
132         loadTemplate('admin_config_point_settings', FALSE, $content);
133 } elseif (getRequestElement('sub') == 'points') {
134         // Load template
135         loadTemplate('admin_config_sub_points');
136 } else {
137         // Display selection box
138         loadTemplate('admin_config_points');
139 }
140
141 // [EOF]
142 ?>