1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * phpGroupWare API - Accounts manager for LDAP * |
---|
4 | * Written by Joao Alfredo Knopik Junior <jakje@celepar.pr.gov.br> * |
---|
5 | * View and manipulate account records using LDAP * |
---|
6 | * Copyright (C) 2000 - 2002 Joseph Engo, Lars Kneschke * |
---|
7 | * Copyright (C) 2003 Lars Kneschke, Bettina Gille * |
---|
8 | * ------------------------------------------------------------------------ * |
---|
9 | * This library is part of the phpGroupWare API * |
---|
10 | * http://www.phpgroupware.org * |
---|
11 | * ------------------------------------------------------------------------ * |
---|
12 | * This library is free software; you can redistribute it and/or modify it * |
---|
13 | * under the terms of the GNU Lesser General Public License as published by * |
---|
14 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
15 | * or any later version. * |
---|
16 | * This library is distributed in the hope that it will be useful, but * |
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
19 | * See the GNU Lesser General Public License for more details. * |
---|
20 | * You should have received a copy of the GNU Lesser General Public License * |
---|
21 | * along with this library; if not, write to the Free Software Foundation, * |
---|
22 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
23 | \**************************************************************************/ |
---|
24 | |
---|
25 | include_once('class.common.inc.php'); |
---|
26 | |
---|
27 | class sector_search_ldap |
---|
28 | { |
---|
29 | var $common; |
---|
30 | var $ldap_connection; |
---|
31 | var $sector_name; |
---|
32 | var $sector_context; |
---|
33 | var $sector_level; |
---|
34 | var $sector_leaf; |
---|
35 | |
---|
36 | function sector_search_ldap($sector_name="", $sector_context="", $sector_level="", $sector_leaf="", $ldap_conn="") |
---|
37 | { |
---|
38 | if ($ldap_conn == "") |
---|
39 | { |
---|
40 | $this->common = new common; |
---|
41 | $this->ldap_connection = $this->common->ldapConnect(); |
---|
42 | } |
---|
43 | else |
---|
44 | $this->ldap_connection = $ldap_conn; |
---|
45 | |
---|
46 | $this->sector_name = $sector_name; |
---|
47 | $this->sector_context = $sector_context; |
---|
48 | $this->sector_level = $sector_level; |
---|
49 | $this->sector_leaf = $sector_leaf; |
---|
50 | } |
---|
51 | |
---|
52 | // All levels of ouŽs, organizations (first level) and sectors (rest levels) |
---|
53 | function sector_search($ldap_context, $clear_static_vars=true) |
---|
54 | { |
---|
55 | static $sectors_list = array(); |
---|
56 | static $level = 0; |
---|
57 | |
---|
58 | if ($clear_static_vars) |
---|
59 | { |
---|
60 | $sectors_list = array(); |
---|
61 | $level = 0; |
---|
62 | } |
---|
63 | |
---|
64 | $filter="ou=*"; |
---|
65 | $justthese = array("ou"); |
---|
66 | $sr=ldap_list($this->ldap_connection, $ldap_context, $filter, $justthese); |
---|
67 | ldap_sort($this->ldap_connection ,$sr, "ou"); |
---|
68 | $info = ldap_get_entries($this->ldap_connection, $sr); |
---|
69 | |
---|
70 | for ($i=0; $i<$info["count"]; $i++) |
---|
71 | { |
---|
72 | $level++; |
---|
73 | $next_ldap_context[$i] = $info[$i]["dn"]; |
---|
74 | |
---|
75 | $obj = new sector_search_ldap($info[$i]["ou"][0], $next_ldap_context[$i], $level, 'False', $this->ldap_connection); |
---|
76 | array_push($sectors_list, $obj); |
---|
77 | |
---|
78 | $this->sector_search($next_ldap_context[$i], false); |
---|
79 | } |
---|
80 | $level--; |
---|
81 | return $sectors_list; |
---|
82 | } |
---|
83 | |
---|
84 | // Just the first level, or the organizations |
---|
85 | function organization_search($ldap_context) |
---|
86 | { |
---|
87 | $filter="ou=*"; |
---|
88 | $justthese = array("ou"); |
---|
89 | |
---|
90 | $sr=ldap_list($this->ldap_connection, $ldap_context, $filter, $justthese); |
---|
91 | $info = ldap_get_entries($this->ldap_connection, $sr); |
---|
92 | |
---|
93 | for ($i=0; $i<$info["count"]; $i++) |
---|
94 | { |
---|
95 | $sectors_list[$i] = $info[$i]["ou"][0]; |
---|
96 | } |
---|
97 | sort($sectors_list); |
---|
98 | return $sectors_list; |
---|
99 | } |
---|
100 | } |
---|
101 | ?> |
---|