47b031141f4079d86d8f3573b3e215ba38465fd3
[mailer.git] / inc / modules / admin / what-config_payouts.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 04/11/2004 *
4  * ================                             Last change: 08/12/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-config_payouts.php                          *
8  * -------------------------------------------------------------------- *
9  * Short description : Configure payout types                           *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Auszahlungensarten editieren                     *
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 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
47
48
49 if (REQUEST_ISSET_POST(('rate'))) REQUEST_SET_POST('rate', convertCommaToDot(REQUEST_POST('rate')));
50
51 if ((REQUEST_ISSET_POST(('add'))) && (REQUEST_ISSET_POST(('title'))) && (REQUEST_POST('rate') > 0)) {
52         // Add new payout type
53         $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_payout_types` WHERE type='%s' LIMIT 1",
54         array(REQUEST_POST('title')), __FILE__, __LINE__);
55         if (SQL_NUMROWS($result) == 0) {
56                 // Add now
57                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_payout_types`
58 (type, rate, min_points, from_account, from_pass, engine_url, engine_ret_ok, engine_ret_failed, pass_enc, allow_url)
59 VALUES ('%s', %d, %d,'%s','%s','%s','%s','%s','%s','%s')",
60                 array(
61                 REQUEST_POST('title'),
62                 bigintval(REQUEST_POST('rate')),
63                 bigintval(REQUEST_POST('mpoi')),
64                 REQUEST_POST('yacc'),
65                 REQUEST_POST('ypass'),
66                 REQUEST_POST('yurl'),
67                 REQUEST_POST('yrdone'),
68                 REQUEST_POST('yrfailed'),
69                 REQUEST_POST('ytrans'),
70                 REQUEST_POST('allow_url'),
71                 ), __FILE__, __LINE__);
72                 $msg = getMessage('ADMIN_PAYOUT_TYPE_ADDED');
73         } else {
74                 // Free memory
75                 SQL_FREERESULT($result);
76
77                 // Does already exist
78                 $msg = "<div class=\"admin_failed\">{--ADMIN_PAYOUT_TYPE_ALREADY--}</div>";
79         }
80 }
81
82 // Payout requests by your members
83 $result_mem = SQL_QUERY("SELECT `id` FROM `{!_MYSQL_PREFIX!}_user_payouts` WHERE `status`='NEW' ORDER BY payout_timestamp DESC", __FILE__, __LINE__);
84
85 $display = true;
86 if ((REQUEST_ISSET_POST('edit')) && (countPostSelection() > 0)) {
87         // Edit payout types
88         if ((REQUEST_ISSET_GET('ok')) && (REQUEST_GET('ok') == "ok")) {
89                 // Init SQLs
90                 INIT_SQLS();
91
92                 // Edit entries
93                 foreach (REQUEST_POST('sel') as $id => $sel) {
94                         // Secure ID
95                         $id = bigintval($id);
96
97                         // Edit only if something is entered
98                         if ((REQUEST_ISSET_POST('title', $id)) && (REQUEST_POST('rate', $id) > 0)) {
99                                 // Update entry
100                                 ADD_SQL(SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_payout_types` SET
101 type='%s',
102 rate=%s,
103 min_points=%s,
104 allow_url='%s'
105 WHERE `id`='".$id."' LIMIT 1",
106                                 array(
107                                 REQUEST_POST('title', $id),
108                                 convertCommaToDot(REQUEST_POST('rate', $id)),
109                                 convertCommaToDot(REQUEST_POST('mpoi' , $id)),
110                                 REQUEST_POST('allow', $id),
111                                 ),__FILE__, __LINE__, false));
112                         }
113                 }
114
115                 // Run all SQLs
116                 runFilterChain('run_sqls');
117
118                 // Get message
119                 $msg = getMessage('ADMIN_PAYOUT_ENTRIES_CHANGED');
120         } else {
121                 $display = false; //Suppress any other outputs
122                 $OUT = ''; $SW = 2;
123                 foreach (REQUEST_POST('sel') as $id => $sel) {
124                         // Load data
125                         $result = SQL_QUERY_ESC("SELECT type, rate, min_points, allow_url FROM `{!_MYSQL_PREFIX!}_payout_types` WHERE `id`=%s LIMIT 1",
126                         array(bigintval($id)), __FILE__, __LINE__);
127                         list($title, $rate, $mpoi, $allow) = SQL_FETCHROW($result);
128                         SQL_FREERESULT($result);
129
130                         // Prepare data for the row template
131                         $content = array(
132                                 'sw'    => $SW,
133                                 'id'    => $id,
134                                 'title' => COMPILE_CODE($title),
135                                 'rate'  => translateComma($rate),
136                                 'mpoi'  => translateComma($mpoi),
137                                 'allow' => ADD_SELECTION('yn', $allow, "allow[".$id."]"),
138                         );
139
140                         // Load row template and switch color
141                         $OUT .= LOAD_TEMPLATE("admin_config_payouts_edit_row", true, $content);
142                         $SW = 3 - $SW;
143                 }
144
145                 // @TODO Rewrite this constant
146                 define('__PAYOUT_ROWS', $OUT);
147
148                 // Load main template
149                 LOAD_TEMPLATE("admin_config_payouts_edit");
150         }
151 } elseif ((REQUEST_ISSET_POST('del')) && (countPostSelection() > 0)) {
152         // Delete payout types
153         if ((REQUEST_ISSET_GET('ok')) && (REQUEST_GET('ok') == "ok")) {
154                 // Init SQLs
155                 INIT_SQLS();
156
157                 // Delete entries
158                 foreach (REQUEST_POST('sel') as $id => $sel) {
159                         ADD_SQL(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_payout_types` WHERE `id`=%s LIMIT 1",
160                         array(bigintval($id)), __FILE__, __LINE__, false));
161                 } // END - foreach
162
163                 // Run all SQLs
164                 runFilterChain('run_sqls');
165
166                 // Get message
167                 $msg = getMessage('ADMIN_PAYOUT_ENTRIES_DELETED');
168         } else {
169                 $display = false; //Suppress any other outputs
170                 $OUT = ''; $SW = 2;
171                 foreach (REQUEST_POST('sel') as $id => $sel) {
172                         // Secure ID number
173                         $id = bigintval($id);
174
175                         // Load data
176                         $result = SQL_QUERY_ESC("SELECT type, rate, min_points FROM `{!_MYSQL_PREFIX!}_payout_types` WHERE `id`=%s LIMIT 1",
177                         array($id), __FILE__, __LINE__);
178                         list($title, $rate, $mpoi) = SQL_FETCHROW($result);
179                         SQL_FREERESULT($result);
180
181                         // Prepare data for the row template
182                         $content = array(
183                                 'sw'    => $SW,
184                                 'id'    => $id,
185                                 'title' => COMPILE_CODE($title),
186                                 'rate'  => translateComma($rate),
187                                 'mpoi'  => translateComma($mpoi),
188                         );
189
190                         // Load row template and switch color
191                         $OUT .= LOAD_TEMPLATE("admin_config_payouts_del_row", true, $content);
192                         $SW = 3 - $SW;
193                 }
194                 define('__PAYOUT_ROWS', $OUT);
195
196                 // Load main template
197                 LOAD_TEMPLATE("admin_config_payouts_del");
198         }
199 }
200
201 if (!empty($msg)) {
202         // Output message
203         LOAD_TEMPLATE('admin_settings_saved', false, $msg);
204 }
205
206 // Payout types
207 $result_type = SQL_QUERY("SELECT id, type, rate, min_points, from_account FROM `{!_MYSQL_PREFIX!}_payout_types` ORDER BY type", __FILE__, __LINE__);
208
209 if ((SQL_NUMROWS($result_type) > 0) && ($display)) {
210         // List all payout types
211         $OUT = ''; $SW = 2;
212         while ($content = SQL_FETCHARRAY($result_type)) {
213                 // Prepare data for the row template
214                 $content = array(
215                         'sw'    => $SW,
216                         'id'    => $content['id'],
217                         'from'  => COMPILE_CODE($content['from_account']),
218                         'type'  => COMPILE_CODE($content['type']),
219                         'rate'  => translateComma($content['rate']),
220                         'mpoi'  => translateComma($content['min_points']),
221                 );
222
223                 // Load row template and switch color
224                 $OUT .= LOAD_TEMPLATE("admin_config_payouts_row", true, $content);
225                 $SW = 3 - $SW;
226         }
227
228         // Free memory
229         SQL_FREERESULT($result_type);
230
231         // @TODO Rewrite this constant
232         define('__PAYOUT_ROWS', $OUT);
233
234         // Load main template
235         LOAD_TEMPLATE("admin_config_payouts");
236 }
237
238 // Does your members request payouts?
239 if ((SQL_NUMROWS($result_mem) > 0) && ($display)) {
240         // Members has requested payouts
241         LOAD_TEMPLATE('admin_settings_saved', false, "<a href=\"{!URL!}/modules.php?module=admin&amp;what=list_payouts\">{--ADMIN_PAYOUT_LIST_REQUESTS--}</a></P>");
242 } elseif ($display) {
243         // No member requests so far
244         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_PAYOUT_NO_MEMBER_REQUESTS'));
245 }
246
247 // Free result
248 SQL_FREERESULT($result_mem);
249
250 // Add new paypout type
251 if ($display) LOAD_TEMPLATE("admin_payout_add_new");
252
253 //
254 ?>