From 2a252331b627de4ae28b11a60f82c63b75a8b758 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 25 Jan 2008 22:30:44 +0000 Subject: [PATCH] List active/inactive extensions --- 0.2.1/inc/libs/task_functions.php | 2 +- 0.2.1/inc/modules/admin/what-extensions.php | 181 ++++++++---------- .../de/html/admin/admin_list_extensions.tpl | 22 +-- 3 files changed, 90 insertions(+), 115 deletions(-) diff --git a/0.2.1/inc/libs/task_functions.php b/0.2.1/inc/libs/task_functions.php index 249a757ec1..ee72a2a4c0 100644 --- a/0.2.1/inc/libs/task_functions.php +++ b/0.2.1/inc/libs/task_functions.php @@ -473,7 +473,7 @@ ORDER BY beg_points DESC, userid"; // All activated extensions // $SQLs[] = "SELECT id FROM "._MYSQL_PREFIX."_extensions WHERE ext_active='Y' ORDER BY id"; - $WHATs[] = "extensions"; + $WHATs[] = "extensions&active=Y"; $DESCRs[] = TASK_ADMIN_LIST_EXTENSIONS_ACTIVE; $TITLEs[] = TASK_ADMIN_LIST_EXTENSIONS_ACTIVE_TITLE; // diff --git a/0.2.1/inc/modules/admin/what-extensions.php b/0.2.1/inc/modules/admin/what-extensions.php index da93337c92..eb3a1e59d0 100644 --- a/0.2.1/inc/modules/admin/what-extensions.php +++ b/0.2.1/inc/modules/admin/what-extensions.php @@ -32,29 +32,26 @@ ************************************************************************/ // Some security stuff... -if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN())) -{ +if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN())) { $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php"; require($INC); -} +} + // Add description as navigation point ADD_DESCR("admin", basename(__FILE__)); global $CACHE, $KEEP_ACTIVE, $CACHE_FILE; // Normally we want the overview of all registered extensions -$mode = "overview"; +$do = "overview"; $SEL = "0"; if (!empty($_POST['sel'])) $SEL = SELECTION_COUNT($_POST['sel']); -if (!empty($_GET['reg_ext'])) -{ +if (!empty($_GET['reg_ext'])) { // We are about to register a new extension - $mode = "register"; $id = $_GET['reg_ext']; + $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())) -{ +} elseif ((isset($_POST['change'])) && ($SEL > 0) && (!IS_DEMO())) { // De-/activate extensions foreach ($_POST['sel'] as $id=>$active) { // Shall we keep the extension always active? @@ -71,39 +68,31 @@ if (!empty($_GET['reg_ext'])) EXTENSION_RUN_SQLS($id, $EXT_LOAD_MODE); } } -} - elseif (((isset($_POST['edit'])) || (isset($_POST['modify']))) && ($SEL > 0) && (!IS_DEMO())) -{ +} elseif (((isset($_POST['edit'])) || (isset($_POST['modify']))) && ($SEL > 0) && (!IS_DEMO())) { // Change settings like CSS file load - if (isset($_POST['modify'])) - { + if (isset($_POST['modify'])) { // Change entries $CACHE_UPDATE = "0"; - foreach ($_POST['sel'] as $id=>$sel) - { + foreach ($_POST['sel'] as $id=>$sel) { // Secure ID $id = bigintval($id); // Change this extension? - if ($sel == 1) - { + if ($sel == 1) { // Update extension's record $active = $_POST['active'][$id]; - if (GET_EXT_VERSION("sql_patches") >= "0.0.6") - { + if (GET_EXT_VERSION("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=%d LIMIT 1", array($_POST['css'][$id], $active, $id), __FILE__, __LINE__); - } - else - { + } 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=%d LIMIT 1", array($active, $id), __FILE__, __LINE__); - } + } + // Run SQLs on activation / deactivation - switch ($active) - { + switch ($active) { case "Y": $EXT_LOAD_MODE = "activate"; break; case "N": $EXT_LOAD_MODE = "deactivate"; break; } @@ -117,26 +106,19 @@ if (!empty($_GET['reg_ext'])) OUTPUT_HTML ("

"); LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_EXT_CHANGED); OUTPUT_HTML ("

"); - } - else - { + } else { // Edit selected entries $SW = "2"; $OUT = ""; - foreach ($_POST['sel'] as $id=>$sel) - { + foreach ($_POST['sel'] as $id=>$sel) { // Edit this extension? - if (($sel == "Y") || ($sel == "N")) - { + if (($sel == "Y") || ($sel == "N")) { // Load required data - if (GET_EXT_VERSION("sql_patches") >= "0.0.6") - { + 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=%d LIMIT 1", array(bigintval($id)), __FILE__, __LINE__); list($name, $css, $active) = SQL_FETCHROW($result); SQL_FREERESULT($result); - } - else - { + } else { $result = SQL_QUERY_ESC("SELECT ext_name, ext_active FROM "._MYSQL_PREFIX."_extensions WHERE id=%d LIMIT 1", array(bigintval($id)), __FILE__, __LINE__); list($name, $active) = SQL_FETCHROW($result); @@ -166,24 +148,22 @@ if (!empty($_GET['reg_ext'])) // Load template LOAD_TEMPLATE("admin_extensions_edit"); - $mode = "edit"; + $do = "edit"; } -} - elseif ((isset($_POST['delete'])) && ($SEL > 0) && (!IS_DEMO())) -{ +} elseif ((isset($_POST['delete'])) && ($SEL > 0) && (!IS_DEMO())) { // List extensions and when verbose is enabled SQL statements which will be executed $SW = 2; $OUT = ""; - foreach ($_POST['sel'] as $id=>$sel) - { + foreach ($_POST['sel'] as $id=>$sel) { $VERBOSE_OUT = ""; $SQLs = array(); // Load extension's data $result = SQL_QUERY_ESC("SELECT ext_name, ext_version FROM "._MYSQL_PREFIX."_extensions WHERE id=%d LIMIT 1", array(bigintval($id)), __FILE__, __LINE__); - list($ext_name, $ext_ver) = SQL_FETCHROW($result); + list($ext_name, $ext_ver) = SQL_FETCHROW($result); + + // Free the result SQL_FREERESULT($result); - if ($CONFIG['verbose_sql']) - { + if ($CONFIG['verbose_sql']) { // Load SQL commands in remove mode $EXT_LOAD_MODE = "remove"; $file = sprintf(PATH."inc/extensions/ext-%s.php", $ext_name); @@ -210,16 +190,16 @@ if (!empty($_GET['reg_ext'])) // Load template LOAD_TEMPLATE("admin_extensions_delete"); - $mode = "delete"; -} - elseif ((isset($_POST['remove'])) && ($SEL > 0) && (!IS_DEMO())) -{ + $do = "delete"; +} elseif ((isset($_POST['remove'])) && ($SEL > 0) && (!IS_DEMO())) { // Remove extensions from DB (you have to delete all files manually!) $CACHE_UPDATE = "0"; - foreach ($_POST['sel'] as $id=>$active) - { - if ($active == 1) - { + foreach ($_POST['sel'] as $id=>$active) { + // Secure ID number + $id = bigintval($id); + + // Is this extension selected? + if ($active == 1) { // Run embeded SQL commands EXTENSION_RUN_SQLS($id, "remove"); @@ -228,37 +208,42 @@ if (!empty($_GET['reg_ext'])) array(bigintval($id)), __FILE__, __LINE__); } } -} - elseif (!empty($_GET['do']) && (!IS_DEMO())) -{ +} elseif (!empty($_GET['do']) && (!IS_DEMO())) { // Other things to do - $mode = $_GET['do']; -} - elseif (!empty($_GET['do'])) -{ + $do = SQL_ESCAPE(strip_tags($_GET['do'])); +} elseif (!empty($_GET['do'])) { // Demo mode active! - $mode = "demo"; + $do = "demo"; } - -switch ($mode) -{ + +// Shall we display active/inactive extensions? +$where = ""; +if (!empty($_GET['active'])) { + $where = sprintf("WHERE ext_active = '%s'", SQL_ESCAPE(strip_tags($_GET['active']))); +} + +// Case selection +switch ($do) { case "overview": // List all registered extensions - if (GET_EXT_VERSION("sql_patches") >= "0.0.6") - { + 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 ORDER BY ext_name", __FILE__, __LINE__); - } - else - { + $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 ORDER BY ext_name", __FILE__, __LINE__); - } - if (SQL_NUMROWS($result) > 0) - { + $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)) - { + 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); @@ -287,9 +272,7 @@ case "overview": // List all registered extensions // Load template LOAD_TEMPLATE("admin_extensions"); - } - else - { + } else { // No extensions are registered LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_EXTENSION_REGISTERED.""); } @@ -300,10 +283,13 @@ case "overview": // List all registered extensions 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($_COOKIE['admin_login']))), __FILE__, __LINE__); - $task_found = SQL_NUMROWS($result); + $task_found = SQL_NUMROWS($result); + + // Free result SQL_FREERESULT($result); - if (($id > 0) && ($task_found == 1)) - { + + // 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=%d LIMIT 1", array(bigintval($id)), __FILE__, __LINE__); @@ -312,44 +298,33 @@ case "register": // Register new extension // Disable cache update by default $CACHE_UPDATE = "0"; - if (!empty($subj)) - { + 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) - { + if ($status) { // 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")) && ($CACHE_FILE != "no")) - { + if ((EXT_IS_ACTIVE("cache")) && ($CACHE_FILE != "no")) { // Remove cache file (will be auto-created again!) if ($CACHE->cache_file("extensions", true)) $CACHE->cache_destroy(); } - } - else - { + } else { // Motify the admin that we have a problem here... LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_REG_FAILED_404); } - } - else - { + } else { // Extension was not found in task management LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_REG_FAILED_ID_404); } - } - elseif ($task_found == "0") - { + } elseif ($task_found == "0") { // No longer assigned or old task LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_REG_FAILED_ASSIGED); - } - else - { + } else { // ID is invalid LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_REG_FAILED_INVALID); } diff --git a/0.2.1/templates/de/html/admin/admin_list_extensions.tpl b/0.2.1/templates/de/html/admin/admin_list_extensions.tpl index a152725f15..8e710a7711 100644 --- a/0.2.1/templates/de/html/admin/admin_list_extensions.tpl +++ b/0.2.1/templates/de/html/admin/admin_list_extensions.tpl @@ -1,19 +1,19 @@ - + - - - - - + + + + + {!__EXTENSIONS_ROWS!} - - + + -
- {--ADMIN_EXT_NEW_FOUND_TITLE--}: - + {--ADMIN_EXT_NEW_FOUND_TITLE--}: +
{--ID_SELECT--}{--ADMIN_EXT_DOWNLOAD_LINK--}{--ADMIN_EXT_FILE_CTIME--}{--ADMIN_EXT_FILE_SIZE--}{--ADMIN_EXT_FILE_VERSION--}{--ID_SELECT--}{--ADMIN_EXT_DOWNLOAD_LINK--}{--ADMIN_EXT_FILE_CTIME--}{--ADMIN_EXT_FILE_SIZE--}{--ADMIN_EXT_FILE_VERSION--}
{--ADMIN_EXT_TOTAL_FOUND--}: {!__TEXT_VALUE!}{--ADMIN_EXT_TOTAL_FSIZE--}:  {--__TKBYTES_VALUE--} {--KBYTES--}  {--ADMIN_EXT_TOTAL_FOUND--}: {!__TEXT_VALUE!}{--ADMIN_EXT_TOTAL_FSIZE--}:  {--__TKBYTES_VALUE--} {--KBYTES--}  
\ No newline at end of file + -- 2.39.5