Code

Allow - as mount point
[gosa.git] / plugins / admin / groups / class_divListGroup.inc
1 <?php
3 class divListGroup extends MultiSelectWindow
4 {
6   /* Current base */
7   var $selectedBase       = "";
8   var $departments        = array();
10   /* Regex */
11   var $Regex              = "*";
12   var $UserRegex          = "*";
14   /* CheckBoxes, to change default values modify $this->AddCheckBox */
15   var $ShowPrimaryGroups;
16   var $ShowSambaGroups;  
17   var $ShowApplicationGroups; 
18   var $ShowMailGroups;
19   var $ShowFunctionalGroups;
21   /* Subsearch checkbox */
22   var $SubSearch              = false;
24   var $parent             ;
25   var $ui                 ;
27   function divListGroup ($config,$parent)
28   {
29     MultiSelectWindow::MultiSelectWindow($config, "Groups", "groups");
30     
31     $this->parent       = $parent;
32     $this->ui           = get_userinfo();
34     /* Set list strings */
35     $this->SetTitle(_("List of groups"));
36     $this->SetSummary(_("List of groups"));
37     $this->EnableAplhabet   (true);
39     /* Result page will look like a headpage */
40     $this->SetHeadpageMode();
41     $this->SetInformation(_("This menu allows you to add, edit and 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."));
42   
43     /* Disable buttonsm */
44     $this->EnableCloseButton(false);
45     $this->EnableSaveButton (false);
47     /* Dynamic action col, depending on snapshot icons */
48     $action_col_size = 80;
49     if($this->parent->snapshotEnabled()){
50       $action_col_size += 38;
51     }
53     /* Toggle all selected / deselected */
54     $chk = "<input type='checkbox' id='select_all' name='select_all'
55                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
57     /* set Page header */
58     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
59     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
60     $this->AddHeader(array("string"=>_("Groupname / Department")));
61     $this->AddHeader(array("string"=>_("Properties"),"attach"=>"style='width:136px;'"));
62     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
64     /*                  Text        ,Value    ,Name         ,Is selected */
65     $this->AddCheckBox("ShowPrimaryGroups",     _("Select to see groups that are primary groups of users"),          _("Show primary groups"),      true);
66     $this->AddCheckBox("ShowSambaGroups",       _("Select to see groups that have samba groups mappings"),          _("Show samba groups"),      true);
67     $this->AddCheckBox("ShowApplicationGroups", _("Select to see groups that have applications configured"),        _("Show application groups"),true);
68     $this->AddCheckBox("ShowMailGroups",        _("Select to see groups that have mail settings"),                  _("Show mail groups"),       true);
69     $this->AddCheckBox("ShowFunctionalGroups",  _("Select to see normal groups that have only functional aspects"), _("Show functional groups"), true);
70     $this->AddCheckBox(SEPERATOR);
72     /* Add SubSearch checkbox */    
73     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
75     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
76     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
77     $this->AddRegex   ("UserRegex", _("User name of which groups are shown"),         "*" , false, "images/search_user.png");
78   }
81   function GenHeader()
82   {
83     /* Prepare departments,
84        which are shown in the listbox on top of the listbox
85      */
86     $options= "";
89     
90     /* Get all departments within this subtree */
91     $ui= get_userinfo();
92     $first = "";
93     $found = FALSE;
94     $base = $this->config->current['BASE'];
97     
98     /* Add base */
99     $tmp = array();
100     $tmp[] = array("dn"=>$this->config->current['BASE']);
101     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
102                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
104     $deps = array();
105     foreach($tmp as $tm){
106       $deps[$tm['dn']] = $tm['dn'];
107     }
109         /* Load possible departments */
110     $ui= get_userinfo();
111     $tdeps= $ui->get_module_departments("groups");
112     $ids = $this->config->idepartments;
113     $first = "";
114     $found = FALSE;
115     foreach($ids as $dep => $name){
116       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
118         /* Keep first base dn in mind, we could need this
119          *  info if no valid base was found
120          */
121         if(empty($first)) {
122           $first = $dep['dn'];
123         }
125         $value = $ids[$dep];
126         if ($this->selectedBase == $dep){
127           $found = TRUE;
128           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
129         } else {
130           $options.= "<option value='".$dep."'>$value</option>";
131         }
132       }
133     }
135     /* The currently used base is not visible with your acl setup.
136      * Set base to first useable base.
137      */
138     if(!$found){
139       $this->selectedBase = $first;
140     }
141   
142     /* Get acls */
143     $acls   = $ui->get_permissions($this->selectedBase,"groups/group");
144     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"groups");
146     /* If this is true add a seperator after added c&p and snapshot icons to header */
147     $addsep = false;
149     /* Get copy & paste icon */
150     $Copy_Paste ="";
151     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
152       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
153       $addsep = true;
154     }
156     /* Add default header */
157     $listhead = MultiSelectWindow::get_default_header();
158     
159     /* Add snapshot restore icon and force a following seperator */
160     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
161       $listhead .= $this->get_snapshot_header($this->selectedBase);
162       $addsep = true;
163     }
165     /* Add Create group icon */
166     if(preg_match("/c/",$acls)) {
167       $listhead.=" <input type='image' class='center' src='images/list_new_group.png' 
168         title='"._("Create new group")."' alt='"._("New")."' name='group_new'>&nbsp;";
169       $addsep = true;
170     }
172     /* Assign copy & paste icons */
173     $listhead.=      $Copy_Paste;
174     
175     /* Append an additional seperator */
176     if($addsep){
177       $listhead.=" <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;";
178     }
179     
180     /* Add department selection */
181     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
182       " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
183       "'>&nbsp;";
185     /* Multiple options */
186     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
187         title='"._("Remove selected groups")."' alt='"._("Remove groups")."' name='remove_multiple_groups'>&nbsp;";
188   
189     /* Add multiple copy & cut icons */
190     if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
191       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcopy.png'
192         title='"._("Copy selected group")."' alt='"._("Copy groups")."' name='multiple_copy_groups'>&nbsp;";
193       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcut.png'
194         title='"._("cut selected group")."' alt='"._("Cut groups")."' name='multiple_cut_groups'>&nbsp;";
195       $listhead .= "</div>";
196     }
197     $this->SetListHeader($listhead);
198   }
200   function execute()
201   {
202     $this->ClearElementsList();
203     $this->GenHeader();
204   }
206   function setEntries($groups)
207   {
208     // Defining Links
209     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
211     // image Buttons
212     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
213     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
215     /* Dynamic action col, depending on snapshot icons */
216     $action_col_size = 80;
217     if($this->parent->snapshotEnabled()){
218       $action_col_size += 38;
219     }
221     /* Assign extension images */
222     $posiximg = "<input type='image' class='center' src='images/select_groups.png'
223                  name='group_group_edit_%KEY%' alt='P'  title='"._("Posix")  ."'>";
224     $mailimg  = "<input type='image' class='center' src='images/mailto.png'
225                  name='mailgroup_group_edit_%KEY%' alt='M'  title='"._("Mail")   ."'>";
226     $sambaimg = "<input type='image'  class='center' src='images/select_winstation.png'
227                  name='group_group_edit_%KEY%' alt='S'  title='"._("Samba")  ."'>";
228     $applimg  = "<input type='image'  class='center' src='images/select_application.png'
229                  name='appgroup_group_edit_%KEY%' alt='A'  title='"._("Application")."'>";
230     $phoneimg = "<input type='image'  class='center' src='images/select_phone.png'
231                  name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone")  ."'>";
232     $envimg   = "<input type='image'  class='center' src='images/smallenv.png'
233                  name='environment_group_edit_%KEY%' alt='E' title='"._("Environment")  ."'>";
235     // Space
236     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
238     // User and Template  Images
239     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
241     $ui = get_userinfo();
243     // Test Every Entry and generate divlist Array
244     foreach($groups as $key => $val){
245     
246       /* Create action icons - copy & paste icons */
247       $acl = $ui->get_permissions($val['dn'],"groups/group");
248       $acl_all= $ui->has_complete_category_acls($val['dn'],"groups");
250       $actions= "";
251       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
252         $actions.= "<input class='center' type='image'
253           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
254         $actions.= "<input class='center' type='image'
255           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
256       }
258       /* Add edit icon */
259       $actions.= "<input class='center' type='image'
260         src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
262       /* Add snapshot functionality */
263       if(preg_match("/(c.*w|w.*c)/", $acl_all)){
264         $actions.= $this->GetSnapShotActions($val['dn']);
265       }
267       if(preg_match("/d/",$acl)){
268         $actions.= "<input class='center' type='image'
269           src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
270       }
273       $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
275       if(isset($val['objectClass'])){
276         if(in_array("posixGroup",           $val['objectClass']))   $posix = $posiximg;
277         if(in_array("gosaMailAccount",      $val['objectClass']))   $mail  = $mailimg;
278         if(in_array("sambaGroupMapping",    $val['objectClass']))   $samba = $sambaimg;
279         if(in_array("gosaApplicationGroup", $val['objectClass']))   $appl  = $applimg;
280         if(in_array("goFonPickupGroup",     $val['objectClass']))   $phone = $phoneimg;
281         if(in_array("gotoEnvironment",      $val['objectClass']))   $enviro= $envimg;
282       }
284       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
286       if(!isset($val['description'][0])){
287         $desc = "";
288       }else{
289         $desc = " - [ ".$val['description'][0]." ]";
290       }
292       /* FAIrelease tag from groupApplications */
293       if(isset($val['FAIrelease'][0])){
294         $desc .= " (".$val['FAIrelease'][0].")";
295       }
297       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
298           "attach" => "style='width:20px;'");
300       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
301       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
302       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone),     "attach" => "style='width:136px;'");
303       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
305       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
306     }
307   }
309   function Save()
310   {
311     MultiSelectWindow :: Save();  
312   }
314   function save_object()
315   {
316     /* Save automatic created POSTs like regex, checkboxes */
317     MultiSelectWindow::save_object();   
318   }
320 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
321 ?>