Code

Updated objectSelection
[gosa.git] / gosa-core / include / class_baseSelector.inc
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     $this->update();
43   }
46   function setBase($base)
47   {
48     if (isset($this->pathMapping[$base])) {
49       $this->base= $base;
50     } else {
51       die("Invalid base selected");
52     }
53   }
56   function setBases($bases)
57   {
58     global $config;
60     $this->pathMapping= array();
61     $selected= $this->base == $config->current['BASE']?"Selected":"";
62     $this->tree= "<div class='treeList'><a class='treeList$selected' href='#'>"._("Root")."</a><ul class='treeList'>\n";
63     $first= true;
64     $last_indent= 2;
66     foreach ($bases as $base => $dummy) {
68       // Build path style display
69       $elements= explode(',', substr($base, 0, strlen($base) - strlen($config->current['BASE'])));
70       $elements= array_reverse($elements, true);
72       $this->pathMapping[$base]= $base == $config->current['BASE']? '/' : ldap::fix(preg_replace('/(^|,)[a-z0-9]+=/i', '/', implode(',', $elements)));
73     }
75     // Save bases to session for autocompletion
76     session::global_set('pathMapping', $this->pathMapping);
77   }
80   function update()
81   {
82     global $config;
84     $selected= $this->base == $config->current['BASE']?"Selected":"";
85     $this->tree= "<div class='treeList'><a class='treeList$selected' href='#'>"._("Root")."</a><ul class='treeList'>\n";
86     $first= true;
87     $last_indent= 2;
89     foreach ($this->pathMapping as $base => $dummy) {
91       // Skip root for tree
92       if ($base == $config->current['BASE']) {
93         continue;
94       }
96       // Build path style display
97       $elements= explode(',', substr($base, 0, strlen($base) - strlen($config->current['BASE'])));
99       $indent= count($elements);
100       if (!$first && ($indent == $last_indent)) {
101         $this->tree.= "</li>\n";
102       }
103       if ($indent > $last_indent) {
104         $this->tree.= "<ul>\n";
105       }
106       if ($indent < $last_indent) {
107         for ($i= 0; $i < ($last_indent-$indent); $i++) {
108           $this->tree.= "</li></ul>\n";
109         }
110         $this->tree.= "</li>\n";
111       }
112       $selected= $this->base == $base?" class='treeListSelected'":"";
113       $this->tree.= "<li><a$selected href='#'>".ldap::fix(preg_replace('/^[a-z0-9]+=([^,]+),.*$/i', '$1', $base))."</a>";
115       $last_indent= $indent;
116       $first= false;
117     }
119     // Close tree
120     for ($i= 0; $i<$last_indent; $i++) {
121       $this->tree.= "</li></ul>\n";
122     }
123     $this->tree.= "</div>\n";
125 echo $this->tree;
126   }
128   function render()
129   {
130     $result= "";
131     return $result;
132   }
135   function getBase()
136   {
137     return $this->base;
138   }
141   function getAction()
142   {
143     // Do not do anything if this is not our PID, or there's even no PID available...
144     #if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
145     #  return;
146     #}
147   }
151 ?>