d3a8c4f4b8261bfd1ff2382881f58b2ee8c7192c
[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         switch (REQUEST_GET('do')) {
49         case "add":
50                 ADD_SQL("INSERT INTO `{!_MYSQL_PREFIX!}_payments` (time, payment, mail_title, price) VALUES ('".REQUEST_POST('t_wait')."','".REQUEST_POST('payment')."','".REQUEST_POST('title')."','".REQUEST_POST('price')."')");
51                 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_payments` WHERE time='%s' LIMIT 1",
52                         array(REQUEST_POST('t_wait')), __FILE__, __LINE__);
53                 if (SQL_NUMROWS($result) == 1) {
54                         // Re-init the array here
55                         INIT_SQLS();
56
57                         // Free memory
58                         SQL_FREERESULT($result);
59                 }
60                 break;
61
62         case "edit":
63                 foreach (REQUEST_POST('time') as $id => $value) {
64                         ADD_SQL("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");
65                 }
66                 break;
67
68         case "del":
69                 foreach (REQUEST_POST('id') as $id => $value) {
70                         ADD_SQL("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_payments` WHERE id='".$id."' LIMIT 1");
71                 }
72                 break;
73         }
74
75         // Save settings
76         if (COUNT_SQLS() > 0) {
77                 // Run all queries
78                 RUN_FILTER('run_sqls', array('dry_run' => false));
79                 $content = "<span class=\"admin_failed\">".SETTINGS_SAVED."</span>";
80         } else {
81                 // Nothing has changed!
82                 $content = "<span class=\"admin_failed\">{--SETTINGS_NOT_SAVED--}</span>";
83         }
84
85         // Output template
86         LOAD_TEMPLATE("admin_settings_saved", false, $content);
87 } elseif ((REQUEST_ISSET_POST(('del'))) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
88         // Delete entries here
89         $SW = 2; $OUT = "";
90         foreach (REQUEST_POST('sel') as $id => $value) {
91                 $result = SQL_QUERY_ESC("SELECT time, mail_title FROM `{!_MYSQL_PREFIX!}_payments` WHERE id=%s LIMIT 1",
92                         array(bigintval($id)), __FILE__, __LINE__);
93                 list($time, $title) = SQL_FETCHROW($result);
94                 SQL_FREERESULT($result);
95
96                 // Prepare array for the row template
97                 $content = array(
98                         'sw'    => $SW,
99                         'id'    => $id,
100                         'time'  => $time,
101                         'title' => $title,
102                 );
103
104                 // Load row template and switch colors
105                 $OUT .= LOAD_TEMPLATE("admin_del_payments_row", true, $content);
106                 $SW = 3 - $SW;
107         }
108         define('__PAYMENT_ROWS', $OUT);
109
110         // Load main template
111         LOAD_TEMPLATE("admin_del_payments");
112 } elseif ((REQUEST_ISSET_POST(('edit'))) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
113         // Edit entries
114         $SW = 2; $OUT = "";
115         foreach (REQUEST_POST('sel') as $id => $value) {
116                 $result = SQL_QUERY_ESC("SELECT time, payment, mail_title, price FROM `{!_MYSQL_PREFIX!}_payments` WHERE id=%s LIMIT 1",
117                  array(bigintval($id)), __FILE__, __LINE__);
118                 list($time, $pay, $title, $price) = SQL_FETCHROW($result);
119                 SQL_FREERESULT($result);
120
121                 // Prepare array for the row template
122                 $content = array(
123                         'sw'    => $SW,
124                         'id'    => $id,
125                         'time'  => $time,
126                         'title' => $title,
127                         'pay'   => $pay,
128                         'price' => $price,
129                 );
130
131                 // Load row template and switch colors
132                 $OUT .= LOAD_TEMPLATE("admin_edit_payments_row", true, $content);
133                 $SW = 3 - $SW;
134         }
135         define('__PAYMENT_ROWS', $OUT);
136
137         // Load main template
138         LOAD_TEMPLATE("admin_edit_payments");
139 } else {
140         // Referal levels
141         $result = SQL_QUERY("SELECT id, time, payment, mail_title, price FROM `{!_MYSQL_PREFIX!}_payments` ORDER BY time", __FILE__, __LINE__);
142         if (SQL_NUMROWS($result) > 0) {
143                 // Make referal levels editable and deletable
144                 $SW = 2; $OUT = "";
145
146                 // List already existing categories for editing
147                 while (list($id, $time, $pay, $title, $price) = SQL_FETCHROW($result)) {
148                         $pay   = TRANSLATE_COMMA($pay);
149                         $price = TRANSLATE_COMMA($price);
150
151                         // Prepare array for the row template
152                         $content = array(
153                                 'sw'    => $SW,
154                                 'id'    => $id,
155                                 'time'  => $time,
156                                 'title' => $title,
157                                 'pay'   => $pay,
158                                 'price' => $price,
159                         );
160
161                         // Load row template and switch colors
162                         $OUT .= LOAD_TEMPLATE("admin_payments_list_row", true, $content);
163                         $SW = 3 - $SW;
164                 }
165
166                 // Free memory
167                 SQL_FREERESULT($result);
168                 define('__PAYMENT_ROWS', $OUT);
169
170                 // Load main template
171                 LOAD_TEMPLATE("admin_list_payments");
172         }
173
174         // Form for adding new referal levels
175         LOAD_TEMPLATE("admin_add_payment");
176 }
177
178 //
179 ?>