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