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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
46 // Normally we want the overview of all registered extensions
49 if (isGetRequestParameterSet('reg_ext')) {
50 // We are about to register a new extension
52 $taskId = determineExtensionTaskId(getRequestParameter('reg_ext'));
54 // The id comes from task management and it is - of course - *not* the extension's name!
55 } elseif ((isFormSent('change')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
56 // De-/activate extensions
57 foreach (postRequestParameter('sel') as $ext_id => $ext_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') && ($ext_active == 'Y')) {
60 // Keep this extension active!
61 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_ALWAYS_ACTIVE', getExtensionName($ext_id)));
63 // Deactivation is default
65 setExtensionMode('deactivate');
67 // Is the extension deactivated?
68 if ($ext_active != 'Y') {
69 // Then we can activate it
71 setExtensionMode('activate');
75 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s AND `ext_active`='%s' LIMIT 1",
76 array($active, bigintval($ext_id), $ext_active), __FILE__, __LINE__);
78 // Run embeded SQL commands
79 doExtensionSqls($ext_id, getExtensionMode());
83 // Redirect to prevent missing cache in js.php
84 redirectToUrl('modules.php?module=admin&what=extensions&changed=' . countPostSelection());
85 } elseif (((isFormSent('edit')) || (isPostRequestParameterSet('modify'))) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
86 // Change settings like CSS file load
87 if (isPostRequestParameterSet('modify')) {
90 foreach (postRequestParameter('sel') as $ext_id => $sel) {
92 $ext_id = bigintval($ext_id);
94 // Change this extension?
96 // Load mode is modify
97 setExtensionMode('modify');
99 // Get entry for 'active'
100 $active = postRequestParameter('active', $ext_id);
102 // Update extension's record
103 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
104 // Update also CSS column when extensions sql_patches is newer or exact v0.0.6
105 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_has_css`='%s', `ext_active`='%s' WHERE `id`=%s LIMIT 1",
106 array(postRequestParameter('css', $ext_id), $active, $ext_id), __FILE__, __LINE__);
108 // When extension is older than v0.0.6 there is no column for the CSS information
109 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s LIMIT 1",
110 array($active, $ext_id), __FILE__, __LINE__);
113 // Run SQLs on activation / deactivation
115 case 'Y': setExtensionMode('activate'); break;
116 case 'N': setExtensionMode('deactivate'); break;
119 // Run embeded SQL commands
120 doExtensionSqls($ext_id, getExtensionMode());
124 // Redirect to prevent missing cache in js.php
125 redirectToUrl('modules.php?module=admin&what=extensions&edited=' . countPostSelection());
127 // Edit selected entries
129 foreach (postRequestParameter('sel') as $ext_id => $sel) {
130 // Edit this extension?
131 if (($sel == 'Y') || ($sel != 'Y')) {
132 // Default is no CSS for non-updated mailers
135 // Load required data
136 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
137 $result = SQL_QUERY_ESC("SELECT ext_has_css, ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
138 array(bigintval($ext_id)), __FILE__, __LINE__);
139 list($css, $active) = SQL_FETCHROW($result);
140 SQL_FREERESULT($result);
142 $result = SQL_QUERY_ESC("SELECT ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
143 array(bigintval($ext_id)), __FILE__, __LINE__);
144 list($active) = SQL_FETCHROW($result);
145 SQL_FREERESULT($result);
149 // Prepare CSS column
150 $cssSelection = '---';
151 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
152 $cssSelection = addSelectionBox('yn', $css, 'css', $ext_id);
155 // Prepare data for the row template
158 'name' => getExtensionName($ext_id),
159 'active' => addSelectionBox('yn', $active, 'active', $ext_id),
160 'css' => $cssSelection,
163 // Load row template and switch color
164 $OUT .= loadTemplate('admin_extensions_edit_row', true, $content);
169 loadTemplate('admin_extensions_edit', false, $OUT);
172 } elseif ((isPostRequestParameterSet('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
173 // List extensions and when verbose is enabled SQL statements which will be executed
175 foreach (postRequestParameter('sel') as $ext_id => $sel) {
181 $ext_id = bigintval($ext_id);
184 if (isExtensionIdValid($ext_id)) {
185 // Get extension name
186 $ext_name = getExtensionName($ext_id);
188 // Listing of SQLs enabled?
189 if (isVerboseSqlEnabled()) {
190 // Load SQL commands in remove mode
191 if (loadExtension($ext_name, 'remove', '0.0', true)) {
192 // Generate extra table with loaded SQL commands
193 $VERBOSE_OUT = addExtensionVerboseSqlTable();
197 // Prepare data for the row template
200 'ext_name' => $ext_name,
201 'ext_ver' => getExtensionVersion($ext_name),
202 'verbose' => $VERBOSE_OUT
205 // Load row template and switch color
206 $OUT .= loadTemplate('admin_extensions_delete_row', true, $content);
208 // Prepare data for the row template
214 $OUT .= loadTemplate('admin_extensions_delete_row_404', true, $content);
219 loadTemplate('admin_extensions_delete', false, $OUT);
221 } elseif ((isFormSent('remove')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
222 // Remove extensions from DB (you have to delete all files manually!)
224 foreach (postRequestParameter('sel') as $ext_id => $active) {
226 $ext_id = bigintval($ext_id);
228 // Is this extension selected and id valid?
229 if (($active == 1) && (isExtensionIdValid($ext_id))) {
230 // Run embeded SQL commands
231 doExtensionSqls($ext_id, 'remove');
235 // Redirect to prevent missing cache in js.php
236 redirectToUrl('modules.php?module=admin&what=extensions&removed=' . countPostSelection());
237 } elseif ((isGetRequestParameterSet('do')) && (!isDemoModeActive())) {
238 // Other things to do
239 $do = SQL_ESCAPE(secureString(getRequestParameter('do')));
240 } elseif (isGetRequestParameterSet('do')) {
243 } elseif (isGetRequestParameterSet('registered')) {
244 // Extensions changed
245 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_REGISTERED', getExtensionName(getRequestParameter('registered'))));
248 if (isExtensionActive('task')) {
249 loadTemplate('admin_next_link', false, array(
250 'url' => 'modules.php?module=admin&what=list_task',
251 'title' => '{--ADMIN_EXTENSION_REGISTER_NEXT_LINK--}'
254 loadTemplate('admin_next_link', false, array(
255 'url' => 'modules.php?module=admin',
256 'title' => '{--ADMIN_EXTENSION_REGISTER_NEXT_LINK--}'
259 } elseif (isGetRequestParameterSet('changed')) {
260 // Extensions changed
261 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_CHANGED', bigintval(getRequestParameter('changed'))));
262 } elseif (isGetRequestParameterSet('edited')) {
263 // Extensions changed
264 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_EDITED', bigintval(getRequestParameter('edited'))));
265 } elseif (isGetRequestParameterSet('removed')) {
266 // Extensions changed
267 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSIONS_REMOVED', bigintval(getRequestParameter('removed'))));
270 // Shall we display active/inactive extensions?
272 if (isGetRequestParameterSet('active')) {
273 $where = sprintf("WHERE `ext_active`='%s'", SQL_ESCAPE(secureString(getRequestParameter('active'))));
278 case 'overview': // List all registered extensions
279 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
280 // Load extension data with CSS informations
281 $result = SQL_QUERY("SELECT
282 `id` AS ext_id, `ext_name`, `ext_active`, `ext_has_css` AS ext_css, `ext_version`
284 `{?_MYSQL_PREFIX?}_extensions`
287 `ext_name` ASC", __FILE__, __LINE__);
289 // Load extension data without CSS informations
290 $result = SQL_QUERY("SELECT
291 `id` AS ext_id, `ext_name`, `ext_active`, `ext_version`
293 `{?_MYSQL_PREFIX?}_extensions`
296 `ext_name` ASC", __FILE__, __LINE__);
299 // Are there some entries?
300 if (!SQL_HASZERONUMS($result)) {
301 // Extensions are registered
303 while ($content = SQL_FETCHARRAY($result)) {
304 // Prepare CSS selection output
305 $cssSelection = '---';
306 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) $cssSelection = translateYesNo($content['ext_css']);
308 // Prepare data for the row template
309 $content['ext_css'] = $cssSelection;
311 // Load row template and switch color
312 $OUT .= loadTemplate('admin_extensions_row', true, $content);
316 SQL_FREERESULT($result);
319 loadTemplate('admin_extensions', false, $OUT);
321 // No extensions are registered
322 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_EXTENSION_REGISTERED--}');
326 case 'register': // Register new extension
327 // Do we have some tasks?
328 $numTasks = countSumTotalData(getCurrentAdminId(), 'task_system', 'id', 'assigned_admin', true, "AND `task_type`='EXTENSION'");
330 // Is the id number valid and the task was found?
331 if (($taskId > 0) && ($numTasks > 0)) {
332 // id is valid so begin with registration, we first want to it's real name from task management (subject column)
333 $result = SQL_QUERY_ESC("SELECT `subject` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
334 array(bigintval($taskId)), __FILE__, __LINE__);
335 list($subject) = SQL_FETCHROW($result);
338 SQL_FREERESULT($result);
340 // Disable cache update by default
342 if (!empty($subject)) {
343 // Extract extension's name from subject...
344 $ext_name = trim(substr($subject, 1, strpos($subject, ':') - 1));
346 // Test the extension for deprecation
347 loadExtension($ext_name, 'test');
349 // Is the extension deprecated?
350 if (!isExtensionDeprecated()) {
351 // ... so we can finally register and load it in registration mode
352 if (registerExtension($ext_name, $taskId)) {
354 if (!ifFatalErrorsDetected()) {
355 // Extension was found and successfully registered
356 redirectToUrl('modules.php?module=admin&what=extensions&registered=' . getExtensionId($ext_name));
359 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_NOT_REGISTERED', $ext_name));
362 // Do we need to update cache file?
363 // @TODO Rewrite this to a filter
364 if (isExtensionActive('cache')) {
365 // Remove cache file (will be auto-created again!)
366 if ($GLOBALS['cache_instance']->loadCacheFile('config')) $GLOBALS['cache_instance']->removeCacheFile();
367 if ($GLOBALS['cache_instance']->loadCacheFile('extension')) $GLOBALS['cache_instance']->removeCacheFile();
368 if ($GLOBALS['cache_instance']->loadCacheFile('filter')) $GLOBALS['cache_instance']->removeCacheFile();
369 if ($GLOBALS['cache_instance']->loadCacheFile('modules')) $GLOBALS['cache_instance']->removeCacheFile();
371 } elseif (isExtensionInstalled($ext_name)) {
372 // Notify the admin that we have a problem here...
373 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ALREADY--}');
375 // Notify the admin that we have a problem here...
376 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_REGISTRATION_FAILED_404', $ext_name));
379 // Motify the admin that we have a problem here...
380 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_DEPRECATED--}');
383 // Extension was not found in task management
384 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ID_404--}');
386 } elseif ($numTasks == '0') {
387 // No longer assigned or old task
388 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ASSIGED--}');
391 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_INVALID--}');
396 loadTemplate('admin_settings_saved', false, '{--SETTINGS_NOT_SAVED--}');