New wrapper functions introduced, TODOs.txt updated
[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 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.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                 $adminsList = generateOptionList('admins', 'id', 'login', '', 'email');
51                 $rows = '';
52                 foreach (postRequestParameter('sel') as $template => $sel) {
53                         // First of all load data from DB
54                         $result = SQL_QUERY_ESC("SELECT `admin_id`, `id` FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE `mail_template`='%s' ORDER BY `id` ASC",
55                                 array($template), __FILE__, __LINE__);
56                         $OUT = '';
57                         $adminId2 = '0'; $id = '0';
58                         while ($content = SQL_FETCHARRAY($result)) {
59                                 // @TODO Can this be rewritten to an API function?
60                                 $OUT .= '<select name="admin_id[' . $content['id'] . ']" size="1" class="form_select">
61 <option value="0"';
62                                 if ($content['admin_id'] == '0') $OUT .= ' selected="selected"';
63                                 $OUT .= '>{--ADMINS_ALL_ADMINS--}</option>';
64                                 if (isExtensionActive('events')) {
65                                         $OUT .= '<option value="-1"';
66                                         if ($content['admin_id'] == '-1') $OUT .= ' selected="selected"';
67                                         $OUT .= '>{--ADMINS_TO_USER_EVENTS--}</option>';
68                                 }
69                                 $OUT .= generateOptionList('admins', 'id', 'login', $content['admin_id'], 'email');
70                                 $OUT .= '</select>';
71
72                                 // Transfer ids
73                                 $adminId2 = $content['admin_id'];
74                                 $id = $content['id'];
75                         } // END - while
76
77                         // Free memory
78                         SQL_FREERESULT($result);
79
80                         // Prepare content
81                         $content['id']            = $id;
82                         $content['mail_template'] = $template;
83                         $content['admins']        = $adminsList;
84
85                         if ($adminId2 > 0) {
86                                 // Add form for an additional admin
87                                 $OUT .= loadTemplate('admin_admins_mails_edit_form', true, $content);
88                         } // END - if
89
90                         // Save full rendered content
91                         $content['content'] = $OUT;
92
93                         // Start outputing line
94                         $rows .= loadTemplate('admin_admins_mails_edit_row', true, $content);
95                 } // END - foreach
96
97                 // Edit checked entries
98                 loadTemplate('admin_admins_mails_edit', false, $rows);
99         } else {
100                 // Nothing selected
101                 displayMessage('{--ADMINS_NO_MAIL_CHECKED--}');
102         }
103 } else {
104         // Load all assigned mails
105         $result = SQL_QUERY("SELECT
106         m.id, m.admin_id, a.login, m.mail_template
107 FROM
108         `{?_MYSQL_PREFIX?}_admins_mails` AS m
109 LEFT JOIN
110         `{?_MYSQL_PREFIX?}_admins` AS a
111 ON
112         m.admin_id=a.id
113 WHERE
114         (m.admin_id=a.id OR m.admin_id < 1) AND m.mail_template != ''
115 ORDER BY
116         m.admin_id ASC,
117         m.mail_template ASC", __FILE__, __LINE__);
118
119         if (!SQL_HASZERONUMS($result)) {
120                 // Shall I change entries?
121                 if (isFormSent('change')) {
122                         // Init SQLs
123                         initSqls();
124
125                         // Ok, update database
126                         foreach (postRequestParameter('admin_id') as $id => $content['admin_id']) {
127                                 // Secure ids
128                                 $id  = bigintval($id);
129                                 $content['admin_id'] = bigintval($content['admin_id']);
130
131                                 // Update entry
132                                 addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins_mails` SET admin_id=%s WHERE `id`=%s ORDER BY `id` LIMIT 1",
133                                         array($content['admin_id'], $id), __FILE__, __LINE__, false));
134
135                                 if (($content['admin_id'] < 1) && (isPostRequestParameterSet('template', $id))) {
136                                         // Remove any other admin entries
137                                         addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE mail_template='%s' AND id != '%s'",
138                                         array(postRequestParameter('template', $id), $id), __FILE__, __LINE__, false));
139                                 } // END - if
140
141                                 if (postRequestParameter('admin_new', postRequestParameter('template', $id)) > 0) {
142                                         // Add new admin
143                                         addSql(SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_mails` (admin_id, mail_template) VALUES ('%s','%s')",
144                                         array($content['admin_id'], postRequestParameter('template', $id)), __FILE__, __LINE__, false));
145                                 } // END - if
146                         } // END - foreach
147
148                         // Run all queries
149                         runFilterChain('run_sqls');
150
151                         // Query again...
152                         $result = SQL_QUERY("SELECT
153         m.id, m.admin_id, a.login, m.mail_template
154 FROM
155         `{?_MYSQL_PREFIX?}_admins_mails` AS m
156 LEFT JOIN
157         `{?_MYSQL_PREFIX?}_admins` AS a
158 ON
159         m.admin_id=a.id
160 WHERE
161         (m.admin_id=a.id OR m.admin_id < 1) AND m.mail_template != ''
162 ORDER BY
163         m.admin_id ASC,
164         m.mail_template ASC", __FILE__, __LINE__);
165                 } // END - if
166
167                 // List found entries
168                 $OUT = '';
169                 while ($content = SQL_FETCHARRAY($result)) {
170                         // Load row template
171                         $OUT .= loadTemplate('admin_admins_mails_list_row', true, $content);
172                 } // END - while
173
174                 // Free result
175                 SQL_FREERESULT($result);
176
177                 // Load template
178                 loadTemplate('admin_admins_mails_list', false, $OUT);
179         } else {
180                 // No entries found
181                 displayMessage('{--ADMINS_MAILS_NO_ENTRIES--}');
182         }
183 }
184
185 // [EOF]
186 ?>