d57e83166a14fc1969c2bbf32598cfd63f8ed7e5
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 divListOGroup extends MultiSelectWindow
24 {
26 /* Current base */
27 var $selectedBase = "";
28 var $departments = array();
30 /* Regex */
31 var $Regex = "*";
33 /* CheckBoxes, to change default values modify $this->AddCheckBox */
34 var $UserGroups ;
35 var $GroupGroups ;
36 var $ApplicationGroups ;
37 var $DepartmentGroups ;
38 var $ServerGroups ;
39 var $WorkstationGroups ;
40 var $WindowsGroups ;
41 var $TerminalGroups ;
42 var $PrinterGroups ;
43 var $PhoneGroups ;
46 /* Subsearch checkbox */
47 var $SubSearch ;
48 var $parent ;
49 var $ui ;
51 function divListOGroup (&$config,$parent)
52 {
53 MultiSelectWindow::MultiSelectWindow($config, "OGroups", "ogroups");
55 $this->parent = $parent;
56 $this->ui = get_userinfo();
58 /* Set list strings */
59 $this->SetTitle(_("List of object groups"));
60 $this->SetSummary(_("List of object groups"));
61 $this->EnableAplhabet(true);
63 /* Result page will look like a headpage */
64 $this->SetHeadpageMode();
65 $this->SetInformation(_("This menu allows you to add, edit or remove selected groups. You may want to use the range selector on top of the group listbox, when working with a large number of groups."));
67 /* Disable buttonsm */
68 $this->EnableCloseButton(false);
69 $this->EnableSaveButton (false);
71 /* Dynamic action col, depending on snapshot icons */
72 $action_col_size = 80;
73 if($this->parent->snapshotEnabled()){
74 $action_col_size += 38;
75 }
77 /* Toggle all selected / deselected */
78 $chk = "<input type='checkbox' id='select_all' name='select_all'
79 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
81 /* set Page header */
82 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
83 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
84 $this->AddHeader(array("string" => _("Name of object groups")." / "._("Departments"), "attach" => "style=''"));
85 $this->AddHeader(array("string" => _("Properties"), "attach" => "style='width:136px;'"));
86 $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
88 /* Text ,Value ,Name ,Is selected */
89 $this->AddCheckBox("UserGroups" , _("Select to see groups containing users") , _("Show groups containing users"), true);
90 $this->AddCheckBox("GroupGroups" , _("Select to see groups containing groups") , _("Show groups containing groups"), true);
91 $this->AddCheckBox("ApplicationGroups", _("Select to see groups containing applications"), _("Show groups containing applications"), true);
92 $this->AddCheckBox("DepartmentGroups" , _("Select to see groups containing departments") , _("Show groups containing departments"), true);
93 $this->AddCheckBox("ServerGroups" , _("Select to see groups containing servers") , _("Show groups containing servers"), true);
94 $this->AddCheckBox("WorkstationGroups", _("Select to see groups containing workstations"), _("Show groups containing workstations"), true);
95 $this->AddCheckBox("WindowsGroups", _("Select to see groups containing windows workstations"), _("Show groups containing windows workstations"), true);
96 $this->AddCheckBox("TerminalGroups" , _("Select to see groups containing terminals") , _("Show groups containing terminals"), true);
97 $this->AddCheckBox("PrinterGroups" , _("Select to see groups containing printer") , _("Show groups containing printer"), true);
98 $this->AddCheckBox("PhoneGroups" , _("Select to see groups containing phones") , _("Show groups containing phones"), true);
100 /* Add SubSearch checkbox */
101 $this->AddCheckBox(SEPERATOR);
102 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
104 /* Name ,Text ,Default , Connect with alphabet */
105 $this->AddRegex ("Regex", _("Regular expression for matching group names"), "*" , true);
106 }
109 function GenHeader()
110 {
111 /* Prepare departments,
112 which are shown in the listbox on top of the listbox
113 */
114 $options= "";
116 /* Get all departments within this subtree */
117 $ui= get_userinfo();
118 $first = "";
119 $found = FALSE;
120 $base = $this->config->current['BASE'];
122 /* Add base */
123 $tmp = array();
124 $tmp[] = array("dn"=>$this->config->current['BASE']);
125 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
126 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
128 $deps = array();
129 foreach($tmp as $tm){
130 $deps[$tm['dn']] = $tm['dn'];
131 }
133 /* Load possible departments */
134 $ui= get_userinfo();
135 $tdeps= $ui->get_module_departments("ogroups");
136 $ids = $this->config->idepartments;
137 $first = "";
138 $found = FALSE;
139 foreach($ids as $dep => $name){
140 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
142 /* Keep first base dn in mind, we could need this
143 * info if no valid base was found
144 */
145 if(empty($first)) {
146 $first = $dep['dn'];
147 }
149 $value = $ids[$dep];
150 if ($this->selectedBase == $dep){
151 $found = TRUE;
152 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
153 } else {
154 $options.= "<option value='".$dep."'>$value</option>";
155 }
156 }
157 }
159 /* The currently used base is not visible with your acl setup.
160 * Set base to first useable base.
161 */
162 if(!$found){
163 $this->selectedBase = $first;
164 }
166 /* Add a seperator after displaying c&p and snapshot icons ? */
167 $add_sep = false;
169 /* Get copy & paste icon */
170 $acls = $ui->get_permissions($this->selectedBase,"ogroups/ogroup");
171 $acl_all= $ui->has_complete_category_acls($this->selectedBase,"ogroups");
172 $Copy_Paste ="";
173 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
174 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
175 $add_sep = true;
176 }
178 /* Add default header */
179 $listhead = MultiSelectWindow::get_default_header();
182 /* Add department selector */
183 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
184 " <input class='center' type='image' src='images/list_submit.png' align='middle'
185 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
188 /* Create Layers menu */
189 $s = ".|"._("Actions")."|\n";
190 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
191 " "._("Create")."|\n";
193 /* Append create options */
194 if(preg_match("/c/",$acls)) {
195 $s.= "...|<input class='center' type='image' src='images/list_new_ogroup.png' alt=''>".
196 " "._("Object group")."|group_new|\n";
197 }
199 /* Multiple options */
200 $s.= "..|---|\n";
201 # $s.= "..|<img src='images/edit.png' alt='' border='0' class='center'>".
202 # " "._("Edit")."|"."multiple_edit|\n";
204 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
205 " "._("Remove")."|"."remove_multiple_ogroups/|\n";
207 /* Add notification event */
208 if(class_available("DaemonEvent_notify")){
209 $events = DaemonEvent::get_event_types(USER_EVENT);
210 $event = $events['BY_CLASS']['DaemonEvent_notify'];
211 $s.= "..|---|\n";
212 $s.= "..|".$event['MenuImage']." ".$event['s_Menu_Name']."|trigger_event_DaemonEvent_notify\n";
213 }
215 /* Add multiple copy & cut icons */
216 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
217 $s.= "..|---|\n";
218 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
219 " "._("Copy")."|"."multiple_copy_systems|\n";
220 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
221 " "._("Cut")."|"."multiple_cut_systems|\n";
223 if($this->parent->CopyPasteHandler->entries_queued()){
224 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
225 $s.="..|".$img." "._("Paste")."|editPaste|\n";
226 }else{
227 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
228 $s.="..|".$img." "._("Paste")."\n";
229 }
230 }
232 /* Add snapshot icons */
233 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
234 $s .= "..|---|\n";
235 $s .= $this->get_snapshot_header(TRUE);
236 }
238 $this->SetDropDownHeaderMenu($s);
239 $this->SetListHeader($listhead);
240 }
242 function execute()
243 {
244 $this->ClearElementsList();
245 $this->GenHeader();
246 }
248 function setEntries($list)
249 {
250 /* Add Copy & Paste buttons if copy&paste is enabled
251 */
252 // Defining Links
253 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
254 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
255 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
256 $mailimg = "<img class='center' src='images/mailto.png' alt='M' title='"._("Mail") ."'>";
257 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
259 /* Dynamic action col, depending on snapshot icons */
260 $action_col_size = 80;
261 if($this->parent->snapshotEnabled()){
262 $action_col_size += 38;
263 }
265 $ui = get_userinfo();
267 // Assigning ogroups
268 foreach($list as $key => $val){
270 /* Create action icons */
271 $actions= "";
272 $acl_all= $ui->has_complete_category_acls($val['dn'],"ogroups");
273 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
274 $actions.= "<input class='center' type='image'
275 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
276 $actions.= "<input class='center' type='image'
277 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
278 }
280 $actions.= "<input class='center' type='image'
281 src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
283 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
284 $actions.= $this->GetSnapShotActions($val['dn']);
285 }
287 if(preg_match("/d/",$ui->get_permissions($val['dn'],"ogroups/ogroup"))) {
288 $actions.= "<input class='center' type='image'
289 src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
290 }else{
291 $actions.= "<img class='center' src='images/empty.png' alt=' '
292 title='"._("You are not allowed to remove this entry.")."'>";
293 }
296 if(isset($val['mail'])){
297 $mail = $mailimg;
298 }else{
299 $mail = $empty;
300 }
301 $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'";
302 if(!isset($val['description'][0])){
303 $desc = "";
304 }else{
305 $desc = " - [ ".$val['description'][0]." ]";
306 }
308 /* Cutted objects should be displayed in light grey */
309 $display = $val['cn'][0].$desc;
310 if($this->parent->CopyPasteHandler){
311 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
312 if($queue_data['dn'] == $val['dn']) {
313 $display = "<font color='#999999'>".$display."</font>";
314 break;
315 }
316 }
317 }
319 /* Create each field */
320 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
321 "attach" => "style='width:20px;'");
322 $field1 = array("string" => "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">", "attach" => "style='text-align:center;width: 20px;'");
323 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
324 $field3 = array("string" => preg_replace("/%KEY/", $key, $this->parent->convert_list($val))." ".$mail, "attach" => "style='width:136px;'");
325 $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
327 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
328 }
331 /* Create summary string for list footer */
332 $num_deps=0;
333 if(!$this->SubSearch){
334 $num_deps = count($this->Added_Departments);
335 }
336 $num_objs = count($list);
338 $num_obj_str = _("Number of listed object groups");
339 $num_dep_str = _("Number of listed departments");
341 $str = "<img class='center' src='images/select_ogroup.png'
342 title='".$num_obj_str."' alt='".$num_obj_str."'> ".$num_objs." ";
343 $str.= "<img class='center' src='images/folder.png'
344 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
346 $this->set_List_Bottom_Info($str);
347 }
349 function Save()
350 {
351 MultiSelectWindow :: Save();
352 }
354 function save_object()
355 {
356 /* Save automatic created POSTs like regex, checkboxes */
357 MultiSelectWindow::save_object();
358 }
359 }
360 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
361 ?>