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