a0d9f340aebc6fa00279ade6cf49d342dfdc8a32
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
11 function baseSelectDialog ($config)
12 {
13 MultiSelectWindow::MultiSelectWindow($config);
15 $this->selected_base = $config->current['BASE'];
17 $this->SetTitle("Base");
18 $this->SetSummary(_("Please choose your prefered base"));
19 $this->SetListHeader("<div style='background:#F0F0F9;padding:5px;'>".
20 " <input class='center' type='image' align='middle' src='images/list_back.png'
21 title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
22 " <input class='center' type='image' src='images/list_root.png' align='middle'
23 title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
24 " <input class='center' type='image' align='middle' src='images/list_home.png'
25 title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
26 "</div>");
28 $this->SetInformation(_("Step in the prefered tree and click save to use the subtree as base for the currently edited user. Or click the image on the end of each entry."));
30 $this->EnableAplhabet (true);
31 $this->EnableCloseButton(true);
32 $this->EnableSaveButton (true);
34 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
35 $this->AddHeader(array("string"=>"Base"));
36 $this->AddHeader(array("string"=>"Option","attach"=>"style='width:50px;border-right:0px;'"));
38 /* Text ,Value ,Name ,Is selected */
39 // $this->AddCheckBox("Doesnothing","servers","Doesnothing",true);
41 /* Name ,Text ,Default , Connect with alphabet */
42 $this->AddRegex ("base_selection_regex",_("Filter entries with this syntax"),"*" , true);
43 }
45 function execute()
46 {
47 $this->setEntries();
48 return($this->Draw());
49 }
51 function setEntries()
52 {
53 $this->ClearElementsList();
54 $ldap = $this->config->get_ldap_link();
55 $ldap->cd($this->selected_base);
56 $ldap->ls("(&(objectClass=gosaDepartment)
57 (|(ou=".$this->base_selection_regex.")
58 (cn=".$this->base_selection_regex.")
59 (description=".$this->base_selection_regex.")))",
60 $this->selected_base,array("ou","description","cn"));
62 $link = "<a href='?plug=".$_GET['plug']."&open_dep=%s'>%s</a>";
64 $base_back = preg_replace("/^[^,]+,/","",$this->selected_base);
65 $base_back = convert_department_dn($base_back);
67 /* Add departments, to be able to switch into them
68 */
69 while($attrs = $ldap->fetch()){
71 $key = $attrs['dn'] ;
72 $val = $attrs['ou'][0];
74 /* Append description */
75 if(isset($attrs['description'][0])){
76 $val.=" [".$attrs['description'][0]."]";
77 }
79 /* Add missing entries ... */
80 if(!isset($this->config->departments[trim($key)])){
81 $this->config->departments[trim($key)]="";
82 }
84 /* check if this department contains sub-departments
85 Display different image in this case
86 */
87 $non_empty="";
88 $keys= str_replace("/","\/",$key);
89 foreach($this->config->departments as $keyd ){
90 if(preg_match("/,".$keys."/",$keyd)){
91 $non_empty="full";
92 }
93 }
95 /* Add to divlist */
96 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>",
97 "attach" => "style='text-align:center;width:20px;'");
98 $field2 = array("string" => sprintf($link,base64_encode($key),$val), "attach" => "style=''");
99 $field3 = array("string" => sprintf(" <input type='image' img src='images/save.png' name='usebase_%s'>",base64_encode($key)),
100 "attach" => "style='width:50px;border-right:0px;text-align:right;'");
101 $this->AddElement(array($field1,$field2,$field3));
102 }
103 }
105 function Save()
106 {
107 MultiSelectWindow :: Save();
108 $this->selectedBase = $this->selected_base;
109 }
111 function isSelected()
112 {
113 return($this->selectedBase);
114 }
116 function setCurrentBase($base)
117 {
118 $this->selected_base = $base;
119 }
121 function save_object()
122 {
123 /* Save automatic created POSTs like regex, checkboxes */
124 MultiSelectWindow::save_object();
126 if(isset($_GET['open_dep'])){
127 $this->selected_base = base64_decode($_GET['open_dep']);
128 }
130 $s_action ="";
131 foreach($_POST as $key => $value){
132 if(preg_match("/^dep_back.*/i",$key)){
133 $s_action="back";
134 }elseif(preg_match("/^dep_root.*/",$key)){
135 $s_action="root";
136 }elseif(preg_match("/^dep_home.*/i",$key)){
137 $s_action="home";
138 }elseif(preg_match("/^usebase_/",$key)){
139 $tmp = preg_replace("/^usebase_/","",$key);
140 $tmp = preg_replace("/_.*$/","",$tmp);
141 $tmp = base64_decode($tmp);
142 $this->selectedBase = $tmp;
143 }
144 }
146 $ui= get_userinfo();
147 /* Homebutton is posted */
148 if($s_action=="home"){
149 $this->selected_base=(preg_replace("/^[^,]+,/","",$ui->dn));
150 $this->selected_base=(preg_replace("/^[^,]+,/","",$this->selected_base));
151 }
153 /* back to the roots ^^ */
154 if($s_action=="root"){
155 $this->selected_base=($this->config->current['BASE']);
156 }
158 /* If Backbutton is Posted */
159 if($s_action=="back"){
160 $base_back = preg_replace("/^[^,]+,/","",$this->selected_base);
161 $base_back = convert_department_dn($base_back);
163 if(isset($this->config->departments[trim($base_back)])){
164 $this->selected_base= $this->config->departments[trim($base_back)];
165 }else{
166 $this->selected_base= $this->config->departments["/"];
167 }
168 }
169 }
170 }
171 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
172 ?>