2 /************************************************************************
3 * MXChange v0.2.1 Start: 06/10/2005 *
4 * =============== Last change: 05/18/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. *
22 * This program is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
25 * GNU General Public License for more details. *
27 * You should have received a copy of the GNU General Public License *
28 * along with this program; if not, write to the Free Software *
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
31 ************************************************************************/
33 // Some security stuff...
34 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!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", basename(__FILE__));
44 if (isset($HTTP_POST_VARS['add']))
46 // Check input variables
47 if (empty($HTTP_POST_VARS['pay_name'])) unset($HTTP_POST_VARS['add']);
48 if ((round($HTTP_POST_VARS['pay_rate']) == 0) || (empty($HTTP_POST_VARS['pay_rate']))) unset($HTTP_POST_VARS['add']);
49 $HTTP_POST_VARS['pay_min_count'] = bigintval($HTTP_POST_VARS['pay_min_count']);
50 if (($HTTP_POST_VARS['pay_min_count'] == 0) || (empty($HTTP_POST_VARS['pay_min_count']))) unset($HTTP_POST_VARS['add']);
51 if (empty($HTTP_POST_VARS['pay_currency'])) unset($HTTP_POST_VARS['add']);
53 elseif ((isset($HTTP_POST_VARS['edit'])) || (isset($HTTP_POST_VARS['del'])) || (isset($HTTP_POST_VARS['change'])) || (isset($HTTP_POST_VARS['remove'])))
55 // Check if at least one entry was selected
56 if (empty($HTTP_POST_VARS['id']))
58 // Nothing selected for editing / deleting???
59 unset($HTTP_POST_VARS['edit']);
60 unset($HTTP_POST_VARS['del']);
61 unset($HTTP_POST_VARS['change']);
62 unset($HTTP_POST_VARS['remove']);
64 elseif (isset($HTTP_POST_VARS['change']))
66 // Change entries here...
67 foreach ($HTTP_POST_VARS['id'] as $id=>$sel)
73 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_paytypes
74 SET pay_name='%s', pay_rate='%s', pay_min_count='%s', pay_currency='%s' WHERE id='%s' LIMIT 1",
75 array($HTTP_POST_VARS['name'][$id], $HTTP_POST_VARS['rate'][$id], bigintval($HTTP_POST_VARS['min'][$id]), $HTTP_POST_VARS['curr'][$id], $id),
80 $MSG = SPONSOR_PAY_ENTRIES_CHANGED;
82 elseif (isset($HTTP_POST_VARS['remove']))
84 // Remove entries here...
85 foreach ($HTTP_POST_VARS['id'] as $id=>$sel)
88 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_sponsor_paytypes WHERE id='%s' LIMIT 1",
89 array(bigintval($id)), __FILE__, __LINE__);
93 $MSG = SPONSOR_PAY_ENTRIES_REMOVED;
99 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
104 if (isset($HTTP_POST_VARS['add']))
106 // Check if entry with same name does exists
107 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_sponsor_paytypes WHERE pay_name='%s' LIMIT 1",
108 array($HTTP_POST_VARS['pay_name']), __FILE__, __LINE__);
109 if (SQL_NUMROWS($result) == 0)
111 // No entry found so add this line
112 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_sponsor_paytypes (pay_name, pay_rate, pay_min_count, pay_currency)
113 VALUES ('%s', '%s', '%s', '%s')",
114 array(htmlspecialchars($HTTP_POST_VARS['pay_name']), str_replace(",", ".", $HTTP_POST_VARS['pay_rate']), bigintval($HTTP_POST_VARS['pay_min_count']), htmlspecialchars($HTTP_POST_VARS['pay_currency'])),
117 // Payment type added!
118 $MSG = SPONSOR_ADMIN_PAYTYPE_ADDED_1.$HTTP_POST_VARS['pay_name'].SPONSOR_ADMIN_PAYTYPE_ADDED_2;
123 SQL_FREERESULT($result);
125 // Entry does already exists
126 $MSG = SPONSOR_ADMIN_PAYTYPE_ALREADY_1.$HTTP_POST_VARS['pay_name'].SPONSOR_ADMIN_PAYTYPE_ALREADY_2;
130 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
133 elseif ((isset($HTTP_POST_VARS['edit'])) || (isset($HTTP_POST_VARS['del'])))
137 foreach ($HTTP_POST_VARS['id'] as $id=>$sel)
140 $result = SQL_QUERY_ESC("SELECT pay_name, pay_rate, pay_min_count, pay_currency FROM "._MYSQL_PREFIX."_sponsor_paytypes WHERE id='%s' LIMIT 1",
141 array(bigintval($id)), __FILE__, __LINE__);
142 if (SQL_NUMROWS($result) == 1)
145 list($name, $rate, $min, $curr) = SQL_FETCHROW($result);
146 SQL_FREERESULT($result);
148 // Transfer data to array
150 'id' => bigintval($id),
151 'sw' => bigintval($SW),
152 'name' => htmlspecialchars($name),
153 'rate' => TRANSLATE_COMMA($rate),
154 'min' => bigintval($min),
155 'curr' => htmlspecialchars($curr)
158 if (isset($HTTP_POST_VARS['edit']))
161 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_edit_row", true, $content);
166 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_del_row", true, $content);
172 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_404", true, $id);
179 // Remember content in constant
180 define('__SPONSOR_ROWS', $OUT);
182 // Load main template depending on mode (edit/delete)
183 if (isset($HTTP_POST_VARS['edit']))
185 // Load main edit template
186 LOAD_TEMPLATE("admin_list_sponsor_pay_edit");
190 // Load main delete template
191 LOAD_TEMPLATE("admin_list_sponsor_pay_del");
196 // Load all payment types
197 $result = SQL_QUERY("SELECT id, pay_name, pay_rate, pay_min_count, pay_currency FROM "._MYSQL_PREFIX."_sponsor_paytypes ORDER BY pay_name",
200 // Do we have some paytypes setup?
201 if (SQL_NUMROWS($result) > 0)
203 // Prepare variables for listing
206 // List alle found payment types
207 while(list($id, $name, $rate, $min, $currency) = SQL_FETCHROW($result))
209 // Remember data in array
214 'rate' => TRANSLATE_COMMA($rate),
216 'currency' => $currency
220 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_row", true, $content);
227 SQL_FREERESULT($result);
229 // Remember rows in constant for the template
230 define('__LIST_ROWS', $OUT);
232 // Load list template
233 define('__LIST_CONTENT', LOAD_TEMPLATE("admin_list_sponsor_pay", true));
237 // Noting setup so far!
238 define('__LIST_CONTENT', LOAD_TEMPLATE("admin_settings_saved", true, SPONSOR_ADMIN_NO_PAYTYPES));
241 // Add new payment types here
242 define('__ADD_CONTENT', LOAD_TEMPLATE("admin_add_sponsor_paytype", true));
244 // Load final template
245 LOAD_TEMPLATE("admin_sponsor_paytypes");