<?php
/***************************************************************************
*
* Path.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 Path {
var $path = array(); //array of path elements which are to show
var $rest = array(); //array of the path elements where a user is located and which are not listed
function Path( $baseDN, $formDN ) {
$bDN = new dnInterpreter ($baseDN);
$bElements = array_reverse($bDN->get_path());
$fDN = new dnInterpreter ($formDN);
$fElements = array_reverse($fDN->get_path());
// Calculate the difference the given baseDN from the formular and the basedn in which the
// user actually is located
// $end gives the last index of a common element
$end = 0;
for ( $i = 0; $i < count($fElements); $i++) {
if (count($bElements) >= $i) {
if ($fElements[$i] == $bElements[$i]) {
$end++;
} else {
$i = count($fElements);
}
} else {
$i = count($fElements);
}
}
$this->path = $bDN->get_path(0,(count($bDN->get_path())-$end));
$this->rest = $bDN->get_path(count($bDN->get_path())-$end);
}
function get_view() {
global $options;
global $ldap_base;
$tmpls = new TPLInterface();
$pathbasedn="";
$pathrest="";
if (count($this->rest) > 0) {
$pathrest = implode(",",$this->rest).",";
}
$tmpls->assign(array("PATHROOT" => $pathrest.$ldap_base ));
$assign = array();
for ( $i=count($this->path)-1; $i > -1; $i-- ) {
// cut the 'ou=' for a fancier output
$pathentry = split("=",$this->path[$i]);
$pathentry = implode("=",array_splice($pathentry,1,count($pathentry)));
$temp = $this->path; // damn poor array_splice implementation
$pathbasedn = implode (",",array_splice($temp,$i,count($this->path))).",";
$assign[] = array("PATHENTRY" => $pathentry,
"PATHBASEDN" => $pathbasedn.$pathrest.$ldap_base
);
}
$tmpls->assign('pathcol',$assign);
return $tmpls->fetch("path.tpl");
}
}
?>