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 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
47 // Normally we want the overview of all registered extensions
50 if (isGetRequestElementSet('reg_ext')) {
51 // We are about to register a new extension
52 $do = 'register'; $ext_id = bigintval(getRequestElement('reg_ext'));
53 // The id comes from task management and it is - of course - *not* the extension's name!
54 } elseif ((isPostRequestElementSet('change')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
55 // De-/activate extensions
56 foreach (postRequestElement('sel') as $ext_id => $active) {
57 // Shall we keep the extension always active?
58 if ((isset($GLOBALS['cache_array']['active_extensions'][getExtensionName($ext_id)])) && ($GLOBALS['cache_array']['active_extensions'][getExtensionName($ext_id)] == 'Y') && ($active != 'Y')) {
59 // Keep this extension active!
61 // De/activate extension
62 $ACT = 'N'; setExtensionMode('deactivate');
63 if ($active != 'Y') { $ACT = 'Y'; setExtensionMode('activate'); }
64 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='".$ACT."' WHERE `id`=%s AND `ext_active`='%s' LIMIT 1",
65 array(bigintval($ext_id), $active), __FILE__, __LINE__);
67 // Run embeded SQL commands
68 doExtensionSqls($ext_id, getExtensionMode());
71 } elseif (((isPostRequestElementSet('edit')) || (isPostRequestElementSet(('modify')))) && (countPostSelection() > 0) && (!isDemoModeActive())) {
72 // Change settings like CSS file load
73 if (isPostRequestElementSet(('modify'))) {
76 foreach (postRequestElement('sel') as $ext_id => $sel) {
78 $ext_id = bigintval($ext_id);
80 // Change this extension?
82 // Load mode is modify
83 setExtensionMode('modify');
85 // Get entry for 'active'
86 $active = postRequestElement('active', $ext_id);
88 // Update extension's record
89 if (getExtensionVersion('sql_patches') >= '0.0.6') {
90 // Update also CSS column when extensions sql_patches is newer or exact v0.0.6
91 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_has_css`='%s', `ext_active`='%s' WHERE `id`=%s LIMIT 1",
92 array(postRequestElement('css', $ext_id), $active, $ext_id), __FILE__, __LINE__);
94 // When extension is older than v0.0.6 there is no column for the CSS information
95 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s LIMIT 1",
96 array($active, $ext_id), __FILE__, __LINE__);
99 // Run SQLs on activation / deactivation
101 case 'Y': setExtensionMode('activate'); break;
102 case 'N': setExtensionMode('deactivate'); break;
105 // Run embeded SQL commands
106 doExtensionSqls($ext_id, getExtensionMode());
110 // Extensions changed
111 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_EXT_CHANGED'));
113 // Edit selected entries
115 foreach (postRequestElement('sel') as $ext_id => $sel) {
116 // Edit this extension?
117 if (($sel == 'Y') || ($sel != 'Y')) {
118 // Default is no CSS for non-updated mailers
121 // Load required data
122 if (getExtensionVersion('sql_patches') >= '0.0.6') {
123 $result = SQL_QUERY_ESC("SELECT ext_has_css, ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
124 array(bigintval($ext_id)), __FILE__, __LINE__);
125 list($css, $active) = SQL_FETCHROW($result);
126 SQL_FREERESULT($result);
128 $result = SQL_QUERY_ESC("SELECT ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
129 array(bigintval($ext_id)), __FILE__, __LINE__);
130 list($active) = SQL_FETCHROW($result);
131 SQL_FREERESULT($result);
136 $cssSelection = '---';
137 if (getExtensionVersion('sql_patches') >= '0.0.6') $cssSelection = addSelectionBox('yn', $css, 'css', $ext_id);
139 // Prepare data for the row template
143 'name' => getExtensionName($ext_id),
144 'active' => addSelectionBox('yn', $active, 'active', $ext_id),
145 'css' => $cssSelection,
148 // Load row template and switch color
149 $OUT .= loadTemplate('admin_extensions_edit_row', true, $content);
155 loadTemplate('admin_extensions_edit', false, $OUT);
158 } elseif ((isPostRequestElementSet('delete')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
159 // List extensions and when verbose is enabled SQL statements which will be executed
161 foreach (postRequestElement('sel') as $ext_id => $sel) {
167 $ext_id = bigintval($ext_id);
170 if (isExtensionIdValid($ext_id)) {
171 // Get extension name
172 $ext_name = getExtensionName($ext_id);
174 if (getConfig('verbose_sql') == 'Y') {
175 // Load SQL commands in remove mode
176 if (loadExtension($ext_name, 'remove', '', true)) {
177 // Generate extra table with loaded SQL commands
178 $VERBOSE_OUT = addExtensionVerboseSqlTable();
182 // Prepare data for the row template
186 'ext_name' => $ext_name,
187 'ext_ver' => getExtensionVersion($ext_name),
188 'verbose' => $VERBOSE_OUT
191 // Load row template and switch color
192 $OUT .= loadTemplate('admin_extensions_delete_row', true, $content);
194 // Prepare data for the row template
201 $OUT .= loadTemplate('admin_extensions_delete_row_404', true, $content);
207 loadTemplate('admin_extensions_delete', false, $OUT);
209 } elseif ((isPostRequestElementSet('remove')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
210 // Remove extensions from DB (you have to delete all files manually!)
212 foreach (postRequestElement('sel') as $ext_id => $active) {
214 $ext_id = bigintval($ext_id);
216 // Is this extension selected and id valid?
217 if (($active == 1) && (isExtensionIdValid($ext_id))) {
218 // Run embeded SQL commands
219 doExtensionSqls($ext_id, 'remove');
223 // Extensions removed
224 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_EXTENSIONS_REMOVED'), countPostSelection()));
225 } elseif ((isGetRequestElementSet('do')) && (!isDemoModeActive())) {
226 // Other things to do
227 $do = SQL_ESCAPE(secureString(getRequestElement('do')));
228 } elseif (isGetRequestElementSet('do')) {
233 // Shall we display active/inactive extensions?
235 if (isGetRequestElementSet(('active'))) {
236 $where = sprintf("WHERE `ext_active`='%s'", SQL_ESCAPE(secureString(getRequestElement('active'))));
241 case 'overview': // List all registered extensions
242 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
243 // Load extension data with CSS informations
244 $result = SQL_QUERY("SELECT `id` AS ext_id, `ext_name`, `ext_active`, `ext_has_css` AS ext_css, `ext_version`
245 FROM `{?_MYSQL_PREFIX?}_extensions`
247 ORDER BY `ext_name` ASC", __FILE__, __LINE__);
249 // Load extension data without CSS informations
250 $result = SQL_QUERY("SELECT `id` AS ext_id, `ext_name`, `ext_active`, `id`, `ext_version`
251 FROM `{?_MYSQL_PREFIX?}_extensions`
253 ORDER BY `ext_name` ASC", __FILE__, __LINE__);
256 // Are there some entries?
257 if (SQL_NUMROWS($result) > 0) {
258 // Extensions are registered
260 while ($content = SQL_FETCHARRAY($result)) {
261 // Prepare CSS selection output
262 $cssSelection = '---';
263 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) $cssSelection = translateYesNo($content['ext_css']);
265 // Prepare data for the row template
268 'id' => $content['ext_id'],
269 'name' => $content['ext_name'],
270 'active' => translateYesNo($content['ext_active']),
271 'act_val' => $content['ext_active'],
272 'css' => $cssSelection,
273 'ver' => $content['ext_version'],
276 // Load row template and switch color
277 $OUT .= loadTemplate('admin_extensions_row', true, $content);
282 SQL_FREERESULT($result);
285 loadTemplate('admin_extensions', false, $OUT);
287 // No extensions are registered
288 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_EXTENSION_REGISTERED'));
292 case 'register': // Register new extension
293 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `assigned_admin`=%s AND `task_type`='EXTENSION' LIMIT 1",
294 array(getCurrentAdminId()), __FILE__, __LINE__);
295 $task_found = SQL_NUMROWS($result);
298 SQL_FREERESULT($result);
300 // Is the id number valid and the task was found?
301 if (($ext_id > 0) && ($task_found == 1)) {
302 // id is valid so begin with registration, we first want to it's real name from task management (subject column)
303 $result = SQL_QUERY_ESC("SELECT `subject` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
304 array(bigintval($ext_id)), __FILE__, __LINE__);
305 list($subj) = SQL_FETCHROW($result);
306 SQL_FREERESULT($result);
308 // Disable cache update by default
311 // Extract extension's name from subject...
312 $ext_name = trim(substr($subj, 1, strpos($subj, ':') - 1));
314 // Test the extension for deprecation
315 loadExtension($ext_name, 'test');
317 // Is the extension deprecated?
318 if (!isExtensionDeprecated()) {
319 // ... so we can finally register and load it in registration mode
320 if (registerExtension($ext_name, $ext_id)) {
322 if (getTotalFatalErrors() == '0') {
323 // Extension was found and successfully registered
324 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_EXTENSION_REGISTERED'), $ext_name));
327 if (isExtensionActive('task')) {
328 loadTemplate('admin_next_link', false, array(
329 'url' => 'modules.php?module=admin&what=list_task',
330 'title' => getMessage('ADMIN_EXT_REGISTER_NEXT_LINK')
333 loadTemplate('admin_next_link', false, array(
334 'url' => 'modules.php?module=admin',
335 'title' => getMessage('ADMIN_EXT_REGISTER_NEXT_LINK')
340 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_EXTENSION_NOT_REGISTERED'), $ext_name));
343 // Do we need to update cache file?
344 // @TODO Rewrite this to a filter
345 if (isExtensionActive('cache')) {
346 // Remove cache file (will be auto-created again!)
347 if ($GLOBALS['cache_instance']->loadCacheFile('config')) $GLOBALS['cache_instance']->removeCacheFile();
348 if ($GLOBALS['cache_instance']->loadCacheFile('extension')) $GLOBALS['cache_instance']->removeCacheFile();
349 if ($GLOBALS['cache_instance']->loadCacheFile('modules')) $GLOBALS['cache_instance']->removeCacheFile();
351 } elseif (getExtensionVersion($ext_name) != '') {
352 // Notify the admin that we have a problem here...
353 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_ALREADY'));
355 // Notify the admin that we have a problem here...
356 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_REG_FAILED_404'), $ext_name));
359 // Motify the admin that we have a problem here...
360 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_DEPRECATED'));
363 // Extension was not found in task management
364 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_ID_404'));
366 } elseif ($task_found == '0') {
367 // No longer assigned or old task
368 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_ASSIGED'));
371 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_INVALID'));
376 loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_NOT_SAVED'));