Code

Added pulldown js
[gosa.git] / gosa-core / include / class_tabs.inc
index b6fb6b057ffa813a55f5993d3cf918a22637f026..feb50d164a248281a5baeef5b6e52b04a601c68d 100644 (file)
@@ -37,12 +37,21 @@ class tabs
   var $acl_category; 
   var $multiple_support_active = FALSE;
 
+  var $read_only = FALSE; // Used when the entry is opened as "readonly" due to locks.
+
   function tabs(&$config, $data, $dn, $acl_category= "")
   {
     /* Save dn */
     $this->dn= $dn;
     $this->config= &$config;
 
+    if(!count($data)) {
+      $data[] = array("CLASS" => 'plugin',"NAME" => 'Error');
+      msg_dialog::display(_("Error"),
+        sprintf(_("No plugin definitions found to initialize '%s', please check your configuration file."),get_class($this)),
+        "ERROR_DIALOG");
+    }
+
     $baseobject= NULL;
     $this->acl_category = $acl_category;
     foreach ($data as &$tab){
@@ -61,6 +70,7 @@ class tabs
         $this->by_object[$tab['CLASS']]= new $tab['CLASS']($this->config, $this->dn, $baseobject);
       }
 
+      $this->read_only |= $this->by_object[$tab['CLASS']]->read_only;
       $this->by_object[$tab['CLASS']]->parent= &$this;
       $this->by_object[$tab['CLASS']]->set_acl_category($this->acl_category);
 
@@ -96,6 +106,9 @@ class tabs
 
   function execute()
   {
+    /* Ensure that the currently selected tab is valid. */
+    if(!isset($this->by_name[$this->current])) $this->current = key($this->by_name);
+
     /* Rotate current to last */
     $this->last= $this->current;
 
@@ -114,11 +127,8 @@ class tabs
       $this->save_object(FALSE);
     }
 
-    /* Build tab line */
-    $display= $this->gen_tabs();
-
     /* Show object */
-    $display.= "<table summary=\"\" cellpadding=4 cellspacing=0 border=0 style=\"width:100%; background-color:#F8F8F8; border-style:solid; border-color:#AAA; border-top-width:0px; border-bottom-width:1px; border-left-width:1px; border-right-width:1px;\">\n";
+    $display = "<table summary=\"\" cellpadding=4 cellspacing=0 border=0 style=\"width:100%; background-color:#F8F8F8; border-style:solid; border-color:#AAA; border-top-width:0px; border-bottom-width:1px; border-left-width:1px; border-right-width:1px;\">\n";
     $display.= "<tr><td>\n";
 
     /* If multiple edit is enabled for this tab, 
@@ -128,9 +138,14 @@ class tabs
     }else{
       $display.= $this->by_object[$this->current]->multiple_execute();
     }
+    $modal_dialog = $this->by_object[$this->current]->is_modal_dialog();
+    
+    /* Build tab line */
+    $modal = TRUE;
+    $tabs= $this->gen_tabs($modal_dialog);
 
     /* Footer for tabbed dialog */
-    $display.= "</td></tr></table>";
+    $display = $tabs.$display."</td></tr></table>";
 
     return ($display);
   }
@@ -169,7 +184,7 @@ class tabs
     }
   }
 
-  function gen_tabs()
+  function gen_tabs($disabled = FALSE)
   {
     $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
     $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
@@ -198,7 +213,7 @@ class tabs
       }
 
       /* nobr causes w3c warnings so we use &nbsp; to keep the tab name in one line */
-      $title= preg_replace("/ /","&nbsp;",$title);
+      $title= str_replace(" ","&nbsp;",$title);
 
       /* Take care about notifications */
       $obj = $this->by_object[$class];
@@ -208,13 +223,19 @@ class tabs
         $notify= "";
       }
 
-      if (session::get('js')==FALSE){  
+      if($disabled){
+        $display.= "<div ".$notify." class=\"$style[$index]\" 
+          style=' font-family:arial,helvetica,sans-serif;
+                  font-weight:bold;
+                  font-size:13px; 
+                  color: gray;'
+          title=\"$title\">".$title."</div>";
+      }elseif (session::global_get('js')==FALSE){      
         $display.= "<div ".$notify." class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
-          " class=\"$style[$index]\" value=\"$title\"";
+          " class=\"$style[$index]\" value=\"$title\"></div></td>";
       } else {                  
-        $display.= "<div ".$notify." class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">$title</a";
+        $display.= "<div ".$notify." class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">$title</a></div></td>";
       }
-      $display.= "></div></td>";
     }
     $display.= "<td style=\"vertical-align:bottom;\">\n";
     $display.= "<div class=\"tab_border\">&nbsp;</div></td></tr></table>";
@@ -302,12 +323,17 @@ class tabs
 
       $obj->dn= $this->dn;
 
-      if ($obj->is_account || $ignore_account || $obj->ignore_account){
-        if ($obj->save() == 1){
-          return (1);
+      if(!$obj instanceof plugin){
+        trigger_error("Something went wrong while saving ".$obj->dn.". Object class '".get_class($obj)."'.");
+      }else{
+
+        if ($obj->is_account || $ignore_account || $obj->ignore_account){
+          if ($obj->save() == 1){
+            return (1);
+          }
+        } else {
+          $obj->remove_from_parent();
         }
-      } else {
-        $obj->remove_from_parent();
       }
     }
     return (0);