Last active
August 29, 2015 14:05
-
-
Save yorikvanhavre/4642b5863bad08e20894 to your computer and use it in GitHub Desktop.
ProjectPier: export the contacts list as VCard - application/views/dashboard/export_vcf.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require('../../../config/config.php'); | |
date_default_timezone_set("America/Sao_Paulo"); | |
header('Content-Type: text/vcard; charset=utf-8'); //To tell that the data is a visiting card format | |
header('Content-Disposition: attachment; filename=projectpier_contacts.vcf'); //To make the data downloadable | |
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect to MySQL database. ' . mysql_error()); | |
mysql_select_db(DB_NAME,$conn)or die(mysql_error()); | |
$companies = array(); | |
$comp = mysql_query('SELECT name,id FROM `'.DB_PREFIX.'companies`'); | |
while ($co = mysql_fetch_array($comp)) { | |
$companies[] = $co; | |
} | |
$rows = mysql_query('SELECT id,company_id,display_name,first_name,last_name,title,email,home_number,office_number,fax_number FROM `'.DB_PREFIX.'contacts`'); | |
while ($contact = mysql_fetch_array($rows)) { | |
$today = getdate(); | |
$company = 'None'; | |
foreach ($companies as $c) { | |
if ($c['id'] == $contact['company_id']) { | |
$company = $c['name']; | |
} | |
} | |
echo 'BEGIN:VCARD'."\n"; | |
echo 'VERSION:3.0'."\n"; | |
echo 'N:'.$contact['last_name'].";".$contact['first_name'].';;'."\n"; | |
echo 'FN:'.$contact['display_name']."\n"; | |
echo 'ORG:'.$company."\n"; | |
echo 'TITLE:'.$contact['title']."\n"; | |
echo 'TEL;TYPE=WORK,VOICE:'.$contact['office_number']."\n"; | |
echo 'TEL;TYPE=HOME,VOICE:'.$contact['home_number']."\n"; | |
echo 'EMAIL;TYPE=PREF,INTERNET:'.$contact['email']."\n"; | |
echo 'REV:'.$today['year']."-".$today['mon']."-".$today['mday']."T".$today['hours'].":".$today['minutes'].":".$today['seconds']."z"."\n"; | |
echo 'END:VCARD'."\n"; | |
} | |
mysql_close(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment