Updated copyright notice as there are changes in this year
[mailer.git] / inc / modules / admin / what-payments.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/19/2003 *
4  * ===================                          Last change: 12/12/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-payments.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Payments (points) for confirmed mails            *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Verguetungen fuer best&auml;tigte Mails              *
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 - 2013 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 if (((!isPostRequestElementSet('t_wait')) || (!isPostRequestElementSet('payment'))) && (isGetRequestElementSet('do')) && (getRequestElement('do') == 'add')) {
47         unsetPostRequestElement('ok');
48 } // END - if
49
50 // Init SQL array
51 nitSqls();
52
53 if (isFormSent()) {
54         switch (getRequestElement('do')) {
55                 case 'add':
56                         if (countSumTotalData(postRequestElement('t_wait'), 'payments', 'id', 'time', TRUE) == 0) {
57                                 addSql("INSERT INTO
58         `{?_MYSQL_PREFIX?}_payments`
59 (
60         `time`,
61         `payment`,
62         `mail_title`,
63         `price`
64 ) VALUES (
65         '" . postRequestElement('t_wait') . "',
66         '" . postRequestElement('payment') . "',
67         '" . postRequestElement('title') . "',
68         '" . postRequestElement('price') . "'
69 )");
70                         } // END - if
71                         break;
72
73                 case 'edit':
74                         foreach (postRequestElement('time') as $id => $value) {
75                                 // Secure id
76                                 $id = bigintval($id);
77
78                                 // Add UPDATE
79                                 addSql("UPDATE
80         `{?_MYSQL_PREFIX?}_payments`
81 SET
82         `time`='" . $value . "',
83         `payment`='" . postRequestElement('payment', $id) . "',
84         `price`='" . postRequestElement('price', $id) . "',
85         `mail_title`='" . postRequestElement('mail_title', $id) . "'
86 WHERE
87         `id`='" . $id . "'
88 LIMIT 1");
89                         } // END - foreach
90                         break;
91
92                 case 'delete':
93                         foreach (postRequestElement('id') as $id => $value) {
94                                 // Secure id
95                                 $id = bigintval($id);
96
97                                 // Add DELETE
98                                 addSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=" . $id . " LIMIT 1");
99                         } // END - foreach
100                         break;
101         } // END - switch
102
103         // Nothing has changed by default
104         $content = '<span class="bad">{--SETTINGS_NOT_SAVED--}</span>';
105
106         // Save settings
107         if (countSqls() > 0) {
108                 // Run all queries
109                 runFilterChain('run_sqls');
110
111                 // Purge cache
112                 rebuildCache('payments', 'payments');
113
114                 // Change message
115                 $content = '<span class="good">{--SETTINGS_SAVED--}</span>';
116         } // END - if
117
118         // Output template
119         displayMessage($content);
120 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
121         // Delete entries here
122         $OUT = '';
123         foreach (postRequestElement('sel') as $id => $value) {
124                 $result = SQL_QUERY_ESC("SELECT
125         `id`,
126         `time`,
127         `payment`,
128         `mail_title`,
129         `price`
130 FROM
131         `{?_MYSQL_PREFIX?}_payments`
132 WHERE
133         `id`=%s
134 LIMIT 1",
135                         array(bigintval($id)), __FILE__, __LINE__);
136                 $content = SQL_FETCHARRAY($result);
137
138                 // Free result
139                 SQL_FREERESULT($result);
140
141                 // Load row template and switch colors
142                 $OUT .= loadTemplate('admin_delete_payments_row', TRUE, $content);
143         } // END - foreach
144
145         // Load main template
146         loadTemplate('admin_delete_payments', FALSE, $OUT);
147 } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
148         // Edit entries
149         $OUT = '';
150         foreach (postRequestElement('sel') as $id => $value) {
151                 $result = SQL_QUERY_ESC("SELECT
152         `id`,
153         `time`,
154         `payment`,
155         `mail_title`,
156         `price`
157 FROM
158         `{?_MYSQL_PREFIX?}_payments`
159 WHERE
160         `id`=%s
161 LIMIT 1",
162                         array(bigintval($id)), __FILE__, __LINE__);
163                 $content = SQL_FETCHARRAY($result);
164
165                 // Free result
166                 SQL_FREERESULT($result);
167
168                 // Load row template and switch colors
169                 $OUT .= loadTemplate('admin_edit_payments_row', TRUE, $content);
170         } // END - foreach
171
172         // Load main template
173         loadTemplate('admin_edit_payments', FALSE, $OUT);
174 } else {
175         // Referral levels
176         $result = SQL_QUERY("SELECT
177         `id`,
178         `time`,
179         `payment`,
180         `mail_title`,
181         `price`
182 FROM
183         `{?_MYSQL_PREFIX?}_payments`
184 ORDER BY
185         `time` ASC", __FILE__, __LINE__);
186         if (!SQL_HASZERONUMS($result)) {
187                 // Make referral levels editable and deletable
188                 $OUT = '';
189
190                 // List already existing categories for editing
191                 while ($content = SQL_FETCHARRAY($result)) {
192                         // Load row template and switch colors
193                         $OUT .= loadTemplate('admin_list_payments_row', TRUE, $content);
194                 } // END - switch
195
196                 // Free memory
197                 SQL_FREERESULT($result);
198
199                 // Load main template
200                 loadTemplate('admin_list_payments', FALSE, $OUT);
201         } // END - if
202
203         // Form for adding new referral levels
204         loadTemplate('admin_add_payment');
205 }
206
207 // [EOF]
208 ?>