75dea69fb2d7431f5321fd923c246d5dcdcbb86b
[mailer.git] / inc / modules / admin / what-list_sponsor_pay.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 $message = '';
49
50 if (isFormSent('add')) {
51         // Check input variables
52         if (!isPostRequestParameterSet('pay_name')) unsetPostRequestParameter('add');
53         if ((round(postRequestParameter('pay_rate')) == 0) || (!isPostRequestParameterSet('pay_rate'))) unsetPostRequestParameter('add');
54
55         setPostRequestParameter('pay_min_count', bigintval(postRequestParameter('pay_min_count')));
56
57         if ((postRequestParameter('pay_min_count') == '0') || (!isPostRequestParameterSet('pay_min_count'))) unsetPostRequestParameter('add');
58         if (!isPostRequestParameterSet('pay_currency')) unsetPostRequestParameter('add');
59
60 } elseif ((isFormSent('edit')) || (isFormSent('del')) || (isFormSent('change')) || (isFormSent('remove'))) {
61         // Check if at least one entry was selected
62         if (!isPostRequestParameterSet('id')) {
63                 // Nothing selected for editing / deleting???
64                 unsetPostRequestParameter('edit');
65                 unsetPostRequestParameter('del');
66                 unsetPostRequestParameter('change');
67                 unsetPostRequestParameter('remove');
68         } elseif (isFormSent('change')) {
69                 // Change entries here...
70                 foreach (postRequestParameter('id') as $id => $sel) {
71                         // Secure id
72                         $id = bigintval($id);
73
74                         // Save entry
75                         SQL_QUERY_ESC("UPDATE
76         `{?_MYSQL_PREFIX?}_sponsor_paytypes`
77 SET
78         `pay_name`='%s',
79         `pay_rate`='%s',
80         `pay_min_count`='%s',
81         `pay_currency`='%s'
82 WHERE
83         `id`=%s
84 LIMIT 1",
85                         array(
86                                 postRequestParameter('name', $id),
87                                 postRequestParameter('rate', $id),
88                                 bigintval(postRequestParameter('min', $id)),
89                                 postRequestParameter('curr', $id),
90                                 $id
91                         ), __FILE__, __LINE__);
92                 }
93
94                 // Generate message
95                 $message = '{--SPONSOR_PAY_ENTRIES_CHANGED--}';
96         } elseif (isFormSent('remove')) {
97                 // Remove entries here...
98                 foreach (postRequestParameter('id') as $id => $sel) {
99                         // Remove entry
100                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes` WHERE `id`=%s LIMIT 1",
101                                 array(bigintval($id)), __FILE__, __LINE__);
102                 }
103
104                 // Generate message
105                 $message = '{--SPONSOR_PAY_ENTRIES_REMOVED--}';
106         }
107
108         if (!empty($message)) {
109                 // Output message
110                 loadTemplate('admin_settings_saved', false, $message);
111         } // END - if
112 }
113
114 if (isFormSent('add')) {
115         // Check if entry with same name does exists
116         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes` WHERE `pay_name`='%s' LIMIT 1",
117                 array(postRequestParameter('pay_name')), __FILE__, __LINE__);
118         if (SQL_HASZERONUMS($result)) {
119                 // No entry found so add this line
120                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_paytypes` (`pay_name`, `pay_rate`, `pay_min_count`, `pay_currency`) VALUES ('%s','%s','%s','%s')",
121                         array(
122                                 postRequestParameter('pay_name'),
123                                 convertCommaToDot(postRequestParameter('pay_rate')),
124                                 bigintval(postRequestParameter('pay_min_count')),
125                                 postRequestParameter('pay_currency')
126                         ), __FILE__, __LINE__);
127
128                 // Payment type added!
129                 $message = getMaskedMessage('ADMIN_SPONSOR_PAYTYPE_ADDED', postRequestParameter('pay_name'));
130         } else {
131                 // Entry does already exists
132                 $message = getMaskedMessage('ADMIN_SPONSOR_PAYTYPE_ALREADY', postRequestParameter('pay_name'));
133         }
134
135         // Free memory
136         SQL_FREERESULT($result);
137
138         // Output message
139         loadTemplate('admin_settings_saved', false, $message);
140 } elseif ((isFormSent('edit')) || (isFormSent('del'))) {
141         // Load all data
142         $OUT = '';
143         foreach (postRequestParameter('id') as $id => $sel) {
144                 // Load entry
145                 $result = SQL_QUERY_ESC("SELECT `id`, `pay_name`, `pay_rate`, `pay_min_count`, `pay_currency` FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes` WHERE `id`=%s LIMIT 1",
146                         array(bigintval($id)), __FILE__, __LINE__);
147                 if (SQL_NUMROWS($result) == 1) {
148                         // Load data
149                         $content = SQL_FETCHARRAY($result);
150
151                         if (isFormSent('edit')) {
152                                 // Edit entry
153                                 $OUT .= loadTemplate('admin_list_sponsor_pay_edit_row', true, $content);
154                         } else {
155                                 // Delete entry
156                                 $OUT .= loadTemplate('admin_list_sponsor_pay_del_row', true, $content);
157                         }
158                 } else {
159                         // Entry invalid
160                         $OUT .= loadTemplate('admin_list_sponsor_pay_404', true, $id);
161                 }
162
163                 // Free result
164                 SQL_FREERESULT($result);
165         } // END - foreach
166
167         // Load main template depending on mode (edit/delete)
168         if (isFormSent('edit')) {
169                 // Load main edit template
170                 loadTemplate('admin_list_sponsor_pay_edit', false, $OUT);
171         } else {
172                 // Load main delete template
173                 loadTemplate('admin_list_sponsor_pay_del', false, $OUT);
174         }
175 } else {
176         // Load all payment types
177         $result = SQL_QUERY("SELECT
178         `id`, `pay_name`, `pay_rate`, `pay_min_count`, `pay_currency`
179 FROM
180         `{?_MYSQL_PREFIX?}_sponsor_paytypes`
181 ORDER BY
182         `pay_name` ASC",
183                 __FILE__, __LINE__);
184
185         // Do we have some paytypes setup?
186         if (!SQL_HASZERONUMS($result)) {
187                 // Prepare variables for listing
188                 $OUT = '';
189
190                 // List alle found payment types
191                 while ($content = SQL_FETCHARRAY($result)) {
192                         // Add row
193                         $OUT .= loadTemplate('admin_list_sponsor_pay_row', true, $content);
194                 } // END - while
195
196                 // Load list template
197                 $content['list_out'] = loadTemplate('admin_list_sponsor_pay', true, $OUT);
198         } else {
199                 // Noting setup so far!
200                 $content['list_out'] = loadTemplate('admin_settings_saved', true, '{--ADMIN_SPONSOR_NO_PAYTYPES--}');
201         }
202
203         // Free memory
204         SQL_FREERESULT($result);
205
206         // Add new payment types here
207         $content['add_out'] = loadTemplate('admin_add_sponsor_paytype', true);
208
209         // Load final template
210         loadTemplate('admin_sponsor_paytypes', false, $content);
211 }
212
213 // [EOF]
214 ?>