Code

removed debug code.
[gosa.git] / gosa-core / include / class_ldap.inc
index 1b39d79252f99116e2e8d907c9faabd1efaae0b1..489f3954e1adbd2ebe3c9d45f75087d2c53905ad 100644 (file)
@@ -91,6 +91,14 @@ class LDAP{
   }
 
 
+  /* Function to fix problematic characters in DN's that are used for search
+     requests. I.e. member=....                                               */
+  static function prepare4filter($dn)
+  {
+       return normalizeLdap(preg_replace('/\\\\/', '\\\\\\', LDAP::fix($dn)));
+  }
+
+
   function connect()
   {
     $this->hascon=false;
@@ -193,7 +201,7 @@ class LDAP{
       if($this->max_ldap_query_time){
         $diff = get_MicroTimeDiff($start,microtime());
         if($diff > $this->max_ldap_query_time){
-          print_red(sprintf(_("The LDAP server is slow (%.2fs for the last query). This may be responsible for performance breakdowns."),$diff)) ;
+          msg_dialog::display(_("Performance warning"), sprintf(_("LDAP performance is poor: last query took about %.2fs!"), $diff), WARNING_DIALOG);
         }
       }
 
@@ -225,7 +233,7 @@ class LDAP{
       if($this->max_ldap_query_time){
         $diff = get_MicroTimeDiff($start,microtime());
         if($diff > $this->max_ldap_query_time){
-          print_red(sprintf(_("The ldapserver is answering very slow (%.2f), this may be responsible for performance breakdowns."),$diff)) ;
+          msg_dialog::display(_("Performance warning"), sprintf(_("LDAP performance is poor: last query took about %.2fs!"), $diff), WARNING_DIALOG);
         }
       }
 
@@ -444,175 +452,6 @@ class LDAP{
     }
   }
 
-  /* Copy given attributes and sub-dns with attributes to destination dn 
-  */
-  function copy_FAI_resource_recursive($sourcedn,$destinationdn,$destinationName,$type="branch",$is_first = true,$depth=0)
-  {
-    error_reporting(E_ALL | E_STRICT);
-    
-    if($is_first){
-      echo "<h2>".sprintf(_("Creating copy of %s"),"<i>".LDAP::fix($sourcedn)."</i>")."</h2>";
-    }else{
-      if(preg_match("/^ou=/",$sourcedn)){
-        echo "<h3>"._("Processing")." <i>".LDAP::fix($destinationdn)."</i></h3>";
-      }else{
-        $tmp = split(",",$sourcedn);
-        
-        echo "&nbsp;<b>"._("Object").":</b> ";
-
-        $deststr = LDAP::fix($destinationdn);
-        if(strlen($deststr) > 96){
-          $deststr = substr($deststr,0,96)."...";
-        }
-
-        echo $deststr."<br>";
-      }
-    }
-
-    flush();
-    
-    if($this->hascon){
-      if ($this->reconnect) $this->connect();
-
-      /* Save base dn */
-      $basedn= $this->basedn;
-      $delarray= array();
-     
-      /* Check if destination entry already exists */
-      $this->cat($destinationdn);
-
-      if($this->count()){
-        return;
-      }else{
-        
-        $this->clearResult();
-
-        /* Get source entry */
-        $this->cd($basedn);
-        $this->cat($sourcedn);
-        $attr = $this->fetch();
-
-        /* Error while fetching object / attribute abort*/
-        if((!$attr) || (count($attr)) ==0) {
-          echo _("Error while fetching source dn - aborted!");
-          return;
-        }
-  
-        /* check if this is a department */
-        if(in_array("organizationalUnit",$attr['objectClass'])){
-          $attr['dn'] = LDAP::convert($destinationdn);
-          $this->cd($basedn);
-          $this->create_missing_trees($destinationdn);
-          $this->cd($destinationdn);
-
-          /* If is first entry, append FAIbranch to department entry */
-          if($is_first){
-            $this->cat($destinationdn);
-            $attr= $this->fetch();
-
-            /* Filter unneeded informations */
-            foreach($attr as $key => $value){
-              if(is_numeric($key)) unset($attr[$key]);
-              if(isset($attr[$key]['count'])){
-                if(is_array($attr[$key])){
-                  unset($attr[$key]['count']);
-                }
-              }
-            }
-            
-            unset($attr['count']);
-            unset($attr['dn']);
-
-            /* Add marking attribute */
-            $attr['objectClass'][] = "FAIbranch";
-            
-            /* Add this entry */
-            $this->modify($attr);
-          }
-        }else{
-
-          /* If this is no department */
-          foreach($attr as $key => $value){
-            if(in_array($key ,array("FAItemplateFile","FAIscript", "gotoLogonScript", "gosaApplicationIcon","gotoMimeIcon"))){
-              $sr= ldap_read($this->cid, LDAP::fix($sourcedn), "$key=*", array($key));
-              $ei= ldap_first_entry($this->cid, $sr);
-              if ($tmp= @ldap_get_values_len($this->cid, $ei,$key)){
-                $attr[$key] = $tmp;
-              }
-            }
-
-            if(is_numeric($key)) unset($attr[$key]);
-            if(isset($attr[$key]['count'])){
-              if(is_array($attr[$key])){
-                unset($attr[$key]['count']);
-              }
-            }
-          }
-          unset($attr['count']);
-          unset($attr['dn']);
-
-          if((!in_array("gosaApplication" , $attr['objectClass'])) && (!in_array("gotoMimeType", $attr['objectClass']))){
-            $attr['FAIdebianRelease'] = $destinationName;
-            if($type=="branch"){
-              $attr['FAIstate'] ="branch";
-            }elseif($type=="freeze"){
-              $attr['FAIstate'] ="freeze";
-            }else{
-              print_red(_("Unknown FAIstate %s"),$type);
-            }
-          }
-
-          /* Replace FAIdebianRelease with new release name */
-          if(in_array("FAIpackageList" , $attr['objectClass'])){
-            $attr['FAIdebianRelease'] = $destinationName; 
-          }
-
-          /* Add entry */
-          $this->cd($destinationdn);
-          $this->cat($destinationdn);
-          $a = $this->fetch();
-          if(!count($a)){
-            $this->add($attr);
-          }
-
-          if($this->error != "Success"){
-            /* Some error occurred */
-            print "---------------------------------------------";
-            print $this->get_error()."<br>";
-            print $sourcedn."<br>";
-            print $destinationdn."<br>";
-            print_a( $attr);
-            exit();
-          }          
-        }
-      }
-
-      echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
-
-      $this->ls ("(objectClass=*)",$sourcedn);
-      while ($this->fetch()){
-        $deldn= $this->getDN();
-        $delarray[$deldn]= strlen($deldn);
-      }
-      asort ($delarray);
-      reset ($delarray);
-
-       $depth ++;
-      foreach($delarray as $dn => $bla){
-        if($dn != $destinationdn){
-          $this->cd($basedn);
-          $item = $this->fetch($this->cat($dn));
-          if(!in_array("FAIbranch",$item['objectClass'])){
-            $this->copy_FAI_resource_recursive($dn,str_replace($sourcedn,$destinationdn,$dn),$destinationName,$type,false,$depth);
-          } 
-        }
-      }
-    }
-    if($is_first){
-      echo "<p class='seperator'>&nbsp;</p>";
-    }
-
-  }
 
   function modify($attrs)
   {
@@ -719,7 +558,7 @@ class LDAP{
 
           /* Bail out, if we've nothing to do... */
           if ($ocname == ""){
-            print_red(sprintf(_("Autocreation of subtree failed. No objectClass found for attribute '%s'."), $type));
+            msg_dialog::display(_("Internal error"), sprintf(_("Cannot automatically create subtrees with RDN '%s': no object class found"),$type), ERROR_DIALOG);
             display_error_page();
           }
 
@@ -767,7 +606,7 @@ class LDAP{
               $na["dc"]= $param;
               break;
             default:
-              print_red(sprintf(_("Autocreation of type '%s' is currently not supported. Please report to the GOsa team."), $type));
+              msg_dialog::display(_("Internal error"), sprintf(_("Cannot automatically create subtrees with RDN '%s': not supported"),$type), ERROR_DIALOG);
               display_error_page();
           }
 
@@ -1362,9 +1201,9 @@ class LDAP{
 
   function log($string)
   {
-    if (isset($_SESSION['config'])){
-      $cfg= $_SESSION['config'];
-      if (1 || isset($cfg->current['LDAPSTATS']) && preg_match('/true/i', $cfg->current['LDAPSTATS'])){
+    if (session::is_set('config')){
+      $cfg = session::get('config');
+      if (isset($cfg->current['LDAPSTATS']) && preg_match('/true/i', $cfg->current['LDAPSTATS'])){
         syslog (LOG_INFO, $string);
       }
     }
@@ -1430,9 +1269,6 @@ class LDAP{
 
     return ($result);
   }
-
-
 }
-
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>