Code

* Fixed undefined index for "All"
[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'];
95     $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
96                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
98     /* Add base */
99     $deps[] = array("dn"=>$this->config->current['BASE']);
101     /* Load possible departments */
102     $ui= get_userinfo();
103     $tdeps= $ui->get_module_departments("groups");
105     $ids = $this->config->idepartments;
107     foreach($deps as $dep){
108       if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
110         /* Keep first base dn in mind, we could need this 
111          *  info if no valid base was found 
112          */
113         if(empty($first)) {
114           $first = $dep['dn'];
115         }
117         $value = $ids[$dep['dn']];
118         if ($this->selectedBase == $dep['dn']){
119           $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
120         } else {
121           $options.= "<option value='".$dep['dn']."'>$value</option>";
122         }
123       }
124     }
126     /* The currently used base is not visible with your acl setup.
127      * Set base to first useable base.
128      */
129     if(!$found){
130       $this->selectedBase = $first;
131     }
132   
133     /* Get acls */
134     $acls   = $ui->get_permissions($this->selectedBase,"groups/group");
135     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"groups");
137     /* If this is true add a seperator after added c&p and snapshot icons to header */
138     $addsep = false;
140     /* Get copy & paste icon */
141     $Copy_Paste ="";
142     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
143       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
144       $addsep = true;
145     }
147     /* Add default header */
148     $listhead = MultiSelectWindow::get_default_header();
149     
150     /* Add snapshot restore icon and force a following seperator */
151     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
152       $listhead .= $this->get_snapshot_header($this->selectedBase);
153       $addsep = true;
154     }
156     /* Add Create group icon */
157     if(preg_match("/c/",$acls)) {
158       $listhead.=" <input type='image' class='center' src='images/list_new_group.png' 
159         title='"._("Create new group")."' alt='"._("New")."' name='group_new'>&nbsp;";
160       $addsep = true;
161     }
163     /* Assign copy & paste icons */
164     $listhead.=      $Copy_Paste;
165     
166     /* Append an additional seperator */
167     if($addsep){
168       $listhead.=" <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;";
169     }
170     
171     /* Add department selection */
172     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
173       " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
174       "'>&nbsp;";
176     /* Multiple options */
177     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
178         title='"._("Remove selected groups")."' alt='"._("Remove groups")."' name='remove_multiple_groups'>&nbsp;";
180     $listhead .= "</div>";
181     $this->SetListHeader($listhead);
182   }
184   function execute()
185   {
186     $this->ClearElementsList();
187     $this->GenHeader();
188   }
190   function setEntries($groups)
191   {
192     // Defining Links
193     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
195     // image Buttons
196     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
197     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
199     /* Dynamic action col, depending on snapshot icons */
200     $action_col_size = 80;
201     if($this->parent->snapshotEnabled()){
202       $action_col_size += 38;
203     }
205     /* Assign extension images */
206     $posiximg = "<input type='image' class='center' src='images/select_groups.png'
207                  name='group_group_edit_%KEY%' alt='P'  title='"._("Posix")  ."'>";
208     $mailimg  = "<input type='image' class='center' src='images/mailto.png'
209                  name='mailgroup_group_edit_%KEY%' alt='M'  title='"._("Mail")   ."'>";
210     $sambaimg = "<input type='image'  class='center' src='images/select_winstation.png'
211                  name='group_group_edit_%KEY%' alt='S'  title='"._("Samba")  ."'>";
212     $applimg  = "<input type='image'  class='center' src='images/select_application.png'
213                  name='appgroup_group_edit_%KEY%' alt='A'  title='"._("Application")."'>";
214     $phoneimg = "<input type='image'  class='center' src='images/select_phone.png'
215                  name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone")  ."'>";
216     $envimg   = "<input type='image'  class='center' src='images/smallenv.png'
217                  name='environment_group_edit_%KEY%' alt='E' title='"._("Environment")  ."'>";
219     // Space
220     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
222     // User and Template  Images
223     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
225     $ui = get_userinfo();
227     // Test Every Entry and generate divlist Array
228     foreach($groups as $key => $val){
229     
230       /* Create action icons - copy & paste icons */
231       $acl = $ui->get_permissions($val['dn'],"groups/group");
232       $acl_all= $ui->has_complete_category_acls($val['dn'],"groups");
234       $actions= "";
235       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
236         $actions.= "<input class='center' type='image'
237           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
238         $actions.= "<input class='center' type='image'
239           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
240       }
242       /* Add edit icon */
243       $actions.= "<input class='center' type='image'
244         src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
246       /* Add snapshot functionality */
247       if(preg_match("/(c.*w|w.*c)/", $acl_all)){
248         $actions.= $this->GetSnapShotActions($val['dn']);
249       }
251       if(preg_match("/d/",$acl)){
252         $actions.= "<input class='center' type='image'
253           src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
254       }
257       $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
259       if(isset($val['objectClass'])){
260         if(in_array("posixGroup",           $val['objectClass']))   $posix = $posiximg;
261         if(in_array("gosaMailAccount",      $val['objectClass']))   $mail  = $mailimg;
262         if(in_array("sambaGroupMapping",    $val['objectClass']))   $samba = $sambaimg;
263         if(in_array("gosaApplicationGroup", $val['objectClass']))   $appl  = $applimg;
264         if(in_array("goFonPickupGroup",     $val['objectClass']))   $phone = $phoneimg;
265         if(in_array("gotoEnvironment",      $val['objectClass']))   $enviro= $envimg;
266       }
268       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
270       if(!isset($val['description'][0])){
271         $desc = "";
272       }else{
273         $desc = " - [ ".$val['description'][0]." ]";
274       }
276       /* FAIrelease tag from groupApplications */
277       if(isset($val['FAIrelease'][0])){
278         $desc .= " (".$val['FAIrelease'][0].")";
279       }
281       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
282           "attach" => "style='width:20px;'");
284       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
285       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
286       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone),     "attach" => "style='width:136px;'");
287       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
289       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
290     }
291   }
293   function Save()
294   {
295     MultiSelectWindow :: Save();  
296   }
298   function save_object()
299   {
300     /* Save automatic created POSTs like regex, checkboxes */
301     MultiSelectWindow::save_object();   
302   }
304 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
305 ?>