Code

829c12724bea796b0d41abc6341044aea4688ccb
[gosa.git] / gosa-core / plugins / generic / references / class_reference.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 reference extends plugin
24 {
25     var $attributes= array('uid');
26     var $aclResolver = NULL;
28     var $referenceFilters = array();
29     var $objectList ="";
31     function reference (&$config, $dn= NULL, $parent = NULL)
32     {
33         // Init the plugin
34         plugin::plugin($config,$dn,$parent);
36         // Initialize the ACL-resolver
37         $this->aclResolver = new aclResolver($this->config, $this->dn, $this);
39         // References we may have to other objects.
40         $this->referenceFilters = array();
42         // Check for group membership
43         $this->referenceFilters[] = array(
44             'filter' => "(&(objectClass=posixGroup)(memberUid={$this->uid}))",
45             'attrs'  => array('cn' => _("Name"),'description' => _("Description")),
46             'msg'    => _("Group membership"));
48         // Check for group membership in rfc 2307 bis mode
49         $this->referenceFilters[] = array(
50             'filter' => "(&(objectClass=posixGroup)(member=".normalizeLdap($this->dn)."))",
51             'attrs'  => array('cn' => _("Name"),'description' => _("Description")),
52             'msg'    => _("Group membership")." (rfc 2307 bis)");
54         // Check for role membership
55         $this->referenceFilters[] = array(
56             'filter' => "(&(objectClass=organizationalRole)(roleOccupant=".normalizeLdap($this->dn)."))",
57             'attrs'  => array('cn' => _("Name"),'description' => _("Description")),
58             'msg'    => _("Role membership"));
60         // Check for objectGroup membership
61         $this->referenceFilters[] = array(
62             'filter' => "(&(objectClass=gosaGroupOfNames)(member=".normalizeLdap($this->dn)."))",
63             'attrs'  => array('cn' => _("Name"),'description' => _("Description")),
64             'msg'    => _("Object group membership"));
66         // Check for department manager 
67         $this->referenceFilters[] = array(
68             'filter' => "(&(objectClass=gosaDepartment)(manager=".normalizeLdap($this->dn)."))",
69             'attrs'  => array('ou' => _("Name"),'description' => _("Description")),
70             'msg'    => _("Department manager"));
72         // Check for user manager 
73         $this->referenceFilters[] = array(
74             'filter' => "(&(objectClass=gosaAccount)(manager=".normalizeLdap($this->dn)."))",
75             'attrs'  => array('givenName' => _("Given name"),'sn' => _("Surname"),'uid'=>_("Uid")),
76             'msg'    => _("User manager"));
77     }
79     function execute()
80     {
81         // Mark plugin as viewed
82         plugin::execute();
84         // Go through filters and detect possible references  
85         $ldap = $this->config->get_ldap_link();
86         $ldap->cd($this->config->current['BASE']);
87         $str = "";
88         foreach($this->referenceFilters as $filter){
89             $ldap->search($filter['filter'], array_keys($filter['attrs']));
90             if(!$ldap->success()){
91                 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_VIEW, get_class()));
92             }elseif($ldap->count()){
93                 $list = new sortableListing();
94                 $list->setDeleteable(false);
95                 $list->setEditable(false);
96                 $list->setWidth("100%");
97                 $list->setHeight("80px");
98                 $list->setHeader(array_values($filter['attrs']));
99                 $list->setDefaultSortColumn(0);
100                 $list->setAcl('rwcdm');
102                 $data = array();
103                 while($attrs = $ldap->fetch()){
105                     $entry = array();
106                     foreach($filter['attrs'] as $name => $desc){
107                         $$name = "";
108                         if(isset($attrs[$name][0])) $$name = $attrs[$name][0];
109                         $entry['data'][] = $$name;
110                     }
111                     $data[] = $entry;
112                 }
113                 $list->setListData($data, $data);
115                 $list->update();    
116                 $str .= "<h3>".$filter['msg']."</h3>";
117                 $str .= $list->render();
118                 $str .= "<div class='v-spacer'></div>";
119             }
120         }
122         $smarty = get_smarty();        
123         $smarty->assign('objectList', $str);
124         $smarty->assign("acls",$this->aclResolver->getReadableACL());
125         $smarty->assign("usePrototype", "true");
126         return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
127     }
132 ?>