- // Load template
- LOAD_TEMPLATE("admin_extensions");
- } else {
- // No extensions are registered
- LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_EXTENSION_REGISTERED."</FONT>");
- }
- 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
- $cache_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")) $cacheInstance->cache_destroy();
- if ($cacheInstance->cache_file("extensions", true)) $cacheInstance->cache_destroy();
- if ($cacheInstance->cache_file("mod_reg")) $cacheInstance->cache_destroy();
- } // END - if
- } 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);
+ // Load template
+ loadTemplate('admin_extensions', false, $OUT);
+ } else {
+ // No extensions are registered
+ loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_EXTENSION_REGISTERED--}');
+ }
+ break;
+
+ case 'register': // Register new extension
+ // Do we have some tasks?
+ $numTasks = countSumTotalData(getCurrentAdminId(), 'task_system', 'id', 'assigned_admin', true, "AND `task_type`='EXTENSION'");
+
+ // Is the id number valid and the task was found?
+ if (($taskId > 0) && ($numTasks > 0)) {
+ // 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($taskId)), __FILE__, __LINE__);
+ list($subject) = SQL_FETCHROW($result);
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Disable cache update by default
+ $cache_update = '0';
+ if (!empty($subject)) {
+ // Extract extension's name from subject...
+ $ext_name = trim(substr($subject, 1, strpos($subject, ':') - 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, $taskId)) {
+ // Errors?
+ if (!ifFatalErrorsDetected()) {
+ // Extension was found and successfully registered
+ redirectToUrl('modules.php?module=admin&what=extensions&registered=' . getExtensionId($ext_name));
+ } 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, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ALREADY--}');
+ } else {
+ // Notify the admin that we have a problem here...
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_REGISTRATION_FAILED_404', $ext_name));
+ }
+ } else {
+ // Motify the admin that we have a problem here...
+ loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_DEPRECATED--}');
+ }