Exemplo n.º 1
0
 private function downloadVCard()
 {
     /* Bail out if we don't have a valid contact ID. */
     if (!$this->isRequiredIDValid('contactID', $_GET)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid contact ID.');
     }
     $contactID = $_GET['contactID'];
     $contacts = new Contacts($this->_siteID);
     $contact = $contacts->get($contactID);
     $companies = new Companies($this->_siteID);
     $company = $companies->get($contact['companyID']);
     /* Bail out if we got an empty result set. */
     if (empty($contact)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'The specified contact ID could not be found.');
     }
     /* Create a new vCard. */
     $vCard = new VCard();
     $vCard->setName($contact['lastName'], $contact['firstName']);
     if (!empty($contact['phoneWork'])) {
         $vCard->setPhoneNumber($contact['phoneWork'], 'PREF;WORK;VOICE');
     }
     if (!empty($contact['phoneCell'])) {
         $vCard->setPhoneNumber($contact['phoneCell'], 'CELL;VOICE');
     }
     /* FIXME: Add fax to contacts and use setPhoneNumber('WORK;FAX') here */
     $addressLines = explode("\n", $contact['address']);
     $address1 = trim($addressLines[0]);
     if (isset($addressLines[1])) {
         $address2 = trim($addressLines[1]);
     } else {
         $address2 = '';
     }
     $vCard->setAddress($address1, $address2, $contact['city'], $contact['state'], $contact['zip']);
     if (!empty($contact['email1'])) {
         $vCard->setEmail($contact['email1']);
     }
     if (!empty($company['url'])) {
         $vCard->setURL($company['url']);
     }
     $vCard->setTitle($contact['title']);
     $vCard->setOrganization($company['name']);
     if (!eval(Hooks::get('CONTACTS_GET_VCARD'))) {
         return;
     }
     $vCard->printVCardWithHeaders();
 }