Even more rewrites/fixes from EL branch (please report any broken part after you...
[mailer.git] / inc / modules / admin / what-payments.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 best&auml;tigte Mails              *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
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 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 if (((!isPostRequestParameterSet(('t_wait'))) || (!isPostRequestParameterSet(('payment')))) && (isGetRequestParameterSet('do')) && (getRequestParameter('do') == 'add')) {
49         unsetPostRequestParameter('ok');
50 } // END - if
51
52 if (isFormSent()) {
53         switch (getRequestParameter('do')) {
54                 case 'add':
55                         addSql("INSERT INTO `{?_MYSQL_PREFIX?}_payments` (time, payment, mail_title, price) VALUES ('".postRequestParameter('t_wait')."','".postRequestParameter('payment')."','".postRequestParameter('title')."','".postRequestParameter('price')."')");
56                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_payments` WHERE time='%s' LIMIT 1",
57                         array(postRequestParameter('t_wait')), __FILE__, __LINE__);
58                         if (SQL_NUMROWS($result) == 1) {
59                                 // Re-init the array here
60                                 initSqls();
61
62                                 // Free memory
63                                 SQL_FREERESULT($result);
64                         }
65                         break;
66
67                 case 'edit':
68                         foreach (postRequestParameter('time') as $id => $value) {
69                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_payments` SET `time`='" . $value . "', `payment`='".postRequestParameter('pay', $id)."', price='".postRequestParameter('price', $id)."', mail_title='".postRequestParameter('title', $id)."' WHERE `id`='".$id."' LIMIT 1");
70                         }
71                         break;
72
73                 case 'del':
74                         foreach (postRequestParameter('id') as $id => $value) {
75                                 addSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=" . bigintval($id) . " LIMIT 1");
76                         }
77                         break;
78         } // END - switch
79
80         // Save settings
81         if (countSqls() > 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         loadTemplate('admin_settings_saved', false, $content);
92 } elseif ((isFormSent('del')) && (countPostSelection() > 0)) {
93         // Delete entries here
94         $OUT = ''; $SW = 2;
95         foreach (postRequestParameter('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 .= loadTemplate('admin_del_payments_row', true, $content);
111                 $SW = 3 - $SW;
112         }
113
114         // Load main template
115         loadTemplate('admin_del_payments', false, $OUT);
116 } elseif ((isFormSent('edit')) && (countPostSelection() > 0)) {
117         // Edit entries
118         $OUT = ''; $SW = 2;
119         foreach (postRequestParameter('sel') as $id => $value) {
120                 $result = SQL_QUERY_ESC("SELECT time, payment, mail_title, price FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1",
121                 array(bigintval($id)), __FILE__, __LINE__);
122                 list($time, $pay, $title, $price) = SQL_FETCHROW($result);
123                 SQL_FREERESULT($result);
124
125                 // Prepare array for the row template
126                 $content = array(
127                         'sw'    => $SW,
128                         'id'    => $id,
129                         'time'  => $time,
130                         'title' => $title,
131                         'pay'   => $pay,
132                         'price' => $price,
133                 );
134
135                 // Load row template and switch colors
136                 $OUT .= loadTemplate('admin_edit_payments_row', true, $content);
137                 $SW = 3 - $SW;
138         }
139
140         // Load main template
141         loadTemplate('admin_edit_payments', false, $OUT);
142 } else {
143         // Referal levels
144         $result = SQL_QUERY("SELECT `id`, `time`, `payment`, `mail_title`, `price` FROM `{?_MYSQL_PREFIX?}_payments` ORDER BY `time` ASC", __FILE__, __LINE__);
145         if (SQL_NUMROWS($result) > 0) {
146                 // Make referal levels editable and deletable
147                 $OUT = ''; $SW = 2;
148
149                 // List already existing categories for editing
150                 while ($content = SQL_FETCHARRAY($result)) {
151                         // Prepare array for the row template
152                         // @TODO Rewritings: title->mail_title, pay->payment in template
153                         $content = array(
154                                 'sw'    => $SW,
155                                 'id'    => $content['id'],
156                                 'time'  => $content['time'],
157                                 'title' => $content['mail_title'],
158                                 'pay'   => translateComma($content['payment']),
159                                 'price' => translateComma($content['price'])
160                         );
161
162                         // Load row template and switch colors
163                         $OUT .= loadTemplate('admin_payments_list_row', true, $content);
164                         $SW = 3 - $SW;
165                 } // END - switch
166
167                 // Free memory
168                 SQL_FREERESULT($result);
169
170                 // Load main template
171                 loadTemplate('admin_list_payments', false, $OUT);
172         } // END - if
173
174         // Form for adding new referal levels
175         loadTemplate('admin_add_payment');
176 }
177
178 // [EOF]
179 ?>