I 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
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
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);