do some search addresses action for the taglist

This commit is contained in:
Klaus Leithoff 2013-07-20 09:27:37 +00:00
parent 40029aa9bf
commit 14db2bd42e
3 changed files with 94 additions and 9 deletions

View File

@ -2489,6 +2489,94 @@ $content['mailtext'] = 'garbage';
return $_string;
}
}
}
function ajax_decodeFolderName($_folderName) {
$folderName = translation::convert(html_entity_decode($_folderName, ENT_QUOTES, $this->charset),'UTF7-IMAP', $this->charset);
//$response->add("decodedFolder ='".$folderName."'");
$results = array();
header('Content-Type: application/json; charset=utf-8');
echo json_encode($results);
common::egw_exit();
}
?>
function ajax_searchAddress() {
$_searchString = trim($_REQUEST['query']);
if (strlen($_searchString)>=3 && $GLOBALS['egw_info']['user']['apps']['addressbook']) {
//error_log(__METHOD__.__LINE__.array2string($_searchString));
if (method_exists($GLOBALS['egw']->contacts,'search')) {
// 1.3+
$showAccounts = empty($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']);
//error_log(__METHOD__.__LINE__.$_searchString);
$seStAr = explode(' ',$_searchString);
foreach ($seStAr as $k => $v) if (strlen($v)<3) unset($seStAr[$k]);
$_searchString = trim(implode(' AND ',$seStAr));
//error_log(__METHOD__.__LINE__.$_searchString);
$filter = ($showAccounts?array():array('account_id' => null));
$filter['cols_to_search']=array('n_prefix','n_given','n_family','org_name','email','email_home');
$contacts = $GLOBALS['egw']->contacts->search(implode(' +',$seStAr),array('n_fn','n_prefix','n_given','n_family','org_name','email','email_home'),'n_fn','','%',false,'OR',array(0,100),$filter);
// additionally search the accounts, if the contact storage is not the account storage
if ($showAccounts && $GLOBALS['egw']->contacts->so_accounts)
{
$accounts = $GLOBALS['egw']->contacts->search(array(
'n_prefix' => $_searchString,
'n_given' => $_searchString,
'n_family' => $_searchString,
'org_name' => $_searchString,
'email' => $_searchString,
'email_home' => $_searchString,
),array('n_fn','n_prefix','n_given','n_family','org_name','email','email_home'),'n_fn','','%',false,'OR',array(0,100),array('owner' => 0));
if ($contacts && $accounts)
{
$contacts = array_merge($contacts,$accounts);
usort($contacts,create_function('$a,$b','return strcasecmp($a["n_fn"],$b["n_fn"]);'));
}
elseif($accounts)
{
$contacts =& $accounts;
}
unset($accounts);
}
} else {
// < 1.3
$contacts = $GLOBALS['egw']->contacts->read(0,20,array(
'fn' => 1,
'email' => 1,
'email_home' => 1,
), $_searchString, 'tid=n', '', 'fn');
}
}
$results = array();
if(is_array($contacts)) {
foreach($contacts as $contact) {
foreach(array($contact['email'],$contact['email_home']) as $email) {
// avoid wrong addresses, if an rfc822 encoded address is in addressbook
$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/",'$2',$email);
if (method_exists($GLOBALS['egw']->contacts,'search'))
{
$contact['n_fn']='';
if (!empty($contact['n_prefix'])) $contact['n_fn'] = $contact['n_prefix'];
if (!empty($contact['n_given'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_given'];
if (!empty($contact['n_family'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_family'];
if (!empty($contact['org_name'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').'('.$contact['org_name'].')';
$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
}
else
{
$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
}
$completeMailString = trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']) .' <'. trim($email) .'>';
if(!empty($email) && in_array($completeMailString ,$results) === false) {
$results[] = array('id'=>$completeMailString, 'label' => htmlspecialchars($completeMailString));
}
if ($i > 10) break; // we check for # of results here, as we might have empty email addresses
}
}
}
//error_log(__METHOD__.__LINE__.array2string($jsArray));
header('Content-Type: application/json; charset=utf-8');
echo json_encode($results);
common::egw_exit();
}
}

View File

@ -1620,6 +1620,7 @@ unset($query['actions']);
}
// Set up data for taglist widget(s)
if ($envelope['FROM']==$envelope['SENDER']) unset($envelope['SENDER']);
foreach(array('SENDER','FROM','TO','CC','BCC') as $field)
{
foreach($envelope[$field] as $field_data)

View File

@ -6,19 +6,15 @@
<vbox class="mailCompose mailComposeHeaderSection" width="100%">
<hbox class="mailComposeHeaders" width="100%">
<description value="From"/>
<html id="mail_composefromaddress" readonly="true"/>
</hbox>
<hbox class="mailComposeHeaders" width="100%">
<description value="on behalf of"/>
<html id="mail_composeonbehalfofaddress" readonly="true"/>
<taglist id="TO" autocomplete_url='mail.mail_compose.ajax_searchAddress' autocomplete_params='' onclick="app.mail.address_click"/>
</hbox>
<hbox class="mailComposeHeaders" width="100%">
<description value="Cc"/>
<html id="mail_composeccaddress" readonly="true"/>
<taglist id="CC" onclick="app.mail.address_click"/>
</hbox>
<hbox class="mailComposeHeaders" width="100%">
<description value="Bcc"/>
<html id="mail_composebccaddress" readonly="true"/>
<taglist id="BCC" onclick="app.mail.address_click"/>
</hbox>
<hbox class="mailComposeHeaders" width="100%">
<description value="Date"/>