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