home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / contacts / vcardimport.php < prev   
Encoding:
PHP Script  |  2003-11-18  |  3.7 KB  |  110 lines

  1. <?php
  2.  
  3. $canEdit = !getDenyEdit( 'contacts' );
  4. if (!$canEdit) {
  5.     $AppUI->redirect( "m=public&a=access_denied" );
  6. }
  7.  
  8.  
  9.  
  10. // check whether vCard file should be fetched from source or parsed for vCardKeys; criteria: get parameters
  11. if ( isset($vcf) && !($vcf =='none') && isset($_GET['suppressHeaders']) && ($_GET['suppressHeaders']=='true')) {    //parse and store vCard file
  12.  
  13.  
  14.     // include PEAR vCard class
  15.     require_once( $AppUI->getLibraryClass( 'PEAR/Contact_Vcard_Parse' ) );
  16.  
  17.  
  18.     if (is_uploaded_file($vcf)) {
  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);
  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 dP 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['ORG'][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];
  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_last_name"].', '.$contactValues["contact_first_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.  
  67.  
  68.         }
  69.         // one or more vCard imports were succesfull
  70.         $AppUI->setMsg( 'vCard(s) imported', UI_MSG_OK, true );
  71.         $AppUI->redirect();
  72.  
  73.     }
  74.     else {    // redirect in case of file upload trouble
  75.         $AppUI->setMsg( "vCardFileUploadError", UI_MSG_ERROR );
  76.         $AppUI->redirect();
  77.     }
  78.  
  79.  
  80.  
  81. }
  82. elseif ( isset($_GET['dialog']) && ($_GET['dialog']=='0') ){    //file upload formular
  83.  
  84. $titleBlock = new CTitleBlock( 'Import vCard', 'monkeychat-48.png', $m, "$m.$a" );
  85. $titleBlock->addCrumb( "?m=contacts", "contacts list" );
  86. $titleBlock->show();
  87.  
  88. ?>
  89.  
  90. <table width="100%" border="0" cellpadding="3" cellspacing="3" class="std">
  91.  
  92.     <form name="vcfFrm" action="?m=contacts&a=vcardimport&suppressHeaders=true" enctype="multipart/form-data" method="post">
  93.         <input type="hidden" name="max_file_size" value="109605000" />
  94.     <tr>
  95.         <td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'Fetch vCard(s) File' );?>:</td>
  96.         <td align="left"><input type="File" class="button" name="vcf" style="width:280px" accept="text/x-vcard"></td>
  97.     </tr>
  98.     <tr>
  99.         <td align="right" colspan="2" nowrap="nowrap"><input type="submit" class="button" value="<?php echo $AppUI->_('submit'); ?>"/></td>
  100.     </tr>
  101.     </form>
  102. </table>
  103.  
  104. <?php } else {    // trouble with get parameters
  105. $AppUI->setMsg( "vCardImportError", UI_MSG_ERROR );
  106.     $AppUI->redirect();
  107. }
  108.  
  109. ?>
  110.