binddn=$binddn;
    $this->bindpw=$bindpw;
    if ($basedn=="")
    $this->basedn=LDAP_BASEDN;
    else
    $this->basedn=str_replace(";",",",$basedn).", ".LDAP_BASEDN;
   
//print "BASS ".$this->basedn."
"; if ($bind=="auth") { //print "BIND ".$this->binddn." / ".$this->bindpw; $this->connect($this->binddn, $this->bindpw, $this->hostname,$bind); } else $this->connect("","", $this->hostname,$bind); return($this->bid); } //***************************************************************************// // Connect to database //***************************************************************************// function connect($binddn, $bindpw, $hostname,$bind) { $e = error_reporting(0); if ($this->cid) { error_reporting($e); return($this->cid); } if (! $this->cid = ldap_connect($hostname)) { $this->error = "Could not connect to LDAP server"; error_reporting($e); return($this->cid); } if (!ldap_set_option($this->cid, LDAP_OPT_PROTOCOL_VERSION, 3)) echo "Could not set protocol to version 3"; if ($bind=="auth") { if ($binddn=="") { $this->error = "Authentication error"; $this->bid=FALSE; return($this->bid); } else if ($this->bid = ldap_bind($this->cid, $binddn, $bindpw)) { $this->error = "Success"; error_reporting($e); return($this->bid); } } else { if ($this->bid = ldap_bind($this->cid)) { $this->error = "Success"; error_reporting($e); return($this->bid); } } // if ($this->bid) // print "AHSHx |".$this->bid."|"; // else // print "AHSHy |".$this->bid."|"; $this->error = "Could not bind to " . $binddn; error_reporting($e); return($this->bid); } //***************************************************************************// // add entry in database //***************************************************************************// function add($data,$masteridx) { $basedn = $this->basedn; $e = error_reporting(0); $cn = $masteridx."=" . $data[$masteridx] . ", ".$basedn; //print "CN: ".$basedn."
"; //print_r($data); $r = ldap_add($this->cid, $cn , $data); $this->error = ldap_error($this->cid); error_reporting($e); return($r ? $r : 0); } //***************************************************************************// // add entry in database //***************************************************************************// function addDirect($data,$cn) { $e = error_reporting(0); $r = ldap_add($this->cid, $cn , $data); $this->error = ldap_error($this->cid); error_reporting($e); return($r ? $r : 0); } //***************************************************************************// // modify entry in database //***************************************************************************// function modify($data1,$masteridx) { $basedn = $this->basedn; $lmod=""; $lclrattr=""; $cn = $masteridx."=" . $data1[$masteridx] . ",".$basedn; // print "MN= ".$cn; $data=array(); foreach ($data1 as $key => $val) { if (($key!=$masteridx) && ($key!="objectClass")) $data[$key]=$val; } // print_r($data); foreach ($data as $key => $val) { if ($val=="") //unschoen { $lclrattr[$key]=array(); ldap_mod_del($this->cid, $cn ,$lclrattr); $lclrattr=""; } else $lmod[$key]=$val; } $e = error_reporting(0); $r = ldap_modify($this->cid, $cn , $lmod); $this->error = ldap_error($this->cid); // if (($r) && ($lclrattr!="")) // { // ldap_mod_del($this->cid, $cn ,$lclrattr); // $this->error = ldap_error($this->cid); // } error_reporting($e); return($r ? $r : 0); } //***************************************************************************// // Delete directory in database //***************************************************************************// function delete($deletedn) { $e = error_reporting(0); $r = ldap_delete($this->cid, $deletedn); $this->error = ldap_error($this->cid); error_reporting($e); return($r ? $r : 0); } //***************************************************************************// // Sort in database //***************************************************************************// function Sort($filter) { $e = error_reporting(0); $result = array(); // if (!$this->connect()) // { // error_reporting($e); // return(0); // } ldap_sort($this->cid,$this->sr,$filter); } //***************************************************************************// // Search in database //***************************************************************************// function Search($filter) { $e = error_reporting(0); $result = array(); //print "SUCHHASSO :".$filter."
"; //print "SUCHHASSO1 :".$this->basedn."
"; // if (!$this->connect()) // { // error_reporting($e); // return(0); // } $this->sr = ldap_search($this->cid, $this->basedn, $filter); $this->start=0; $this->re=0; $ldap->error = ldap_error($this->cid); //print "SUCHHASSO :".$ldap->error." - ".$tst."
"; return($this->sr); } //***************************************************************************// // rename datebase entry //***************************************************************************// function rename($olddn,$nrdn,$nparent) { $e = error_reporting(0); error_reporting(E_ALL); //print "RENAME |".$olddn."|".$nrdn."|".$nparent."|"; $erg = ldap_rename($this->cid,$olddn,$nrdn,$nparent,TRUE); $ldap->error = ldap_error($this->cid); print "

Status: ".$ldap->error."

\n"; return($erg); } //***************************************************************************// // fetch entries in database //***************************************************************************// function fetch() { $e = error_reporting(0); if ($this->start == 0) { $this->start = 1; $this->re = ldap_first_entry($this->cid, $this->sr); $this->dn=ldap_get_dn( $this->cid,$this->re); } else { $this->re = ldap_next_entry($this->cid, $this->re); $this->dn=ldap_get_dn( $this->cid,$this->re); } if ($this->re) { $att = ldap_get_attributes($this->cid, $this->re); } $ldap->error = ldap_error($this->cid); error_reporting($e); return($att); } //***************************************************************************// // get attributes //***************************************************************************// function getattr() { //$e = error_reporting(0); $attr = ldap_get_attributes($this->cid,$this->re); $ldap->error = ldap_error($this->cid); //error_reporting($e); return($attr); } //***************************************************************************// // Count entries in database //***************************************************************************// function count() { $e = error_reporting(0); $rv = ldap_count_entries($this->cid, $this->sr); $ldap->error = ldap_error($this->cid); error_reporting($e); return($rv); } //***************************************************************************// // Disconnect from database //***************************************************************************// function disconnect() { ldap_close($this->cid); } } } ?>