Check if the tab is already inserted - refs #7173

1.9.x
Francis Gonzales 11 years ago
parent be7459d7bd
commit 5b88eabe83
  1. 26
      main/inc/lib/plugin.class.php

@ -481,11 +481,10 @@ class Plugin
public function addTab($tabName, $url) public function addTab($tabName, $url)
{ {
$sql = "SELECT * FROM settings_current $sql = "SELECT * FROM settings_current
WHERE WHERE
variable = 'show_tabs' AND variable = 'show_tabs' AND
subkey like 'custom_tab_%'"; subkey like 'custom_tab_%'";
$result = Database::query($sql); $result = Database::query($sql);
$customTabsNum = Database::num_rows($result); $customTabsNum = Database::num_rows($result);
$tabNum = $customTabsNum + 1; $tabNum = $customTabsNum + 1;
@ -493,6 +492,22 @@ class Plugin
//Avoid Tab Name Spaces //Avoid Tab Name Spaces
$tabNameNoSpaces = preg_replace('/\s+/', '', $tabName); $tabNameNoSpaces = preg_replace('/\s+/', '', $tabName);
$subkeytext = "Tabs" . $tabNameNoSpaces; $subkeytext = "Tabs" . $tabNameNoSpaces;
//Check if it is already added
$checkCondition = array(
'where' =>
array(
"variable = 'show_tabs' AND subkeytext = ?" => array(
$subkeytext
)
)
);
$checkDuplicate = Database::select('*', 'settings_current', $checkCondition);
if (!empty($checkDuplicate)) {
return false;
}
//End Check
$subkey = 'custom_tab_' . $tabNum; $subkey = 'custom_tab_' . $tabNum;
$attributes = array( $attributes = array(
'variable' => 'show_tabs', 'variable' => 'show_tabs',
@ -517,7 +532,6 @@ class Plugin
$whereCondition = array( $whereCondition = array(
'id = ?' => key($settings) 'id = ?' => key($settings)
); );
Database::update('settings_current', $setData, $whereCondition); Database::update('settings_current', $setData, $whereCondition);
return $resp; return $resp;
@ -526,6 +540,8 @@ class Plugin
/** /**
* Delete a tab to chamilo's platform * Delete a tab to chamilo's platform
* @param string $key * @param string $key
*
* @return boolean $resp
*/ */
public function deleteTab($key) public function deleteTab($key)
{ {

Loading…
Cancel
Save