Code

Fixed Translation Strings.
[gosa.git] / plugins / admin / systems / class_goLdapServer.inc
index f5a28488279f392a2ba41abfb1267ebc6ca3c4d4..64d385f8a6ed2ab186a0afe63530a99f0b790a1e 100644 (file)
@@ -1,26 +1,26 @@
 <?php
 
 class goLdapServer extends plugin{
-       
+
   var $cli_summary      = "This plugin is used within the ServerService Pluign \nand indicates that this server has goLdapServer defined.";
   var $cli_description  = "Some longer text\nfor help";
   var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
 
   /* This plugin only writes its objectClass */
   var $objectclasses    = array("goLdapServer");
-  var $attributes       = array("goLdapServerStatus","goLdapBase");
+  var $attributes       = array("goLdapBase");
   var $StatusFlag       = "goLdapServerStatus";
+
   /* This class can't be assigned twice so it conflicts with itsself */
   var $conflicts        = array("goLdapServer");
 
   var $DisplayName      = "";
   var $dn               = NULL;
   var $acl;
-
+  var $cn                  = "";
   var $goLdapServerStatus  = "";
   var $goLdapBase          = ""; 
+
   function goLdapServer($config,$dn)
   {
     plugin::plugin($config,$dn);
@@ -41,6 +41,7 @@ class goLdapServer extends plugin{
 
   function getListEntry()
   {
+    $this->updateStatusState();
     $flag = $this->StatusFlag;
     $fields['Status']     = $this->$flag;
     $fields['Message']    = _("LDAP Service");
@@ -67,6 +68,7 @@ class goLdapServer extends plugin{
       $ldap->add($this->attrs);
     }
     show_ldap_error($ldap->get_error());
+    $this->handle_post_events("remove");
   }
 
 
@@ -84,6 +86,12 @@ class goLdapServer extends plugin{
       $ldap->add($this->attrs);
     }
     show_ldap_error($ldap->get_error());
+    if($this->initially_was_account){
+      $this->handle_post_events("modify");
+    }else{
+      $this->handle_post_events("add");
+    }
+
   }
 
 
@@ -91,54 +99,101 @@ class goLdapServer extends plugin{
   function setStatus($value)
   {
     if($value == "none") return;
+    if(!$this->initially_was_account) return;
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($this->dn);
-    $ldap->cat($this->dn,array("objectClass","goLdapBase"));
-      
+    $ldap->cat($this->dn,array("objectClass"));
     if($ldap->count()){
-      $attrs =array();
-      foreach(array("goLdapBase") as $req) {
-        if(!isset($attrs[$req])){
-          if(empty($this->$req)){
-            print_red(sprintf(_("The required attribute '%s' is not set."),$req));
-          }else{
-            $attrs[$req] = $this->$req;
-          }
-        }else{
-          $attrs[$req] = $attrs[$req][0];
-        }
-      }
 
       $tmp = $ldap->fetch();
       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
         $attrs['objectClass'][] = $tmp['objectClass'][$i];
-      }    
-      if(!in_array("goLdapServer",$attrs['objectClass'])){
-        $attrs['objectClass'][] = "goLdapServer";
       }
-
       $flag = $this->StatusFlag;
       $attrs[$flag] = $value;
       $this->$flag = $value;
       $ldap->modify($attrs);
       show_ldap_error($ldap->get_error());
-    }    
+      $this->action_hook();
+    }
   }
 
-  
+
   function check()
   { 
     $message = plugin::check();
+    if(empty($this->goLdapBase)){
+      $message[] = _("The given base is empty or contains invalid characters.");
+    }
     return($message);
   }
-  
+
 
   function save_object()
   {
     if(isset($_POST['goLdapServerPosted'])){
       plugin::save_object();
     }
-  }  
+  } 
+
+  function action_hook($add_attrs= array())
+  {
+    /* Find postcreate entries for this class */
+    $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
+    if ($command == "" && isset($this->config->data['TABS'])){
+      $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
+    }
+    if ($command != ""){
+      /* Walk through attribute list */
+      foreach ($this->attributes as $attr){
+        if (!is_array($this->$attr)){
+          $command= preg_replace("/%$attr/", $this->$attr, $command);
+        }
+      }
+      $command= preg_replace("/%dn/", $this->dn, $command);
+      /* Additional attributes */
+      foreach ($add_attrs as $name => $value){
+        $command= preg_replace("/%$name/", $value, $command);
+      }
+
+      /* If there are still some %.. in our command, try to fill these with some other class vars */
+      if(preg_match("/%/",$command)){
+        $attrs = get_object_vars($this);
+        foreach($attrs as $name => $value){
+          if(!is_string($value)) continue;
+          $command= preg_replace("/%$name/", $value, $command);
+        }
+      }
+
+      if (check_command($command)){
+        @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
+            $command, "Execute");
+
+        exec($command);
+      } else {
+        $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
+        print_red ($message);
+      }
+    }
+  }
+
+  /* Get updates for status flag */
+  function updateStatusState()
+  {
+    if(empty($this->StatusFlag)) return;
+
+    $attrs = array();
+    $flag = $this->StatusFlag;
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->cn);
+    $ldap->cat($this->dn,array($flag));
+    if($ldap->count()){
+      $attrs = $ldap->fetch();
+    }
+    if(isset($attrs[$flag][0])){
+      $this->$flag = $attrs[$flag][0];
+    }
+  }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>