Code

Updated gotomasses to support dns and dhcp options for initial_install action
[gosa.git] / plugins / addons / gotomasses / class_target_list.inc
1 <?php
3 class target_list extends MultiSelectWindow
4 {
5   var $config;
6   var $list         =array();
7   var $Targets_used =array();
9   /* Current base */
10   var $selectedBase       = "";
11   var $departments        = array();
13   /* Regex */
14   var $Regex              = "*";
16   /* CheckBoxes, to change default values modify $this->AddCheckBox */
17   var $ogroups        ;
18   var $servers        ;
19   var $workstations   ;
22   /* Subsearch checkbox */
23   var $SubSearch          ;
24   var $parent             ;
25   var $ui                 ;
26  
27  
28   function target_list($config,$Targets_used)
29   {
30     MultiSelectWindow::MultiSelectWindow($config, "Targetselection", array("ogroup","gotomasses"));
32     $this->Targets_used = $Targets_used;
33     
34     $this->SetInformation(  _("Select the target objects for your scheduled action."));
35     $this->SetTitle(        _("Available targets"));
36     $this->SetSummary(      _("Available targets"));
37     $this->SetHeadpageMode(FALSE);
38     
39     /* set Page header */
40     $chk = "<input type='checkbox' id='select_all' name='select_all'
41                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
42     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
44     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
45     $this->AddHeader(array("string" => _("Object name"), "attach" => "style=''"));
47     /* Text ,Value, Name, Is selected */
48     $this->AddCheckBox("ogroups",       _("Select to see object groups"),  _("Show object groups"), true);
49     $this->AddCheckBox("servers",       _("Select to see servers")  ,   _("Show servers"), true);
50     $this->AddCheckBox("workstations",  _("Select to see workstations"),_("Show workstations"), true);
52     /* Add SubSearch checkbox */
53     $this->AddCheckBox(SEPERATOR);
54     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
56     /* Name,Text,Default  , Connect with alphabet  */
57     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
58     $this->EnableAplhabet(TRUE);
59   }
62   function GenHeader()
63   {
64     $options= "";
66     /* Get all departments within this subtree */
67     $ui= get_userinfo();
68     $first = "";
69     $found = FALSE;
70     $base = $this->config->current['BASE'];
72     /* Add base */
73     $tmp = array();
74     $tmp[] = array("dn"=>$this->config->current['BASE']);
75     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
76                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
78     $deps = array();
79     foreach($tmp as $tm){
80       $deps[$tm['dn']] = $tm['dn'];
81     }
83     /* Load possible departments */
84     $ui= get_userinfo();
85     $tdeps= $ui->get_module_departments("ogroups");
86     $ids = $this->config->idepartments;
87     $first = "";
88     $found = FALSE;
89     foreach($ids as $dep => $name){
90       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
92         /* Keep first base dn in mind, we could need this
93          *  info if no valid base was found
94          */
95         if(empty($first)) {
96           $first = $dep['dn'];
97         }
99         $value = $ids[$dep];
100         if ($this->selectedBase == $dep){
101           $found = TRUE;
102           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
103         } else {
104           $options.= "<option value='".$dep."'>$value</option>";
105         }
106       }
107     }
109     /* The currently used base is not visible with your acl setup.
110      * Set base to first useable base.
111      */
112     if(!$found){
113       $this->selectedBase = $first;
114     }
116     /* Get copy & paste icon */
117     $acls  = $ui->get_permissions($this->selectedBase,"ogroups/ogroup");
118     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"ogroups");
120     /* Add default header */
121     $listhead = MultiSelectWindow::get_default_header();
123     /* Add department selector */
124     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
125       " <input class='center' type='image' src='images/list_submit.png' align='middle'
126       title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
127     $listhead .="</div>";
129     $this->SetListHeader($listhead);
130   }
133   function execute()
134   {
135     $this->ClearElementsList();
136     $this->GenHeader();
137     $this->reload();
138     $this->SetEntries($this->list);
139     foreach($this->list as $key => $data){
140       
141     } 
142     return($this->Draw());
143   }
145   
146   function SetEntries($list)
147   {
148       /* Add Copy & Paste buttons if copy&paste is enabled
149      */
150     // Defining Links
151     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
152     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
154     $ui = get_userinfo();
156     // Assigning ogroups
157     foreach($list as $key => $val){
159       if(in_array($val['cn'][0],$this->Targets_used) || 
160          isset($val['macAddress'][0]) && in_array($val['macAddress'][0],$this->Targets_used)) continue;
162       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
163       if(!isset($val['description'][0])){
164         $desc = "";
165       }else{
166         $desc = " - [ ".$val['description'][0]." ]";
167       }
169       $img ="Hmm";
170       if(in_array("goServer",$val['objectClass'])){
171         $img = "<img src='images/select_server.png' alt='"._("Server")."' ".$title.">";
172       }elseif(in_array("gotoWorkstation",$val['objectClass'])){
173         $img = "<img src='images/select_workstation.png' alt='"._("Workstation")."' ".$title.">";
174       }elseif(in_array("gosaGroupOfNames",$val['objectClass'])){
175         $img = "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">";
176       }
178       /* Create each field */
179       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
180                       "attach" => "style='width:20px;'");
181       $field1 = array("string" => $img, 
182                       "attach" => "style='text-   align:center;width: 20px;'");
183       $field2 = array("string" => $val['cn'][0].$desc, 
184                       "attach" => "style='border-right:0px;' ".$title);
186       $this->AddElement(array($field0,$field1,$field2));
187     }
188   }
190   
191   function save()
192   { 
193     $ret = array();
194     $items = $this->list_get_selected_items();
195     foreach($items as $item){
196       $ret[] = $this->list[$item];
197     }
198     return($ret);
199   }
202   function save_object()
203   {
204     MultiSelectWindow::save_object();
205   }
207   
208   function reload()
209   {
210     /* Set base for all searches && initialise some vars */
211     $this->list= array();
212     $base     = $this->selectedBase;
213     $filter   = "";
214     $Regex    = $this->Regex;
216     $chk = array(
217         "ogroups"       => "(&(objectClass=gosaGroupOfNames)(|(gosaGroupObjects=*S*)(gosaGroupObjects=*W*)))" ,
218         "servers"       => "(objectClass=goServer)" ,
219         "workstations"  => "(objectClass=gotoWorkstation)");
221     /* Create filter */
222     foreach($chk as $chkBox => $FilterPart){
223       if($this->$chkBox){
224         $filter .=  $FilterPart;
225       }
226     }
227     $filter= "(&(cn=".$Regex.")(|".$filter."))";
229     if($this->SubSearch){
230       $res= get_list($filter, array("ogroups","workstations","servers"), $base, 
231             array("cn","objectClass","gosaGroupObjects"), GL_SIZELIMIT | GL_SUBSEARCH);
232     }else{
233       $res= get_list($filter, "ogroups", get_groups_ou().$base, 
234             array("cn","objectClass"), GL_SIZELIMIT );
235       $res= array_merge($res,get_list($filter, "workstation",  "ou=workstations,ou=systems,".$base, 
236             array("cn","objectClass"), GL_SIZELIMIT ));
237       $res= array_merge($res,get_list($filter, "server", "ou=servers,ou=systems,".$base, 
238             array("cn","objectClass"), GL_SIZELIMIT ));
239   
240     }
242     $this->list= $res;
243     ksort ($this->list);
244     reset ($this->list);
245     $tmp=array();
246     foreach($this->list as $tkey => $val ){
247       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
248     }
249     ksort($tmp);
250     $this->list=array();
251     foreach($tmp as $val){
252       $this->list[]=$val;
253     }
254     reset ($this->list);
255   }
257   function list_get_selected_items()
258   {
259     $ids = array();
260     foreach($_POST as $name => $value){
261       if(preg_match("/^item_selected_[0-9]*$/",$name)){
262         $id   = preg_replace("/^item_selected_/","",$name);
263         $ids[$id] = $id;
264       }
265     }
266     return($ids);
267   }
271 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
272 ?>