79b583926828602a1f69b6c99f30ba816d479c22
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->SetSaveButtonString(_("Use"));
40 $this->SetCloseButtonString(_("Cancel"));
42 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
43 $this->AddHeader(array("string"=>_("Base")));
44 $this->AddHeader(array("string"=>_("Action"),"attach"=>"style='width:50px;border-right:0px;'"));
46 /* Text ,Value ,Name ,Is selected */
47 // $this->AddCheckBox("Doesnothing","servers","Doesnothing",true);
49 /* Name ,Text ,Default , Connect with alphabet */
50 $this->AddRegex ("base_selection_regex",_("Filter entries with this syntax"),"*" , true);
51 }
53 function execute()
54 {
55 $this->setEntries();
56 return($this->Draw());
57 }
59 function setEntries()
60 {
61 $this->ClearElementsList();
62 $ldap = $this->config->get_ldap_link();
63 $ldap->cd($this->selected_base);
64 $ldap->ls("(&(objectClass=gosaDepartment)
65 (|(ou=".$this->base_selection_regex.")
66 (cn=".$this->base_selection_regex.")
67 (description=".$this->base_selection_regex.")))",
68 $this->selected_base,array("ou","description","cn"));
70 $link = "<a href='?plug=".$_GET['plug']."&open_dep=%s'>%s</a>";
72 $base_back = preg_replace("/^[^,]+,/","",$this->selected_base);
73 $base_back = convert_department_dn($base_back);
75 /* Add departments, to be able to switch into them
76 */
77 while($attrs = $ldap->fetch()){
79 $key = $attrs['dn'] ;
80 $val = $attrs['ou'][0];
82 if(count($this->allowedBases) != 0){
83 if(!isset($this->allowedBases[$key])){
84 continue;
85 break;
86 }
87 }
89 /* Append description */
90 if(isset($attrs['description'][0])){
91 $val.=" [".$attrs['description'][0]."]";
92 }
94 /* Add missing entries ... */
95 if(!isset($this->config->departments[trim($key)])){
96 $this->config->departments[trim($key)]="";
97 }
99 /* check if this department contains sub-departments
100 Display different image in this case
101 */
102 $non_empty="";
103 $keys= str_replace("/","\/",$key);
104 foreach($this->config->departments as $keyd ){
105 if(preg_match("/,".$keys."/",$keyd)){
106 $non_empty="full";
107 }
108 }
110 /* Add to divlist */
111 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>",
112 "attach" => "style='text-align:center;width:20px;'");
113 $field2 = array("string" => sprintf($link,base64_encode($key),$val), "attach" => "style=''");
114 $field3 = array("string" => sprintf(" <input type='image' img src='images/save.png' name='usebase_%s'>",base64_encode($key)),
115 "attach" => "style='width:50px;border-right:0px;text-align:right;'");
116 $this->AddElement(array($field1,$field2,$field3));
117 }
118 }
120 function Save()
121 {
122 MultiSelectWindow :: Save();
123 $this->selectedBase = $this->selected_base;
124 }
126 function isSelected()
127 {
128 return($this->selectedBase);
129 }
131 function setCurrentBase($base)
132 {
133 $this->selected_base = $base;
134 }
136 function save_object()
137 {
138 /* Save automatic created POSTs like regex, checkboxes */
139 MultiSelectWindow::save_object();
141 if(isset($_GET['open_dep'])){
142 $this->selected_base = base64_decode($_GET['open_dep']);
143 }
145 $s_action ="";
146 foreach($_POST as $key => $value){
147 if(preg_match("/^dep_back.*/i",$key)){
148 $s_action="back";
149 }elseif(preg_match("/^dep_root.*/",$key)){
150 $s_action="root";
151 }elseif(preg_match("/^dep_home.*/i",$key)){
152 $s_action="home";
153 }elseif(preg_match("/^usebase_/",$key)){
154 $tmp = preg_replace("/^usebase_/","",$key);
155 $tmp = preg_replace("/_.*$/","",$tmp);
156 $tmp = base64_decode($tmp);
157 $this->selectedBase = $tmp;
158 }
159 }
161 $ui= get_userinfo();
162 /* Homebutton is posted */
163 if($s_action=="home"){
164 $this->selected_base=(preg_replace("/^[^,]+,/","",$ui->dn));
165 $this->selected_base=(preg_replace("/^[^,]+,/","",$this->selected_base));
166 }
168 /* back to the roots ^^ */
169 if($s_action=="root"){
170 $this->selected_base=($this->config->current['BASE']);
171 }
173 /* If Backbutton is Posted */
174 if($s_action=="back"){
175 $base_back = preg_replace("/^[^,]+,/","",$this->selected_base);
176 $base_back = convert_department_dn($base_back);
178 if(isset($this->config->departments[trim($base_back)])){
179 $this->selected_base= $this->config->departments[trim($base_back)];
180 }else{
181 $this->selected_base= $this->config->departments["/"];
182 }
183 }
184 }
185 }
186 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
187 ?>