source: trunk/workflow/inc/engine/class.ajax_ldap.inc.php @ 7655

Revision 7655, 4.6 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Melhorias de performance no codigo do Expresso.

  • Property svn:executable set to *
Line 
1<?php
2        /**
3        * @package Galaxia
4        * @author Mauricio Luiz Viani - viani@celepar.pr.gov.br
5        */
6
7class ajax_ldap
8{
9        /**
10        * @var object $ds data source
11        * @access public
12        */
13        var $ds;
14        /**
15        * @var $user_context
16        * @access public
17        */
18        var $user_context  = '';
19        /**
20        * @var $group_context
21        * @access public
22        */
23        var $group_context = '';
24        /**
25        *
26        * @return void
27        * @access public
28        */
29        function ajax_ldap()
30        {
31                $tmpLDAP = &Factory::getInstance('WorkflowLDAP');
32                $this->user_context  = $tmpLDAP->getUserContext();
33                $this->group_context = $tmpLDAP->getGroupContext();
34
35                $this->ds =& Factory::getInstance('WorkflowObjects')->getLDAP();
36        }
37
38        /**
39        * @param integer $account_id
40        * @param $wich
41        * @return
42        * @access public
43        */
44        function id2name($account_id,$which='account_lid')
45        {
46                if ($which == 'account_lid' || $which == 'account_type')        // groups only support account_lid and account_type
47                {
48                        $allValues = array();
49                        $sri = ldap_search($this->ds, $this->group_context, '(&(gidnumber=' . (int)$account_id . ')(phpgwaccounttype=g))');
50                        $allValues = ldap_get_entries($this->ds, $sri);
51
52                        $attr = $which == 'account_lid' ? 'cn' : 'phpgwaccounttype';
53                        if (@$allValues[0]['cn'][0])
54                        {
55                                return $allValues[0]['cn'][0];
56                        }
57                }
58                $to_ldap = array(
59                                'account_lid'   => 'uid',
60                                'account_email' => 'mail',
61                                'account_firstname' => 'surname',
62                                'account_lastname'  => 'cn',
63                                'account_type'      => 'phpgwaccounttype',
64                );
65                if (!isset($to_ldap[$which])) return False;
66
67                $allValues = array();
68                $sri = ldap_search($this->ds, $this->user_context, '(&(uidnumber=' . (int)$account_id . ')(phpgwaccounttype=u))');
69                $allValues = ldap_get_entries($this->ds, $sri);
70
71                if (@$allValues[0][$to_ldap[$which]][0])
72                {
73                        return $allValues[0][$to_ldap[$which]][0];
74                }
75                return False;
76        }
77
78        /**
79        * Get full account data from account id
80        * @return array the whole config-array for that app
81        * @access public
82        */
83        function id2fullname($account_id)
84    {
85                return Factory::getInstance('WorkflowLDAP')->getName($account_id);
86    }
87
88    /**
89        * Close the ldap connection
90        * @return void
91        * @access public
92        */
93    function close()
94    {
95        ldap_close($this->ds);
96    }
97
98    /**
99    * Return groups IDs and names of a given user
100    * @param $accountID ID of the user that we want to know the groups
101        * @return mixed Array containing the groups informations or false in case no group was found
102        * @access public
103        */
104    function membership($accountID = '')
105        {
106                if ($accountID == '')
107                        $accountID = $_SESSION['phpgw_info']['workflow']['account_id'];
108
109                $ldap =& Factory::getInstance('WorkflowLDAP');
110                if (count($output = $ldap->getUserGroups($accountID)) == 0)
111                        return false;
112                else
113                        return $output;
114        }
115        /**
116        * @param string $app
117        * @param string $required
118        * @param string $accountid
119        * @return mixed
120        * @access public
121        */
122        function get_location_list_for_id($app, $required, $accountid = '')
123        {
124                $GLOBALS['ajax']->db->select('phpgw_acl','acl_location,acl_rights',array(
125                                'acl_appname' => $app,
126                                'acl_account' => $accountid,
127                        ),__LINE__,__FILE__);
128
129                $locations = false;
130                while ($GLOBALS['ajax']->db->next_record())
131                {
132                        if ($GLOBALS['ajax']->db->f('acl_rights') & $required)
133                        {
134                                $locations[] = $GLOBALS['ajax']->db->f('acl_location');
135                        }
136                }
137                return $locations;
138        }
139        /**
140        * Return members from accountid
141        *
142        * @param integer $accountid
143        * @return mixed (boolean or array)
144        * @access public
145        */
146        function member($accountid = '')
147        {
148                        $security_equals = Array();
149                        $security_equals = $this->get_ids_for_location($accountid, 1, 'phpgw_group');
150
151                        if ($security_equals == False)
152                        {
153                                return False;
154                        }
155
156                        $members = array();
157            $security_equals_count = count($security_equals);
158
159                        for ($idx=0; $idx<$security_equals_count; ++$idx)
160                        {
161                                $name = $this->id2name((int)$security_equals[$idx]);
162                                $members[] = Array('account_id' => (int)$security_equals[$idx], 'account_name' => $name);
163                        }
164
165                        return $members;
166                }
167        /**
168         * Return accounts from location
169         *
170         * @param $location
171         * @param $required
172         * @param $app
173         * @return void
174         * @access public
175         */
176        function get_ids_for_location($location, $required, $app = False)
177        {
178
179                        $GLOBALS['ajax']->db->select('phpgw_acl',array('acl_account','acl_rights'),array(
180                                'acl_appname'  => $app,
181                                'acl_location' => $location,
182                                ),__LINE__,__FILE__);
183
184                        $accounts = false;
185                        while ($GLOBALS['ajax']->db->next_record())
186                        {
187                                if (!!($GLOBALS['ajax']->db->f('acl_rights') & $required))
188                                {
189                                        $accounts[] = (int) $GLOBALS['ajax']->db->f('acl_account');
190                                }
191                        }
192                        return $accounts;
193        }
194
195}
196?>
Note: See TracBrowser for help on using the repository browser.