[ Index ]

Source Code Reference for V1.00

title

Body

[close]

/modules/contacts/ -> vcardimport.php (source)

   1  <?php /* CONTACTS $Id: vcardimport.php,v 1.4.12.3 2007/03/06 00:34:40 merlinyoda Exp $ */
   2  if (!defined('W2P_BASE_DIR')) {
   3      die('You should not access this file directly.');
   4  }
   5  
   6  $canEdit = !getDenyEdit('contacts');
   7  if (!$canEdit) {
   8      $AppUI->redirect('m=public&a=access_denied');
   9  }
  10  
  11  // check whether vCard file should be fetched from source or parsed for vCardKeys; criteria: get parameters
  12  if (isset($_FILES['vcf']) && isset($_GET['suppressHeaders']) && (w2PgetParam($_GET, 'suppressHeaders', null) == 'true')) { //parse and store vCard file
  13  
  14      $vcf = $_FILES['vcf'];
  15      // include PEAR vCard class
  16      require_once ($AppUI->getLibraryClass('PEAR/Contact_Vcard_Parse'));
  17  
  18      if (is_uploaded_file($vcf['tmp_name'])) {
  19  
  20          // instantiate a parser object
  21          $parse = new Contact_Vcard_Parse();
  22  
  23          // parse a vCard file and store the data
  24          // in $cardinfo
  25          $cardinfo = $parse->fromFile($vcf['tmp_name']);
  26  
  27          // store the card info array
  28  
  29          foreach ($cardinfo as $ci) { //one file can contain multiple vCards
  30  
  31              $obj = new CContact();
  32  
  33              //transform the card info array to w2P store format
  34              $contactValues['contact_last_name'] = $ci['N'][0]['value'][0][0];
  35              $contactValues['contact_first_name'] = $ci['N'][0]['value'][1][0];
  36              $contactValues['contact_title'] = $ci['N'][0]['value'][3][0];
  37              $contactValues['contact_birthday'] = $ci['BDAY'][0]['value'][0][0];
  38              $contactValues['contact_company'] = $ci['UID'][0]['value'][0][0];
  39              $contactValues['contact_type'] = $ci['N'][0]['value'][2][0];
  40              $contactValues['contact_email'] = $ci['EMAIL'][0]['value'][0][0];
  41              $contactValues['contact_email2'] = $ci['EMAIL'][1]['value'][0][0];
  42              $contactValues['contact_phone'] = $ci['TEL'][0]['value'][0][0];
  43              $contactValues['contact_phone2'] = $ci['TEL'][1]['value'][0][0];
  44              $contactValues['contact_mobile'] = $ci['TEL'][2]['value'][0][0];
  45              $contactValues['contact_address1'] = $ci['ADR'][0]['value'][2][0];
  46              $contactValues['contact_address2'] = $ci['ADR'][0]['value'][1][0] . ', ' . $ci['ORG'][0]['value'][0][0];
  47              $contactValues['contact_city'] = $ci['ADR'][0]['value'][3][0];
  48              $contactValues['contact_state'] = $ci['ADR'][0]['value'][4][0];
  49              $contactValues['contact_zip'] = $ci['ADR'][0]['value'][5][0];
  50              $contactValues['contact_country'] = $ci['ADR'][0]['value'][6][0];
  51              $contactValues['contact_notes'] = $ci['NOTE'][0]['value'][0][0];
  52              $contactValues['contact_order_by'] = $contactValues['contact_first_name'] . ' ' . $contactValues['contact_last_name'];
  53              $contactValues['contact_id'] = 0;
  54  
  55              // bind array to object
  56              if (!$obj->bind($contactValues)) {
  57                  $AppUI->setMsg($obj->getError(), UI_MSG_ERROR);
  58                  $AppUI->redirect();
  59              }
  60  
  61              // store vCard data for this object
  62              if (($msg = $obj->store())) {
  63                  $AppUI->setMsg($msg, UI_MSG_ERROR);
  64              }
  65          }
  66          // one or more vCard imports were successful
  67          $AppUI->setMsg('vCard(s) imported', UI_MSG_OK, true);
  68          $AppUI->redirect();
  69  
  70      } else { // redirect in case of file upload trouble
  71          $AppUI->setMsg('vCardFileUploadError', UI_MSG_ERROR);
  72          $AppUI->redirect();
  73      }
  74  } elseif (isset($_GET['dialog']) && (w2PgetParam($_GET, 'dialog', null) == '0')) { //file upload formular
  75  
  76      $titleBlock = new CTitleBlock('Import vCard', 'monkeychat-48.png', $m, $m . '.' . $a);
  77      $titleBlock->addCrumb('?m=contacts', 'contacts list');
  78      $titleBlock->show();
  79  
  80  ?>
  81  
  82  <table width="100%" border="0" cellpadding="3" cellspacing="3" class="std">
  83  
  84      <form name="vcfFrm" action="?m=contacts&a=vcardimport&suppressHeaders=true" enctype="multipart/form-data" method="post">
  85          <input type="hidden" name="max_file_size" value="109605000" />
  86      <tr>
  87          <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Fetch vCard(s) File'); ?>:</td>
  88          <td align="left"><input type="File" class="button" name="vcf" style="width:280px" accept="text/x-vcard"></td>
  89      </tr>
  90      <tr>
  91          <td align="right" colspan="2" nowrap="nowrap"><input type="submit" class="button" value="<?php echo $AppUI->_('submit'); ?>"/></td>
  92      </tr>
  93      </form>
  94  </table>
  95  
  96  <?php } else { // trouble with get parameters
  97      $AppUI->setMsg('vCardImportError', UI_MSG_ERROR);
  98      $AppUI->redirect();
  99  }
 100  
 101  ?>


Generated: Wed Jan 7 03:00:01 2009 Cross-referenced by PHPXref 0.7