A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / admin / what-edit_emails.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 if ((IS_FORM_SENT()) && (!REQUEST_ISSET_POST(('id')))) {
44         REQUEST_UNSET_POST('ok');
45 }
46
47 $result = SQL_QUERY("SELECT id, sender, subject, payment_id, cat_id FROM `{!_MYSQL_PREFIX!}_pool` ORDER BY timestamp", __FILE__, __LINE__);
48 if (SQL_NUMROWS($result) > 0) {
49         if (IS_FORM_SENT()) {
50                 // Make mail editable...
51                 $result = SQL_QUERY_ESC("SELECT subject, text, url FROM `{!_MYSQL_PREFIX!}_pool` WHERE id=%s LIMIT 1",
52                  array(bigintval(REQUEST_POST('id'))), __FILE__, __LINE__);
53                 list($subj, $text, $url) = SQL_FETCHROW($result);
54                 SQL_FREERESULT($result);
55                 // @TODO More constants to rewrite
56                 define('__ID_VALUE'  , REQUEST_POST('id'));
57                 define('__URL_VALUE' , $url);
58                 define('__SUBJ_VALUE', $subj);
59                 define('__TEXT_VALUE', $text);
60
61                 // Load template
62                 LOAD_TEMPLATE("admin_edit_email");
63         } elseif (REQUEST_ISSET_POST(('save'))) {
64                 // Save changes
65                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_pool` SET
66 subject='%s',
67 text='%s',
68 url='%s'
69 WHERE id=%s LIMIT 1",
70  array(
71         REQUEST_POST('subj'),
72         REQUEST_POST('text'),
73         REQUEST_POST('url'),
74         bigintval(REQUEST_POST('id')),
75 ), __FILE__, __LINE__);
76
77                 if (SQL_AFFECTEDROWS() == 1) {
78                         $content = getMessage('SETTINGS_SAVED');
79                 } else {
80                         $content = "<span class=\"admin_failed\">{--SETTINGS_NOT_SAVED--}</span>";
81                 }
82
83                 // Display message
84                 LOAD_TEMPLATE("admin_settings_saved", false, $content);
85         } else {
86                 // There are mail orders available
87                 $OUT = ""; $SW = 2;
88                 while ($content = SQL_FETCHARRAY($result)) {
89                         // Prepare data for the row template
90                         // @TODO Rewritings: subj->subject in template
91                         $content = array(
92                                 'sw'   => $SW,
93                                 'id'   => $content['id'],
94                                 'subj' => $content['subject'],
95                                 'uid'  => ADMIN_USER_PROFILE_LINK($content['sender']),
96                                 'pay'  => GET_PAYMENT($content['payment_id']),
97                                 'cat'  => GET_CATEGORY($content['cat_id']),
98                         );
99
100                         // Load row template and switch colors
101                         $OUT .= LOAD_TEMPLATE("admin_edit_email_row", true, $content);
102                         $SW = 3 - $SW;
103                 }
104
105                 // Free memory
106                 SQL_FREERESULT($result);
107
108                 // @TODO Yet another constant to rewrite
109                 define('__EMAIL_SELECT_ROWS', $OUT);
110
111                 // Load email template
112                 LOAD_TEMPLATE("admin_edit_email_select");
113         }
114 } else {
115         // No mail orders left in pool
116         LOAD_TEMPLATE("admin_settings_saved", false, "<span class=\"admin_failed\">{--ADMIN_NO_MAILS_IN_POOL--}</span>");
117 }
118
119 //
120 ?>