2001-07-08 15:54:40 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2004-01-25 23:02:59 +01:00
|
|
|
* eGroupWare - Addressbook *
|
|
|
|
* http://www.egroupware.org *
|
2001-07-08 15:54:40 +02:00
|
|
|
* Written by Joseph Engo <jengo@phpgroupware.org> and *
|
2003-10-19 08:14:21 +02:00
|
|
|
* Miles Lott <milos@groupwhere.org> *
|
2001-07-08 15:54:40 +02:00
|
|
|
* -------------------------------------------- *
|
|
|
|
* 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$ */
|
|
|
|
|
|
|
|
class uivcard
|
|
|
|
{
|
|
|
|
var $template;
|
|
|
|
var $contacts;
|
|
|
|
var $browser;
|
|
|
|
var $vcard;
|
|
|
|
var $bo;
|
|
|
|
|
|
|
|
var $public_functions = array(
|
|
|
|
'in' => True,
|
|
|
|
'out' => True
|
|
|
|
);
|
|
|
|
|
2003-10-19 08:14:21 +02:00
|
|
|
var $extrafields = array(
|
2001-07-08 15:54:40 +02:00
|
|
|
'ophone' => 'ophone',
|
|
|
|
'address2' => 'address2',
|
|
|
|
'address3' => 'address3'
|
|
|
|
);
|
|
|
|
|
|
|
|
function uivcard()
|
|
|
|
{
|
2003-11-19 15:16:15 +01:00
|
|
|
$this->template = &$GLOBALS['phpgw']->template;
|
2001-07-10 21:52:30 +02:00
|
|
|
$this->contacts = CreateObject('phpgwapi.contacts');
|
2001-07-08 15:54:40 +02:00
|
|
|
$this->browser = CreateObject('phpgwapi.browser');
|
|
|
|
$this->vcard = CreateObject('phpgwapi.vcard');
|
|
|
|
$this->bo = CreateObject('addressbook.boaddressbook',True);
|
|
|
|
}
|
|
|
|
|
|
|
|
function in()
|
|
|
|
{
|
2003-11-19 15:16:15 +01:00
|
|
|
$uploadedfile = get_var('uploadedfile','FILES');
|
2003-10-19 08:14:21 +02:00
|
|
|
$action = get_var('action',array('POST','GET'));
|
2001-07-08 15:54:40 +02:00
|
|
|
|
2003-11-19 15:16:15 +01:00
|
|
|
if($uploadedfile)
|
|
|
|
{
|
|
|
|
$ab_id = $this->bo->add_vcard($uploadedfile);
|
2003-12-05 12:27:47 +01:00
|
|
|
if($ab_id)
|
2003-11-19 15:16:15 +01:00
|
|
|
{
|
|
|
|
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.view&ab_id=' . $ab_id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-05 12:27:47 +01:00
|
|
|
$GLOBALS['phpgw']->common->phpgw_header();
|
|
|
|
echo parse_navbar();
|
|
|
|
echo '<body bgcolor="' . $GLOBALS['phpgw_info']['theme']['bg_color'] . '">';
|
|
|
|
|
2003-10-19 08:14:21 +02:00
|
|
|
if($action == 'GetFile')
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
echo '<b><center>' . lang('You must select a vcard. (*.vcf)') . '</b></center><br><br>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->template->set_file(array('vcardin' => 'vcardin.tpl'));
|
|
|
|
|
|
|
|
$this->template->set_var('vcard_header','<p> <b>' . lang('Address book - VCard in') . '</b><hr><p>');
|
2003-11-19 15:16:15 +01:00
|
|
|
$this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uivcard.in'));
|
2001-07-08 15:54:40 +02:00
|
|
|
$this->template->set_var('lang_access',lang('Access'));
|
|
|
|
$this->template->set_var('lang_groups',lang('Which groups'));
|
|
|
|
$this->template->set_var('access_option',$access_option);
|
|
|
|
$this->template->set_var('group_option',$group_option);
|
|
|
|
|
|
|
|
$this->template->pparse('out','vcardin');
|
2003-08-28 16:16:30 +02:00
|
|
|
|
|
|
|
$GLOBALS['phpgw']->common->phpgw_footer();
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function out()
|
|
|
|
{
|
2003-10-19 08:14:21 +02:00
|
|
|
$ab_id = get_var('ab_id',array('GET','POST'));
|
|
|
|
$nolname = get_var('nolname','GET');
|
|
|
|
$nofname = get_var('nofname','GET');
|
2001-07-08 15:54:40 +02:00
|
|
|
|
2002-01-17 04:52:56 +01:00
|
|
|
if($nolname || $nofname)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2002-01-17 04:52:56 +01:00
|
|
|
$GLOBALS['phpgw']->common->phpgw_header();
|
2003-08-28 16:16:30 +02:00
|
|
|
echo parse_navbar();
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
2002-01-17 04:52:56 +01:00
|
|
|
if(!$ab_id)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2002-01-17 04:52:56 +01:00
|
|
|
Header('Location: ' . $GLOBALS['phpgw']->link('/addressbook/index.php'));
|
2003-08-28 16:16:30 +02:00
|
|
|
$GLOBALS['phpgw']->common->phpgw_exit();
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// First, make sure they have permission to this entry
|
2003-08-28 16:16:30 +02:00
|
|
|
$check = $this->bo->read_entry(array('id' => $ab_id, 'fields' => array('owner' => 'owner')));
|
2001-07-08 15:54:40 +02:00
|
|
|
$perms = $this->contacts->check_perms($this->contacts->grants[$check[0]['owner']],PHPGW_ACL_READ);
|
|
|
|
|
2003-10-19 08:14:21 +02:00
|
|
|
if((!$perms) && ($check[0]['owner'] != $GLOBALS['phpgw_info']['user']['account_id']))
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
Header("Location: " . $GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.get_list'));
|
|
|
|
$GLOBALS['phpgw']->common->phpgw_exit();
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
2003-10-19 08:14:21 +02:00
|
|
|
$extrafields = array('address2' => 'address2');
|
2001-07-08 15:54:40 +02:00
|
|
|
$qfields = $this->contacts->stock_contact_fields + $extrafields;
|
|
|
|
|
2001-08-09 02:19:28 +02:00
|
|
|
$fieldlist = $this->bo->read_entry(array('id' => $ab_id, 'fields' => $qfields));
|
2001-07-08 15:54:40 +02:00
|
|
|
$fields = $fieldlist[0];
|
|
|
|
|
|
|
|
$email = $fields['email'];
|
|
|
|
$emailtype = $fields['email_type'];
|
2003-10-19 08:14:21 +02:00
|
|
|
if(!$emailtype)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$fields['email_type'] = 'INTERNET';
|
|
|
|
}
|
|
|
|
$hemail = $fields['email_home'];
|
|
|
|
$hemailtype = $fields['email_home_type'];
|
2003-10-19 08:14:21 +02:00
|
|
|
if(!$hemailtype)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$fields['email_home_type'] = 'INTERNET';
|
|
|
|
}
|
|
|
|
$firstname = $fields['n_given'];
|
|
|
|
$lastname = $fields['n_family'];
|
|
|
|
|
|
|
|
if(!$nolname && !$nofname)
|
|
|
|
{
|
|
|
|
/* First name and last must be in the vcard. */
|
|
|
|
if($lastname == '')
|
|
|
|
{
|
|
|
|
/* Run away here. */
|
2003-08-28 16:16:30 +02:00
|
|
|
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php',"menuaction=addressbook.uivcard.out&nolname=1&ab_id=$ab_id"));
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
if($firstname == '')
|
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php',"menuaction=addressbook.uivcard.out&nofname=1&ab_id=$ab_id"));
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
2003-10-19 08:14:21 +02:00
|
|
|
if($email)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$fn = explode('@',$email);
|
2003-08-28 16:16:30 +02:00
|
|
|
$filename = sprintf("%s.vcf", $fn[0]);
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
2003-10-19 08:14:21 +02:00
|
|
|
elseif($hemail)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
$fn = explode('@',$hemail);
|
2003-08-28 16:16:30 +02:00
|
|
|
$filename = sprintf("%s.vcf", $fn[0]);
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$fn = strtolower($firstname);
|
2003-08-28 16:16:30 +02:00
|
|
|
$filename = sprintf("%s.vcf", $fn);
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// set translation variable
|
|
|
|
$myexport = $this->vcard->export;
|
|
|
|
// check that each $fields exists in the export array and
|
|
|
|
// set a new array to equal the translation and original value
|
2003-10-19 08:14:21 +02:00
|
|
|
while(list($name,$value) = each($fields))
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2003-10-19 08:14:21 +02:00
|
|
|
if($myexport[$name] && ($value != ''))
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2003-08-28 16:16:30 +02:00
|
|
|
//echo '<br>'.$name."=".$fields[$name]."\n";
|
2001-07-08 15:54:40 +02:00
|
|
|
$buffer[$myexport[$name]] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a vcard from this translated array
|
2003-10-19 08:14:21 +02:00
|
|
|
$entry = $this->vcard->out($buffer);
|
2001-07-08 15:54:40 +02:00
|
|
|
// print it using browser class for headers
|
|
|
|
// filename, mimetype, no length, default nocache True
|
|
|
|
$this->browser->content_header($filename,'text/x-vcard');
|
|
|
|
echo $entry;
|
2003-08-28 16:16:30 +02:00
|
|
|
exit;
|
|
|
|
//$GLOBALS['phpgw']->common->exit;
|
2001-07-08 15:54:40 +02:00
|
|
|
} /* !nolname && !nofname */
|
|
|
|
|
|
|
|
if($nofname)
|
|
|
|
{
|
|
|
|
echo '<br><br><center>';
|
|
|
|
echo lang("This person's first name was not in the address book.") .'<br>';
|
|
|
|
echo lang('Vcards require a first name entry.') . '<br><br>';
|
2003-08-28 16:16:30 +02:00
|
|
|
echo '<a href="' . $GLOBALS['phpgw']->link('/addressbook/index.php',
|
|
|
|
"order=$order&start=$start&filter=$filter&query=$query&sort=$sort&cat_id=$cat_id") . '">' . lang('OK') . '</a>';
|
2001-07-08 15:54:40 +02:00
|
|
|
echo '</center>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if($nolname)
|
|
|
|
{
|
|
|
|
echo '<br><br><center>';
|
|
|
|
echo lang("This person's last name was not in the address book.") . '<br>';
|
|
|
|
echo lang('Vcards require a last name entry.') . '<br><br>';
|
2003-08-28 16:16:30 +02:00
|
|
|
echo '<a href="' . $GLOBALS['phpgw']->link('/addressbook/index.php',
|
|
|
|
"order=$order&start=$start&filter=$filter&query=$query&sort=$sort&cat_id=$cat_id") . '">' . lang('OK') . '</a>';
|
2001-07-08 15:54:40 +02:00
|
|
|
echo '</center>';
|
|
|
|
}
|
2003-08-28 16:16:30 +02:00
|
|
|
|
|
|
|
if($nolname || $nofname)
|
|
|
|
{
|
|
|
|
//$GLOBALS['phpgw']->common->phpgw_footer();
|
|
|
|
}
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|