fd1e6faf1e10589da3c2c6a1b1180f5d394340e6
[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         // Add new payout type
47         $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_payout_types` WHERE type='%s' LIMIT 1",
48                 array($_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         $_POST['title'],
56         bigintval($_POST['rate']),
57         bigintval($_POST['mpoi']),
58         $_POST['yacc'],
59         $_POST['ypass'],
60         $_POST['yurl'],
61         $_POST['yrdone'],
62         $_POST['yrfailed'],
63         $_POST['ytrans'],
64         $_POST['allow_url'],
65 ), __FILE__, __LINE__);
66                 $msg = 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 ((isset($_POST['edit'])) && (SELECTION_COUNT($_POST['sel']) > 0)) {
81         // Edit payout types
82         if ((isset($_GET['ok'])) && ($_GET['ok'] == "ok")) {
83                 // Edit entries
84                 foreach ($_POST['sel'] as $id => $sel) {
85                         // Secure ID
86                         $id = bigintval($id);
87
88                         // Edit only if something is entered
89                         if ((!empty($_POST['title'][$id])) && ($_POST['rate'][$id] > 0)) {
90                                 // Update entry
91                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_payout_types` SET
92 type='%s',
93 rate=%s,
94 min_points=%s,
95 allow_url='%s'
96 WHERE id='".$id."' LIMIT 1",
97  array(
98         $_POST['title'][$id],
99         bigintval(REVERT_COMMA($_POST['rate'][$id])),
100         bigintval(REVERT_COMMA($_POST['mpoi'][$id])),
101         $_POST['allow'][$id],
102 ),__FILE__, __LINE__);
103                         }
104                 }
105                 $msg = ADMIN_PAYOUT_ENTRIES_CHANGED;
106         } else {
107                 $display = false; //Suppress any other outputs
108                 $SW = 2; $OUT = "";
109                 foreach ($_POST['sel'] as $id => $sel) {
110                         // Load data
111                         $result = SQL_QUERY_ESC("SELECT type, rate, min_points, allow_url FROM `{!_MYSQL_PREFIX!}_payout_types` WHERE id=%s LIMIT 1",
112                          array(bigintval($id)), __FILE__, __LINE__);
113                         list($title, $rate, $mpoi, $allow) = SQL_FETCHROW($result);
114                         SQL_FREERESULT($result);
115
116                         // Prepare data for the row template
117                         $content = array(
118                                 'sw'    => $SW,
119                                 'id'    => $id,
120                                 'title' => COMPILE_CODE($title),
121                                 'rate'  => TRANSLATE_COMMA($rate),
122                                 'mpoi'  => TRANSLATE_COMMA($mpoi),
123                                 'allow' => ADD_SELECTION("yn", $allow, "allow[".$id."]"),
124                         );
125
126                         // Load row template and switch color
127                         $OUT .= LOAD_TEMPLATE("admin_config_payouts_edit_row", true, $content);
128                         $SW = 3 - $SW;
129                 }
130                 define('__PAYOUT_ROWS', $OUT);
131
132                 // Load main template
133                 LOAD_TEMPLATE("admin_config_payouts_edit");
134         }
135 } elseif ((isset($_POST['del'])) && (SELECTION_COUNT($_POST['sel']) > 0)) {
136         // Delete payout types
137         if ((isset($_GET['ok'])) && ($_GET['ok'] == "ok")) {
138                 // Delete entries
139                 foreach ($_POST['sel'] as $id => $sel) {
140                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_payout_types` WHERE id=%s LIMIT 1",
141                                 array(bigintval($id)), __FILE__, __LINE__);
142                 }
143                 $msg = ADMIN_PAYOUT_ENTRIES_DELETED;
144         } else {
145                 $display = false; //Suppress any other outputs
146                 $SW = 2; $OUT = "";
147                 foreach ($_POST['sel'] as $id => $sel) {
148                         // Secure ID number
149                         $id = bigintval($id);
150
151                         // Load data
152                         $result = SQL_QUERY_ESC("SELECT type, rate, min_points FROM `{!_MYSQL_PREFIX!}_payout_types` WHERE id=%s LIMIT 1",
153                          array($id), __FILE__, __LINE__);
154                         list($title, $rate, $mpoi) = SQL_FETCHROW($result);
155                         SQL_FREERESULT($result);
156
157                         // Prepare data for the row template
158                         $content = array(
159                                 'sw'    => $SW,
160                                 'id'    => $id,
161                                 'title' => COMPILE_CODE($title),
162                                 'rate'  => TRANSLATE_COMMA($rate),
163                                 'mpoi'  => TRANSLATE_COMMA($mpoi),
164                         );
165
166                         // Load row template and switch color
167                         $OUT .= LOAD_TEMPLATE("admin_config_payouts_del_row", true, $content);
168                         $SW = 3 - $SW;
169                 }
170                 define('__PAYOUT_ROWS', $OUT);
171
172                 // Load main template
173                 LOAD_TEMPLATE("admin_config_payouts_del");
174         }
175 }
176
177 if (!empty($msg)) {
178         // Output message
179         LOAD_TEMPLATE("admin_settings_saved", false, $msg);
180 }
181
182 // Payout types
183 $result_type = SQL_QUERY("SELECT id, type, rate, min_points, from_account FROM `{!_MYSQL_PREFIX!}_payout_types` ORDER BY type", __FILE__, __LINE__);
184
185 if ((SQL_NUMROWS($result_type) > 0) && ($display)) {
186         // List all payout types
187         $SW = 2; $OUT = "";
188         while (list($id, $type, $rate, $mpoi, $from) = SQL_FETCHROW($result_type)) {
189                 // Prepare data for the row template
190                 $content = array(
191                         'sw'    => $SW,
192                         'id'    => $id,
193                         'from'  => COMPILE_CODE($from),
194                         'type'  => COMPILE_CODE($type),
195                         'rate'  => TRANSLATE_COMMA($rate),
196                         'mpoi'  => TRANSLATE_COMMA($mpoi),
197                 );
198
199                 // Load row template and switch color
200                 $OUT .= LOAD_TEMPLATE("admin_config_payouts_row", true, $content);
201                 $SW = 3 - $SW;
202         }
203
204         // Free memory
205         SQL_FREERESULT($result_type);
206         define('__PAYOUT_ROWS', $OUT);
207
208         // Load main template
209         LOAD_TEMPLATE("admin_config_payouts");
210 }
211
212 // Does your members request payouts?
213 if ((SQL_NUMROWS($result_mem) > 0) && ($display)) {
214         // Members has requested payouts
215         LOAD_TEMPLATE("admin_settings_saved", false, "<a href=\"{!URL!}/modules.php?module=admin&amp;what=list_payouts\">".ADMIN_PAYOUT_LIST_REQUESTS."</a></P>");
216 } elseif ($display) {
217         // No member requests so far
218         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_PAYOUT_NO_MEMBER_REQUESTS'));
219 }
220
221 // Free result
222 SQL_FREERESULT($result_mem);
223
224 // Add new paypout type
225 if ($display) LOAD_TEMPLATE("admin_payout_add_new");
226
227 //
228 ?>