Code

Updated copy & paste acls, centralized checks
[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   
66     /* Disable buttonsm */
67     $this->EnableCloseButton(false);
68     $this->EnableSaveButton (false);
70     /* Dynamic action col, depending on snapshot icons */
71     $action_col_size = 80;
72     if($this->parent->snapshotEnabled()){
73       $action_col_size += 38; 
74     }
76     /* Toggle all selected / deselected */
77     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
78                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
80     /* set Page header */
81     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
82     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
83     $this->AddHeader(array("string" => _("Object group")." / "._("Department"), "attach" => "style=''"));
84     $this->AddHeader(array("string" => _("Properties"), "attach" => "style='width:136px;'"));
85     $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
87     /*                  Text        ,Value    ,Name         ,Is selected */
88     $str2 = _("Show %s");
89     $this->AddCheckBox("UserGroups" ,       sprintf($str2,  _("user groups")), 
90                                             sprintf($str2,  _("user groups")), true);
91     $this->AddCheckBox("GroupGroups" ,      sprintf($str2,  _("nested groups")),
92                                             sprintf($str2,  _("nested groups")), true);
93     $this->AddCheckBox("ApplicationGroups", sprintf($str2,  _("application groups")),
94                                             sprintf($str2,  _("application groups")), true);
95     $this->AddCheckBox("DepartmentGroups" , sprintf($str2,  _("department groups")),
96                                             sprintf($str2,  _("department groups")), true);
97     $this->AddCheckBox("ServerGroups" ,     sprintf($str2,  _("server groups")),
98                                             sprintf($str2,  _("server groups")), true);
99     $this->AddCheckBox("WorkstationGroups", sprintf($str2,  _("workstation groups")),
100                                             sprintf($str2,  _("workstation groups")), true);
101     $this->AddCheckBox("WindowsGroups",     sprintf($str2,  _("windows workstation groups")),
102                                             sprintf($str2,  _("windows workstation groups")), true);
103     $this->AddCheckBox("TerminalGroups" ,   sprintf($str2,  _("terminal groups")),
104                                             sprintf($str2,  _("terminal groups")), true);
105     $this->AddCheckBox("PrinterGroups" ,    sprintf($str2,  _("printer groups")),
106                                             sprintf($str2,  _("printer groups")), true);
107     $this->AddCheckBox("PhoneGroups" ,      sprintf($str2,  _("phone groups")),
108                                             sprintf($str2,  _("phone groups")), true);
110     /* Add SubSearch checkbox */    
111     $this->AddCheckBox(SEPERATOR);
112     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
114     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
115     $this->AddRegex   ("Regex", _("Regular expression for matching group names"), "*" , true);
116   }
119   function GenHeader()
120   {
121     /* Prepare departments,
122        which are shown in the listbox on top of the listbox
123      */
124     $options= "";
126     /* Get all departments within this subtree */
127     $ui= get_userinfo();
128     $first = "";
129     $found = FALSE;
130     $base = $this->config->current['BASE'];
132     /* Add base */
133     $tmp = array();
134     $tmp[] = array("dn"=>$this->config->current['BASE']);
135     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
136                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
138     $deps = array();
139     foreach($tmp as $tm){
140       $deps[$tm['dn']] = $tm['dn'];
141     }
143     /* Load possible departments */
144     $ui= get_userinfo();
145     $tdeps= $ui->get_module_departments("ogroups");
146     $ids = $this->config->idepartments;
147     $first = "";
148     $found = FALSE;
149     foreach($ids as $dep => $name){
150       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
152         /* Keep first base dn in mind, we could need this
153          *  info if no valid base was found
154          */
155         if(empty($first)) {
156           $first = $dep['dn'];
157         }
159         $value = $ids[$dep];
160         if ($this->selectedBase == $dep){
161           $found = TRUE;
162           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
163         } else {
164           $options.= "<option value='".$dep."'>$value</option>";
165         }
166       }
167     }
169     /* The currently used base is not visible with your acl setup.
170      * Set base to first useable base.
171      */
172     if(!$found){
173       $this->selectedBase = $first;
174     }
176     /* Add a seperator after displaying c&p and snapshot icons ? */
177     $add_sep = false;
178   
179     /* Get copy & paste icon */
180     $acls  = $ui->get_permissions($this->selectedBase,"ogroups/ogroup");
181     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"ogroups");
184     /* Add default header */
185     $listhead = MultiSelectWindow::get_default_header();
186   
187     /* Add department selector */
188     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
189       " <input class='center' type='image' src='images/lists/submit.png' align='middle' 
190       title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
193     /* Create Layers menu */
194     $s  = ".|"._("Actions")."|\n";
196     /* Append create options */
197     if(preg_match("/c/",$acls)) {
198       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
199         "&nbsp;"._("Create")."|\n";
200       $s.= "...|<input class='center' type='image' src='plugins/ogroups/images/new.png' alt=''>".
201         "&nbsp;"._("Object group")."|group_new|\n";
202     }
204     /* Multiple options */
205     $s.= "..|---|\n";
206 #   $s.= "..|<img src='images/lists/edit.png' alt='' border='0' class='center'>".
207 #     "&nbsp;"._("Edit")."|"."multiple_edit|\n";
208     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
209       "&nbsp;"._("Remove")."|"."remove_multiple_ogroups/|\n";
211     /* Add event tag */
212     if(class_available("DaemonEvent")){
213       $events  = DaemonEvent::get_event_types(USER_EVENT);
214       if(count($events['BY_CLASS'])){
215         $s.= "..|---|\n";
216         foreach($events['BY_CLASS'] as $name => $event){
217           $s.= "..|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|event_".$name."\n";
218         }
219       }
220     }
222     /* Add Copy & Paste header */
223     $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
225     /* Add snapshot icons */
226     $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);    
228     $this->SetDropDownHeaderMenu($s);
229     $this->SetListHeader($listhead);
230   }
233   function execute()
234   {
235     $this->ClearElementsList();
236     $this->GenHeader();
237   }
239   function setEntries($list)
240   {
241     /* Add Copy & Paste buttons if copy&paste is enabled
242      */
243     // Defining Links
244     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
245     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
246     $userimg  = "<img class='center' src='plugins/groups/images/groups.png' alt='User'    title='%s'>";
247     $mailimg  = "<img class='center' src='plugins/ogroups/images/mail.png'             alt='M'  title='"._("Mail")   ."'>";
248     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
250     /* Dynamic action col, depending on snapshot icons */
251     $action_col_size = 80;
252     if($this->parent->snapshotEnabled()){
253       $action_col_size += 38; 
254     }
255   
256     $ui = get_userinfo();
258     // Assigning ogroups
259     foreach($list as $key => $val){
261       $actions = "";
262       
263       /* Create action icons */
264       $acl    = $ui->get_permissions($val['dn'],"ogroups/ogroup");
265       $acl_all= $ui->has_complete_category_acls($val['dn'],"ogroups");
267       if($ui->is_cutable($val['dn'],"ogroups","ogroup") && $this->parent->CopyPasteHandler){
268         $actions .= "<input class='center' type='image'
269           src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
270       }else{
271         $actions.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
272       }
274       if($ui->is_copyable($val['dn'],"ogroups","ogroup") && $this->parent->CopyPasteHandler){
275         $actions.= "<input class='center' type='image'
276           src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
277       }else{
278         $actions.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
279       }
281       $actions.= "<input class='center' type='image'
282         src='images/lists/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
283     
284       $actions.= $this->parent->get_snapshot_action($val['dn'],$this->module);
286       if(preg_match("/d/",$acl)){
287         $actions.= "<input class='center' type='image'
288           src='images/lists/trash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
289       }else{
290         $actions.= "<img class='center' src='images/empty.png' alt='&nbsp;'
291           title='".msgPool::permDelete()."'>";
292       }
294       if(isset($val['mail'])){
295         $mail = $mailimg;
296       }else{
297         $mail = $empty;
298       }
299       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
300       if(!isset($val['description'][0])){
301         $desc = "";
302       }else{
303         $desc = " - [ ".$val['description'][0]." ]";
304       }
306       /* Cutted objects should be displayed in light grey */
307       $display = $val['cn'][0].$desc;
308       if($this->parent->CopyPasteHandler){
309         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
310           if($queue_data['dn'] == $val['dn']) {
311             $display = "<font color='#999999'>".$display."</font>";
312             break;
313           }
314         }
315       }
317       /* Create each field */
318       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
319                       "attach" => "style='width:20px;'");
320       $field1 = array("string" => "<img src='plugins/ogroups/images/ogroup.png' alt='"._("Object group")."' ".$title.">", "attach" => "style='text-align:center;width: 20px;'");
321       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
322       $field3 = array("string" => preg_replace("/%KEY/", $key, $this->parent->convert_list($val))."&nbsp;".$mail, "attach" => "style='width:136px;'");
323       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
325       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
326     }
327    
328  
329     /* Create summary string for list footer */
330     $num_deps=0;
331     if(!$this->SubSearch){
332       $num_deps = count($this->Added_Departments);
333     }
334     $num_objs = count($list);
336     $num_obj_str = _("Number of listed object groups");
337     $num_dep_str = _("Number of listed departments");
339     $str = "<img class='center' src='plugins/ogroups/images/ogroup.png'
340               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
341     $str.= "<img class='center' src='images/lists/folder.png'
342               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
344     $this->set_List_Bottom_Info($str);
345   }
347   function Save()
348   {
349     MultiSelectWindow :: Save();  
350   }
352   function save_object()
353   {
354     /* Save automatic created POSTs like regex, checkboxes */
355     MultiSelectWindow::save_object();   
356   }
358 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
359 ?>