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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
48 // Normally we want the overview of all registered extensions
51 if (isGetRequestParameterSet('reg_ext')) {
52 // We are about to register a new extension
53 $do = 'register'; $ext_id = bigintval(getRequestParameter('reg_ext'));
54 // The id comes from task management and it is - of course - *not* the extension's name!
55 } elseif ((isFormSent('change')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
56 // De-/activate extensions
57 foreach (postRequestParameter('sel') as $ext_id => $active) {
58 // Shall we keep the extension always active?
59 if ((isset($GLOBALS['cache_array']['always_active'][getExtensionName($ext_id)])) && ($GLOBALS['cache_array']['always_active'][getExtensionName($ext_id)] == 'Y') && ($active == 'Y')) {
60 // Keep this extension active!
61 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_ALWAYS_ACTIVE', getExtensionName($ext_id)));
63 // De/activate extension
64 $ACT = 'N'; setExtensionMode('deactivate');
65 if ($active != 'Y') { $ACT = 'Y'; setExtensionMode('activate'); }
66 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s AND `ext_active`='%s' LIMIT 1",
67 array($ACT, bigintval($ext_id), $active), __FILE__, __LINE__);
69 // Run embeded SQL commands
70 doExtensionSqls($ext_id, getExtensionMode());
74 // Redirect to prevent missing cache in js.php
75 redirectToUrl('modules.php?module=admin&what=extensions&changed=' . countPostSelection());
76 } elseif (((isFormSent('edit')) || (isPostRequestParameterSet('modify'))) && (countPostSelection() > 0) && (!isDemoModeActive())) {
77 // Change settings like CSS file load
78 if (isPostRequestParameterSet('modify')) {
81 foreach (postRequestParameter('sel') as $ext_id => $sel) {
83 $ext_id = bigintval($ext_id);
85 // Change this extension?
87 // Load mode is modify
88 setExtensionMode('modify');
90 // Get entry for 'active'
91 $active = postRequestParameter('active', $ext_id);
93 // Update extension's record
94 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
95 // Update also CSS column when extensions sql_patches is newer or exact v0.0.6
96 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_has_css`='%s', `ext_active`='%s' WHERE `id`=%s LIMIT 1",
97 array(postRequestParameter('css', $ext_id), $active, $ext_id), __FILE__, __LINE__);
99 // When extension is older than v0.0.6 there is no column for the CSS information
100 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s LIMIT 1",
101 array($active, $ext_id), __FILE__, __LINE__);
104 // Run SQLs on activation / deactivation
106 case 'Y': setExtensionMode('activate'); break;
107 case 'N': setExtensionMode('deactivate'); break;
110 // Run embeded SQL commands
111 doExtensionSqls($ext_id, getExtensionMode());
115 // Redirect to prevent missing cache in js.php
116 redirectToUrl('modules.php?module=admin&what=extensions&edited=' . countPostSelection());
118 // Edit selected entries
120 foreach (postRequestParameter('sel') as $ext_id => $sel) {
121 // Edit this extension?
122 if (($sel == 'Y') || ($sel != 'Y')) {
123 // Default is no CSS for non-updated mailers
126 // Load required data
127 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
128 $result = SQL_QUERY_ESC("SELECT ext_has_css, ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
129 array(bigintval($ext_id)), __FILE__, __LINE__);
130 list($css, $active) = SQL_FETCHROW($result);
131 SQL_FREERESULT($result);
133 $result = SQL_QUERY_ESC("SELECT ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
134 array(bigintval($ext_id)), __FILE__, __LINE__);
135 list($active) = SQL_FETCHROW($result);
136 SQL_FREERESULT($result);
140 // Prepare CSS column
141 $cssSelection = '---';
142 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
143 $cssSelection = addSelectionBox('yn', $css, 'css', $ext_id);
146 // Prepare data for the row template
149 'name' => getExtensionName($ext_id),
150 'active' => addSelectionBox('yn', $active, 'active', $ext_id),
151 'css' => $cssSelection,
154 // Load row template and switch color
155 $OUT .= loadTemplate('admin_extensions_edit_row', true, $content);
160 loadTemplate('admin_extensions_edit', false, $OUT);
163 } elseif ((isPostRequestParameterSet('delete')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
164 // List extensions and when verbose is enabled SQL statements which will be executed
166 foreach (postRequestParameter('sel') as $ext_id => $sel) {
172 $ext_id = bigintval($ext_id);
175 if (isExtensionIdValid($ext_id)) {
176 // Get extension name
177 $ext_name = getExtensionName($ext_id);
179 if (getConfig('verbose_sql') == 'Y') {
180 // Load SQL commands in remove mode
181 if (loadExtension($ext_name, 'remove', '', true)) {
182 // Generate extra table with loaded SQL commands
183 $VERBOSE_OUT = addExtensionVerboseSqlTable();
187 // Prepare data for the row template
190 'ext_name' => $ext_name,
191 'ext_ver' => getExtensionVersion($ext_name),
192 'verbose' => $VERBOSE_OUT
195 // Load row template and switch color
196 $OUT .= loadTemplate('admin_extensions_delete_row', true, $content);
198 // Prepare data for the row template
204 $OUT .= loadTemplate('admin_extensions_delete_row_404', true, $content);
209 loadTemplate('admin_extensions_delete', false, $OUT);
211 } elseif ((isFormSent('remove')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
212 // Remove extensions from DB (you have to delete all files manually!)
214 foreach (postRequestParameter('sel') as $ext_id => $active) {
216 $ext_id = bigintval($ext_id);
218 // Is this extension selected and id valid?
219 if (($active == 1) && (isExtensionIdValid($ext_id))) {
220 // Run embeded SQL commands
221 doExtensionSqls($ext_id, 'remove');
225 // Redirect to prevent missing cache in js.php
226 redirectToUrl('modules.php?module=admin&what=extensions&removed=' . countPostSelection());
227 } elseif ((isGetRequestParameterSet('do')) && (!isDemoModeActive())) {
228 // Other things to do
229 $do = SQL_ESCAPE(secureString(getRequestParameter('do')));
230 } elseif (isGetRequestParameterSet('do')) {
233 } elseif (isGetRequestParameterSet('changed')) {
234 // Extensions changed
235 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_CHANGED', bigintval(getRequestParameter('changed'))));
236 } elseif (isGetRequestParameterSet('edited')) {
237 // Extensions changed
238 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_EDITED', bigintval(getRequestParameter('edited'))));
239 } elseif (isGetRequestParameterSet('removed')) {
240 // Extensions changed
241 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSIONS_REMOVED', bigintval(getRequestParameter('removed'))));
244 // Shall we display active/inactive extensions?
246 if (isGetRequestParameterSet(('active'))) {
247 $where = sprintf("WHERE `ext_active`='%s'", SQL_ESCAPE(secureString(getRequestParameter('active'))));
252 case 'overview': // List all registered extensions
253 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
254 // Load extension data with CSS informations
255 $result = SQL_QUERY("SELECT
256 `id` AS ext_id, `ext_name`, `ext_active`, `ext_has_css` AS ext_css, `ext_version`
258 `{?_MYSQL_PREFIX?}_extensions`
261 `ext_name` ASC", __FILE__, __LINE__);
263 // Load extension data without CSS informations
264 $result = SQL_QUERY("SELECT
265 `id` AS ext_id, `ext_name`, `ext_active, `ext_version`
267 `{?_MYSQL_PREFIX?}_extensions`
270 `ext_name` ASC", __FILE__, __LINE__);
273 // Are there some entries?
274 if (SQL_NUMROWS($result) > 0) {
275 // Extensions are registered
277 while ($content = SQL_FETCHARRAY($result)) {
278 // Prepare CSS selection output
279 $cssSelection = '---';
280 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) $cssSelection = translateYesNo($content['ext_css']);
282 // Prepare data for the row template
283 $content['ext_css'] = $cssSelection;
285 // Load row template and switch color
286 $OUT .= loadTemplate('admin_extensions_row', true, $content);
290 SQL_FREERESULT($result);
293 loadTemplate('admin_extensions', false, $OUT);
295 // No extensions are registered
296 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_EXTENSION_REGISTERED--}');
300 case 'register': // Register new extension
301 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `assigned_admin`=%s AND `task_type`='EXTENSION' LIMIT 1",
302 array(getCurrentAdminId()), __FILE__, __LINE__);
303 $task_found = SQL_NUMROWS($result);
306 SQL_FREERESULT($result);
308 // Is the id number valid and the task was found?
309 if (($ext_id > 0) && ($task_found == 1)) {
310 // id is valid so begin with registration, we first want to it's real name from task management (subject column)
311 $result = SQL_QUERY_ESC("SELECT `subject` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
312 array(bigintval($ext_id)), __FILE__, __LINE__);
313 list($subject) = SQL_FETCHROW($result);
316 SQL_FREERESULT($result);
318 // Disable cache update by default
320 if (!empty($subject)) {
321 // Extract extension's name from subject...
322 $ext_name = trim(substr($subject, 1, strpos($subject, ':') - 1));
324 // Test the extension for deprecation
325 loadExtension($ext_name, 'test');
327 // Is the extension deprecated?
328 if (!isExtensionDeprecated()) {
329 // ... so we can finally register and load it in registration mode
330 if (registerExtension($ext_name, $ext_id)) {
332 if (!ifFatalErrorsDetected()) {
333 // Extension was found and successfully registered
334 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_REGISTERED', $ext_name));
337 if (isExtensionActive('task')) {
338 loadTemplate('admin_next_link', false, array(
339 'url' => 'modules.php?module=admin&what=list_task',
340 'title' => '{--ADMIN_EXTENSION_REGISTER_NEXT_LINK--}'
343 loadTemplate('admin_next_link', false, array(
344 'url' => 'modules.php?module=admin',
345 'title' => '{--ADMIN_EXTENSION_REGISTER_NEXT_LINK--}'
350 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_NOT_REGISTERED', $ext_name));
353 // Do we need to update cache file?
354 // @TODO Rewrite this to a filter
355 if (isExtensionActive('cache')) {
356 // Remove cache file (will be auto-created again!)
357 if ($GLOBALS['cache_instance']->loadCacheFile('config')) $GLOBALS['cache_instance']->removeCacheFile();
358 if ($GLOBALS['cache_instance']->loadCacheFile('extension')) $GLOBALS['cache_instance']->removeCacheFile();
359 if ($GLOBALS['cache_instance']->loadCacheFile('filter')) $GLOBALS['cache_instance']->removeCacheFile();
360 if ($GLOBALS['cache_instance']->loadCacheFile('modules')) $GLOBALS['cache_instance']->removeCacheFile();
362 } elseif (isExtensionInstalled($ext_name)) {
363 // Notify the admin that we have a problem here...
364 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ALREADY--}');
366 // Notify the admin that we have a problem here...
367 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_REGISTRATION_FAILED_404', $ext_name));
370 // Motify the admin that we have a problem here...
371 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_DEPRECATED--}');
374 // Extension was not found in task management
375 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ID_404--}');
377 } elseif ($task_found == '0') {
378 // No longer assigned or old task
379 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ASSIGED--}');
382 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_INVALID--}');
387 loadTemplate('admin_settings_saved', false, '{--SETTINGS_NOT_SAVED--}');