2 /************************************************************************
3 * M-XChange v0.2.1 Start: 06/10/2005 *
4 * ================ Last change: 05/19/2008 *
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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
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');
55 REQUEST_SET_POST('pay_min_count', bigintval(REQUEST_POST('pay_min_count')));
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');
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) {
76 `{!_MYSQL_PREFIX!}_sponsor_paytypes`
86 REQUEST_POST('name', $id),
87 REQUEST_POST('rate', $id),
88 bigintval(REQUEST_POST('min', $id)),
89 REQUEST_POST('curr', $id),
91 ), __FILE__, __LINE__);
95 $message = getMessage('SPONSOR_PAY_ENTRIES_CHANGED');
96 } elseif (REQUEST_ISSET_POST('remove')) {
97 // Remove entries here...
98 foreach (REQUEST_POST('id') as $id => $sel) {
100 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes` WHERE `id`='%s' LIMIT 1",
101 array(bigintval($id)), __FILE__, __LINE__);
105 $message = getMessage('SPONSOR_PAY_ENTRIES_REMOVED');
108 if (!empty($message)) {
110 LOAD_TEMPLATE('admin_settings_saved', false, $message);
114 if (REQUEST_ISSET_POST('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(REQUEST_POST('pay_name')), __FILE__, __LINE__);
118 if (SQL_NUMROWS($result) == 0) {
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')",
122 REQUEST_POST('pay_name'),
123 convertCommaToDot(REQUEST_POST('pay_rate')),
124 bigintval(REQUEST_POST('pay_min_count')),
125 REQUEST_POST('pay_currency')
126 ), __FILE__, __LINE__);
128 // Payment type added!
129 $message = sprintf(getMessage('ADMIN_SPONSOR_PAYTYPE_ADDED'), REQUEST_POST('pay_name'));
132 SQL_FREERESULT($result);
134 // Entry does already exists
135 $message = sprintf(getMessage('ADMIN_SPONSOR_PAYTYPE_ALREADY'), REQUEST_POST('pay_name'));
139 LOAD_TEMPLATE('admin_settings_saved', false, $message);
140 } elseif ((REQUEST_ISSET_POST('edit')) || (REQUEST_ISSET_POST('del'))) {
143 foreach (REQUEST_POST('id') as $id => $sel) {
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) {
149 list($name, $rate, $min, $curr) = SQL_FETCHROW($result);
150 SQL_FREERESULT($result);
152 // Transfer data to 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)
162 if (REQUEST_ISSET_POST('edit')) {
164 $OUT .= LOAD_TEMPLATE('admin_list_sponsor_pay_edit_row', true, $content);
167 $OUT .= LOAD_TEMPLATE('admin_list_sponsor_pay_del_row', true, $content);
171 $OUT .= LOAD_TEMPLATE('admin_list_sponsor_pay_404', true, $id);
178 // Remember content in constant
179 define('__SPONSOR_ROWS', $OUT);
181 // Load main template depending on mode (edit/delete)
182 if (REQUEST_ISSET_POST('edit')) {
183 // Load main edit template
184 LOAD_TEMPLATE('admin_list_sponsor_pay_edit');
186 // Load main delete template
187 LOAD_TEMPLATE('admin_list_sponsor_pay_del');
190 // Load all payment types
191 $result = SQL_QUERY("SELECT `id`, `pay_name`, `pay_rate`, `pay_min_count`, `pay_currency` FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes` ORDER BY `pay_name` ASC",
194 // Do we have some paytypes setup?
195 if (SQL_NUMROWS($result) > 0) {
196 // Prepare variables for listing
199 // List alle found payment types
200 while ($content = SQL_FETCHARRAY($result)) {
201 // Remember data in array
204 'id' => $content['id'],
205 'name' => $content['pay_name'],
206 'rate' => translateComma($content['pay_rate']),
207 'min' => $content['pay_min_count'],
208 'currency' => $content['pay_currency']
212 $OUT .= LOAD_TEMPLATE('admin_list_sponsor_pay_row', true, $content);
219 SQL_FREERESULT($result);
221 // Remember rows in constant for the template
222 define('__LIST_ROWS', $OUT);
224 // Load list template
225 define('__LIST_CONTENT', LOAD_TEMPLATE('admin_list_sponsor_pay', true));
227 // Noting setup so far!
228 define('__LIST_CONTENT', LOAD_TEMPLATE('admin_settings_saved', true, getMessage('ADMIN_SPONSOR_NO_PAYTYPES')));
231 // Add new payment types here
232 define('__ADD_CONTENT', LOAD_TEMPLATE('admin_add_sponsor_paytype', true));
234 // Load final template
235 LOAD_TEMPLATE('admin_sponsor_paytypes');