2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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
50 if (isGetRequestElementSet('reg_ext')) {
51 // We are about to register a new extension
52 $do = 'register'; $ext_id = bigintval(getRequestElement('reg_ext'));
53 // The id comes from task management and it is - of course - *not* the extension's name!
54 } elseif ((isPostRequestElementSet('change')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
55 // De-/activate extensions
56 foreach (postRequestElement('sel') as $ext_id => $active) {
57 // Shall we keep the extension always active?
58 if ((isset($GLOBALS['cache_array']['always_active'][getExtensionName($ext_id)])) && ($GLOBALS['cache_array']['always_active'][getExtensionName($ext_id)] == 'Y') && ($active == 'Y')) {
59 // Keep this extension active!
60 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_ALWAYS_ACTIVE', getExtensionName($ext_id)));
62 // De/activate extension
63 $ACT = 'N'; setExtensionMode('deactivate');
64 if ($active != 'Y') { $ACT = 'Y'; setExtensionMode('activate'); }
65 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='".$ACT."' WHERE `id`=%s AND `ext_active`='%s' LIMIT 1",
66 array(bigintval($ext_id), $active), __FILE__, __LINE__);
68 // Run embeded SQL commands
69 doExtensionSqls($ext_id, getExtensionMode());
72 } elseif (((isPostRequestElementSet('edit')) || (isPostRequestElementSet('modify'))) && (countPostSelection() > 0) && (!isDemoModeActive())) {
73 // Change settings like CSS file load
74 if (isPostRequestElementSet('modify')) {
77 foreach (postRequestElement('sel') as $ext_id => $sel) {
79 $ext_id = bigintval($ext_id);
81 // Change this extension?
83 // Load mode is modify
84 setExtensionMode('modify');
86 // Get entry for 'active'
87 $active = postRequestElement('active', $ext_id);
89 // Update extension's record
90 if (getExtensionVersion('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(postRequestElement('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': setExtensionMode('activate'); break;
103 case 'N': setExtensionMode('deactivate'); break;
106 // Run embeded SQL commands
107 doExtensionSqls($ext_id, getExtensionMode());
111 // Extensions changed
112 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_EXT_CHANGED'));
114 // Edit selected entries
116 foreach (postRequestElement('sel') as $ext_id => $sel) {
117 // Edit this extension?
118 if (($sel == 'Y') || ($sel != 'Y')) {
119 // Default is no CSS for non-updated mailers
122 // Load required data
123 if (getExtensionVersion('sql_patches') >= '0.0.6') {
124 $result = SQL_QUERY_ESC("SELECT ext_has_css, ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
125 array(bigintval($ext_id)), __FILE__, __LINE__);
126 list($css, $active) = SQL_FETCHROW($result);
127 SQL_FREERESULT($result);
129 $result = SQL_QUERY_ESC("SELECT ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
130 array(bigintval($ext_id)), __FILE__, __LINE__);
131 list($active) = SQL_FETCHROW($result);
132 SQL_FREERESULT($result);
137 $cssSelection = '---';
138 if (getExtensionVersion('sql_patches') >= '0.0.6') $cssSelection = addSelectionBox('yn', $css, 'css', $ext_id);
140 // Prepare data for the row template
144 'name' => getExtensionName($ext_id),
145 'active' => addSelectionBox('yn', $active, 'active', $ext_id),
146 'css' => $cssSelection,
149 // Load row template and switch color
150 $OUT .= loadTemplate('admin_extensions_edit_row', true, $content);
156 loadTemplate('admin_extensions_edit', false, $OUT);
159 } elseif ((isPostRequestElementSet('delete')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
160 // List extensions and when verbose is enabled SQL statements which will be executed
162 foreach (postRequestElement('sel') as $ext_id => $sel) {
168 $ext_id = bigintval($ext_id);
171 if (isExtensionIdValid($ext_id)) {
172 // Get extension name
173 $ext_name = getExtensionName($ext_id);
175 if (getConfig('verbose_sql') == 'Y') {
176 // Load SQL commands in remove mode
177 if (loadExtension($ext_name, 'remove', '', true)) {
178 // Generate extra table with loaded SQL commands
179 $VERBOSE_OUT = addExtensionVerboseSqlTable();
183 // Prepare data for the row template
187 'ext_name' => $ext_name,
188 'ext_ver' => getExtensionVersion($ext_name),
189 'verbose' => $VERBOSE_OUT
192 // Load row template and switch color
193 $OUT .= loadTemplate('admin_extensions_delete_row', true, $content);
195 // Prepare data for the row template
202 $OUT .= loadTemplate('admin_extensions_delete_row_404', true, $content);
208 loadTemplate('admin_extensions_delete', false, $OUT);
210 } elseif ((isPostRequestElementSet('remove')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
211 // Remove extensions from DB (you have to delete all files manually!)
213 foreach (postRequestElement('sel') as $ext_id => $active) {
215 $ext_id = bigintval($ext_id);
217 // Is this extension selected and id valid?
218 if (($active == 1) && (isExtensionIdValid($ext_id))) {
219 // Run embeded SQL commands
220 doExtensionSqls($ext_id, 'remove');
224 // Extensions removed
225 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSIONS_REMOVED', countPostSelection()));
226 } elseif ((isGetRequestElementSet('do')) && (!isDemoModeActive())) {
227 // Other things to do
228 $do = SQL_ESCAPE(secureString(getRequestElement('do')));
229 } elseif (isGetRequestElementSet('do')) {
234 // Shall we display active/inactive extensions?
236 if (isGetRequestElementSet(('active'))) {
237 $where = sprintf("WHERE `ext_active`='%s'", SQL_ESCAPE(secureString(getRequestElement('active'))));
242 case 'overview': // List all registered extensions
243 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
244 // Load extension data with CSS informations
245 $result = SQL_QUERY("SELECT `id` AS ext_id, `ext_name`, `ext_active`, `ext_has_css` AS ext_css, `ext_version`
246 FROM `{?_MYSQL_PREFIX?}_extensions`
248 ORDER BY `ext_name` ASC", __FILE__, __LINE__);
250 // Load extension data without CSS informations
251 $result = SQL_QUERY("SELECT `id` AS ext_id, `ext_name`, `ext_active`, `id`, `ext_version`
252 FROM `{?_MYSQL_PREFIX?}_extensions`
254 ORDER BY `ext_name` ASC", __FILE__, __LINE__);
257 // Are there some entries?
258 if (SQL_NUMROWS($result) > 0) {
259 // Extensions are registered
261 while ($content = SQL_FETCHARRAY($result)) {
262 // Prepare CSS selection output
263 $cssSelection = '---';
264 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) $cssSelection = translateYesNo($content['ext_css']);
266 // Prepare data for the row template
269 'id' => $content['ext_id'],
270 'name' => $content['ext_name'],
271 'active' => translateYesNo($content['ext_active']),
272 'act_val' => $content['ext_active'],
273 'css' => $cssSelection,
274 'ver' => $content['ext_version'],
277 // Load row template and switch color
278 $OUT .= loadTemplate('admin_extensions_row', true, $content);
283 SQL_FREERESULT($result);
286 loadTemplate('admin_extensions', false, $OUT);
288 // No extensions are registered
289 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_EXTENSION_REGISTERED'));
293 case 'register': // Register new extension
294 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `assigned_admin`=%s AND `task_type`='EXTENSION' LIMIT 1",
295 array(getCurrentAdminId()), __FILE__, __LINE__);
296 $task_found = SQL_NUMROWS($result);
299 SQL_FREERESULT($result);
301 // Is the id number valid and the task was found?
302 if (($ext_id > 0) && ($task_found == 1)) {
303 // id is valid so begin with registration, we first want to it's real name from task management (subject column)
304 $result = SQL_QUERY_ESC("SELECT `subject` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
305 array(bigintval($ext_id)), __FILE__, __LINE__);
306 list($subj) = SQL_FETCHROW($result);
309 SQL_FREERESULT($result);
311 // Disable cache update by default
314 // Extract extension's name from subject...
315 $ext_name = trim(substr($subj, 1, strpos($subj, ':') - 1));
317 // Test the extension for deprecation
318 loadExtension($ext_name, 'test');
320 // Is the extension deprecated?
321 if (!isExtensionDeprecated()) {
322 // ... so we can finally register and load it in registration mode
323 if (registerExtension($ext_name, $ext_id)) {
325 if (getTotalFatalErrors() == '0') {
326 // Extension was found and successfully registered
327 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_REGISTERED', $ext_name));
330 if (isExtensionActive('task')) {
331 loadTemplate('admin_next_link', false, array(
332 'url' => 'modules.php?module=admin&what=list_task',
333 'title' => getMessage('ADMIN_EXT_REGISTER_NEXT_LINK')
336 loadTemplate('admin_next_link', false, array(
337 'url' => 'modules.php?module=admin',
338 'title' => getMessage('ADMIN_EXT_REGISTER_NEXT_LINK')
343 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_NOT_REGISTERED', $ext_name));
346 // Do we need to update cache file?
347 // @TODO Rewrite this to a filter
348 if (isExtensionActive('cache')) {
349 // Remove cache file (will be auto-created again!)
350 if ($GLOBALS['cache_instance']->loadCacheFile('config')) $GLOBALS['cache_instance']->removeCacheFile();
351 if ($GLOBALS['cache_instance']->loadCacheFile('extension')) $GLOBALS['cache_instance']->removeCacheFile();
352 if ($GLOBALS['cache_instance']->loadCacheFile('modules')) $GLOBALS['cache_instance']->removeCacheFile();
354 } elseif (getExtensionVersion($ext_name) != '') {
355 // Notify the admin that we have a problem here...
356 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_ALREADY'));
358 // Notify the admin that we have a problem here...
359 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_REG_FAILED_404', $ext_name));
362 // Motify the admin that we have a problem here...
363 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_DEPRECATED'));
366 // Extension was not found in task management
367 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_ID_404'));
369 } elseif ($task_found == '0') {
370 // No longer assigned or old task
371 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_ASSIGED'));
374 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_INVALID'));
379 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_NOT_SAVED'));