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