f0874d6a173c3e11a92c737d3b30dbbb8b95f712
[mailer.git] / inc / modules / admin / what-list_sponsor_pay.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/10/2005 *
4  * ===================                          Last change: 05/19/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_sponsor_pay.php                        *
8  * -------------------------------------------------------------------- *
9  * Short description : List/edit/delete all payments and add new        *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Auflisten/Aendern/Loeschen aller Buchungspakete  *
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 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 $message = '';
49
50 if (isFormSent('add')) {
51         // Check input variables
52         if (!isPostRequestParameterSet('pay_name')) unsetPostRequestParameter('add');
53         if ((round(postRequestParameter('pay_rate')) == 0) || (!isPostRequestParameterSet('pay_rate'))) unsetPostRequestParameter('add');
54
55         setPostRequestParameter('pay_min_count', bigintval(postRequestParameter('pay_min_count')));
56
57         if ((postRequestParameter('pay_min_count') == '0') || (!isPostRequestParameterSet('pay_min_count'))) unsetPostRequestParameter('add');
58         if (!isPostRequestParameterSet('pay_currency')) unsetPostRequestParameter('add');
59
60 } elseif ((isFormSent('edit')) || (isFormSent('del')) || (isFormSent('change')) || (isFormSent('remove'))) {
61         // Check if at least one entry was selected
62         if (!isPostRequestParameterSet('id')) {
63                 // Nothing selected for editing / deleting???
64                 unsetPostRequestParameter('edit');
65                 unsetPostRequestParameter('del');
66                 unsetPostRequestParameter('change');
67                 unsetPostRequestParameter('remove');
68         } elseif (isFormSent('change')) {
69                 // Change entries here...
70                 foreach (postRequestParameter('id') as $id => $sel) {
71                         // Secure id
72                         $id = bigintval($id);
73
74                         // Save entry
75                         SQL_QUERY_ESC("UPDATE
76         `{?_MYSQL_PREFIX?}_sponsor_paytypes`
77 SET
78         `pay_name`='%s',
79         `pay_rate`='%s',
80         `pay_min_count`='%s',
81         `pay_currency`='%s'
82 WHERE
83         `id`='%s'
84 LIMIT 1",
85                         array(
86                                 postRequestParameter('name', $id),
87                                 postRequestParameter('rate', $id),
88                                 bigintval(postRequestParameter('min', $id)),
89                                 postRequestParameter('curr', $id),
90                                 $id
91                         ), __FILE__, __LINE__);
92                 }
93
94                 // Generate message
95                 $message = getMessage('SPONSOR_PAY_ENTRIES_CHANGED');
96         } elseif (isFormSent('remove')) {
97                 // Remove entries here...
98                 foreach (postRequestParameter('id') as $id => $sel) {
99                         // Remove entry
100                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes` WHERE `id`='%s' LIMIT 1",
101                                 array(bigintval($id)), __FILE__, __LINE__);
102                 }
103
104                 // Generate message
105                 $message = getMessage('SPONSOR_PAY_ENTRIES_REMOVED');
106         }
107
108         if (!empty($message)) {
109                 // Output message
110                 loadTemplate('admin_settings_saved', false, $message);
111         } // END - if
112 }
113
114 if (isFormSent('add')) {
115         // Check if entry with same name does exists
116         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes` WHERE `pay_name`='%s' LIMIT 1",
117                 array(postRequestParameter('pay_name')), __FILE__, __LINE__);
118         if (SQL_HASZERONUMS($result)) {
119                 // No entry found so add this line
120                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_paytypes` (`pay_name`, `pay_rate`, `pay_min_count`, `pay_currency`) VALUES ('%s','%s','%s','%s')",
121                         array(
122                                 postRequestParameter('pay_name'),
123                                 convertCommaToDot(postRequestParameter('pay_rate')),
124                                 bigintval(postRequestParameter('pay_min_count')),
125                                 postRequestParameter('pay_currency')
126                         ), __FILE__, __LINE__);
127
128                 // Payment type added!
129                 $message = getMaskedMessage('ADMIN_SPONSOR_PAYTYPE_ADDED', postRequestParameter('pay_name'));
130         } else {
131                 // Entry does already exists
132                 $message = getMaskedMessage('ADMIN_SPONSOR_PAYTYPE_ALREADY', postRequestParameter('pay_name'));
133         }
134
135         // Free memory
136         SQL_FREERESULT($result);
137
138         // Output message
139         loadTemplate('admin_settings_saved', false, $message);
140 } elseif ((isFormSent('edit')) || (isFormSent('del'))) {
141         // Load all data
142         $OUT = ''; $SW = 2;
143         foreach (postRequestParameter('id') as $id => $sel) {
144                 // Load entry
145                 $result = SQL_QUERY_ESC("SELECT `pay_name`, `pay_rate`, `pay_min_count`, `pay_currency` FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes` WHERE `id`='%s' LIMIT 1",
146                         array(bigintval($id)), __FILE__, __LINE__);
147                 if (SQL_NUMROWS($result) == 1) {
148                         // Load data
149                         list($name, $rate, $min, $curr) = SQL_FETCHROW($result);
150                         SQL_FREERESULT($result);
151
152                         // Transfer data to array
153                         $content = array(
154                                 'id'   => bigintval($id),
155                                 'sw'   => bigintval($SW),
156                                 'name' => htmlspecialchars($name),
157                                 'rate' => translateComma($rate),
158                                 'min'  => bigintval($min),
159                                 'curr' => htmlspecialchars($curr)
160                         );
161
162                         if (isFormSent('edit')) {
163                                 // Edit entry
164                                 $OUT .= loadTemplate('admin_list_sponsor_pay_edit_row', true, $content);
165                         } else {
166                                 // Delete entry
167                                 $OUT .= loadTemplate('admin_list_sponsor_pay_del_row', true, $content);
168                         }
169                 } else {
170                         // Entry invalid
171                         $OUT .= loadTemplate('admin_list_sponsor_pay_404', true, $id);
172                 }
173
174                 // Switch colors
175                 $SW = 3 - $SW;
176         } // END - foreach
177
178         // Load main template depending on mode (edit/delete)
179         if (isFormSent('edit')) {
180                 // Load main edit template
181                 loadTemplate('admin_list_sponsor_pay_edit', false, $OUT);
182         } else {
183                 // Load main delete template
184                 loadTemplate('admin_list_sponsor_pay_del', false, $OUT);
185         }
186 } else {
187         // Load all payment types
188         $result = SQL_QUERY("SELECT
189         `id`, `pay_name`, `pay_rate`, `pay_min_count`, `pay_currency`
190 FROM
191         `{?_MYSQL_PREFIX?}_sponsor_paytypes`
192 ORDER BY
193         `pay_name` ASC",
194                 __FILE__, __LINE__);
195
196         // Do we have some paytypes setup?
197         if (SQL_NUMROWS($result) > 0) {
198                 // Prepare variables for listing
199                 $OUT = ''; $SW = 2;
200
201                 // List alle found payment types
202                 while ($content = SQL_FETCHARRAY($result)) {
203                         // Remember data in array
204                         $content = array(
205                                 'sw'       => $SW,
206                                 'id'       => $content['id'],
207                                 'name'     => $content['pay_name'],
208                                 'rate'     => translateComma($content['pay_rate']),
209                                 'min'      => $content['pay_min_count'],
210                                 'currency' => $content['pay_currency']
211                         );
212
213                         // Add row
214                         $OUT .= loadTemplate('admin_list_sponsor_pay_row', true, $content);
215
216                         // Switch colors
217                         $SW = 3 - $SW;
218                 } // END - while
219
220                 // Load list template
221                 $content['list_out'] = loadTemplate('admin_list_sponsor_pay', true, $OUT);
222         } else {
223                 // Noting setup so far!
224                 $content['list_out'] = loadTemplate('admin_settings_saved', true, '{--ADMIN_SPONSOR_NO_PAYTYPES--}');
225         }
226
227         // Free memory
228         SQL_FREERESULT($result);
229
230         // Add new payment types here
231         $content['add_out'] = loadTemplate('admin_add_sponsor_paytype', true);
232
233         // Load final template
234         loadTemplate('admin_sponsor_paytypes', false, $content);
235 }
236
237 // [EOF]
238 ?>