Code

c53613cc0a6be36f0346481300ef83dba6fcd65d
[gosa.git] / trunk / gosa-core / plugins / admin / groups / class_divListGroup.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class divListGroup extends MultiSelectWindow
24 {
26   /* Current base */
27   var $selectedBase       = "";
28   var $departments        = array();
30   /* Regex */
31   var $Regex              = "*";
32   var $UserRegex          = "*";
34   /* CheckBoxes, to change default values modify $this->AddCheckBox */
35   var $ShowPrimaryGroups;
36   var $ShowSambaGroups;  
37   var $ShowApplicationGroups; 
38   var $ShowMailGroups;
39   var $ShowFunctionalGroups;
41   /* Subsearch checkbox */
42   var $SubSearch              = false;
44   var $parent             ;
45   var $ui                 ;
47   function divListGroup (&$config, &$parent)
48   {
49     MultiSelectWindow::MultiSelectWindow($config, "Groups", "groups");
50     
51     $this->parent       = &$parent;
52     $this->ui           = get_userinfo();
54     /* Set list strings */
55     $this->SetTitle(_("List of groups"));
56     $this->SetSummary(_("List of groups"));
57     $this->EnableAplhabet   (true);
59     /* Result page will look like a headpage */
60     $this->SetHeadpageMode();
61   
62     /* Disable buttonsm */
63     $this->EnableCloseButton(false);
64     $this->EnableSaveButton (false);
66     /* Dynamic action col, depending on snapshot icons */
67     $action_col_size = 80;
68     if($this->parent->snapshotEnabled()){
69       $action_col_size += 38;
70     }
72     /* Toggle all selected / deselected */
73     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
74                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
76     /* set Page header */
77     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
78     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
79     $this->AddHeader(array("string"=>_("Name")."&nbsp;/&nbsp;"._("Department")));
80     $this->AddHeader(array("string"=>_("Properties"),"attach"=>"style='width:136px;'"));
81     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
83     /*                  Text        ,Value    ,Name         ,Is selected */
84     $this->AddCheckBox("ShowPrimaryGroups",     _("Select to see groups that are primary groups of users"), 
85                                                   sprintf(_("Show %s"),_("primary groups")),     true);
86     $this->AddCheckBox("ShowSambaGroups",       msgPool::selectToView(_("samba groups mappings"),"enabled"), 
87                                                   sprintf(_("Show %s"),_("samba groups")),              true);
88     $this->AddCheckBox("ShowApplicationGroups", msgPool::selectToView(_("application settings"),"enabled"),     
89                                                   sprintf(_("Show %s"),_("application groups")),        true);
90     $this->AddCheckBox("ShowMailGroups",        msgPool::selectToView(_("mail settings"),"enabled"), 
91                                                   sprintf(_("Show %s"),_("mail groups")),               true);
92     $this->AddCheckBox("ShowFunctionalGroups",  _("Select to see normal groups that have only functional aspects"),
93                                                   sprintf(_("Show %s"),_("functional groups")),     true);
94     $this->AddCheckBox(SEPERATOR);
96     /* Add SubSearch checkbox */    
97     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"),msgPool::selectToView("","subsearch_small"), false);
99     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
100     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
101     $this->AddRegex   ("UserRegex", _("User name of which groups are shown"),         "*" , false, "images/lists/search-user.png");
102   }
105   function GenHeader()
106   {
107     /* Get all departments within this subtree */
108     $ui= get_userinfo();
109     $first = "";
110     $found = FALSE;
111     $base = $this->config->current['BASE'];
112     $options  = $this->create_department_list($this->module);
113   
114     /* Get acls */
115     $acl   = $ui->get_permissions($this->selectedBase,"groups/group");
117     /* Add default header */
118     $listhead = MultiSelectWindow::get_default_header();
119     
120     /* Add department selection */
121     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
122       " <input type='image' class='center' src='images/lists/submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
123       "'>&nbsp;";
125     /* Create Layers menu */
126     $s  = ".|"._("Actions")."|\n";
128     /* Append create options */
129     if(preg_match("/c/",$acl)) {
130       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
131         "&nbsp;"._("Create")."|\n";
132       $s.= "...|<input class='center' type='image' src='plugins/groups/images/new.png' alt=''>".
133         "&nbsp;"._("Group")."|group_new|\n";
134     }
136     /* Multiple options */
137     $s.= "..|---|\n";
138     $s.= "..|<img src='images/lists/edit.png' alt='' border='0' class='center'>".
139       "&nbsp;"._("Edit")."|"."multiple_edit|\n";
140     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
141       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
143     /* Add event tag */
144     if(class_available("DaemonEvent")){
145       $events  = DaemonEvent::get_event_types(USER_EVENT);
146       if(count($events['BY_CLASS'])){
147         $s.= "..|---|\n";
148         foreach($events['BY_CLASS'] as $name => $event){
149           $s.= "..|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|event_".$name."\n";
150         }
151       }
152     }
154     /* Add multiple copy & cut icons */
155     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"groups");
157     /* Add Copy & Paste header */
158     $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
159     
160     /* Add snapshot functionality */
161     $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
163     $this->SetDropDownHeaderMenu($s);
165     $this->SetListHeader($listhead);
166   }
168   function execute()
169   {
170     $this->ClearElementsList();
171     $this->GenHeader();
172   }
174   function setEntries($groups)
175   {
176     // image Buttons
177     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
178     $userimg  = "<img class='center' src='plugins/groups/images/groups.png' alt='User'    title='%s'>";
180     /* Dynamic action col, depending on snapshot icons */
181     $action_col_size = 80;
182     if($this->parent->snapshotEnabled()){
183       $action_col_size += 38;
184     }
186     /* Assign extension images */
187     $posiximg = "<input type='image' class='center' src='plugins/groups/images/groups.png'
188                  name='group_group_edit_%KEY%' alt='P'  title='"._("Posix")  ."'>";
189     $mailimg  = "<input type='image' class='center' src='plugins/groups/images/mail.png'
190                  name='mailgroup_group_edit_%KEY%' alt='M'  title='"._("Mail")   ."'>";
191     $sambaimg = "<input type='image'  class='center' src='plugins/groups/images/samba.png'
192                  name='group_group_edit_%KEY%' alt='S'  title='"._("Samba")  ."'>";
193     $applimg  = "<input type='image'  class='center' src='plugins/groups/images/menu.png'
194                  name='appgroup_group_edit_%KEY%' alt='A'  title='"._("Application")."'>";
195     $phoneimg = "<input type='image'  class='center' src='plugins/groups/images/asterisk.png'
196                  name='group_group_edit_%KEY%' alt='Ph' title='"._("Phone")  ."'>";
197     $envimg   = "<input type='image'  class='center' src='plugins/groups/images/environment.png'
198                  name='environment_group_edit_%KEY%' alt='E' title='"._("Environment")  ."'>";
200     // Space
201     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
203     // User and Template  Images
204     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
206     $ui = get_userinfo();
208     $ldap = $this->config->get_ldap_link();
210     // Test Every Entry and generate divlist Array
211     foreach($groups as $key => $val){
212         
213       /* Create action icons - copy & paste icons */
214       $acl = $ui->get_permissions($val['dn'],"groups/group");
215       $acl_all  = $ui->has_complete_category_acls($val['dn'],"groups");
217       $actions= "";
219       /* Add copy & cut functionality */
220       $actions.= $this->parent->get_copypaste_action($val['dn'],"groups","group");
222       /* Add edit icon */
223       $actions.= "<input class='center' type='image'
224         src='images/lists/edit.png' alt='"._("edit")."' name='group_edit_%KEY%' title='"._("Edit this entry")."'>";
226       /* Add snapshot functionality */
227       $actions.= $this->parent->get_snapshot_action($val['dn'],$this->module);
228   
229       if(preg_match("/d/",$acl)){
230         $actions.= "<input class='center' type='image'
231           src='images/lists/trash.png' alt='"._("delete")."' name='group_del_%KEY%' title='"._("Delete this entry")."'>";
232       }else{
233         $actions.= "<img class='center' src='images/empty.png' alt='&nbsp;'
234           title='"._("Not allowed")."'>";
235       }
237       $posix=$mail=$samba=$appl=$phone=$enviro=$empty;
239       /* Set ldap base to dn of this group */
240       $ldap->cd ($val['dn']);
242       /* Set ldap size limit to 1, because we only need one entry */
243       $ldap->set_size_limit(1);
245       /* Search for applications. */
246       $ldap->search("(objectClass=gotoMenuEntry)",array("dn"));
247       $entry = $ldap->fetch();
249       if (isset($entry['dn'])) {
250         $appl  = $applimg;
251       }
253       if(isset($val['objectClass'])){
254         if(in_array("posixGroup",           $val['objectClass']))   $posix = $posiximg;
255         if(in_array("gosaMailAccount",      $val['objectClass']))   $mail  = $mailimg;
256         if(in_array("sambaGroupMapping",    $val['objectClass']))   $samba = $sambaimg;
257         if(in_array("goFonPickupGroup",     $val['objectClass']))   $phone = $phoneimg;
258         if(in_array("gotoEnvironment",      $val['objectClass']))   $enviro= $envimg;
259       }
261       $title = "title='".preg_replace('/ /', '&nbsp;', LDAP::fix($val['dn']))."'";
263       if(!isset($val['description'][0])){
264         $desc = "";
265       }else{
266         $desc = " - [ ".$val['description'][0]." ]";
267       }
269       /* FAIrelease tag from groupApplications */
270       if(isset($val['FAIrelease'][0])){
271         $desc .= " (".$val['FAIrelease'][0].")";
272       }
274       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
275           "attach" => "style='width:20px;'");
277       /* Cutted objects should be displayed in light grey */
278       $display = $val['cn'][0].$desc;
279       if($this->parent->CopyPasteHandler){
280         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
281           if($queue_data['dn'] == $val['dn']) {
282             $display = "<font color='#999999'>".$display."</font>";
283             break;
284           }
285         }
286       }
288       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
289       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' ".$title);
290       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone),     "attach" => "style='width:136px;'");
291       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
293       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
294     }
296     /* Create summary string for list footer */
297     $num_deps=0;
298     if(!$this->SubSearch){
299       $num_deps = count($this->Added_Departments);
300     }
301     $num_grps = count($groups);
303     $num_grp_str = _("Number of listed groups");
304     $num_dep_str = _("Number of listed departments");
306     $str = "<img class='center' src='plugins/groups/images/groups.png'
307               title='".$num_grp_str."' alt='".$num_grp_str."'>&nbsp;".$num_grps."&nbsp;&nbsp;&nbsp;&nbsp;";
308     $str.= "<img class='center' src='images/lists/folder.png'
309               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
311     $this->set_List_Bottom_Info($str);
313   }
315   function Save()
316   {
317     MultiSelectWindow :: Save();  
318   }
320   function save_object()
321   {
322     /* Save automatic created POSTs like regex, checkboxes */
323     MultiSelectWindow::save_object();   
324   }
326 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
327 ?>