Cleanup handling of vcard file import

This commit is contained in:
Miles Lott 2003-12-05 11:27:47 +00:00
parent 2e69a4dfe8
commit f3549ec4d8
2 changed files with 8 additions and 25 deletions

View File

@ -288,30 +288,18 @@
function add_vcard($uploadedfile='') function add_vcard($uploadedfile='')
{ {
if($uploadedfile == 'none' || $uploadedfile == '') if($uploadedfile == 'none' || $uploadedfile == '' || substr($uploadedfile['name'],-4) != '.vcf')
{ {
return False; return False;
} }
else else
{ {
$uploaddir = $GLOBALS['phpgw_info']['server']['temp_dir'] . SEP; $filename = $uploadedfile['tmp_name'];
srand((double)microtime() * 1000000);
$random_number = rand(100000000,999999999);
$newfilename = md5("$uploadedfile, $uploadedfile_name, "
. time() . getenv('REMOTE_ADDR') . $random_number);
copy($uploadedfile, $uploaddir . $newfilename);
$ftp = fopen($uploaddir . $newfilename . '.info','w');
fputs($ftp,"$uploadedfile_type\n$uploadedfile_name\n");
fclose($ftp);
$filename = $uploaddir . $newfilename;
$vcard = CreateObject('phpgwapi.vcard'); $vcard = CreateObject('phpgwapi.vcard');
$entry = $vcard->in_file($filename); $entry = $vcard->in_file($filename);
/* _debug_array($entry);exit; */ /* _debug_array($entry);exit; */
$entry['owner'] = $GLOBALS['phpgw_info']['user']['account_id']; $entry['owner'] = (int)$GLOBALS['phpgw_info']['user']['account_id'];
$entry['access'] = 'private'; $entry['access'] = 'private';
$entry['tid'] = 'n'; $entry['tid'] = 'n';
/* _debug_array($entry);exit; */ /* _debug_array($entry);exit; */
@ -319,10 +307,6 @@
$this->so->add_entry($entry); $this->so->add_entry($entry);
$ab_id = $this->get_lastid(); $ab_id = $this->get_lastid();
/* Delete the temp file. */
unlink($filename);
unlink($filename . '.info');
return(int)$ab_id; return(int)$ab_id;
} }
} }

View File

@ -46,20 +46,19 @@
$uploadedfile = get_var('uploadedfile','FILES'); $uploadedfile = get_var('uploadedfile','FILES');
$action = get_var('action',array('POST','GET')); $action = get_var('action',array('POST','GET'));
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
echo '<body bgcolor="' . $GLOBALS['phpgw_info']['theme']['bg_color'] . '">';
if($uploadedfile) if($uploadedfile)
{ {
$ab_id = $this->bo->add_vcard($uploadedfile); $ab_id = $this->bo->add_vcard($uploadedfile);
if($done) if($ab_id)
{ {
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.view&ab_id=' . $ab_id)); Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.view&ab_id=' . $ab_id));
} }
} }
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
echo '<body bgcolor="' . $GLOBALS['phpgw_info']['theme']['bg_color'] . '">';
if($action == 'GetFile') if($action == 'GetFile')
{ {
echo '<b><center>' . lang('You must select a vcard. (*.vcf)') . '</b></center><br><br>'; echo '<b><center>' . lang('You must select a vcard. (*.vcf)') . '</b></center><br><br>';