Fixes for stripped HTML tags, and false warnings in debug log
[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 bestaetigte Mails              *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 if (((!REQUEST_ISSET_POST(('t_wait'))) || (!REQUEST_ISSET_POST(('payment')))) && (REQUEST_ISSET_GET(('do'))) && (REQUEST_GET('do') == "add")) {
44         REQUEST_UNSET_POST('ok');
45 }
46
47 if (IS_FORM_SENT()) {
48         $SQL = array();
49         switch (REQUEST_GET('do')) {
50         case "add":
51                 $SQLs[] = "INSERT INTO `{!_MYSQL_PREFIX!}_payments` (time, payment, mail_title, price) VALUES ('".REQUEST_POST('t_wait')."','".REQUEST_POST('payment')."','".REQUEST_POST('title')."','".REQUEST_POST('price')."')";
52                 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_payments` WHERE time='%s' LIMIT 1",
53                  array(REQUEST_POST('t_wait')), __FILE__, __LINE__);
54                 if (SQL_NUMROWS($result) == 1) {
55                         // Free memory
56                         $SQLs[0] = "";
57                         SQL_FREERESULT($result);
58                 }
59                 break;
60
61         case "edit":
62                 foreach (REQUEST_POST('time') as $id => $value) {
63                         $SQLs[] = "UPDATE `{!_MYSQL_PREFIX!}_payments` SET time='".$value."', payment='".REQUEST_POST('pay', $id)."', price='".REQUEST_POST('price', $id)."', mail_title='".REQUEST_POST('title', $id)."' WHERE id='".$id."' LIMIT 1";
64                 }
65                 break;
66
67         case "del":
68                 foreach (REQUEST_POST('id') as $id => $value) {
69                         $SQLs[] = "DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_payments` WHERE id='".$id."' LIMIT 1";
70                 }
71                 break;
72         }
73
74         // Save settings
75         if (count($SQLs) > 0) {
76                 // Run all queries
77                 RUN_FILTER('run_sqls', array('dry_run' => false, 'sqls' => $SQLs));
78                 $content = "<span class=\"admin_failed\">".SETTINGS_SAVED."</span>";
79         } else {
80                 // Nothing has changed!
81                 $content = "<span class=\"admin_failed\">{--SETTINGS_NOT_SAVED--}</span>";
82         }
83
84         // Output template
85         LOAD_TEMPLATE("admin_settings_saved", false, $content);
86 } elseif ((REQUEST_ISSET_POST(('del'))) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
87         // Delete entries here
88         $SW = 2; $OUT = "";
89         foreach (REQUEST_POST('sel') as $id => $value) {
90                 $result = SQL_QUERY_ESC("SELECT time, mail_title FROM `{!_MYSQL_PREFIX!}_payments` WHERE id=%s LIMIT 1",
91                         array(bigintval($id)), __FILE__, __LINE__);
92                 list($time, $title) = SQL_FETCHROW($result);
93                 SQL_FREERESULT($result);
94
95                 // Prepare array for the row template
96                 $content = array(
97                         'sw'    => $SW,
98                         'id'    => $id,
99                         'time'  => $time,
100                         'title' => $title,
101                 );
102
103                 // Load row template and switch colors
104                 $OUT .= LOAD_TEMPLATE("admin_del_payments_row", true, $content);
105                 $SW = 3 - $SW;
106         }
107         define('__PAYMENT_ROWS', $OUT);
108
109         // Load main template
110         LOAD_TEMPLATE("admin_del_payments");
111 } elseif ((REQUEST_ISSET_POST(('edit'))) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
112         // Edit entries
113         $SW = 2; $OUT = "";
114         foreach (REQUEST_POST('sel') as $id => $value) {
115                 $result = SQL_QUERY_ESC("SELECT time, payment, mail_title, price FROM `{!_MYSQL_PREFIX!}_payments` WHERE id=%s LIMIT 1",
116                  array(bigintval($id)), __FILE__, __LINE__);
117                 list($time, $pay, $title, $price) = SQL_FETCHROW($result);
118                 SQL_FREERESULT($result);
119
120                 // Prepare array for the row template
121                 $content = array(
122                         'sw'    => $SW,
123                         'id'    => $id,
124                         'time'  => $time,
125                         'title' => $title,
126                         'pay'   => $pay,
127                         'price' => $price,
128                 );
129
130                 // Load row template and switch colors
131                 $OUT .= LOAD_TEMPLATE("admin_edit_payments_row", true, $content);
132                 $SW = 3 - $SW;
133         }
134         define('__PAYMENT_ROWS', $OUT);
135
136         // Load main template
137         LOAD_TEMPLATE("admin_edit_payments");
138 } else {
139         // Referal levels
140         $result = SQL_QUERY("SELECT id, time, payment, mail_title, price FROM `{!_MYSQL_PREFIX!}_payments` ORDER BY time", __FILE__, __LINE__);
141         if (SQL_NUMROWS($result) > 0) {
142                 // Make referal levels editable and deletable
143                 $SW = 2; $OUT = "";
144
145                 // List already existing categories for editing
146                 while (list($id, $time, $pay, $title, $price) = SQL_FETCHROW($result)) {
147                         $pay   = TRANSLATE_COMMA($pay);
148                         $price = TRANSLATE_COMMA($price);
149
150                         // Prepare array for the row template
151                         $content = array(
152                                 'sw'    => $SW,
153                                 'id'    => $id,
154                                 'time'  => $time,
155                                 'title' => $title,
156                                 'pay'   => $pay,
157                                 'price' => $price,
158                         );
159
160                         // Load row template and switch colors
161                         $OUT .= LOAD_TEMPLATE("admin_payments_list_row", true, $content);
162                         $SW = 3 - $SW;
163                 }
164
165                 // Free memory
166                 SQL_FREERESULT($result);
167                 define('__PAYMENT_ROWS', $OUT);
168
169                 // Load main template
170                 LOAD_TEMPLATE("admin_list_payments");
171         }
172
173         // Form for adding new referal levels
174         LOAD_TEMPLATE("admin_add_payment");
175 }
176
177 //
178 ?>