File: class_reference.inc

package info (click to toggle)
gosa 2.7.4%2Breloaded3-16
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 38,716 kB
  • sloc: php: 87,789; perl: 14,364; xml: 4,987; javascript: 4,127; sh: 887; pascal: 306; sql: 263; python: 162; makefile: 76
file content (167 lines) | stat: -rw-r--r-- 6,891 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/*
 * This code is part of GOsa (http://www.gosa-project.org)
 * Copyright (C) 2003-2008 GONICUS GmbH
 *
 * ID: $$Id: class_reference.inc 19290 2010-07-29 16:21:26Z cajus $$
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

class reference extends plugin
{
    var $attributes= array('uid','modifyTimestamp');
    var $aclResolver = NULL;

    var $referenceFilters = array();
    var $objectList ="";
    var $modifyTimestamp = "";

    function __construct(&$config, $dn= NULL, $parent = NULL)
    {
        // Init the plugin
        plugin::__construct($config,$dn,$parent);

        // Try to read the 'modifyTimestamp' - this has to be done separately. 
        $ldap = $this->config->get_ldap_link();
        $ldap->cd($this->config->current['BASE']);
        $ldap->cat($this->dn, array('modifyTimestamp'));
        if($ldap->count()){
            $attrs = $ldap->fetch();
            if(isset($attrs['modifyTimestamp'][0])){
                $this->modifyTimestamp = $attrs['modifyTimestamp'][0];
            }
        }

        // Initialize the ACL-resolver
        $this->aclResolver = new aclResolver($this->config, $this->dn, $this);

        // References we may have to other objects.
        $this->referenceFilters = array();

        // Check for group membership
        $this->referenceFilters[] = array(
            'filter' => "(&(objectClass=posixGroup)(memberUid={$this->uid}))",
            'attrs'  => array('cn' => _("Name"),'description' => _("Description")),
            'msg'    => _("Group membership"));

        // Check for group membership in rfc 2307 bis mode
        $this->referenceFilters[] = array(
            'filter' => "(&(objectClass=posixGroup)(member=".normalizeLdap($this->dn)."))",
            'attrs'  => array('cn' => _("Name"),'description' => _("Description")),
            'msg'    => _("Group membership")." (rfc 2307 bis)");

        // Check for role membership
        $this->referenceFilters[] = array(
            'filter' => "(&(objectClass=organizationalRole)(roleOccupant=".normalizeLdap($this->dn)."))",
            'attrs'  => array('cn' => _("Name"),'description' => _("Description")),
            'msg'    => _("Role membership"));

        // Check for objectGroup membership
        $this->referenceFilters[] = array(
            'filter' => "(&(objectClass=gosaGroupOfNames)(member=".normalizeLdap($this->dn)."))",
            'attrs'  => array('cn' => _("Name"),'description' => _("Description")),
            'msg'    => _("Object group membership"));

        // Check for department manager 
        $this->referenceFilters[] = array(
            'filter' => "(&(objectClass=gosaDepartment)(manager=".normalizeLdap($this->dn)."))",
            'attrs'  => array('ou' => _("Name"),'description' => _("Description")),
            'msg'    => _("Department manager"));

        // Check for user manager 
        $this->referenceFilters[] = array(
            'filter' => "(&(objectClass=gosaAccount)(manager=".normalizeLdap($this->dn)."))",
            'attrs'  => array('givenName' => _("Given name"),'sn' => _("Surname"),'uid'=>_("UID")),
            'msg'    => _("User manager"));

        // Go through filters and detect possible references  
        $ldap = $this->config->get_ldap_link();
        $ldap->cd($this->config->current['BASE']);
        $str = "";
        foreach($this->referenceFilters as $filter){
            $ldap->search($filter['filter'], array_keys($filter['attrs']));
            if(!$ldap->success()){
                msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_VIEW, get_class()));
            }elseif($ldap->count()){
                $list = new sortableListing();
                $list->setDeleteable(false);
                $list->setEditable(false);
                $list->setWidth("100%");
                $list->setHeight("80px");
                $list->setHeader(array_values($filter['attrs']));
                $list->setDefaultSortColumn(0);
                $list->setAcl('rwcdm');

                $data = array();
                while($attrs = $ldap->fetch()){

                    $entry = array();
                    foreach($filter['attrs'] as $name => $desc){
                        $$name = "";
                        if(isset($attrs[$name][0])) $$name = $attrs[$name][0];
                        $entry['data'][] = $$name;
                    }
                    $data[] = $entry;
                }
                $list->setListData($data, $data);

                $list->update();    
                $str .= "<h3>".$filter['msg']."</h3>";
                $str .= $list->render();
                $str .= "<div class='v-spacer'></div>";
            }
        }
        $this->objectList = $str;
    }

    function execute()
    {
        // Mark plugin as viewed
        plugin::execute();

        // Show ldif viewer
        if(isset($_POST['viewLdif'])){
            $this->dialog = new ldifViewer($this->config, $this->dn);
        }
        if(isset($_POST['cancelLdifViewer'])) $this->dialog = NULL;
        if($this->dialog instanceOf ldifViewer){
            return($this->dialog->execute());
        }

        $smarty = get_smarty();        

        // Assign permissions
        $tmp = $this->plInfo();
        $ui = get_userinfo();

        $category = preg_replace("/\/.*$/", "", $this->acl_category);
        $smarty->assign('aclREAD',  preg_match("/r/",$ui->get_category_permissions($this->dn, 'acl')));
        $smarty->assign('completeACL',  $ui->has_complete_category_acls($this->dn, $category)); 
        $smarty->assign('someACL',      $ui->get_category_permissions($this->dn, $category));
        
        // Convert the modifyTimestamp to a human readable value
        $tz = timezone::get_default_timezone();
        $smarty->assign('modifyTimestamp', set_post(date('d.m.Y H:i:s', strtotime($this->modifyTimestamp))));

        $smarty->assign('objectList', $this->objectList);
        $smarty->assign("acls",$this->aclResolver->getReadableACL());

        session::set('autocomplete', $this->aclResolver);
        return ($smarty->fetch (get_template_path('contents.tpl', TRUE, dirname(__FILE__))));
    }
}

?>