source: trunk/jabberit_messenger/inc/class.ldap_im.inc.php @ 417

Revision 417, 3.7 KB checked in by niltonneto, 16 years ago (diff)

Vide changelog do módulo.
http://www.expressolivre.org/dev/wiki/jabberit/changelog
Alterações feitas por Alexandre Correia
email: alexandrecorreia@…

  • Property svn:executable set to *
Line 
1<?php
2  /***************************************************************************\
3  *  Expresso - Expresso Messenger                                            *
4  *     - Alexandre Correia / Rodrigo Souza                                                               *
5  *     - JETI - http://jeti-im.org/                                                                              *
6  * ------------------------------------------------------------------------- *
7  *  This program is free software; you can redistribute it and/or modify it  *
8  *  under the terms of the GNU General Public License as published by the    *
9  *  Free Software Foundation; either version 2 of the License, or (at your   *
10  *  option) any later version.                                               *
11  \***************************************************************************/
12
13define('PHPGW_INCLUDE_ROOT', '../');
14define('PHPGW_API_INC','../phpgwapi/inc');
15require_once( PHPGW_API_INC . '/class.common.inc.php');
16
17class ldap_im
18{
19        private $ldap;
20        private $ldap_host;
21        private $ldap_context;
22        private $ldap_dn;
23        private $ldap_pass;
24        private $common;
25        private $jid;
26        private $max_result;
27       
28        public final function __construct()
29        {
30                $this->ldap_host        = $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit'];
31                $this->ldap_context     = $_SESSION['phpgw_info']['jabberit_messenger']['context_ldap_jabberit'];
32                $this->ldap_dn          = $_SESSION['phpgw_info']['jabberit_messenger']['user_ldap_jabberit'];
33                $this->ldap_pass        = $_SESSION['phpgw_info']['jabberit_messenger']['password_ldap_jabberit'];
34                $this->jid                      = $_SESSION['phpgw_info']['jabberit_messenger']['user'];
35                $this->max_result       = 50;
36        }
37
38        public final function __destruct()
39        {
40                if( $this->ldap )
41                        ldap_close($this->ldap);
42        }       
43
44        private final function _connect_ldap()
45        {
46                $this->common = new common();
47               
48                if( !$this->ldap )
49                {
50                        $GLOBALS['phpgw_info']['server']['ldap_version3'] = true;
51                        $this->ldap = $this->common->ldapConnect( $this->ldap_host,$this->ldap_dn,$this->ldap_pass );
52                }
53        }
54       
55        public final function list_users_ldap($search, $uidnumber)
56        {
57                $this->_connect_ldap();
58       
59                if( $this->ldap )
60                {
61                        $filter = "(&(phpgwaccounttype=u)(|".$uidnumber.")(".$search ."))";
62                        $justthese = array("uid","uidNumber","cn","mail","phpgwAccountVisible","dn","jpegPhoto");
63                        $search = ldap_search($this->ldap,$this->ldap_context,$filter,$justthese, 0, $this->max_result + 1);
64                        $entry1 = ldap_get_entries($this->ldap,$search);
65                        $entry = ldap_first_entry( $this->ldap, $search );
66                }
67
68                if( $entry1['count'] > 0 )
69                {
70                        if( count($entry1) < $this->max_result )
71                        {
72                                $i = 0;
73                                $result_user = array();
74                                $result = array();
75
76                                while($entry)
77                                {
78                               
79                                        if ( $entry1[$i]['phpgwaccountvisible'][0] != '-1' )
80                                        {
81                                                $result['uidnumber'] = @ldap_get_values($this->ldap, $entry, 'uidnumber');                     
82                                                $result['mail'] = @ldap_get_values($this->ldap, $entry, 'mail');
83                                                $result['uid'] = @ldap_get_values($this->ldap, $entry, 'uid');
84                                                $result['cn'] = @ldap_get_values($this->ldap, $entry, 'cn');
85
86                                                foreach ( $result as $key => $value )
87                                                        $result_user[$i][$key] = $value[0];
88
89                                                $ou = explode('dc=', $entry1[$i]['dn']);
90                                                $ou = explode("ou=",$ou[0]);
91                                                $ou = array_pop($ou);
92                                                $result_user[$i]['dn'] = strtoupper(substr($ou,0,strlen($ou)-1));
93
94                                                $result_user[$i]['photo'] = 0;
95                                                $photo = @ldap_get_values_len($this->ldap, $entry, 'jpegphoto');
96                                                if ( $photo )
97                                                {
98                                                        $result_user[$i]['photo'] = 1;
99                                                        $_SESSION['phpgw_info']['jabberit_messenger']['photo'][trim($result_user[$i]['uid'])] = $photo[0];
100                                                }
101                                                $i++;
102                                        }                               
103                                        $entry = ldap_next_entry($this->ldap,$entry);   
104                                }
105                                return $result_user;
106                        }
107                        else
108                        {
109                                return "Many Results";
110                        }
111                }
112                return 0;
113        }
114       
115        public final function teste()
116        {
117                 return 'dentro da classe do php';
118        }
119}
120
121?>
Note: See TracBrowser for help on using the repository browser.