"copied"
[mailer.git] / 0.2.1-FINAL / 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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 if (!empty($_GET['sub'])) {
44         switch ($_GET['sub'])
45         {
46         case "points":
47                 if ((empty($_POST['points_register'])) || (empty($_POST['points_ref']))) {
48                         unset($_POST['ok']);
49                 }
50                 break;
51
52         case "ref":
53                 if (isset($_GET['do'])) {
54                         if (((empty($_POST['lvl'])) || (empty($_POST['perc']))) && ($_GET['do'] == "add")) {
55                                 unset($_POST['ok']);
56                         }
57                 }
58                 break;
59         }
60 } else {
61         // Display overview
62         $_GET['sub'] = "overview";
63 }
64
65 if (isset($_POST['ok'])) {
66         $SQLs = array();
67         switch ($_GET['sub'])
68         {
69         case "points":
70                 $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_config` SET points_register='".$_POST['points_register']."', points_ref='".$_POST['points_ref']."' WHERE config=0 LIMIT 1";
71                 break;
72
73         case "ref":
74                 switch ($_GET['do'])
75                 {
76                 case "add":
77                         $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_refdepths (level, percents) VALUES ('".$_POST['lvl']."','".$_POST['perc']."')";
78                         break;
79
80                 case "edit": // Change entries
81                         foreach ($_POST['lvl'] as $id => $value) {
82                                 // Secure ID
83                                 $id = bigintval($id);
84
85                                 // Revert german commata
86                                 $_POST['perc'][$id] = REVERT_COMMA($_POST['perc'][$id]);
87
88                                 // Update entry
89                                 SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_refdepths SET level='%s', percents='%s' WHERE id=%s LIMIT 1",
90                                         array(bigintval($value), $_POST['perc'][$id], $id), __FILE__, __LINE__);
91                         }
92                         $TEXT = REF_DEPTHS_SAVED;
93                         break;
94
95                 case "del":
96                         foreach ($_POST['id'] as $id => $value) {
97                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_refdepths WHERE id=%s LIMIT 1",
98                                         array(bigintval($id)), __FILE__, __LINE__);
99                         }
100                         $TEXT = REF_DEPTHS_DELETED;
101                         break;
102                 }
103
104                 // Update cache file
105                 if (GET_EXT_VERSION("cache") >= "0.1.2") {
106                         if ($cacheInstance->loadCacheFile("refdepths")) $cacheInstance->destroyCacheFile();
107                 }
108                 break;
109
110         case "settings":
111                 $REF = bigintval($_POST['ref_payout']);
112                 $SQLs[] = sprintf("UPDATE `"._MYSQL_PREFIX."_config` SET
113 allow_direct_pay='%s',
114 reg_points_mode='%s',
115 ref_payout='%s'
116 WHERE config=0 LIMIT 1",
117  $_POST['allow_direct_pay'],
118  $_POST['reg_points_mode'],
119  $REF
120                 );
121                 if ((getConfig('ref_payout') == 0) && ($_POST['ref_payout'] > 0))
122                 {
123                         // Update account's ref_payout for "must-confirm"
124                         $SQLs[] = sprintf("UPDATE `"._MYSQL_PREFIX."_user_data` SET ref_payout=(%s - mails_confirmed)
125 WHERE mails_confirmed < %s", $REF, $REF);
126                 }
127                  elseif ((getConfig('ref_payout') > 0) && ($_POST['ref_payout'] == 0))
128                 {
129                         // Update account's ref_payout for "not-must-confirm"
130                         $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_user_data` SET ref_payout=0 WHERE ref_payout > 0";
131                         $SQLs[] = "UPDATE "._MYSQL_PREFIX."_user_points SET points=points+locked_points WHERE locked_points>0";
132                         $SQLs[] = "UPDATE "._MYSQL_PREFIX."_user_points SET locked_points=0 WHERE locked_points>0";
133                 }
134                 break;
135         }
136
137         if ((isset($SQLs)) && (is_array($SQLs)) && (!empty($SQLs[0]))) {
138                 if (strpos($SQLs[0], "INSERT") > -1)
139                 {
140                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_refdepths WHERE level='%s' LIMIT 1",
141                                 array(bigintval($_POST['lvl'])), __FILE__, __LINE__);
142                         SQL_FREERESULT($result);
143                 }
144                 if (count($SQLs) > 0) {
145                         // Run all SQL commands
146                         RUN_FILTER('run_sqls', array('dry_run' => false, 'sqls' => $SQLs));
147
148                         $content = "<SPAN class=\"admin_done\">".SETTINGS_SAVED."</SPAN>";
149
150                         // Destroy config cache file here...
151                         REBUILD_CACHE("config", "config");
152                 } else {
153                         $content = "<SPAN class=\"admin_failed\">".SETTINGS_NOT_SAVED."</SPAN>";
154                 }
155                 unset($SQLs);
156                 LOAD_TEMPLATE("admin_settings_saved", false, $content);
157         } elseif (isset($TEXT)) {
158                 LOAD_TEMPLATE("admin_settings_saved", false, $TEXT);
159         }
160 } elseif ($_GET['sub'] == "settings") {
161         // Setup some settings like direct pay and so on
162         // Including new add-mode for one-time referal bonus
163         switch (getConfig('allow_direct_pay')) {
164         case "Y":
165                 define('__DIRECT_Y', " checked=\"checked\"");
166                 define('__DIRECT_N', "");
167                 break;
168
169         case "N":
170                 define('__DIRECT_Y', "");
171                 define('__DIRECT_N', " checked=\"checked\"");
172                 break;
173         }
174
175         // One-time referal bonus add-mode
176         switch (getConfig('reg_points_mode')) {
177                 case "ref"   : define('__MODE_REF', " checked=\"checked\""); define('__MODE_DIRECT', "");         break;
178                 case "direct": define('__MODE_REF', "");         define('__MODE_DIRECT', " checked=\"checked\""); break;
179         }
180
181         // Referal payout value
182         define('__REF_PAYOUT', round(getConfig('ref_payout')));
183
184         // Load template
185         LOAD_TEMPLATE("admin_config_point_settings");
186 } elseif ($_GET['sub'] == "ref") {
187         if ((isset($_POST['del'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0])))) {
188                 // Delete entries
189                 $SW = 2; $OUT = "";
190                 foreach ($_POST['sel'] as $id => $value) {
191                         $result = SQL_QUERY_ESC("SELECT level, percents FROM "._MYSQL_PREFIX."_refdepths WHERE id=%s LIMIT 1",
192                                 array(bigintval($id)), __FILE__, __LINE__);
193                         list($lvl, $perc) = SQL_FETCHROW($result);
194                         SQL_FREERESULT($result);
195
196                         // Prepare data for the row template
197                         $content = array(
198                                 'sw'  => $SW,
199                                 'id'  => $id,
200                                 'lvl' => $lvl,
201                                 'per' => TRANSLATE_COMMA($perc),
202                         );
203
204                         // Load row template and switch color
205                         $OUT .= LOAD_TEMPLATE("admin_points_del_row", true, $content);
206                         $SW = 3 - $SW;
207                 }
208                 define('__LEVEL_ROWS', $OUT);
209
210                 // Load main template
211                 LOAD_TEMPLATE("admin_points_del");
212         } elseif ((isset($_POST['edit'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0])))) {
213                 // Edit entries
214                 $SW = 2; $OUT = "";
215                 foreach ($_POST['sel'] as $id => $value) {
216                         $result = SQL_QUERY_ESC("SELECT level, percents FROM "._MYSQL_PREFIX."_refdepths WHERE id=%s LIMIT 1",
217                          array(bigintval($id)), __FILE__, __LINE__);
218                         list($lvl, $perc) = SQL_FETCHROW($result);
219                         SQL_FREERESULT($result);
220
221                         // Prepare data for the row template
222                         $content = array(
223                                 'sw'  => $SW,
224                                 'id'  => $id,
225                                 'lvl' => $lvl,
226                                 'per' => TRANSLATE_COMMA($perc),
227                         );
228
229                         // Load row template and switch color
230                         $OUT .= LOAD_TEMPLATE("admin_points_edit_row", true, $content);
231                         $SW = 3 - $SW;
232                 }
233                 define('__LEVEL_ROWS', $OUT);
234
235                 // Load main template
236                 LOAD_TEMPLATE("admin_points_edit");
237         } else {
238                 // Referal levels
239                 $result = SQL_QUERY("SELECT id, level, percents FROM "._MYSQL_PREFIX."_refdepths ORDER BY level", __FILE__, __LINE__);
240                 if (SQL_NUMROWS($result) > 0) {
241                         // Make referal levels editable and deletable
242                         $SW = 2; $OUT = "";
243
244                         // List already existing categories for editing
245                         while (list($id, $lvl, $perc) = SQL_FETCHROW($result)) {
246                                 // Prepare data for the row template
247                                 $content = array(
248                                         'sw'  => $SW,
249                                         'id'  => $id,
250                                         'lvl' => $lvl,
251                                         'per' => TRANSLATE_COMMA($perc),
252                                 );
253
254                                 // Load row template and switch color
255                                 $OUT .= LOAD_TEMPLATE("admin_points_row", true, $content);
256                                 $SW = 3 - $SW;
257                         }
258
259                         // Free memory
260                         SQL_FREERESULT($result);
261                         define('__LEVEL_ROWS', $OUT);
262
263                         // Load main template
264                         LOAD_TEMPLATE("admin_points");
265                 }
266
267                 // Form for adding new referal levels
268                 LOAD_TEMPLATE("admin_add_reflvl");
269         }
270 } elseif ($_GET['sub'] == "points") {
271         // First points for registration and other fixed points including new add-mode for one-time referal bonus...
272         define('P_REG_VALUE', getConfig('points_register'));
273         define('P_REF_VALUE', getConfig('points_ref'));
274
275         // Load templates
276         LOAD_TEMPLATE("admin_config_sub_points");
277 } else {
278         // Display selection box
279         LOAD_TEMPLATE("admin_config_points");
280 }
281
282 //
283 ?>