Code

Added some logging
[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;";
189     $listhead .= "</div>";
190     $this->SetListHeader($listhead);
191   }
193   function execute()
194   {
195     $this->ClearElementsList();
196     $this->GenHeader();
197   }
199   function setEntries($groups)
200   {
201     // Defining Links
202     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
204     // image Buttons
205     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
206     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
208     /* Dynamic action col, depending on snapshot icons */
209     $action_col_size = 80;
210     if($this->parent->snapshotEnabled()){
211       $action_col_size += 38;
212     }
214     /* Assign extension images */
215     $posiximg = "<input type='image' class='center' src='images/select_groups.png'
216                  name='group_group_edit_%KEY%' alt='P'  title='"._("Posix")  ."'>";
217     $mailimg  = "<input type='image' class='center' src='images/mailto.png'
218                  name='mailgroup_group_edit_%KEY%' alt='M'  title='"._("Mail")   ."'>";
219     $sambaimg = "<input type='image'  class='center' src='images/select_winstation.png'
220                  name='group_group_edit_%KEY%' alt='S'  title='"._("Samba")  ."'>";
221     $applimg  = "<input type='image'  class='center' src='images/select_application.png'
222                  name='appgroup_group_edit_%KEY%' alt='A'  title='"._("Application")."'>";
223     $phoneimg = "<input type='image'  class='center' src='images/select_phone.png'
224                  name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone")  ."'>";
225     $envimg   = "<input type='image'  class='center' src='images/smallenv.png'
226                  name='environment_group_edit_%KEY%' alt='E' title='"._("Environment")  ."'>";
228     // Space
229     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
231     // User and Template  Images
232     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
234     $ui = get_userinfo();
236     // Test Every Entry and generate divlist Array
237     foreach($groups as $key => $val){
238     
239       /* Create action icons - copy & paste icons */
240       $acl = $ui->get_permissions($val['dn'],"groups/group");
241       $acl_all= $ui->has_complete_category_acls($val['dn'],"groups");
243       $actions= "";
244       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
245         $actions.= "<input class='center' type='image'
246           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
247         $actions.= "<input class='center' type='image'
248           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
249       }
251       /* Add edit icon */
252       $actions.= "<input class='center' type='image'
253         src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
255       /* Add snapshot functionality */
256       if(preg_match("/(c.*w|w.*c)/", $acl_all)){
257         $actions.= $this->GetSnapShotActions($val['dn']);
258       }
260       if(preg_match("/d/",$acl)){
261         $actions.= "<input class='center' type='image'
262           src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
263       }
266       $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
268       if(isset($val['objectClass'])){
269         if(in_array("posixGroup",           $val['objectClass']))   $posix = $posiximg;
270         if(in_array("gosaMailAccount",      $val['objectClass']))   $mail  = $mailimg;
271         if(in_array("sambaGroupMapping",    $val['objectClass']))   $samba = $sambaimg;
272         if(in_array("gosaApplicationGroup", $val['objectClass']))   $appl  = $applimg;
273         if(in_array("goFonPickupGroup",     $val['objectClass']))   $phone = $phoneimg;
274         if(in_array("gotoEnvironment",      $val['objectClass']))   $enviro= $envimg;
275       }
277       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
279       if(!isset($val['description'][0])){
280         $desc = "";
281       }else{
282         $desc = " - [ ".$val['description'][0]." ]";
283       }
285       /* FAIrelease tag from groupApplications */
286       if(isset($val['FAIrelease'][0])){
287         $desc .= " (".$val['FAIrelease'][0].")";
288       }
290       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
291           "attach" => "style='width:20px;'");
293       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
294       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
295       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone),     "attach" => "style='width:136px;'");
296       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
298       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
299     }
300   }
302   function Save()
303   {
304     MultiSelectWindow :: Save();  
305   }
307   function save_object()
308   {
309     /* Save automatic created POSTs like regex, checkboxes */
310     MultiSelectWindow::save_object();   
311   }
313 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
314 ?>