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 - 2013 by Mailer Developer Team *
20 * For more information visit: http://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 // By default generate overview of all installed extensions
49 if (isGetRequestElementSet('register_ext')) {
50 // We are about to register a new extension
52 $taskId = determineExtensionTaskId(getRequestElement('register_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 (postRequestElement('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 displayMessage('{%message,ADMIN_EXTENSION_ALWAYS_ACTIVE=' . $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 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s AND `ext_active`='%s' LIMIT 1",
80 ), __FILE__, __LINE__);
82 // Run embeded SQL commands
83 doExtensionSqls($ext_id, getExtensionMode());
87 // Redirect to prevent missing cache in js.php
88 redirectToUrl('modules.php?module=admin&what=extensions&changed=' . countPostSelection());
89 } elseif (((isFormSent('edit')) || (isPostRequestElementSet('do_edit'))) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
90 // Change settings like CSS file load
91 if (isPostRequestElementSet('do_edit')) {
94 foreach (postRequestElement('sel') as $ext_id => $sel) {
96 $ext_id = bigintval($ext_id);
98 // Change this extension?
100 // Load mode is modify
101 setExtensionMode('modify');
103 // Get entry for 'active'
104 $active = postRequestElement('active', $ext_id);
106 // Update extension's record
107 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
108 // Update also CSS column when extensions ext-sql_patches is newer or exact v0.0.6
109 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_has_css`='%s',`ext_active`='%s' WHERE `id`=%s LIMIT 1",
110 array(postRequestElement('css', $ext_id), $active, $ext_id), __FILE__, __LINE__);
112 // When extension is older than v0.0.6 there is no column for the CSS information
113 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s LIMIT 1",
114 array($active, $ext_id), __FILE__, __LINE__);
117 // Run SQLs on activation / deactivation
119 case 'Y': setExtensionMode('activate'); break;
120 case 'N': setExtensionMode('deactivate'); break;
123 // Run embeded SQL commands
124 doExtensionSqls($ext_id, getExtensionMode());
128 // Redirect to prevent missing cache in js.php
129 redirectToUrl('modules.php?module=admin&what=extensions&edited=' . countPostSelection());
131 // Edit selected entries
133 foreach (postRequestElement('sel') as $ext_id => $sel) {
134 // Edit this extension?
135 if (($sel == 'Y') || ($sel != 'Y')) {
136 // Default is no CSS for non-updated mailers
139 // Load required data
140 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
141 $result = sqlQueryEscaped("SELECT `ext_has_css`, `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
142 array(bigintval($ext_id)), __FILE__, __LINE__);
143 list($css, $active) = sqlFetchRow($result);
144 sqlFreeResult($result);
146 $result = sqlQueryEscaped("SELECT `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
147 array(bigintval($ext_id)), __FILE__, __LINE__);
148 list($active) = sqlFetchRow($result);
149 sqlFreeResult($result);
153 // Prepare CSS column
154 $cssSelection = '---';
155 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
156 $cssSelection = addSelectionBox('yn', $css, 'css', $ext_id);
159 // Prepare data for the row template
162 'name' => getExtensionName($ext_id),
163 'active' => addSelectionBox('yn', $active, 'active', $ext_id),
164 'css' => $cssSelection,
167 // Load row template and switch color
168 $OUT .= loadTemplate('admin_edit_extensions_row', TRUE, $content);
173 loadTemplate('admin_edit_extensions', FALSE, $OUT);
176 } elseif ((isPostRequestElementSet('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
177 // List extensions and when verbose is enabled SQL statements which will be executed
179 foreach (postRequestElement('sel') as $ext_id => $sel) {
185 $ext_id = bigintval($ext_id);
188 if (isExtensionIdValid($ext_id)) {
189 // Get extension name
190 $ext_name = getExtensionName($ext_id);
192 // Listing of SQLs enabled?
193 if (isVerboseSqlEnabled()) {
194 // Load SQL commands in remove mode
195 if (loadExtension($ext_name, 'remove', '0.0.0', TRUE)) {
196 // Generate extra table with loaded SQL commands
197 $VERBOSE_OUT = addExtensionVerboseSqlTable();
201 // Prepare data for the row template
204 'ext_name' => $ext_name,
205 'verbose' => $VERBOSE_OUT
208 // Load row template and switch color
209 $OUT .= loadTemplate('admin_delete_extensions_row', TRUE, $content);
211 // Prepare data for the row template
217 $OUT .= loadTemplate('admin_delete_extensions_row_404', TRUE, $content);
222 loadTemplate('admin_delete_extensions', FALSE, $OUT);
224 } elseif ((isFormSent('do_delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
225 // Remove extensions from DB (you have to delete all files manually!)
227 foreach (postRequestElement('sel') as $ext_id => $active) {
229 $ext_id = bigintval($ext_id);
231 // Is this extension selected and id valid?
232 if (($active == 1) && (isExtensionIdValid($ext_id))) {
233 // Run embeded SQL commands
234 doExtensionSqls($ext_id, 'remove');
238 // Redirect to prevent missing cache in js.php
239 redirectToUrl('modules.php?module=admin&what=extensions&removed=' . countPostSelection());
240 } elseif ((isGetRequestElementSet('do')) && (!isDemoModeActive())) {
241 // Other things to do
242 $do = getRequestElement('do');
243 } elseif (isGetRequestElementSet('do')) {
246 } elseif (isGetRequestElementSet('registered')) {
247 // Extensions changed
248 displayMessage('{%message,ADMIN_EXTENSION_REGISTERED=' . getExtensionName(getRequestElement('registered')) . '%}');
251 if (isExtensionActive('task')) {
252 loadTemplate('admin_next_link', FALSE, array(
253 'url' => 'modules.php?module=admin&what=list_task',
254 'title' => '{--ADMIN_EXTENSION_REGISTER_NEXT_LINK--}'
257 loadTemplate('admin_next_link', FALSE, array(
258 'url' => 'modules.php?module=admin',
259 'title' => '{--ADMIN_EXTENSION_REGISTER_NEXT_LINK--}'
262 } elseif (isGetRequestElementSet('changed')) {
263 // Extensions changed
264 displayMessage('{%message,ADMIN_EXTENSION_CHANGED=' . bigintval(getRequestElement('changed')) . '%}');
265 } elseif (isGetRequestElementSet('edited')) {
266 // Extensions changed
267 displayMessage('{%message,ADMIN_EXTENSION_EDITED=' . bigintval(getRequestElement('edited')) . '%}');
268 } elseif (isGetRequestElementSet('removed')) {
269 // Extensions changed
270 displayMessage('{%message,ADMIN_EXTENSIONS_REMOVED=' . bigintval(getRequestElement('removed')) . '%}');
273 // Shall we display active/inactive extensions?
275 if (isGetRequestElementSet('active')) {
276 $where = sprintf("WHERE `ext_active`='%s'", sqlEscapeString(getRequestElement('active')));
281 case 'overview': // List all registered extensions
282 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
283 // Load extension data with CSS informations
284 $result = sqlQuery('SELECT
288 `ext_has_css` AS `ext_css`,
291 `{?_MYSQL_PREFIX?}_extensions`
294 `ext_name` ASC', __FILE__, __LINE__);
296 // Load extension data without CSS informations
297 $result = sqlQuery('SELECT
303 `{?_MYSQL_PREFIX?}_extensions`
306 `ext_name` ASC', __FILE__, __LINE__);
309 // Are there some entries?
310 if (!ifSqlHasZeroNums($result)) {
311 // Extensions are registered
313 while ($content = sqlFetchArray($result)) {
314 // Prepare CSS selection output
315 $cssSelection = '---';
316 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
317 $cssSelection = '{%pipe,translateYesNo=' . $content['ext_css'] . '%}';
320 // Prepare data for the row template
321 $content['ext_css'] = $cssSelection;
323 // Load row template and switch color
324 $OUT .= loadTemplate('admin_list_extensions_row', TRUE, $content);
328 sqlFreeResult($result);
331 loadTemplate('admin_list_extensions', FALSE, $OUT);
333 // No extensions are registered
334 displayMessage('{--ADMIN_NO_EXTENSION_REGISTERED--}');
338 case 'setup': // Setup new extension
339 // Are there some tasks?
340 $numTasks = countSumTotalData(getCurrentAdminId(), 'task_system', 'id', 'assigned_admin', TRUE, "AND `task_type`='EXTENSION'");
342 // Is the id number valid and the task was found?
343 if ((isValidId($taskId)) && ($numTasks > 0)) {
344 // id is valid so begin with registration, we first want to it's real name from task management (subject column)
345 $result = sqlQueryEscaped("SELECT `subject` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
346 array(bigintval($taskId)), __FILE__, __LINE__);
347 list($subject) = sqlFetchRow($result);
350 sqlFreeResult($result);
352 // Disable cache update by default
354 if (!empty($subject)) {
355 // Extract extension's name from subject...
356 $ext_name = trim(substr($subject, 1, strpos($subject, ':') - 1));
358 // Test the extension for deprecation
359 loadExtension($ext_name, 'test');
361 // Is the extension deprecated?
362 if (!isExtensionDeprecated()) {
363 // ... so we can finally register and load it in registration mode
364 if (registerExtension($ext_name, $taskId)) {
365 // Do we need to update cache file?
366 // @TODO Rewrite this to a filter
367 if (isExtensionActive('cache')) {
368 // Remove cache file (will be auto-created again!)
369 foreach (array('config', 'extension', 'filter', 'modules') as $cache) {
370 // Rebuild cache file
371 rebuildCache($cache);
376 if (!ifFatalErrorsDetected()) {
377 // Extension was found and successfully registered
378 redirectToUrl('modules.php?module=admin&what=extensions&registered=' . getExtensionId($ext_name));
381 displayMessage('{%message,ADMIN_EXTENSION_NOT_REGISTERED=' . $ext_name . '%}');
383 } elseif (isExtensionInstalled($ext_name)) {
384 // Notify the admin that we have a problem here...
385 displayMessage('{--ADMIN_EXTENSION_REGISTRATION_FAILED_ALREADY--}');
387 // Notify the admin that we have a problem here...
388 displayMessage('{%message,ADMIN_EXTENSION_REGISTRATION_FAILED_404=' . $ext_name . '%}');
391 // Motify the admin that we have a problem here...
392 displayMessage('{--ADMIN_EXTENSION_REGISTRATION_FAILED_DEPRECATED--}');
395 // Extension was not found in task management
396 displayMessage('{--ADMIN_EXTENSION_REGISTRATION_FAILED_ID_404--}');
398 } elseif ($numTasks == '0') {
399 // No longer assigned or old task
400 displayMessage('{--ADMIN_EXTENSION_REGISTRATION_FAILED_ASSIGED--}');
403 displayMessage('{--ADMIN_EXTENSION_REGISTRATION_FAILED_INVALID--}');
408 displayMessage('{--SETTINGS_NOT_SAVED--}');