diff --git a/main/admin/configure_plugin.php b/main/admin/configure_plugin.php index e55624b281..6e6b8d195c 100755 --- a/main/admin/configure_plugin.php +++ b/main/admin/configure_plugin.php @@ -69,6 +69,10 @@ if (isset($form)) { 1 ); } + if (isset($values['show_main_menu_tab'])) { + $objPlugin = $plugin_info['plugin_class']::create(); + $objPlugin->manageTab($values['show_main_menu_tab']); + } $message = Display::return_message(get_lang('Updated'), 'success'); } } diff --git a/main/inc/lib/plugin.class.php b/main/inc/lib/plugin.class.php index e7a42d0aca..6982890b6a 100755 --- a/main/inc/lib/plugin.class.php +++ b/main/inc/lib/plugin.class.php @@ -189,6 +189,12 @@ class Plugin $help = null; if ($this->get_lang_plugin_exists($name.'_help')) { $help = $this->get_lang($name.'_help'); + if ($name === "show_main_menu_tab") { + $pluginName = strtolower(str_replace('Plugin', '', get_class($this))); + $pluginUrl = api_get_path(WEB_PATH)."plugin/$pluginName/index.php"; + $pluginUrl = "$pluginUrl"; + $help = sprintf($help, $pluginUrl); + } } switch ($type) { @@ -635,4 +641,35 @@ class Plugin return $resp; } + + /** + * This method shows or hides plugin's tab + * @param boolean Shows or hides the main menu plugin tab + */ + public function manageTab($showTab) + { + $langString = str_replace('Plugin', '', get_class($this)); + $pluginName = strtolower($langString); + $pluginUrl = 'plugin/'.$pluginName.'/index.php'; + if ($showTab === 'true') { + $rsTab = $this->addTab($this->get_lang($langString), $pluginUrl); + if ($rsTab) { + echo ""; + } + } else { + $settingsCurrentTable = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); + $conditions = array( + 'where' => array( + "variable = 'show_tabs' AND title = ? AND comment = ? " => array( + $this->get_lang($langString), + $pluginUrl + ) + ) + ); + $result = Database::select('subkey', $settingsCurrentTable, $conditions); + if (!empty($result)) { + $this->deleteTab($result[0]['subkey']); + } + } + } } diff --git a/plugin/buycourses/database.php b/plugin/buycourses/database.php index 10b3221b3e..f1cc054280 100644 --- a/plugin/buycourses/database.php +++ b/plugin/buycourses/database.php @@ -14,7 +14,6 @@ if (!function_exists('api_get_path')) { /** * Create the script context, then execute database queries to enable */ -$objPlugin = BuyCoursesPlugin::create(); $table = Database::get_main_table(TABLE_BUY_SESSION); $sql = "CREATE TABLE IF NOT EXISTS $table ( @@ -407,10 +406,3 @@ $sql = "CREATE TABLE IF NOT EXISTS $table ( status VARCHAR(20) NOT NULL DEFAULT '', date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)"; Database::query($sql); - -//Menu main tabs -$rsTab = $objPlugin->addTab($objPlugin->get_lang('BuyCourses'), 'plugin/buycourses/index.php'); - -if ($rsTab) { - echo ""; -} diff --git a/plugin/buycourses/lang/english.php b/plugin/buycourses/lang/english.php index 2a81b17f81..41e7787a68 100644 --- a/plugin/buycourses/lang/english.php +++ b/plugin/buycourses/lang/english.php @@ -1,6 +1,8 @@ 'boolean', 'include_sessions' => 'boolean', 'paypal_enable' => 'boolean', 'transfer_enable' => 'boolean', @@ -67,8 +68,6 @@ class BuyCoursesPlugin extends Plugin $sql = "DROP TABLE IF EXISTS $tableToBeDeleted"; Database::query($sql); } - - $objPlugin = BuyCoursesPlugin::create(); - $objPlugin->deleteTab('custom_tab_1'); + $this->manageTab(false); } }