1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2010 GONICUS GmbH
5 *
6 * ID: $$Id: class_listing.inc 15296 2010-01-26 08:27:39Z cajus $$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class baseSelector {
25 private $base;
26 protected $tree;
27 protected $pathMapping;
29 // It would be better to get a dn -> [name, description, type] array
30 // to avoid these tasks be done several times. Skipping for the moment.
31 #'dc' => 'plugins/departments/images/domain.png',
32 #'dc' => 'plugins/departments/images/dc.png',
33 #'l' => 'plugins/departments/images/locality.png',
34 #'c' => 'plugins/departments/images/country.png',
35 #'o' => 'plugins/departments/images/organization.png',
36 #'ou' => 'plugins/departments/images/folder.png',
38 function __construct($bases, $base= "")
39 {
40 $this->setBases($bases);
41 $this->setBase($base);
42 }
45 function setBase($base)
46 {
47 if (isset($this->pathMapping[$base])) {
48 $this->base= $base;
49 } else {
50 die("Invalid base selected");
51 }
52 }
55 function setBases($bases)
56 {
57 global $config;
59 $this->pathMapping= array();
60 $selected= $this->base == $config->current['BASE']?"Selected":"";
61 $this->tree= "<div class='treeList'><a class='treeList$selected' href='#'>"._("Root")."</a><ul class='treeList'>\n";
62 $first= true;
63 $last_indent= 2;
65 foreach ($bases as $base => $dummy) {
67 // Build path style display
68 $elements= explode(',', substr($base, 0, strlen($base) - strlen($config->current['BASE'])));
69 $elements= array_reverse($elements, true);
71 $this->pathMapping[$base]= $base == $config->current['BASE']? '/' : ldap::fix(preg_replace('/(^|,)[a-z0-9]+=/i', '/', implode(',', $elements)));
73 // Skip root for tree
74 if ($base == $config->current['BASE']) {
75 continue;
76 }
78 $indent= count($elements);
79 if (!$first && ($indent == $last_indent)) {
80 $this->tree.= "</li>\n";
81 }
82 if ($indent > $last_indent) {
83 $this->tree.= "<ul>\n";
84 }
85 if ($indent < $last_indent) {
86 for ($i= 0; $i < ($last_indent-$indent); $i++) {
87 $this->tree.= "</li></ul>\n";
88 }
89 $this->tree.= "</li>\n";
90 }
91 $selected= $this->base == $base?" class='treeListSelected'":"";
92 $this->tree.= "<li$selected><a href='#'>".ldap::fix(preg_replace('/^[a-z0-9]+=([^,]+),.*$/i', '$1', $base))."</a>";
94 $last_indent= $indent;
95 $first= false;
96 }
98 // Close tree
99 for ($i= 0; $i<$last_indent; $i++) {
100 $this->tree.= "</li></ul>\n";
101 }
102 $this->tree.= "</div>\n";
104 echo $this->tree;
106 // Save bases to session for autocompletion
107 session::global_set('pathMapping', $this->pathMapping);
108 }
111 function render()
112 {
113 $result= "";
114 return $result;
115 }
118 function update()
119 {
120 echo "update";
121 }
124 function getBase()
125 {
126 return $this->base;
127 }
130 function getAction()
131 {
132 // Do not do anything if this is not our PID, or there's even no PID available...
133 #if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
134 # return;
135 #}
136 }
138 }
140 ?>