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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
47 // Normally we want the overview of all registered extensions
51 // Are some extensions submitted?
52 if (isPostRequestElementSet('sel')) {
54 $SEL = countPostSelection();
57 if (isGetRequestElementSet('reg_ext')) {
58 // We are about to register a new extension
59 $do = 'register'; $ext_id = bigintval(getRequestElement('reg_ext'));
60 // The ID comes from task management and it is - of course - *not* the extension's name!
61 } elseif ((isPostRequestElementSet('change')) && ($SEL > 0) && (!isDemoModeActive())) {
62 // De-/activate extensions
63 foreach (postRequestElement('sel') as $ext_id => $active) {
64 // Shall we keep the extension always active?
65 if ((isset($GLOBALS['cache_array']['active_extensions'][getExtensionName($ext_id)])) && ($GLOBALS['cache_array']['active_extensions'][getExtensionName($ext_id)] == 'Y') && ($active != 'Y')) {
66 // Keep this extension active!
68 // De/activate extension
69 $ACT = 'N'; getExtensionMode('deactivate');
70 if ($active != 'Y') { $ACT = 'Y'; setExtensionMode('activate'); }
71 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='".$ACT."' WHERE `id`=%s AND `ext_active`='%s' LIMIT 1",
72 array(bigintval($ext_id), $active), __FILE__, __LINE__);
74 // Run embeded SQL commands
75 doExtensionSqls($ext_id, getExtensionMode());
78 } elseif (((isPostRequestElementSet('edit')) || (isPostRequestElementSet(('modify')))) && ($SEL > 0) && (!isDemoModeActive())) {
79 // Change settings like CSS file load
80 if (isPostRequestElementSet(('modify'))) {
83 foreach (postRequestElement('sel') as $ext_id => $sel) {
85 $ext_id = bigintval($ext_id);
87 // Change this extension?
89 // Load mode is modify
90 getExtensionMode('modify');
92 // Get entry for 'active'
93 $active = postRequestElement('active', $ext_id);
95 // Update extension's record
96 if (getExtensionVersion('sql_patches') >= '0.0.6') {
97 // Update also CSS column when extensions sql_patches is newer or exact v0.0.6
98 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_has_css`='%s', `ext_active`='%s' WHERE `id`=%s LIMIT 1",
99 array(postRequestElement('css', $ext_id), $active, $ext_id), __FILE__, __LINE__);
101 // When extension is older than v0.0.6 there is no column for the CSS information
102 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s LIMIT 1",
103 array($active, $ext_id), __FILE__, __LINE__);
106 // Run SQLs on activation / deactivation
108 case 'Y': setExtensionMode('activate'); break;
109 case 'N': setExtensionMode('deactivate'); break;
112 // Run embeded SQL commands
113 doExtensionSqls($ext_id, getExtensionMode());
117 // Extensions changed
118 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_EXT_CHANGED'));
120 // Edit selected entries
122 foreach (postRequestElement('sel') as $ext_id => $sel) {
123 // Edit this extension?
124 if (($sel == 'Y') || ($sel != 'Y')) {
125 // Default is no CSS for non-updated mailers
128 // Load required data
129 if (getExtensionVersion('sql_patches') >= '0.0.6') {
130 $result = SQL_QUERY_ESC("SELECT ext_has_css, ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
131 array(bigintval($ext_id)), __FILE__, __LINE__);
132 list($css, $active) = SQL_FETCHROW($result);
133 SQL_FREERESULT($result);
135 $result = SQL_QUERY_ESC("SELECT ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
136 array(bigintval($ext_id)), __FILE__, __LINE__);
137 list($active) = SQL_FETCHROW($result);
138 SQL_FREERESULT($result);
143 $cssSelection = '---';
144 if (getExtensionVersion('sql_patches') >= '0.0.6') $cssSelection = addSelectionBox('yn', $css, 'css', $ext_id);
146 // Prepare data for the row template
150 'name' => getExtensionName($ext_id),
151 'active' => addSelectionBox('yn', $active, 'active', $ext_id),
152 'css' => $cssSelection,
155 // Load row template and switch color
156 $OUT .= loadTemplate('admin_extensions_edit_row', true, $content);
162 loadTemplate('admin_extensions_edit', false, $OUT);
165 } elseif ((isPostRequestElementSet('delete')) && ($SEL > 0) && (!isDemoModeActive())) {
166 // List extensions and when verbose is enabled SQL statements which will be executed
168 foreach (postRequestElement('sel') as $ext_id => $sel) {
174 $ext_id = bigintval($ext_id);
177 if (isExtensionIdValid($ext_id)) {
178 // Get extension name
179 $ext_name = getExtensionName($ext_id);
181 if (getConfig('verbose_sql') == 'Y') {
182 // Load SQL commands in remove mode
183 if (loadExtension($ext_name, 'remove', '', true)) {
184 // Generate extra table with loaded SQL commands
185 $VERBOSE_OUT = addExtensionVerboseSqlTable();
189 // Prepare data for the row template
193 'ext_name' => $ext_name,
194 'ext_ver' => getExtensionVersion($ext_name),
195 'verbose' => $VERBOSE_OUT
198 // Load row template and switch color
199 $OUT .= loadTemplate('admin_extensions_delete_row', true, $content);
201 // Prepare data for the row template
208 $OUT .= loadTemplate('admin_extensions_delete_row_404', true, $content);
214 loadTemplate('admin_extensions_delete', false, $OUT);
216 } elseif ((isPostRequestElementSet('remove')) && ($SEL > 0) && (!isDemoModeActive())) {
217 // Remove extensions from DB (you have to delete all files manually!)
219 foreach (postRequestElement('sel') as $ext_id => $active) {
221 $ext_id = bigintval($ext_id);
223 // Is this extension selected and id valid?
224 if (($active == 1) && (isExtensionIdValid($ext_id))) {
225 // Run embeded SQL commands
226 doExtensionSqls($ext_id, 'remove');
230 // Extensions removed
231 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_EXTENSIONS_REMOVED'), $SEL));
232 } elseif ((isGetRequestElementSet('do')) && (!isDemoModeActive())) {
233 // Other things to do
234 $do = SQL_ESCAPE(secureString(getRequestElement('do')));
235 } elseif (isGetRequestElementSet('do')) {
240 // Shall we display active/inactive extensions?
242 if (isGetRequestElementSet(('active'))) {
243 $where = sprintf("WHERE `ext_active`='%s'", SQL_ESCAPE(secureString(getRequestElement('active'))));
248 case 'overview': // List all registered extensions
249 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
250 // Load extension data with CSS informations
251 $result = SQL_QUERY("SELECT `id` AS ext_id, `ext_name`, `ext_active`, `ext_has_css` AS ext_css, `ext_version`
252 FROM `{?_MYSQL_PREFIX?}_extensions`
254 ORDER BY `ext_name` ASC", __FILE__, __LINE__);
256 // Load extension data without CSS informations
257 $result = SQL_QUERY("SELECT `id` AS ext_id, `ext_name`, `ext_active`, `id`, `ext_version`
258 FROM `{?_MYSQL_PREFIX?}_extensions`
260 ORDER BY `ext_name` ASC", __FILE__, __LINE__);
263 // Are there some entries?
264 if (SQL_NUMROWS($result) > 0) {
265 // Extensions are registered
267 while ($content = SQL_FETCHARRAY($result)) {
268 // Prepare CSS selection output
269 $cssSelection = '---';
270 if (getExtensionVersion('sql_patches') >= '0.0.6') $cssSelection = translateYesNo($content['ext_css']);
272 // Prepare data for the row template
275 'id' => $content['ext_id'],
276 'name' => $content['ext_name'],
277 'active' => translateYesNo($content['ext_active']),
278 'act_val' => $content['ext_active'],
279 'css' => $cssSelection,
280 'ver' => $content['ext_version'],
283 // Load row template and switch color
284 $OUT .= loadTemplate('admin_extensions_row', true, $content);
289 SQL_FREERESULT($result);
292 loadTemplate('admin_extensions', false, $OUT);
294 // No extensions are registered
295 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_EXTENSION_REGISTERED'));
299 case 'register': // Register new extension
300 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `assigned_admin`=%s AND `task_type`='EXTENSION' LIMIT 1",
301 array(getCurrentAdminId()), __FILE__, __LINE__);
302 $task_found = SQL_NUMROWS($result);
305 SQL_FREERESULT($result);
307 // Is the ID number valid and the task was found?
308 if (($ext_id > 0) && ($task_found == 1)) {
309 // ID is valid so begin with registration, we first want to it's real name from task management (subject column)
310 $result = SQL_QUERY_ESC("SELECT `subject` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
311 array(bigintval($ext_id)), __FILE__, __LINE__);
312 list($subj) = SQL_FETCHROW($result);
313 SQL_FREERESULT($result);
315 // Disable cache update by default
318 // Extract extension's name from subject...
319 $ext_name = trim(substr($subj, 1, strpos($subj, ':') - 1));
321 // Test the extension for deprecation
322 loadExtension($ext_name, 'test');
324 // Is the extension deprecated?
325 if (!isExtensionDeprecated()) {
326 // ... so we can finally register and load it in registration mode
327 if (registerExtension($ext_name, $ext_id)) {
329 if (getTotalFatalErrors() == 0) {
330 // Extension was found and successfully registered
331 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_EXTENSION_REGISTERED'), $ext_name));
334 if (isExtensionActive('task')) {
335 loadTemplate('admin_next_link', false, array(
336 'url' => 'modules.php?module=admin&what=list_task',
337 'title' => getMessage('ADMIN_EXT_REGISTER_NEXT_LINK')
340 loadTemplate('admin_next_link', false, array(
341 'url' => 'modules.php?module=admin',
342 'title' => getMessage('ADMIN_EXT_REGISTER_NEXT_LINK')
347 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_EXTENSION_NOT_REGISTERED'), $ext_name));
350 // Do we need to update cache file?
351 // @TODO Rewrite this to a filter
352 if (isExtensionActive('cache')) {
353 // Remove cache file (will be auto-created again!)
354 if ($GLOBALS['cache_instance']->loadCacheFile('config')) $GLOBALS['cache_instance']->removeCacheFile();
355 if ($GLOBALS['cache_instance']->loadCacheFile('extension')) $GLOBALS['cache_instance']->removeCacheFile();
356 if ($GLOBALS['cache_instance']->loadCacheFile('modules')) $GLOBALS['cache_instance']->removeCacheFile();
358 } elseif (getExtensionVersion($ext_name) != '') {
359 // Notify the admin that we have a problem here...
360 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_ALREADY'));
362 // Notify the admin that we have a problem here...
363 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_REG_FAILED_404'), $ext_name));
366 // Motify the admin that we have a problem here...
367 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_DEPRECATED'));
370 // Extension was not found in task management
371 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_ID_404'));
373 } elseif ($task_found == 0) {
374 // No longer assigned or old task
375 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_ASSIGED'));
378 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_INVALID'));
383 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_NOT_SAVED'));