587fc0580522e824dbeaf5c8c048ba0186f93819
[mailer.git] / inc / modules / admin / what-list_sponsor_pay.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 06/10/2005 *
4  * ===============                              Last change: 05/18/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 {
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", basename(__FILE__));
42 $MSG = "";
43
44 if (isset($HTTP_POST_VARS['add']))
45 {
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']);
52 }
53  elseif ((isset($HTTP_POST_VARS['edit'])) || (isset($HTTP_POST_VARS['del'])) || (isset($HTTP_POST_VARS['change'])) || (isset($HTTP_POST_VARS['remove'])))
54 {
55         // Check if at least one entry was selected
56         if (empty($HTTP_POST_VARS['id']))
57         {
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']);
63         }
64          elseif (isset($HTTP_POST_VARS['change']))
65         {
66                 // Change entries here...
67                 foreach ($HTTP_POST_VARS['id'] as $id=>$sel)
68                 {
69                         // Secure ID
70                         $id = bigintval($id);
71
72                         // Save entry
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),
76  __FILE__, __LINE__);
77                 }
78
79                 // Generate message
80                 $MSG = SPONSOR_PAY_ENTRIES_CHANGED;
81         }
82          elseif (isset($HTTP_POST_VARS['remove']))
83         {
84                 // Remove entries here...
85                 foreach ($HTTP_POST_VARS['id'] as $id=>$sel)
86                 {
87                         // Remove entry
88                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_sponsor_paytypes WHERE id='%s' LIMIT 1",
89  array(bigintval($id)), __FILE__, __LINE__);
90                 }
91
92                 // Generate message
93                 $MSG = SPONSOR_PAY_ENTRIES_REMOVED;
94         }
95
96         if (!empty($MSG))
97         {
98                 // Output message
99                 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
100                 OUTPUT_HTML("<BR>");
101         }
102 }
103
104 if (isset($HTTP_POST_VARS['add']))
105 {
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)
110         {
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'])),
115  __FILE__, __LINE__);
116
117                 // Payment type added!
118                 $MSG = SPONSOR_ADMIN_PAYTYPE_ADDED_1.$HTTP_POST_VARS['pay_name'].SPONSOR_ADMIN_PAYTYPE_ADDED_2;
119         }
120          else
121         {
122                 // Free memory
123                 SQL_FREERESULT($result);
124
125                 // Entry does already exists
126                 $MSG = SPONSOR_ADMIN_PAYTYPE_ALREADY_1.$HTTP_POST_VARS['pay_name'].SPONSOR_ADMIN_PAYTYPE_ALREADY_2;
127         }
128
129         // Output message
130         LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
131         OUTPUT_HTML("<BR>");
132 }
133  elseif ((isset($HTTP_POST_VARS['edit'])) || (isset($HTTP_POST_VARS['del'])))
134 {
135         // Load all data
136         $OUT = ""; $SW = 2;
137         foreach ($HTTP_POST_VARS['id'] as $id=>$sel)
138         {
139                 // Load entry
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)
143                 {
144                         // Load data
145                         list($name, $rate, $min, $curr) = SQL_FETCHROW($result);
146                         SQL_FREERESULT($result);
147
148                         // Transfer data to array
149                         $content = 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)
156                         );
157
158                         if (isset($HTTP_POST_VARS['edit']))
159                         {
160                                 // Edit entry
161                                 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_edit_row", true, $content);
162                         }
163                          else
164                         {
165                                 // Delete entry
166                                 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_del_row", true, $content);
167                         }
168                 }
169                  else
170                 {
171                         // Entry invalid
172                         $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_404", true, $id);
173                 }
174
175                 // Switch colors
176                 $SW = 3 - $SW;
177         }
178
179         // Remember content in constant
180         define('__SPONSOR_ROWS', $OUT);
181
182         // Load main template depending on mode (edit/delete)
183         if (isset($HTTP_POST_VARS['edit']))
184         {
185                 // Load main edit template
186                 LOAD_TEMPLATE("admin_list_sponsor_pay_edit");
187         }
188          else
189         {
190                 // Load main delete template
191                 LOAD_TEMPLATE("admin_list_sponsor_pay_del");
192         }
193 }
194  else
195 {
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",
198          __FILE__, __LINE__);
199
200         // Do we have some paytypes setup?
201         if (SQL_NUMROWS($result) > 0)
202         {
203                 // Prepare variables for listing
204                 $SW = 2; $OUT = "";
205
206                 // List alle found payment types
207                 while(list($id, $name, $rate, $min, $currency) = SQL_FETCHROW($result))
208                 {
209                         // Remember data in array
210                         $content = array(
211                                 'sw'       => $SW,
212                                 'id'       => $id,
213                                 'name'     => $name,
214                                 'rate'     => TRANSLATE_COMMA($rate),
215                                 'min'      => $min,
216                                 'currency' => $currency
217                         );
218
219                         // Add row
220                         $OUT .= LOAD_TEMPLATE("admin_list_sponsor_pay_row", true, $content);
221
222                         // Switch colors
223                         $SW = 3 - $SW;
224                 }
225
226                 // Free memory
227                 SQL_FREERESULT($result);
228
229                 // Remember rows in constant for the template
230                 define('__LIST_ROWS', $OUT);
231
232                 // Load list template
233                 define('__LIST_CONTENT', LOAD_TEMPLATE("admin_list_sponsor_pay", true));
234         }
235          else
236         {
237                 // Noting setup so far!
238                 define('__LIST_CONTENT', LOAD_TEMPLATE("admin_settings_saved", true, SPONSOR_ADMIN_NO_PAYTYPES));
239         }
240
241         // Add new payment types here
242         define('__ADD_CONTENT', LOAD_TEMPLATE("admin_add_sponsor_paytype", true));
243
244         // Load final template
245         LOAD_TEMPLATE("admin_sponsor_paytypes");
246 }
247
248 //
249 ?>