Complete rewrite of and , wrapper functions added, see bug #101
[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         // Change modules
88         foreach (REQUEST_POST('sel') as $id => $sel) {
89                 // Secure ID number
90                 $id = bigintval($id);
91
92                 // Update module
93                 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",
94                         array(
95                                 REQUEST_POST('title', $id),
96                                 REQUEST_POST('locked', $id),
97                                 REQUEST_POST('hidden', $id),
98                                 REQUEST_POST('admin', $id),
99                                 REQUEST_POST('member', $id),
100                                 $id
101                         ),  __FILE__, __LINE__);
102         }
103
104         // Remove cache file if version matches
105         if (GET_EXT_VERSION("cache") >= "0.1.2") {
106                 if ($GLOBALS['cache_instance']->loadCacheFile("mod_reg")) $GLOBALS['cache_instance']->destroyCacheFile();
107         }
108
109         // Entries updated
110         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MODS_CHANGED'));
111 }
112
113 if ($SEL == 0) {
114         // Load module data (We do not need to check if there's at least one...)
115         $result = SQL_QUERY("SELECT id, module, locked, hidden, admin_only, title, mem_only, clicks
116 FROM `{!_MYSQL_PREFIX!}_mod_reg`
117 ORDER BY module", __FILE__, __LINE__);
118         $OUT = ""; $SW = 2;
119         while (list($id, $mod, $locked, $hidden, $admin, $title, $mem) = SQL_FETCHROW($result)) {
120                 // Reset title to --- if it is NULL
121                 if (empty($title)) $title = "---";
122                 if (($mod == "index") || ($mod == "login")) {
123                         // Add link to detail statistics
124                         $mod = "<strong><a href=\"{!URL!}/modules.php?module=admin&amp;what=stats_mods&amp;mod=".$mod."\">".$mod."</a></strong>";
125                 }
126
127                 // Prepare array for the template
128                 $content = array(
129                         'sw'     => $SW,
130                         'id'     => $id,
131                         'mod'    => $mod,
132                         'title'  => $title,
133                         'locked' => TRANSLATE_YESNO($locked),
134                         'hidden' => TRANSLATE_YESNO($hidden),
135                         'admin'  => TRANSLATE_YESNO($admin),
136                         'mem'    => TRANSLATE_YESNO($mem),
137                 );
138
139                 // Load row template
140                 $OUT .= LOAD_TEMPLATE("admin_mods_list_row", true, $content);
141
142                 // Switch colors
143                 $SW = 3 - $SW;
144         }
145
146         // Free memory
147         SQL_FREERESULT($result);
148         define('__MODS_ROWS', $OUT);
149
150         // Load main template
151         LOAD_TEMPLATE("admin_mods_list");
152 }
153
154 //
155 ?>