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