Code

641f06192f7388078065296dd2ce12e7003c1814
[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"));
78         // Go through filters and detect possible references  
79         $ldap = $this->config->get_ldap_link();
80         $ldap->cd($this->config->current['BASE']);
81         $str = "";
82         foreach($this->referenceFilters as $filter){
83             $ldap->search($filter['filter'], array_keys($filter['attrs']));
84             if(!$ldap->success()){
85                 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_VIEW, get_class()));
86             }elseif($ldap->count()){
87                 $list = new sortableListing();
88                 $list->setDeleteable(false);
89                 $list->setEditable(false);
90                 $list->setWidth("100%");
91                 $list->setHeight("80px");
92                 $list->setHeader(array_values($filter['attrs']));
93                 $list->setDefaultSortColumn(0);
94                 $list->setAcl('rwcdm');
96                 $data = array();
97                 while($attrs = $ldap->fetch()){
99                     $entry = array();
100                     foreach($filter['attrs'] as $name => $desc){
101                         $$name = "";
102                         if(isset($attrs[$name][0])) $$name = $attrs[$name][0];
103                         $entry['data'][] = $$name;
104                     }
105                     $data[] = $entry;
106                 }
107                 $list->setListData($data, $data);
109                 $list->update();    
110                 $str .= "<h3>".$filter['msg']."</h3>";
111                 $str .= $list->render();
112                 $str .= "<div class='v-spacer'></div>";
113             }
114         }
115         $this->objectList = $str;
116     }
118     function execute()
119     {
120         // Mark plugin as viewed
121         plugin::execute();
123         $smarty = get_smarty();        
124         $smarty->assign('objectList', $this->objectList);
125         $smarty->assign("acls",$this->aclResolver->getReadableACL());
126         $smarty->assign("usePrototype", "true");
127         session::set('autocomplete', $this->aclResolver);
128         return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
129     }
132 ?>