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 - 2009 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')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
49 if (isPostRequestElementSet('add')) {
50 // Check input variables
51 if (!isPostRequestElementSet('pay_name')) unsetPostRequestElement('add');
52 if ((round(postRequestElement('pay_rate')) == 0) || (!isPostRequestElementSet('pay_rate'))) unsetPostRequestElement('add');
54 setRequestPostElement('pay_min_count', bigintval(postRequestElement('pay_min_count')));
56 if ((postRequestElement('pay_min_count') == 0) || (!isPostRequestElementSet('pay_min_count'))) unsetPostRequestElement('add');
57 if (!isPostRequestElementSet('pay_currency')) unsetPostRequestElement('add');
59 } elseif ((isPostRequestElementSet('edit')) || (isPostRequestElementSet('del')) || (isPostRequestElementSet('change')) || (isPostRequestElementSet('remove'))) {
60 // Check if at least one entry was selected
61 if (!isPostRequestElementSet('id')) {
62 // Nothing selected for editing / deleting???
63 unsetPostRequestElement('edit');
64 unsetPostRequestElement('del');
65 unsetPostRequestElement('change');
66 unsetPostRequestElement('remove');
67 } elseif (isPostRequestElementSet('change')) {
68 // Change entries here...
69 foreach (postRequestElement('id') as $id => $sel) {
75 `{?_MYSQL_PREFIX?}_sponsor_paytypes`
85 postRequestElement('name', $id),
86 postRequestElement('rate', $id),
87 bigintval(postRequestElement('min', $id)),
88 postRequestElement('curr', $id),
90 ), __FILE__, __LINE__);
94 $message = getMessage('SPONSOR_PAY_ENTRIES_CHANGED');
95 } elseif (isPostRequestElementSet('remove')) {
96 // Remove entries here...
97 foreach (postRequestElement('id') as $id => $sel) {
99 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes` WHERE `id`='%s' LIMIT 1",
100 array(bigintval($id)), __FILE__, __LINE__);
104 $message = getMessage('SPONSOR_PAY_ENTRIES_REMOVED');
107 if (!empty($message)) {
109 loadTemplate('admin_settings_saved', false, $message);
113 if (isPostRequestElementSet('add')) {
114 // Check if entry with same name does exists
115 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes` WHERE `pay_name`='%s' LIMIT 1",
116 array(postRequestElement('pay_name')), __FILE__, __LINE__);
117 if (SQL_NUMROWS($result) == 0) {
118 // No entry found so add this line
119 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_paytypes` (`pay_name`, `pay_rate`, `pay_min_count`, `pay_currency`) VALUES ('%s','%s','%s','%s')",
121 postRequestElement('pay_name'),
122 convertCommaToDot(postRequestElement('pay_rate')),
123 bigintval(postRequestElement('pay_min_count')),
124 postRequestElement('pay_currency')
125 ), __FILE__, __LINE__);
127 // Payment type added!
128 $message = sprintf(getMessage('ADMIN_SPONSOR_PAYTYPE_ADDED'), postRequestElement('pay_name'));
131 SQL_FREERESULT($result);
133 // Entry does already exists
134 $message = sprintf(getMessage('ADMIN_SPONSOR_PAYTYPE_ALREADY'), postRequestElement('pay_name'));
138 loadTemplate('admin_settings_saved', false, $message);
139 } elseif ((isPostRequestElementSet('edit')) || (isPostRequestElementSet('del'))) {
142 foreach (postRequestElement('id') as $id => $sel) {
144 $result = SQL_QUERY_ESC("SELECT `pay_name`, `pay_rate`, `pay_min_count`, `pay_currency` FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes` WHERE `id`='%s' LIMIT 1",
145 array(bigintval($id)), __FILE__, __LINE__);
146 if (SQL_NUMROWS($result) == 1) {
148 list($name, $rate, $min, $curr) = SQL_FETCHROW($result);
149 SQL_FREERESULT($result);
151 // Transfer data to array
153 'id' => bigintval($id),
154 'sw' => bigintval($SW),
155 'name' => htmlspecialchars($name),
156 'rate' => translateComma($rate),
157 'min' => bigintval($min),
158 'curr' => htmlspecialchars($curr)
161 if (isPostRequestElementSet('edit')) {
163 $OUT .= loadTemplate('admin_list_sponsor_pay_edit_row', true, $content);
166 $OUT .= loadTemplate('admin_list_sponsor_pay_del_row', true, $content);
170 $OUT .= loadTemplate('admin_list_sponsor_pay_404', true, $id);
177 // Load main template depending on mode (edit/delete)
178 if (isPostRequestElementSet('edit')) {
179 // Load main edit template
180 loadTemplate('admin_list_sponsor_pay_edit', false, $OUT);
182 // Load main delete template
183 loadTemplate('admin_list_sponsor_pay_del', false, $OUT);
186 // Load all payment types
187 $result = SQL_QUERY("SELECT `id`, `pay_name`, `pay_rate`, `pay_min_count`, `pay_currency` FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes` ORDER BY `pay_name` ASC",
190 // Do we have some paytypes setup?
191 if (SQL_NUMROWS($result) > 0) {
192 // Prepare variables for listing
195 // List alle found payment types
196 while ($content = SQL_FETCHARRAY($result)) {
197 // Remember data in array
200 'id' => $content['id'],
201 'name' => $content['pay_name'],
202 'rate' => translateComma($content['pay_rate']),
203 'min' => $content['pay_min_count'],
204 'currency' => $content['pay_currency']
208 $OUT .= loadTemplate('admin_list_sponsor_pay_row', true, $content);
215 SQL_FREERESULT($result);
217 // Load list template
218 $content['list_out'] = loadTemplate('admin_list_sponsor_pay', true, $OUT);
220 // Noting setup so far!
221 $content['list_out'] = loadTemplate('admin_settings_saved', true, getMessage('ADMIN_SPONSOR_NO_PAYTYPES'));
224 // Add new payment types here
225 $content['add_out'] = loadTemplate('admin_add_sponsor_paytype', true);
227 // Load final template
228 loadTemplate('admin_sponsor_paytypes', false, $content);