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 $taskId => $active) {
60 // Shall we keep the extension always active?
61 if ((isset($GLOBALS['cache_array']['always_active'][getExtensionName($taskId)])) && ($GLOBALS['cache_array']['always_active'][getExtensionName($taskId)] == 'Y') && ($active == 'Y')) {
62 // Keep this extension active!
63 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_ALWAYS_ACTIVE', getExtensionName($taskId)));
65 // De/activate extension
66 $ACT = 'N'; setExtensionMode('deactivate');
67 if ($active != 'Y') { $ACT = 'Y'; setExtensionMode('activate'); }
68 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s AND `ext_active`='%s' LIMIT 1",
69 array($ACT, bigintval($taskId), $active), __FILE__, __LINE__);
71 // Run embeded SQL commands
72 doExtensionSqls($taskId, getExtensionMode());
76 // Redirect to prevent missing cache in js.php
77 redirectToUrl('modules.php?module=admin&what=extensions&changed=' . countPostSelection());
78 } elseif (((isFormSent('edit')) || (isPostRequestParameterSet('modify'))) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
79 // Change settings like CSS file load
80 if (isPostRequestParameterSet('modify')) {
83 foreach (postRequestParameter('sel') as $taskId => $sel) {
85 $taskId = bigintval($taskId);
87 // Change this extension?
89 // Load mode is modify
90 setExtensionMode('modify');
92 // Get entry for 'active'
93 $active = postRequestParameter('active', $taskId);
95 // Update extension's record
96 if (isExtensionInstalledAndNewer('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(postRequestParameter('css', $taskId), $active, $taskId), __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, $taskId), __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($taskId, getExtensionMode());
117 // Redirect to prevent missing cache in js.php
118 redirectToUrl('modules.php?module=admin&what=extensions&edited=' . countPostSelection());
120 // Edit selected entries
122 foreach (postRequestParameter('sel') as $taskId => $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 (isExtensionInstalledAndNewer('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($taskId)), __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($taskId)), __FILE__, __LINE__);
137 list($active) = SQL_FETCHROW($result);
138 SQL_FREERESULT($result);
142 // Prepare CSS column
143 $cssSelection = '---';
144 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
145 $cssSelection = addSelectionBox('yn', $css, 'css', $taskId);
148 // Prepare data for the row template
151 'name' => getExtensionName($taskId),
152 'active' => addSelectionBox('yn', $active, 'active', $taskId),
153 'css' => $cssSelection,
156 // Load row template and switch color
157 $OUT .= loadTemplate('admin_extensions_edit_row', true, $content);
162 loadTemplate('admin_extensions_edit', false, $OUT);
165 } elseif ((isPostRequestParameterSet('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
166 // List extensions and when verbose is enabled SQL statements which will be executed
168 foreach (postRequestParameter('sel') as $taskId => $sel) {
174 $taskId = bigintval($taskId);
177 if (isExtensionIdValid($taskId)) {
178 // Get extension name
179 $ext_name = getExtensionName($taskId);
181 if (isVerboseSqlEnabled()) {
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
192 'ext_name' => $ext_name,
193 'ext_ver' => getExtensionVersion($ext_name),
194 'verbose' => $VERBOSE_OUT
197 // Load row template and switch color
198 $OUT .= loadTemplate('admin_extensions_delete_row', true, $content);
200 // Prepare data for the row template
206 $OUT .= loadTemplate('admin_extensions_delete_row_404', true, $content);
211 loadTemplate('admin_extensions_delete', false, $OUT);
213 } elseif ((isFormSent('remove')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
214 // Remove extensions from DB (you have to delete all files manually!)
216 foreach (postRequestParameter('sel') as $taskId => $active) {
218 $taskId = bigintval($taskId);
220 // Is this extension selected and id valid?
221 if (($active == 1) && (isExtensionIdValid($taskId))) {
222 // Run embeded SQL commands
223 doExtensionSqls($taskId, 'remove');
227 // Redirect to prevent missing cache in js.php
228 redirectToUrl('modules.php?module=admin&what=extensions&removed=' . countPostSelection());
229 } elseif ((isGetRequestParameterSet('do')) && (!isDemoModeActive())) {
230 // Other things to do
231 $do = SQL_ESCAPE(secureString(getRequestParameter('do')));
232 } elseif (isGetRequestParameterSet('do')) {
235 } elseif (isGetRequestParameterSet('registered')) {
236 // Extensions changed
237 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_REGISTERED', getExtensionName(getRequestParameter('registered'))));
240 if (isExtensionActive('task')) {
241 loadTemplate('admin_next_link', false, array(
242 'url' => 'modules.php?module=admin&what=list_task',
243 'title' => '{--ADMIN_EXTENSION_REGISTER_NEXT_LINK--}'
246 loadTemplate('admin_next_link', false, array(
247 'url' => 'modules.php?module=admin',
248 'title' => '{--ADMIN_EXTENSION_REGISTER_NEXT_LINK--}'
251 } elseif (isGetRequestParameterSet('changed')) {
252 // Extensions changed
253 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_CHANGED', bigintval(getRequestParameter('changed'))));
254 } elseif (isGetRequestParameterSet('edited')) {
255 // Extensions changed
256 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_EDITED', bigintval(getRequestParameter('edited'))));
257 } elseif (isGetRequestParameterSet('removed')) {
258 // Extensions changed
259 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSIONS_REMOVED', bigintval(getRequestParameter('removed'))));
262 // Shall we display active/inactive extensions?
264 if (isGetRequestParameterSet('active')) {
265 $where = sprintf("WHERE `ext_active`='%s'", SQL_ESCAPE(secureString(getRequestParameter('active'))));
270 case 'overview': // List all registered extensions
271 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
272 // Load extension data with CSS informations
273 $result = SQL_QUERY("SELECT
274 `id` AS ext_id, `ext_name`, `ext_active`, `ext_has_css` AS ext_css, `ext_version`
276 `{?_MYSQL_PREFIX?}_extensions`
279 `ext_name` ASC", __FILE__, __LINE__);
281 // Load extension data without CSS informations
282 $result = SQL_QUERY("SELECT
283 `id` AS ext_id, `ext_name`, `ext_active`, `ext_version`
285 `{?_MYSQL_PREFIX?}_extensions`
288 `ext_name` ASC", __FILE__, __LINE__);
291 // Are there some entries?
292 if (!SQL_HASZERONUMS($result)) {
293 // Extensions are registered
295 while ($content = SQL_FETCHARRAY($result)) {
296 // Prepare CSS selection output
297 $cssSelection = '---';
298 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) $cssSelection = translateYesNo($content['ext_css']);
300 // Prepare data for the row template
301 $content['ext_css'] = $cssSelection;
303 // Load row template and switch color
304 $OUT .= loadTemplate('admin_extensions_row', true, $content);
308 SQL_FREERESULT($result);
311 loadTemplate('admin_extensions', false, $OUT);
313 // No extensions are registered
314 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_EXTENSION_REGISTERED--}');
318 case 'register': // Register new extension
319 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `assigned_admin`=%s AND `task_type`='EXTENSION' LIMIT 1",
320 array(getCurrentAdminId()), __FILE__, __LINE__);
321 $task_found = SQL_NUMROWS($result);
324 SQL_FREERESULT($result);
326 // Is the id number valid and the task was found?
327 if (($taskId > 0) && ($task_found == 1)) {
328 // id is valid so begin with registration, we first want to it's real name from task management (subject column)
329 $result = SQL_QUERY_ESC("SELECT `subject` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
330 array(bigintval($taskId)), __FILE__, __LINE__);
331 list($subject) = SQL_FETCHROW($result);
334 SQL_FREERESULT($result);
336 // Disable cache update by default
338 if (!empty($subject)) {
339 // Extract extension's name from subject...
340 $ext_name = trim(substr($subject, 1, strpos($subject, ':') - 1));
342 // Test the extension for deprecation
343 loadExtension($ext_name, 'test');
345 // Is the extension deprecated?
346 if (!isExtensionDeprecated()) {
347 // ... so we can finally register and load it in registration mode
348 if (registerExtension($ext_name, $taskId)) {
350 if (!ifFatalErrorsDetected()) {
351 // Extension was found and successfully registered
352 redirectToUrl('modules.php?module=admin&what=extensions&registered=' . getExtensionId($ext_name));
355 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_NOT_REGISTERED', $ext_name));
358 // Do we need to update cache file?
359 // @TODO Rewrite this to a filter
360 if (isExtensionActive('cache')) {
361 // Remove cache file (will be auto-created again!)
362 if ($GLOBALS['cache_instance']->loadCacheFile('config')) $GLOBALS['cache_instance']->removeCacheFile();
363 if ($GLOBALS['cache_instance']->loadCacheFile('extension')) $GLOBALS['cache_instance']->removeCacheFile();
364 if ($GLOBALS['cache_instance']->loadCacheFile('filter')) $GLOBALS['cache_instance']->removeCacheFile();
365 if ($GLOBALS['cache_instance']->loadCacheFile('modules')) $GLOBALS['cache_instance']->removeCacheFile();
367 } elseif (isExtensionInstalled($ext_name)) {
368 // Notify the admin that we have a problem here...
369 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ALREADY--}');
371 // Notify the admin that we have a problem here...
372 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_REGISTRATION_FAILED_404', $ext_name));
375 // Motify the admin that we have a problem here...
376 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_DEPRECATED--}');
379 // Extension was not found in task management
380 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ID_404--}');
382 } elseif ($task_found == '0') {
383 // No longer assigned or old task
384 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ASSIGED--}');
387 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_INVALID--}');
392 loadTemplate('admin_settings_saved', false, '{--SETTINGS_NOT_SAVED--}');