Code

Updated ogroup mangement.
[gosa.git] / gosa-core / plugins / admin / ogroups / class_divListOGroup.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 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        ;
44   
46   /* Subsearch checkbox */
47   var $SubSearch          ;
48   var $parent             ;
49   var $ui                 ;
51   function divListOGroup (&$config,$parent)
52   {
53     MultiSelectWindow::MultiSelectWindow($config, "OGroups", "ogroups");
54     
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."));
66   
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" => "&nbsp;", "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;
168   
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();
181   
182     /* Add department selector */
183     $listhead .= _("Base")."&nbsp;<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")."'>&nbsp;";
188     /* Create Layers menu */
189     $s  = ".|"._("Actions")."|\n";
190     $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
191       "&nbsp;"._("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         "&nbsp;"._("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 #      "&nbsp;"._("Edit")."|"."multiple_edit|\n";
204     $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
205       "&nbsp;"._("Remove")."|"."remove_multiple_ogroups/|\n";
207     /* Add event tag */
208     if(class_available("DaemonEvent")){
209       $events  = DaemonEvent::get_event_types(USER_EVENT);
210       if(count($events['BY_CLASS'])){
211         $s.= "..|---|\n";
212         foreach($events['BY_CLASS'] as $name => $event){
213           $s.= "..|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|event_".$name."\n";
214         }
215       }
216     }
218     /* Add multiple copy & cut icons */
219     if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
220       $s.= "..|---|\n";
221       $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
222         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
223       $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
224         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
226       if($this->parent->CopyPasteHandler->entries_queued()){
227         $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
228         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
229       }else{
230         $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
231         $s.="..|".$img."&nbsp;"._("Paste")."\n";
232       }
233     }
235     /* Add snapshot icons */
236     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
237       $s .= "..|---|\n";
238       $s .= $this->get_snapshot_header(TRUE);
239     }
241     $this->SetDropDownHeaderMenu($s);
242     $this->SetListHeader($listhead);
243   }
245   function execute()
246   {
247     $this->ClearElementsList();
248     $this->GenHeader();
249   }
251   function setEntries($list)
252   {
253     /* Add Copy & Paste buttons if copy&paste is enabled
254      */
255     // Defining Links
256     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
257     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
258     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
259     $mailimg  = "<img class='center' src='images/mailto.png'             alt='M'  title='"._("Mail")   ."'>";
260     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
262     /* Dynamic action col, depending on snapshot icons */
263     $action_col_size = 80;
264     if($this->parent->snapshotEnabled()){
265       $action_col_size += 38; 
266     }
267   
268     $ui = get_userinfo();
270     // Assigning ogroups
271     foreach($list as $key => $val){
273       /* Create action icons */
274       $actions= "";
275       $acl_all= $ui->has_complete_category_acls($val['dn'],"ogroups");
276       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
277         $actions.= "<input class='center' type='image'
278           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
279         $actions.= "<input class='center' type='image'
280           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
281       }
283       $actions.= "<input class='center' type='image'
284         src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
285     
286       if(preg_match("/(c.*w|w.*c)/", $acl_all)){
287         $actions.= $this->GetSnapShotActions($val['dn']);
288       }
290       if(preg_match("/d/",$ui->get_permissions($val['dn'],"ogroups/ogroup"))) {
291         $actions.= "<input class='center' type='image'
292           src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
293       }else{
294         $actions.= "<img class='center' src='images/empty.png' alt='&nbsp;'
295           title='"._("You are not allowed to remove this entry.")."'>";
296       }
299       if(isset($val['mail'])){
300         $mail = $mailimg;
301       }else{
302         $mail = $empty;
303       }
304       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
305       if(!isset($val['description'][0])){
306         $desc = "";
307       }else{
308         $desc = " - [ ".$val['description'][0]." ]";
309       }
311       /* Cutted objects should be displayed in light grey */
312       $display = $val['cn'][0].$desc;
313       if($this->parent->CopyPasteHandler){
314         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
315           if($queue_data['dn'] == $val['dn']) {
316             $display = "<font color='#999999'>".$display."</font>";
317             break;
318           }
319         }
320       }
322       /* Create each field */
323       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
324                       "attach" => "style='width:20px;'");
325       $field1 = array("string" => "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">", "attach" => "style='text-align:center;width: 20px;'");
326       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
327       $field3 = array("string" => preg_replace("/%KEY/", $key, $this->parent->convert_list($val))."&nbsp;".$mail, "attach" => "style='width:136px;'");
328       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
330       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
331     }
332    
333  
334     /* Create summary string for list footer */
335     $num_deps=0;
336     if(!$this->SubSearch){
337       $num_deps = count($this->Added_Departments);
338     }
339     $num_objs = count($list);
341     $num_obj_str = _("Number of listed object groups");
342     $num_dep_str = _("Number of listed departments");
344     $str = "<img class='center' src='images/select_ogroup.png'
345               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
346     $str.= "<img class='center' src='images/folder.png'
347               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
349     $this->set_List_Bottom_Info($str);
350   }
352   function Save()
353   {
354     MultiSelectWindow :: Save();  
355   }
357   function save_object()
358   {
359     /* Save automatic created POSTs like regex, checkboxes */
360     MultiSelectWindow::save_object();   
361   }
363 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
364 ?>