52079ff988879701020c0e8161cbe43be15c5b71
[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  * 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 - 2009 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')) || (!isAdmin())) {
41         die();
42 }
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 if (isPostRequestElementSet('edit')) {
48         // Check if entires are checked
49         if (countPostSelection() > 0) {
50                 // Add option for events
51                 $adminsList = generateOptionList('admins', 'id', 'login', '', 'email');
52                 $SW = 2; $rowNameS = '';
53                 foreach (postRequestElement('sel') as $template => $sel) {
54                         // First of all load data from DB
55                         $result = SQL_QUERY_ESC("SELECT `admin_id`, `id` FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE `mail_template`='%s' ORDER BY `id` ASC",
56                                 array($template), __FILE__, __LINE__);
57                         $OUT = ''; $adminId2 = '0';
58                         while ($content = SQL_FETCHARRAY($result)) {
59                                 // @TODO Can this be rewritten???
60                                 $OUT .= "<select name=\"admin_id[".$content['id']."]\" size=\"1\" class=\"admin_select\">
61 <option value=\"0\"";
62                                 if ($content['admin_id'] == '0') $OUT .= ' selected="selected"';
63                                 $OUT .=">{--ADMINS_ALL_ADMINS--}</option>\n";
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>\n";
68                                 }
69                                 $OUT .= generateOptionList('admins', 'id', 'login', $content['admin_id'], 'email');
70                                 $OUT .= "</select>\n<br />\n";
71                                 $adminId2 = $content['admin_id']; $id2 = $content['id'];
72                         }
73
74                         // Free memory
75                         SQL_FREERESULT($result);
76
77                         // Prepare content
78                         $content = array(
79                                 'sw'      => $SW,
80                                 'id'      => $id,
81                                 'id2'     => $id2,
82                                 'tpl'     => $template,
83                                 'admins'  => $adminsList
84                         );
85
86                         if ($adminId2 > 0) {
87                                 // Add form for an additional admin
88                                 $OUT .= loadTemplate('admin_admins_mails_edit_form', true, $content);
89                         } // END - if
90
91                         // Save full rendered content
92                         $content['content'] = $OUT;
93
94                         // Start outputing line
95                         $rowNameS .= loadTemplate('admin_admins_mails_edit_row', true, $content);
96                         $SW = 3 - $SW;
97                 }
98
99                 // Edit checked entries
100                 loadTemplate('admin_admins_mails_edit', false, $rowNameS);
101         } else {
102                 // Nothing selected
103                 loadTemplate('admin_settings_saved', false, getMessage('ADMINS_NO_MAIL_CHECKED'));
104         }
105 } else {
106         // Load all assigned mails
107         $result = SQL_QUERY("SELECT
108         m.id, m.admin_id, a.login, m.mail_template
109 FROM
110         `{?_MYSQL_PREFIX?}_admins_mails` AS m
111 LEFT JOIN
112         `{?_MYSQL_PREFIX?}_admins` AS a
113 ON
114         m.admin_id=a.id
115 WHERE
116         (m.admin_id=a.id OR m.admin_id < 1) AND m.mail_template != ''
117 ORDER BY
118         m.admin_id ASC,
119         m.mail_template ASC", __FILE__, __LINE__);
120
121         if (SQL_NUMROWS($result) > 0) {
122                 // Shall I change entries?
123                 if (isPostRequestElementSet('change')) {
124                         // Init SQLs
125                         initSqls();
126
127                         // Ok, update database
128                         foreach (postRequestElement('admin_id') as $id => $content['admin_id']) {
129                                 // Secure ids
130                                 $id  = bigintval($id);
131                                 $content['admin_id'] = bigintval($content['admin_id']);
132
133                                 // Update entry
134                                 addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins_mails` SET admin_id=%s WHERE `id`=%s ORDER BY `id` LIMIT 1",
135                                 array($content['admin_id'], $id), __FILE__, __LINE__, false));
136
137                                 if (($content['admin_id'] < 1) && (isPostRequestElementSet('template', $id))) {
138                                         // Remove any other admin entries
139                                         addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE mail_template='%s' AND id != '%s'",
140                                         array(postRequestElement('template', $id), $id), __FILE__, __LINE__, false));
141                                 } // END - if
142
143                                 if (postRequestElement('admin_new', postRequestElement('template', $id)) > 0) {
144                                         // Add new admin
145                                         addSql(SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_mails` (admin_id, mail_template) VALUES ('%s','%s')",
146                                         array($content['admin_id'], postRequestElement('template', $id)), __FILE__, __LINE__, false));
147                                 } // END - if
148                         } // END - foreach
149
150                         // Run all queries
151                         runFilterChain('run_sqls');
152
153                         // Query again...
154                         $result = SQL_QUERY("SELECT 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__);
155                 } // END - if
156
157                 // List found entries
158                 $OUT = ''; $SW = 2;
159                 while ($data = SQL_FETCHARRAY($result)) {
160                         // Prepare content
161                         $content = array(
162                                 'sw'   => $SW,
163                                 'id'   => $data['id'],
164                                 'tpl'  => $data['mail_template'],
165                                 'alnk' => generateAdminLink($data['admin_id'])
166                         );
167
168                         // Load row template
169                         $OUT .= loadTemplate('admin_admins_mails_list_row', true, $content);
170                         $SW = 3 - $SW;
171                 } // END - while
172
173                 // Free result
174                 SQL_FREERESULT($result);
175
176                 // Load template
177                 loadTemplate('admin_admins_mails_list', false, $OUT);
178         } else {
179                 // No entries found
180                 loadTemplate('admin_settings_saved', false, getMessage('ADMINS_MAILS_NO_ENTRIES'));
181         }
182 }
183
184 // [EOF]
185 ?>