7edb41e4b9b2afd6a5f6ee9631ae87a906cb6c8e
[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 = '';
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                         'id'    => $id,
104                         'time'  => $time,
105                         'title' => $title,
106                 );
107
108                 // Load row template and switch colors
109                 $OUT .= loadTemplate('admin_del_payments_row', true, $content);
110         } // END - foreach
111
112         // Load main template
113         loadTemplate('admin_del_payments', false, $OUT);
114 } elseif ((isFormSent('edit')) && (countPostSelection() > 0)) {
115         // Edit entries
116         $OUT = '';
117         foreach (postRequestParameter('sel') as $id => $value) {
118                 $result = SQL_QUERY_ESC("SELECT time, payment, mail_title, price FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1",
119                 array(bigintval($id)), __FILE__, __LINE__);
120                 list($time, $pay, $title, $price) = SQL_FETCHROW($result);
121                 SQL_FREERESULT($result);
122
123                 // Prepare array for the row template
124                 $content = array(
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 .= loadTemplate('admin_edit_payments_row', true, $content);
134         } // END - foreach
135
136         // Load main template
137         loadTemplate('admin_edit_payments', false, $OUT);
138 } else {
139         // Referal levels
140         $result = SQL_QUERY("SELECT `id`, `time`, `payment`, `mail_title`, `price` FROM `{?_MYSQL_PREFIX?}_payments` ORDER BY `time` ASC", __FILE__, __LINE__);
141         if (SQL_NUMROWS($result) > 0) {
142                 // Make referal levels editable and deletable
143                 $OUT = '';
144
145                 // List already existing categories for editing
146                 while ($content = SQL_FETCHARRAY($result)) {
147                         // Load row template and switch colors
148                         $OUT .= loadTemplate('admin_list_payments_row', true, $content);
149                 } // END - switch
150
151                 // Free memory
152                 SQL_FREERESULT($result);
153
154                 // Load main template
155                 loadTemplate('admin_list_payments', false, $OUT);
156         } // END - if
157
158         // Form for adding new referal levels
159         loadTemplate('admin_add_payment');
160 }
161
162 // [EOF]
163 ?>