home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / contacts / vcardexport.php < prev    next >
Encoding:
PHP Script  |  2003-09-18  |  3.2 KB  |  101 lines

  1. <?php
  2. // get GETPARAMETER for contact_id
  3. $contact_id = intval( $_GET['contact_id']);
  4.  
  5. $canRead = !getDenyRead( 'contacts' );
  6. if (!$canRead) {
  7.     $AppUI->redirect( "m=public&a=access_denied" );
  8. }
  9.  
  10. if ( isset($_GET['contact_id']) && !($_GET['contact_id']=='') ) {
  11.  
  12.     //pull data for this contact
  13.     $sql = "SELECT * FROM contacts WHERE contact_id = $contact_id";
  14.     $contacts = db_loadList( $sql );
  15.  
  16.     //foreach ($contacts as $row) {
  17.     //echo $row['contact_id'];
  18.     //}
  19.  
  20.  
  21.     // include PEAR vCard class
  22.     require_once( $AppUI->getLibraryClass( 'PEAR/Contact_Vcard_Build' ) );
  23.  
  24.     // instantiate a builder object
  25.     // (defaults to version 3.0)
  26.     $vcard = new Contact_Vcard_Build();
  27.  
  28.     // set a formatted name
  29.     $vcard->setFormattedName($contacts[0]['contact_first_name'].' '.$contacts[0]['contact_last_name']);
  30.  
  31.     // set the structured name parts
  32.     $vcard->setName($contacts[0]['contact_last_name'], $contacts[0]['contact_first_name'], $contacts[0]['contact_type'],
  33.         $contacts[0]['contact_title'], '');
  34.  
  35.     // set the source of the vCard
  36.     $vcard->setSource($AppUI->cfg['company_name'].' '.$AppUI->cfg['page_title'].': '.$AppUI->cfg['site_domain']);
  37.  
  38.     // set the birthday of the contact
  39.     $vcard->setBirthday($contacts[0]['contact_birthday']);
  40.  
  41.     // set a note of the contact
  42.     $contacts[0]['contact_notes'] = str_replace("\r", " ", $contacts[0]['contact_notes'] );
  43.     $vcard->setNote($contacts[0]['contact_notes']);
  44.  
  45.     // add an organization
  46.     $vcard->addOrganization($contacts[0]['contact_company']);
  47.  
  48.     // add a phone number
  49.     $vcard->addTelephone($contacts[0]['contact_phone']);
  50.     $vcard->addParam('TYPE', 'PF');
  51.  
  52.     // add a phone number
  53.     $vcard->addTelephone($contacts[0]['contact_phone2']);
  54.  
  55.     // add a mobile phone number
  56.     $vcard->addTelephone($contacts[0]['contact_mobile']);
  57.     $vcard->addParam('TYPE', 'car');
  58.  
  59.     // add a work email.  note that we add the value
  60.     // first and the param after -- Contact_Vcard_Build
  61.     // is smart enough to add the param in the correct
  62.     // place.
  63.     $vcard->addEmail($contacts[0]['contact_email']);
  64.     //$vcard->addParam('TYPE', 'WORK');
  65.     $vcard->addParam('TYPE', 'PF');
  66.  
  67.     // add a home/preferred email
  68.     $vcard->addEmail($contacts[0]['contact_email2']);
  69.     //$vcard->addParam('TYPE', 'HOME');
  70.  
  71.     // add an address
  72.     $vcard->addAddress('', $contacts[0]['contact_address2'], $contacts[0]['contact_address1'],
  73.         $contacts[0]['contact_city'], $contacts[0]['contact_state'], $contacts[0]['contact_zip'], $contacts[0]['contact_country']);
  74.     //$vcard->addParam('TYPE', 'WORK');
  75.  
  76.  
  77.     // get back the vCard
  78.     $text = $vcard->fetch();
  79.  
  80.     //send http-output with this vCard
  81.  
  82.     // BEGIN extra headers to resolve IE caching bug (JRP 9 Feb 2003)
  83.     // [http://bugs.php.net/bug.php?id=16173]
  84.         header("Pragma: ");
  85.         header("Cache-Control: ");
  86.         header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  87.         header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  88.         header("Cache-Control: no-store, no-cache, must-revalidate");  //HTTP/1.1
  89.         header("Cache-Control: post-check=0, pre-check=0", false);
  90.     // END extra headers to resolve IE caching bug
  91.  
  92.     header("MIME-Version: 1.0");
  93.     header("Content-Type: text/x-vcard");
  94.     header("Content-Disposition: attachment; filename={$contacts[0]['contact_last_name']}{$contacts[0]['contact_first_name']}.vcf");
  95.     print_r($text);
  96. } else {
  97. $AppUI->setMsg( "contactIdError", UI_MSG_ERROR );
  98.     $AppUI->redirect();
  99. }
  100. ?>
  101.