source: trunk/jabberit_messenger/inc/class.contacts_im.inc.php @ 598

Revision 598, 3.3 KB checked in by niltonneto, 15 years ago (diff)

Corrigido condicional com array_search.

  • 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
13
14require_once "class.ldap_im.inc.php";
15require_once "class.db_im.inc.php";
16
17class contacts_im
18{
19        private $ldap;
20        private $db;
21       
22        public final function __construct()
23        {
24                $this->ldap = new ldap_im();
25                $this->db = new db_im();               
26        }
27
28        public final function getParticipantsExternal()
29        {               
30                if( !$this->groupsLocked() && $_SESSION['phpgw_info']['jabberit_messenger']['use_external_participants_jabberit'] )             
31                        return "true";
32                else
33                        return "false";         
34        }
35
36        private final function groupsLocked()
37        {
38                $memberShip = array();
39                $groupsLocked =  explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
40               
41                foreach($_SESSION['phpgw_info']['jabberit_messenger']['membership'] as $tmp)
42                        $memberShip[] = $tmp['account_name'];
43               
44                foreach($groupsLocked as $tmp)
45                {
46                        $groups = explode(":", $tmp);
47                        if( array_search($groups[1], $memberShip) !== False)
48                                return true;
49                }
50               
51                return false;
52        }
53
54        public final function list_contacts($param)
55        {
56                $users  = $this->users_auth_im($param['name']);
57                $order  = array();
58
59                if (!is_array($users) && trim($users) === 'Many Results')
60                        return "<error>Many Results</error>";
61
62                if( is_array($users) )
63                {       
64                        foreach($users as $tmp)
65                        {
66                                if ( !array_key_exists($tmp['dn'], $order) )
67                                        $order[$tmp['dn']] = array();
68
69                                $order[$tmp['dn']][] = '<data><cn>' . $tmp['cn'] . '</cn><mail>' . $tmp['mail'] .'</mail><uid>' . $tmp['uid'] . '</uid><photo>' . $tmp['photo'] . '</photo></data>';
70                        }
71                       
72                        ksort($order);
73                               
74                        $return = '<uids>';
75                        foreach ( $order as $key => $val )
76                                $return .= '<'.$key.'>'.implode('',$val).'</'.$key.'>';
77                        $return .= '</uids>';
78                }
79                else
80                        $return = '<empty/>';
81               
82                return $return;
83        }
84       
85        private final function users_auth_im($pName)
86        {   
87        $array_uids = $this->db->get_accounts_acl();
88        $count = count($array_uids);
89        $uids_members = array();
90       
91        for($i = 0; $i < $count ;$i+=50)
92        {   
93            $partial_uids = array_slice($array_uids,$i,50);
94            $filter_uid = implode(")(uidnumber=",$partial_uids);
95            $filter_uid = "(uidnumber=". $filter_uid. ")";
96            $result = $this->ldap->list_users_ldap("cn=*".$pName."*", $filter_uid, $this->groupsLocked());
97            if ( is_array($result) )
98                $uids_members = array_merge($uids_members,$result);                         
99               
100                if(count($uids_members) > 50){
101                        unset($_SESSION['phpgw_info']['jabberit_messenger']['photo']);         
102                        return 'Many Results';
103                }           
104        }
105        if(count($uids_members) > 0)
106            return $uids_members;
107        else
108            return 0;   
109        }
110}
111?>
Note: See TracBrowser for help on using the repository browser.