Advanced Search  :  Site Statistics  :  Directory  :  Web Resources  :  Forum  
    Plugins for Geeklog Geeklog Plugins    
 Welcome to Plugins for Geeklog
 Saturday, May 17 2008 @ 07:01 AM EDT

vCard export from contacts

   
ContactsI wrote the following php script to download the selected contact with the main company info in vCard format (tailored for Mac OS X Addressbook). This was my first php ever, copy and pasted together to get it to work, so please don't judge too harshly :-)


I have an icon in the viewp.php screen which is linked to http://mydomain.com/contact/vcard.php?c_id=240&c_type=1. Now that I think about it, I can't remember if c_type is even used since this only shows in viewp.php.

The vcard.php follows:



header('Content-Type: text/plain');

header('Content-Disposition: inline; filename="ContactExport.vcf"');

// open connection to database
$connection = mysql_connect("localhost", , ) or die ("Unable to connect!");

mysql_select_db("geeklog") or die ("Unable to select database!");

$query_p = "SELECT * FROM ct_person where (c_id = '$c_id')";
$result_p = mysql_query($query_p) or die ("Error in person query: $query_p. " . mysql_error());

if ($row = mysql_fetch_assoc($result_p))
{
$query_c = "SELECT * FROM ct_company where (c_id = '$row[co_id]')";
$result_c = mysql_query($query_c) or die ("Error in company query: $query_c. " . mysql_error());

print ("begin:vcardn");
print ("version:3.0n");
print ("fn:") . $row[fname] . (" ");
if ($row[mname] != ""){print $row[mname] . (" ");}
print $row[lname] . ("n");
print ("n:") . $row[lname] . (";") . $row[fname] . (";") . $row[mname] . (";") . $row[salutation] . (";") . ("n");
print ("nickname:") . $row[user1] . ("n");
print ("title:") . $row[title] . ("n");
if ($row_c = mysql_fetch_assoc($result_c)) {
print ("org:") . $row_c[name] . (";") . ("n");
if ($row_c[city] !="") {
if ($row_c[address2] != "") {
$work_address=$row_c[address1] . 'n' . $row_c[address2];
} else {
$work_address=$row_c[address1];
}
print ("adr;type=work;type=pref:;;") . $work_address . (";") . $row_c[city] . (";") . $row_c[state] . (";") . $row_c[postalcode] . (";") . $row_c[country] . ("n");
}
print ("tel;type=main:") . $row_c[phone1] . ("n");
print ("tel;type=other:") . $row_c[phone2] . ("n");
print ("tel;type=main;type=fax:") . $row_c[fax] . ("n");
print ("email;type=INTERNET:") . $row_c[email1] . ("n");
print ("url;type=work:") . $row_c[url1] . ("n");
if ($row_c[notes] != "") {$work_note="Company Note - " . $row_c[notes];}
}
if ($row[notes] != "") {
print ("note:") . $work_note . 'n' . ("Personal Note - ") . $row[notes] . ("n");
} else {
print ("note:") . $work_note . ("n");
}
print ("url;type=home:") . $row[url1] . ("n");
print ("tel;type=work:") . $row[phone1] . ("n");
if ($row[city] !="") {
if ($row[address2] != "") {
$home_address=$row[address1] . 'n' . $row[address2];
} else {
$home_address=$row[address1];
}
print ("adr;type=home:;;") . $home_address . (";") . $row[city] . (";") . $row[state] . (";") . $row[postalcode] . (";") . $row[country] . ("n");
}
print ("tel;type=cell:") . $row[phone2] . ("n");
print ("tel;type=work;type=fax:") . $row[fax] . ("n");
print ("email;type=work;type=pref:") . $row[email1] . ("n");
print ("email;type=home:") . $row[email2] . ("n");
print ("end:vcard");
} else {
print "Sorry, there was an error extracting the information from the database";
}

mysql_close($connection);
 

Story Options

vCard export from contacts | 4 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
vCard export from contacts
Authored by: tomw on Tuesday, March 18 2003 @ 10:55 AM EST

No criticism from me.  I always appreciate people who take something and make it do what they want.  I learned to program by hacking cpm (predecessor of msdos) and making it do what it was not intended to do.

One little problem area that you might have is the direct connection to the mysql database instead of using geeklogs methods.  This could cause some conflicts and possible corruption.

TomW

vCard export from contacts
Authored by: anonymous on Wednesday, March 19 2003 @ 02:11 PM EST
I think this is a great idea.  What the Contacts Plugin really needs is a way to import from a csv file.  This would let people export from Outlook and then import into the Contacts Plugin.
Found a CSV Import Script
Authored by: anonymous on Monday, March 24 2003 @ 02:43 PM EST

I found a script that will do CSV importing into MySQL via a graphical interface.
All you do is upload and run.  Nothing to setup.
Very cool.
http://www.hotscripts.com/Detailed/18098.html

 

 Copyright © 2008 Plugins for Geeklog
 All trademarks and copyrights on this page are owned by their respective owners.
Powered By Geeklog 
Created this page in 0.16 seconds