512e2a7064a26076647f27cdeedc5d00a839cbd3
[mailer.git] / inc / modules / admin / what-list_sponsor_pay.php
1 <?php
2 /************************************************************************
3  * M-XChange v0.2.1                                   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 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
47
48 $message = '';
49
50 if (REQUEST_ISSET_POST(('add'))) {
51         // Check input variables
52         if (!REQUEST_ISSET_POST(('pay_name'))) REQUEST_UNSET_POST(('add'));
53         if ((round(REQUEST_POST('pay_rate')) == 0) || (!REQUEST_ISSET_POST(('pay_rate')))) REQUEST_UNSET_POST(('add'));
54
55         REQUEST_SET_POST('pay_min_count', bigintval(REQUEST_POST('pay_min_count')));
56
57         if ((REQUEST_POST('pay_min_count') == 0) || (!REQUEST_ISSET_POST(('pay_min_count')))) REQUEST_UNSET_POST(('add'));
58         if (!REQUEST_ISSET_POST(('pay_currency'))) REQUEST_UNSET_POST(('add'));
59
60 } elseif ((REQUEST_ISSET_POST('edit')) || (REQUEST_ISSET_POST('del')) || (REQUEST_ISSET_POST('change')) || (REQUEST_ISSET_POST('remove'))) {
61         // Check if at least one entry was selected
62         if (!REQUEST_ISSET_POST('id')) {
63                 // Nothing selected for editing / deleting???
64                 REQUEST_UNSET_POST('edit');
65                 REQUEST_UNSET_POST('del');
66                 REQUEST_UNSET_POST('change');
67                 REQUEST_UNSET_POST('remove');
68         } elseif (REQUEST_ISSET_POST('change')) {
69                 // Change entries here...
70                 foreach (REQUEST_POST('id') as $id => $sel) {
71                         // Secure ID
72                         $id = bigintval($id);
73
74                         // Save entry
75                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_sponsor_paytypes`
76 SET pay_name='%s', pay_rate='%s', pay_min_count='%s', pay_currency='%s' WHERE `id`='%s' LIMIT 1",
77                         array(
78                         REQUEST_POST('name', $id),
79                         REQUEST_POST('rate', $id),
80                         bigintval(REQUEST_POST('min', $id)),
81                         REQUEST_POST('curr', $id),
82                         $id
83                         ), __FILE__, __LINE__);
84                 }
85
86                 // Generate message
87                 $message = getMessage('SPONSOR_PAY_ENTRIES_CHANGED');
88         } elseif (REQUEST_ISSET_POST('remove')) {
89                 // Remove entries here...
90                 foreach (REQUEST_POST('id') as $id => $sel) {
91                         // Remove entry
92                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes` WHERE `id`='%s' LIMIT 1",
93                         array(bigintval($id)), __FILE__, __LINE__);
94                 }
95
96                 // Generate message
97                 $message = getMessage('SPONSOR_PAY_ENTRIES_REMOVED');
98         }
99
100         if (!empty($message)) {
101                 // Output message
102                 LOAD_TEMPLATE('admin_settings_saved', false, $message);
103         }
104 }
105
106 if (REQUEST_ISSET_POST(('add'))) {
107         // Check if entry with same name does exists
108         $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes` WHERE pay_name='%s' LIMIT 1",
109         array(REQUEST_POST('pay_name')), __FILE__, __LINE__);
110         if (SQL_NUMROWS($result) == 0) {
111                 // No entry found so add this line
112                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_sponsor_paytypes` (pay_name, pay_rate, pay_min_count, pay_currency) VALUES ('%s','%s','%s','%s')",
113                 array(
114                 htmlspecialchars(REQUEST_POST('pay_name')),
115                 convertCommaToDot(REQUEST_POST('pay_rate')),
116                 bigintval(REQUEST_POST('pay_min_count')),
117                 htmlspecialchars(REQUEST_POST('pay_currency'))
118                 ), __FILE__, __LINE__);
119
120                 // Payment type added!
121                 $message = sprintf(getMessage('ADMIN_SPONSOR_PAYTYPE_ADDED'), REQUEST_POST('pay_name'));
122         } else {
123                 // Free memory
124                 SQL_FREERESULT($result);
125
126                 // Entry does already exists
127                 $message = sprintf(getMessage('ADMIN_SPONSOR_PAYTYPE_ALREADY'), REQUEST_POST('pay_name'));
128         }
129
130         // Output message
131         LOAD_TEMPLATE('admin_settings_saved', false, $message);
132 } elseif ((REQUEST_ISSET_POST('edit')) || (REQUEST_ISSET_POST('del'))) {
133         // Load all data
134         $OUT = ''; $SW = 2;
135         foreach (REQUEST_POST('id') as $id => $sel) {
136                 // Load entry
137                 $result = SQL_QUERY_ESC("SELECT pay_name, pay_rate, pay_min_count, pay_currency FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes` WHERE `id`='%s' LIMIT 1",
138                 array(bigintval($id)), __FILE__, __LINE__);
139                 if (SQL_NUMROWS($result) == 1) {
140                         // Load data
141                         list($name, $rate, $min, $curr) = SQL_FETCHROW($result);
142                         SQL_FREERESULT($result);
143
144                         // Transfer data to array
145                         $content = array(
146                                 'id'   => bigintval($id),
147                                 'sw'   => bigintval($SW),
148                                 'name' => htmlspecialchars($name),
149                                 'rate' => translateComma($rate),
150                                 'min'  => bigintval($min),
151                                 'curr' => htmlspecialchars($curr)
152                         );
153
154                         if (REQUEST_ISSET_POST('edit')) {
155                                 // Edit entry
156                                 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_edit_row", true, $content);
157                         } else {
158                                 // Delete entry
159                                 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_del_row", true, $content);
160                         }
161                 } else {
162                         // Entry invalid
163                         $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_404", true, $id);
164                 }
165
166                 // Switch colors
167                 $SW = 3 - $SW;
168         } // END - foreach
169
170         // Remember content in constant
171         define('__SPONSOR_ROWS', $OUT);
172
173         // Load main template depending on mode (edit/delete)
174         if (REQUEST_ISSET_POST('edit')) {
175                 // Load main edit template
176                 LOAD_TEMPLATE("admin_list_sponsor_pay_edit");
177         } else {
178                 // Load main delete template
179                 LOAD_TEMPLATE("admin_list_sponsor_pay_del");
180         }
181 } else {
182         // Load all payment types
183         $result = SQL_QUERY("SELECT id, pay_name, pay_rate, pay_min_count, pay_currency FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes` ORDER BY pay_name",
184         __FILE__, __LINE__);
185
186         // Do we have some paytypes setup?
187         if (SQL_NUMROWS($result) > 0) {
188                 // Prepare variables for listing
189                 $OUT = ''; $SW = 2;
190
191                 // List alle found payment types
192                 while ($content = SQL_FETCHARRAY($result)) {
193                         // Remember data in array
194                         $content = array(
195                                 'sw'       => $SW,
196                                 'id'       => $content['id'],
197                                 'name'     => $content['pay_name'],
198                                 'rate'     => translateComma($content['pay_rate']),
199                                 'min'      => $content['pay_min_count'],
200                                 'currency' => $content['pay_currency']
201                         );
202
203                         // Add row
204                         $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_row", true, $content);
205
206                         // Switch colors
207                         $SW = 3 - $SW;
208                 } // END - while
209
210                 // Free memory
211                 SQL_FREERESULT($result);
212
213                 // Remember rows in constant for the template
214                 define('__LIST_ROWS', $OUT);
215
216                 // Load list template
217                 define('__LIST_CONTENT', LOAD_TEMPLATE("admin_list_sponsor_pay", true));
218         } else {
219                 // Noting setup so far!
220                 define('__LIST_CONTENT', LOAD_TEMPLATE('admin_settings_saved', true, getMessage('ADMIN_SPONSOR_NO_PAYTYPES')));
221         }
222
223         // Add new payment types here
224         define('__ADD_CONTENT', LOAD_TEMPLATE("admin_add_sponsor_paytype", true));
225
226         // Load final template
227         LOAD_TEMPLATE("admin_sponsor_paytypes");
228 }
229
230 //
231 ?>