Code

Starting move
[gosa.git] / gosa-core / 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"), _("Search in 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");
147     /* Add default header */
148     $listhead = MultiSelectWindow::get_default_header();
149     
150     /* Add department selection */
151     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
152       " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
153       "'>&nbsp;";
156         /* Create Layers menu */
157     $s  = ".|"._("Actions")."|\n";
158     $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
159       "&nbsp;"._("Create")."|\n";
162     /* Append create options */
163     if(preg_match("/c/",$acl_all)) {
164       $s.= "...|<input class='center' type='image' src='images/list_new_group.png' alt=''>".
165         "&nbsp;"._("Group")."|group_new|\n";
166     }
168     /* Multiple options */
169     $s.= "..|---|\n";
170     $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
171       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
173     /* Add multiple copy & cut icons */
174     if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
175       $s.= "..|---|\n";
176       $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
177         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
178       $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
179         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
181       if($this->parent->CopyPasteHandler->entries_queued()){
182         $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
183         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
184       }else{
185         $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
186         $s.="..|".$img."&nbsp;"._("Paste")."\n";
187       }
188     }
190     /* Add snapshot icons */
191     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
192       $s .= "..|---|\n";
193       $s .= $this->get_snapshot_header(TRUE);
194     }
196     $this->SetDropDownHeaderMenu($s);
198     $this->SetListHeader($listhead);
199   }
201   function execute()
202   {
203     $this->ClearElementsList();
204     $this->GenHeader();
205   }
207   function setEntries($groups)
208   {
209     // Defining Links
210     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
212     // image Buttons
213     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
214     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
216     /* Dynamic action col, depending on snapshot icons */
217     $action_col_size = 80;
218     if($this->parent->snapshotEnabled()){
219       $action_col_size += 38;
220     }
222     /* Assign extension images */
223     $posiximg = "<input type='image' class='center' src='images/select_groups.png'
224                  name='group_group_edit_%KEY%' alt='P'  title='"._("Posix")  ."'>";
225     $mailimg  = "<input type='image' class='center' src='images/mailto.png'
226                  name='mailgroup_group_edit_%KEY%' alt='M'  title='"._("Mail")   ."'>";
227     $sambaimg = "<input type='image'  class='center' src='images/select_winstation.png'
228                  name='group_group_edit_%KEY%' alt='S'  title='"._("Samba")  ."'>";
229     $applimg  = "<input type='image'  class='center' src='images/select_application.png'
230                  name='appgroup_group_edit_%KEY%' alt='A'  title='"._("Application")."'>";
231     $phoneimg = "<input type='image'  class='center' src='images/select_phone.png'
232                  name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone")  ."'>";
233     $envimg   = "<input type='image'  class='center' src='images/smallenv.png'
234                  name='environment_group_edit_%KEY%' alt='E' title='"._("Environment")  ."'>";
236     // Space
237     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
239     // User and Template  Images
240     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
242     $ui = get_userinfo();
244     // Test Every Entry and generate divlist Array
245     foreach($groups as $key => $val){
246     
247       /* Create action icons - copy & paste icons */
248       $acl = $ui->get_permissions($val['dn'],"groups/group");
249       $acl_all= $ui->has_complete_category_acls($val['dn'],"groups");
251       $actions= "";
252       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
253         $actions.= "<input class='center' type='image'
254           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
255         $actions.= "<input class='center' type='image'
256           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
257       }
259       /* Add edit icon */
260       $actions.= "<input class='center' type='image'
261         src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
263       /* Add snapshot functionality */
264       if(preg_match("/(c.*w|w.*c)/", $acl_all)){
265         $actions.= $this->GetSnapShotActions($val['dn']);
266       }
268       if(preg_match("/d/",$acl)){
269         $actions.= "<input class='center' type='image'
270           src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
271       }
274       $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
276       if(isset($val['objectClass'])){
277         if(in_array("posixGroup",           $val['objectClass']))   $posix = $posiximg;
278         if(in_array("gosaMailAccount",      $val['objectClass']))   $mail  = $mailimg;
279         if(in_array("sambaGroupMapping",    $val['objectClass']))   $samba = $sambaimg;
280         if(in_array("gosaApplicationGroup", $val['objectClass']))   $appl  = $applimg;
281         if(in_array("goFonPickupGroup",     $val['objectClass']))   $phone = $phoneimg;
282         if(in_array("gotoEnvironment",      $val['objectClass']))   $enviro= $envimg;
283       }
285       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
287       if(!isset($val['description'][0])){
288         $desc = "";
289       }else{
290         $desc = " - [ ".$val['description'][0]." ]";
291       }
293       /* FAIrelease tag from groupApplications */
294       if(isset($val['FAIrelease'][0])){
295         $desc .= " (".$val['FAIrelease'][0].")";
296       }
298       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
299           "attach" => "style='width:20px;'");
301       /* Cutted objects should be displayed in light grey */
302       $display = $val['cn'][0].$desc;
303       if($this->parent->CopyPasteHandler){
304         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
305           if($queue_data['dn'] == $val['dn']) {
306             $display = "<font color='#999999'>".$display."</font>";
307             break;
308           }
309         }
310       }
312       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
313       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
314       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone),     "attach" => "style='width:136px;'");
315       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
317       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
318     }
320     /* Create summary string for list footer */
321     $num_deps=0;
322     if(!$this->SubSearch){
323       $num_deps = count($this->Added_Departments);
324     }
325     $num_grps = count($groups);
327     $num_grp_str = _("Number of listed groups");
328     $num_dep_str = _("Number of listed departments");
330     $str = "<img class='center' src='images/select_groups.png'
331               title='".$num_grp_str."' alt='".$num_grp_str."'>&nbsp;".$num_grps."&nbsp;&nbsp;&nbsp;&nbsp;";
332     $str.= "<img class='center' src='images/folder.png'
333               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
335     $this->set_List_Bottom_Info($str);
337   }
339   function Save()
340   {
341     MultiSelectWindow :: Save();  
342   }
344   function save_object()
345   {
346     /* Save automatic created POSTs like regex, checkboxes */
347     MultiSelectWindow::save_object();   
348   }
350 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
351 ?>