2003-11-02 20:12:52 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* eGroupWare - email/addressbook *
|
|
|
|
* http://www.eGroupWare.org *
|
|
|
|
* Originaly written by Bettina Gille [ceb@phpgroupware.org] *
|
|
|
|
* ----------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw_info']['flags'] = array(
|
2003-11-02 20:12:52 +01:00
|
|
|
'noheader' => True,
|
|
|
|
'nonavbar' => True,
|
2004-08-29 21:08:50 +02:00
|
|
|
'currentapp' => 'addressbook',
|
2003-11-02 20:12:52 +01:00
|
|
|
'enable_nextmatchs_class' => True
|
|
|
|
);
|
2004-06-16 08:39:18 +02:00
|
|
|
|
2003-11-02 20:12:52 +01:00
|
|
|
include('../header.inc.php');
|
2004-06-16 08:39:18 +02:00
|
|
|
|
|
|
|
// add a content-type header to overwrite an existing default charset in apache (AddDefaultCharset directiv)
|
2005-11-03 15:33:39 +01:00
|
|
|
header('Content-type: text/html; charset='.$GLOBALS['egw']->translation->charset());
|
2004-06-16 08:39:18 +02:00
|
|
|
|
2005-11-03 15:33:39 +01:00
|
|
|
include('templates/'.$GLOBALS['egw_info']['user']['preferences']['common']['template_set'].'/head.inc.php');
|
2003-11-02 20:12:52 +01:00
|
|
|
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_root(EGW_TEMPLATE_DIR);
|
|
|
|
$GLOBALS['egw']->template->set_file(array(
|
2003-11-02 20:12:52 +01:00
|
|
|
'addressbook_list_t' => 'addressbook.tpl',
|
|
|
|
));
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_block('addressbook_list_t','addressbook_list','list');
|
2003-11-02 20:12:52 +01:00
|
|
|
|
2005-11-03 15:33:39 +01:00
|
|
|
$contacts =& CreateObject('phpgwapi.contacts');
|
|
|
|
$cats =& CreateObject('phpgwapi.categories','','addressbook');
|
2003-11-02 20:12:52 +01:00
|
|
|
|
|
|
|
$include_personal = True;
|
|
|
|
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var(array(
|
2003-11-02 20:12:52 +01:00
|
|
|
'lang_search' => lang('Search'),
|
|
|
|
'lang_select_cats' => lang('Show all categorys'),
|
|
|
|
'lang_done' => lang('Done'),
|
|
|
|
'to' => lang('To'),
|
|
|
|
'cc' => lang('Cc'),
|
|
|
|
'bcc' => lang('Bcc'),
|
|
|
|
'lang_email' => lang('Select work email address'),
|
|
|
|
'lang_hemail' => lang('Select home email address'),
|
2003-11-03 01:29:11 +01:00
|
|
|
'lang_to_title' => lang('Select all %1 %2 for %3')
|
2003-11-02 20:12:52 +01:00
|
|
|
));
|
|
|
|
|
2003-12-20 19:26:24 +01:00
|
|
|
$start = (int)get_var('start',array('POST','GET'),0);
|
2003-11-02 20:12:52 +01:00
|
|
|
$filter = get_var('filter',array('POST','GET'),'none');
|
2003-12-20 19:26:24 +01:00
|
|
|
$cat_id = (int)get_var('cat_id',array('POST','GET'),0);
|
2003-11-02 20:12:52 +01:00
|
|
|
$query = get_var('query',array('POST','GET'));
|
|
|
|
$sort = get_var('sort',array('POST','GET'));
|
|
|
|
$order = get_var('order',array('POST','GET'));
|
2003-11-03 01:29:11 +01:00
|
|
|
list($all) = @each($_POST['all']);
|
|
|
|
$inserted = $_GET['inserted'];
|
2003-11-02 20:12:52 +01:00
|
|
|
|
|
|
|
$common_vars = array(
|
|
|
|
'filter' => $filter,
|
|
|
|
'cat_id' => $cat_id,
|
|
|
|
'query' => $query,
|
|
|
|
'sort' => $sort,
|
|
|
|
'order' => $order,
|
|
|
|
);
|
|
|
|
|
|
|
|
$link = '/phpgwapi/addressbook.php';
|
2005-11-03 15:33:39 +01:00
|
|
|
$full_link = $GLOBALS['egw']->link($link,$common_vars+array(
|
2003-11-02 20:12:52 +01:00
|
|
|
'start' => $start,
|
2003-11-03 01:29:11 +01:00
|
|
|
));
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('form_action',$full_link);
|
2003-11-02 20:12:52 +01:00
|
|
|
|
|
|
|
$qfilter = 'tid=n';
|
|
|
|
switch($filter)
|
|
|
|
{
|
|
|
|
case 'none':
|
|
|
|
break;
|
|
|
|
case 'private':
|
|
|
|
$qfilter .=',access=private';
|
|
|
|
// fall-through
|
|
|
|
case 'yours':
|
2005-11-03 15:33:39 +01:00
|
|
|
$qfilter .= ',owner='.$GLOBALS['egw_info']['user']['account_id'];
|
2003-11-02 20:12:52 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if(is_numeric($filter))
|
|
|
|
{
|
|
|
|
$qfilter = ',owner='.$filter;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cat_id)
|
|
|
|
{
|
|
|
|
$qfilter .= ',cat_id='.$cat_id;
|
|
|
|
}
|
|
|
|
|
2005-11-03 15:33:39 +01:00
|
|
|
if ($GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] > 0)
|
2003-11-02 20:12:52 +01:00
|
|
|
{
|
2005-11-03 15:33:39 +01:00
|
|
|
$offset = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
|
2003-11-02 20:12:52 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$offset = 15;
|
|
|
|
}
|
|
|
|
|
2005-11-03 15:33:39 +01:00
|
|
|
$account_id = $GLOBALS['egw_info']['user']['account_id'];
|
2003-11-02 20:12:52 +01:00
|
|
|
|
|
|
|
$cols = array (
|
|
|
|
'n_given' => 'n_given',
|
|
|
|
'n_family' => 'n_family',
|
|
|
|
'org_name' => 'org_name',
|
|
|
|
'email' => 'email',
|
|
|
|
'email_home' => 'email_home'
|
|
|
|
);
|
|
|
|
|
2003-11-03 01:29:11 +01:00
|
|
|
if ($all)
|
|
|
|
{
|
|
|
|
$qfilter .= ',email'.($all[0] == 'h' ? '_home' : '')."=!''";
|
2006-04-25 21:09:39 +02:00
|
|
|
$entries = $contacts->read(0,0,$cols,$query,$qfilter,$sort,$order);
|
2003-11-03 01:29:11 +01:00
|
|
|
//echo "<pre>".print_r($entries,True)."</pre>\n";
|
|
|
|
if (!$entries)
|
|
|
|
{
|
|
|
|
$all = False;
|
|
|
|
$inserted = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$all)
|
|
|
|
{
|
2006-04-25 21:09:39 +02:00
|
|
|
$entries = $contacts->read($start,$offset,$cols,$query,$qfilter,$sort,$order);
|
2003-11-03 01:29:11 +01:00
|
|
|
}
|
2003-11-02 20:12:52 +01:00
|
|
|
//------------------------------------------- nextmatch --------------------------------------------
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('left',$GLOBALS['egw']->nextmatchs->left(
|
2003-11-02 20:12:52 +01:00
|
|
|
$link,$start,$contacts->total_records,'&'.explode('&',$common_vars)));
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('right',$GLOBALS['egw']->nextmatchs->right(
|
2003-11-02 20:12:52 +01:00
|
|
|
$link,$start,$contacts->total_records,'&'.explode('&',$common_vars)));
|
|
|
|
foreach(array(
|
|
|
|
'n_given' => lang('Firstname'),
|
|
|
|
'n_family' => lang('Lastname'),
|
|
|
|
'org_name' => lang('Company'),
|
|
|
|
) as $col => $translation)
|
|
|
|
{
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('sort_'.$col,$GLOBALS['egw']->nextmatchs->show_sort_order(
|
2003-11-02 20:12:52 +01:00
|
|
|
$sort,$col,$order,$link,$translation,'&cat_id='.$cat_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($contacts->total_records > $offset)
|
|
|
|
{
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('lang_showing',lang('showing %1 - %2 of %3',
|
2003-11-02 20:12:52 +01:00
|
|
|
1+$start,$start+$offset>$contacts->total_records ? $contacts->total_records : $start+$offset,
|
|
|
|
$contacts->total_records));
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('lang_showing',lang('showing %1',$contacts->total_records));
|
2003-11-02 20:12:52 +01:00
|
|
|
}
|
|
|
|
// --------------------------------------- end nextmatch ------------------------------------------
|
|
|
|
|
2003-11-03 01:29:11 +01:00
|
|
|
foreach(array(
|
|
|
|
'work' => lang('work email'),
|
|
|
|
'home' => lang('home email')
|
|
|
|
) as $type => $lang_type)
|
|
|
|
{
|
|
|
|
foreach(array(
|
|
|
|
'to' => lang('To'),
|
|
|
|
'cc' => lang('Cc'),
|
|
|
|
'bcc'=> lang('Bcc')) as $target => $lang_target)
|
|
|
|
{
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('title_'.$type.'_'.$target,
|
2003-11-03 01:29:11 +01:00
|
|
|
lang('Insert all %1 addresses of the %2 contacts in %3',$lang_type,
|
|
|
|
$contacts->total_records,$lang_target));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-02 20:12:52 +01:00
|
|
|
// ------------------- list header variable template-declaration -----------------------
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('cats_list',$cats->formated_list('select','all',$cat_id,'True'));
|
2003-11-02 20:12:52 +01:00
|
|
|
|
|
|
|
$filter_list = '';
|
|
|
|
foreach(array(
|
|
|
|
'none' => lang('Show all'),
|
|
|
|
'yours' => lang('Only yours'),
|
|
|
|
'private' => lang('Only private'),
|
|
|
|
) as $id => $translation)
|
|
|
|
{
|
|
|
|
$filter_list .= "<option value=\"$id\"".($filter == $id ? ' selected':'').">$translation</option>\n";
|
|
|
|
}
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var(array(
|
2003-11-02 20:12:52 +01:00
|
|
|
'query' => $query,
|
|
|
|
'filter_list' => $filter_list,
|
|
|
|
));
|
|
|
|
// --------------------------- end header declaration ----------------------------------
|
|
|
|
|
2003-11-03 01:29:11 +01:00
|
|
|
$all_emails = array();
|
|
|
|
if ($entries)
|
|
|
|
foreach ($entries as $entry)
|
2003-11-02 20:12:52 +01:00
|
|
|
{
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('tr_class',
|
|
|
|
$GLOBALS['egw']->nextmatchs->alternate_row_color('',True));
|
2003-11-02 20:12:52 +01:00
|
|
|
|
2003-11-03 01:29:11 +01:00
|
|
|
$firstname = $entry['n_given'];
|
2003-11-02 20:12:52 +01:00
|
|
|
if (!$firstname)
|
|
|
|
{
|
|
|
|
$firstname = ' ';
|
|
|
|
}
|
2003-11-03 01:29:11 +01:00
|
|
|
$lastname = $entry['n_family'];
|
2003-11-02 20:12:52 +01:00
|
|
|
if (!$lastname)
|
|
|
|
{
|
|
|
|
$lastname = ' ';
|
|
|
|
}
|
|
|
|
// thanks to dave.hall@mbox.com.au for adding company
|
2003-11-03 01:29:11 +01:00
|
|
|
$company = $entry['org_name'];
|
2003-11-02 20:12:52 +01:00
|
|
|
if (!$company)
|
|
|
|
{
|
|
|
|
$company = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
$personal_firstname = '';
|
|
|
|
$personal_lastname = '';
|
|
|
|
$personal_part = '';
|
|
|
|
if ((isset($firstname)) &&
|
|
|
|
($firstname != '') &&
|
|
|
|
($firstname != ' '))
|
|
|
|
{
|
|
|
|
$personal_firstname = $firstname.' ';
|
|
|
|
}
|
|
|
|
if ((isset($lastname)) &&
|
|
|
|
($lastname != '') &&
|
|
|
|
($lastname != ' '))
|
|
|
|
{
|
|
|
|
$personal_lastname = $lastname;
|
|
|
|
}
|
|
|
|
$personal_part = $personal_firstname.$personal_lastname;
|
|
|
|
|
|
|
|
if (($personal_part == '') ||
|
|
|
|
($include_personal == False))
|
|
|
|
{
|
2003-11-03 01:29:11 +01:00
|
|
|
$id = $entry['id'];
|
|
|
|
$email = $entry['email'];
|
|
|
|
$hemail = $entry['email_home'];
|
2003-11-02 20:12:52 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-03 01:29:11 +01:00
|
|
|
$id = $entry['id'];
|
|
|
|
if ((isset($entry['email'])) &&
|
|
|
|
(trim($entry['email']) != ''))
|
2003-11-02 20:12:52 +01:00
|
|
|
{
|
2003-11-03 01:29:11 +01:00
|
|
|
$email = '"'.$personal_part.'" <'.$entry['email'].'>';
|
2003-11-02 20:12:52 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-03 01:29:11 +01:00
|
|
|
$email = $entry['email'];
|
2003-11-02 20:12:52 +01:00
|
|
|
}
|
2003-11-03 01:29:11 +01:00
|
|
|
if ((isset($entry['email_home'])) &&
|
|
|
|
(trim($entry['email_home']) != ''))
|
2003-11-02 20:12:52 +01:00
|
|
|
{
|
2003-11-03 01:29:11 +01:00
|
|
|
$hemail = '"'.$personal_part.'" <'.$entry['email_home'].'>';
|
2003-11-02 20:12:52 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-03 01:29:11 +01:00
|
|
|
$hemail = $entry['email_home'];
|
2003-11-02 20:12:52 +01:00
|
|
|
}
|
|
|
|
}
|
2003-11-03 01:29:11 +01:00
|
|
|
if ($all)
|
|
|
|
{
|
|
|
|
$all_emails[] = $all[0] == 'h' ? $hemail : $email;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$email = htmlspecialchars($email);
|
|
|
|
$hemail = htmlspecialchars($hemail);
|
|
|
|
|
|
|
|
// --------------------- template declaration for list records --------------------------
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var(array(
|
2003-11-03 01:29:11 +01:00
|
|
|
'firstname' => $firstname,
|
|
|
|
'lastname' => $lastname,
|
|
|
|
'company' => $company
|
|
|
|
));
|
|
|
|
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('id',$id);
|
|
|
|
$GLOBALS['egw']->template->set_var('email',$email);
|
|
|
|
$GLOBALS['egw']->template->set_var('hemail',$hemail);
|
2003-11-03 01:29:11 +01:00
|
|
|
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->parse('list','addressbook_list',True);
|
2003-11-03 01:29:11 +01:00
|
|
|
}
|
2003-11-02 20:12:52 +01:00
|
|
|
}
|
|
|
|
// --------------------------- end record declaration ---------------------------
|
|
|
|
|
2003-11-03 01:29:11 +01:00
|
|
|
if ($all && count($all_emails))
|
|
|
|
{
|
|
|
|
$full_link .= '&inserted='.count($all_emails);
|
|
|
|
$target = substr($all,1);
|
|
|
|
echo "<script type=\"text/javascript\">
|
|
|
|
if (opener.document.doit.$target.value != '')
|
|
|
|
{
|
|
|
|
opener.document.doit.$target.value += ',';
|
|
|
|
}
|
|
|
|
opener.document.doit.$target.value += '".str_replace("'","\\'",implode(',',$all_emails))."';
|
|
|
|
window.location.href = '$full_link';
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($inserted || $inserted === 0)
|
|
|
|
{
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('message','<b>'.
|
2003-12-20 19:26:24 +01:00
|
|
|
lang('%1 email addresses inserted',(int)$_GET['inserted']).'</b>');
|
2003-11-03 01:29:11 +01:00
|
|
|
}
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->template->parse('out','addressbook_list_t',True);
|
|
|
|
$GLOBALS['egw']->template->p('out');
|
2003-11-03 01:29:11 +01:00
|
|
|
}
|
2005-11-03 15:33:39 +01:00
|
|
|
$GLOBALS['egw']->common->egw_exit();
|
2003-11-02 20:12:52 +01:00
|
|
|
?>
|