Some language strings fixed, renamed. Copyright notice updated
[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 if (isPostRequestParameterSet('rate')) setPostRequestParameter('rate', convertCommaToDot(postRequestParameter('rate')));
47
48 if ((isFormSent('add')) && (isPostRequestParameterSet('title')) && (postRequestParameter('rate') > 0)) {
49         // Add new payout type
50         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE type='%s' LIMIT 1",
51         array(postRequestParameter('title')), __FILE__, __LINE__);
52         if (SQL_HASZERONUMS($result)) {
53                 // Add now
54                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_payout_types`
55 (`type`, `rate`, `min_points`, `from_account`, `from_pass`, `engine_url`, `engine_ret_ok`, `engine_ret_failed`, `pass_enc`, `allow_url`)
56 VALUES ('%s', %s, %s,'%s','%s','%s','%s','%s','%s','%s')",
57                 array(
58                         postRequestParameter('title'),
59                         bigintval(postRequestParameter('rate')),
60                         bigintval(postRequestParameter('min_points')),
61                         postRequestParameter('yacc'),
62                         postRequestParameter('ypass'),
63                         postRequestParameter('yurl'),
64                         postRequestParameter('yrdone'),
65                         postRequestParameter('yrfailed'),
66                         postRequestParameter('ytrans'),
67                         postRequestParameter('allow_url'),
68                 ), __FILE__, __LINE__);
69
70                 // Get message
71                 $message = '{--ADMIN_PAYOUT_TYPE_ADDED--}';
72         } else {
73                 // Free memory
74                 SQL_FREERESULT($result);
75
76                 // Does already exist
77                 $message = '<div class="notice">{--ADMIN_PAYOUT_TYPE_ALREADY--}</div>';
78         }
79 }
80
81 // Payout requests by your members
82 $result_mem = SQL_QUERY("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `status`='NEW' ORDER BY payout_timestamp DESC", __FILE__, __LINE__);
83
84 $display = true;
85 if ((isFormSent('edit')) && (ifPostContainsSelections())) {
86         // Edit payout types
87         if ((isGetRequestParameterSet('ok')) && (getRequestParameter('ok') == 'ok')) {
88                 // Init SQLs
89                 initSqls();
90
91                 // Edit entries
92                 foreach (postRequestParameter('sel') as $id => $sel) {
93                         // Secure id
94                         $id = bigintval($id);
95
96                         // Edit only if something is entered
97                         if ((isPostRequestParameterSet('title', $id)) && (postRequestParameter('rate', $id) > 0)) {
98                                 // Update entry
99                                 addSql(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
105         `id`=%s
106 LIMIT 1",
107                                 array(
108                                         postRequestParameter('type', $id),
109                                         convertCommaToDot(postRequestParameter('rate', $id)),
110                                         convertCommaToDot(postRequestParameter('min_points' , $id)),
111                                         postRequestParameter('allow_url', $id),
112                                         bigintval($id)
113                                 ),__FILE__, __LINE__, false));
114                         }
115                 }
116
117                 // Run all SQLs
118                 runFilterChain('run_sqls');
119
120                 // Get message
121                 $message = '{--ADMIN_PAYOUT_ENTRIES_CHANGED--}';
122         } else {
123                 $display = false; //Suppress any other outputs
124                 $OUT = '';
125                 foreach (postRequestParameter('sel') as $id => $sel) {
126                         // Load data
127                         $result = SQL_QUERY_ESC("SELECT `id`, `type`, `rate`, `min_points`, `allow_url` FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
128                                 array(bigintval($id)), __FILE__, __LINE__);
129                         $content = SQL_FETCHARRAY($result);
130                         SQL_FREERESULT($result);
131
132                         // Prepare data for the row template
133                         $content['allow_url'] = addSelectionBox('yn', $content['allow_url'], 'allow_url[' . $content['id'] . ']');
134
135                         // Load row template and switch color
136                         $OUT .= loadTemplate('admin_config_payouts_edit_row', true, $content);
137                 } // END - foreach
138
139                 // Load main template
140                 loadTemplate('admin_config_payouts_edit', false, $OUT);
141         }
142 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
143         // Delete payout types
144         if ((isGetRequestParameterSet('ok')) && (getRequestParameter('ok') == 'ok')) {
145                 // Init SQLs
146                 initSqls();
147
148                 // Delete entries
149                 foreach (postRequestParameter('sel') as $id => $sel) {
150                         addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
151                                 array(bigintval($id)), __FILE__, __LINE__, false));
152                 } // END - foreach
153
154                 // Run all SQLs
155                 runFilterChain('run_sqls');
156
157                 // Get message
158                 $message = '{--ADMIN_PAYOUT_ENTRIES_DELETED--}';
159         } else {
160                 $display = false; //Suppress any other outputs
161                 $OUT = '';
162                 foreach (postRequestParameter('sel') as $id => $sel) {
163                         // Secure id number
164                         $id = bigintval($id);
165
166                         // Load data
167                         $result = SQL_QUERY_ESC("SELECT `id`, `type`, `rate`, `min_points` FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
168                                 array($id), __FILE__, __LINE__);
169                         $content = SQL_FETCHARRAY($result);
170                         SQL_FREERESULT($result);
171
172                         // Load row template and switch color
173                         $OUT .= loadTemplate('admin_config_payouts_del_row', true, $content);
174                 } // END - foreach
175
176                 // Load main template
177                 loadTemplate('admin_config_payouts_del', false, $OUT);
178         }
179 }
180
181 if (!empty($message)) {
182         // Output message
183         loadTemplate('admin_settings_saved', false, $message);
184 } // END - if
185
186 // Payout types
187 $result_type = SQL_QUERY("SELECT
188         `id`, `type`, `rate`, `min_points`, `from_account`
189 FROM
190         `{?_MYSQL_PREFIX?}_payout_types`
191 ORDER BY
192         `type` ASC", __FILE__, __LINE__);
193
194 if ((!SQL_HASZERONUMS($result_type)) && ($display)) {
195         // List all payout types
196         $OUT = '';
197         while ($content = SQL_FETCHARRAY($result_type)) {
198                 // Load row template and switch color
199                 $OUT .= loadTemplate('admin_config_payouts_row', true, $content);
200         } // END - while
201
202         // Free memory
203         SQL_FREERESULT($result_type);
204
205         // Load main template
206         loadTemplate('admin_config_payouts', false, $OUT);
207 } // END - if
208
209 // Does your members request payouts?
210 if ((!SQL_HASZERONUMS($result_mem)) && ($display)) {
211         // Members has requested payouts
212         loadTemplate('admin_settings_saved', false, '<a href="{%url=modules.php?module=admin&amp;what=list_payouts%}">{--ADMIN_PAYOUT_LIST_REQUESTS--}</a>');
213 } elseif ($display) {
214         // No member requests so far
215         loadTemplate('admin_settings_saved', false, '{--ADMIN_PAYOUT_NO_MEMBER_REQUESTS--}');
216 }
217
218 // Free result
219 SQL_FREERESULT($result_mem);
220
221 // Add new payout type
222 if ($display === true) loadTemplate('admin_payout_add_new');
223
224 // [EOF]
225 ?>