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