public static function vcard($mailvars) { if (!is_array($mailvars)) { return false; } $default = array('firstname' => '', 'middlename' => '', 'lastname' => '', 'nickname' => '', 'title' => '', 'work_title' => '', 'email' => '', 'pobox' => '', 'extendedaddress' => '', 'street' => '', 'zipcode' => '', 'city' => '', 'state' => '', 'country' => '', 'work_pobox' => '', 'work_office' => '', 'work_street' => '', 'work_zipcode' => '', 'work_city' => '', 'work_state' => '', 'work_country' => '', 'birthday' => '', 'work_email' => '', 'work_telephone' => '', 'website' => '', 'telephone' => '', 'work_role' => '', 'note' => '', 'work_organization' => ''); $vars = array_merge($default, $mailvars); $vcard = new Contact_Vcard_Build(); // General informations $vcard->setFormattedName($vars['nom'] . ' ' . $vars['lastname']); $vcard->setName($vars['lastname'], $vars['firstname'], $vars['middlename'], $vars['title'], ''); $vcard->setBirthday($vars['birthday']); $vcard->addNickname($vars['nickname']); $vcard->setNote($vars['note']); // Home informations $vcard->addEmail($vars['email']); $vcard->addParam('TYPE', 'HOME'); $vcard->addTelephone($vars['telephone']); $vcard->addParam('TYPE', 'HOME'); $vcard->addAddress($vars['pobox'], $vars['street'], $vars['extendedaddress'], $vars['city'], $vars['state'], $vars['zipcode'], $vars['country']); $vcard->addParam('TYPE', 'HOME'); $vcard->setURL($vars['website']); $vcard->addParam('TYPE', 'HOME'); // Business informations $vcard->addEmail($vars['work_email']); $vcard->addParam('TYPE', 'WORK'); $vcard->addTelephone($vars['work_telephone']); $vcard->addParam('TYPE', 'WORK'); $vcard->addAddress($vars['work_pobox'], $vars['work_office'], $vars['work_street'], $vars['work_city'], $vars['work_state'], $vars['work_zipcode'], $vars['work_country']); $vcard->addParam('TYPE', 'WORK'); $vcard->addOrganization($vars['work_organization']); $vcard->setRole($vars['work_role']); $vcard->setTitle($vars['work_title']); return $vcard->fetch(); }
/** * Heart of the vCard data assignment process. * * The runner gets all the metadata for the contact and calls the writeVcard method to output the vCard * to the user. */ public function run() { $this->preProcess(); $params = array(); $defaults = array(); $ids = array(); $params['id'] = $params['contact_id'] = $this->_contactId; $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids); // now that we have the contact's data - let's build the vCard // TODO: non-US-ASCII support (requires changes to the Contact_Vcard_Build class) $vcardNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'vcard_name')); $vcard = new Contact_Vcard_Build('2.1'); if ($defaults['contact_type'] == 'Individual') { $vcard->setName(CRM_Utils_Array::value('last_name', $defaults), CRM_Utils_Array::value('first_name', $defaults), CRM_Utils_Array::value('middle_name', $defaults), CRM_Utils_Array::value('prefix', $defaults), CRM_Utils_Array::value('suffix', $defaults)); $organizationName = CRM_Utils_Array::value('organization_name', $defaults); if ($organizationName !== NULL) { $vcard->addOrganization($organizationName); } } elseif ($defaults['contact_type'] == 'Organization') { $vcard->setName($defaults['organization_name'], '', '', '', ''); } elseif ($defaults['contact_type'] == 'Household') { $vcard->setName($defaults['household_name'], '', '', '', ''); } $vcard->setFormattedName($defaults['display_name']); $vcard->setSortString($defaults['sort_name']); if (!empty($defaults['nick_name'])) { $vcard->addNickname($defaults['nick_name']); } if (!empty($defaults['job_title'])) { $vcard->setTitle($defaults['job_title']); } if (!empty($defaults['birth_date_display'])) { $vcard->setBirthday(CRM_Utils_Array::value('birth_date_display', $defaults)); } if (!empty($defaults['home_URL'])) { $vcard->setURL($defaults['home_URL']); } // TODO: $vcard->setGeo($lat, $lon); if (!empty($defaults['address'])) { $stateProvices = CRM_Core_PseudoConstant::stateProvince(); $countries = CRM_Core_PseudoConstant::country(); foreach ($defaults['address'] as $location) { // we don't keep PO boxes in separate fields $pob = ''; $extend = CRM_Utils_Array::value('supplemental_address_1', $location); if (!empty($location['supplemental_address_2'])) { $extend .= ', ' . $location['supplemental_address_2']; } $street = CRM_Utils_Array::value('street_address', $location); $locality = CRM_Utils_Array::value('city', $location); $region = NULL; if (!empty($location['state_province_id'])) { $region = $stateProvices[CRM_Utils_Array::value('state_province_id', $location)]; } $country = NULL; if (!empty($location['country_id'])) { $country = $countries[CRM_Utils_Array::value('country_id', $location)]; } $postcode = CRM_Utils_Array::value('postal_code', $location); if (!empty($location['postal_code_suffix'])) { $postcode .= '-' . $location['postal_code_suffix']; } $vcard->addAddress($pob, $extend, $street, $locality, $region, $postcode, $country); $vcardName = $vcardNames[$location['location_type_id']]; if ($vcardName) { $vcard->addParam('TYPE', $vcardName); } if (!empty($location['is_primary'])) { $vcard->addParam('TYPE', 'PREF'); } } } if (!empty($defaults['phone'])) { foreach ($defaults['phone'] as $phone) { $vcard->addTelephone($phone['phone']); $vcardName = $vcardNames[$phone['location_type_id']]; if ($vcardName) { $vcard->addParam('TYPE', $vcardName); } if ($phone['is_primary']) { $vcard->addParam('TYPE', 'PREF'); } } } if (!empty($defaults['email'])) { foreach ($defaults['email'] as $email) { $vcard->addEmail($email['email']); $vcardName = $vcardNames[$email['location_type_id']]; if ($vcardName) { $vcard->addParam('TYPE', $vcardName); } if ($email['is_primary']) { $vcard->addParam('TYPE', 'PREF'); } } } // all that's left is sending the vCard to the browser $filename = CRM_Utils_String::munge($defaults['display_name']); $vcard->send($filename . '.vcf', 'attachment', 'utf-8'); CRM_Utils_System::civiExit(); }
/** * export the member informations as a vcard (*.vcf) * * @param integer $id * @return void */ function _exportVCard($id) { global $objDatabase; //error_reporting(E_ALL);ini_set('display_errors',1); $query = " SELECT `pic1`, `pic2`, `0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `13`, `14`, `15`, `16`, `17`, `18`\n FROM `" . DBPREFIX . "module_memberdir_values`\n WHERE `id` = " . $id; if (($objRS = $objDatabase->SelectLimit($query, 1)) !== false) { \Env::get('ClassLoader')->loadFile(ASCMS_LIBRARY_PATH . '/PEAR/Contact_Vcard_Build.php'); $vcard = new \Contact_Vcard_Build(); $lastname = $objRS->fields['1']; $firstname = $objRS->fields['2']; $company = $objRS->fields['3']; $phone = $objRS->fields['4']; $mobile = $objRS->fields['5']; $address = $objRS->fields['6']; $zip = $objRS->fields['7']; $city = $objRS->fields['8']; $email = $objRS->fields['9']; $fax = $objRS->fields['10']; $homepage = $objRS->fields['11']; $birthday = $objRS->fields['12']; $special1 = $objRS->fields['13']; $special2 = $objRS->fields['14']; $special3 = $objRS->fields['15']; $special4 = $objRS->fields['16']; $special5 = $objRS->fields['17']; $special6 = $objRS->fields['18']; $vcard->setFormattedName("{$lastname} {$firstname}"); $vcard->setName($lastname, $firstname, '', '', ''); $vcard->addEmail($email); $vcard->addParam('TYPE', 'HOME'); $vcard->addAddress($address, '', '', '', '', '', ''); $vcard->addOrganization($company); $vcard->addTelephone($phone); $vcard->addParam('TYPE', 'HOME'); $vcard->addTelephone($mobile); $vcard->addParam('TYPE', 'CELL'); $vcard->setURL($homepage); $vcard->setBirthday($birthday); header('Content-Disposition: attachment; filename="' . $lastname . '_' . $firstname . '.vcf"'); header('Content-Type: text/x-vcard'); echo $vcard->fetch(); die; } else { die('DB Error: ' . $objDatabase->ErrorMsg()); } }
if ($contact_id) { $contact = new CContact(); $contact->loadFull($AppUI, $contact_id); // include PEAR vCard class require_once $AppUI->getLibraryClass('PEAR/Contact_Vcard_Build'); // instantiate a builder object // (defaults to version 3.0) $vcard = new Contact_Vcard_Build(); // set a formatted name $vcard->setFormattedName($contact->contact_first_name . ' ' . $contact->contact_last_name); // set the structured name parts $vcard->setName($contact->contact_last_name, $contact->contact_first_name, $contact->contact_type, $contact->contact_title, ''); // set the source of the vCard $vcard->setSource($w2Pconfig['company_name'] . ' ' . $w2Pconfig['page_title'] . ': ' . $w2Pconfig['site_domain']); // set the birthday of the contact $vcard->setBirthday($contact->contact_birthday); // set a note of the contact $contact->contact_notes = mb_str_replace("\r", ' ', $contact->contact_notes); $vcard->setNote($contact->contact_notes); // add an organization $vcard->addOrganization($contact->company_name); // add dp company id $vcard->setUniqueID($contact->contact_company); // add a phone number $vcard->addTelephone($contact->contact_phone); $vcard->addParam('TYPE', 'PF'); // add a phone number $vcard->addTelephone($contact->contact_phone2); // add a mobile phone number $vcard->addTelephone($contact->contact_mobile); $vcard->addParam('TYPE', 'car');
//foreach ($contacts as $row) { //echo $row['contact_id']; //} // include PEAR vCard class require_once $AppUI->getLibraryClass('PEAR/Contact_Vcard_Build'); // instantiate a builder object // (defaults to version 3.0) $vcard = new Contact_Vcard_Build(); // set a formatted name $vcard->setFormattedName($contacts[0]['contact_first_name'] . ' ' . $contacts[0]['contact_last_name']); // set the structured name parts $vcard->setName($contacts[0]['contact_last_name'], $contacts[0]['contact_first_name'], $contacts[0]['contact_type'], $contacts[0]['contact_title'], ''); // set the source of the vCard $vcard->setSource($dPconfig['company_name'] . ' ' . $dPconfig['page_title'] . ': ' . $dPconfig['site_domain']); // set the birthday of the contact $vcard->setBirthday($contacts[0]['contact_birthday']); // set a note of the contact $contacts[0]['contact_notes'] = str_replace("\r", " ", $contacts[0]['contact_notes']); $vcard->setNote($contacts[0]['contact_notes']); // add an organization $vcard->addOrganization($contacts[0]['contact_company']); // add a phone number $vcard->addTelephone($contacts[0]['contact_phone']); $vcard->addParam('TYPE', 'PF'); // add a phone number $vcard->addTelephone($contacts[0]['contact_phone2']); // add a mobile phone number $vcard->addTelephone($contacts[0]['contact_mobile']); $vcard->addParam('TYPE', 'car'); // add a work email. note that we add the value // first and the param after -- Contact_Vcard_Build
// set the structured name parts $prefix = $data["cp_greeting"] ? $data["cp_greeting"] . " " . $data["cp_title"] : $data["cp_title"]; $vcard->setName($data["cp_name"], $data["cp_givenname"], "", $prefix, ""); // add a work email. note that we add the value // first and the param after -- Contact_Vcard_Build // is smart enough to add the param in the correct place. if ($data["cp_email"]) { $vcard->addEmail($data["cp_email"]); $vcard->addParam('TYPE', 'WORK'); $vcard->addParam('TYPE', 'PREF'); } // add a work address $vcard->addAddress('', '', $data["cp_street"], $data["cp_city"], '', $data["cp_zipcode"], $data["cp_country"]); $vcard->addParam('TYPE', 'WORK'); if ($data["cp_birthday"]) { $vcard->setBirthday($data["cp_birthday"]); } if ($data["cp_notes"]) { $vcard->setNote($data["cp_notes"]); } if ($data["cp_phone1"]) { $vcard->addTelephone($data["cp_phone1"]); $vcard->addParam('TYPE', 'WORK'); $vcard->addParam('TYPE', 'PREF'); } if ($data["cp_fax"]) { $vcard->addTelephone($data["cp_fax"]); $vcard->addParam('TYPE', 'FAX'); } if ($data["cp_position"]) { $vcard->setTitle($data["cp_position"]);