source: companies/serpro/workflow/inc/class.WorkflowLDAP.inc.php @ 903

Revision 903, 22.3 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

Line 
1<?php
2/**************************************************************************\
3* eGroupWare                                                               *
4* http://www.egroupware.org                                                *
5* --------------------------------------------                             *
6*  This program is free software; you can redistribute it and/or modify it *
7*  under the terms of the GNU General Public License as published by the   *
8*  Free Software Foundation; either version 2 of the License, or (at your  *
9*  option) any later version.                                              *
10\**************************************************************************/
11
12/**
13 * Implements common LDAP methods
14 * @author Sidnei Augusto Drovetto Jr. - drovetto@gmail.com
15 * @version 1.0
16 * @package Workflow
17 * @license http://www.gnu.org/copyleft/gpl.html GPL
18 */
19class WorkflowLDAP
20{
21        /**
22         * @var resource $dataSource Recurso de conexão com o LDAP
23         * @access private
24         */
25        private $dataSource;
26
27        /**
28         * @var string $userContext Contexto do usuário
29         * @access private
30         */
31        private $userContext;
32
33        /**
34         * @var string $groupContext Contexto do grupo
35         * @access private
36         */
37        private $groupContext;
38
39        /**
40         * @var string $ldapContext Contexto do LDAP
41         * @access private
42         */
43        private $ldapContext;
44
45        /**
46         * Construtor da classe
47         * @return object
48         * @access public
49         */
50        function WorkflowLDAP()
51        {
52                $this->dataSource = &$GLOBALS['workflow']['workflowObjects']->getLDAP();
53
54                /* get the required parameters */
55                $info = (isset($GLOBALS['phpgw_info']['server']['ldap_context'])) ?
56                        $GLOBALS['phpgw_info']['server'] :
57                        $_SESSION['phpgw_info']['workflow']['server'];
58                $ldapConfigValues = galaxia_get_config_values(array('ldap_user_context' => '', 'ldap_group_context' => ''));
59                if (empty($ldapConfigValues['ldap_user_context']))
60                        $ldapConfigValues['ldap_user_context'] = $info['ldap_context'];
61                if (empty($ldapConfigValues['ldap_group_context']))
62                        $ldapConfigValues['ldap_group_context'] = $info['ldap_group_context'];
63                $this->userContext = $ldapConfigValues['ldap_user_context'];
64                $this->groupContext = $ldapConfigValues['ldap_group_context'];
65                $this->ldapContext = $ldapConfigValues['ldap_user_context'];
66
67                $this->cache = array(
68                        'getEntities' => array(),
69                        'getUserGroups' => array(),
70                        'getGroupUsers' => array(),
71                        'getOrganizations' => array(),
72                        'getNames' => array()
73                );
74        }
75
76        /**
77         * Checa se um método, e seus parâmetros, já estão em cache
78         * @param string $methodName O nome do método que se quer verificar
79         * @param string $parameters Parâmetros passados para o método (serializados)
80         * @return bool true se foi encontrada uma versão em cache dos dados solicitados e false caso contrário
81         * @access private
82         */
83        private function checkCache($methodName, $parameters)
84        {
85                return isset($this->cache[$methodName][$parameters]);
86        }
87
88        /**
89         * Pega a informação, em cache, de um método e seus parâmetros
90         * @param string $methodName O nome do método que está em cache
91         * @param string $parameters Parâmetros passados para o método (serializados)
92         * @return mixed O retorno do método usando os parâmetros passados
93         * @access private
94         */
95        private function getCache($methodName, $parameters)
96        {
97                return $this->cache[$methodName][$parameters];
98        }
99
100        /**
101         * Coloca em cache um método e seus parâmetros
102         * @param string $methodName O nome do método
103         * @param string $parameters Parâmetros passados para o método (serializados)
104         * @param mixed $output Saída do método usando os parâmetros passados
105         * @return mixed A saéda igual ao parâmetro $output
106         * @access private
107         */
108        private function setCache($methodName, $parameters, $output)
109        {
110                $this->cache[$methodName][$parameters] = $output;
111                return $output;
112        }
113
114        /**
115         * Faz consultas ao LDAP
116         * @param string $context Contexto das entidades
117         * @param string $filter Filtro utilizado para selecionar as entidades desejadas
118         * @param array $elements Array dos campos que se deseja obter
119         * @param bool $depthSearch Indica se a busca deve incluir sub-árvores ou não
120         * @param string $elementSort O elemento pelo qual se quer ordenar o resultado
121         * @return mixed Array do resultado. Ou false em caso de erro
122         * @access private
123         */
124        private function runLDAP($context, $filter, $elements, $depthSearch = false, $elementSort = null)
125        {
126                if ($depthSearch)
127                        $resourceIdentifier = ldap_search($this->dataSource, $context, $filter, $elements);
128                else
129                        $resourceIdentifier = ldap_list($this->dataSource, $context, $filter, $elements);
130
131                if (!$resourceIdentifier)
132                        return false;
133
134                if (!is_null($elementSort))
135                        ldap_sort($this->dataSource, $resourceIdentifier, $elementSort);
136
137                $output = ldap_get_entries($this->dataSource, $resourceIdentifier);
138                return $output;
139        }
140
141        /**
142         * Faz consultas ao LDAP (inclusive com campos binários)
143         * @param string $context Contexto das entidades
144         * @param string $filter Filtro utilizado para selecionar as entidades desejadas
145         * @param array $elements Array dos campos que se deseja obter
146         * @param bool $depthSearch Indica se a busca deve incluir sub-árvores ou não
147         * @param string $elementSort O elemento pelo qual se quer ordenar o resultado
148         * @return mixed Array do resultado. Ou false em caso de erro
149         * @access private
150         */
151        private function runBinaryLDAP($context, $filter, $elements, $depthSearch = false, $elementSort = null)
152        {
153                if ($depthSearch)
154                        $resourceIdentifier = ldap_search($this->dataSource, $context, $filter, $elements);
155                else
156                        $resourceIdentifier = ldap_list($this->dataSource, $context, $filter, $elements);
157
158                if (!$resourceIdentifier)
159                        return false;
160
161                if (!is_null($elementSort))
162                        ldap_sort($this->dataSource, $resourceIdentifier, $elementSort);
163
164                $entry = ldap_first_entry($this->dataSource, $resourceIdentifier);
165                if (!$entry)
166                        return array();
167
168                $output = array();
169                $counter = 0;
170                do
171                {
172                        $attributes = ldap_get_attributes($this->dataSource, $entry);
173                        for ($i = 0; $i < $attributes['count']; $i++)
174                                $output[$counter][$attributes[$i]] = ldap_get_values_len($this->dataSource, $entry, $attributes[$i]);
175
176                        $counter++;
177                } while ($entry = ldap_next_entry($this->dataSource, $entry));
178
179                return $output;
180        }
181
182        /**
183         * Busca entidades (usuários, grupos ou listas públicas) do LDAP
184         * @param string $context Contexto das entidades
185         * @param string $filter Filtro utilizado para selecionar as entidades desejadas
186         * @param array $elements Array dos campos que representa, nesta ordem: o ID, o nome e o e-mail da entidade
187         * @param char $type O tipo da entidade: 'u' para usuários; 'g' para grupos; e 'l' para listas públicas
188         * @param bool $depthSearch Indica se a busca deve incluir sub-árvores ou não
189         * @return array Array das entidades
190         * @access private
191         */
192        private function getEntities($context, $filter, $elements, $type, $depthSearch = false)
193        {
194                /* check if the required information is in cache */
195                $methodName = 'getEntities';
196                $parameters = serialize(func_get_args());
197                if ($this->checkCache($methodName, $parameters))
198                        return $this->getCache($methodName, $parameters);
199
200                $result = $this->runLDAP($context, $filter, $elements, $depthSearch, $elements[1]);
201
202                $output = array();
203                for ($i = 0; $i < $result['count']; $i++)
204                {
205                        $output[] = array(
206                                'id' => $result[$i][$elements[0]][0],
207                                'name' => $result[$i][$elements[1]][0],
208                                'type' => $type,
209                                'mail' => $result[$i][$elements[2]][0]);
210                }
211
212                /* store the information in cache and return the output */
213                return $this->setCache($methodName, $parameters, $output);
214        }
215
216        /**
217         * Retorna os grupos de um usuário
218         * @param int $userID O ID do usuário
219         * @return array Array dos grupos
220         * @access public
221         */
222        function getUserGroups($userID)
223        {
224                /* do not perform any search if the user is '*' */
225                if ($userID == '*')
226                        return array();
227
228                /* check if the required information is in cache */
229                $methodName = 'getUserGroups';
230                $parameters = serialize(func_get_args());
231                if ($this->checkCache($methodName, $parameters))
232                        return $this->getCache($methodName, $parameters);
233
234                /* check for error in connection */
235                if (!$this->dataSource)
236                        return false;
237
238                /* first, get the UID */
239                $resourceIdentifier = ldap_search($this->dataSource, $this->userContext, "(&(phpgwaccounttype=u)(uidnumber={$userID}))", array('uid'));
240                $result = ldap_get_entries($this->dataSource, $resourceIdentifier);
241                if (!isset($result[0]['uid'][0]))
242                        return false;
243                $userLogin = $result[0]['uid'][0];
244
245                /* initialize some variables */
246                $output = array();
247
248                /* search the LDAP tree */
249                $resourceIdentifier = ldap_search($this->dataSource, $this->groupContext, "(&(phpgwaccounttype=g)(memberuid={$userLogin}))", array('gidnumber'));
250                $result = ldap_get_entries($this->dataSource, $resourceIdentifier);
251                for ($i = 0; $i < $result['count']; $i++)
252                        $output[] = $result[$i]['gidnumber'][0];
253
254                /* store the information in cache and return the output */
255                return $this->setCache($methodName, $parameters, $output);
256        }
257
258        /**
259         * Retorna os usuários de um grupo
260         * @param int $groupID O ID do grupo
261         * @return array Array dos usuários
262         * @access public
263         */
264        function getGroupUsers($groupID)
265        {
266                /* check if the required information is in cache */
267                $methodName = 'getGroupUsers';
268                $parameters = serialize(func_get_args());
269                if ($this->checkCache($methodName, $parameters))
270                        return $this->getCache($methodName, $parameters);
271
272                /* check for error in connection */
273                if (!$this->dataSource)
274                        return false;
275
276                /* first, we get the UIDs that are members of the group */
277                $resourceIdentifier = ldap_search($this->dataSource, $this->ldapContext, "(&(phpgwaccounttype=g)(gidnumber={$groupID}))", array('memberuid'));
278                $result = ldap_get_entries($this->dataSource, $resourceIdentifier);
279                if (!isset($result[0]['memberuid'][0]))
280                        return false;
281
282                $userLogins = $result[0]['memberuid'];
283                unset($userLogins['count']);
284
285                /* next, we get the UIDNumber and CN of all members of the group */
286                $resourceIdentifier = ldap_search($this->dataSource, $this->ldapContext, "(&(phpgwaccounttype=u)(|" . implode('', array_map(create_function('$a', 'return "(uid={$a})";'), $userLogins)) . "))", array('cn', 'uidnumber'));
287                ldap_sort($this->dataSource, $resourceIdentifier, "cn");
288                $result = ldap_get_entries($this->dataSource, $resourceIdentifier);
289
290                $output = array();
291                for ($i = 0; $i < $result['count']; $i++)
292                        $output[] = array(
293                                'account_id' => $result[$i]['uidnumber'][0],
294                                'account_name' => $result[$i]['cn'][0]);
295
296                /* store the information in cache and return the output */
297                return $this->setCache($methodName, $parameters, $output);
298        }
299
300        /**
301         * Retorna as organizações do nível raiz
302         * @return array Array de organizações
303         * @access public
304         */
305        function getOrganizations()
306        {
307                /* check if the required information is in cache */
308                $methodName = 'getOrganizations';
309                $parameters = serialize(func_get_args());
310                if ($this->checkCache($methodName, $parameters))
311                        return $this->getCache($methodName, $parameters);
312
313                /* check for error in connection */
314                if (!$this->dataSource)
315                        return false;
316
317                /* load the sectors of level 0 as organizations, then format the data */
318                $output = array_map(create_function('$a', 'return $a[\'ou\'];'), $this->getSectors());
319
320                /* store the information in cache and return the output */
321                return $this->setCache($methodName, $parameters, $output);
322        }
323
324        /**
325         * Retorna os setores de um determinado contexto
326         * @param string $organization A organização a partir da qual a busca deve inciar. Utilize null para o nível raiz
327         * @param bool $recursive Indica se a busca deve ser recursiva ou não. true indica que deve ser recursiva e false que não deve ser recursiva
328         * @param string $contextBase A base do contexto. Utilize null para o contexto padrão
329         * @param int $level Indica o nível atual de recursão
330         * @return array Array de setores
331         * @access public
332         */
333        function getSectors($organization = null, $recursive = false, $contextBase = null, $level = 0)
334        {
335                /* determines the context in which the search will be performed */
336                $context = (!is_null($contextBase) ? $contextBase : $this->ldapContext);
337                $context = (!is_null($organization) ? 'ou=' . $organization . ',' : '') . $context;
338
339                /* search for the sectors */
340                $resourceIdentifier = @ldap_list($this->dataSource, $context, '(objectClass=organizationalUnit)', array('ou'));
341                if ($resourceIdentifier === false)
342                        return false;
343
344                ldap_sort($this->dataSource, $resourceIdentifier, 'ou');
345                $result = ldap_get_entries($this->dataSource, $resourceIdentifier);
346
347                /* collect the data */
348                $output = array();
349                for ($i = 0; $i < $result['count']; $i++)
350                {
351                        $output[] = array(
352                                'dn' => $result[$i]['dn'],
353                                'ou' => $result[$i]['ou'][0],
354                                'level' => $level);
355
356                        /* if requested, perform a recursive search */
357                        if ($recursive)
358                                $output = array_merge($output, $this->getSectors($result[$i]['ou'][0], $recursive, $context, $level + 1));
359                }
360
361                return $output;
362        }
363
364        /**
365         * Retorna os usuários de um determinado contexto
366         * @param string $context O contexto a partir do qual a busca deve começar
367         * @return array Array dos usuários encontrados
368         * @access public
369         */
370        function getUsers($context,$depthSearch = false)
371        {
372                $filter = '(&(phpgwaccounttype=u)(!(phpgwAccountVisible=-1)))';
373                $elements = array('uidnumber', 'cn', 'mail');
374                return $this->getEntities($context, $filter, $elements, 'u', $depthSearch);
375        }
376
377        /**
378         * Retorna os usuários de um determinado contexto
379         * @param string $context O contexto a partir do qual a busca deve começar
380         * @return array Array dos usuários encontrados
381         * @access public
382         */
383        function searchUsers($searchField,$context,$depthSearch = false)
384        {
385                $filter = '(&(phpgwaccounttype=u)(!(phpgwAccountVisible=-1))(|(mail=*'.$searchField.'*)(mailalternateaddress=*'.$searchField.'*)(mailforwardingaddress=*'.$searchField.'*)(cn=*'.$searchField.'*)(sn=*'.$searchField.'*)(givenname=*'.$searchField.'*)))';
386                $elements = array('uidnumber', 'cn', 'mail');
387                return $this->getEntities($context, $filter, $elements, 'u', $depthSearch);
388        }
389
390        /**
391         * Retorna os grupos de um determinado contexto
392         * @param string $context O contexto a partir do qual a busca deve começar
393         * @return array Array dos grupos encontrados
394         * @access public
395         */
396        function getGroups($context)
397        {
398                $filter = '(phpgwaccounttype=g)';
399                $elements = array('gidnumber', 'cn', 'mail');
400                return $this->getEntities($context, $filter, $elements, 'g', false);
401        }
402
403        /**
404         * Retorna listas pï¿œblicas de um determinado contexto
405         * @param string $context O contexto a partir do qual a busca deve comeï¿œar
406         * @return array Array das listas pï¿œblicas encontradas
407         * @access public
408         */
409        /**
410         * Retorna os usuï¿œrios de um determinado contexto
411         * @param string $context O contexto a partir do qual a busca deve comeï¿œar
412         * @return array Array dos usuï¿œrios encontrados
413         * @access public
414         */
415        function searchGroups($searchField,$context,$depthSearch = false)
416        {
417                $filter = '(&(phpgwaccounttype=g)(!(phpgwAccountVisible=-1))(cn=*'.$searchField.'*))';
418                $elements = array('gidnumber', 'cn', 'mail');
419                return $this->getEntities($context, $filter, $elements, 'g', $depthSearch);
420        }
421
422        /**
423         * Retorna listas pï¿œblicas de um determinado contexto
424         * @param string $context O contexto a partir do qual a busca deve comeï¿œar
425         * @return array Array das listas pï¿œblicas encontradas
426         * @access public
427         */
428        function getPublicLists($context)
429        {
430                $filter = '(phpgwaccounttype=l)';
431                $elements = array('uidnumber', 'cn', 'mail');
432                return $this->getEntities($context, $filter, $elements, 'l', false);
433        }
434
435        /**
436         * Retornar informaᅵᅵo sobre um usuï¿œrio
437         * @param int $userID O ID do usuï¿œrio
438         * @return mixed Array contento informaᅵᅵo sobre um usuï¿œrio ou false se o usuï¿œrio nï¿œo for encontrado
439         * @access public
440         */
441        function getUserInfo($userID)
442        {
443                $filter = '(&(phpgwaccounttype=u)(uidnumber=' . $userID . '))';
444                $elements = array('uidnumber', 'cn', 'mail');
445                $output = $this->getEntities($this->ldapContext, $filter, $elements, 'u', true);
446                if (count($output) == 1)
447                        return $output[0];
448                else
449                        return false;
450        }
451
452        function getUserPicture($userID)
453        {
454                $userID = (int) $userID;
455                $filter = '(&(phpgwaccounttype=u)(uidnumber=' . $userID . '))';
456                $elements = array('jpegPhoto');
457                $result = $this->runBinaryLDAP($this->ldapContext, $filter, $elements, true);
458
459                if (isset($result[0]['jpegPhoto'][0]))
460                        return $result[0]['jpegPhoto'][0];
461
462                return false;
463        }
464
465        /**
466         * Retrieves information about a group
467         * @param int $userID The ID of the group
468         * @return mixed Array containing information about a group or false if the group is not found
469         * @access public
470         */
471        function getGroupInfo($groupID)
472        {
473                $filter = '(&(phpgwaccounttype=g)(gidnumber=' . $groupID . '))';
474                $elements = array('gidnumber', 'cn', 'mail');
475                $output = $this->getEntities($this->ldapContext, $filter, $elements, 'g', true);
476                if (count($output) == 1)
477                        return $output[0];
478                else
479                        return false;
480        }
481
482        /**
483         * Retorna o tipo de uma entidade
484         * @param int $entityID O ID da entidade
485         * @return string O tipo da entidade ('g' para grupo e 'u' para usuï¿œrio)
486         * @access public
487         */
488        function getEntityType($entityID)
489        {
490                if ($entityID == '*')
491                        return false;
492
493                $output = $this->getUserInfo($entityID);
494                if (is_array($output))
495                        return 'u';
496                else
497                {
498                        $output = $this->getGroupInfo($entityID);
499                        if (is_array($output))
500                                return 'g';
501                }
502
503                return false;
504        }
505
506        /**
507         * Retorna o nome de uma entidade
508         * @param int $entityID O ID da entidade
509         * @return string O nome da entidade
510         * @access public
511         */
512        function getName($entityID)
513        {
514                if ($entityID == '*')
515                        return '*';
516                $output = $this->getUserInfo($entityID);
517                if (is_array($output))
518                        return $output['name'];
519                else
520                {
521                        $output = $this->getGroupInfo($entityID);
522                        if (is_array($output))
523                                return $output['name'];
524                }
525        }
526
527        /**
528         * Retorna os nomes de uma entidade
529         * @param array $entitiesID Os IDs das entidades
530         * @return string Os nomes das entidades
531         * @access public
532         */
533        function getNames($entitiesID)
534        {
535                /* check if the required information is in cache */
536                $methodName = 'getNames';
537                $parameters = serialize(func_get_args());
538                if ($this->checkCache($methodName, $parameters))
539                        return $this->getCache($methodName, $parameters);
540
541                /* check for error in connection */
542                if (!$this->dataSource)
543                        return false;
544
545                /* check for '*' */
546                $asteriskIndex = array_search('*', $entitiesID);
547                if ($asteriskIndex !== false)
548                        unset($entitiesID[$asteriskIndex]);
549
550                $resourceIdentifier = ldap_search($this->dataSource, $this->ldapContext, "(|" . implode('', array_map(create_function('$a', 'return "(|(&(uidnumber={$a})(|(phpgwaccounttype=u)(phpgwaccounttype=l)))(&(gidnumber={$a})(phpgwaccounttype=g)))";'), array_unique($entitiesID))) . ")", array('cn', 'uidnumber', 'gidnumber', 'phpgwaccounttype'));
551                ldap_sort($this->dataSource, $resourceIdentifier, 'cn');
552                $result = ldap_get_entries($this->dataSource, $resourceIdentifier);
553
554                $output = array();
555                for ($i = 0; $i < $result['count']; $i++)
556                        $output[] = array(
557                                'id' => ($result[$i]['phpgwaccounttype'][0] == 'g') ? $result[$i]['gidnumber'][0] : $result[$i]['uidnumber'][0],
558                                'name' => $result[$i]['cn'][0]);
559
560                if ($asteriskIndex !== false)
561                        $output[] = array('id' => '*', 'name' => '*');
562
563                /* store the information in cache and return the output */
564                return $this->setCache($methodName, $parameters, $output);
565
566        }
567
568        /**
569         * Faz uma busca (em todo o catálogo) por um nome
570         * @param string $searchTerm O termo que está sendo procurado (pode conter '*')
571         * @param bool $includeUsers Indica se na busca devem ser incluídos os registros referentes a usuários (true por padrão)
572         * @param bool $includeGroups Indica se na busca devem ser incluídos os registros referentes a grupos (false por padrão)
573         * @param bool $includeLists Indica se na busca devem ser incluídos os registros referentes a listas (false por padrão)
574         * @return array Uma array contendo os registros encontrados
575         * @access public
576         */
577        function search($searchTerm, $includeUsers = true, $includeGroups = false, $includeLists = false, $context = null)
578        {
579                if (!($includeUsers || $includeGroups || $includeLists))
580                        return false;
581
582                if (is_null($context))
583                        $context = $this->ldapContext;
584
585                /* check for error in connection */
586                if (!$this->dataSource)
587                        return false;
588
589                $entityFilter = array();
590                if ($includeUsers)
591                        $entityFilter[] = '(phpgwaccounttype=u)';
592                if ($includeGroups)
593                        $entityFilter[] = '(phpgwaccounttype=g)';
594                if ($includeLists)
595                        $entityFilter[] = '(phpgwaccounttype=l)';
596
597                if (count($entityFilter) > 1)
598                        $entityFilter = '(|' . implode('', $entityFilter) . ')';
599                else
600                        $entityFilter = $entityFilter[0];
601
602                $filter = "(&{$entityFilter}(cn={$searchTerm})(!(phpgwAccountVisible=-1)))";
603                $resourceIdentifier = ldap_search($this->dataSource, $context, $filter, array('cn', 'uidnumber', 'gidnumber', 'phpgwaccounttype', 'mail'));
604                ldap_sort($this->dataSource, $resourceIdentifier, 'cn');
605                $result = ldap_get_entries($this->dataSource, $resourceIdentifier);
606
607                $output = array();
608                for ($i = 0; $i < $result['count']; $i++)
609                        $output[] = array(
610                                'id' => ($result[$i]['phpgwaccounttype'][0] == 'g') ? $result[$i]['gidnumber'][0] : $result[$i]['uidnumber'][0],
611                                'name' => $result[$i]['cn'][0],
612                                'mail' => $result[$i]['mail'][0],
613                                'type' => $result[$i]['phpgwaccounttype'][0],
614                                'dn' => $result[$i]['dn']
615                        );
616
617                /* store the information in cache and return the output */
618                return $output;
619        }
620
621        /**
622         * Retorna o contexto de usuï¿œrios do LDAP
623         * @return string O contexto de usuï¿œrios do LDAP
624         * @access public
625         */
626        function getUserContext()
627        {
628                return $this->userContext;
629        }
630
631        /**
632         * Retorna o contexto de grupos do LDAP
633         * @return string O contexto de grupos do LDAP
634         * @access public
635         */
636        function getGroupContext()
637        {
638                return $this->groupContext;
639        }
640
641        /**
642         * Retorna o contexto do LDAP
643         * @return string O contexto do LDAP
644         * @access public
645         */
646        function getLDAPContext()
647        {
648                return $this->ldapContext;
649        }
650
651        /**
652         * Retorna a organização de um DN
653         * @param mixed $DN O DN do usuário
654         * @return mixed Uma string contendo a organização ou false caso não seja achada a organização
655         * @access public
656         */
657        public function getOrganizationFromDN($DN)
658        {
659                $userContext = str_replace(' ', '', $this->userContext);
660                $DN = str_replace(' ', '', $DN);
661                $userInfo = array_reverse(explode(',', substr($DN, 0, - (strlen($userContext) + 1))));
662                foreach ($userInfo as $attributePair)
663                {
664                        list($name, $value) = explode('=', $attributePair, 2);
665                        if ($name === 'ou')
666                                return $value;
667                }
668
669                return false;
670        }
671}
672?>
Note: See TracBrowser for help on using the repository browser.