b78d8b9465996193b526358887fa7ab19d31109f
[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 // Add description as navigation point
40 ADD_DESCR("admin", __FILE__);
41
42 if (empty($_GET['do'])) unset($_GET['do']);
43 if (((empty($_POST['t_wait'])) || (empty($_POST['payment']))) && (!empty($_GET['do'])) && ($_GET['do'] == "add"))
44 {
45         unset($_POST['ok']);
46 }
47
48 if (isset($_POST['ok']))
49 {
50         $SQL = array();
51         switch ($_GET['do'])
52         {
53         case "add":
54                 $SQL[] = "INSERT INTO "._MYSQL_PREFIX."_payments (time, payment, mail_title, price) VALUES ('".$_POST['t_wait']."','".$_POST['payment']."','".$_POST['title']."','".$_POST['price']."')";
55                 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_payments WHERE time='%s' LIMIT 1",
56                  array($_POST['t_wait']), __FILE__, __LINE__);
57                 if (SQL_NUMROWS($result) == 1)
58                 {
59                         // Free memory
60                         $SQL[0] = "";
61                         SQL_FREERESULT($result);
62                 }
63                 break;
64
65         case "edit":
66                 foreach ($_POST['time'] as $id => $value)
67                 {
68                         $SQL[] = "UPDATE "._MYSQL_PREFIX."_payments SET time='".$value."', payment='".$_POST['pay'][$id]."', price='".$_POST['price'][$id]."', mail_title='".$_POST['title'][$id]."' WHERE id='".$id."' LIMIT 1";
69                 }
70                 break;
71
72         case "del":
73                 foreach ($_POST['id'] as $id => $value)
74                 {
75                         $SQL[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_payments WHERE id='".$id."' LIMIT 1";
76                 }
77                 break;
78         }
79         // Daten abspeichern
80         if ((count($SQL) > 0) || (!empty($SQL[0])))
81         {
82                 foreach ($SQL as $s)
83                 {
84                         if (!empty($s))
85                         {
86                                 // Only run non-empty strings
87                                 $result = SQL_QUERY(trim($s), __FILE__, __LINE__);
88                                 if (empty($content))
89                                 {
90                                         if (SQL_AFFECTEDROWS() == 1)
91                                         {
92                                                 $content = "<SPAN class=\"admin_done\">".SETTINGS_SAVED."</SPAN>";
93                                         }
94                                          else
95                                         {
96                                                 $content = "<SPAN class=\"admin_failed\">".SETTINGS_NOT_SAVED."</SPAN>";
97                                         }
98                                 }
99                         }
100                 }
101         }
102          else
103         {
104                 $content = "<SPAN class=\"admin_failed\">".SETTINGS_NOT_SAVED."</SPAN>";
105         }
106         LOAD_TEMPLATE("admin_settings_saved", false, $content);
107 }
108  elseif ((isset($_POST['del'])) && (SELECTION_COUNT($_POST['sel']) > 0))
109 {
110         // Delete entries here
111         $SW = 2; $OUT = "";
112         foreach ($_POST['sel'] as $id => $value)
113         {
114                 $result = SQL_QUERY_ESC("SELECT time, mail_title FROM "._MYSQL_PREFIX."_payments WHERE id=%s LIMIT 1",
115                  array(bigintval($id)), __FILE__, __LINE__);
116                 list($time, $title) = SQL_FETCHROW($result);
117                 SQL_FREERESULT($result);
118
119                 // Prepare array for the row template
120                 $content = array(
121                         'sw'    => $SW,
122                         'id'    => $id,
123                         'time'  => $time,
124                         'title' => $title,
125                 );
126
127                 // Load row template and switch colors
128                 $OUT .= LOAD_TEMPLATE("admin_del_payments_row", true, $content);
129                 $SW = 3 - $SW;
130         }
131         define('__PAYMENT_ROWS', $OUT);
132
133         // Load main template
134         LOAD_TEMPLATE("admin_del_payments");
135 }
136  elseif ((isset($_POST['edit'])) && (SELECTION_COUNT($_POST['sel']) > 0))
137 {
138         // Edit entries
139         $SW = 2; $OUT = "";
140         foreach ($_POST['sel'] as $id => $value)
141         {
142                 $result = SQL_QUERY_ESC("SELECT time, payment, mail_title, price FROM "._MYSQL_PREFIX."_payments WHERE id=%s LIMIT 1",
143                  array(bigintval($id)), __FILE__, __LINE__);
144                 list($time, $pay, $title, $price) = SQL_FETCHROW($result);
145                 SQL_FREERESULT($result);
146
147                 // Prepare array for the row template
148                 $content = array(
149                         'sw'    => $SW,
150                         'id'    => $id,
151                         'time'  => $time,
152                         'title' => $title,
153                         'pay'   => $pay,
154                         'price' => $price,
155                 );
156
157                 // Load row template and switch colors
158                 $OUT .= LOAD_TEMPLATE("admin_edit_payments_row", true, $content);
159                 $SW = 3 - $SW;
160         }
161         define('__PAYMENT_ROWS', $OUT);
162
163         // Load main template
164         LOAD_TEMPLATE("admin_edit_payments");
165 }
166  else
167 {
168         // Referal levels
169         $result = SQL_QUERY("SELECT id, time, payment, mail_title, price FROM "._MYSQL_PREFIX."_payments ORDER BY time", __FILE__, __LINE__);
170         if (SQL_NUMROWS($result) > 0)
171         {
172                 // Make referal levels editable and deletable
173                 $SW = 2; $OUT = "";
174
175                 // List already existing categories for editing
176                 while (list($id, $time, $pay, $title, $price) = SQL_FETCHROW($result))
177                 {
178                         $pay   = TRANSLATE_COMMA($pay);
179                         $price = TRANSLATE_COMMA($price);
180
181                         // Prepare array for the row template
182                         $content = array(
183                                 'sw'    => $SW,
184                                 'id'    => $id,
185                                 'time'  => $time,
186                                 'title' => $title,
187                                 'pay'   => $pay,
188                                 'price' => $price,
189                         );
190
191                         // Load row template and switch colors
192                         $OUT .= LOAD_TEMPLATE("admin_payments_list_row", true, $content);
193                         $SW = 3 - $SW;
194                 }
195
196                 // Free memory
197                 SQL_FREERESULT($result);
198                 define('__PAYMENT_ROWS', $OUT);
199
200                 // Load main template
201                 LOAD_TEMPLATE("admin_list_payments");
202         }
203
204         // Form for adding new referal levels
205         LOAD_TEMPLATE("admin_add_payment");
206 }
207
208 //
209 ?>