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) {
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",
78 REQUEST_POST('name', $id),
79 REQUEST_POST('rate', $id),
80 bigintval(REQUEST_POST('min', $id)),
81 REQUEST_POST('curr', $id),
83 ), __FILE__, __LINE__);
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) {
92 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes` WHERE `id`='%s' LIMIT 1",
93 array(bigintval($id)), __FILE__, __LINE__);
97 $message = getMessage('SPONSOR_PAY_ENTRIES_REMOVED');
100 if (!empty($message)) {
102 LOAD_TEMPLATE('admin_settings_saved', false, $message);
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')",
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__);
120 // Payment type added!
121 $message = sprintf(getMessage('ADMIN_SPONSOR_PAYTYPE_ADDED'), REQUEST_POST('pay_name'));
124 SQL_FREERESULT($result);
126 // Entry does already exists
127 $message = sprintf(getMessage('ADMIN_SPONSOR_PAYTYPE_ALREADY'), REQUEST_POST('pay_name'));
131 LOAD_TEMPLATE('admin_settings_saved', false, $message);
132 } elseif ((REQUEST_ISSET_POST('edit')) || (REQUEST_ISSET_POST('del'))) {
135 foreach (REQUEST_POST('id') as $id => $sel) {
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) {
141 list($name, $rate, $min, $curr) = SQL_FETCHROW($result);
142 SQL_FREERESULT($result);
144 // Transfer data to 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)
154 if (REQUEST_ISSET_POST('edit')) {
156 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_edit_row", true, $content);
159 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_del_row", true, $content);
163 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_404", true, $id);
170 // Remember content in constant
171 define('__SPONSOR_ROWS', $OUT);
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");
178 // Load main delete template
179 LOAD_TEMPLATE("admin_list_sponsor_pay_del");
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",
186 // Do we have some paytypes setup?
187 if (SQL_NUMROWS($result) > 0) {
188 // Prepare variables for listing
191 // List alle found payment types
192 while ($content = SQL_FETCHARRAY($result)) {
193 // Remember data in array
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']
204 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_row", true, $content);
211 SQL_FREERESULT($result);
213 // Remember rows in constant for the template
214 define('__LIST_ROWS', $OUT);
216 // Load list template
217 define('__LIST_CONTENT', LOAD_TEMPLATE("admin_list_sponsor_pay", true));
219 // Noting setup so far!
220 define('__LIST_CONTENT', LOAD_TEMPLATE('admin_settings_saved', true, getMessage('ADMIN_SPONSOR_NO_PAYTYPES')));
223 // Add new payment types here
224 define('__ADD_CONTENT', LOAD_TEMPLATE("admin_add_sponsor_paytype", true));
226 // Load final template
227 LOAD_TEMPLATE("admin_sponsor_paytypes");