911dc01ea085e99279c2efeae41326edfce53a71
[mailer.git] / inc / modules / admin / what-edit_emails.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 09/28/2003 *
4  * ===================                          Last change: 04/09/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-edit_emails.php                             *
8  * -------------------------------------------------------------------- *
9  * Short description : Edit ordered mails e.g. redirecting the URL      *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Werbebuchungen aendern (z.B. umleiten der URL)   *
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 ((isFormSent()) && (!isPostRequestElementSet('id'))) {
47         unsetPostRequestElement('ok');
48 } // END - if
49
50 // Form sent or anything else? ;-)
51 if ((isFormSent()) && (isPostRequestElementSet('mid'))) {
52         // Make mail editable...
53         $result = SQL_QUERY_ESC('SELECT
54         `id`,
55         `sender` AS `userid`,
56         `subject`,
57         `text`,
58         `url`
59 FROM
60         `{?_MYSQL_PREFIX?}_pool`
61 WHERE
62         `id`=%s
63 LIMIT 1',
64                 array(bigintval(postRequestElement('mid'))), __FILE__, __LINE__);
65
66         // Fetch row
67         $content = SQL_FETCHARRAY($result);
68
69         // Free result
70         SQL_FREERESULT($result);
71
72         // Load template
73         loadTemplate('admin_edit_email', FALSE, $content);
74 } elseif (isGetRequestElementSet('mid')) {
75         // Make also this email editable
76         $result = SQL_QUERY_ESC('SELECT
77         `id`,
78         `sender` AS `userid`,
79         `subject`,
80         `text`,
81         `url`
82 FROM
83         `{?_MYSQL_PREFIX?}_pool`
84 WHERE
85         `id`=%s
86 LIMIT 1',
87                 array(bigintval(getRequestElement('mid'))), __FILE__, __LINE__);
88
89         // Fetch row
90         $content = SQL_FETCHARRAY($result);
91
92         // Free result
93         SQL_FREERESULT($result);
94
95         // Load template
96         loadTemplate('admin_edit_email', FALSE, $content);
97 } elseif (isGetRequestElementSet('bid')) {
98                 // Make also this email editable
99                 $result = SQL_QUERY_ESC('SELECT
100         `id`,
101         `subject`,
102         `text`,
103         `url`
104 FROM
105         `{?_MYSQL_PREFIX?}_bonus`
106 WHERE
107         `id`=%s
108 LIMIT 1',
109                 array(bigintval(getRequestElement('bid'))), __FILE__, __LINE__);
110
111         // Fetch row
112         $content = SQL_FETCHARRAY($result);
113
114         // Free result
115         SQL_FREERESULT($result);
116
117         // Load template
118         loadTemplate('admin_edit_bonus_email', FALSE, $content);
119 } elseif (isFormSent('save')) {
120         // Save changes
121         if (isPostRequestElementSet('mid')) {
122                 // Update pool
123                 SQL_QUERY_ESC("UPDATE
124         `{?_MYSQL_PREFIX?}_pool`
125 SET
126         `subject`='%s',
127         `text`='%s',
128         `url`='%s'
129 WHERE
130         `id`=%s
131 LIMIT 1",
132                         array(
133                                 postRequestElement('subject'),
134                                 postRequestElement('text'),
135                                 postRequestElement('url'),
136                                 bigintval(postRequestElement('mid')),
137                         ), __FILE__, __LINE__);
138
139                 if (!SQL_HASZEROAFFECTED()) {
140                         $content = '{--ADMIN_EMAIL_CHANGES_SAVED--}';
141                 } else {
142                         $content = '<span class="bad">{--ADMIN_EMAIL_CHANGES_NOT_SAVED--}</span>';
143                 }
144         } elseif (isPostRequestElementSet('bid')) {
145                 // Update pool
146                 SQL_QUERY_ESC("UPDATE
147         `{?_MYSQL_PREFIX?}_bonus`
148 SET
149         `subject`='%s',
150         `text`='%s',
151         `url`='%s'
152 WHERE
153         `id`=%s
154 LIMIT 1",
155                         array(
156                                 postRequestElement('subject'),
157                                 postRequestElement('text'),
158                                 postRequestElement('url'),
159                                 bigintval(postRequestElement('bid')),
160                         ), __FILE__, __LINE__);
161
162                 if (!SQL_HASZEROAFFECTED()) {
163                         $content = '{--ADMIN_EMAIL_CHANGES_SAVED--}';
164                 } else {
165                         $content = '<span class="bad">{--ADMIN_EMAIL_CHANGES_NOT_SAVED--}</span>';
166                 }
167         } else {
168                 // No valid action
169                 $content = '<span class="bad">{--ADMIN_EDIT_EMAIL_FAILED--}</span>';
170         }
171
172         // Display message
173         displayMessage($content);
174 } else {
175         // Query the pool
176         $result = SQL_QUERY('SELECT
177         `id`,
178         `sender` AS `userid`,
179         `subject`,
180         `payment_id`,
181         `cat_id`
182 FROM
183         `{?_MYSQL_PREFIX?}_pool`
184 ORDER BY
185         `timestamp` ASC', __FILE__, __LINE__);
186
187         // Entries found?
188         if (!SQL_HASZERONUMS($result)) {
189                 // There are mail orders available
190                 $OUT = '';
191                 while ($content = SQL_FETCHARRAY($result)) {
192                         // Load row template and switch colors
193                         $OUT .= loadTemplate('admin_edit_email_row', TRUE, $content);
194                 } // END - while
195
196                 // Free memory
197                 SQL_FREERESULT($result);
198
199                 // Load email template
200                 loadTemplate('admin_edit_email_select', FALSE, $OUT);
201         } else {
202                 // No mail orders left in pool
203                 displayMessage('{--ADMIN_NO_MAILS_IN_POOL--}');
204         }
205 }
206
207 // [EOF]
208 ?>