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 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
45 if (REQUEST_ISSET_POST(('add'))) {
46 // Check input variables
47 if (!REQUEST_ISSET_POST(('pay_name'))) REQUEST_UNSET_POST(('add'));
48 if ((round(REQUEST_POST('pay_rate')) == 0) || (!REQUEST_ISSET_POST(('pay_rate')))) REQUEST_UNSET_POST(('add'));
50 REQUEST_SET_POST('pay_min_count', bigintval(REQUEST_POST('pay_min_count')));
52 if ((REQUEST_POST('pay_min_count') == 0) || (!REQUEST_ISSET_POST(('pay_min_count')))) REQUEST_UNSET_POST(('add'));
53 if (!REQUEST_ISSET_POST(('pay_currency'))) REQUEST_UNSET_POST(('add'));
55 } elseif ((REQUEST_ISSET_POST(('edit'))) || (REQUEST_ISSET_POST(('del'))) || (REQUEST_ISSET_POST(('change'))) || (REQUEST_ISSET_POST(('remove')))) {
56 // Check if at least one entry was selected
57 if (!REQUEST_ISSET_POST(('id'))) {
58 // Nothing selected for editing / deleting???
59 REQUEST_UNSET_POST(('edit'));
60 REQUEST_UNSET_POST(('del'));
61 REQUEST_UNSET_POST(('change'));
62 REQUEST_UNSET_POST(('remove'));
63 } elseif (REQUEST_ISSET_POST(('change'))) {
64 // Change entries here...
65 foreach (REQUEST_POST('id') as $id => $sel) {
70 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_sponsor_paytypes`
71 SET pay_name='%s', pay_rate='%s', pay_min_count='%s', pay_currency='%s' WHERE id='%s' LIMIT 1",
73 REQUEST_POST('name', $id),
74 REQUEST_POST('rate', $id),
75 bigintval(REQUEST_POST('min', $id)),
76 REQUEST_POST('curr', $id),
78 ), __FILE__, __LINE__);
82 $MSG = getMessage('SPONSOR_PAY_ENTRIES_CHANGED');
83 } elseif (REQUEST_ISSET_POST(('remove'))) {
84 // Remove entries here...
85 foreach (REQUEST_POST('id') as $id => $sel) {
87 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes` WHERE id='%s' LIMIT 1",
88 array(bigintval($id)), __FILE__, __LINE__);
92 $MSG = getMessage('SPONSOR_PAY_ENTRIES_REMOVED');
97 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
101 if (REQUEST_ISSET_POST(('add'))) {
102 // Check if entry with same name does exists
103 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes` WHERE pay_name='%s' LIMIT 1",
104 array(REQUEST_POST('pay_name')), __FILE__, __LINE__);
105 if (SQL_NUMROWS($result) == 0) {
106 // No entry found so add this line
107 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_sponsor_paytypes` (pay_name, pay_rate, pay_min_count, pay_currency) VALUES ('%s','%s','%s','%s')",
109 htmlspecialchars(REQUEST_POST('pay_name')),
110 REVERT_COMMA(REQUEST_POST('pay_rate')),
111 bigintval(REQUEST_POST('pay_min_count')),
112 htmlspecialchars(REQUEST_POST('pay_currency'))
113 ), __FILE__, __LINE__);
115 // Payment type added!
116 $MSG = ADMIN_SPONSOR_PAYTYPE_ADDED_1.REQUEST_POST('pay_name').ADMIN_SPONSOR_PAYTYPE_ADDED_2;
119 SQL_FREERESULT($result);
121 // Entry does already exists
122 $MSG = ADMIN_SPONSOR_PAYTYPE_ALREADY_1.REQUEST_POST('pay_name').ADMIN_SPONSOR_PAYTYPE_ALREADY_2;
126 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
127 } elseif ((REQUEST_ISSET_POST(('edit'))) || (REQUEST_ISSET_POST(('del')))) {
130 foreach (REQUEST_POST('id') as $id => $sel) {
132 $result = SQL_QUERY_ESC("SELECT pay_name, pay_rate, pay_min_count, pay_currency FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes` WHERE id='%s' LIMIT 1",
133 array(bigintval($id)), __FILE__, __LINE__);
134 if (SQL_NUMROWS($result) == 1) {
136 list($name, $rate, $min, $curr) = SQL_FETCHROW($result);
137 SQL_FREERESULT($result);
139 // Transfer data to array
141 'id' => bigintval($id),
142 'sw' => bigintval($SW),
143 'name' => htmlspecialchars($name),
144 'rate' => TRANSLATE_COMMA($rate),
145 'min' => bigintval($min),
146 'curr' => htmlspecialchars($curr)
149 if (REQUEST_ISSET_POST(('edit'))) {
151 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_edit_row", true, $content);
154 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_del_row", true, $content);
158 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_404", true, $id);
165 // Remember content in constant
166 define('__SPONSOR_ROWS', $OUT);
168 // Load main template depending on mode (edit/delete)
169 if (REQUEST_ISSET_POST(('edit'))) {
170 // Load main edit template
171 LOAD_TEMPLATE("admin_list_sponsor_pay_edit");
173 // Load main delete template
174 LOAD_TEMPLATE("admin_list_sponsor_pay_del");
177 // Load all payment types
178 $result = SQL_QUERY("SELECT id, pay_name, pay_rate, pay_min_count, pay_currency FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes` ORDER BY pay_name",
181 // Do we have some paytypes setup?
182 if (SQL_NUMROWS($result) > 0) {
183 // Prepare variables for listing
186 // List alle found payment types
187 while (list($id, $name, $rate, $min, $currency) = SQL_FETCHROW($result)) {
188 // Remember data in array
193 'rate' => TRANSLATE_COMMA($rate),
195 'currency' => $currency
199 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_row", true, $content);
206 SQL_FREERESULT($result);
208 // Remember rows in constant for the template
209 define('__LIST_ROWS', $OUT);
211 // Load list template
212 define('__LIST_CONTENT', LOAD_TEMPLATE("admin_list_sponsor_pay", true));
214 // Noting setup so far!
215 define('__LIST_CONTENT', LOAD_TEMPLATE("admin_settings_saved", true, getMessage('ADMIN_SPONSOR_NO_PAYTYPES')));
218 // Add new payment types here
219 define('__ADD_CONTENT', LOAD_TEMPLATE("admin_add_sponsor_paytype", true));
221 // Load final template
222 LOAD_TEMPLATE("admin_sponsor_paytypes");