Huge script change, see http://forum.mxchange.org/topic-458.html for details:
[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  * $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  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 } // END - if
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 $message = '';
48
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');
53
54         setRequestPostElement('pay_min_count', bigintval(postRequestElement('pay_min_count')));
55
56         if ((postRequestElement('pay_min_count') == 0) || (!isPostRequestElementSet('pay_min_count'))) unsetPostRequestElement('add');
57         if (!isPostRequestElementSet('pay_currency')) unsetPostRequestElement('add');
58
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) {
70                         // Secure ID
71                         $id = bigintval($id);
72
73                         // Save entry
74                         SQL_QUERY_ESC("UPDATE
75         `{?_MYSQL_PREFIX?}_sponsor_paytypes`
76 SET
77         `pay_name`='%s',
78         `pay_rate`='%s',
79         `pay_min_count`='%s',
80         `pay_currency`='%s'
81 WHERE
82         `id`='%s'
83 LIMIT 1",
84                         array(
85                                 postRequestElement('name', $id),
86                                 postRequestElement('rate', $id),
87                                 bigintval(postRequestElement('min', $id)),
88                                 postRequestElement('curr', $id),
89                                 $id
90                         ), __FILE__, __LINE__);
91                 }
92
93                 // Generate message
94                 $message = getMessage('SPONSOR_PAY_ENTRIES_CHANGED');
95         } elseif (isPostRequestElementSet('remove')) {
96                 // Remove entries here...
97                 foreach (postRequestElement('id') as $id => $sel) {
98                         // Remove entry
99                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes` WHERE `id`='%s' LIMIT 1",
100                                 array(bigintval($id)), __FILE__, __LINE__);
101                 }
102
103                 // Generate message
104                 $message = getMessage('SPONSOR_PAY_ENTRIES_REMOVED');
105         }
106
107         if (!empty($message)) {
108                 // Output message
109                 loadTemplate('admin_settings_saved', false, $message);
110         } // END - if
111 }
112
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')",
120                         array(
121                                 postRequestElement('pay_name'),
122                                 convertCommaToDot(postRequestElement('pay_rate')),
123                                 bigintval(postRequestElement('pay_min_count')),
124                                 postRequestElement('pay_currency')
125                         ), __FILE__, __LINE__);
126
127                 // Payment type added!
128                 $message = sprintf(getMessage('ADMIN_SPONSOR_PAYTYPE_ADDED'), postRequestElement('pay_name'));
129         } else {
130                 // Free memory
131                 SQL_FREERESULT($result);
132
133                 // Entry does already exists
134                 $message = sprintf(getMessage('ADMIN_SPONSOR_PAYTYPE_ALREADY'), postRequestElement('pay_name'));
135         }
136
137         // Output message
138         loadTemplate('admin_settings_saved', false, $message);
139 } elseif ((isPostRequestElementSet('edit')) || (isPostRequestElementSet('del'))) {
140         // Load all data
141         $OUT = ''; $SW = 2;
142         foreach (postRequestElement('id') as $id => $sel) {
143                 // Load entry
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) {
147                         // Load data
148                         list($name, $rate, $min, $curr) = SQL_FETCHROW($result);
149                         SQL_FREERESULT($result);
150
151                         // Transfer data to array
152                         $content = 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)
159                         );
160
161                         if (isPostRequestElementSet('edit')) {
162                                 // Edit entry
163                                 $OUT .= loadTemplate('admin_list_sponsor_pay_edit_row', true, $content);
164                         } else {
165                                 // Delete entry
166                                 $OUT .= loadTemplate('admin_list_sponsor_pay_del_row', true, $content);
167                         }
168                 } else {
169                         // Entry invalid
170                         $OUT .= loadTemplate('admin_list_sponsor_pay_404', true, $id);
171                 }
172
173                 // Switch colors
174                 $SW = 3 - $SW;
175         } // END - foreach
176
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);
181         } else {
182                 // Load main delete template
183                 loadTemplate('admin_list_sponsor_pay_del', false, $OUT);
184         }
185 } else {
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",
188         __FILE__, __LINE__);
189
190         // Do we have some paytypes setup?
191         if (SQL_NUMROWS($result) > 0) {
192                 // Prepare variables for listing
193                 $OUT = ''; $SW = 2;
194
195                 // List alle found payment types
196                 while ($content = SQL_FETCHARRAY($result)) {
197                         // Remember data in array
198                         $content = array(
199                                 'sw'       => $SW,
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']
205                         );
206
207                         // Add row
208                         $OUT .= loadTemplate('admin_list_sponsor_pay_row', true, $content);
209
210                         // Switch colors
211                         $SW = 3 - $SW;
212                 } // END - while
213
214                 // Free memory
215                 SQL_FREERESULT($result);
216
217                 // Load list template
218                 $content['list_out'] = loadTemplate('admin_list_sponsor_pay', true, $OUT);
219         } else {
220                 // Noting setup so far!
221                 $content['list_out'] = loadTemplate('admin_settings_saved', true, getMessage('ADMIN_SPONSOR_NO_PAYTYPES'));
222         }
223
224         // Add new payment types here
225         $content['add_out'] = loadTemplate('admin_add_sponsor_paytype', true);
226
227         // Load final template
228         loadTemplate('admin_sponsor_paytypes', false, $content);
229 }
230
231 // [EOF]
232 ?>