[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/addressbook/inc/import/ -> Import_from_Horde (source)

   1  <?php
   2  /**
   3     * @file
   4     *  Import_from_Horde: Import Horde CSV contacts into eGW AddressBook
   5     *
   6     * @version 0.0.1
   7     * @author Pakus - Paco Orozco <pakus (at) pakusland.net>
   8     * @date 20061023
   9     * ----------------------------------------------------------------
  10     * CHANGELOG:
  11     * 20061023
  12     * - First version
  13     * *****************************************************************
  14     */
  15  /*
  16    This file defines a set of functions and an associative array.
  17    The key of the array corresponds to a header in the source
  18    import file and the value of the array item will be used in
  19    the creation of the output file.
  20  
  21    The array need not be in any order and any fields not defined will
  22    not be transferred.  If the val='+', the value will be appended to
  23    the previous field and any text after the '+' will be appended 
  24    before the value.  For example, the following would add a comma and
  25    a space between LastName and FirstName and store it in FullName:
  26  
  27       array('LastName' => 'FullName','FirstName' => '+, ');
  28  
  29    Also start with a '#' symbol and a comma separated list will be
  30    turned into a number of the same entries.
  31  */
  32  
  33      class import_conv
  34      {
  35          var $currentrecord = array(); 
  36          var $id;
  37          var $type = 'csv';
  38  
  39          var $import = array(
  40              'name'        => 'fn', 
  41              'email'        => 'email',
  42              'alias'        => '',
  43              'homeAddress'    => 'adr_one_street',
  44              'workAddress'    => 'adr_two_street',
  45              'homePhone'    => 'tel_home',
  46              'workPhone'    => 'tel_work',
  47              'cellPhone'    => 'tel_cell',
  48              'fax'        => 'tel_fax',
  49              'title'        => 'title',
  50              'company'    => 'org_name',
  51              'freebusyUrl'    => '',
  52              'notes'        => 'note'
  53          );
  54  
  55  		function import_start_file($buffer)
  56          {
  57              return $buffer;
  58          }
  59  
  60  		function import_start_record($buffer)
  61          {
  62              $top = array();
  63              ++$this->id;
  64              $this->currentrecord = $top;
  65              return $buffer;
  66          }
  67  
  68  		function import_new_attrib($buffer,$name,$value)
  69          {
  70              $value = trim($value);
  71              $value = str_replace('\r','',$value);
  72              //
  73              // I need to calculate given and family 
  74              // name from full name
  75              if($name == "fn")
  76              {
  77                  list($nom, $cognom) = split(' ', $value, 2);
  78                  $this->currentrecord += array('n_given' => $nom);
  79                  $this->currentrecord += array('n_family' => $cognom);
  80              }
  81              $this->currentrecord += array($name => $value);
  82  
  83              return $buffer;
  84          }
  85  
  86  		function import_end_record($buffer)
  87          {
  88              $buffer[$this->id] = '';
  89              while(list($name, $value) = each($this->currentrecord))
  90              {
  91                  $buffer[$this->id][$name] = $value;
  92              }
  93              return $buffer;
  94          }
  95  
  96  		function import_end_file($buffer,$access='private',$cat_id=0)
  97          {
  98              $contacts = CreateObject('phpgwapi.contacts');
  99              for($i=1;$i<=count($buffer);$i++)
 100              {
 101                  while(list($name,$value) = @each($buffer[$i]))
 102                  {
 103                      $entry[$i][$name] = $value;
 104                  }
 105                  $entry[$i]['email_type']      = 'INTERNET';
 106                  $entry[$i]['email_home_type'] = 'INTERNET';
 107                  $entry[$i]['adr_one_type']    = 'intl';
 108                  $entry[$i]['adr_two_type']    = 'intl';
 109                  $contacts->add($GLOBALS['egw_info']['user']['account_id'],$entry[$i],$access,$cat_id);
 110              }
 111              $num = $i - 1;
 112              return lang('Successfully imported %1 records into your addressbook.',$num);
 113          }
 114      }
 115  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7