1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Class for basic operations with user accounts on LDAP to be used in activities only |
---|
5 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
6 | * @package Workflow |
---|
7 | * @subpackage local |
---|
8 | */ |
---|
9 | class wf_ldap |
---|
10 | { |
---|
11 | /** |
---|
12 | * @var $ds resource recurso |
---|
13 | * @access public |
---|
14 | */ |
---|
15 | var $ds; |
---|
16 | |
---|
17 | /** |
---|
18 | * @var $user_context string contexto do usuário |
---|
19 | * @access public |
---|
20 | */ |
---|
21 | var $user_context = ''; |
---|
22 | |
---|
23 | /** |
---|
24 | * @var $group_context string contexto do grupo |
---|
25 | * access public |
---|
26 | */ |
---|
27 | var $group_context = ''; |
---|
28 | |
---|
29 | /** |
---|
30 | * @var object $cachedLDAP Objeto da classe CachedLDAP |
---|
31 | * access private |
---|
32 | */ |
---|
33 | private $cachedLDAP; |
---|
34 | |
---|
35 | /** |
---|
36 | * Construtor da classe wf_ldap Inicializa a conexão com o LDAP |
---|
37 | * @return object |
---|
38 | * @access public |
---|
39 | */ |
---|
40 | function wf_ldap() |
---|
41 | { |
---|
42 | $tmpLDAP = Factory::getInstance('WorkflowLDAP'); |
---|
43 | $this->user_context = $tmpLDAP->getUserContext(); |
---|
44 | $this->group_context = $tmpLDAP->getGroupContext(); |
---|
45 | |
---|
46 | $this->ds = &Factory::getInstance('WorkflowObjects')->getLDAP(); |
---|
47 | |
---|
48 | $this->cachedLDAP = &Factory::getInstance('wf_cached_ldap'); |
---|
49 | $this->cachedLDAP->setOperationMode($this->cachedLDAP->OPERATION_MODE_LDAP); |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * Busca registros do LDAP de acordo com o o id e tipo de conta passados como parametro |
---|
54 | * @param int $account_id ID do usuário ou grupo. |
---|
55 | * @param string $account_type Tipo de conta ("u" usuario,"g" grupo) |
---|
56 | * @return array Informações do(s) registro(s) encontrado(s). |
---|
57 | * @access public |
---|
58 | */ |
---|
59 | function get_entry($account_id, $account_type = "u") |
---|
60 | { |
---|
61 | if ($account_type == "u") |
---|
62 | { |
---|
63 | return $this->cachedLDAP->getEntryByID($account_id); |
---|
64 | } |
---|
65 | elseif ($account_type == "g") |
---|
66 | { |
---|
67 | $sri = ldap_search($this->ds, $this->group_context, '(&(gidnumber=' . (int)$account_id . ')(phpgwaccounttype=g))'); |
---|
68 | $allvalues = ldap_get_entries($this->ds, $sri); |
---|
69 | return array( 'dn' => $allvalues[0]['dn'], |
---|
70 | 'memberuid' => $allvalues[0]['memberuid'], |
---|
71 | 'gidnumber' => $allvalues[0]['gidnumber'][0], |
---|
72 | 'cn' => $allvalues[0]['cn'][0] |
---|
73 | ); |
---|
74 | } |
---|
75 | else |
---|
76 | { |
---|
77 | return false; |
---|
78 | } |
---|
79 | |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | * Busca um registro do LDAP de acordo com o CPF. |
---|
84 | * @param int $cpf CPF do usuário. |
---|
85 | * @return array Informações do registro encontrado. |
---|
86 | * @acess public |
---|
87 | */ |
---|
88 | function get_entry_by_cpf($cpf) |
---|
89 | { |
---|
90 | return $this->cachedLDAP->getEntryByCPF($cpf); |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | * Busca um registro do LDAP de acordo com o e-mail. |
---|
95 | * @param string $email E-mail do usuário. |
---|
96 | * @return array Informações do registro encontrado. |
---|
97 | * @acess public |
---|
98 | */ |
---|
99 | function get_entry_by_email($email) |
---|
100 | { |
---|
101 | return $this->cachedLDAP->getEntryByEmail($email); |
---|
102 | } |
---|
103 | |
---|
104 | /** |
---|
105 | * Busca um registro do LDAP de acordo com a matricula. |
---|
106 | * @param int $matricula Matrícula do usuário. |
---|
107 | * @return array Informações do registro encontrado. |
---|
108 | * @acess public |
---|
109 | */ |
---|
110 | function get_entry_by_matricula($matricula) |
---|
111 | { |
---|
112 | return $this->cachedLDAP->getEntryByEmployeeNumber($matricula); |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * Busca um registro do LDAP de acordo com o uid. |
---|
117 | * @param string $uid Uid do usuário. |
---|
118 | * @return array Informações do registro encontrado. |
---|
119 | * @acess public |
---|
120 | */ |
---|
121 | function get_entry_by_uid($uid) |
---|
122 | { |
---|
123 | return $this->cachedLDAP->getEntryByUid($uid); |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | /** |
---|
128 | * Busca nomes de uma array de IDs. |
---|
129 | * @param array $IDs Os IDs dos quais se quer o nome. |
---|
130 | * @return array Uma array contento os IDs e os nomes encontrados. |
---|
131 | * @acess public |
---|
132 | */ |
---|
133 | function getNames($IDs) |
---|
134 | { |
---|
135 | if (!is_array($IDs)) |
---|
136 | return false; |
---|
137 | |
---|
138 | /* faz a busca para encontrar os nomes */ |
---|
139 | $resourceIdentifier = ldap_search($this->ds, $this->user_context, "(|" . implode('', array_map(create_function('$a', 'return "(uidnumber={$a})";'), array_unique($IDs))) . ")", array('cn', 'uidnumber')); |
---|
140 | $result = ldap_get_entries($this->ds, $resourceIdentifier); |
---|
141 | |
---|
142 | /* prepara a saída */ |
---|
143 | $output = array(); |
---|
144 | for ($i = 0; $i < $result['count']; $i++) |
---|
145 | $output[] = array( |
---|
146 | 'id' => $result[$i]['uidnumber'][0], |
---|
147 | 'name' => $result[$i]['cn'][0]); |
---|
148 | |
---|
149 | /* retorna os IDs/nomes */ |
---|
150 | return $output; |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | * Termina a conexão com o LDAP |
---|
155 | * @return void |
---|
156 | * @acess public |
---|
157 | */ |
---|
158 | function close() |
---|
159 | { |
---|
160 | ldap_close($this->ds); |
---|
161 | } |
---|
162 | } |
---|
163 | ?> |
---|