0f11f5fed2984351a16089fedc30a4388e14b462
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if (((!isPostRequestElementSet('t_wait')) || (!isPostRequestElementSet('payment'))) && (isGetRequestElementSet('do')) && (getRequestElement('do') == 'add')) {
47         unsetPostRequestElement('ok');
48 } // END - if
49
50 if (isFormSent()) {
51         switch (getRequestElement('do')) {
52                 case 'add':
53                         addSql("INSERT INTO `{?_MYSQL_PREFIX?}_payments` (`time`, `payment`, `mail_title`, `price`) VALUES ('".postRequestElement('t_wait')."','".postRequestElement('payment')."','".postRequestElement('title')."','".postRequestElement('price')."')");
54                         if (countSumTotalData(postRequestElement('t_wait'), 'payments', 'id', 'time', TRUE) == 1) {
55                                 // Re-init the array here
56                                 initSqls();
57                         } // END - if
58                         break;
59
60                 case 'edit':
61                         foreach (postRequestElement('time') as $id => $value) {
62                                 addSql("UPDATE `{?_MYSQL_PREFIX?}_payments` SET `time`='" . $value . "',`payment`='".postRequestElement('payment', $id)."', price='".postRequestElement('price', $id)."', mail_title='".postRequestElement('mail_title', $id)."' WHERE `id`='".$id."' LIMIT 1");
63                         } // END - foreach
64                         break;
65
66                 case 'delete':
67                         foreach (postRequestElement('id') as $id => $value) {
68                                 addSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=" . bigintval($id) . " LIMIT 1");
69                         } // END - foreach
70                         break;
71         } // END - switch
72
73         // Nothing has changed by default
74         $content = '<span class="bad">{--SETTINGS_NOT_SAVED--}</span>';
75
76         // Save settings
77         if (countSqls() > 0) {
78                 // Run all queries
79                 runFilterChain('run_sqls');
80
81                 // Purge cache
82                 rebuildCache('payments', 'payments');
83
84                 // Change message
85                 $content = '<span class="good">{--SETTINGS_SAVED--}</span>';
86         } // END - if
87
88         // Output template
89         displayMessage($content);
90 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
91         // Delete entries here
92         $OUT = '';
93         foreach (postRequestElement('sel') as $id => $value) {
94                 $result = SQL_QUERY_ESC("SELECT `id`, `time`, `mail_title` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1",
95                         array(bigintval($id)), __FILE__, __LINE__);
96                 $content = SQL_FETCHARRAY($result);
97
98                 // Free result
99                 SQL_FREERESULT($result);
100
101                 // Load row template and switch colors
102                 $OUT .= loadTemplate('admin_delete_payments_row', TRUE, $content);
103         } // END - foreach
104
105         // Load main template
106         loadTemplate('admin_delete_payments', FALSE, $OUT);
107 } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
108         // Edit entries
109         $OUT = '';
110         foreach (postRequestElement('sel') as $id => $value) {
111                 $result = SQL_QUERY_ESC("SELECT `id`, `time`, `payment`, `mail_title`, `price` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1",
112                         array(bigintval($id)), __FILE__, __LINE__);
113                 $content = SQL_FETCHARRAY($result);
114
115                 // Free result
116                 SQL_FREERESULT($result);
117
118                 // Load row template and switch colors
119                 $OUT .= loadTemplate('admin_edit_payments_row', TRUE, $content);
120         } // END - foreach
121
122         // Load main template
123         loadTemplate('admin_edit_payments', FALSE, $OUT);
124 } else {
125         // Referral levels
126         $result = SQL_QUERY("SELECT `id`, `time`, `payment`, `mail_title`, `price` FROM `{?_MYSQL_PREFIX?}_payments` ORDER BY `time` ASC", __FILE__, __LINE__);
127         if (!SQL_HASZERONUMS($result)) {
128                 // Make referral levels editable and deletable
129                 $OUT = '';
130
131                 // List already existing categories for editing
132                 while ($content = SQL_FETCHARRAY($result)) {
133                         // Load row template and switch colors
134                         $OUT .= loadTemplate('admin_list_payments_row', TRUE, $content);
135                 } // END - switch
136
137                 // Free memory
138                 SQL_FREERESULT($result);
139
140                 // Load main template
141                 loadTemplate('admin_list_payments', FALSE, $OUT);
142         } // END - if
143
144         // Form for adding new referral levels
145         loadTemplate('admin_add_payment');
146 }
147
148 // [EOF]
149 ?>