Code

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