1 <?php
3 class baseSelectDialog extends MultiSelectWindow
4 {
5 var $selected_base = ""; // Used for navigation
6 var $base_selection_regex = "*"; // Used regex ...
7 // var $Doesnothing = ""; // Checkbox which does nothing
9 var $selectedBase = false; // used to specify the selected base,
10 // false if none is selected
12 var $allowedBases = array();
14 function baseSelectDialog ($config,$onlyAllowThisBases = array())
15 {
16 MultiSelectWindow::MultiSelectWindow($config);
18 $this->selected_base = $config->current['BASE'];
20 $this->allowedBases = $onlyAllowThisBases;
22 $this->SetTitle("Base");
23 $this->SetSummary(_("Choose a base"));
24 $this->SetListHeader("<div style='background:#F0F0F9;padding:5px;'>".
25 " <input class='center' type='image' align='middle' src='images/list_back.png'
26 title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
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_home.png'
30 title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
31 "</div>");
33 $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."));
35 $this->EnableAplhabet (true);
36 $this->EnableCloseButton(true);
37 $this->EnableSaveButton (true);
39 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
40 $this->AddHeader(array("string"=>"Base"));
41 $this->AddHeader(array("string"=>"Option","attach"=>"style='width:50px;border-right:0px;'"));
43 /* Text ,Value ,Name ,Is selected */
44 // $this->AddCheckBox("Doesnothing","servers","Doesnothing",true);
46 /* Name ,Text ,Default , Connect with alphabet */
47 $this->AddRegex ("base_selection_regex",_("Filter entries with this syntax"),"*" , true);
48 }
50 function execute()
51 {
52 $this->setEntries();
53 return($this->Draw());
54 }
56 function setEntries()
57 {
58 $this->ClearElementsList();
59 $ldap = $this->config->get_ldap_link();
60 $ldap->cd($this->selected_base);
61 $ldap->ls("(&(objectClass=gosaDepartment)
62 (|(ou=".$this->base_selection_regex.")
63 (cn=".$this->base_selection_regex.")
64 (description=".$this->base_selection_regex.")))",
65 $this->selected_base,array("ou","description","cn"));
67 $link = "<a href='?plug=".$_GET['plug']."&open_dep=%s'>%s</a>";
69 $base_back = preg_replace("/^[^,]+,/","",$this->selected_base);
70 $base_back = convert_department_dn($base_back);
72 /* Add departments, to be able to switch into them
73 */
74 while($attrs = $ldap->fetch()){
76 $key = $attrs['dn'] ;
77 $val = $attrs['ou'][0];
79 if(count($this->allowedBases) != 0){
80 if(!isset($this->allowedBases[$key])){
81 continue;
82 break;
83 }
84 }
86 /* Append description */
87 if(isset($attrs['description'][0])){
88 $val.=" [".$attrs['description'][0]."]";
89 }
91 /* Add missing entries ... */
92 if(!isset($this->config->departments[trim($key)])){
93 $this->config->departments[trim($key)]="";
94 }
96 /* check if this department contains sub-departments
97 Display different image in this case
98 */
99 $non_empty="";
100 $keys= str_replace("/","\/",$key);
101 foreach($this->config->departments as $keyd ){
102 if(preg_match("/,".$keys."/",$keyd)){
103 $non_empty="full";
104 }
105 }
107 /* Add to divlist */
108 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>",
109 "attach" => "style='text-align:center;width:20px;'");
110 $field2 = array("string" => sprintf($link,base64_encode($key),$val), "attach" => "style=''");
111 $field3 = array("string" => sprintf(" <input type='image' img src='images/save.png' name='usebase_%s'>",base64_encode($key)),
112 "attach" => "style='width:50px;border-right:0px;text-align:right;'");
113 $this->AddElement(array($field1,$field2,$field3));
114 }
115 }
117 function Save()
118 {
119 MultiSelectWindow :: Save();
120 $this->selectedBase = $this->selected_base;
121 }
123 function isSelected()
124 {
125 return($this->selectedBase);
126 }
128 function setCurrentBase($base)
129 {
130 $this->selected_base = $base;
131 }
133 function save_object()
134 {
135 /* Save automatic created POSTs like regex, checkboxes */
136 MultiSelectWindow::save_object();
138 if(isset($_GET['open_dep'])){
139 $this->selected_base = base64_decode($_GET['open_dep']);
140 }
142 $s_action ="";
143 foreach($_POST as $key => $value){
144 if(preg_match("/^dep_back.*/i",$key)){
145 $s_action="back";
146 }elseif(preg_match("/^dep_root.*/",$key)){
147 $s_action="root";
148 }elseif(preg_match("/^dep_home.*/i",$key)){
149 $s_action="home";
150 }elseif(preg_match("/^usebase_/",$key)){
151 $tmp = preg_replace("/^usebase_/","",$key);
152 $tmp = preg_replace("/_.*$/","",$tmp);
153 $tmp = base64_decode($tmp);
154 $this->selectedBase = $tmp;
155 }
156 }
158 $ui= get_userinfo();
159 /* Homebutton is posted */
160 if($s_action=="home"){
161 $this->selected_base=(preg_replace("/^[^,]+,/","",$ui->dn));
162 $this->selected_base=(preg_replace("/^[^,]+,/","",$this->selected_base));
163 }
165 /* back to the roots ^^ */
166 if($s_action=="root"){
167 $this->selected_base=($this->config->current['BASE']);
168 }
170 /* If Backbutton is Posted */
171 if($s_action=="back"){
172 $base_back = preg_replace("/^[^,]+,/","",$this->selected_base);
173 $base_back = convert_department_dn($base_back);
175 if(isset($this->config->departments[trim($base_back)])){
176 $this->selected_base= $this->config->departments[trim($base_back)];
177 }else{
178 $this->selected_base= $this->config->departments["/"];
179 }
180 }
181 }
182 }
183 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
184 ?>