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