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