Huge script change, see http://forum.mxchange.org/topic-458.html for details:
[mailer.git] / inc / modules / admin / what-payments.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  * 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 }
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 if (((!isPostRequestElementSet(('t_wait'))) || (!isPostRequestElementSet(('payment')))) && (isGetRequestElementSet('do')) && (getRequestElement('do') == 'add')) {
48         unsetPostRequestElement('ok');
49 }
50
51 if (isFormSent()) {
52         switch (getRequestElement('do')) {
53                 case 'add':
54                         addSql("INSERT INTO `{?_MYSQL_PREFIX?}_payments` (time, payment, mail_title, price) VALUES ('".postRequestElement('t_wait')."','".postRequestElement('payment')."','".postRequestElement('title')."','".postRequestElement('price')."')");
55                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_payments` WHERE time='%s' LIMIT 1",
56                         array(postRequestElement('t_wait')), __FILE__, __LINE__);
57                         if (SQL_NUMROWS($result) == 1) {
58                                 // Re-init the array here
59                                 initSqls();
60
61                                 // Free memory
62                                 SQL_FREERESULT($result);
63                         }
64                         break;
65
66                 case 'edit':
67                         foreach (postRequestElement('time') as $id => $value) {
68                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_payments` SET time='".$value."', payment='".postRequestElement('pay', $id)."', price='".postRequestElement('price', $id)."', mail_title='".postRequestElement('title', $id)."' WHERE `id`='".$id."' LIMIT 1");
69                         }
70                         break;
71
72                 case 'del':
73                         foreach (postRequestElement('id') as $id => $value) {
74                                 addSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`='".$id."' LIMIT 1");
75                         }
76                         break;
77         }
78
79         // Save settings
80         if (countSqls() > 0) {
81                 // Run all queries
82                 runFilterChain('run_sqls');
83                 $content = "<span class=\"admin_failed\">".SETTINGS_SAVED."</span>";
84         } else {
85                 // Nothing has changed!
86                 $content = "<span class=\"admin_failed\">{--SETTINGS_NOT_SAVED--}</span>";
87         }
88
89         // Output template
90         loadTemplate('admin_settings_saved', false, $content);
91 } elseif ((isPostRequestElementSet('del')) && (countPostSelection() > 0)) {
92         // Delete entries here
93         $OUT = ''; $SW = 2;
94         foreach (postRequestElement('sel') as $id => $value) {
95                 $result = SQL_QUERY_ESC("SELECT time, mail_title FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1",
96                 array(bigintval($id)), __FILE__, __LINE__);
97                 list($time, $title) = SQL_FETCHROW($result);
98                 SQL_FREERESULT($result);
99
100                 // Prepare array for the row template
101                 $content = array(
102                         'sw'    => $SW,
103                         'id'    => $id,
104                         'time'  => $time,
105                         'title' => $title,
106                 );
107
108                 // Load row template and switch colors
109                 $OUT .= loadTemplate('admin_del_payments_row', true, $content);
110                 $SW = 3 - $SW;
111         }
112
113         // Load main template
114         loadTemplate('admin_del_payments', false, $OUT);
115 } elseif ((isPostRequestElementSet('edit')) && (countPostSelection() > 0)) {
116         // Edit entries
117         $OUT = ''; $SW = 2;
118         foreach (postRequestElement('sel') as $id => $value) {
119                 $result = SQL_QUERY_ESC("SELECT time, payment, mail_title, price FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1",
120                 array(bigintval($id)), __FILE__, __LINE__);
121                 list($time, $pay, $title, $price) = SQL_FETCHROW($result);
122                 SQL_FREERESULT($result);
123
124                 // Prepare array for the row template
125                 $content = array(
126                         'sw'    => $SW,
127                         'id'    => $id,
128                         'time'  => $time,
129                         'title' => $title,
130                         'pay'   => $pay,
131                         'price' => $price,
132                 );
133
134                 // Load row template and switch colors
135                 $OUT .= loadTemplate('admin_edit_payments_row', true, $content);
136                 $SW = 3 - $SW;
137         }
138
139         // Load main template
140         loadTemplate('admin_edit_payments', false, $OUT);
141 } else {
142         // Referal levels
143         $result = SQL_QUERY("SELECT id, time, payment, mail_title, price FROM `{?_MYSQL_PREFIX?}_payments` ORDER BY time", __FILE__, __LINE__);
144         if (SQL_NUMROWS($result) > 0) {
145                 // Make referal levels editable and deletable
146                 $OUT = ''; $SW = 2;
147
148                 // List already existing categories for editing
149                 while ($content = SQL_FETCHARRAY($result)) {
150                         // Prepare array for the row template
151                         // @TODO Rewritings: title->mail_title, pay->payment in template
152                         $content = array(
153                                 'sw'    => $SW,
154                                 'id'    => $content['id'],
155                                 'time'  => $content['time'],
156                                 'title' => $content['mail_title'],
157                                 'pay'   => translateComma($content['payment']),
158                                 'price' => translateComma($content['price'])
159                         );
160
161                         // Load row template and switch colors
162                         $OUT .= loadTemplate('admin_payments_list_row', true, $content);
163                         $SW = 3 - $SW;
164                 }
165
166                 // Free memory
167                 SQL_FREERESULT($result);
168
169                 // Load main template
170                 loadTemplate('admin_list_payments', false, $OUT);
171         }
172
173         // Form for adding new referal levels
174         loadTemplate('admin_add_payment');
175 }
176
177 // [EOF]
178 ?>