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