1 <?php
3 class baseSelectDialog extends MultiSelectWindow
4 {
5 var $selectedBase = ""; // Used for navigation
6 var $base_selection_regex = "*"; // Used regex ...
7 var $BaseToUse = false; // used to specify the selected base,
8 // false if none is selected
10 var $allowedBases = array();
11 var $parent = NULL;
13 function baseSelectDialog ($config,$parent,$onlyAllowThisBases = array())
14 {
15 echo "Need to pass module via parameter!<br>";
16 $module= "all";
17 MultiSelectWindow::MultiSelectWindow($config, "BASEselectWindow", $module);
19 $this->parent = $parent;
21 $this->selectedBase = $config->current['BASE'];
22 $this->allowedBases = $onlyAllowThisBases;
24 $this->SetTitle("Base");
25 $this->SetSummary(_("Choose a base"));
26 $this->SetListHeader("<div style='background:#F0F0F9;padding:5px;'>".
27 " <input class='center' type='image' src='images/list_root.png' align='middle'
28 title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
29 " <input class='center' type='image' align='middle' src='images/list_back.png'
30 title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
31 " <input class='center' type='image' align='middle' src='images/list_home.png'
32 title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
33 " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ".
34 "</div>");
36 $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."));
38 $this->EnableAplhabet (true);
39 $this->EnableCloseButton(true);
40 $this->EnableSaveButton (true);
42 $this->SetSaveButtonString(_("Use"));
43 $this->SetCloseButtonString(_("Cancel"));
45 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
46 $this->AddHeader(array("string"=>_("Base")));
47 $this->AddHeader(array("string"=>_("Action"),"attach"=>"style='width:50px;border-right:0px;'"));
49 /* Text ,Value ,Name ,Is selected */
50 // $this->AddCheckBox("Doesnothing","servers","Doesnothing",true);
52 /* Name ,Text ,Default , Connect with alphabet */
53 $this->AddRegex ("base_selection_regex",_("Filter entries with this syntax"),"*" , true);
54 }
56 function execute()
57 {
58 $this->setEntries();
59 return($this->Draw());
60 }
62 function setEntries()
63 {
64 $this->ClearElementsList();
65 $ldap = $this->config->get_ldap_link();
66 $ldap->cd($this->selectedBase);
67 $ldap->ls("(&(objectClass=gosaDepartment)
68 (|(ou=".$this->base_selection_regex.")
69 (cn=".$this->base_selection_regex.")
70 (description=".$this->base_selection_regex.")))",
71 $this->selectedBase,array("ou","description","cn"));
73 $link = "<a href='?plug=".$_GET['plug']."&open_dep=%s'>%s</a>";
75 $base_back = preg_replace("/^[^,]+,/","",$this->selectedBase);
76 $base_back = convert_department_dn($base_back);
78 /* Add departments, to be able to switch into them
79 */
80 while($attrs = $ldap->fetch()){
82 $key = $attrs['dn'] ;
83 $val = $attrs['ou'][0];
85 if(count($this->allowedBases) != 0){
86 if(!isset($this->allowedBases[$key])){
87 continue;
88 break;
89 }
90 }
92 /* Append description */
93 if(isset($attrs['description'][0])){
94 $val.=" [".$attrs['description'][0]."]";
95 }
97 /* Add missing entries ... */
98 if(!isset($this->config->departments[trim($key)])){
99 $this->config->departments[trim($key)]="";
100 }
102 /* check if this department contains sub-departments
103 Display different image in this case
104 */
105 $non_empty="";
106 $keys= str_replace("/","\/",$key);
107 foreach($this->config->departments as $keyd ){
108 if(preg_match("/,".$keys."/",$keyd)){
109 $non_empty="full";
110 }
111 }
113 /* Add to divlist */
114 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>",
115 "attach" => "style='text-align:center;width:20px;'");
116 $field2 = array("string" => sprintf($link,base64_encode($key),$val), "attach" => "style=''");
117 $field3 = array("string" => sprintf(" <input title='"._("Select this base")."' type='image' img src='images/save.png' name='usebase_%s'>",base64_encode($key)),
118 "attach" => "style='width:50px;border-right:0px;text-align:right;'");
119 $this->AddElement(array($field1,$field2,$field3));
120 }
121 }
123 function Save()
124 {
125 MultiSelectWindow :: Save();
126 $this->BaseToUse = $this->selectedBase;
127 }
129 function isSelected()
130 {
131 return($this->BaseToUse);
132 }
134 function setCurrentBase($base)
135 {
136 $this->selectedBase = $base;
137 }
139 function save_object()
140 {
141 /* Save current base */
142 $old_base = $this->selectedBase;
144 /* Save automatic created POSTs like regex, checkboxes */
145 MultiSelectWindow::save_object();
147 if(isset($_GET['open_dep'])){
148 $this->selectedBase = base64_decode($_GET['open_dep']);
149 }
151 $s_action ="";
152 foreach($_POST as $key => $value){
153 if(preg_match("/^dep_back.*/i",$key)){
154 $s_action="back";
155 }elseif(preg_match("/^dep_root.*/",$key)){
156 $s_action="root";
157 }elseif(preg_match("/^dep_home.*/i",$key)){
158 $s_action="home";
159 }elseif(preg_match("/^usebase_/",$key)){
160 $tmp = preg_replace("/^usebase_/","",$key);
161 $tmp = preg_replace("/_.*$/","",$tmp);
162 $tmp = base64_decode($tmp);
163 $this->BaseToUse = $tmp;
164 }
165 }
167 $ui= get_userinfo();
168 /* Homebutton is posted */
169 if($s_action=="home"){
170 $this->selectedBase=(preg_replace("/^[^,]+,/","",$ui->dn));
171 $this->selectedBase=(preg_replace("/^[^,]+,/","",$this->selectedBase));
172 }
174 /* back to the roots ^^ */
175 if($s_action=="root"){
176 $this->selectedBase=($this->config->current['BASE']);
177 }
179 /* If Backbutton is Posted */
180 if($s_action=="back"){
181 $base_back = preg_replace("/^[^,]+,/","",$this->selectedBase);
182 $base_back = convert_department_dn($base_back);
184 if(isset($this->config->departments[trim($base_back)])){
185 $this->selectedBase= $this->config->departments[trim($base_back)];
186 }else{
187 $this->selectedBase= $this->config->departments["/"];
188 }
189 }
191 /* Restore old base, if selected base is not allowed */
192 if(count($this->allowedBases) && !isset($this->allowedBases[$this->selectedBase])){
193 $this->selectedBase = $old_base;
194 }
195 }
196 }
197 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
198 ?>