2000-08-18 05:24:22 +02:00
|
|
|
<?php
|
2001-07-03 09:17:13 +02:00
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare - Addressbook *
|
|
|
|
* http://www.phpgroupware.org *
|
|
|
|
* Written by Joseph Engo <jengo@phpgroupware.org> and *
|
|
|
|
* Miles Lott <miloschphpgroupware.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. *
|
|
|
|
\**************************************************************************/
|
2001-02-10 13:56:49 +01:00
|
|
|
|
2001-07-03 09:17:13 +02:00
|
|
|
/* $Id$ */
|
2001-02-10 13:56:49 +01:00
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
$phpgw_info['flags'] = array(
|
|
|
|
'currentapp' => 'addressbook',
|
|
|
|
'enable_contacts_class' => True,
|
|
|
|
'enable_nextmatchs_class' => True
|
2001-02-19 13:14:25 +01:00
|
|
|
);
|
2001-02-13 04:20:33 +01:00
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
include('../header.inc.php');
|
2001-02-10 13:56:49 +01:00
|
|
|
|
2001-05-11 16:01:06 +02:00
|
|
|
$t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
|
2001-05-10 14:21:16 +02:00
|
|
|
$t->set_file(array('addressbook_list_t' => 'index.tpl'));
|
|
|
|
$t->set_block('addressbook_list_t','addressbook_header','addressbook_header');
|
|
|
|
$t->set_block('addressbook_list_t','column','column');
|
|
|
|
$t->set_block('addressbook_list_t','row','row');
|
|
|
|
$t->set_block('addressbook_list_t','addressbook_footer','addressbook_footer');
|
2001-02-10 13:56:49 +01:00
|
|
|
|
2001-07-03 09:17:13 +02:00
|
|
|
$contacts = CreateObject('phpgwapi.contacts');
|
|
|
|
|
2001-03-16 18:56:18 +01:00
|
|
|
$customfields = array();
|
2001-05-06 14:33:36 +02:00
|
|
|
while (list($col,$descr) = @each($phpgw_info['user']['preferences']['addressbook']))
|
|
|
|
{
|
|
|
|
if ( substr($col,0,6) == 'extra_' )
|
|
|
|
{
|
2001-03-16 18:56:18 +01:00
|
|
|
$field = ereg_replace('extra_','',$col);
|
|
|
|
$field = ereg_replace(' ','_',$field);
|
|
|
|
$customfields[$field] = ucfirst($field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
if (!isset($cat_id))
|
|
|
|
{
|
|
|
|
$cat_id = $phpgw_info['user']['preferences']['addressbook']['default_category'];
|
2001-03-29 13:12:03 +02:00
|
|
|
}
|
2001-05-06 14:33:36 +02:00
|
|
|
if ($phpgw_info['user']['preferences']['addressbook']['autosave_category'])
|
|
|
|
{
|
|
|
|
$phpgw->preferences->delete('addressbook','default_category');
|
|
|
|
$phpgw->preferences->add('addressbook','default_category',$cat_id);
|
2001-03-25 09:39:58 +02:00
|
|
|
}
|
2001-03-29 13:12:03 +02:00
|
|
|
$phpgw->preferences->save_repository();
|
2001-03-25 09:39:58 +02:00
|
|
|
|
2001-02-19 14:16:07 +01:00
|
|
|
$extrafields = array(
|
2001-05-06 14:33:36 +02:00
|
|
|
'ophone' => 'ophone',
|
|
|
|
'address2' => 'address2',
|
|
|
|
'address3' => 'address3'
|
2001-02-19 14:16:07 +01:00
|
|
|
);
|
2001-07-03 09:17:13 +02:00
|
|
|
/* $qfields = $contacts->stock_contact_fields + $extrafields + $customfields; */
|
2001-02-10 13:56:49 +01:00
|
|
|
|
2001-07-03 09:17:13 +02:00
|
|
|
/* create column list and the top row of the table based on user prefs */
|
|
|
|
while ($column = each($contacts->stock_contact_fields))
|
2001-05-06 14:33:36 +02:00
|
|
|
{
|
2001-03-22 00:57:30 +01:00
|
|
|
$test = strtolower($column[0]);
|
2001-05-06 14:33:36 +02:00
|
|
|
if (isset($phpgw_info['user']['preferences']['addressbook'][$test]) &&
|
|
|
|
$phpgw_info['user']['preferences']['addressbook'][$test])
|
|
|
|
{
|
2001-03-17 22:29:44 +01:00
|
|
|
$showcol = display_name($column[0]);
|
2001-07-03 09:17:13 +02:00
|
|
|
$cols .= ' <td height="21">' . "\n";
|
2001-03-17 22:29:44 +01:00
|
|
|
$cols .= ' <font size="-1" face="Arial, Helvetica, sans-serif">';
|
2001-03-25 09:56:55 +02:00
|
|
|
$cols .= $phpgw->nextmatchs->show_sort_order($sort,
|
2001-05-03 07:22:19 +02:00
|
|
|
$column[0],$order,"/addressbook/index.php",$showcol,"&cat_id=".$cat_id);
|
2001-03-17 22:29:44 +01:00
|
|
|
$cols .= "</font>\n </td>";
|
|
|
|
$cols .= "\n";
|
|
|
|
|
2001-07-03 09:17:13 +02:00
|
|
|
/* To be used when displaying the rows */
|
2001-03-17 22:29:44 +01:00
|
|
|
$columns_to_display[$column[0]] = True;
|
|
|
|
}
|
|
|
|
}
|
2001-05-06 14:33:36 +02:00
|
|
|
|
2001-03-17 22:29:44 +01:00
|
|
|
$nonstd = $extrafields + $customfields;
|
2001-05-06 14:33:36 +02:00
|
|
|
while ($column = each($nonstd))
|
|
|
|
{
|
2001-03-16 18:56:18 +01:00
|
|
|
$test = strtolower($column[1]);
|
2001-05-06 14:33:36 +02:00
|
|
|
if (isset($phpgw_info['user']['preferences']['addressbook'][$test]) &&
|
|
|
|
$phpgw_info['user']['preferences']['addressbook'][$test])
|
|
|
|
{
|
2001-02-10 13:56:49 +01:00
|
|
|
$showcol = display_name($column[0]);
|
2001-07-03 09:17:13 +02:00
|
|
|
/* This must be a custom field */
|
2001-03-16 18:56:18 +01:00
|
|
|
if (!$showcol) { $showcol = $column[1]; }
|
2001-07-03 09:17:13 +02:00
|
|
|
$cols .= ' <td height="21">' . "\n";
|
2001-02-10 13:56:49 +01:00
|
|
|
$cols .= ' <font size="-1" face="Arial, Helvetica, sans-serif">';
|
2001-03-17 22:29:44 +01:00
|
|
|
$cols .= $showcol;
|
2001-02-10 13:56:49 +01:00
|
|
|
$cols .= "</font>\n </td>";
|
|
|
|
$cols .= "\n";
|
2001-03-08 15:36:35 +01:00
|
|
|
|
2001-07-03 09:17:13 +02:00
|
|
|
/* To be used when displaying the rows */
|
2001-02-10 13:56:49 +01:00
|
|
|
$columns_to_display[$column[0]] = True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
if (!$start)
|
|
|
|
{
|
2001-02-10 13:56:49 +01:00
|
|
|
$start = 0;
|
2001-05-06 14:33:36 +02:00
|
|
|
}
|
2001-02-10 13:56:49 +01:00
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
if($phpgw_info['user']['preferences']['common']['maxmatchs'] &&
|
|
|
|
$phpgw_info['user']['preferences']['common']['maxmatchs'] > 0)
|
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
$limit = $phpgw_info['user']['preferences']['common']['maxmatchs'];
|
2001-05-06 14:33:36 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
$limit = 30;
|
2001-02-10 13:56:49 +01:00
|
|
|
}
|
|
|
|
|
2001-06-24 03:30:37 +02:00
|
|
|
if (!$filter)
|
|
|
|
{
|
2001-06-24 03:59:56 +02:00
|
|
|
if($phpgw_info['user']['preferences']['addressbook']['default_filter'])
|
|
|
|
{
|
|
|
|
$filter = $phpgw_info['user']['preferences']['addressbook']['default_filter'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$filter = 'none';
|
|
|
|
}
|
2001-06-24 03:30:37 +02:00
|
|
|
}
|
2001-03-25 08:02:52 +02:00
|
|
|
|
2001-06-24 03:30:37 +02:00
|
|
|
/*
|
|
|
|
Set qfilter to display entries where tid=n (normal contact entry),
|
|
|
|
else they may be accounts, etc.
|
|
|
|
*/
|
2001-05-23 22:15:40 +02:00
|
|
|
$qfilter = 'tid=n';
|
2001-06-24 03:30:37 +02:00
|
|
|
switch ($filter)
|
|
|
|
{
|
|
|
|
case 'blank':
|
|
|
|
$nosearch = True;
|
|
|
|
break;
|
2001-05-23 22:15:40 +02:00
|
|
|
case 'none':
|
|
|
|
break;
|
|
|
|
case 'private':
|
2001-07-03 09:17:13 +02:00
|
|
|
$qfilter .= ',access=private'; /* fall through */
|
2001-05-23 22:15:40 +02:00
|
|
|
case 'yours':
|
|
|
|
$qfilter .= ',owner='.$phpgw_info['user']['account_id'];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$qfilter .= ',owner='.$filter;
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
2001-06-24 03:30:37 +02:00
|
|
|
if ($cat_id)
|
|
|
|
{
|
2001-05-23 22:15:40 +02:00
|
|
|
$qfilter .= ',cat_id='.$cat_id;
|
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
|
2001-07-03 09:17:13 +02:00
|
|
|
/* Check if prefs were set, if not, create some defaults */
|
2001-05-06 14:33:36 +02:00
|
|
|
if (!$columns_to_display )
|
|
|
|
{
|
2001-03-08 04:26:16 +01:00
|
|
|
$columns_to_display = array(
|
2001-05-06 14:33:36 +02:00
|
|
|
'n_given' => 'n_given',
|
|
|
|
'n_family' => 'n_family',
|
|
|
|
'org_name' => 'org_name'
|
2001-03-08 04:26:16 +01:00
|
|
|
);
|
2001-03-16 18:56:18 +01:00
|
|
|
$columns_to_display = $columns_to_display + $customfields;
|
2001-07-03 09:17:13 +02:00
|
|
|
/* No prefs,. so cols above may have been set to "" or a bunch of <td></td> */
|
2001-05-03 07:22:19 +02:00
|
|
|
$cols="";
|
2001-05-06 14:33:36 +02:00
|
|
|
while ($column = each($columns_to_display))
|
|
|
|
{
|
2001-03-08 15:36:35 +01:00
|
|
|
$showcol = display_name($column[0]);
|
2001-03-16 18:56:18 +01:00
|
|
|
if (!$showcol) { $showcol = $column[1]; }
|
2001-07-03 09:17:13 +02:00
|
|
|
$cols .= ' <td height="21">' . "\n";
|
2001-03-08 15:36:35 +01:00
|
|
|
$cols .= ' <font size="-1" face="Arial, Helvetica, sans-serif">';
|
2001-03-25 09:56:55 +02:00
|
|
|
$cols .= $phpgw->nextmatchs->show_sort_order($sort,
|
|
|
|
$column[0],$order,"/addressbook/index.php",$showcol,"&cat_id=$cat_id");
|
2001-03-08 15:36:35 +01:00
|
|
|
$cols .= "</font>\n </td>";
|
|
|
|
$cols .= "\n";
|
|
|
|
}
|
2001-05-06 14:33:36 +02:00
|
|
|
$noprefs=lang('Please set your preferences for this app');
|
2001-02-10 13:56:49 +01:00
|
|
|
}
|
2001-03-08 13:18:12 +01:00
|
|
|
$qcols = $columns_to_display;
|
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
if (!$userid) { $userid = $phpgw_info['user']['account_id']; }
|
2001-03-26 12:23:30 +02:00
|
|
|
|
2001-06-24 03:30:37 +02:00
|
|
|
if ($nosearch && !$query)
|
|
|
|
{
|
|
|
|
$entries = array();
|
2001-07-03 09:17:13 +02:00
|
|
|
$contacts->total_records = 0;
|
2001-06-24 03:30:37 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* read the entry list */
|
2001-07-03 09:17:13 +02:00
|
|
|
$entries = addressbook_read_entries($start,$limit,$qcols,$query,$qfilter,$sort,$order,$userid);
|
2001-06-24 03:30:37 +02:00
|
|
|
}
|
2001-02-10 13:56:49 +01:00
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
$search_filter = $phpgw->nextmatchs->show_tpl('/addressbook/index.php',
|
2001-07-03 09:17:13 +02:00
|
|
|
$start, $contacts->total_records,"&order=$order&filter=$filter&sort=$sort&query=$query&cat_id=$cat_id","75%",
|
2001-05-03 07:22:19 +02:00
|
|
|
$phpgw_info["theme"]["th_bg"],1,1,1,1);
|
2001-02-10 13:56:49 +01:00
|
|
|
|
2001-07-03 09:17:13 +02:00
|
|
|
$lang_showing = $phpgw->nextmatchs->show_hits($contacts->total_records,$start);
|
2001-02-10 13:56:49 +01:00
|
|
|
|
2001-07-03 09:17:13 +02:00
|
|
|
/* set basic vars and parse the header */
|
2001-05-06 14:33:36 +02:00
|
|
|
$t->set_var(font,$phpgw_info['theme']['font']);
|
|
|
|
$t->set_var('lang_view',lang('View'));
|
|
|
|
$t->set_var('lang_vcard',lang('VCard'));
|
|
|
|
$t->set_var('lang_edit',lang('Edit'));
|
|
|
|
$t->set_var('lang_owner',lang('Owner'));
|
2001-07-03 09:17:13 +02:00
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
$t->set_var('searchreturn',$noprefs . ' ' . $searchreturn);
|
|
|
|
$t->set_var('lang_showing',$lang_showing);
|
|
|
|
$t->set_var('search_filter',$search_filter);
|
|
|
|
$t->set_var('cats',lang('Category'));
|
|
|
|
$t->set_var('cats_url',$phpgw->link('/addressbook/index.php'));
|
|
|
|
$t->set_var('cats_link',cat_option($cat_id));
|
|
|
|
$t->set_var('lang_cats',lang('Select'));
|
|
|
|
$t->set_var('lang_addressbook',lang('Address book'));
|
|
|
|
$t->set_var('th_bg',$phpgw_info['theme']['th_bg']);
|
|
|
|
$t->set_var('th_font',$phpgw_info['theme']['font']);
|
|
|
|
$t->set_var('th_text',$phpgw_info['theme']['th_text']);
|
|
|
|
$t->set_var('lang_add',lang('Add'));
|
|
|
|
$t->set_var('add_url',$phpgw->link('/addressbook/add.php'));
|
|
|
|
$t->set_var('lang_addvcard',lang('AddVCard'));
|
|
|
|
$t->set_var('vcard_url',$phpgw->link('/addressbook/vcardin.php'));
|
|
|
|
$t->set_var('lang_import',lang('Import Contacts'));
|
|
|
|
$t->set_var('import_url',$phpgw->link('/addressbook/import.php'));
|
2001-05-23 22:15:40 +02:00
|
|
|
$t->set_var('lang_import_alt',lang('Alt. CSV Import'));
|
|
|
|
$t->set_var('import_alt_url',$phpgw->link('/addressbook/csv_import.php'));
|
2001-05-06 14:33:36 +02:00
|
|
|
$t->set_var('lang_export',lang('Export Contacts'));
|
|
|
|
$t->set_var('export_url',$phpgw->link('/addressbook/export.php'));
|
|
|
|
$t->set_var('start',$start);
|
|
|
|
$t->set_var('sort',$sort);
|
|
|
|
$t->set_var('order',$order);
|
|
|
|
$t->set_var('filter',$filter);
|
|
|
|
$t->set_var('query',$query);
|
|
|
|
$t->set_var('cat_id',$cat_id);
|
|
|
|
$t->set_var('qfield',$qfield);
|
|
|
|
$t->set_var('query',$query);
|
|
|
|
$t->set_var('start',$start);
|
|
|
|
$t->set_var('filter',$filter);
|
|
|
|
$t->set_var('cols',$cols);
|
2001-07-03 09:17:13 +02:00
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
$t->pparse('out','addressbook_header');
|
2001-02-11 04:23:58 +01:00
|
|
|
|
2001-07-03 09:17:13 +02:00
|
|
|
/* Show the entries */
|
|
|
|
/* each entry */
|
|
|
|
for ($i=0;$i<count($entries);$i++)
|
2001-05-06 14:33:36 +02:00
|
|
|
{
|
|
|
|
$t->set_var('columns','');
|
2001-02-14 01:56:07 +01:00
|
|
|
$tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color);
|
2001-05-06 14:33:36 +02:00
|
|
|
$t->set_var('row_tr_color',$tr_color);
|
|
|
|
$myid = $entries[$i]['id'];
|
|
|
|
$myowner = $entries[$i]['owner'];
|
2001-02-10 13:56:49 +01:00
|
|
|
|
2001-07-03 09:17:13 +02:00
|
|
|
/* each entry column */
|
|
|
|
while ($column = each($columns_to_display))
|
2001-05-06 14:33:36 +02:00
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
$ref = $data='';
|
2001-02-14 01:56:07 +01:00
|
|
|
$coldata = $entries[$i][$column[0]];
|
2001-07-03 09:17:13 +02:00
|
|
|
/* Some fields require special formatting. */
|
2001-05-06 14:33:36 +02:00
|
|
|
if ($column[0] == 'url')
|
|
|
|
{
|
2001-03-12 03:09:57 +01:00
|
|
|
if ( !empty($coldata) && (substr($coldata,0,7) != 'http://') ) { $coldata = 'http://' . $coldata; }
|
2001-02-14 01:56:07 +01:00
|
|
|
$ref='<a href="'.$coldata.'" target="_new">';
|
|
|
|
$data=$coldata.'</a>';
|
2001-05-06 14:33:36 +02:00
|
|
|
}
|
|
|
|
elseif ( ($column[0] == 'email') || ($column[0] == 'email_home') )
|
|
|
|
{
|
|
|
|
if ($phpgw_info['user']['apps']['email'])
|
|
|
|
{
|
2001-05-03 07:22:19 +02:00
|
|
|
$ref='<a href="'.$phpgw->link("/email/compose.php","to=" . urlencode($coldata)).'" target="_new">';
|
2001-05-06 14:33:36 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-02-14 01:56:07 +01:00
|
|
|
$ref='<a href="mailto:'.$coldata.'">';
|
2001-02-10 13:56:49 +01:00
|
|
|
}
|
2001-07-03 09:17:13 +02:00
|
|
|
$data=$coldata . '</a>';
|
2001-05-06 14:33:36 +02:00
|
|
|
}
|
2001-07-03 09:17:13 +02:00
|
|
|
else /* But these do not */
|
2001-05-06 14:33:36 +02:00
|
|
|
{
|
2001-07-03 09:17:13 +02:00
|
|
|
$ref = ''; $data = $coldata;
|
2001-02-10 13:56:49 +01:00
|
|
|
}
|
2001-05-06 14:33:36 +02:00
|
|
|
$t->set_var('col_data',$ref.$data);
|
|
|
|
$t->parse('columns','column',True);
|
2001-02-14 01:56:07 +01:00
|
|
|
}
|
2001-03-18 16:44:30 +01:00
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
if (1)
|
|
|
|
{
|
|
|
|
$t->set_var('row_view_link',$phpgw->link('/addressbook/view.php',
|
2001-05-03 07:22:19 +02:00
|
|
|
"ab_id=$myid&start=$start&order=$order&filter="
|
|
|
|
. "$filter&query=$query&sort=$sort&cat_id=$cat_id"));
|
2001-05-06 14:33:36 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$t->set_var('row_view_link','');
|
|
|
|
$t->set_var('lang_view',lang('Private'));
|
2001-03-18 16:44:30 +01:00
|
|
|
}
|
2001-07-03 09:17:13 +02:00
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
$t->set_var('row_vcard_link',$phpgw->link('/addressbook/vcardout.php',
|
2001-05-03 07:22:19 +02:00
|
|
|
"ab_id=$myid&start=$start&sort=$sort&order=$order&filter="
|
|
|
|
. "$filter&query=$query&sort=$sort&cat_id=$cat_id"));
|
2001-07-03 09:17:13 +02:00
|
|
|
/* echo '<br>: ' . $contacts->grants[$myowner] . ' - ' . $myowner; */
|
|
|
|
if ($contacts->check_perms($contacts->grants[$myowner],PHPGW_ACL_EDIT) || $myowner == $phpgw_info['user']['account_id'])
|
2001-05-06 14:33:36 +02:00
|
|
|
{
|
|
|
|
$t->set_var('row_edit','<a href="' . $phpgw->link("/addressbook/edit.php",
|
2001-05-03 07:22:19 +02:00
|
|
|
"ab_id=$myid&start=$start&sort=$sort&order=$order&filter="
|
|
|
|
. "$filter&query=$query&sort=$sort&cat_id=$cat_id") . '">' . lang('Edit') . '</a>');
|
2001-05-06 14:33:36 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$t->set_var('row_edit',' ');
|
2001-03-18 09:51:03 +01:00
|
|
|
}
|
2001-07-03 09:17:13 +02:00
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
$t->set_var('row_owner',$phpgw->accounts->id2name($myowner));
|
2001-07-03 09:17:13 +02:00
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
$t->parse('rows','row',True);
|
|
|
|
$t->pparse('out','row');
|
2001-07-03 09:17:13 +02:00
|
|
|
reset($columns_to_display);
|
2001-02-10 13:56:49 +01:00
|
|
|
}
|
|
|
|
|
2001-05-06 14:33:36 +02:00
|
|
|
$t->pparse('out','addressbook_footer');
|
2001-02-10 13:56:49 +01:00
|
|
|
$phpgw->common->phpgw_footer();
|
2000-10-27 04:07:59 +02:00
|
|
|
?>
|