c2476640b0c0dfccf88e97a241075cbfb1f39f69
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
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 baseSelectDialog extends MultiSelectWindow
24 {
25 var $selectedBase = ""; // Used for navigation
26 var $base_selection_regex = "*"; // Used regex ...
27 var $BaseToUse = false; // used to specify the selected base,
28 // false if none is selected
30 var $allowedBases = array();
31 var $parent = NULL;
33 function baseSelectDialog (&$config,$parent,$onlyAllowThisBases = array())
34 {
35 $module= "all";
36 MultiSelectWindow::MultiSelectWindow($config, "BASEselectWindow", $module);
38 $this->parent = $parent;
40 $this->selectedBase = $config->current['BASE'];
41 $this->allowedBases = $onlyAllowThisBases;
43 $this->SetTitle("Base");
44 $this->SetSummary(_("Choose a base"));
45 $this->SetListHeader("<div style='background:#F0F0F9;padding:5px;'>".
46 " <input class='center' type='image' src='images/lists/root.png' align='middle'
47 title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
48 " <input class='center' type='image' align='middle' src='images/lists/back.png'
49 title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
50 " <input class='center' type='image' align='middle' src='images/lists/home.png'
51 title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
52 " <input class='center' type='image' src='images/lists/reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ".
53 "</div>");
55 $this->SetInformation(_("Step in the prefered tree and click save to use the current subtree as base. Or click the image at the end of each entry."));
57 $this->EnableAplhabet (true);
58 $this->EnableCloseButton(true);
59 $this->EnableSaveButton (true);
61 $this->SetSaveButtonString(_("Use"));
62 $this->SetCloseButtonString(_("Cancel"));
64 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
65 $this->AddHeader(array("string"=>_("Base")));
66 $this->AddHeader(array("string"=>_("Action"),"attach"=>"style='width:50px;border-right:0px;'"));
68 /* Text ,Value ,Name ,Is selected */
69 // $this->AddCheckBox("Doesnothing","servers","Doesnothing",true);
71 /* Name ,Text ,Default , Connect with alphabet */
72 $this->AddRegex ("base_selection_regex",_("Filter entries with this syntax"),"*" , true);
73 }
75 function execute()
76 {
77 $this->setEntries();
78 return($this->Draw());
79 }
81 function setEntries()
82 {
83 $this->ClearElementsList();
84 $ldap = $this->config->get_ldap_link();
85 $ldap->cd($this->selectedBase);
86 $ldap->ls("(&(objectClass=gosaDepartment)
87 (|(ou=".$this->base_selection_regex.")
88 (cn=".$this->base_selection_regex.")
89 (description=".$this->base_selection_regex.")))",
90 $this->selectedBase,array("ou","description","cn"));
92 $link = "<a href='?plug=".$_GET['plug']."&open_dep=%s'>%s</a>";
94 $base_back = preg_replace("/^[^,]+,/","",$this->selectedBase);
95 $base_back = convert_department_dn($base_back);
97 /* Add departments, to be able to switch into them
98 */
99 while($attrs = $ldap->fetch()){
101 $key = $attrs['dn'] ;
102 $val = $attrs['ou'][0];
104 if(count($this->allowedBases) != 0){
105 if(!isset($this->allowedBases[$key])){
106 continue;
107 break;
108 }
109 }
111 /* Append description */
112 if(isset($attrs['description'][0])){
113 $val.=" [".$attrs['description'][0]."]";
114 }
116 /* Add missing entries ... */
117 if(!isset($this->config->departments[trim($key)])){
118 $this->config->departments[trim($key)]="";
119 }
121 /* check if this department contains sub-departments
122 Display different image in this case
123 */
124 $non_empty="";
125 $keys= str_replace("/","\/",$key);
126 foreach($this->config->departments as $keyd ){
127 if(preg_match("/,".$keys."/",$keyd)){
128 $non_empty="full";
129 }
130 }
132 /* Add to divlist */
133 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>",
134 "attach" => "style='text-align:center;width:20px;'");
135 $field2 = array("string" => sprintf($link,base64_encode($key),$val), "attach" => "style=''");
136 $field3 = array("string" => sprintf(" <input title='"._("Select this base")."' type='image' img src='images/save.png' name='usebase_%s'>",base64_encode($key)),
137 "attach" => "style='width:50px;border-right:0px;text-align:right;'");
138 $this->AddElement(array($field1,$field2,$field3));
139 }
140 }
142 function Save()
143 {
144 MultiSelectWindow :: Save();
145 $this->BaseToUse = $this->selectedBase;
146 }
148 function isSelected()
149 {
150 return($this->BaseToUse);
151 }
153 function setCurrentBase($base)
154 {
155 $this->selectedBase = $base;
156 }
158 function save_object()
159 {
160 /* Save current base */
161 $old_base = $this->selectedBase;
163 /* Save automatic created POSTs like regex, checkboxes */
164 MultiSelectWindow::save_object();
166 if(isset($_GET['open_dep'])){
167 $this->selectedBase = base64_decode($_GET['open_dep']);
168 }
170 $s_action ="";
171 foreach($_POST as $key => $value){
172 if(preg_match("/^dep_back.*/i",$key)){
173 $s_action="back";
174 }elseif(preg_match("/^dep_root.*/",$key)){
175 $s_action="root";
176 }elseif(preg_match("/^dep_home.*/i",$key)){
177 $s_action="home";
178 }elseif(preg_match("/^usebase_/",$key)){
179 $tmp = preg_replace("/^usebase_/","",$key);
180 $tmp = preg_replace("/_.*$/","",$tmp);
181 $tmp = base64_decode($tmp);
182 $this->BaseToUse = $tmp;
183 }
184 }
186 $ui= get_userinfo();
187 /* Homebutton is posted */
188 if($s_action=="home"){
189 $this->selectedBase=(preg_replace("/^[^,]+,/","",$ui->dn));
190 $this->selectedBase=(preg_replace("/^[^,]+,/","",$this->selectedBase));
191 }
193 /* back to the roots ^^ */
194 if($s_action=="root"){
195 $this->selectedBase=($this->config->current['BASE']);
196 }
198 /* If Backbutton is Posted */
199 if($s_action=="back"){
200 $base_back = preg_replace("/^[^,]+,/","",$this->selectedBase);
201 $base_back = convert_department_dn($base_back);
203 if(isset($this->config->departments[trim($base_back)])){
204 $this->selectedBase= $this->config->departments[trim($base_back)];
205 }else{
206 $this->selectedBase= $this->config->departments["/"];
207 }
208 }
210 /* Restore old base, if selected base is not allowed */
211 if(count($this->allowedBases) && !isset($this->allowedBases[$this->selectedBase])){
212 $this->selectedBase = $old_base;
213 }
214 }
215 }
216 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
217 ?>