source: trunk/egroupware/felamimail/inc/class.ajax_contacts.inc.php @ 74

Last change on this file since 74 was 74, checked in by guille, 16 years ago

correccion de ajax de contactos para excluir cuentas

File size: 4.2 KB
Line 
1 
2<?php
3        /***************************************************************************\
4        * eGroupWare - FeLaMiMail                                                   *
5        * http://www.linux-at-work.de                                               *
6        * http://www.phpgw.de                                                       *
7        * http://www.egroupware.org                                                 *
8        * Written by : Lars Kneschke [lkneschke@linux-at-work.de]                   *
9        * -------------------------------------------------                         *
10        * This program is free software; you can redistribute it and/or modify it   *
11        * under the terms of the GNU General Public License as published by the     *
12        * Free Software Foundation; either version 2 of the License, or (at your    *
13        * option) any later version.                                                *
14        \***************************************************************************/
15
16        /* $Id: class.ajaxfelamimail.inc.php 21848 2006-06-15 21:50:59Z ralfbecker $ */
17
18        class ajax_contacts {
19                function ajax_contacts() {
20                        $GLOBALS['egw']->session->commit_session();
21                        $this->charset  = $GLOBALS['egw']->translation->charset();
22                }
23               
24                function searchAddress($_searchString) {
25                        if (!is_object($GLOBALS['egw']->contacts)) {
26                                $GLOBALS['egw']->contacts =& CreateObject('phpgwapi.contacts');
27                        }
28                        if (method_exists($GLOBALS['egw']->contacts,'search')) {
29                                // 1.3+
30                                $contacts = $GLOBALS['egw']->contacts->search(array(
31                                        'n_fn'       => $_searchString,
32                                        'email'      => $_searchString,
33                                        'email_home' => $_searchString,
34                                ),array('n_fn','email','email_home'),'n_fn','','%',false,'OR',array(0,20));
35
36//      Se saco esto para excluir las cuentas de la busqueda de destinatarios automaticos
37//                     
38//                              // additionally search the accounts, if the contact storage is not the account storage
39//                              if ($GLOBALS['egw_info']['server']['account_repository'] == 'ldap' &&
40//                                      $GLOBALS['egw_info']['server']['contact_repository'] == 'sql')
41//                              {
42//                                      $accounts = $GLOBALS['egw']->contacts->search(array(
43//                                              'n_fn'       => $_searchString,
44//                                              'email'      => $_searchString,
45//                                              'email_home' => $_searchString,
46//                                      ),array('n_fn','email','email_home'),'n_fn','','%',false,'OR',array(0,20),array('owner' => 0));
47//                                     
48//                                      if ($contacts && $accounts)
49//                                      {
50//                                              $contacts = array_merge($contacts,$accounts);
51//                                              usort($contacts,create_function('$a,$b','return strcasecmp($a["n_fn"],$b["n_fn"]);'));
52//                                      }
53//                                      elseif($accounts)
54//                                      {
55//                                              $contacts =& $accounts;
56//                                      }
57//                                      unset($accounts);
58//                              }
59                        } else {
60                                // < 1.3
61                                $contacts = $GLOBALS['egw']->contacts->read(0,20,array(
62                                        'fn' => 1,
63                                        'email' => 1,
64                                        'email_home' => 1,
65                                ), $_searchString, 'tid=n', '', 'fn');
66                        }
67
68                        $response =& new xajaxResponse();
69
70                        if(is_array($contacts)) {
71                                $innerHTML      = '';
72                                $jsArray        = array();
73                                $i              = 0;
74                               
75                                foreach($contacts as $contact) {
76                                        foreach(array($contact['email'],$contact['email_home']) as $email) {
77                                                // avoid wrong addresses, if an rfc822 encoded address is in addressbook
78                                                $email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/",'$2',$email);
79                                                if(!empty($email) && !isset($jsArray[$email])) {
80                                                        $i++;
81                                                        $str = $GLOBALS['egw']->translation->convert(trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']) .' <'. trim($email) .'>', $this->charset, 'utf-8');
82                                                        $innerHTML .= '<div class="inactiveResultRow" onclick="selectSuggestion('. $i .')">'.
83                                                                htmlentities($str, ENT_QUOTES, 'utf-8') .'</div>';
84                                                        $jsArray[$email] = addslashes(trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']) .' <'. trim($email) .'>');
85                                                }
86                                                if ($i > 10) break;     // we check for # of results here, as we might have empty email addresses
87                                        }
88                                }
89
90                                if($jsArray) {
91                                        $response->addAssign('resultBox', 'innerHTML', $innerHTML);
92                                        $response->addScript('results = new Array("'.implode('","',$jsArray).'");');
93                                        $response->addScript('displayResultBox();');
94                                }
95                                //$response->addScript("getResults();");
96                                //$response->addScript("selectSuggestion(-1);");
97                        } else {
98                                $response->addAssign('resultBox', 'className', 'resultBoxHidden');
99                        }
100
101                        return $response->getXML();
102                }
103        }
Note: See TracBrowser for help on using the repository browser.