Code

Updated groups acls
[gosa.git] / gosa-core / plugins / admin / groups / class_divListGroup.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 divListGroup extends MultiSelectWindow
24 {
26   /* Current base */
27   var $selectedBase       = "";
28   var $departments        = array();
30   /* Regex */
31   var $Regex              = "*";
32   var $UserRegex          = "*";
34   /* CheckBoxes, to change default values modify $this->AddCheckBox */
35   var $ShowPrimaryGroups;
36   var $ShowSambaGroups;  
37   var $ShowApplicationGroups; 
38   var $ShowMailGroups;
39   var $ShowFunctionalGroups;
41   /* Subsearch checkbox */
42   var $SubSearch              = false;
44   var $parent             ;
45   var $ui                 ;
47   function divListGroup (&$config, &$parent)
48   {
49     MultiSelectWindow::MultiSelectWindow($config, "Groups", "groups");
50     
51     $this->parent       = &$parent;
52     $this->ui           = get_userinfo();
54     /* Set list strings */
55     $this->SetTitle(_("List of groups"));
56     $this->SetSummary(_("List of groups"));
57     $this->EnableAplhabet   (true);
59     /* Result page will look like a headpage */
60     $this->SetHeadpageMode();
61   
62     /* Disable buttonsm */
63     $this->EnableCloseButton(false);
64     $this->EnableSaveButton (false);
66     /* Dynamic action col, depending on snapshot icons */
67     $action_col_size = 80;
68     if($this->parent->snapshotEnabled()){
69       $action_col_size += 38;
70     }
72     /* Toggle all selected / deselected */
73     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
74                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
76     /* set Page header */
77     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
78     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
79     $this->AddHeader(array("string"=>_("Name")."&nbsp;/&nbsp;"._("Department")));
80     $this->AddHeader(array("string"=>_("Properties"),"attach"=>"style='width:136px;'"));
81     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
83     /*                  Text        ,Value    ,Name         ,Is selected */
84     $this->AddCheckBox("ShowPrimaryGroups",     _("Select to see groups that are primary groups of users"), 
85                                                   sprintf(_("Show %s"),_("primary groups")),     true);
86     $this->AddCheckBox("ShowSambaGroups",       msgPool::selectToView(_("samba groups mappings"),"enabled"), 
87                                                   sprintf(_("Show %s"),_("samba groups")),              true);
88     $this->AddCheckBox("ShowApplicationGroups", msgPool::selectToView(_("application settings"),"enabled"),     
89                                                   sprintf(_("Show %s"),_("application groups")),        true);
90     $this->AddCheckBox("ShowMailGroups",        msgPool::selectToView(_("mail settings"),"enabled"), 
91                                                   sprintf(_("Show %s"),_("mail groups")),               true);
92     $this->AddCheckBox("ShowFunctionalGroups",  _("Select to see normal groups that have only functional aspects"),
93                                                   sprintf(_("Show %s"),_("functional groups")),     true);
94     $this->AddCheckBox(SEPERATOR);
96     /* Add SubSearch checkbox */    
97     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"),msgPool::selectToView("","subsearch_small"), false);
99     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
100     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
101     $this->AddRegex   ("UserRegex", _("User name of which groups are shown"),         "*" , false, "images/lists/search-user.png");
102   }
105   function GenHeader()
106   {
107     /* Prepare departments,
108        which are shown in the listbox on top of the listbox
109      */
110     $options= "";
113     
114     /* Get all departments within this subtree */
115     $ui= get_userinfo();
116     $first = "";
117     $found = FALSE;
118     $base = $this->config->current['BASE'];
121     
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("groups");
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     }
165   
166     /* Get acls */
167     $acl   = $ui->get_permissions($this->selectedBase,"groups/group");
170     /* Add default header */
171     $listhead = MultiSelectWindow::get_default_header();
172     
173     /* Add department selection */
174     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
175       " <input type='image' class='center' src='images/lists/submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
176       "'>&nbsp;";
178     /* Create Layers menu */
179     $s  = ".|"._("Actions")."|\n";
181     /* Append create options */
182     if(preg_match("/c/",$acl)) {
183       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
184         "&nbsp;"._("Create")."|\n";
185       $s.= "...|<input class='center' type='image' src='plugins/groups/images/new.png' alt=''>".
186         "&nbsp;"._("Group")."|group_new|\n";
187     }
189     /* Multiple options */
190     $s.= "..|---|\n";
191     $s.= "..|<img src='images/lists/edit.png' alt='' border='0' class='center'>".
192       "&nbsp;"._("Edit")."|"."multiple_edit|\n";
193     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
194       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
196     /* Add event tag */
197     if(class_available("DaemonEvent")){
198       $events  = DaemonEvent::get_event_types(USER_EVENT);
199       if(count($events['BY_CLASS'])){
200         $s.= "..|---|\n";
201         foreach($events['BY_CLASS'] as $name => $event){
202           $s.= "..|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|event_".$name."\n";
203         }
204       }
205     }
207     /* Add multiple copy & cut icons */
208     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"groups");
210     if(is_object($this->parent->CopyPasteHandler) && preg_match("/r/",$acl_all)){
211       $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
212         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
213       $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
214         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
215     }
217     /* Copy & paste icons */
218     if(is_object($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler->entries_queued()){
219       $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
220       $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
221     }else{
222       $img = "<img border='0' class='center' src='images/lists/paste-grey.png' alt=''>";
223       $s.="..|".$img."&nbsp;"._("Paste")."\n";
224     }
226     /* Add snapshot icons */
227     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
228       $s .= "..|---|\n";
229       $s .= $this->get_snapshot_header(TRUE);
230     }
232     $this->SetDropDownHeaderMenu($s);
234     $this->SetListHeader($listhead);
235   }
237   function execute()
238   {
239     $this->ClearElementsList();
240     $this->GenHeader();
241   }
243   function setEntries($groups)
244   {
245     // Defining Links
246     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
248     // image Buttons
249     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
250     $userimg  = "<img class='center' src='plugins/groups/images/groups.png' alt='User'    title='%s'>";
252     /* Dynamic action col, depending on snapshot icons */
253     $action_col_size = 80;
254     if($this->parent->snapshotEnabled()){
255       $action_col_size += 38;
256     }
258     /* Assign extension images */
259     $posiximg = "<input type='image' class='center' src='plugins/groups/images/groups.png'
260                  name='group_group_edit_%KEY%' alt='P'  title='"._("Posix")  ."'>";
261     $mailimg  = "<input type='image' class='center' src='plugins/groups/images/mail.png'
262                  name='mailgroup_group_edit_%KEY%' alt='M'  title='"._("Mail")   ."'>";
263     $sambaimg = "<input type='image'  class='center' src='plugins/groups/images/samba.png'
264                  name='group_group_edit_%KEY%' alt='S'  title='"._("Samba")  ."'>";
265     $applimg  = "<input type='image'  class='center' src='plugins/groups/images/menu.png'
266                  name='appgroup_group_edit_%KEY%' alt='A'  title='"._("Application")."'>";
267     $phoneimg = "<input type='image'  class='center' src='plugins/groups/images/asterisk.png'
268                  name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone")  ."'>";
269     $envimg   = "<input type='image'  class='center' src='plugins/groups/images/environment.png'
270                  name='environment_group_edit_%KEY%' alt='E' title='"._("Environment")  ."'>";
272     // Space
273     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
275     // User and Template  Images
276     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
278     $ui = get_userinfo();
280     /* Fetch all application menu entries 
281      */
282     $base = get_groups_ou().$this->selectedBase;
283     $ldap = $this->config->get_ldap_link();
284     $ldap->cd ($base);
285     $ldap->search("(objectClass=gotoMenuEntry)",array("dn"));
286     $configured_apps = array();
287     while($entry = $ldap->fetch()){
288       $dn = preg_replace("/^.*(cn=[^,]+,".normalizePreg(get_groups_ou()).")/","\\1",$entry['dn']);
289       $configured_apps[$dn] = $dn;
290     }
292     // Test Every Entry and generate divlist Array
293     foreach($groups as $key => $val){
294     
295       /* Create action icons - copy & paste icons */
296       $acl = $ui->get_permissions($val['dn'],"groups/group");
297       $acl_all  = $ui->has_complete_category_acls($val['dn'],"groups");
299       $actions= "";
300       if(preg_match("/(r.*d|r.*d)/",$acl_all) && $this->parent->CopyPasteHandler){
301         $actions.= "<input class='center' type='image'
302           src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
303       }else{
304         $actions.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
305       }
307       if(preg_match("/r/",$acl_all) && $this->parent->CopyPasteHandler){
308         $actions.= "<input class='center' type='image'
309           src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
310       }else{
311         $actions.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
312       }
314       /* Add edit icon */
315       $actions.= "<input class='center' type='image'
316         src='images/lists/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
318       /* Add snapshot functionality */
319       if(preg_match("/(r.*w|w.*r)/",$acl_all)){
320         $actions.= $this->GetSnapShotActions($val['dn']);
321       }else{
322         $actions.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
323         $actions.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
324       }
326       if(preg_match("/d/",$acl)){
327         $actions.= "<input class='center' type='image'
328           src='images/lists/trash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
329       }else{
330         $actions.= "<img class='center' src='images/empty.png' alt='&nbsp;'
331           title='"._("Not allowed")."'>";
332       }
334       $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
336       if(isset($val['objectClass'])){
337         if(in_array("posixGroup",           $val['objectClass']))   $posix = $posiximg;
338         if(in_array("gosaMailAccount",      $val['objectClass']))   $mail  = $mailimg;
339         if(in_array("sambaGroupMapping",    $val['objectClass']))   $samba = $sambaimg;
340         if(in_array("goFonPickupGroup",     $val['objectClass']))   $phone = $phoneimg;
341         if(in_array("gotoEnvironment",      $val['objectClass']))   $enviro= $envimg;
342       }
344       if(isset($configured_apps[$val['dn']])){
345           $appl  = $applimg;
346       }
348       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
350       if(!isset($val['description'][0])){
351         $desc = "";
352       }else{
353         $desc = " - [ ".$val['description'][0]." ]";
354       }
356       /* FAIrelease tag from groupApplications */
357       if(isset($val['FAIrelease'][0])){
358         $desc .= " (".$val['FAIrelease'][0].")";
359       }
361       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
362           "attach" => "style='width:20px;'");
364       /* Cutted objects should be displayed in light grey */
365       $display = $val['cn'][0].$desc;
366       if($this->parent->CopyPasteHandler){
367         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
368           if($queue_data['dn'] == $val['dn']) {
369             $display = "<font color='#999999'>".$display."</font>";
370             break;
371           }
372         }
373       }
375       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
376       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
377       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone),     "attach" => "style='width:136px;'");
378       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
380       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
381     }
383     /* Create summary string for list footer */
384     $num_deps=0;
385     if(!$this->SubSearch){
386       $num_deps = count($this->Added_Departments);
387     }
388     $num_grps = count($groups);
390     $num_grp_str = _("Number of listed groups");
391     $num_dep_str = _("Number of listed departments");
393     $str = "<img class='center' src='plugins/groups/images/groups.png'
394               title='".$num_grp_str."' alt='".$num_grp_str."'>&nbsp;".$num_grps."&nbsp;&nbsp;&nbsp;&nbsp;";
395     $str.= "<img class='center' src='images/lists/folder.png'
396               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
398     $this->set_List_Bottom_Info($str);
400   }
402   function Save()
403   {
404     MultiSelectWindow :: Save();  
405   }
407   function save_object()
408   {
409     /* Save automatic created POSTs like regex, checkboxes */
410     MultiSelectWindow::save_object();   
411   }
413 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
414 ?>