1 | <?php |
---|
2 | /** |
---|
3 | * @package Galaxia |
---|
4 | * @author Mauricio Luiz Viani - viani@celepar.pr.gov.br |
---|
5 | */ |
---|
6 | |
---|
7 | class 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 = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP'); |
---|
32 | $this->user_context = $tmpLDAP->getUserContext(); |
---|
33 | $this->group_context = $tmpLDAP->getGroupContext(); |
---|
34 | |
---|
35 | $this->ds = &$GLOBALS['workflow']['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 $GLOBALS['workflow']['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 = &$GLOBALS['workflow']['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 | |
---|
158 | for ($idx=0; $idx<count($security_equals); $idx++) |
---|
159 | { |
---|
160 | $name = $this->id2name((int)$security_equals[$idx]); |
---|
161 | $members[] = Array('account_id' => (int)$security_equals[$idx], 'account_name' => $name); |
---|
162 | } |
---|
163 | |
---|
164 | return $members; |
---|
165 | } |
---|
166 | /** |
---|
167 | * Return accounts from location |
---|
168 | * |
---|
169 | * @param $location |
---|
170 | * @param $required |
---|
171 | * @param $app |
---|
172 | * @return void |
---|
173 | * @access public |
---|
174 | */ |
---|
175 | function get_ids_for_location($location, $required, $app = False) |
---|
176 | { |
---|
177 | |
---|
178 | $GLOBALS['ajax']->db->select('phpgw_acl',array('acl_account','acl_rights'),array( |
---|
179 | 'acl_appname' => $app, |
---|
180 | 'acl_location' => $location, |
---|
181 | ),__LINE__,__FILE__); |
---|
182 | |
---|
183 | $accounts = false; |
---|
184 | while ($GLOBALS['ajax']->db->next_record()) |
---|
185 | { |
---|
186 | if (!!($GLOBALS['ajax']->db->f('acl_rights') & $required)) |
---|
187 | { |
---|
188 | $accounts[] = (int) $GLOBALS['ajax']->db->f('acl_account'); |
---|
189 | } |
---|
190 | } |
---|
191 | return $accounts; |
---|
192 | } |
---|
193 | |
---|
194 | } |
---|
195 | ?> |
---|