Code

Added branches container for old stuff
[gosa.git] / gosa-plugins / sudo / admin / sudo / class_target_list_systems.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id: class_target_list.inc 9850 2008-03-14 14:15:12Z hickert $$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class target_list_systems extends MultiSelectWindow
24 {
25   public $config;
26   protected $list         =array();
27   private $Targets_used =array();
29   /* Regex */
30   protected $Regex           = "*";
32   /* CheckBoxes, to change default values modify $this->AddCheckBox */
33   protected $servers        ;
34   protected $workstations   ;
35   protected $terminals      ;
38   /* Subsearch checkbox */
39   protected $SubSearch       ;
40   protected $parent          ;
41   public $ui                 ;
42  
43  
44   function target_list_systems(&$config,$Targets_used)
45   {
46     MultiSelectWindow::MultiSelectWindow($config, "Targetselection", array("server","terminal","workstation"));
48     $this->Targets_used = $Targets_used;
49     
50     $this->SetInformation(  _("Select the target objects for your scheduled action."));
51     $this->SetTitle(        _("Available systems"));
52     $this->SetSummary(      _("Available systems"));
53     $this->SetHeadpageMode(FALSE);
54     
55     /* set Page header */
56     $chk = "<input type='checkbox' id='select_all' name='select_all'
57                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
58     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
60     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
61     $this->AddHeader(array("string" => _("Object name"), "attach" => "style=''"));
63     /* Text ,Value, Name, Is selected */
64     $this->AddCheckBox("terminal",     _("Select to see terminals"),   _("Show terminals"), true);
65     $this->AddCheckBox("server",       _("Select to see servers")  ,   _("Show servers"), true);
66     $this->AddCheckBox("workstation",  _("Select to see workstations"),_("Show workstations"), true);
68     /* Add SubSearch checkbox */
69     $this->AddCheckBox(SEPERATOR);
70     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
72     /* Name,Text,Default  , Connect with alphabet  */
73     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
74     $this->EnableAplhabet(TRUE);
75   }
78   function GenHeader()
79   {
80     $options= "";
82     /* Get all departments within this subtree */
83     $ui= get_userinfo();
84     $first = "";
85     $found = FALSE;
86     $base = $this->config->current['BASE'];
88     /* Add base */
89     $tmp = array();
90     $tmp[] = array("dn"=>$this->config->current['BASE']);
91     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
92                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
94     $deps = array();
95     foreach($tmp as $tm){
96       $deps[$tm['dn']] = $tm['dn'];
97     }
99     /* Load possible departments */
100     $tdeps= array();
101     $tdeps= array_merge($tdeps,$ui->get_module_departments("server"));
102     $tdeps= array_merge($tdeps,$ui->get_module_departments("terminal"));
103     $tdeps= array_merge($tdeps,$ui->get_module_departments("workstation"));
104     $tdeps = array_unique($tdeps); 
105  
106     $ids = $this->config->idepartments;
107     $first = "";
108     $found = FALSE;
109     foreach($ids as $dep => $name){
110       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
112         /* Keep first base dn in mind, we could need this
113          *  info if no valid base was found
114          */
115         if(empty($first)) {
116           $first = $dep['dn'];
117         }
119         $value = $ids[$dep];
120         if ($this->selectedBase == $dep){
121           $found = TRUE;
122           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
123         } else {
124           $options.= "<option value='".$dep."'>$value</option>";
125         }
126       }
127     }
129     /* The currently used base is not visible with your acl setup.
130      * Set base to first useable base.
131      */
132     if(!$found){
133       $this->selectedBase = $first;
134     }
136     /* Add default header */
137     $listhead = MultiSelectWindow::get_default_header();
139     /* Add department selector */
140     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
141       " <input class='center' type='image' src='images/lists/submit.png' align='middle'
142       title='"._("Submit")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
143     $listhead .="</div>";
145     $this->SetListHeader($listhead);
146   }
149   function execute()
150   {
151     $this->ClearElementsList();
152     $this->GenHeader();
153     $this->reload();
154     $this->SetEntries($this->list);
155     return($this->Draw());
156   }
158   
159   function SetEntries($list)
160   {
161       /* Add Copy & Paste buttons if copy&paste is enabled
162      */
163     // Defining Links
164     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
166     $ui = get_userinfo();
168     // Assigning systems 
169     foreach($list as $key => $val){
171       if(in_array($val['cn'][0],$this->Targets_used) || 
172          isset($val['macAddress'][0]) && in_array($val['macAddress'][0],$this->Targets_used)) continue;
174       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
175       if(!isset($val['description'][0])){
176         $desc = "";
177       }else{
178         $desc = " - [ ".$val['description'][0]." ]";
179       }
181       $img ="?";
182       if(in_array("goServer",$val['objectClass'])){
183         $img = "<img src='plugins/systems/images/select_server.png' alt='"._("Server")."' ".$title.">";
184       }elseif(in_array("gotoWorkstation",$val['objectClass'])){
185         $img = "<img src='plugins/systems/images/select_workstation.png' alt='"._("Workstation")."' ".$title.">";
186       }elseif(in_array("gotoTerminal",$val['objectClass'])){
187         $img = "<img src='plugins/systems/images/select_terminal.png' alt='"._("Terminal")."' ".$title.">";
188       }
190       /* Create each field */
191       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
192                       "attach" => "style='width:20px;'");
193       $field1 = array("string" => $img, 
194                       "attach" => "style='text-   align:center;width: 20px;'");
195       $field2 = array("string" => $val['cn'][0].$desc, 
196                       "attach" => "style='border-right:0px;' ".$title);
198       $this->AddElement(array($field0,$field1,$field2));
199     }
200   }
202   
203   function save()
204   { 
205     $ret = array();
206     $items = $this->list_get_selected_items();
207     foreach($items as $item){
208       $ret[] = $this->list[$item];
209     }
210     return($ret);
211   }
214   function save_object()
215   {
216     MultiSelectWindow::save_object();
217   }
219   
220   function reload()
221   {
222     /* Set base for all searches && initialise some vars */
223     $this->list= array();
224     $base     = $this->selectedBase;
225     $filter   = "";
226     $Regex    = $this->Regex;
228     $filter= "(&(cn=".$Regex.")(|".$filter."))";
230     if($this->SubSearch){
231       $res= array();
232       if($this->terminal){
233         $filter = "(objectClass=gotoTerminal)";
234         $filter= "(&(cn=".$Regex.")(|".$filter."))";
235         $res= array_merge($res,get_sub_list($filter,"terminal",get_ou('terminalou'),$base, 
236               array("cn","objectClass","description"), GL_SIZELIMIT | GL_SUBSEARCH));
237       }
238       if($this->workstation){
239         $filter = "(objectClass=gotoWorkstation)";  
240         $filter= "(&(cn=".$Regex.")(|".$filter."))";
241         $res= array_merge($res,get_sub_list($filter, "workstation",  get_ou('workstationou'),$base, 
242               array("cn","objectClass","description"), GL_SIZELIMIT | GL_SUBSEARCH));
243       }
244       if($this->server){
245         $filter = "(objectClass=goServer)";
246         $filter = "(&(cn=".$Regex.")(|".$filter."))";
247         $res= array_merge($res,get_sub_list($filter, "server", get_ou('serverou'),$base, 
248               array("cn","objectClass","description"), GL_SIZELIMIT | GL_SUBSEARCH));
249       }
250     }else{
251       $res= array();
252       if($this->terminal){
253         $filter = "(objectClass=gotoTerminal)";
254         $filter= "(&(cn=".$Regex.")(|".$filter."))";
255         $res= array_merge($res,get_list($filter,"terminal", get_ou('terminalou').$base, 
256               array("cn","objectClass","description"), GL_SIZELIMIT ));
257       }
258       if($this->workstation){
259         $filter = "(objectClass=gotoWorkstation)";  
260         $filter= "(&(cn=".$Regex.")(|".$filter."))";
261         $res= array_merge($res,get_list($filter, "workstation",  get_ou('workstationou').$base, 
262               array("cn","objectClass","description"), GL_SIZELIMIT ));
263       }
264       if($this->server){
265         $filter = "(objectClass=goServer)";
266         $filter = "(&(cn=".$Regex.")(|".$filter."))";
267         $res= array_merge($res,get_list($filter, "server", get_ou('serverou').$base, 
268               array("cn","objectClass","description"), GL_SIZELIMIT ));
269       }
270     }
272     $this->list= $res;
273     ksort ($this->list);
274     reset ($this->list);
275     $tmp=array();
276     foreach($this->list as $tkey => $val ){
277       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
278     }
279     ksort($tmp);
280     $this->list=array();
281     foreach($tmp as $val){
282       $this->list[]=$val;
283     }
284     reset ($this->list);
285   }
287   function list_get_selected_items()
288   {
289     $ids = array();
290     foreach($_POST as $name => $value){
291       if(preg_match("/^item_selected_[0-9]*$/",$name)){
292         $id   = preg_replace("/^item_selected_/","",$name);
293         $ids[$id] = $id;
294       }
295     }
296     return($ids);
297   }
301 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
302 ?>