Code

Fixed base selection.
[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 = 70;
49     if($this->parent->snapshotEnabled()){
50       $action_col_size += 38;
51     }
53     /* set Page header */
54     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
55     $this->AddHeader(array("string"=>_("Groupname / Department")));
56     $this->AddHeader(array("string"=>_("Properties"),"attach"=>"style='width:136px;'"));
57     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
59     /*                  Text        ,Value    ,Name         ,Is selected */
60     $this->AddCheckBox("ShowPrimaryGroups",     _("Select to see groups that are primary groups of users"),          _("Show primary groups"),      true);
61     $this->AddCheckBox("ShowSambaGroups",       _("Select to see groups that have samba groups mappings"),          _("Show samba groups"),      true);
62     $this->AddCheckBox("ShowApplicationGroups", _("Select to see groups that have applications configured"),        _("Show application groups"),true);
63     $this->AddCheckBox("ShowMailGroups",        _("Select to see groups that have mail settings"),                  _("Show mail groups"),       true);
64     $this->AddCheckBox("ShowFunctionalGroups",  _("Select to see normal groups that have only functional aspects"), _("Show functional groups"), true);
65     $this->AddCheckBox(SEPERATOR);
67     /* Add SubSearch checkbox */    
68     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
70     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
71     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
72     $this->AddRegex   ("UserRegex", _("User name of which groups are shown"),         "*" , false, "images/search_user.png");
73   }
76   function GenHeader()
77   {
78     /* Prepare departments,
79        which are shown in the listbox on top of the listbox
80      */
81     $options= "";
84     
85     /* Get all departments within this subtree */
86     $base = $this->config->current['BASE'];
87     $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
88                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
90     /* Load possible departments */
91     $ui= get_userinfo();
92     $tdeps= $ui->get_module_departments("groups");
94     $ids = $this->config->idepartments;
96     foreach($deps as $dep){
97       if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
99         $value = $ids[$dep['dn']];
100         if ($this->selectedBase == $dep['dn']){
101           $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
102         } else {
103           $options.= "<option value='".$dep['dn']."'>$value</option>";
104         }
105       }
106     }
108     $acls   = $ui->get_permissions($this->selectedBase,"groups/group");
109     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"groups");
111     /* Get copy & paste icon */
112     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
113       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
114     }else{
115       $Copy_Paste ="";
116     }
118     // Managment
119     $listhead = "
120       <div style='background:#F0F0F9;padding:5px;'>".
121       " <input type='image' class='center' src='images/list_root.png' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
122       " <input type='image' class='center' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
123       " <input type='image' class='center' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
124       " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='".        _("Submit")."'>&nbsp;".
125       " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;";
127     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
128       $listhead .= $this->get_snapshot_header($this->selectedBase);
129     }else{
130       $listhead .= "<img class='center' src='images/restore_grey.png' alt=''>&nbsp;";
131     }
133     if(preg_match("/c/",$acls)) {
134       $listhead.=" <input type='image' class='center' src='images/list_new_group.png' 
135         title='"._("Create new group")."' alt='"._("New")."' name='group_new'>&nbsp;";
136     }
138     $listhead.=      $Copy_Paste.
139       " <img class='center' src='images/list_seperator.png' alt='' height='16' width='1'>&nbsp;".
140       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
141       " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
142       "'>&nbsp;".
143       "</div>";
145     $this->SetListHeader($listhead);
146   }
148   function execute()
149   {
150     $this->ClearElementsList();
151     $this->GenHeader();
152   }
154   function setEntries($groups)
155   {
156     // Defining Links
157     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
159     // image Buttons
160     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
161     $userimg  = "<img class='center' src='images/select_groups.png' alt='User'    title='%s'>";
163     /* Dynamic action col, depending on snapshot icons */
164     $action_col_size = 70;
165     if($this->parent->snapshotEnabled()){
166       $action_col_size += 38;
167     }
169     /* Assign extension images */
170     $posiximg = "<input type='image' class='center' src='images/select_groups.png'
171                  name='group_group_edit_%KEY%' alt='P'  title='"._("Posix")  ."'>";
172     $mailimg  = "<input type='image' class='center' src='images/mailto.png'
173                  name='mailgroup_group_edit_%KEY%' alt='M'  title='"._("Mail")   ."'>";
174     $sambaimg = "<input type='image'  class='center' src='images/select_winstation.png'
175                  name='group_group_edit_%KEY%' alt='S'  title='"._("Samba")  ."'>";
176     $applimg  = "<input type='image'  class='center' src='images/select_application.png'
177                  name='appgroup_group_edit_%KEY%' alt='A'  title='"._("Application")."'>";
178     $phoneimg = "<input type='image'  class='center' src='images/select_phone.png'
179                  name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone")  ."'>";
180     $envimg   = "<input type='image'  class='center' src='images/smallenv.png'
181                  name='environment_group_edit_%KEY%' alt='E' title='"._("Environment")  ."'>";
183     // Space
184     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
186     // User and Template  Images
187     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
189     $ui = get_userinfo();
191     // Test Every Entry and generate divlist Array
192     foreach($groups as $key => $val){
193     
194       /* Create action icons - copy & paste icons */
195       $acl = $ui->get_permissions($val['dn'],"groups/group");
196       $acl_all= $ui->has_complete_category_acls($val['dn'],"groups");
198       $actions= "";
199       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
200         $actions.= "<input class='center' type='image'
201           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
202         $actions.= "<input class='center' type='image'
203           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
204       }
206       /* Add edit icon */
207       $actions.= "<input class='center' type='image'
208         src='images/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
210       /* Add snapshot functionality */
211       if(preg_match("/(c.*w|w.*c)/", $acl_all)){
212         $actions.= $this->GetSnapShotActions($val['dn']);
213       }
215       if(preg_match("/d/",$acl)){
216         $actions.= "<input class='center' type='image'
217           src='images/edittrash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
218       }
221       $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
223       if(isset($val['objectClass'])){
224         if(in_array("posixGroup",           $val['objectClass']))   $posix = $posiximg;
225         if(in_array("gosaMailAccount",      $val['objectClass']))   $mail  = $mailimg;
226         if(in_array("sambaGroupMapping",    $val['objectClass']))   $samba = $sambaimg;
227         if(in_array("gosaApplicationGroup", $val['objectClass']))   $appl  = $applimg;
228         if(in_array("goFonPickupGroup",     $val['objectClass']))   $phone = $phoneimg;
229         if(in_array("gotoEnvironment",      $val['objectClass']))   $enviro= $envimg;
230       }
232       $title = "title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'";
234       if(!isset($val['description'][0])){
235         $desc = "";
236       }else{
237         $desc = " - [ ".$val['description'][0]." ]";
238       }
240       /* FAIrelease tag from groupApplications */
241       if(isset($val['FAIrelease'][0])){
242         $desc .= " (".$val['FAIrelease'][0].")";
243       }
245       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
246       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
247       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone),     "attach" => "style='width:136px;'");
248       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
250       $this->AddElement(array($field1,$field2,$field3,$field4));
251     }
252   }
254   function Save()
255   {
256     MultiSelectWindow :: Save();  
257   }
259   function save_object()
260   {
261     /* Save automatic created POSTs like regex, checkboxes */
262     MultiSelectWindow::save_object();   
263   }
265 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
266 ?>