<?php
/***************************************************************************
*
* dnInterpreter.php
* -------------------
*
* begin : Friday, Jul 5, 2002
* copyright : (C) 2002 The Kabramps Team
* email : hide@address.com,
* hide@address.com
*
*
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
* (http://www.gnu.org/licenses/gpl.html)
*
***************************************************************************/
class dnInterpreter {
var $dn;
function dnInterpreter ($dn) {
$this->dn=$dn;
}
function get_dn () {
return $this->dn;
}
function get_OrgUnits () { //deprecated method; use get_path instead
global $ldap_base;
$return = array();
$basecount = count(split(",",$ldap_base));
$all = split(",",$this->dn);
for ($i=1;$i<(count($all)-$basecount);$i++) {
$one = split("=",$all[$i]);
$return[]=trim($one[0])."=".trim(implode("=", array_slice($one,1)));
}
return $return;
}
function get_path ( $start = 0, $end = -1 ) {
$return = array();
$dnNoBase = $this->cut_LDAPBase();
if ( ( $dnNoBase != "" ) && ( $start > -1 ) ) { //split implementation is bad...
$all = split(",",$dnNoBase);
if ( $end < 0 ) {
$end = count($all);
}
for ($i=$start; $i < $end; $i++) {
$one = split("=",$all[$i]);
$return[]=trim($one[0])."=".trim(implode("=", array_slice($one,1)));
}
}
return $return;
}
function get_leaf () {
$all = split(",",$this->dn);
$one = split("=",$all[0]);
return trim($one[0])."=".trim(implode("=", array_slice($one,1)));
}
function get_type ($string) {
$one = split ("=",$string);
return trim( $one[0] );
}
function get_label ($string) {
$one = split ("=",$string);
return trim(implode("=", array_slice($one,1)));
}
function cut_LDAPBase () {
global $ldap_base;
$LongBaseDn = split(",",$this->dn);
//echo ($this->dn.":".count($LongBaseDn)."-".count(split(",",$ldap_base))."<br>");
return implode (",",array_splice($LongBaseDn,0,(count($LongBaseDn)-count(split(",",$ldap_base)))));
}
function get_javascript_encode() {
// IE window names have to be named with only special charakters
// Mozilla is much better in this point
return str_replace('=',base64_encode($this->dn),'');
}
function shift()
{
$tmp = explode( ',', $this->dn );
array_shift( $tmp );
return implode( ',', $tmp );
}
}
?>