Code

Updated gotomasses
[gosa.git] / gosa-plugins / goto / addons / goto / events / class_EventTargetAddList.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$$
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 EventTargetAddList extends MultiSelectWindow
24 {
25   public $display_server = TRUE;
26   public $display_workstation = TRUE;
27   public $display_ogroup = TRUE;
28   public $filter_iprange = FALSE;
30   public $regex  = "*";
31   public $ipfrom = "0.0.0.0";
32   public $ipto   = "*";
33   public $_target_list = array();
35   public $workstation_list = array();
36   public $server_list = array();
39   function __construct(&$config,$parent)
40   {
41     MultiSelectWindow::MultiSelectWindow($config, "EventTargetAddList", 
42         array("server",
43           "workstation",
44           "ogroup"));
46     $this->parent       = $parent;
47     $this->ui           = get_userinfo();
50     $this->target_divlist = new MultiSelectWindow($this->config,"EventAddTargedtList","gotomasses");
51     $this->SetSummary(_("Targets"));
52     $this->EnableCloseButton(FALSE);
53     $this->EnableSaveButton(FALSE);
55     $this->SetInformation(_("This dialog shows all available targets for your event, check the targets you want to add   and use the 'Use' button to accept."));
57     /* Toggle all selected / deselected */
58     $chk = "<input type='checkbox' id='select_all' name='select_all'
59       onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
61     $this->EnableAplhabet(TRUE);
63     /* set Page header */
64     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
65     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
66     $this->AddHeader(array("string"=>_("System / Department")));
68     //$name,$string,$value,$conn,$image="images/search.png")
69     $this->AddRegex("regex" ,"regex"  ,"*"                , TRUE);
70     $this->AddRegex("ipfrom","ipfrom" ,"0.0.0.0"          , FALSE);
71     $this->AddRegex("ipto"  ,"ipto"   ,"255.255.255.255"  , FALSE);
73     $this->AddCheckBox("display_server","1"     ,_("Display server"),TRUE);
74     $this->AddCheckBox("display_workstation","1",_("Display workstation"),TRUE);
75     $this->AddCheckBox("display_ogroup","1"     ,_("Display object groups"),TRUE);
76     $this->AddCheckBox("filter_iprange","1"     ,_("Filter by IP range"),FALSE);
80     /* Create a list of servers
81      */
82     $tmp = get_sub_list("(&(macAddress=*)(objectClass=goServer))",
83           "server",get_ou("serverou"),$config->current['BASE'],
84           array("cn","objectClass","description","ipHostNumber","macAddress"),GL_SUBSEARCH);
85     foreach($tmp as $server){
86       $this->server_list[$server['dn']] = $server;
87     }
89     /* Create a list of workstations
90      */
91     $tmp = get_sub_list("(&(macAddress=*)(objectClass=gotoWorkstation))",
92           "server",get_ou("workstationou"),$config->current['BASE'],
93           array("cn","objectClass","description","ipHostNumber","macAddress"),GL_SUBSEARCH);
94     foreach($tmp as $server){
95       $this->workstation_list[$server['dn']] = $server;
96     }
98   }
101   function execute()
102   {
103     $this->ClearElementsList();
104     $this->AddDepartments($this->selectedBase,2,1);
105     $this->setEntries();
106     $this->GenHeader();
107   }
110   function GenHeader()
111   {
112     $modules = array("server","workstation");
114     /* Add base */
115     $tmp = array();
116     $base = $this->config->current['BASE'];
117     $tmp[] = array("dn"=>$this->config->current['BASE']);
118     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $modules, $base,
119           array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
121     $deps = array();
122     foreach($tmp as $tm){
123       $deps[$tm['dn']] = $tm['dn'];
124     }
126     $department = $departments = array();
127     $ui= get_userinfo();
128     $d = $ui->get_module_departments($modules);
129     foreach($d as $department){
130       $departments[$department] = $department;
131     }
133     /* Load possible departments */
134     $ids = $this->config->idepartments;
135     $first = "";
136     $found = FALSE;
137     $options = array();
138     foreach($ids as $dep => $name){
139       if(isset($deps[$dep]) && in_array_ics($dep, $departments)){
141         /* Keep first base dn in mind, we could need this
142          *  info if no valid base was found
143          */
144         if(empty($first)) {
145           $first = $dep['dn'];
146         }
148         $value = $ids[$dep];
149         if ($this->selectedBase == $dep){
150           $found = TRUE;
151           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
152         } else {
153           $options.= "<option value='".$dep."'>$value</option>";
154         }
155       }
156     }
158     $listhead = $this->get_default_header();
160     /* Add base selection */
161     $listhead .= _("Base")."&nbsp; <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
162       " <input class='center' type='image' src='images/list_submit.png' align='middle'
163       title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'>&nbsp;";
165     $this->SetListHeader($listhead);
167   }
170   function setEntries()
171   {
172     $_target_list = array();
173     if($this->display_server){
174       $_target_list = array_merge($_target_list,
175             get_list("(&(cn=".$this->regex.")(objectClass=goServer))",
176             "server",get_ou("serverou").$this->selectedBase,
177             array("cn","objectClass","description","ipHostNumber","macAddress"),GL_NONE));
178     }
179     if($this->display_workstation){
180       $_target_list = array_merge($_target_list,
181             get_list("(&(cn=".$this->regex.")(objectClass=gotoWorkstation))",
182             "workstation",get_ou("workstationou").$this->selectedBase,
183             array("cn","objectClass","description","ipHostNumber","macAddress"),GL_NONE));
184     }
185     if($this->display_ogroup){
186       $_target_list = array_merge($_target_list,
187             get_list("(&(cn=".$this->regex.")(member=*)(objectClass=gosaGroupOfNames))",
188             "ogroups",get_ou("ogroupou").$this->selectedBase,
189             array("cn","objectClass","description","member"),GL_NONE));
190     }
191     $this->_target_list = $_target_list;
193     $tmp = array();
194     foreach($this->_target_list as $key => $object){
195       $tmp[$key] = $object['cn'][0];
196     }
197     natcasesort($tmp);
199     foreach($tmp as $key => $obj){
201       $obj = $this->_target_list[$key];
202       $name = $obj['cn'][0];
203       if(isset($obj['description'])){
204         $name .= "&nbsp;[".$obj['description'][0]."]";
205       }
206       if(isset($obj['macAddress'])){
207         $name .= "&nbsp;- ".$obj['macAddress'][0]."";
208       }
209       if(isset($obj['ipHostNumber'])){
210         $name .= "&nbsp;- ".$obj['ipHostNumber'][0]."";
211       }
213       $img ="";
214       if(in_array("goServer",$obj['objectClass'])){
215         $img = '<img class="center" src="images/select_server.png" alt="S" title="'._("Server").'">';
217         if($this->filter_iprange){
218           if(!isset($obj['ipHostNumber']) || !tests::is_in_ip_range($this->ipfrom,$this->ipto,             $obj['ipHostNumber'][0])) {
219             continue;
220           }
221         }
222         if(!isset($this->server_list[$obj['dn']])){
223           continue;
224         }
225       }elseif(in_array("gotoWorkstation",$obj['objectClass'])){
226         $img = '<img class="center" src="images/select_workstation.png" alt="W" title="'._("Workstation").'">';
227         if($this->filter_iprange){
228           if(!isset($obj['ipHostNumber']) || !tests::is_in_ip_range($this->ipfrom,$this->ipto,$obj['ipHostNumber'][0])) {
229             continue;
230           }
231         }
232         if(!isset($this->workstation_list[$obj['dn']])){
233           continue;
234         }
235       }elseif(in_array("gosaGroupOfNames",$obj['objectClass'])){
236         $img = '<img class="center" src="images/select_ogroup.png" alt="O" title="'._("Object group").'">';
237       }
239       $field1 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>",
240                       "attach" => "style='width:20px;'");
241       $field2 = array("string" => $img,
242                       "attach" => "style='width:20px;'");
243       $field3 = array("string" => $name , "attach" => "title='".$obj['dn']."'");
244       $this->AddElement(array($field1,$field2,$field3));
245     }
246   }
248 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
249 ?>