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