[382] | 1 | <?php |
---|
| 2 | |
---|
| 3 | require_once "class.ldap_im.inc.php"; |
---|
| 4 | require_once "class.db_im.inc.php"; |
---|
| 5 | |
---|
| 6 | class contacts_im |
---|
| 7 | { |
---|
| 8 | private $ldap; |
---|
| 9 | private $db; |
---|
| 10 | |
---|
| 11 | public final function __construct() |
---|
| 12 | { |
---|
| 13 | $this->ldap = new ldap_im(); |
---|
| 14 | $this->db = new db_im(); |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | private final function users_auth_im($pName) |
---|
| 18 | { |
---|
| 19 | $array_uids = $this->db->get_accounts_acl(); |
---|
| 20 | $count = count($array_uids); |
---|
| 21 | $uids_members = array(); |
---|
| 22 | |
---|
| 23 | for($i = 0; $i < $count ;$i+=50) |
---|
| 24 | { |
---|
| 25 | $partial_uids = array_slice($array_uids,$i,50); |
---|
| 26 | $filter_uid = implode(")(uidnumber=",$partial_uids); |
---|
| 27 | $filter_uid = "(uidnumber=". $filter_uid. ")"; |
---|
| 28 | $result = $this->ldap->list_users_ldap("cn=*".$pName."*", $filter_uid); |
---|
| 29 | if ( is_array($result) ) |
---|
| 30 | $uids_members = array_merge($uids_members,$result); |
---|
| 31 | |
---|
| 32 | if(count($uids_members) > 50){ |
---|
| 33 | unset($_SESSION['phpgw_info']['jabberit_messenger']['photo']); |
---|
| 34 | return 'Many Results'; |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | if(count($uids_members) > 0) |
---|
| 38 | return $uids_members; |
---|
| 39 | else |
---|
| 40 | return 0; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | public final function list_contacts($param) |
---|
| 44 | { |
---|
| 45 | $users = $this->users_auth_im($param['name']); |
---|
| 46 | $order = array(); |
---|
| 47 | |
---|
| 48 | if (!is_array($users) && trim($users) === 'Many Results') |
---|
| 49 | return "<error>Many Results</error>"; |
---|
| 50 | |
---|
| 51 | if( is_array($users) ) |
---|
| 52 | { |
---|
| 53 | foreach($users as $tmp) |
---|
| 54 | { |
---|
| 55 | if ( !array_key_exists($tmp['dn'], $order) ) |
---|
| 56 | $order[$tmp['dn']] = array(); |
---|
| 57 | |
---|
| 58 | $order[$tmp['dn']][] = '<data><cn>' . $tmp['cn'] . '</cn><mail>' . $tmp['mail'] .'</mail><uid>' . $tmp['uid'] . '</uid><photo>' . $tmp['photo'] . '</photo></data>'; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | ksort($order); |
---|
| 62 | |
---|
| 63 | $return = '<uids>'; |
---|
| 64 | foreach ( $order as $key => $val ) |
---|
| 65 | $return .= '<'.$key.'>'.implode('',$val).'</'.$key.'>'; |
---|
| 66 | $return .= '</uids>'; |
---|
| 67 | } |
---|
| 68 | else |
---|
| 69 | $return = '<empty/>'; |
---|
| 70 | |
---|
| 71 | return $return; |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | ?> |
---|