80ed7d304fddc945c79ac2a7c2b75e9efe86553a
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','modifyTimestamp');
26 var $aclResolver = NULL;
28 var $referenceFilters = array();
29 var $objectList ="";
30 var $modifyTimestamp = "";
32 function reference (&$config, $dn= NULL, $parent = NULL)
33 {
34 // Init the plugin
35 plugin::plugin($config,$dn,$parent);
37 // Try to read the 'modifyTimestamp' - this has to be done separately.
38 $ldap = $this->config->get_ldap_link();
39 $ldap->cd($this->config->current['BASE']);
40 $ldap->cat($this->dn, array('modifyTimestamp'));
41 if($ldap->count()){
42 $attrs = $ldap->fetch();
43 if(isset($attrs['modifyTimestamp'][0])){
44 $this->modifyTimestamp = $attrs['modifyTimestamp'][0];
45 }
46 }
48 // Initialize the ACL-resolver
49 $this->aclResolver = new aclResolver($this->config, $this->dn, $this);
51 // References we may have to other objects.
52 $this->referenceFilters = array();
54 // Check for group membership
55 $this->referenceFilters[] = array(
56 'filter' => "(&(objectClass=posixGroup)(memberUid={$this->uid}))",
57 'attrs' => array('cn' => _("Name"),'description' => _("Description")),
58 'msg' => _("Group membership"));
60 // Check for group membership in rfc 2307 bis mode
61 $this->referenceFilters[] = array(
62 'filter' => "(&(objectClass=posixGroup)(member=".normalizeLdap($this->dn)."))",
63 'attrs' => array('cn' => _("Name"),'description' => _("Description")),
64 'msg' => _("Group membership")." (rfc 2307 bis)");
66 // Check for role membership
67 $this->referenceFilters[] = array(
68 'filter' => "(&(objectClass=organizationalRole)(roleOccupant=".normalizeLdap($this->dn)."))",
69 'attrs' => array('cn' => _("Name"),'description' => _("Description")),
70 'msg' => _("Role membership"));
72 // Check for objectGroup membership
73 $this->referenceFilters[] = array(
74 'filter' => "(&(objectClass=gosaGroupOfNames)(member=".normalizeLdap($this->dn)."))",
75 'attrs' => array('cn' => _("Name"),'description' => _("Description")),
76 'msg' => _("Object group membership"));
78 // Check for department manager
79 $this->referenceFilters[] = array(
80 'filter' => "(&(objectClass=gosaDepartment)(manager=".normalizeLdap($this->dn)."))",
81 'attrs' => array('ou' => _("Name"),'description' => _("Description")),
82 'msg' => _("Department manager"));
84 // Check for user manager
85 $this->referenceFilters[] = array(
86 'filter' => "(&(objectClass=gosaAccount)(manager=".normalizeLdap($this->dn)."))",
87 'attrs' => array('givenName' => _("Given name"),'sn' => _("Surname"),'uid'=>_("Uid")),
88 'msg' => _("User manager"));
90 // Go through filters and detect possible references
91 $ldap = $this->config->get_ldap_link();
92 $ldap->cd($this->config->current['BASE']);
93 $str = "";
94 foreach($this->referenceFilters as $filter){
95 $ldap->search($filter['filter'], array_keys($filter['attrs']));
96 if(!$ldap->success()){
97 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_VIEW, get_class()));
98 }elseif($ldap->count()){
99 $list = new sortableListing();
100 $list->setDeleteable(false);
101 $list->setEditable(false);
102 $list->setWidth("100%");
103 $list->setHeight("80px");
104 $list->setHeader(array_values($filter['attrs']));
105 $list->setDefaultSortColumn(0);
106 $list->setAcl('rwcdm');
108 $data = array();
109 while($attrs = $ldap->fetch()){
111 $entry = array();
112 foreach($filter['attrs'] as $name => $desc){
113 $$name = "";
114 if(isset($attrs[$name][0])) $$name = $attrs[$name][0];
115 $entry['data'][] = $$name;
116 }
117 $data[] = $entry;
118 }
119 $list->setListData($data, $data);
121 $list->update();
122 $str .= "<h3>".$filter['msg']."</h3>";
123 $str .= $list->render();
124 $str .= "<div class='v-spacer'></div>";
125 }
126 }
127 $this->objectList = $str;
128 }
130 function execute()
131 {
132 // Mark plugin as viewed
133 plugin::execute();
135 // Show ldif viewer
136 if(isset($_POST['viewLdif'])){
137 $this->dialog = new ldifViewer($this->config, $this->dn);
138 }
139 if(isset($_POST['cancelLdifViewer'])) $this->dialog = NULL;
140 if($this->dialog instanceOf ldifViewer){
141 return($this->dialog->execute());
142 }
144 $smarty = get_smarty();
146 // Assign permissions
147 $tmp = $this->plInfo();
148 $ui = get_userinfo();
150 $category = preg_replace("/\/.*$/", "", $this->acl_category);
151 $smarty->assign('aclREAD', preg_match("/r/",$ui->get_category_permissions($this->dn, 'acl')));
152 $smarty->assign('completeACL', $ui->has_complete_category_acls($this->dn, $category));
153 $smarty->assign('someACL', $ui->get_category_permissions($this->dn, $category));
155 // Convert the modifyTimestamp to a human readable value
156 $tz = timezone::get_default_timezone();
157 $smarty->assign('modifyTimestamp', date('d.m.Y H:i:s', strtotime($this->modifyTimestamp)));
159 $smarty->assign('objectList', $this->objectList);
160 $smarty->assign("acls",$this->aclResolver->getReadableACL());
161 $smarty->assign("usePrototype", "true");
162 session::set('autocomplete', $this->aclResolver);
163 return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
164 }
165 }
167 ?>