]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-admins_mails.php
3305017e372963fb8468f7a29077bdce6a4e2a6e
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 if (isset($_POST['edit']))
44 {
45         // Check if entires are checked
46         $SEL = SELECTION_COUNT($_POST['sel']);
47         if ($SEL > 0)
48         {
49                 // Add option for events
50                 $cacheArray['admins'] = ADD_OPTION_LINES("admins", "id", "login", "", "email");
51                 $SW = 2; $rowNameS = "";
52                 foreach ($_POST['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`",
55                          array($template), __FILE__, __LINE__);
56                         $OUT = ""; $aid = 0; $aid2 = 0;
57                         while (list($aid, $id) = SQL_FETCHROW($result)) {
58                                 // @TODO Can this be rewritten???
59                                 $OUT .= "<select name=\"admin_id[".$id."]\" size=\"1\" class=\"admin_select\">
60 <option value=\"0\"";
61                                 if ($aid == "0") $OUT .= " selected=\"selected\"";
62                                 $OUT .=">{--ADMINS_ALL_ADMINS--}</option>\n";
63                                 if (EXT_IS_ACTIVE("events")) {
64                                         $OUT .= "<option value=\"-1\"";
65                                         if ($aid == "-1") $OUT .= " selected=\"selected\"";
66                                         $OUT .= ">{--ADMINS_TO_USERLOG--}</option>\n";
67                                 }
68                                 $OUT .= ADD_OPTION_LINES("admins", "id", "login", $aid, "email");
69                                 $OUT .= "</select><br />\n";
70                                 $aid2 = $aid; $id2 = $id;
71                         }
72
73                         // Free memory
74                         SQL_FREERESULT($result);
75
76                         $content = array(
77                                 'sw'      => $SW,
78                                 'id'      => $id,
79                                 'id2'     => $id2,
80                                 'tpl'     => $template,
81                                 'admins'  => $cacheArray['admins']
82                         );
83
84                         if ($aid2 > 0)
85                         {
86                                 // Add form for an additional admin
87                                 $OUT .= LOAD_TEMPLATE("admin_admins_mails_edit_form", true, $content);
88                         }
89                         // Save full rendered content
90                         $content['content'] = $OUT;
91
92                         // Start outputing line
93                         $rowNameS .= LOAD_TEMPLATE("admin_admins_mails_edit_row", true, $content);
94                         $SW = 3 - $SW;
95                 }
96                 define('__ADMINS_ROWS', $rowNameS);
97
98                 // Edit checked entries
99                 LOAD_TEMPLATE("admin_admins_mails_edit");
100         }
101          else
102         {
103                 // Nothing selected
104                 LOAD_TEMPLATE("admin_settings_saved", false, ADMINS_NO_MAIL_CHECKED);
105         }
106 }
107  else
108 {
109         // Load all assigned mails
110         $result = SQL_QUERY("SELECT DISTINCT m.id, m.admin_id, a.login, m.mail_template
111 FROM `{!_MYSQL_PREFIX!}_admins_mails` AS m
112 LEFT JOIN `{!_MYSQL_PREFIX!}_admins` AS a
113 ON m.admin_id=a.id
114 WHERE (m.admin_id=a.id OR m.admin_id < 1) AND m.mail_template != ''
115 ORDER BY m.admin_id, m.mail_template", __FILE__, __LINE__);
116
117         if (SQL_NUMROWS($result) > 0)
118         {
119                 // Shall I change entries?
120                 if (isset($_POST['change']))
121                 {
122                         // Ok, update database
123                         foreach ($_POST['admin_id'] as $id => $aid)
124                         {
125                                 // Secure IDs
126                                 $id  = bigintval($id);
127                                 $aid = bigintval($aid);
128
129                                 // Update entry
130                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_admins_mails` SET admin_id=%s WHERE id=%s ORDER BY `id` LIMIT 1",
131                                         array($aid, $id), __FILE__, __LINE__);
132
133                                 if (($aid < 1) && (!empty($_POST['template'][$id])))
134                                 {
135                                         // Remove any other admin entries
136                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_admins_mails` WHERE mail_template='%s' AND id != '%s'",
137                                                 array($_POST['template'][$id], $id), __FILE__, __LINE__);
138                                 }
139                                 if ($_POST['admin_new'][$_POST['template'][$id]] > 0)
140                                 {
141                                         // Add new admin
142                                         SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_admins_mails` (admin_id, mail_template) VALUES ('%s','%s')",
143                                                 array($aid, $_POST['template'][$id]), __FILE__, __LINE__);
144                                 }
145                         }
146
147                         // Query again...
148                         $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__);
149                 }
150
151                 // List found entries
152                 $SW = 2; $OUT = "";
153                 while ($data = SQL_FETCHARRAY($result)) {
154                         // Prepare content
155                         $content = array(
156                                 'sw'   => $SW,
157                                 'id'   => $data['id'],
158                                 'tpl'  => $data['mail_template'],
159                                 'alnk' => GENERATE_AID_LINK($data['admin_id'])
160                         );
161
162                         // Load row template
163                         $OUT .= LOAD_TEMPLATE("admin_admins_mails_list_row", true, $content);
164                         $SW = 3 - $SW;
165                 }
166
167                 // Free result
168                 SQL_FREERESULT($result);
169                 define('__MAILS_ROWS', $OUT);
170
171                 // Load template
172                 LOAD_TEMPLATE("admin_admins_mails_list");
173         } else {
174                 // No entries found
175                 LOAD_TEMPLATE("admin_settings_saved", false, ADMINS_MAILS_NO_ENTRIES);
176         }
177 }
178
179 //
180 ?>