Even more rewrites/fixes from EL branch (please report any broken part after you...
[mailer.git] / inc / modules / admin / what-extensions.php
index 3d47fee1d9dde02ec61a4da5fb2bef42b603d7b7..965bc1f8bd0596947ee5bcf40f27a72a16661948 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 03/22/2004 *
- * ================                             Last change: 12/13/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 03/22/2004 *
+ * ===================                          Last change: 12/13/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-extentions.php                              *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Erweiterungen-Management                         *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * Needs to be in all Files and every File needs "svn propset           *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  ************************************************************************/
 
 // Some security stuff...
-if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN())) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-}
+if ((!defined('__SECURITY')) || (!isAdmin())) {
+       die();
+} // END - if
 
 // Add description as navigation point
-ADD_DESCR("admin", basename(__FILE__));
-
-global $cacheInstance, $cacheArray, $cacheMode;
+addMenuDescription('admin', __FILE__);
 
 // Normally we want the overview of all registered extensions
-$do = "overview";
-$SEL = "0";
-if (!empty($_POST['sel'])) $SEL = SELECTION_COUNT($_POST['sel']);
+$do = 'overview';
 
-if (!empty($_GET['reg_ext'])) {
+if (isGetRequestParameterSet('reg_ext')) {
        // We are about to register a new extension
-       $do = "register"; $id = $_GET['reg_ext'];
-       // The ID comes from task management and it is - of course - *not* the extension's name!
-} elseif ((isset($_POST['change'])) && ($SEL > 0) && (!IS_DEMO())) {
+       $do = 'register'; $ext_id = bigintval(getRequestParameter('reg_ext'));
+       // The id comes from task management and it is - of course - *not* the extension's name!
+} elseif ((isFormSent('change')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
        // De-/activate extensions
-       foreach ($_POST['sel'] as $id=>$active) {
+       foreach (postRequestParameter('sel') as $ext_id => $active) {
                // Shall we keep the extension always active?
-               if ((isset($cacheArray['active_extensions'][GET_EXT_NAME($id)])) && ($cacheArray['active_extensions'][GET_EXT_NAME($id)] == "Y") && ($active == "N")) {
+               if ((isset($GLOBALS['cache_array']['always_active'][getExtensionName($ext_id)])) && ($GLOBALS['cache_array']['always_active'][getExtensionName($ext_id)] == 'Y') && ($active == 'Y')) {
                        // Keep this extension active!
+                       loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_ALWAYS_ACTIVE', getExtensionName($ext_id)));
                } else {
                        // De/activate extension
-                       $ACT = "N"; $EXT_LOAD_MODE = "deactivate";
-                       if ($active == "N") { $ACT = "Y"; $EXT_LOAD_MODE = "activate"; }
-                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_extensions SET ext_active='".$ACT."' WHERE id=%s AND ext_active='%s' LIMIT 1",
-                        array(bigintval($id), $active), __FILE__, __LINE__);
+                       $ACT = 'N'; setExtensionMode('deactivate');
+                       if ($active != 'Y') { $ACT = 'Y'; setExtensionMode('activate'); }
+                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s AND `ext_active`='%s' LIMIT 1",
+                               array($ACT, bigintval($ext_id), $active), __FILE__, __LINE__);
 
                        // Run embeded SQL commands
-                       EXTENSION_RUN_SQLS($id, $EXT_LOAD_MODE);
+                       doExtensionSqls($ext_id, getExtensionMode());
                }
-       }
-} elseif (((isset($_POST['edit'])) || (isset($_POST['modify']))) && ($SEL > 0) && (!IS_DEMO())) {
+       } // END - foreach
+
+       // Redirect to prevent missing cache in js.php
+       redirectToUrl('modules.php?module=admin&amp;what=extensions&amp;changed=' . countPostSelection());
+} elseif (((isFormSent('edit')) || (isPostRequestParameterSet('modify'))) && (countPostSelection() > 0) && (!isDemoModeActive())) {
        // Change settings like CSS file load
-       if (isset($_POST['modify'])) {
+       if (isPostRequestParameterSet('modify')) {
                // Change entries
-               $cacheInstance_UPDATE = "0";
-               foreach ($_POST['sel'] as $id=>$sel) {
-                       // Secure ID
-                       $id = bigintval($id);
+               $cache_update = '0';
+               foreach (postRequestParameter('sel') as $ext_id => $sel) {
+                       // Secure id
+                       $ext_id = bigintval($ext_id);
 
                        // Change this extension?
                        if ($sel == 1) {
+                               // Load mode is modify
+                               setExtensionMode('modify');
+
+                               // Get entry for 'active'
+                               $active = postRequestParameter('active', $ext_id);
+
                                // Update extension's record
-                               $active = $_POST['active'][$id];
-                               if (GET_EXT_VERSION("sql_patches") >= "0.0.6")  {
+                               if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
                                        // Update also CSS column when extensions sql_patches is newer or exact v0.0.6
-                                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_extensions SET ext_has_css='%s', ext_active='%s' WHERE id=%s LIMIT 1",
-                                        array($_POST['css'][$id], $active, $id), __FILE__, __LINE__);
+                                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_has_css`='%s', `ext_active`='%s' WHERE `id`=%s LIMIT 1",
+                                               array(postRequestParameter('css', $ext_id), $active, $ext_id), __FILE__, __LINE__);
                                } else {
                                        // When extension is older than v0.0.6 there is no column for the CSS information
-                                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_extensions SET ext_active='%s' WHERE id=%s LIMIT 1",
-                                        array($active, $id), __FILE__, __LINE__);
+                                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s LIMIT 1",
+                                               array($active, $ext_id), __FILE__, __LINE__);
                                }
 
                                // Run SQLs on activation / deactivation
                                switch ($active) {
-                                       case 'Y': $EXT_LOAD_MODE = "activate";   break;
-                                       case 'N': $EXT_LOAD_MODE = "deactivate"; break;
-                               }
+                                       case 'Y': setExtensionMode('activate');   break;
+                                       case 'N': setExtensionMode('deactivate'); break;
+                               } // END - if
 
                                // Run embeded SQL commands
-                               EXTENSION_RUN_SQLS($id, $EXT_LOAD_MODE);
+                               doExtensionSqls($ext_id, getExtensionMode());
                        }
                }
 
-               // Extensions changed
-               OUTPUT_HTML("<P align=\"center\">");
-               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_EXT_CHANGED);
-               OUTPUT_HTML("</P>");
+               // Redirect to prevent missing cache in js.php
+               redirectToUrl('modules.php?module=admin&amp;what=extensions&amp;edited=' . countPostSelection());
        } else {
                // Edit selected entries
-               $SW = "2"; $OUT = "";
-               foreach ($_POST['sel'] as $id=>$sel) {
+               $SW = 2; $OUT = '';
+               foreach (postRequestParameter('sel') as $ext_id => $sel) {
                        // Edit this extension?
-                       if (($sel == "Y") || ($sel == "N")) {
+                       if (($sel == 'Y') || ($sel != 'Y')) {
+                               // Default is no CSS for non-updated mailers
+                               $css = 'N';
+
                                // Load required data
-                               if (GET_EXT_VERSION("sql_patches") >= "0.0.6") {
-                                       $result = SQL_QUERY_ESC("SELECT ext_name, ext_has_css, ext_active FROM "._MYSQL_PREFIX."_extensions WHERE id=%s LIMIT 1",
-                                        array(bigintval($id)), __FILE__, __LINE__);
-                                       list($name, $css, $active) = SQL_FETCHROW($result);
+                               if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
+                                       $result = SQL_QUERY_ESC("SELECT ext_has_css, ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
+                                               array(bigintval($ext_id)), __FILE__, __LINE__);
+                                       list($css, $active) = SQL_FETCHROW($result);
                                        SQL_FREERESULT($result);
                                } else {
-                                       $result = SQL_QUERY_ESC("SELECT ext_name, ext_active FROM "._MYSQL_PREFIX."_extensions WHERE id=%s LIMIT 1",
-                                        array(bigintval($id)), __FILE__, __LINE__);
-                                       list($name, $active) = SQL_FETCHROW($result);
+                                       $result = SQL_QUERY_ESC("SELECT ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
+                                               array(bigintval($ext_id)), __FILE__, __LINE__);
+                                       list($active) = SQL_FETCHROW($result);
                                        SQL_FREERESULT($result);
-                                       $css = "X";
+                                       $css = 'X';
                                }
 
-                               // Output row
-                               $CSS = "---";
-                               if (GET_EXT_VERSION("sql_patches") >= "0.0.6") $CSS = ADD_SELECTION("yn", $css, "css", $id);
+                               // Prepare CSS column
+                               $cssSelection = '---';
+                               if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
+                                       $cssSelection = addSelectionBox('yn', $css, 'css', $ext_id);
+                               } // END - if
 
                                // Prepare data for the row template
                                $content = array(
                                        'sw'     => $SW,
-                                       'id'     => $id,
-                                       'name'   => $name,
-                                       'active' => ADD_SELECTION("yn", $active, "active", $id),
-                                       'css'    => $CSS,
+                                       'id'     => $ext_id,
+                                       'name'   => getExtensionName($ext_id),
+                                       'active' => addSelectionBox('yn', $active, 'active', $ext_id),
+                                       'css'    => $cssSelection,
                                );
 
                                // Load row template and switch color
-                               $OUT .= LOAD_TEMPLATE("admin_extensions_edit_row", true, $content);
+                               $OUT .= loadTemplate('admin_extensions_edit_row', true, $content);
                                $SW = 3 - $SW;
                        }
                } // END - foreach
-               define('__EXTENSIONS_ROWS', $OUT);
 
                // Load template
-               LOAD_TEMPLATE("admin_extensions_edit");
-               $do = "edit";
+               loadTemplate('admin_extensions_edit', false, $OUT);
+               $do = 'edit';
        }
-} elseif ((isset($_POST['delete'])) && ($SEL > 0) && (!IS_DEMO())) {
+} elseif ((isPostRequestParameterSet('delete')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
        // List extensions and when verbose is enabled SQL statements which will be executed
-       $SW = 2; $OUT = "";
-       foreach ($_POST['sel'] as $id=>$sel) {
+       $OUT = ''; $SW = 2;
+       foreach (postRequestParameter('sel') as $ext_id => $sel) {
                // Init variables
-               $VERBOSE_OUT = ""; $SQLs = array();
+               $VERBOSE_OUT = '';
+               initSqls();
 
                // Secure id number
-               $id = bigintval($id);
+               $ext_id = bigintval($ext_id);
 
-               // Get extension name
-               $ext_name = GET_EXT_NAME($id);
-               $ext_ver = GET_EXT_VERSION($ext_name);
+               // Is the id valid?
+               if (isExtensionIdValid($ext_id)) {
+                       // Get extension name
+                       $ext_name = getExtensionName($ext_id);
 
-               // Free the result
-               SQL_FREERESULT($result);
+                       if (getConfig('verbose_sql') == 'Y') {
+                               // Load SQL commands in remove mode
+                               if (loadExtension($ext_name, 'remove', '', true)) {
+                                       // Generate extra table with loaded SQL commands
+                                       $VERBOSE_OUT = addExtensionVerboseSqlTable();
+                               } // END - if
+                       } // END - if
 
-               if ($_CONFIG['verbose_sql']) {
-                       // Load SQL commands in remove mode
-                       $EXT_LOAD_MODE = "remove";
-                       $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name);
-                       include($file);
+                       // Prepare data for the row template
+                       $content = array(
+                               'sw'       => $SW,
+                               'id'       => $ext_id,
+                               'ext_name' => $ext_name,
+                               'ext_ver'  => getExtensionVersion($ext_name),
+                               'verbose'  => $VERBOSE_OUT
+                       );
 
-                       // Generate extra table with loaded SQL commands
-                       $VERBOSE_OUT = EXTENSION_VERBOSE_TABLE($SQLs);
-               } // END - if
+                       // Load row template and switch color
+                       $OUT .= loadTemplate('admin_extensions_delete_row', true, $content);
+               } else {
+                       // Prepare data for the row template
+                       $content = array(
+                               'sw'       => $SW,
+                               'id'       => $ext_id
+                       );
 
-               // Prepare data for the row template
-               $content = array(
-                       'sw'       => $SW,
-                       'id'       => $id,
-                       'ext_name' => $ext_name,
-                       'ext_ver'  => $ext_ver,
-                       'verbose'  => $VERBOSE_OUT
-               );
-
-               // Load row template and switch color
-               $OUT .= LOAD_TEMPLATE("admin_extensions_delete_row", true, $content);
+                       // Not valid!
+                       $OUT .= loadTemplate('admin_extensions_delete_row_404', true, $content);
+               }
                $SW = 3 - $SW;
        } // END - foreach
-       define('__EXTENSIONS_ROWS', $OUT);
 
        // Load template
-       LOAD_TEMPLATE("admin_extensions_delete");
-       $do = "delete";
-} elseif ((isset($_POST['remove'])) && ($SEL > 0) && (!IS_DEMO())) {
+       loadTemplate('admin_extensions_delete', false, $OUT);
+       $do = 'delete';
+} elseif ((isFormSent('remove')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
        // Remove extensions from DB (you have to delete all files manually!)
-       $cacheInstance_UPDATE = "0";
-       foreach ($_POST['sel'] as $id=>$active) {
-               // Secure ID number
-               $id = bigintval($id);
+       $cache_update = '0';
+       foreach (postRequestParameter('sel') as $ext_id => $active) {
+               // Secure id number
+               $ext_id = bigintval($ext_id);
 
-               // Is this extension selected?
-               if ($active == 1) {
+               // Is this extension selected and id valid?
+               if (($active == 1) && (isExtensionIdValid($ext_id))) {
                        // Run embeded SQL commands
-                       EXTENSION_RUN_SQLS($id, "remove");
+                       doExtensionSqls($ext_id, 'remove');
                } // END - if
        } // END - foreach
-} elseif (!empty($_GET['do']) && (!IS_DEMO())) {
+
+       // Redirect to prevent missing cache in js.php
+       redirectToUrl('modules.php?module=admin&amp;what=extensions&amp;removed=' . countPostSelection());
+} elseif ((isGetRequestParameterSet('do')) && (!isDemoModeActive())) {
        // Other things to do
-       $do = SQL_ESCAPE(strip_tags($_GET['do']));
-} elseif (!empty($_GET['do'])) {
+       $do = SQL_ESCAPE(secureString(getRequestParameter('do')));
+} elseif (isGetRequestParameterSet('do')) {
        // Demo mode active!
-       $do = "demo";
+       $do = 'demo';
+} elseif (isGetRequestParameterSet('changed')) {
+       // Extensions changed
+       loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_CHANGED', bigintval(getRequestParameter('changed'))));
+} elseif (isGetRequestParameterSet('edited')) {
+       // Extensions changed
+       loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_EDITED', bigintval(getRequestParameter('edited'))));
+} elseif (isGetRequestParameterSet('removed')) {
+       // Extensions changed
+       loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSIONS_REMOVED', bigintval(getRequestParameter('removed'))));
 }
 
 // Shall we display active/inactive extensions?
-$where = "";
-if (!empty($_GET['active'])) {
-       $where = sprintf("WHERE ext_active = '%s'", SQL_ESCAPE(strip_tags($_GET['active'])));
+$where = '';
+if (isGetRequestParameterSet(('active'))) {
+       $where = sprintf("WHERE `ext_active`='%s'", SQL_ESCAPE(secureString(getRequestParameter('active'))));
 } // END - if
 
 // Case selection
 switch ($do) {
-case "overview": // List all registered extensions
-       if (GET_EXT_VERSION("sql_patches") >= "0.0.6") {
-               // Load extension data with CSS informations
-               $result = SQL_QUERY("SELECT id, ext_name, ext_lang_file, ext_active, ext_has_css, ext_version
-               FROM "._MYSQL_PREFIX."_extensions
-               ".$where."
-               ORDER BY ext_name", __FILE__, __LINE__);
-       } else {
-               // Load extension data without CSS informations
-               $result = SQL_QUERY("SELECT id, ext_name, ext_lang_file, ext_active, id, ext_version
-               FROM "._MYSQL_PREFIX."_extensions
-               ".$where."
-               ORDER BY ext_name", __FILE__, __LINE__);
-       }
-
-       // Are there some entries?
-       if (SQL_NUMROWS($result) > 0) {
-               // Extensions are registered
-               $SW = 2; $OUT = "";
-               while (list($id, $name, $lang, $active, $css, $ver) = SQL_FETCHROW($result)) {
-                       $CSS = "---";
-                       if (GET_EXT_VERSION("sql_patches") >= "0.0.6") $CSS = TRANSLATE_YESNO($css);
-
-                       // Prepare data for the row template
-                       $content = array(
-                               'sw'      => $SW,
-                               'id'      => $id,
-                               'name'    => $name,
-                               'active'  => TRANSLATE_YESNO($active),
-                               'act_val' => $active,
-                               'lang'    => $lang,
-                               'css'     => $CSS,
-                               'ver'     => $ver,
-                       );
-
-                       // Load row template and switch color
-                       $OUT .= LOAD_TEMPLATE("admin_extensions_row", true, $content);
-                       $SW = 3 - $SW;
-               }
-
-               // Free memory
-               SQL_FREERESULT($result);
-
-               // Remember rows in constant for the template
-               define('__EXT_ROWS', $OUT);
-
-               // Load template
-               LOAD_TEMPLATE("admin_extensions");
-       } else {
-               // No extensions are registered
-               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_EXTENSION_REGISTERED."</FONT>");
-       }
-       // Link for checking for new or updated extensions
-       OUTPUT_HTML("<br /><A href=\"".URL."/modules.php?module=admin&amp;what=extensions&amp;do=search\">".ADMIN_SEARCH_NEW_EXTENSIONS."</A>");
-       break;
-
-case "register": // Register new extension
-       $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_task_system WHERE assigned_admin='%s' AND task_type='EXTENSION' LIMIT 1",
-        array(bigintval(GET_ADMIN_ID(get_session('admin_login')))), __FILE__, __LINE__);
-       $task_found = SQL_NUMROWS($result);
-
-       // Free result
-       SQL_FREERESULT($result);
-
-       // Is the ID number valid and the task was found?
-       if (($id > 0) && ($task_found == 1)) {
-               // ID is valid so begin with registration, we first want to it's real name from task management (subject column)
-               $result = SQL_QUERY_ESC("SELECT subject FROM "._MYSQL_PREFIX."_task_system WHERE id=%s LIMIT 1",
-                array(bigintval($id)), __FILE__, __LINE__);
-               list($subj) = SQL_FETCHROW($result);
-               SQL_FREERESULT($result);
-
-               // Disable cache update by default
-               $cacheInstance_UPDATE = "0";
-               if (!empty($subj)) {
-                       // Extract extension's name from subject...
-                       $ext_name = trim(substr($subj, 1, strpos($subj, ":") - 1));
-
-                       // ... so we can finally register and load it in registration mode
-                       $status = EXTENSION_REGISTER($ext_name, $id);
-                       if ($status == true) {
-                               // Extension was found and successfully registered
-                               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_EXTENSION_REGISTERED);
-
-                               // Do we need to update cache file?
-                               if ((EXT_IS_ACTIVE("cache")) && ($cacheMode != "no")) {
-                                       // Remove cache file (will be auto-created again!)
-                                       if ($cacheInstance->cache_file("config"    , true)) $cacheInstance->cache_destroy();
-                                       if ($cacheInstance->cache_file("extensions", true)) $cacheInstance->cache_destroy();
-                                       if ($cacheInstance->cache_file("mod_reg"   , true)) $cacheInstance->cache_destroy();
-                               }
-                       } elseif (GET_EXT_VERSION($ext_name) != "") {
-                               // Motify the admin that we have a problem here...
-                               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_REG_FAILED_ALREADY);
-                       } else {
-                               // Motify the admin that we have a problem here...
-                               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_REG_FAILED_404);
-                       }
+       case 'overview': // List all registered extensions
+               if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
+                       // Load extension data with CSS informations
+                       $result = SQL_QUERY("SELECT `id` AS ext_id, `ext_name`, `ext_active`, `ext_has_css` AS ext_css, `ext_version`
+FROM `{?_MYSQL_PREFIX?}_extensions`
+".$where."
+ORDER BY `ext_name` ASC", __FILE__, __LINE__);
                } else {
-                       // Extension was not found in task management
-                       LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_REG_FAILED_ID_404);
-               }
-       } elseif ($task_found == "0") {
-               // No longer assigned or old task
-               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_REG_FAILED_ASSIGED);
-       } else {
-               // ID is invalid
-               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_REG_FAILED_INVALID);
-       }
-       break;
-
-case "search": // Search for new extensions on our server
-       // Get response from our server
-       $response = MXCHANGE_OPEN("extensions.php");
-
-       // Are extensions found?
-       if (($response[sizeof($response) - 1] == "[EOF]") && ($response[0] != "[EOF]"))
-       {
-               // Ok, mark found and create the array
-               $EXT_SEARCH = array(
-                       'fname'  => array(), // File names
-                       'fsize'  => array(), // File size
-                       'fctime' => array(), // File creation timestamp
-                       'infos'  => array(), // File informations (maybe loaded!)
-                       'ver'    => array(), // Version number
-                       'cver'   => array(), // Current version number
-               );
-
-               // Get count of extensions for validation
-               $count = trim($response[sizeof($response) - 2]);
-               foreach ($response as $id=>$value)
-               {
-                       $value = str_replace("\n", "", $value); $ver = "";
-                       // Leave loop when data is invalid or EOF?
-                       if ((substr($value, 0, 4) == "ext-") && (substr($value, -4) == ".zip"))
-                       {
-                               $name = substr($value, 4, -4);
-                               $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $name);
-                               $ver = trim(substr($response[$id + 3], 4));
-
-                               // Load current extension's version
-                               $cver = GET_EXT_VERSION($name);
-                               if (empty($cver)) $cver = "-.-";
-
-                               // Is the extension already installed or not?
-                               if (!file_exists($file) || ($ver != $cver))
-                               {
-                                       // No, it isn't. So let's add this one!
-                                       $EXT_SEARCH['fname'][]  = $name;
-                                       $EXT_SEARCH['fsize'][]  = $response[$id + 1];
-                                       $EXT_SEARCH['fctime'][] = $response[$id + 2];
-                                       $EXT_SEARCH['ver'][]    = $ver;
-                                       $EXT_SEARCH['cver'][]   = $cver;
-
-                                       $LANG_DUMMY = explode("[nl]", $response[$id + 4]);
-                                       $LANG = array();
-                                       $INFO = ADMIN_EXT_NO_INFO_FOUND;
-
-                                       // Trim every data line
-                                       foreach ($LANG_DUMMY as $k=>$v)
-                                       {
-                                               $v = trim($v);
-                                               if (substr($v, 3) == "") $v = "---";
-                                               $LANG_DUMMY[$k] = $v;
-                                               if ($v == "xx:xx") break;
-                                               $LANG[] = $v;
-                                       }
-
-                                       // If language is found stop searching on matching line
-                                       foreach($LANG as $search)
-                                       {
-                                               if (substr($search, 0, 3) == (GET_LANGUAGE().":")) { $INFO = substr($search, 3); break; }
-                                       }
-
-                                       // Add informations to array
-                                       $EXT_SEARCH['infos'][] = $INFO;
-                               }
-                       }
+                       // Load extension data without CSS informations
+                       $result = SQL_QUERY("SELECT `id` AS ext_id, `ext_name`, `ext_active`, `id`, `ext_version`
+FROM `{?_MYSQL_PREFIX?}_extensions`
+".$where."
+ORDER BY `ext_name` ASC", __FILE__, __LINE__);
                }
 
-               // Ok, extensions are on our server but maybe you have already installed them?
-               if (sizeof($EXT_SEARCH['fname']) > 0)
-               {
-                       // Sort array (I missed ver and cver here)
-                       array_pk_sort($EXT_SEARCH, array("cver", "fname"), 0, 1);
-
-                       // Extensions where found which are not downloaded and installed
-                       $SW = 2; $OUT = ""; $TSIZE = 0;
-                       foreach ($EXT_SEARCH['fname'] as $id=>$name)
-                       {
-                               // Generate download link
-                               $LINK = SERVER_URL."/extensions/ext-".$name.".zip";
+               // Are there some entries?
+               if (SQL_NUMROWS($result) > 0) {
+                       // Extensions are registered
+                       $OUT = ''; $SW = 2;
+                       while ($content = SQL_FETCHARRAY($result)) {
+                               // Prepare CSS selection output
+                               $cssSelection = '---';
+                               if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) $cssSelection = translateYesNo($content['ext_css']);
 
                                // Prepare data for the row template
                                $content = array(
                                        'sw'      => $SW,
-                                       'id'      => ($id + 1),
-                                       'name'    => $name,
-                                       'new_ver' => $EXT_SEARCH['ver'][$id],
-                                       'old_ver' => $EXT_SEARCH['cver'][$id],
-                                       'link'    => $LINK,
-                                       'last'    => MAKE_DATETIME($EXT_SEARCH['fctime'][$id], "2"),
-                                       'size'    => TRANSLATE_COMMA(round($EXT_SEARCH['fsize'][$id] / 1.024) / 1000),
-                                       'info'    => $EXT_SEARCH['infos'][$id],
+                                       'id'      => $content['ext_id'],
+                                       'name'    => $content['ext_name'],
+                                       'active'  => translateYesNo($content['ext_active']),
+                                       'act_val' => $content['ext_active'],
+                                       'css'     => $cssSelection,
+                                       'ver'     => $content['ext_version'],
                                );
 
-                               // Load row template add current size to total size and switch color
-                               $OUT .= LOAD_TEMPLATE("admin_list_extensions_row", true, $content);
-                               $TSIZE += $EXT_SEARCH['fsize'][$id];
+                               // Load row template and switch color
+                               $OUT .= loadTemplate('admin_extensions_row', true, $content);
                                $SW = 3 - $SW;
                        }
-                       define('__EXTENSIONS_ROWS', $OUT);
-                       define('__TKBYTES_VALUE', TRANSLATE_COMMA(round($TSIZE / 1.024) / 1000));
-                       define('__TEXT_VALUE', sizeof($EXT_SEARCH['fname']));
+
+                       // Free memory
+                       SQL_FREERESULT($result);
 
                        // Load template
-                       LOAD_TEMPLATE("admin_list_extensions");
+                       loadTemplate('admin_extensions', false, $OUT);
+               } else {
+                       // No extensions are registered
+                       loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_EXTENSION_REGISTERED'));
                }
-                else
-               {
-                       // All extensions are downloaded and installed
-                       LOAD_TEMPLATE("admin_extensions_installed", false, $count);
+               break;
+
+       case 'register': // Register new extension
+               $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `assigned_admin`=%s AND `task_type`='EXTENSION' LIMIT 1",
+                       array(getCurrentAdminId()), __FILE__, __LINE__);
+               $task_found = SQL_NUMROWS($result);
+
+               // Free result
+               SQL_FREERESULT($result);
+
+               // Is the id number valid and the task was found?
+               if (($ext_id > 0) && ($task_found == 1)) {
+                       // id is valid so begin with registration, we first want to it's real name from task management (subject column)
+                       $result = SQL_QUERY_ESC("SELECT `subject` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
+                               array(bigintval($ext_id)), __FILE__, __LINE__);
+                       list($subj) = SQL_FETCHROW($result);
+
+                       // Free result
+                       SQL_FREERESULT($result);
+
+                       // Disable cache update by default
+                       $cache_update = '0';
+                       if (!empty($subj)) {
+                               // Extract extension's name from subject...
+                               $ext_name = trim(substr($subj, 1, strpos($subj, ':') - 1));
+
+                               // Test the extension for deprecation
+                               loadExtension($ext_name, 'test');
+
+                               // Is the extension deprecated?
+                               if (!isExtensionDeprecated()) {
+                                       // ... so we can finally register and load it in registration mode
+                                       if (registerExtension($ext_name, $ext_id)) {
+                                               // Errors?
+                                               if (!ifFatalErrorsDetected()) {
+                                                       // Extension was found and successfully registered
+                                                       loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_REGISTERED', $ext_name));
+
+                                                       // Show next link
+                                                       if (isExtensionActive('task')) {
+                                                               loadTemplate('admin_next_link', false, array(
+                                                                       'url'   => 'modules.php?module=admin&amp;what=list_task',
+                                                                       'title' => getMessage('ADMIN_EXTENSION_REGISTER_NEXT_LINK')
+                                                               ));
+                                                       } else {
+                                                               loadTemplate('admin_next_link', false, array(
+                                                                       'url'   => 'modules.php?module=admin',
+                                                                       'title' => getMessage('ADMIN_EXTENSION_REGISTER_NEXT_LINK')
+                                                               ));
+                                                       }
+                                               } else {
+                                                       // Errors detected!
+                                                       loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_NOT_REGISTERED', $ext_name));
+                                               }
+
+                                               // Do we need to update cache file?
+                                               // @TODO Rewrite this to a filter
+                                               if (isExtensionActive('cache')) {
+                                                       // Remove cache file (will be auto-created again!)
+                                                       if ($GLOBALS['cache_instance']->loadCacheFile('config'))    $GLOBALS['cache_instance']->removeCacheFile();
+                                                       if ($GLOBALS['cache_instance']->loadCacheFile('extension')) $GLOBALS['cache_instance']->removeCacheFile();
+                                                       if ($GLOBALS['cache_instance']->loadCacheFile('filter'))    $GLOBALS['cache_instance']->removeCacheFile();
+                                                       if ($GLOBALS['cache_instance']->loadCacheFile('modules'))   $GLOBALS['cache_instance']->removeCacheFile();
+                                               } // END - if
+                                       } elseif (isExtensionInstalled($ext_name)) {
+                                               // Notify the admin that we have a problem here...
+                                               loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_ALREADY'));
+                                       } else {
+                                               // Notify the admin that we have a problem here...
+                                               loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_REG_FAILED_404', $ext_name));
+                                       }
+                               } else {
+                                       // Motify the admin that we have a problem here...
+                                       loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_DEPRECATED'));
+                               }
+                       } else {
+                               // Extension was not found in task management
+                               loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_ID_404'));
+                       }
+               } elseif ($task_found == '0') {
+                       // No longer assigned or old task
+                       loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_ASSIGED'));
+               } else {
+                       // id is invalid
+                       loadTemplate('admin_settings_saved', false, getMessage('ADMIN_REG_FAILED_INVALID'));
                }
-       }
-        else
-       {
-               // No extensions where found
-               LOAD_TEMPLATE("admin_extensions_404");
-       }
-       break;
+               break;
 
-case "demo":
-       LOAD_TEMPLATE("admin_settings_saved", false, SETTINGS_NOT_SAVED);
-       break;
-}
-//
+       case 'demo':
+               loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_NOT_SAVED'));
+               break;
+} // END - switch
+
+// [EOF]
 ?>