[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/addressbook/inc/export/ -> eGroupWare_SQL (source)

   1  <?php
   2  // This file defines a set of functions and an associative array.
   3  // The key of the array corresponds to a header in the source
   4  // export file and the value of the array item will be used in
   5  // the creation of the output file.
   6  //
   7  // The array need not be in any order and any fields not defined will
   8  // not be transferred.  If the val='+', the value will be appended to
   9  // the previous field and any text after the '+' will be appended 
  10  // before the value.  For example, the following would add a comma and
  11  // a space between LastName and FirstName and store it in FullName:
  12  //
  13  //    array("LastName" => "FullName","FirstName" => "+, ");
  14  //
  15  // Also start with a '#' symbol and a comma separated list will be
  16  // turned into a number of the same entries.
  17  
  18      class export_conv
  19      {
  20          var $currentrecord = array(); //used for buffering to allow uid lines to go first
  21          var $id;
  22          //list of all id's
  23          var $ids = array();
  24          var $type = 'sql';
  25                  
  26          var $export= array(
  27              'id'                  => 'id',
  28              'lid'                 => 'lid',
  29              'tid'                 => 'tid',
  30              'owner'               => 'owner',
  31              'fn'                  => 'fn',
  32              'n_given'             => 'n_given',
  33              'n_family'            => 'n_family',
  34              'n_middle'            => 'n_middle',
  35              'n_prefix'            => 'n_prefix',
  36              'n_suffix'            => 'n_suffix',
  37              'sound'               => 'sound',
  38              'bday'                => 'bday',
  39              'note'                => 'note',
  40              'tz'                  => 'tz',
  41              'geo'                 => 'geo',
  42              'url'                 => 'url',
  43              'pubkey'              => 'pubkey',
  44  
  45              'org_name'            => 'org_name',
  46              'org_unit'            => 'org_unit',
  47              'title'               => 'title',
  48  
  49              'adr_one_street'      => 'adr_one_street',
  50              'adr_one_locality'    => 'adr_one_locality', 
  51              'adr_one_region'      => 'adr_one_region', 
  52              'adr_one_postalcode'  => 'adr_one_postalcode',
  53              'adr_one_countryname' => 'adr_one_countryname',
  54              'adr_one_type'        => 'adr_one_type',
  55              'label'               => 'label',
  56  
  57              'adr_two_street'      => 'adr_two_street',
  58              'adr_two_locality'    => 'adr_two_locality', 
  59              'adr_two_region'      => 'adr_two_region', 
  60              'adr_two_postalcode'  => 'adr_two_postalcode',
  61              'adr_two_countryname' => 'adr_two_countryname',
  62              'adr_two_type'        => 'adr_two_type',
  63  
  64              'tel_work'            => 'tel_work',
  65              'tel_home'            => 'tel_home',
  66              'tel_voice'           => 'tel_voice',
  67              'tel_fax'             => 'tel_fax', 
  68              'tel_msg'             => 'tel_msg',
  69              'tel_cell'            => 'tel_cell',
  70              'tel_pager'           => 'tel_pager',
  71              'tel_bbs'             => 'tel_bbs',
  72              'tel_modem'           => 'tel_modem',
  73              'tel_car'             => 'tel_car',
  74              'tel_isdn'            => 'tel_isdn',
  75              'tel_video'           => 'tel_video',
  76              'tel_prefer'          => 'tel_prefer',
  77              'email'               => 'email',
  78              'email_type'          => 'email_type',
  79              'email_home'          => 'email_home',
  80              'email_home_type'     => 'email_home_type'
  81          );
  82  
  83          // This will store the contacts object
  84          var $contacts = '';
  85  
  86          // Read full list of user's contacts only to get id's for each
  87  		function export_start_file($buffer,$ncat_id='')
  88          {
  89              $this->id=-1;
  90              if ($ncat_id)
  91              {
  92                  $filter = 'tid=n,cat_id=' . $ncat_id;
  93              }
  94              else
  95              {
  96                  $filter = 'tid=n';
  97              }
  98              $this->contacts = CreateObject('phpgwapi.contacts');
  99  
 100              $tmp = $this->contacts->read('','',array('id'=>'id'),'',$filter);
 101              for ($i=0;$i<count($tmp);$i++)
 102              {
 103                  $this->ids[$i] = $tmp[$i]['id'];
 104              }
 105              // $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc...
 106              // $buffer is still empty
 107              return $buffer;
 108          }
 109  
 110          // Read each entry
 111  		function export_start_record($buffer)
 112          {
 113              $this->id++;
 114              $top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields);
 115              $this->currentrecord = $top[0];
 116              return $buffer;
 117          }
 118  
 119          // Read each attribute, populate buffer array
 120          // name/value are the fields from the export array above
 121  		function export_new_attrib($buffer,$name,$value)
 122          {
 123              if ($this->export[$name])
 124              {
 125                  $buffer[$this->id][$this->export[$name]] = $value;
 126                  //echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]];
 127              }
 128              return $buffer;
 129          }
 130  
 131          // Tack on some extra values - none for this file
 132  		function export_end_record($buffer)
 133          {
 134              return $buffer;
 135          }
 136  
 137          // Parse it all into a string
 138  		function export_end_file($buffer)
 139          {
 140              $top = 'INSERT INTO egw_addressbook(';
 141              reset($this->ids);
 142              for ($i=0;$i<count($this->ids);$i++)
 143              {
 144                  reset($this->export);
 145                  $fields = $values = "";
 146                  while (list($name,$value) = each($this->export))
 147                  {
 148                      $fields .= $value . ",";
 149                      $values .= "'" . $buffer[$i][$value] . "',";
 150                  }
 151                  $fields = substr($fields,0,-1) . ")\n VALUES(";
 152                  $values = substr($values,0,-1) . ");\n";
 153                  $entries .= $top . $fields . $values;
 154              }
 155              $buffer = $entries;
 156              return $buffer;
 157          }
 158      }
 159  ?>


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