2 /************************************************************************
3 * MXChange v0.2.1 Start: 03/22/2004 *
4 * ================ Last change: 12/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-extentions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Extension management *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Erweiterungen-Management *
12 * -------------------------------------------------------------------- *
14 * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. Mär 2009) $ *
15 * $Tag:: 0.2.1-FINAL $ *
16 * $Author:: stelzi $ *
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 - 2008 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
45 // Add description as navigation point
46 ADD_DESCR("admin", __FILE__);
48 // Normally we want the overview of all registered extensions
51 if (REQUEST_ISSET_POST('sel')) $SEL = SELECTION_COUNT(REQUEST_POST('sel'));
53 if (REQUEST_ISSET_GET(('reg_ext'))) {
54 // We are about to register a new extension
55 $do = "register"; $ext_id = bigintval(REQUEST_GET('reg_ext'));
56 // The ID comes from task management and it is - of course - *not* the extension's name!
57 } elseif ((REQUEST_ISSET_POST(('change'))) && ($SEL > 0) && (!IS_DEMO())) {
58 // De-/activate extensions
59 foreach (REQUEST_POST('sel') as $ext_id => $active) {
60 // Shall we keep the extension always active?
61 if ((isset($GLOBALS['cache_array']['active_extensions'][GET_EXT_NAME($ext_id)])) && ($GLOBALS['cache_array']['active_extensions'][GET_EXT_NAME($ext_id)] == "Y") && ($active == "N")) {
62 // Keep this extension active!
64 // De/activate extension
65 $ACT = "N"; $EXT_LOAD_MODE = "deactivate";
66 if ($active == "N") { $ACT = "Y"; $EXT_LOAD_MODE = "activate"; }
67 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_active='".$ACT."' WHERE id=%s AND ext_active='%s' LIMIT 1",
68 array(bigintval($ext_id), $active), __FILE__, __LINE__);
70 // Run embeded SQL commands
71 EXTENSION_RUN_SQLS($ext_id, $EXT_LOAD_MODE);
74 } elseif (((REQUEST_ISSET_POST('edit')) || (REQUEST_ISSET_POST(('modify')))) && ($SEL > 0) && (!IS_DEMO())) {
75 // Change settings like CSS file load
76 if (REQUEST_ISSET_POST(('modify'))) {
79 foreach (REQUEST_POST('sel') as $ext_id => $sel) {
81 $ext_id = bigintval($ext_id);
83 // Change this extension?
85 // Load mode is modify
86 $EXT_LOAD_MODE = "modify";
88 // Update extension's record
89 $active = REQUEST_POST('active', $ext_id);
90 if (GET_EXT_VERSION("sql_patches") >= "0.0.6") {
91 // Update also CSS column when extensions sql_patches is newer or exact v0.0.6
92 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_has_css='%s', ext_active='%s' WHERE id=%s LIMIT 1",
93 array(REQUEST_POST('css', $ext_id), $active, $ext_id), __FILE__, __LINE__);
95 // When extension is older than v0.0.6 there is no column for the CSS information
96 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_active='%s' WHERE id=%s LIMIT 1",
97 array($active, $ext_id), __FILE__, __LINE__);
100 // Run SQLs on activation / deactivation
102 case "Y": $EXT_LOAD_MODE = "activate"; break;
103 case "N": $EXT_LOAD_MODE = "deactivate"; break;
106 // Run embeded SQL commands
107 EXTENSION_RUN_SQLS($ext_id, $EXT_LOAD_MODE);
111 // Extensions changed
112 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_EXT_CHANGED'));
114 // Edit selected entries
115 $SW = "2"; $OUT = "";
116 foreach (REQUEST_POST('sel') as $ext_id => $sel) {
117 // Edit this extension?
118 if (($sel == "Y") || ($sel == "N")) {
119 // Load required data
120 if (GET_EXT_VERSION("sql_patches") >= "0.0.6") {
121 $result = SQL_QUERY_ESC("SELECT ext_name, ext_has_css, ext_active FROM `{!_MYSQL_PREFIX!}_extensions` WHERE id=%s LIMIT 1",
122 array(bigintval($ext_id)), __FILE__, __LINE__);
123 list($name, $css, $active) = SQL_FETCHROW($result);
124 SQL_FREERESULT($result);
126 $result = SQL_QUERY_ESC("SELECT ext_name, ext_active FROM `{!_MYSQL_PREFIX!}_extensions` WHERE id=%s LIMIT 1",
127 array(bigintval($ext_id)), __FILE__, __LINE__);
128 list($name, $active) = SQL_FETCHROW($result);
129 SQL_FREERESULT($result);
134 $cssSelection = "---";
135 if (GET_EXT_VERSION("sql_patches") >= "0.0.6") $cssSelection = ADD_SELECTION("yn", $css, "css", $ext_id);
137 // Prepare data for the row template
142 'active' => ADD_SELECTION("yn", $active, "active", $ext_id),
143 'css' => $cssSelection,
146 // Load row template and switch color
147 $OUT .= LOAD_TEMPLATE("admin_extensions_edit_row", true, $content);
151 define('__EXTENSIONS_ROWS', $OUT);
154 LOAD_TEMPLATE("admin_extensions_edit");
157 } elseif ((REQUEST_ISSET_POST(('delete'))) && ($SEL > 0) && (!IS_DEMO())) {
158 // List extensions and when verbose is enabled SQL statements which will be executed
160 foreach (REQUEST_POST('sel') as $ext_id => $sel) {
162 $VERBOSE_OUT = ""; INIT_SQLS();
165 $ext_id = bigintval($ext_id);
167 // Get extension name
168 $ext_name = GET_EXT_NAME($ext_id);
170 if (getConfig('verbose_sql') == "Y") {
171 // Load SQL commands in remove mode
172 if (LOAD_EXTENSION($ext_name, "remove", "", true)) {
173 // Generate extra table with loaded SQL commands
174 $VERBOSE_OUT = EXTENSION_VERBOSE_TABLE();
178 // Prepare data for the row template
182 'ext_name' => $ext_name,
183 'ext_ver' => GET_EXT_VERSION($ext_name),
184 'verbose' => $VERBOSE_OUT
187 // Load row template and switch color
188 $OUT .= LOAD_TEMPLATE("admin_extensions_delete_row", true, $content);
191 define('__EXTENSIONS_ROWS', $OUT);
194 LOAD_TEMPLATE("admin_extensions_delete");
196 } elseif ((REQUEST_ISSET_POST(('remove'))) && ($SEL > 0) && (!IS_DEMO())) {
197 // Remove extensions from DB (you have to delete all files manually!)
199 foreach (REQUEST_POST('sel') as $ext_id => $active) {
201 $ext_id = bigintval($ext_id);
203 // Is this extension selected?
205 // Run any assigned removal filters
206 runFilterChain('extension_remove', GET_EXT_NAME($ext_id));
208 // Run embeded SQL commands
209 EXTENSION_RUN_SQLS($ext_id, "remove");
212 } elseif (REQUEST_ISSET_GET(('do')) && (!IS_DEMO())) {
213 // Other things to do
214 $do = SQL_ESCAPE(strip_tags(REQUEST_GET('do')));
215 } elseif (REQUEST_ISSET_GET(('do'))) {
220 // Shall we display active/inactive extensions?
222 if (REQUEST_ISSET_GET(('active'))) {
223 $where = sprintf("WHERE ext_active = '%s'", SQL_ESCAPE(strip_tags(REQUEST_GET('active'))));
228 case "overview": // List all registered extensions
229 if (GET_EXT_VERSION("sql_patches") >= "0.0.6") {
230 // Load extension data with CSS informations
231 $result = SQL_QUERY("SELECT id AS ext_id, ext_name, ext_active, ext_has_css AS ext_css, ext_version
232 FROM `{!_MYSQL_PREFIX!}_extensions`
234 ORDER BY ext_name", __FILE__, __LINE__);
236 // Load extension data without CSS informations
237 $result = SQL_QUERY("SELECT id AS ext_id, ext_name, ext_active, id, ext_version
238 FROM `{!_MYSQL_PREFIX!}_extensions`
240 ORDER BY ext_name", __FILE__, __LINE__);
243 // Are there some entries?
244 if (SQL_NUMROWS($result) > 0) {
245 // Extensions are registered
247 while ($content = SQL_FETCHARRAY($result)) {
248 // Prepare CSS selection output
249 $cssSelection = "---";
250 if (GET_EXT_VERSION("sql_patches") >= "0.0.6") $cssSelection = TRANSLATE_YESNO($content['ext_css']);
252 // Prepare data for the row template
255 'id' => $content['ext_id'],
256 'name' => $content['ext_name'],
257 'active' => TRANSLATE_YESNO($content['ext_active']),
258 'act_val' => $content['ext_active'],
259 'css' => $cssSelection,
260 'ver' => $content['ext_version'],
263 // Load row template and switch color
264 $OUT .= LOAD_TEMPLATE("admin_extensions_row", true, $content);
269 SQL_FREERESULT($result);
271 // Remember rows in constant for the template
272 define('__EXT_ROWS', $OUT);
275 LOAD_TEMPLATE("admin_extensions");
277 // No extensions are registered
278 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_NO_EXTENSION_REGISTERED'));
282 case "register": // Register new extension
283 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_task_system` WHERE assigned_admin=%s AND task_type='EXTENSION' LIMIT 1",
284 array(GET_CURRENT_ADMIN_ID()), __FILE__, __LINE__);
285 $task_found = SQL_NUMROWS($result);
288 SQL_FREERESULT($result);
290 // Is the ID number valid and the task was found?
291 if (($ext_id > 0) && ($task_found == 1)) {
292 // ID is valid so begin with registration, we first want to it's real name from task management (subject column)
293 $result = SQL_QUERY_ESC("SELECT subject FROM `{!_MYSQL_PREFIX!}_task_system` WHERE id=%s LIMIT 1",
294 array(bigintval($ext_id)), __FILE__, __LINE__);
295 list($subj) = SQL_FETCHROW($result);
296 SQL_FREERESULT($result);
298 // Disable cache update by default
301 // Extract extension's name from subject...
302 $ext_name = trim(substr($subj, 1, strpos($subj, ":") - 1));
304 // Test the extension for deprecation
305 LOAD_EXTENSION($ext_name, "test");
307 // Is the extension deprecated?
308 if (EXT_GET_DEPRECATED() == "N") {
309 // ... so we can finally register and load it in registration mode
310 if (EXTENSION_REGISTER($ext_name, $ext_id)) {
311 // Extension was found and successfully registered
312 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_EXTENSION_REGISTERED'));
315 if (EXT_IS_ACTIVE("task")) {
316 LOAD_TEMPLATE("admin_next_link", false, array(
317 'url' => "modules.php?module=admin&what=list_task",
318 'title' => getMessage('ADMIN_EXT_REGISTER_NEXT_LINK')
321 LOAD_TEMPLATE("admin_next_link", false, array(
322 'url' => "modules.php?module=admin",
323 'title' => getMessage('ADMIN_EXT_REGISTER_NEXT_LINK')
327 // Do we need to update cache file?
328 if ((EXT_IS_ACTIVE("cache")) && ($GLOBALS['cache_mode'] != "no")) {
329 // Remove cache file (will be auto-created again!)
330 if ($GLOBALS['cache_instance']->loadCacheFile("config")) $GLOBALS['cache_instance']->destroyCacheFile();
331 if ($GLOBALS['cache_instance']->loadCacheFile("extensions", true)) $GLOBALS['cache_instance']->destroyCacheFile();
332 if ($GLOBALS['cache_instance']->loadCacheFile("modreg")) $GLOBALS['cache_instance']->destroyCacheFile();
334 } elseif (GET_EXT_VERSION($ext_name) != "") {
335 // Notify the admin that we have a problem here...
336 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_REG_FAILED_ALREADY'));
338 // Notify the admin that we have a problem here...
339 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('ADMIN_REG_FAILED_404'), $ext_name));
342 // Motify the admin that we have a problem here...
343 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_REG_FAILED_DEPRECATED'));
346 // Extension was not found in task management
347 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_REG_FAILED_ID_404'));
349 } elseif ($task_found == "0") {
350 // No longer assigned or old task
351 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_REG_FAILED_ASSIGED'));
354 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_REG_FAILED_INVALID'));
359 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_NOT_SAVED'));