368a3e8c5f9a14b46ad4da8bb28847104a754dbc
[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 if (REQUEST_ISSET_POST(('rate'))) REQUEST_SET_POST('rate', REVERT_COMMA(REQUEST_POST('rate')));
49
50 if ((REQUEST_ISSET_POST(('add'))) && (REQUEST_ISSET_POST(('title'))) && (REQUEST_POST('rate') > 0)) {
51         // Add new payout type
52         $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_payout_types` WHERE type='%s' LIMIT 1",
53                 array(REQUEST_POST('title')), __FILE__, __LINE__);
54         if (SQL_NUMROWS($result) == 0) {
55                 // Add now
56                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_payout_types`
57 (type, rate, min_points, from_account, from_pass, engine_url, engine_ret_ok, engine_ret_failed, pass_enc, allow_url)
58 VALUES ('%s', %d, %d,'%s','%s','%s','%s','%s','%s','%s')",
59  array(
60         REQUEST_POST('title'),
61         bigintval(REQUEST_POST('rate')),
62         bigintval(REQUEST_POST('mpoi')),
63         REQUEST_POST('yacc'),
64         REQUEST_POST('ypass'),
65         REQUEST_POST('yurl'),
66         REQUEST_POST('yrdone'),
67         REQUEST_POST('yrfailed'),
68         REQUEST_POST('ytrans'),
69         REQUEST_POST('allow_url'),
70 ), __FILE__, __LINE__);
71                 $msg = getMessage('ADMIN_PAYOUT_TYPE_ADDED');
72         } else {
73                 // Free memory
74                 SQL_FREERESULT($result);
75
76                 // Does already exist
77                 $msg = "<div class=\"admin_failed\">{--ADMIN_PAYOUT_TYPE_ALREADY--}</div>";
78         }
79 }
80
81 // Payout requests by your members
82 $result_mem = SQL_QUERY("SELECT id FROM `{!_MYSQL_PREFIX!}_user_payouts` WHERE `status`='NEW' ORDER BY payout_timestamp DESC", __FILE__, __LINE__);
83
84 $display = true;
85 if ((REQUEST_ISSET_POST('edit')) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
86         // Edit payout types
87         if ((REQUEST_ISSET_GET('ok')) && (REQUEST_GET('ok') == "ok")) {
88                 // Init SQLs
89                 INIT_SQLS();
90
91                 // Edit entries
92                 foreach (REQUEST_POST('sel') as $id => $sel) {
93                         // Secure ID
94                         $id = bigintval($id);
95
96                         // Edit only if something is entered
97                         if ((REQUEST_ISSET_POST(('title', $id))) && (REQUEST_POST('rate', $id) > 0)) {
98                                 // Update entry
99                                 ADD_SQL(SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_payout_types` SET
100 type='%s',
101 rate=%s,
102 min_points=%s,
103 allow_url='%s'
104 WHERE id='".$id."' LIMIT 1",
105  array(
106         REQUEST_POST('title', $id),
107         REVERT_COMMA(REQUEST_POST('rate', $id)),
108         REVERT_COMMA(REQUEST_POST('mpoi' , $id)),
109         REQUEST_POST('allow', $id),
110 ),__FILE__, __LINE__, false));
111                         }
112                 }
113
114                 // Run all SQLs
115                 runFilterChain('run_sqls');
116
117                 // Get message
118                 $msg = getMessage('ADMIN_PAYOUT_ENTRIES_CHANGED');
119         } else {
120                 $display = false; //Suppress any other outputs
121                 $OUT = ''; $SW = 2;
122                 foreach (REQUEST_POST('sel') as $id => $sel) {
123                         // Load data
124                         $result = SQL_QUERY_ESC("SELECT type, rate, min_points, allow_url FROM `{!_MYSQL_PREFIX!}_payout_types` WHERE id=%s LIMIT 1",
125                                 array(bigintval($id)), __FILE__, __LINE__);
126                         list($title, $rate, $mpoi, $allow) = SQL_FETCHROW($result);
127                         SQL_FREERESULT($result);
128
129                         // Prepare data for the row template
130                         $content = array(
131                                 'sw'    => $SW,
132                                 'id'    => $id,
133                                 'title' => COMPILE_CODE($title),
134                                 'rate'  => TRANSLATE_COMMA($rate),
135                                 'mpoi'  => TRANSLATE_COMMA($mpoi),
136                                 'allow' => ADD_SELECTION("yn", $allow, "allow[".$id."]"),
137                         );
138
139                         // Load row template and switch color
140                         $OUT .= LOAD_TEMPLATE("admin_config_payouts_edit_row", true, $content);
141                         $SW = 3 - $SW;
142                 }
143
144                 // @TODO Rewrite this constant
145                 define('__PAYOUT_ROWS', $OUT);
146
147                 // Load main template
148                 LOAD_TEMPLATE("admin_config_payouts_edit");
149         }
150 } elseif ((REQUEST_ISSET_POST('del')) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
151         // Delete payout types
152         if ((REQUEST_ISSET_GET('ok')) && (REQUEST_GET('ok') == "ok")) {
153                 // Init SQLs
154                 INIT_SQLS();
155
156                 // Delete entries
157                 foreach (REQUEST_POST('sel') as $id => $sel) {
158                         ADD_SQL(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_payout_types` WHERE id=%s LIMIT 1",
159                                 array(bigintval($id)), __FILE__, __LINE__, false));
160                 } // END - foreach
161
162                 // Run all SQLs
163                 runFilterChain('run_sqls');
164
165                 // Get message
166                 $msg = getMessage('ADMIN_PAYOUT_ENTRIES_DELETED');
167         } else {
168                 $display = false; //Suppress any other outputs
169                 $OUT = ''; $SW = 2;
170                 foreach (REQUEST_POST('sel') as $id => $sel) {
171                         // Secure ID number
172                         $id = bigintval($id);
173
174                         // Load data
175                         $result = SQL_QUERY_ESC("SELECT type, rate, min_points FROM `{!_MYSQL_PREFIX!}_payout_types` WHERE id=%s LIMIT 1",
176                                 array($id), __FILE__, __LINE__);
177                         list($title, $rate, $mpoi) = SQL_FETCHROW($result);
178                         SQL_FREERESULT($result);
179
180                         // Prepare data for the row template
181                         $content = array(
182                                 'sw'    => $SW,
183                                 'id'    => $id,
184                                 'title' => COMPILE_CODE($title),
185                                 'rate'  => TRANSLATE_COMMA($rate),
186                                 'mpoi'  => TRANSLATE_COMMA($mpoi),
187                         );
188
189                         // Load row template and switch color
190                         $OUT .= LOAD_TEMPLATE("admin_config_payouts_del_row", true, $content);
191                         $SW = 3 - $SW;
192                 }
193                 define('__PAYOUT_ROWS', $OUT);
194
195                 // Load main template
196                 LOAD_TEMPLATE("admin_config_payouts_del");
197         }
198 }
199
200 if (!empty($msg)) {
201         // Output message
202         LOAD_TEMPLATE('admin_settings_saved', false, $msg);
203 }
204
205 // Payout types
206 $result_type = SQL_QUERY("SELECT id, type, rate, min_points, from_account FROM `{!_MYSQL_PREFIX!}_payout_types` ORDER BY type", __FILE__, __LINE__);
207
208 if ((SQL_NUMROWS($result_type) > 0) && ($display)) {
209         // List all payout types
210         $OUT = ''; $SW = 2;
211         while ($content = SQL_FETCHARRAY($result_type)) {
212                 // Prepare data for the row template
213                 $content = array(
214                         'sw'    => $SW,
215                         'id'    => $content['id'],
216                         'from'  => COMPILE_CODE($content['from_account']),
217                         'type'  => COMPILE_CODE($content['type']),
218                         'rate'  => TRANSLATE_COMMA($content['rate']),
219                         'mpoi'  => TRANSLATE_COMMA($content['min_points']),
220                 );
221
222                 // Load row template and switch color
223                 $OUT .= LOAD_TEMPLATE("admin_config_payouts_row", true, $content);
224                 $SW = 3 - $SW;
225         }
226
227         // Free memory
228         SQL_FREERESULT($result_type);
229
230         // @TODO Rewrite this constant
231         define('__PAYOUT_ROWS', $OUT);
232
233         // Load main template
234         LOAD_TEMPLATE("admin_config_payouts");
235 }
236
237 // Does your members request payouts?
238 if ((SQL_NUMROWS($result_mem) > 0) && ($display)) {
239         // Members has requested payouts
240         LOAD_TEMPLATE('admin_settings_saved', false, "<a href=\"{!URL!}/modules.php?module=admin&amp;what=list_payouts\">{--ADMIN_PAYOUT_LIST_REQUESTS--}</a></P>");
241 } elseif ($display) {
242         // No member requests so far
243         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_PAYOUT_NO_MEMBER_REQUESTS'));
244 }
245
246 // Free result
247 SQL_FREERESULT($result_mem);
248
249 // Add new paypout type
250 if ($display) LOAD_TEMPLATE("admin_payout_add_new");
251
252 //
253 ?>