1 <?php
3 class pathNavigator
4 {
6 static function registerPlugin($class, $title= "")
7 {
8 $str = "";
10 // Display headline of management plugins
11 if($class instanceOf management && isset($class->plHeadline)){
12 $str= _($class->plHeadline);
13 }
15 // Shown title of sub dialogs (They have no plHeadline set.)
16 if($class instanceOf plugin && !isset($class->plHeadline)){
17 if(!empty($class->pathTitle)){
18 $str = _($class->pathTitle);
19 }
20 }
22 // In case of tabs add the 'dn' of the entry
23 if($class instanceOf tabs){
25 // Convert dn to cn
26 if(isset($class->dn)){
27 if(!session::is_set("pathNavigator::registerPlugin:{$class->dn}")){
28 global $config;
29 $ldap = $config->get_ldap_link();
31 if(!empty($class->dn)){
32 $namingAttr = preg_replace("/^([^=]*)=.*$/","\\1",$class->dn);
34 $ldap->cat($class->dn, array($namingAttr));
35 if($ldap->count()){
36 $attrs = $ldap->fetch();
37 $str = $attrs[$namingAttr][0];
38 }
39 session::set("pathNavigator::registerPlugin:{$class->dn}", $str);
40 }
41 }
42 $str = session::get("pathNavigator::registerPlugin:{$class->dn}");
43 if(empty($title)){
44 $title = $class->dn;
45 }
46 }
47 }
49 // Simple string given
50 if(is_string($class)){
51 $str = $class;
52 }
54 if(!empty($str)){
55 $cur = session::get('pathNavigator::position');
56 $entry = array('TITLE' => $title, 'NAME' => $str);
57 $cur[] = $entry;
58 session::set('pathNavigator::position', $cur);
59 }
60 }
62 static function getCurrentPath()
63 {
64 // Ensure that we've a position value initialized.
65 if(!session::is_set('pathNavigator::position')) {
66 session::set('pathNavigator::position',array());
67 }
69 // Get position and validate its value
70 $list = session::get('pathNavigator::position');
71 if(!is_array($list)){
72 $list = array();
73 }
75 // Build up title and path string.
76 $path = "";
77 $sTitle = "";
78 foreach($list as $entry){
79 $title = (!empty($entry['TITLE']))? 'title="'.htmlentities(LDAP::fix($entry['TITLE']),ENT_COMPAT,'UTF-8').'"': '';
80 $path.= "\n<li {$title} class='left path-element'>{$entry['NAME']}</li>";
81 $sTitle .= " - ".$entry['NAME'];
82 }
84 // If no path is given then show a simple 'Welcome to GOsa' string.
85 if(empty($path)){
86 $path = "<li class='left path-element'>"._("Welcome to GOsa")."</li>";
87 }
89 $smarty = get_smarty();
90 $smarty->assign('title', 'GOsa '.$sTitle);
91 return($path);
92 }
94 static function clear()
95 {
96 session::set('pathNavigator::position', array());
97 }
98 }
100 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
101 ?>