New functions introduced, several rewrites:
[mailer.git] / inc / modules / admin / what-config_mods.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * $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 at least one module is selected
49         if (countPostSelection() > 0) {
50                 // Output header
51                 $OUT = ''; $SW = 2;
52
53                 // Edit selected modules
54                 foreach (postRequestElement('sel') as $id => $sel) {
55                         // Load module data
56                         // @TODO This can be moved into mysql-function.php, see checkModulePermissions() function
57                         $result = SQL_QUERY_ESC("SELECT `module`, `title`, `locked`, `hidden`, `admin_only`, `mem_only` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `id`=%s LIMIT 1",
58                                 array(bigintval($id)), __FILE__, __LINE__);
59
60                         // Load data
61                         $data = SQL_FETCHARRAY($result);
62
63                         // Free result
64                         SQL_FREERESULT($result);
65
66                         // Prepare array for the template
67                         $content = array(
68                                 'sw'     => $SW,
69                                 'mod'    => $data['module'],
70                                 'id'     => $id,
71                                 'title'  => $data['title'],
72                                 'locked' => addSelectionBox('yn', $data['locked']    , 'locked', $id),
73                                 'hidden' => addSelectionBox('yn', $data['hidden']    , 'hidden', $id),
74                                 'admin'  => addSelectionBox('yn', $data['admin_only'], 'admin' , $id),
75                                 'mem'    => addSelectionBox('yn', $data['mem_only']  , 'member', $id),
76                         );
77
78                         // Load row template
79                         $OUT .= loadTemplate('admin_mods_edit_row', true, $content);
80                 } // END - foreach
81
82                 // Load main template
83                 loadTemplate('admin_mods_edit', false, $OUT);
84         } else {
85                 // Nothing selected
86                 loadTemplate('admin_settings_saved', false, getMessage('MODS_NOTHING_SELECTED'));
87
88                 // Remove maybe confusing data
89                 unsetPostRequestElement('edit');
90                 unsetPostRequestElement('change');
91         }
92 } elseif (isPostRequestElementSet('change')) {
93         // Init SQLs
94         initSqls();
95
96         // Change modules
97         foreach (postRequestElement('sel') as $id => $sel) {
98                 // Secure id number
99                 $id = bigintval($id);
100
101                 // Update module
102                 addSql(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",
103                         array(
104                                 postRequestElement('title', $id),
105                                 postRequestElement('locked', $id),
106                                 postRequestElement('hidden', $id),
107                                 postRequestElement('admin', $id),
108                                 postRequestElement('member', $id),
109                                 $id
110                         ),  __FILE__, __LINE__, false));
111         }
112
113         // Run all sqls
114         runFilterChain('run_sqls');
115
116         // Remove cache file if version matches
117         if (getExtensionVersion('cache') >= '0.1.2') {
118                 if ($GLOBALS['cache_instance']->loadCacheFile('modules')) $GLOBALS['cache_instance']->removeCacheFile();
119         } // END - if
120
121         // Entries updated
122         loadTemplate('admin_settings_saved', false, getMessage('MODS_CHANGED'));
123 }
124
125 if (countPostSelection() == '0') {
126         // Load module data (We do not need to check if there's at least one...)
127         $result = SQL_QUERY('SELECT id, module, locked, hidden, admin_only, title, mem_only
128 FROM `{?_MYSQL_PREFIX?}_mod_reg`
129 ORDER BY module', __FILE__, __LINE__);
130         $OUT = ''; $SW = 2;
131         while ($content = SQL_FETCHARRAY($result)) {
132                 // Reset title to --- if it is NULL
133                 if (empty($content['title'])) $content['title'] = '---';
134                 if (($content['module'] == 'index') || ($content['module'] == 'login')) {
135                         // Add link to detail statistics
136                         $content['module'] = "<strong><a href=\"{%url=modules.php?module=admin&amp;what=stats_mods&amp;mod=" . $content['module'] . "%}\">" . $content['module'] . "</a></strong>";
137                 } // END - if
138
139                 // Prepare array for the template
140                 // @TODO Rewritings: mod->module in template
141                 $content = array(
142                         'sw'     => $SW,
143                         'id'     => $content['id'],
144                         'mod'    => $content['module'],
145                         'title'  => $content['title'],
146                         'locked' => translateYesNo($content['locked']),
147                         'hidden' => translateYesNo($content['hidden']),
148                         'admin'  => translateYesNo($content['admin_only']),
149                         'mem'    => translateYesNo($content['mem_only']),
150                 );
151
152                 // Load row template
153                 $OUT .= loadTemplate('admin_list_mods_row', true, $content);
154
155                 // Switch colors
156                 $SW = 3 - $SW;
157         }
158
159         // Free memory
160         SQL_FREERESULT($result);
161
162         // Load main template
163         loadTemplate('admin_list_mods', false, $OUT);
164 }
165
166 // [EOF]
167 ?>