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