[ Index ]

Source Code Reference for V1.00

title

Body

[close]

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

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


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