Updated copyright notice as there are changes in this year
[mailer.git] / inc / modules / admin / what-admins_mails.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2013 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('edit')) {
47         // Check if entires are checked
48         if (ifPostContainsSelections()) {
49                 // Add option for events
50                 $rows = '';
51                 foreach (postRequestElement('sel') as $template => $sel) {
52                         // First of all load data from DB
53                         $result = SQL_QUERY_ESC("SELECT `admin_id`, `id` FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE `mail_template`='%s' ORDER BY `id` ASC",
54                                 array($template), __FILE__, __LINE__);
55                         $OUT = '';
56                         $adminId2 = '0'; $id = '0';
57                         while ($content = SQL_FETCHARRAY($result)) {
58                                 // @TODO Can this be rewritten to an API function?
59                                 $OUT .= '<select name="admin_id[' . $content['id'] . ']" size="1" class="form_select">
60 <option value="0"';
61                                 if (is_null($content['admin_id'])) {
62                                         $OUT .= ' selected="selected"';
63                                 } // END - if
64                                 $OUT .= '>{--ADMIN_TO_ALL_ADMINS--}</option>';
65
66                                 if (isExtensionActive('events')) {
67                                         $OUT .= '<option value="-1"';
68                                         if ($content['admin_id'] == '-1') {
69                                                 $OUT .= ' selected="selected"';
70                                         } // END - if
71                                         $OUT .= '>{--ADMIN_ADMINS_TO_USER_EVENTS--}</option>';
72                                 } // END - if
73
74                                 $OUT .= generateOptions('admins', 'id', 'login', $content['admin_id'], 'email');
75                                 $OUT .= '</select>';
76
77                                 // Transfer ids
78                                 $adminId2 = $content['admin_id'];
79                                 $id = $content['id'];
80                         } // END - while
81
82                         // Free memory
83                         SQL_FREERESULT($result);
84
85                         // Prepare content
86                         $content['id']            = $id;
87                         $content['mail_template'] = $template;
88                         $content['admins']        = generateOptions('admins', 'id', 'login', '', 'email');;
89
90                         if (isValidId($adminId2)) {
91                                 // Add form for an additional admin
92                                 $OUT .= loadTemplate('admin_admins_mails_edit_form', TRUE, $content);
93                         } // END - if
94
95                         // Save full rendered content
96                         $content['content'] = $OUT;
97
98                         // Start outputing line
99                         $rows .= loadTemplate('admin_admins_mails_edit_row', TRUE, $content);
100                 } // END - foreach
101
102                 // Edit checked entries
103                 loadTemplate('admin_admins_mails_edit', FALSE, $rows);
104         } else {
105                 // Nothing selected
106                 displayMessage('{--ADMINS_NO_MAIL_CHECKED--}');
107         }
108 } else {
109         // Load all assigned mails
110         $result = SQL_QUERY("SELECT
111         `m`.`id`,
112         `m`.`admin_id`,
113         `a`.`login`,
114         `m`.`mail_template`
115 FROM
116         `{?_MYSQL_PREFIX?}_admins_mails` AS `m`
117 LEFT JOIN
118         `{?_MYSQL_PREFIX?}_admins` AS `a`
119 ON
120         `m`.`admin_id`=`a`.`id`
121 WHERE
122         (`m`.`admin_id`=`a`.`id` OR `m`.`admin_id` < 1) AND `m`.`mail_template` != ''
123 ORDER BY
124         `m`.`admin_id` ASC,
125         `m`.`mail_template` ASC", __FILE__, __LINE__);
126
127         if (!SQL_HASZERONUMS($result)) {
128                 // Shall I change entries?
129                 if (isFormSent('do_edit')) {
130                         // Init SQLs
131                         initSqls();
132
133                         // Ok, update database
134                         foreach (postRequestElement('admin_id') as $id => $content['admin_id']) {
135                                 // Secure ids
136                                 $id  = bigintval($id);
137                                 $content['admin_id'] = bigintval($content['admin_id']);
138
139                                 // Update entry
140                                 addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins_mails` SET `admin_id`=%s WHERE `id`=%s ORDER BY `id` LIMIT 1",
141                                         array($content['admin_id'], $id), __FILE__, __LINE__, FALSE));
142
143                                 if ((!isValidId($content['admin_id'])) && (isPostRequestElementSet('template', $id))) {
144                                         // Remove any other admin entries
145                                         addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE mail_template='%s' AND id != '%s'",
146                                         array(postRequestElement('template', $id), $id), __FILE__, __LINE__, FALSE));
147                                 } // END - if
148
149                                 if (postRequestElement('admin_new', postRequestElement('template', $id)) > 0) {
150                                         // Add new admin
151                                         addSql(SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_mails` (admin_id, mail_template) VALUES ('%s','%s')",
152                                         array($content['admin_id'], postRequestElement('template', $id)), __FILE__, __LINE__, FALSE));
153                                 } // END - if
154                         } // END - foreach
155
156                         // Run all queries
157                         runFilterChain('run_sqls');
158
159                         // Query again...
160                         $result = SQL_QUERY("SELECT
161         `m`.`id`,
162         `m`.`admin_id`,
163         `a`.`login`,
164         `m`.`mail_template`
165 FROM
166         `{?_MYSQL_PREFIX?}_admins_mails` AS `m`
167 LEFT JOIN
168         `{?_MYSQL_PREFIX?}_admins` AS `a`
169 ON
170         `m`.`admin_id`=`a`.`id`
171 WHERE
172         (`m`.`admin_id`=`a`.`id` OR `m`.`admin_id` < 1) AND `m`.`mail_template` != ''
173 ORDER BY
174         `m`.`admin_id` ASC,
175         `m`.`mail_template` ASC", __FILE__, __LINE__);
176                 } // END - if
177
178                 // List found entries
179                 $OUT = '';
180                 while ($content = SQL_FETCHARRAY($result)) {
181                         // Load row template
182                         $OUT .= loadTemplate('admin_admins_mails_list_row', TRUE, $content);
183                 } // END - while
184
185                 // Free result
186                 SQL_FREERESULT($result);
187
188                 // Load template
189                 loadTemplate('admin_admins_mails_list', FALSE, $OUT);
190         } else {
191                 // No entries found
192                 displayMessage('{--ADMIN_ADMINS_MAILS_NO_ENTRIES--}');
193         }
194 }
195
196 // [EOF]
197 ?>