All database names are now 'back-ticked' and constant _MYSQL_PREFIX is wrapped. Partl...
[mailer.git] / inc / modules / admin / what-list_sponsor_pay.php
1 <?php
2 /************************************************************************
3  * M-XChange v0.2.1                                   Start: 06/10/2005 *
4  * ================                             Last change: 05/19/2008 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
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.                                  *
22  *                                                                      *
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.                         *
27  *                                                                      *
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,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 $MSG = "";
44
45 if (isset($_POST['add'])) {
46         // Check input variables
47         if (empty($_POST['pay_name'])) unset($_POST['add']);
48         if ((round($_POST['pay_rate']) == 0) || (empty($_POST['pay_rate']))) unset($_POST['add']);
49         $_POST['pay_min_count'] = bigintval($_POST['pay_min_count']);
50         if (($_POST['pay_min_count'] == 0) || (empty($_POST['pay_min_count']))) unset($_POST['add']);
51         if (empty($_POST['pay_currency'])) unset($_POST['add']);
52 } elseif ((isset($_POST['edit'])) || (isset($_POST['del'])) || (isset($_POST['change'])) || (isset($_POST['remove']))) {
53         // Check if at least one entry was selected
54         if (empty($_POST['id'])) {
55                 // Nothing selected for editing / deleting???
56                 unset($_POST['edit']);
57                 unset($_POST['del']);
58                 unset($_POST['change']);
59                 unset($_POST['remove']);
60         } elseif (isset($_POST['change'])) {
61                 // Change entries here...
62                 foreach ($_POST['id'] as $id => $sel) {
63                         // Secure ID
64                         $id = bigintval($id);
65
66                         // Save entry
67                         SQL_QUERY_ESC("UPDATE `{!MYSQL_PREFIX!}_sponsor_paytypes`
68 SET pay_name='%s', pay_rate='%s', pay_min_count='%s', pay_currency='%s' WHERE id='%s' LIMIT 1",
69  array($_POST['name'][$id], $_POST['rate'][$id], bigintval($_POST['min'][$id]), $_POST['curr'][$id], $id),
70  __FILE__, __LINE__);
71                 }
72
73                 // Generate message
74                 $MSG = SPONSOR_PAY_ENTRIES_CHANGED;
75         } elseif (isset($_POST['remove'])) {
76                 // Remove entries here...
77                 foreach ($_POST['id'] as $id => $sel) {
78                         // Remove entry
79                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!MYSQL_PREFIX!}_sponsor_paytypes` WHERE id='%s' LIMIT 1",
80                                 array(bigintval($id)), __FILE__, __LINE__);
81                 }
82
83                 // Generate message
84                 $MSG = SPONSOR_PAY_ENTRIES_REMOVED;
85         }
86
87         if (!empty($MSG)) {
88                 // Output message
89                 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
90                 OUTPUT_HTML("<br />");
91         }
92 }
93
94 if (isset($_POST['add'])) {
95         // Check if entry with same name does exists
96         $result = SQL_QUERY_ESC("SELECT id FROM `{!MYSQL_PREFIX!}_sponsor_paytypes` WHERE pay_name='%s' LIMIT 1",
97          array($_POST['pay_name']), __FILE__, __LINE__);
98         if (SQL_NUMROWS($result) == 0) {
99                 // No entry found so add this line
100                 SQL_QUERY_ESC("INSERT INTO `{!MYSQL_PREFIX!}_sponsor_paytypes` (pay_name, pay_rate, pay_min_count, pay_currency)
101  VALUES ('%s','%s','%s','%s')",
102  array(htmlspecialchars($_POST['pay_name']), REVERT_COMMA($_POST['pay_rate']), bigintval($_POST['pay_min_count']), htmlspecialchars($_POST['pay_currency'])),
103  __FILE__, __LINE__);
104
105                 // Payment type added!
106                 $MSG = SPONSOR_ADMIN_PAYTYPE_ADDED_1.$_POST['pay_name'].SPONSOR_ADMIN_PAYTYPE_ADDED_2;
107         } else {
108                 // Free memory
109                 SQL_FREERESULT($result);
110
111                 // Entry does already exists
112                 $MSG = SPONSOR_ADMIN_PAYTYPE_ALREADY_1.$_POST['pay_name'].SPONSOR_ADMIN_PAYTYPE_ALREADY_2;
113         }
114
115         // Output message
116         LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
117         OUTPUT_HTML("<br />");
118 } elseif ((isset($_POST['edit'])) || (isset($_POST['del']))) {
119         // Load all data
120         $OUT = ""; $SW = 2;
121         foreach ($_POST['id'] as $id => $sel) {
122                 // Load entry
123                 $result = SQL_QUERY_ESC("SELECT pay_name, pay_rate, pay_min_count, pay_currency FROM `{!MYSQL_PREFIX!}_sponsor_paytypes` WHERE id='%s' LIMIT 1",
124                  array(bigintval($id)), __FILE__, __LINE__);
125                 if (SQL_NUMROWS($result) == 1) {
126                         // Load data
127                         list($name, $rate, $min, $curr) = SQL_FETCHROW($result);
128                         SQL_FREERESULT($result);
129
130                         // Transfer data to array
131                         $content = array(
132                                 'id'   => bigintval($id),
133                                 'sw'   => bigintval($SW),
134                                 'name' => htmlspecialchars($name),
135                                 'rate' => TRANSLATE_COMMA($rate),
136                                 'min'  => bigintval($min),
137                                 'curr' => htmlspecialchars($curr)
138                         );
139
140                         if (isset($_POST['edit'])) {
141                                 // Edit entry
142                                 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_edit_row", true, $content);
143                         } else {
144                                 // Delete entry
145                                 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_del_row", true, $content);
146                         }
147                 } else {
148                         // Entry invalid
149                         $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_404", true, $id);
150                 }
151
152                 // Switch colors
153                 $SW = 3 - $SW;
154         }
155
156         // Remember content in constant
157         define('__SPONSOR_ROWS', $OUT);
158
159         // Load main template depending on mode (edit/delete)
160         if (isset($_POST['edit'])) {
161                 // Load main edit template
162                 LOAD_TEMPLATE("admin_list_sponsor_pay_edit");
163         } else {
164                 // Load main delete template
165                 LOAD_TEMPLATE("admin_list_sponsor_pay_del");
166         }
167 } else {
168         // Load all payment types
169         $result = SQL_QUERY("SELECT id, pay_name, pay_rate, pay_min_count, pay_currency FROM `{!MYSQL_PREFIX!}_sponsor_paytypes` ORDER BY pay_name",
170          __FILE__, __LINE__);
171
172         // Do we have some paytypes setup?
173         if (SQL_NUMROWS($result) > 0) {
174                 // Prepare variables for listing
175                 $SW = 2; $OUT = "";
176
177                 // List alle found payment types
178                 while(list($id, $name, $rate, $min, $currency) = SQL_FETCHROW($result)) {
179                         // Remember data in array
180                         $content = array(
181                                 'sw'       => $SW,
182                                 'id'       => $id,
183                                 'name'     => $name,
184                                 'rate'     => TRANSLATE_COMMA($rate),
185                                 'min'      => $min,
186                                 'currency' => $currency
187                         );
188
189                         // Add row
190                         $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_row", true, $content);
191
192                         // Switch colors
193                         $SW = 3 - $SW;
194                 }
195
196                 // Free memory
197                 SQL_FREERESULT($result);
198
199                 // Remember rows in constant for the template
200                 define('__LIST_ROWS', $OUT);
201
202                 // Load list template
203                 define('__LIST_CONTENT', LOAD_TEMPLATE("admin_list_sponsor_pay", true));
204         } else {
205                 // Noting setup so far!
206                 define('__LIST_CONTENT', LOAD_TEMPLATE("admin_settings_saved", true, SPONSOR_ADMIN_NO_PAYTYPES));
207         }
208
209         // Add new payment types here
210         define('__ADD_CONTENT', LOAD_TEMPLATE("admin_add_sponsor_paytype", true));
211
212         // Load final template
213         LOAD_TEMPLATE("admin_sponsor_paytypes");
214 }
215
216 //
217 ?>