A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / admin / what-config_email.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/11/2003 *
4  * ===============                              Last change: 07/04/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-config_emails.php                           *
8  * -------------------------------------------------------------------- *
9  * Short description : Edit all things around email and sending         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Aendern aller Email-Einstellungen                *
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 // Remove empty array index
44 if (!REQUEST_ISSET_POST(('max'))) REQUEST_UNSET_POST(('add_max'));
45
46 if (REQUEST_ISSET_POST(('add_max'))) {
47         // Save all settings
48         $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_max_receive` WHERE value='%s' LIMIT 1",
49          array(bigintval(REQUEST_POST('max'))), __FILE__, __LINE__);
50         if (SQL_NUMROWS($result) == 0) {
51                 // Add this value (including comment)
52                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_max_receive` (value, comment) VALUES ('%s','%s')",
53                         array(bigintval(REQUEST_POST('max')), REQUEST_POST('comment')),__FILE__, __LINE__);
54                 $content = MAX_VALUE_SAVED;
55         } else {
56                 // Value does alread exists!
57                 $content = "<span class=\"admin_failed\">{--MAX_VALUE_ALREADY--}</span>";
58         }
59
60         // Free memory
61         SQL_FREERESULT($result);
62
63         // Display message
64         LOAD_TEMPLATE("admin_settings_saved", false, $content);
65 } elseif ((IS_FORM_SENT()) && (REQUEST_ISSET_GET(('do')))) {
66         // Change or delete entries...
67         $TEXT = "";
68         foreach (REQUEST_POST('id') as $id => $value) {
69                 // Secure ID
70                 $id = bigintval($id);
71
72                 switch (REQUEST_GET('do'))
73                 {
74                 case "edit": // Change entries
75                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_max_receive` SET value='%s', comment='%s' WHERE id=%s LIMIT 1",
76                                 array(
77                                         bigintval(REQUEST_POST('val', $id)),
78                                         REQUEST_POST('comm', $id),
79                                         $id
80                                 ),__FILE__, __LINE__);
81                         $TEXT = MRECEIVE_SAVED;
82                         break;
83
84                 case "del":
85                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_max_receive` WHERE id=%s LIMIT 1",
86                                 array($id), __FILE__, __LINE__);
87                         $TEXT = MRECEIVE_DELETED;
88                         break;
89                 }
90         }
91
92         if (isset($TEXT)) {
93                 // Display message
94                 LOAD_TEMPLATE("admin_settings_saved", false, $TEXT);
95         }
96 } elseif ((REQUEST_ISSET_POST('del')) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
97         // Delete entries
98         $OUT = ""; $SW = 2;
99         foreach (REQUEST_POST('sel') as $id => $value)
100         {
101                 // Load data
102                 $result = SQL_QUERY_ESC("SELECT value, comment FROM `{!_MYSQL_PREFIX!}_max_receive` WHERE id=%s LIMIT 1",
103                  array(bigintval($id)), __FILE__, __LINE__);
104                 list($value, $comment) = SQL_FETCHROW($result);
105                 SQL_FREERESULT($result);
106
107                 // Prepare data for the row template
108                 $content = array(
109                         'sw'      => $SW,
110                         'id'      => $id,
111                         'value'   => $value,
112                         'comment' => $comment,
113                 );
114
115                 // Load row template and switch color
116                 $OUT .= LOAD_TEMPLATE("admin_config_email_del_row", true, $content);
117                 $SW = 3 - $SW;
118         }
119         define('__ROWS', $OUT);
120
121         // Load main template
122         LOAD_TEMPLATE("admin_config_email_del");
123 } elseif ((REQUEST_ISSET_POST('edit')) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
124         // Edit entries
125         $OUT = ""; $SW = 2;
126         foreach (REQUEST_POST('sel') as $id => $value) {
127                 // Load data
128                 $result = SQL_QUERY_ESC("SELECT value, comment FROM `{!_MYSQL_PREFIX!}_max_receive` WHERE id=%s LIMIT 1",
129                  array(bigintval($id)), __FILE__, __LINE__);
130                 list($value, $comment) = SQL_FETCHROW($result);
131                 SQL_FREERESULT($result);
132
133                 // Prepare data for the row template
134                 $content = array(
135                         'sw'      => $SW,
136                         'id'      => $id,
137                         'value'   => $value,
138                         'comment' => $comment,
139                 );
140
141                 // Load row template and switch color
142                 $OUT .= LOAD_TEMPLATE("admin_config_email_edit_row", true, $content);
143                 $SW = 3 - $SW;
144         }
145         define('__ROWS', $OUT);
146
147         // Load main template
148         LOAD_TEMPLATE("admin_config_email_edit");
149 } else {
150         $result = SQL_QUERY("SELECT id, value, comment FROM `{!_MYSQL_PREFIX!}_max_receive` ORDER BY value",
151                 __FILE__, __LINE__);
152         if (SQL_NUMROWS($result) > 0) {
153                 // List already existing entries for editing
154                 $OUT = ""; $SW = 2;
155                 while ($content = SQL_FETCHARRAY($result)) {
156                         // Prepare data for the row template
157                         $content['sw'] = $SW;
158
159                         // Load row template and switch color
160                         $OUT .= LOAD_TEMPLATE("admin_config_email_row", true, $content);
161                         $SW = 3 - $SW;
162                 } // END - while
163
164                 // Free memory
165                 SQL_FREERESULT($result);
166                 define('__ROWS', $OUT);
167
168                 // Load main template
169                 LOAD_TEMPLATE("admin_config_email");
170         } // END - if
171
172         // Display form
173         LOAD_TEMPLATE("admin_add_max");
174 }
175
176 //
177 ?>