A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / admin / what-config_mods.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 08/27/2004 *
4  * ================                             Last change: 08/27/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-config_mods.php                             *
8  * -------------------------------------------------------------------- *
9  * Short description : Module configuration                             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Modul-Konfiguration                              *
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 $SEL = 0;
44 if (REQUEST_ISSET_POST('edit')) {
45         // Check if at least one module is selected
46         $SEL = SELECTION_COUNT(REQUEST_POST('sel'));
47         if ($SEL > 0) {
48                 // Output header
49                 $OUT = ""; $SW = 2;
50
51                 // Edit selected modules
52                 foreach (REQUEST_POST('sel') as $id => $sel) {
53                         // Load module data
54                         $result = SQL_QUERY_ESC("SELECT module, title, locked, hidden, admin_only, mem_only FROM `{!_MYSQL_PREFIX!}_mod_reg` WHERE id=%s LIMIT 1",
55                                 array(bigintval($id)), __FILE__, __LINE__);
56                         list($mod, $title, $locked, $hidden, $admin, $mem) = SQL_FETCHROW($result);
57                         SQL_FREERESULT($result);
58
59                         // Prepare array for the template
60                         $content = array(
61                                 'sw'     => $SW,
62                                 'mod'    => $mod,
63                                 'id'     => $id,
64                                 'title'  => $title,
65                                 'locked' => ADD_SELECTION("yn", $locked, "locked", $id),
66                                 'hidden' => ADD_SELECTION("yn", $hidden, "hidden", $id),
67                                 'admin'  => ADD_SELECTION("yn", $admin , "admin" , $id),
68                                 'mem'    => ADD_SELECTION("yn", $mem   , "member", $id),
69                         );
70
71                         // Load row template
72                         $OUT .= LOAD_TEMPLATE("admin_mods_edit_row", true, $content);
73                 }
74                 define('__MODS_ROWS', $OUT);
75
76                 // Load main template
77                 LOAD_TEMPLATE("admin_mods_edit");
78         } else {
79                 // Nothing selected
80                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MODS_NOTHING_SELECTED'));
81
82                 // Remove maybe confusing data
83                 REQUEST_UNSET_POST('edit');
84                 REQUEST_UNSET_POST(('change'));
85         }
86 } elseif (REQUEST_ISSET_POST(('change'))) {
87         // Init SQLs
88         INIT_SQLS();
89
90         // Change modules
91         foreach (REQUEST_POST('sel') as $id => $sel) {
92                 // Secure ID number
93                 $id = bigintval($id);
94
95                 // Update module
96                 ADD_SQL(SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_mod_reg` SET `title`='%s', `locked`='%s', hidden='%s', admin_only='%s', mem_only='%s' WHERE id=%s LIMIT 1",
97                         array(
98                                 REQUEST_POST('title', $id),
99                                 REQUEST_POST('locked', $id),
100                                 REQUEST_POST('hidden', $id),
101                                 REQUEST_POST('admin', $id),
102                                 REQUEST_POST('member', $id),
103                                 $id
104                         ),  __FILE__, __LINE__, false));
105         }
106
107         // Run all sqls
108         runFilterChain('run_sqls');
109
110         // Remove cache file if version matches
111         if (GET_EXT_VERSION("cache") >= "0.1.2") {
112                 if ($GLOBALS['cache_instance']->loadCacheFile("modreg")) $GLOBALS['cache_instance']->destroyCacheFile();
113         } // END - if
114
115         // Entries updated
116         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MODS_CHANGED'));
117 }
118
119 if ($SEL == 0) {
120         // Load module data (We do not need to check if there's at least one...)
121         $result = SQL_QUERY("SELECT id, module, locked, hidden, admin_only, title, mem_only
122 FROM `{!_MYSQL_PREFIX!}_mod_reg`
123 ORDER BY module", __FILE__, __LINE__);
124         $OUT = ""; $SW = 2;
125         while ($content = SQL_FETCHARRAY($result)) {
126                 // Reset title to --- if it is NULL
127                 if (empty($content['title'])) $content['title'] = "---";
128                 if (($content['module'] == "index") || ($content['module'] == "login")) {
129                         // Add link to detail statistics
130                         $content['module'] = "<strong><a href=\"{!URL!}/modules.php?module=admin&amp;what=stats_mods&amp;mod=".$content['module']."\">".$content['module']."</a></strong>";
131                 }
132
133                 // Prepare array for the template
134                 // @TODO Rewritings: mod->module in template
135                 $content = array(
136                         'sw'     => $SW,
137                         'id'     => $content['id'],
138                         'mod'    => $content['module'],
139                         'title'  => $content['title'],
140                         'locked' => TRANSLATE_YESNO($content['locked']),
141                         'hidden' => TRANSLATE_YESNO($content['hidden']),
142                         'admin'  => TRANSLATE_YESNO($content['admin_only']),
143                         'mem'    => TRANSLATE_YESNO($content['mem_only']),
144                 );
145
146                 // Load row template
147                 $OUT .= LOAD_TEMPLATE("admin_mods_list_row", true, $content);
148
149                 // Switch colors
150                 $SW = 3 - $SW;
151         }
152
153         // Free memory
154         SQL_FREERESULT($result);
155
156         // @TODO Rewrite this constant
157         define('__MODS_ROWS', $OUT);
158
159         // Load main template
160         LOAD_TEMPLATE("admin_mods_list");
161 }
162
163 //
164 ?>