Code

Updated strings in dhcp error msgs
[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 $Doesnothing          = ""; // Checkbox which does nothing 
9   var $BaseToUse         = false;  // used to specify the selected base, 
10                                       // false if none is selected
12   var $allowedBases         = array();
13  
14   function baseSelectDialog ($config,$onlyAllowThisBases = array())
15   {
16     MultiSelectWindow::MultiSelectWindow($config,"BASEselectWindow");
17     
18     $this->selectedBase = $config->current['BASE'];
19   
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();
64     $link = "<a href='?plug=".$_GET['plug']."&open_dep=%s'>%s</a>";
66     $base_back          = preg_replace("/^[^,]+,/","",$this->selectedBase);
67     $base_back          = convert_department_dn($base_back);
68   
70     $filter = "(&(objectClass=gosaDepartment)".
71                 "(|(ou=".$this->base_selection_regex.")".
72                   "(cn=".$this->base_selection_regex.")".
73                   "(description=".$this->base_selection_regex.")))";
75     $ui = get_userinfo();
76     $res = get_list($filter,$ui->subtreeACL,$this->selectedBase,array("ou","description","cn"),GL_SIZELIMIT);
78     /* Add departments, to be able to switch into them
79      */
80     foreach($res as $attrs){
81  
82       $key = $attrs['dn']  ;
83       $val = $attrs['ou'][0];
84     
85       if(count($this->allowedBases) != 0){
86         if(!isset($this->allowedBases[$key])){
87           continue;
88           break;
89         }
90       }
91  
92       /* Append description */ 
93       if(isset($attrs['description'][0])){
94         $val.=" [".$attrs['description'][0]."]";
95       }
97       /* Add missing entries ... */
98       if(!isset($this->config->departments[trim($key)])){
99         $this->config->departments[trim($key)]="";
100       }
102       /* check if this department contains sub-departments
103          Display different image in this case
104        */
105       $non_empty="";
106       $keys= str_replace("/","\/",$key);
107       foreach($this->config->departments as $keyd ){
108         if(preg_match("/,".$keys."/",$keyd)){
109           $non_empty="full";
110         }
111       }
113       /* Add to divlist */
114       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", 
115                       "attach" => "style='text-align:center;width:20px;'");
116       $field2 = array("string" => sprintf($link,base64_encode($key),$val), "attach" => "style=''");
117       $field3 = array("string" => sprintf("&nbsp;<input title='"._("Select this base")."' type='image' img src='images/save.png' name='usebase_%s'>",base64_encode($key)), 
118                       "attach" => "style='width:50px;border-right:0px;text-align:right;'");
119       $this->AddElement(array($field1,$field2,$field3));
120     }
121   }
123   function Save()
124   {
125     MultiSelectWindow :: Save();  
126     $this->BaseToUse = $this->selectedBase;
127   }
129   function isSelected() 
130   {
131     return($this->BaseToUse);
132   }
134   function setCurrentBase($base)
135   {
136     $this->selectedBase = $base;
137   }
139   function save_object()
140   {
141     /* Save automatic created POSTs like regex, checkboxes */
142     MultiSelectWindow::save_object();   
143     
144     if(isset($_GET['open_dep'])){
145       $this->selectedBase = base64_decode($_GET['open_dep']);
146     } 
148     $s_action ="";
149     foreach($_POST as $key => $value){
150       if(preg_match("/^dep_back.*/i",$key)){
151         $s_action="back";
152       }elseif(preg_match("/^dep_root.*/",$key)){
153         $s_action="root";
154       }elseif(preg_match("/^dep_home.*/i",$key)){
155         $s_action="home";
156       }elseif(preg_match("/^usebase_/",$key)){
157         $tmp = preg_replace("/^usebase_/","",$key);
158         $tmp = preg_replace("/_.*$/","",$tmp);
159         $tmp = base64_decode($tmp);
160         $this->BaseToUse = $tmp;
161       }
162     }
164     $ui= get_userinfo();
165     /* Homebutton is posted */
166     if($s_action=="home"){
167       $this->selectedBase=(preg_replace("/^[^,]+,/","",$ui->dn));
168       $this->selectedBase=(preg_replace("/^[^,]+,/","",$this->selectedBase));
169     }
171     /* back to the roots ^^ */
172     if($s_action=="root"){
173       $this->selectedBase=($this->config->current['BASE']);
174     }
176     /* If Backbutton is Posted */
177     if($s_action=="back"){
178       $base_back          = preg_replace("/^[^,]+,/","",$this->selectedBase);
179       $base_back          = convert_department_dn($base_back);
181       if(isset($this->config->departments[trim($base_back)])){
182         $this->selectedBase= $this->config->departments[trim($base_back)];
183       }else{
184         $this->selectedBase= $this->config->departments["/"];
185       }
186     }
187   }
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
190 ?>