Code

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