Code

Updated class ldap
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 5 Nov 2009 07:01:07 +0000 (07:01 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 5 Nov 2009 07:01:07 +0000 (07:01 +0000)
-Displays attribute list in case of an error, id display_errors is true.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14748 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/class_ldap.inc

index 9b968fd9d91b79598919fbaa6c8e2a2114be5446..bf5385e011fbc79fe6e6ece3ef59c7df5bd36303 100644 (file)
@@ -557,6 +557,29 @@ class LDAP{
     }
   }
 
+  function makeReadableErrors($error,$attrs)
+  { 
+    global $config;
+
+    if($this->success()) return("");
+
+    $str = "";
+    if(preg_match("/^objectClass: value #([0-9]*) invalid per syntax$/", $this->get_additional_error())){
+      $oc = preg_replace("/^objectClass: value #([0-9]*) invalid per syntax$/","\\1", $this->get_additional_error());
+      if(isset($attrs['objectClass'][$oc])){
+        $str.= " - <b>objectClass: ".$attrs['objectClass'][$oc]."</b>";
+      }
+    }
+    if($error == "Undefined attribute type"){
+      $str = " - <b>attribute: ".preg_replace("/:.*$/","",$this->get_additional_error())."</b>";
+    } 
+
+    if(is_object($config) && $config->get_cfg_value("displayerrors") == "true" && function_exists("print_a")){
+      $str .= print_a($attrs,true);
+    }
+    
+    return($str);
+  }
 
   function modify($attrs)
   {
@@ -564,14 +587,13 @@ class LDAP{
       return (0);
     }
     if($this->hascon){
+
+      $attrs['objectClass'][0] = "Herb ert";
       if ($this->reconnect) $this->connect();
       $r = @ldap_modify($this->cid, LDAP::fix($this->basedn), $attrs);
       $this->error = @ldap_error($this->cid);
-      if(!$this->success() && preg_match("/^objectClass: value #([0-9]*) invalid per syntax$/", $this->get_additional_error())){
-        $oc = preg_replace("/^objectClass: value #([0-9]*) invalid per syntax$/","\\1", $this->get_additional_error());
-        if(isset($attrs['objectClass'][$oc])){
-          $this->error.= " <b>objectClass: ".$attrs['objectClass'][$oc]."</b>"; 
-        }
+      if(!$this->success()){
+        $this->error.= $this->makeReadableErrors($this->error,$attrs);
       }
       return($r ? $r : 0);
     }else{
@@ -586,11 +608,8 @@ class LDAP{
       if ($this->reconnect) $this->connect();
       $r = @ldap_add($this->cid, LDAP::fix($this->basedn), $attrs);
       $this->error = @ldap_error($this->cid);
-      if(!$this->success() && preg_match("/^objectClass: value #([0-9]*) invalid per syntax$/", $this->get_additional_error())){
-        $oc = preg_replace("/^objectClass: value #([0-9]*) invalid per syntax$/","\\1", $this->get_additional_error());
-        if(isset($attrs['objectClass'][$oc])){
-          $this->error.= " <b>objectClass: ".$attrs['objectClass'][$oc]."</b>"; 
-        }
+      if(!$this->success()){
+        $this->error.= $this->makeReadableErrors($this->error,$attrs);
       }
       return($r ? $r : 0);
     }else{