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 var $config;
26 var $list =array();
27 var $Targets_used =array();
29 /* Current base */
30 var $selectedBase = "";
31 var $departments = array();
33 /* Regex */
34 var $Regex = "*";
36 /* CheckBoxes, to change default values modify $this->AddCheckBox */
37 var $servers ;
38 var $workstations ;
39 var $terminals ;
42 /* Subsearch checkbox */
43 var $SubSearch ;
44 var $parent ;
45 var $ui ;
48 function target_list_systems(&$config,$Targets_used)
49 {
50 MultiSelectWindow::MultiSelectWindow($config, "Targetselection", array("server","terminal","workstation"));
52 $this->Targets_used = $Targets_used;
54 $this->SetInformation( _("Select the target objects for your scheduled action."));
55 $this->SetTitle( _("Available targets"));
56 $this->SetSummary( _("Available targets"));
57 $this->SetHeadpageMode(FALSE);
59 /* set Page header */
60 $chk = "<input type='checkbox' id='select_all' name='select_all'
61 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
62 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
64 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
65 $this->AddHeader(array("string" => _("Object name"), "attach" => "style=''"));
67 /* Text ,Value, Name, Is selected */
68 $this->AddCheckBox("terminal", _("Select to see terminals"), _("Show terminals"), true);
69 $this->AddCheckBox("server", _("Select to see servers") , _("Show servers"), true);
70 $this->AddCheckBox("workstation", _("Select to see workstations"),_("Show workstations"), true);
72 /* Add SubSearch checkbox */
73 $this->AddCheckBox(SEPERATOR);
74 $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
76 /* Name,Text,Default , Connect with alphabet */
77 $this->AddRegex ("Regex", _("Regular expression for matching group names"), "*" , true);
78 $this->EnableAplhabet(TRUE);
79 }
82 function GenHeader()
83 {
84 $options= "";
86 /* Get all departments within this subtree */
87 $ui= get_userinfo();
88 $first = "";
89 $found = FALSE;
90 $base = $this->config->current['BASE'];
92 /* Add base */
93 $tmp = array();
94 $tmp[] = array("dn"=>$this->config->current['BASE']);
95 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
96 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
98 $deps = array();
99 foreach($tmp as $tm){
100 $deps[$tm['dn']] = $tm['dn'];
101 }
103 /* Load possible departments */
104 $tdeps= $ui->get_module_departments(array("server","terminal","workstation"));
105 $ids = $this->config->idepartments;
106 $first = "";
107 $found = FALSE;
108 foreach($ids as $dep => $name){
109 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
111 /* Keep first base dn in mind, we could need this
112 * info if no valid base was found
113 */
114 if(empty($first)) {
115 $first = $dep['dn'];
116 }
118 $value = $ids[$dep];
119 if ($this->selectedBase == $dep){
120 $found = TRUE;
121 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
122 } else {
123 $options.= "<option value='".$dep."'>$value</option>";
124 }
125 }
126 }
128 /* The currently used base is not visible with your acl setup.
129 * Set base to first useable base.
130 */
131 if(!$found){
132 $this->selectedBase = $first;
133 }
135 /* Add default header */
136 $listhead = MultiSelectWindow::get_default_header();
138 /* Add department selector */
139 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
140 " <input class='center' type='image' src='images/list_submit.png' align='middle'
141 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
142 $listhead .="</div>";
144 $this->SetListHeader($listhead);
145 }
148 function execute()
149 {
150 $this->ClearElementsList();
151 $this->GenHeader();
152 $this->reload();
153 $this->SetEntries($this->list);
154 return($this->Draw());
155 }
158 function SetEntries($list)
159 {
160 /* Add Copy & Paste buttons if copy&paste is enabled
161 */
162 // Defining Links
163 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
164 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&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('/ /', ' ', @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='images/select_server.png' alt='"._("Server")."' ".$title.">";
184 }elseif(in_array("gotoWorkstation",$val['objectClass'])){
185 $img = "<img src='images/select_workstation.png' alt='"._("Workstation")."' ".$title.">";
186 }elseif(in_array("gotoTerminal",$val['objectClass'])){
187 $img = "<img src='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 }
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 }
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 $chk = array(
229 "terminal" => "(objectClass=gotoTerminal)",
230 "server" => "(objectClass=goServer)" ,
231 "workstation" => "(objectClass=gotoWorkstation)");
233 /* Create filter */
234 foreach($chk as $chkBox => $FilterPart){
235 if($this->$chkBox){
236 $filter .= $FilterPart;
237 }
238 }
239 $filter= "(&(cn=".$Regex.")(|".$filter."))";
241 if($this->SubSearch){
242 $res= get_list($filter, array("terminal","workstation","server"), $base,
243 array("cn","objectClass","gosaGroupObjects","description"), GL_SIZELIMIT | GL_SUBSEARCH);
244 }else{
245 $res= get_list($filter, "terminal", get_ou('terminalou').$base,
246 array("cn","objectClass","description"), GL_SIZELIMIT );
247 $res= array_merge($res,get_list($filter, "workstation", get_ou('workstationou').$base,
248 array("cn","objectClass","description"), GL_SIZELIMIT ));
249 $res= array_merge($res,get_list($filter, "server", get_ou('serverou').$base,
250 array("cn","objectClass","description"), GL_SIZELIMIT ));
252 $deps_a = array(
253 get_ou("workstationou"),
254 get_ou("terminalou"),
255 get_ou("serverou"));
257 $res = get_sub_list($filter,array("server","terminal","workstation"),
258 $deps_a,get_ou("systemsou").$base,array("cn","objectClass","description"),GL_SIZELIMIT);
259 }
261 $this->list= $res;
262 ksort ($this->list);
263 reset ($this->list);
264 $tmp=array();
265 foreach($this->list as $tkey => $val ){
266 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
267 }
268 ksort($tmp);
269 $this->list=array();
270 foreach($tmp as $val){
271 $this->list[]=$val;
272 }
273 reset ($this->list);
274 }
276 function list_get_selected_items()
277 {
278 $ids = array();
279 foreach($_POST as $name => $value){
280 if(preg_match("/^item_selected_[0-9]*$/",$name)){
281 $id = preg_replace("/^item_selected_/","",$name);
282 $ids[$id] = $id;
283 }
284 }
285 return($ids);
286 }
287 }
290 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
291 ?>