[ 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_Multiple_VCard (source)

   1  <?php
   2  /*
   3    This file defines a set of functions and an associative array.
   4    The key of the array corresponds to a header in the source
   5    import file and the value of the array item will be used in
   6    the creation of the output file.
   7  
   8    The array need not be in any order and any fields not defined will
   9    not be transferred.  If the val='+', the value will be appended to
  10    the previous field and any text after the '+' will be appended 
  11    before the value.  For example, the following would add a comma and
  12    a space between LastName and FirstName and store it in FullName:
  13  
  14       array('LastName' => 'FullName','FirstName' => '+, ');
  15  
  16    Also start with a '#' symbol and a comma separated list will be
  17    turned into a number of the same entries.
  18  */
  19  
  20    /* $Id: Import_Multiple_VCard 18716 2005-07-03 14:15:23Z milosch $ */
  21  
  22      class import_conv
  23      {
  24          var $currentrecord = array(); /* used for buffering to allow uid lines to go first */
  25          var $id;
  26          var $type = 'vcard';
  27  
  28          /* These will hold the class objects */
  29          var $contacts = '';
  30          var $vcard = '';
  31  
  32          /* This will be populated via the vcard->import var */
  33          var $import = array();
  34  
  35  		function import_start_file($buffer)
  36          {
  37              $this->id = 0;
  38              $this->contacts = CreateObject('phpgwapi.contacts');
  39              $this->vcard = CreateObject('phpgwapi.vcard');
  40              $this->import = $this->vcard->import;
  41              return $buffer;
  42          }
  43  
  44  		function import_start_record($buffer)
  45          {
  46              ++$this->id;
  47              $this->currentrecord = array();
  48              return $buffer;
  49          }
  50  
  51  		function import_new_attrib($buffer,$name,$value)
  52          {
  53              $value = trim($value);
  54              $value = str_replace('=0D=0A',"\n",$value);
  55              /* echo '<br>'.$this->id.': '.$name.' => '.$value; */
  56              $this->currentrecord += array($name => $value);
  57  
  58              return $buffer;
  59          }
  60  
  61  		function import_end_record($buffer)
  62          {
  63              $buffer[$this->id]='';
  64              while ( list($name, $value) = each($this->currentrecord))
  65              {
  66                  $buffer[$this->id][$name] = $value;
  67                  /* $buffer[$this->id]['private'] = $private; */
  68                  /* echo '<br>'.$name.' => '.$value; */
  69              }
  70              return $buffer;
  71          }
  72  
  73  		function import_end_file($buffer,$access='private',$cat_id=0)
  74          {
  75              for ($i=1;$i<=count($buffer);$i++)
  76              {
  77                  /*
  78                     Send the entire array to the vcard class in function.
  79                     It will parse the vcard fields and clean the array of extra
  80                     bogus values that get stuffed in.
  81                  */
  82                  $entry = $this->vcard->in($buffer[$i]);
  83                  /* Now actually add the new entry */
  84                  $this->contacts->add($GLOBALS['egw_info']['user']['account_id'],$entry,$access,$cat_id);
  85              }
  86              $num = $i - 1;
  87              return lang('Successfully imported %1 records into your addressbook.',$num);
  88          }
  89      }
  90  ?>


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