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