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"));
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")." (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"));
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"));
65 }
67 function execute()
68 {
69 // Mark plugin as viewed
70 plugin::execute();
72 // Go through filters and detect possible references
73 $ldap = $this->config->get_ldap_link();
74 $ldap->cd($this->config->current['BASE']);
75 $str = "";
76 foreach($this->referenceFilters as $filter){
77 $ldap->search($filter['filter'], array_keys($filter['attrs']));
78 if(!$ldap->success()){
79 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_VIEW, get_class()));
80 }elseif($ldap->count()){
81 $list = new sortableListing();
82 $list->setDeleteable(false);
83 $list->setEditable(false);
84 $list->setWidth("100%");
85 $list->setHeight("80px");
86 $list->setHeader(array_values($filter['attrs']));
87 $list->setDefaultSortColumn(0);
88 $list->setAcl('rwcdm');
90 $data = array();
91 while($attrs = $ldap->fetch()){
93 $entry = array();
94 foreach($filter['attrs'] as $name => $desc){
95 $$name = "";
96 if(isset($attrs[$name][0])) $$name = $attrs[$name][0];
97 $entry['data'][] = $$name;
98 }
99 $data[] = $entry;
100 }
101 $list->setListData($data, $data);
103 $list->update();
104 $str .= "<h3>".$filter['msg']."</h3>";
105 $str .= $list->render();
106 }
107 }
109 $smarty = get_smarty();
110 $smarty->assign('objectList', $str);
111 $smarty->assign("acls",$this->aclResolver->getReadableACL());
113 return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
114 }
117 }
119 ?>