Code

Migrated to get_cfg_value
[gosa.git] / gosa-core / include / class_ldap.inc
index bfb8e955ed7a574bddd7b37316bd921418b42121..1aaa8e800c557389bb2888cd22edbfe0a93dc820 100644 (file)
@@ -60,8 +60,8 @@ class LDAP{
     $this->hostname=$hostname;
 
     /* Check if MAX_LDAP_QUERY_TIME is defined */ 
-    if(isset($config->data['MAIN']['MAX_LDAP_QUERY_TIME'])){
-      $str = $config->data['MAIN']['MAX_LDAP_QUERY_TIME'];
+    if($config->get_cfg_value("max_ldap_query_time") != ""){
+      $str = $config->get_cfg_value("max_ldap_query_time");
       $this->max_ldap_query_time = (float)($str);
     }
 
@@ -443,6 +443,55 @@ class LDAP{
     }
   }
 
+
+  /*! \brief Move the given Ldap entry from $source to $dest
+      @param  String  $source The source dn.
+      @param  String  $dest   The destination dn.
+      @return Boolean TRUE on success else FALSE.
+   */
+  function rename_dn($source,$dest)
+  {
+    $source = LDAP::fix($source);
+    $dest = LDAP::fix($dest);
+
+    /* Check if source and destination are the same entry */
+    if(strtolower($source) == strtolower($dest)){
+      trigger_error("Source and destination can't be the same entry.");
+      $this->error = "Source and destination can't be the same entry.";
+      return(FALSE);
+    }
+
+    /* Check if destination entry exists */    
+    if($this->dn_exists($dest)){
+      trigger_error("Destination '$dest' already exists.");
+      $this->error = "Destination '$dest' already exists.";
+      return(FALSE);
+    }
+
+    /* Extract the name and the parent part out ouf source dn.
+        e.g.  cn=herbert,ou=department,dc=... 
+         parent   =>  ou=department,dc=...
+         dest_rdn =>  cn=herbert
+     */
+    $parent   = preg_replace("/^[^,]+,/","",$dest);
+    $dest_rdn = preg_replace("/,.*$/","",$dest);
+  
+    if($this->hascon){
+      if ($this->reconnect) $this->connect();
+      $r= ldap_rename($this->cid,$source,$dest_rdn,$parent,TRUE); 
+      $this->error = ldap_error($this->cid);
+
+      /* Check if destination dn exists, if not the 
+          server may not support this operation */
+      $r &= is_resource($this->dn_exists($dest));
+      return($r);
+    }else{
+      $this->error = "Could not connect to LDAP server";
+      return(FALSE);
+    }
+  }
+
+
   /**
   *  Function rmdir_recursive
   *
@@ -451,7 +500,6 @@ class LDAP{
   *  GiveBack:    True on sucessfull , 0 in error, and "" when we don't get a ldap conection
   *
   */
-
   function rmdir_recursive($srp, $deletedn)
   {
     if($this->hascon){
@@ -588,7 +636,7 @@ class LDAP{
 
           /* Bail out, if we've nothing to do... */
           if ($ocname == ""){
-            msg_dialog::display(_("Internal error"), sprintf(_("Cannot automatically create subtrees with RDN '%s': no object class found"),$type), FATAL_ERROR_DIALOG);
+            msg_dialog::display(_("Internal error"), sprintf(_("Cannot automatically create subtrees with RDN '%s': no object class found!"),$type), FATAL_ERROR_DIALOG);
             exit();
           }
 
@@ -861,7 +909,7 @@ class LDAP{
       if JustMofify id false the destination dn will be overwritten by the new ldif. 
     */
 
-  function import_complete_ldif($srp, $str_attr,&$error,$JustModify,$DeleteOldEntries)
+  function import_complete_ldif($srp, $str_attr,$error,$JustModify,$DeleteOldEntries)
   {
     if($this->reconnect) $this->connect();
 
@@ -1147,7 +1195,7 @@ class LDAP{
 
     /* Only read schema if it is allowed */
     if(isset($config) && preg_match("/config/i",get_class($config))){
-      if(!isset($config->data['MAIN']['SCHEMA_CHECK']) || !preg_match("/true/i",$config->data['MAIN']['SCHEMA_CHECK'])){
+      if ($config->get_cfg_value("schema_check") != "true"){
         return($objectclasses);
       } 
     }
@@ -1159,11 +1207,7 @@ class LDAP{
     }
        
          # Get base to look for schema 
-         $sr = @ldap_read ($this->cid, NULL, "objectClass=*", array("subschemaSubentry"));
-    if(!$sr){
-           $sr = @ldap_read ($this->cid, "", "objectClass=*", array("subschemaSubentry"));
-    }
-
+         $sr = @ldap_read ($this->cid, "", "objectClass=*", array("subschemaSubentry"));
          $attr = @ldap_get_entries($this->cid,$sr);
          if (!isset($attr[0]['subschemasubentry'][0])){
            return array();
@@ -1223,6 +1267,7 @@ class LDAP{
     if(class_available("session")){
       session::set("LDAP_CACHE::get_objectclasses",$objectclasses);
     }
+
          return $objectclasses;
   }