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
54 $taskId = determineExtensionTaskId(getRequestParameter('reg_ext'));
56 // The id comes from task management and it is - of course - *not* the extension's name!
57 } elseif ((isFormSent('change')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
58 // De-/activate extensions
59 foreach (postRequestParameter('sel') as $ext_id => $ext_active) {
60 // Shall we keep the extension always active?
61 if ((isset($GLOBALS['cache_array']['always_active'][getExtensionName($ext_id)])) && ($GLOBALS['cache_array']['always_active'][getExtensionName($ext_id)] == 'Y') && ($ext_active == 'Y')) {
62 // Keep this extension active!
63 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_ALWAYS_ACTIVE', getExtensionName($ext_id)));
65 // Deactivation is default
67 setExtensionMode('deactivate');
69 // Is the extension deactivated?
70 if ($ext_active != 'Y') {
71 // Then we can activate it
73 setExtensionMode('activate');
77 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s AND `ext_active`='%s' LIMIT 1",
78 array($active, bigintval($ext_id), $ext_active), __FILE__, __LINE__);
80 // Run embeded SQL commands
81 doExtensionSqls($ext_id, getExtensionMode());
85 // Redirect to prevent missing cache in js.php
86 redirectToUrl('modules.php?module=admin&what=extensions&changed=' . countPostSelection());
87 } elseif (((isFormSent('edit')) || (isPostRequestParameterSet('modify'))) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
88 // Change settings like CSS file load
89 if (isPostRequestParameterSet('modify')) {
92 foreach (postRequestParameter('sel') as $ext_id => $sel) {
94 $ext_id = bigintval($ext_id);
96 // Change this extension?
98 // Load mode is modify
99 setExtensionMode('modify');
101 // Get entry for 'active'
102 $active = postRequestParameter('active', $ext_id);
104 // Update extension's record
105 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
106 // Update also CSS column when extensions sql_patches is newer or exact v0.0.6
107 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_has_css`='%s', `ext_active`='%s' WHERE `id`=%s LIMIT 1",
108 array(postRequestParameter('css', $ext_id), $active, $ext_id), __FILE__, __LINE__);
110 // When extension is older than v0.0.6 there is no column for the CSS information
111 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s LIMIT 1",
112 array($active, $ext_id), __FILE__, __LINE__);
115 // Run SQLs on activation / deactivation
117 case 'Y': setExtensionMode('activate'); break;
118 case 'N': setExtensionMode('deactivate'); break;
121 // Run embeded SQL commands
122 doExtensionSqls($ext_id, getExtensionMode());
126 // Redirect to prevent missing cache in js.php
127 redirectToUrl('modules.php?module=admin&what=extensions&edited=' . countPostSelection());
129 // Edit selected entries
131 foreach (postRequestParameter('sel') as $ext_id => $sel) {
132 // Edit this extension?
133 if (($sel == 'Y') || ($sel != 'Y')) {
134 // Default is no CSS for non-updated mailers
137 // Load required data
138 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
139 $result = SQL_QUERY_ESC("SELECT ext_has_css, ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
140 array(bigintval($ext_id)), __FILE__, __LINE__);
141 list($css, $active) = SQL_FETCHROW($result);
142 SQL_FREERESULT($result);
144 $result = SQL_QUERY_ESC("SELECT ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
145 array(bigintval($ext_id)), __FILE__, __LINE__);
146 list($active) = SQL_FETCHROW($result);
147 SQL_FREERESULT($result);
151 // Prepare CSS column
152 $cssSelection = '---';
153 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
154 $cssSelection = addSelectionBox('yn', $css, 'css', $ext_id);
157 // Prepare data for the row template
160 'name' => getExtensionName($ext_id),
161 'active' => addSelectionBox('yn', $active, 'active', $ext_id),
162 'css' => $cssSelection,
165 // Load row template and switch color
166 $OUT .= loadTemplate('admin_extensions_edit_row', true, $content);
171 loadTemplate('admin_extensions_edit', false, $OUT);
174 } elseif ((isPostRequestParameterSet('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
175 // List extensions and when verbose is enabled SQL statements which will be executed
177 foreach (postRequestParameter('sel') as $ext_id => $sel) {
183 $ext_id = bigintval($ext_id);
186 if (isExtensionIdValid($ext_id)) {
187 // Get extension name
188 $ext_name = getExtensionName($ext_id);
190 // Listing of SQLs enabled?
191 if (isVerboseSqlEnabled()) {
192 // Load SQL commands in remove mode
193 if (loadExtension($ext_name, 'remove', '', true)) {
194 // Generate extra table with loaded SQL commands
195 $VERBOSE_OUT = addExtensionVerboseSqlTable();
199 // Prepare data for the row template
202 'ext_name' => $ext_name,
203 'ext_ver' => getExtensionVersion($ext_name),
204 'verbose' => $VERBOSE_OUT
207 // Load row template and switch color
208 $OUT .= loadTemplate('admin_extensions_delete_row', true, $content);
210 // Prepare data for the row template
216 $OUT .= loadTemplate('admin_extensions_delete_row_404', true, $content);
221 loadTemplate('admin_extensions_delete', false, $OUT);
223 } elseif ((isFormSent('remove')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
224 // Remove extensions from DB (you have to delete all files manually!)
226 foreach (postRequestParameter('sel') as $ext_id => $active) {
228 $ext_id = bigintval($ext_id);
230 // Is this extension selected and id valid?
231 if (($active == 1) && (isExtensionIdValid($ext_id))) {
232 // Run embeded SQL commands
233 doExtensionSqls($ext_id, 'remove');
237 // Redirect to prevent missing cache in js.php
238 redirectToUrl('modules.php?module=admin&what=extensions&removed=' . countPostSelection());
239 } elseif ((isGetRequestParameterSet('do')) && (!isDemoModeActive())) {
240 // Other things to do
241 $do = SQL_ESCAPE(secureString(getRequestParameter('do')));
242 } elseif (isGetRequestParameterSet('do')) {
245 } elseif (isGetRequestParameterSet('registered')) {
246 // Extensions changed
247 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_REGISTERED', getExtensionName(getRequestParameter('registered'))));
250 if (isExtensionActive('task')) {
251 loadTemplate('admin_next_link', false, array(
252 'url' => 'modules.php?module=admin&what=list_task',
253 'title' => '{--ADMIN_EXTENSION_REGISTER_NEXT_LINK--}'
256 loadTemplate('admin_next_link', false, array(
257 'url' => 'modules.php?module=admin',
258 'title' => '{--ADMIN_EXTENSION_REGISTER_NEXT_LINK--}'
261 } elseif (isGetRequestParameterSet('changed')) {
262 // Extensions changed
263 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_CHANGED', bigintval(getRequestParameter('changed'))));
264 } elseif (isGetRequestParameterSet('edited')) {
265 // Extensions changed
266 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_EDITED', bigintval(getRequestParameter('edited'))));
267 } elseif (isGetRequestParameterSet('removed')) {
268 // Extensions changed
269 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSIONS_REMOVED', bigintval(getRequestParameter('removed'))));
272 // Shall we display active/inactive extensions?
274 if (isGetRequestParameterSet('active')) {
275 $where = sprintf("WHERE `ext_active`='%s'", SQL_ESCAPE(secureString(getRequestParameter('active'))));
280 case 'overview': // List all registered extensions
281 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
282 // Load extension data with CSS informations
283 $result = SQL_QUERY("SELECT
284 `id` AS ext_id, `ext_name`, `ext_active`, `ext_has_css` AS ext_css, `ext_version`
286 `{?_MYSQL_PREFIX?}_extensions`
289 `ext_name` ASC", __FILE__, __LINE__);
291 // Load extension data without CSS informations
292 $result = SQL_QUERY("SELECT
293 `id` AS ext_id, `ext_name`, `ext_active`, `ext_version`
295 `{?_MYSQL_PREFIX?}_extensions`
298 `ext_name` ASC", __FILE__, __LINE__);
301 // Are there some entries?
302 if (!SQL_HASZERONUMS($result)) {
303 // Extensions are registered
305 while ($content = SQL_FETCHARRAY($result)) {
306 // Prepare CSS selection output
307 $cssSelection = '---';
308 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) $cssSelection = translateYesNo($content['ext_css']);
310 // Prepare data for the row template
311 $content['ext_css'] = $cssSelection;
313 // Load row template and switch color
314 $OUT .= loadTemplate('admin_extensions_row', true, $content);
318 SQL_FREERESULT($result);
321 loadTemplate('admin_extensions', false, $OUT);
323 // No extensions are registered
324 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_EXTENSION_REGISTERED--}');
328 case 'register': // Register new extension
329 // Do we have some tasks?
330 $numTasks = countSumTotalData(getCurrentAdminId(), 'task_system', 'id', 'assigned_admin', true, "AND `task_type`='EXTENSION'");
332 // Is the id number valid and the task was found?
333 if (($taskId > 0) && ($numTasks > 0)) {
334 // id is valid so begin with registration, we first want to it's real name from task management (subject column)
335 $result = SQL_QUERY_ESC("SELECT `subject` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
336 array(bigintval($taskId)), __FILE__, __LINE__);
337 list($subject) = SQL_FETCHROW($result);
340 SQL_FREERESULT($result);
342 // Disable cache update by default
344 if (!empty($subject)) {
345 // Extract extension's name from subject...
346 $ext_name = trim(substr($subject, 1, strpos($subject, ':') - 1));
348 // Test the extension for deprecation
349 loadExtension($ext_name, 'test');
351 // Is the extension deprecated?
352 if (!isExtensionDeprecated()) {
353 // ... so we can finally register and load it in registration mode
354 if (registerExtension($ext_name, $taskId)) {
356 if (!ifFatalErrorsDetected()) {
357 // Extension was found and successfully registered
358 redirectToUrl('modules.php?module=admin&what=extensions&registered=' . getExtensionId($ext_name));
361 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_NOT_REGISTERED', $ext_name));
364 // Do we need to update cache file?
365 // @TODO Rewrite this to a filter
366 if (isExtensionActive('cache')) {
367 // Remove cache file (will be auto-created again!)
368 if ($GLOBALS['cache_instance']->loadCacheFile('config')) $GLOBALS['cache_instance']->removeCacheFile();
369 if ($GLOBALS['cache_instance']->loadCacheFile('extension')) $GLOBALS['cache_instance']->removeCacheFile();
370 if ($GLOBALS['cache_instance']->loadCacheFile('filter')) $GLOBALS['cache_instance']->removeCacheFile();
371 if ($GLOBALS['cache_instance']->loadCacheFile('modules')) $GLOBALS['cache_instance']->removeCacheFile();
373 } elseif (isExtensionInstalled($ext_name)) {
374 // Notify the admin that we have a problem here...
375 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ALREADY--}');
377 // Notify the admin that we have a problem here...
378 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_REGISTRATION_FAILED_404', $ext_name));
381 // Motify the admin that we have a problem here...
382 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_DEPRECATED--}');
385 // Extension was not found in task management
386 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ID_404--}');
388 } elseif ($numTasks == '0') {
389 // No longer assigned or old task
390 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ASSIGED--}');
393 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_INVALID--}');
398 loadTemplate('admin_settings_saved', false, '{--SETTINGS_NOT_SAVED--}');