A lot double-quotes rewritten to single-quotes, some redirect URLs fixed
[mailer.git] / inc / modules / admin / what-admins_mails.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 08/14/2004 *
4  * ================                             Last change: 10/22/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-admins_mails.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Control which admin shall receive which mail     *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Stellen Sie ein, welcher Admin welche Mail erh.  *
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 - 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 (REQUEST_ISSET_POST('edit')) {
49         // Check if entires are checked
50         $SEL = SELECTION_COUNT(REQUEST_POST('sel'));
51         if ($SEL > 0) {
52                 // Add option for events
53                 $GLOBALS['cache_array']['admins'] = ADD_OPTION_LINES('admins', "id", "login", '', 'email');
54                 $SW = 2; $rowNameS = '';
55                 foreach (REQUEST_POST('sel') as $template => $sel) {
56                         // First of all load data from DB
57                         $result = SQL_QUERY_ESC("SELECT admin_id, id FROM `{!_MYSQL_PREFIX!}_admins_mails` WHERE mail_template='%s' ORDER BY `id`",
58                                 array($template), __FILE__, __LINE__);
59                         $OUT = ''; $aid2 = 0;
60                         while ($content = SQL_FETCHARRAY($result)) {
61                                 // @TODO Can this be rewritten???
62                                 $OUT .= "<select name=\"admin_id[".$content['id']."]\" size=\"1\" class=\"admin_select\">
63 <option value=\"0\"";
64                                 if ($content['admin_id'] == "0") $OUT .= " selected=\"selected\"";
65                                 $OUT .=">{--ADMINS_ALL_ADMINS--}</option>\n";
66                                 if (EXT_IS_ACTIVE('events')) {
67                                         $OUT .= "<option value=\"-1\"";
68                                         if ($content['admin_id'] == "-1") $OUT .= " selected=\"selected\"";
69                                         $OUT .= ">{--ADMINS_TO_USER_EVENTS--}</option>\n";
70                                 }
71                                 $OUT .= ADD_OPTION_LINES('admins', "id", "login", $content['admin_id'], 'email');
72                                 $OUT .= "</select>\n<br />\n";
73                                 $aid2 = $content['admin_id']; $id2 = $content['id'];
74                         }
75
76                         // Free memory
77                         SQL_FREERESULT($result);
78
79                         $content = array(
80                                 'sw'      => $SW,
81                                 'id'      => $id,
82                                 'id2'     => $id2,
83                                 'tpl'     => $template,
84                                 'admins'  => $GLOBALS['cache_array']['admins']
85                         );
86
87                         if ($aid2 > 0) {
88                                 // Add form for an additional admin
89                                 $OUT .= LOAD_TEMPLATE("admin_admins_mails_edit_form", true, $content);
90                         }
91
92                         // Save full rendered content
93                         $content['content'] = $OUT;
94
95                         // Start outputing line
96                         $rowNameS .= LOAD_TEMPLATE("admin_admins_mails_edit_row", true, $content);
97                         $SW = 3 - $SW;
98                 }
99
100                 // @TODO Rewrite this constant
101                 define('__ADMINS_ROWS', $rowNameS);
102
103                 // Edit checked entries
104                 LOAD_TEMPLATE("admin_admins_mails_edit");
105         } else {
106                 // Nothing selected
107                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMINS_NO_MAIL_CHECKED'));
108         }
109 } else {
110         // Load all assigned mails
111         $result = SQL_QUERY("SELECT DISTINCT m.id, m.admin_id, a.login, m.mail_template
112 FROM `{!_MYSQL_PREFIX!}_admins_mails` AS m
113 LEFT JOIN `{!_MYSQL_PREFIX!}_admins` AS a
114 ON m.admin_id=a.id
115 WHERE (m.admin_id=a.id OR m.admin_id < 1) AND m.mail_template != ''
116 ORDER BY m.admin_id, m.mail_template", __FILE__, __LINE__);
117
118         if (SQL_NUMROWS($result) > 0) {
119                 // Shall I change entries?
120                 if (REQUEST_ISSET_POST('change')) {
121                         // Init SQLs
122                         INIT_SQLS();
123
124                         // Ok, update database
125                         foreach (REQUEST_POST('admin_id') as $id => $content['admin_id']) {
126                                 // Secure IDs
127                                 $id  = bigintval($id);
128                                 $content['admin_id'] = bigintval($content['admin_id']);
129
130                                 // Update entry
131                                 ADD_SQL(SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_admins_mails` SET admin_id=%s WHERE id=%s ORDER BY `id` LIMIT 1",
132                                         array($content['admin_id'], $id), __FILE__, __LINE__, false));
133
134                                 if (($content['admin_id'] < 1) && (REQUEST_ISSET_POST('template', $id))) {
135                                         // Remove any other admin entries
136                                         ADD_SQL(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_admins_mails` WHERE mail_template='%s' AND id != '%s'",
137                                                 array(REQUEST_POST('template', $id), $id), __FILE__, __LINE__, false));
138                                 } // END - if
139
140                                 if (REQUEST_POST('admin_new', REQUEST_POST('template', $id)) > 0) {
141                                         // Add new admin
142                                         ADD_SQL(SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_admins_mails` (admin_id, mail_template) VALUES ('%s','%s')",
143                                                 array($content['admin_id'], REQUEST_POST('template', $id)), __FILE__, __LINE__, false));
144                                 } // END - if
145                         } // END - foreach
146
147                         // Run all queries
148                         runFilterChain('run_sqls');
149
150                         // Query again...
151                         $result = SQL_QUERY("SELECT DISTINCT m.id, m.admin_id, a.login, m.mail_template FROM `{!_MYSQL_PREFIX!}_admins_mails` AS m, `{!_MYSQL_PREFIX!}_admins` AS a WHERE m.admin_id=a.id OR m.admin_id < 1 ORDER BY m.admin_id", __FILE__, __LINE__);
152                 } // END - if
153
154                 // List found entries
155                 $OUT = ''; $SW = 2;
156                 while ($data = SQL_FETCHARRAY($result)) {
157                         // Prepare content
158                         $content = array(
159                                 'sw'   => $SW,
160                                 'id'   => $data['id'],
161                                 'tpl'  => $data['mail_template'],
162                                 'alnk' => GENERATE_AID_LINK($data['admin_id'])
163                         );
164
165                         // Load row template
166                         $OUT .= LOAD_TEMPLATE("admin_admins_mails_list_row", true, $content);
167                         $SW = 3 - $SW;
168                 } // END - while
169
170                 // Free result
171                 SQL_FREERESULT($result);
172
173                 // @TODO Rewrite this constant
174                 define('__MAILS_ROWS', $OUT);
175
176                 // Load template
177                 LOAD_TEMPLATE("admin_admins_mails_list");
178         } else {
179                 // No entries found
180                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMINS_MAILS_NO_ENTRIES'));
181         }
182 }
183
184 //
185 ?>