forked from extern/egroupware
Horde import plugin from Paco Orozco <pakusland-at-gmail.com>: Patch #37
This commit is contained in:
parent
3d6ef7ce57
commit
e5c82ae4db
115
addressbook/inc/import/Import_from_Horde
Normal file
115
addressbook/inc/import/Import_from_Horde
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Import_from_Horde: Import Horde CSV contacts into eGW AddressBook
|
||||
*
|
||||
* @version 0.0.1
|
||||
* @author Pakus - Paco Orozco <pakus (at) pakusland.net>
|
||||
* @date 20061023
|
||||
* ----------------------------------------------------------------
|
||||
* CHANGELOG:
|
||||
* 20061023
|
||||
* - First version
|
||||
* *****************************************************************
|
||||
*/
|
||||
/*
|
||||
This file defines a set of functions and an associative array.
|
||||
The key of the array corresponds to a header in the source
|
||||
import file and the value of the array item will be used in
|
||||
the creation of the output file.
|
||||
|
||||
The array need not be in any order and any fields not defined will
|
||||
not be transferred. If the val='+', the value will be appended to
|
||||
the previous field and any text after the '+' will be appended
|
||||
before the value. For example, the following would add a comma and
|
||||
a space between LastName and FirstName and store it in FullName:
|
||||
|
||||
array('LastName' => 'FullName','FirstName' => '+, ');
|
||||
|
||||
Also start with a '#' symbol and a comma separated list will be
|
||||
turned into a number of the same entries.
|
||||
*/
|
||||
|
||||
class import_conv
|
||||
{
|
||||
var $currentrecord = array();
|
||||
var $id;
|
||||
var $type = 'csv';
|
||||
|
||||
var $import = array(
|
||||
'name' => 'fn',
|
||||
'email' => 'email',
|
||||
'alias' => '',
|
||||
'homeAddress' => 'adr_one_street',
|
||||
'workAddress' => 'adr_two_street',
|
||||
'homePhone' => 'tel_home',
|
||||
'workPhone' => 'tel_work',
|
||||
'cellPhone' => 'tel_cell',
|
||||
'fax' => 'tel_fax',
|
||||
'title' => 'title',
|
||||
'company' => 'org_name',
|
||||
'freebusyUrl' => '',
|
||||
'notes' => 'note'
|
||||
);
|
||||
|
||||
function import_start_file($buffer)
|
||||
{
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
function import_start_record($buffer)
|
||||
{
|
||||
$top = array();
|
||||
++$this->id;
|
||||
$this->currentrecord = $top;
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
function import_new_attrib($buffer,$name,$value)
|
||||
{
|
||||
$value = trim($value);
|
||||
$value = str_replace('\r','',$value);
|
||||
//
|
||||
// I need to calculate given and family
|
||||
// name from full name
|
||||
if($name == "fn")
|
||||
{
|
||||
list($nom, $cognom) = split(' ', $value, 2);
|
||||
$this->currentrecord += array('n_given' => $nom);
|
||||
$this->currentrecord += array('n_family' => $cognom);
|
||||
}
|
||||
$this->currentrecord += array($name => $value);
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
function import_end_record($buffer)
|
||||
{
|
||||
$buffer[$this->id] = '';
|
||||
while(list($name, $value) = each($this->currentrecord))
|
||||
{
|
||||
$buffer[$this->id][$name] = $value;
|
||||
}
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
function import_end_file($buffer,$access='private',$cat_id=0)
|
||||
{
|
||||
$contacts = CreateObject('phpgwapi.contacts');
|
||||
for($i=1;$i<=count($buffer);$i++)
|
||||
{
|
||||
while(list($name,$value) = @each($buffer[$i]))
|
||||
{
|
||||
$entry[$i][$name] = $value;
|
||||
}
|
||||
$entry[$i]['email_type'] = 'INTERNET';
|
||||
$entry[$i]['email_home_type'] = 'INTERNET';
|
||||
$entry[$i]['adr_one_type'] = 'intl';
|
||||
$entry[$i]['adr_two_type'] = 'intl';
|
||||
$contacts->add($GLOBALS['egw_info']['user']['account_id'],$entry[$i],$access,$cat_id);
|
||||
}
|
||||
$num = $i - 1;
|
||||
return lang('Successfully imported %1 records into your addressbook.',$num);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user