*
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
$phpgw_info["flags"] = array("currentapp" => "addressbook", "enable_addressbook_class" => True, "noheader" => True, "nonavbar" => True);
include("../header.inc.php");
// parse a vcard and fill the address book with it.
function parsevcard($filename,$access)
{
global $phpgw;
global $phpgw_info;
$vcard = fopen($filename, "r");
if (!$vcard) // Make sure we have a file to read.
{
fclose($vcard);
return FALSE;
}
// Keep runnig through this to support vcards
// with multiple entries.
while (!feof($vcard))
{
if(!empty($varray))
unset($varray);
// Make sure our file is a vcard.
// I should deal with empty line at the
// begining of the file. Those will fail here.
$vline = fgets($vcard,20);
$vline = strtolower($vline);
if(strcmp("begin:vcard", substr($vline, 0, strlen("begin:vcard")) ) != 0)
{
fclose($vcard);
return FALSE;
}
// Write the vcard into an array.
// You can have multiple vcards in one file.
// I only deal with halve of that. :)
// It will only return values from the 1st vcard.
$varray[0] = "begin";
$varray[1] = "vcard";
$i=2;
while(!feof($vcard) && strcmp("end:vcard", strtolower(substr($vline, 0, strlen("end:vcard"))) ) !=0 )
{
$vline = fgets($vcard,4096);
// Check for folded lines and escaped colons '\:'
$la = explode(":", $vline);
//if (ereg("\:",$vline))
//{
// // Oh, no.... Horrible disaster....
// // Yell.
// echo "
";
// echo "DANGER WILL ROBINSON!!!!!!!!!!
";
// echo "This just broke. Really.
";
// echo "
";
//}
// DANGER Will Robinson!!!!!!!
// I don't check for escaped colons here.
// '\:' These would cause horrible disaster..
// Fix this situation. Check if the last character
// of the line is \ If it is, you've found one.
if (count($la) > 1)
{
$varray[$i] = strtolower($la[0]);
$i++;
for($j=1;$j<=count($la);$j++)
{
$varray[$i] .= $la[$j];
}
$i++;
}
else // This is the continuation of a folded line.
{
$varray[$i-1] .= $la[0];
}
}
fillab($varray,$access); // Add this entry to the addressbook before
// moving on to the next one.
} // while(!feof($vcard))
fclose($vcard);
return TRUE;
}
function fillab($varray,$access)
{
global $phpgw;
global $phpgw_info;
$i=0;
while($i < count($varray)) // incremented by 2
{
$k = explode(";",$varray[$i]); // Key
$v = explode(";",$varray[$i+1]); // Values
for($h=0;$h 1)
{
$notes .= $v[0] . "\n";
for($j=1;$j";
//echo "First Name: " . $firstname . "
";
//echo "Last Name: " . $lastname . "
";
//echo "Home Phone: " .$hphone . "
";
//echo "Cell Phone: " . $mphone . "
";
//echo "Work Phone: " . $wphone . "
";
//echo "Fax: " . $fax . "
";
//echo "Email: " . $email . "
";
//echo "Organization: " . $company . "
";
//echo "Address:
";
//echo $address2 . "
" . $street ."
";
//echo $city . " " . $state . " " . $zip . "
";
//echo "Notes: " . $notes . "
";
if($phpgw_info["apps"]["timetrack"]["enabled"]) {
$sql = "insert into addressbook (ab_owner,ab_access,ab_firstname,ab_lastname,ab_title,ab_email,"
. "ab_hphone,ab_wphone,ab_fax,ab_pager,ab_mphone,ab_ophone,ab_street,ab_address2,ab_city,"
. "ab_state,ab_zip,ab_bday,"
. "ab_notes,ab_company_id) values ('" . $phpgw_info["user"]["account_id"] . "','$access','"
. addslashes($firstname). "','"
. addslashes($lastname) . "','"
. addslashes($title) . "','"
. addslashes($email) . "','"
. addslashes($hphone) . "','"
. addslashes($wphone) . "','"
. addslashes($fax) . "','"
. addslashes($pager) . "','"
. addslashes($mphone) . "','"
. addslashes($ophone) . "','"
. addslashes($street) . "','"
. addslashes($address2) . "','"
. addslashes($city) . "','"
. addslashes($state) . "','"
. addslashes($zip) . "','"
. addslashes($bday) . "','"
. addslashes($notes) . "','"
. addslashes($company). "')";
} else {
$sql = "insert into addressbook (ab_owner,ab_access,ab_firstname,ab_lastname,ab_title,ab_email,"
. "ab_hphone,ab_wphone,ab_fax,ab_pager,ab_mphone,ab_ophone,ab_street,ab_address2,ab_city,"
. "ab_state,ab_zip,ab_bday,"
. "ab_notes,ab_company) values ('" . $phpgw_info["user"]["account_id"] . "','$access','"
. addslashes($firstname). "','"
. addslashes($lastname) . "','"
. addslashes($title) . "','"
. addslashes($email) . "','"
. addslashes($hphone) . "','"
. addslashes($wphone) . "','"
. addslashes($fax) . "','"
. addslashes($pager) . "','"
. addslashes($mphone) . "','"
. addslashes($ophone) . "','"
. addslashes($street) . "','"
. addslashes($address2) . "','"
. addslashes($city) . "','"
. addslashes($state) . "','"
. addslashes($zip) . "','"
. addslashes($bday) . "','"
. addslashes($notes) . "','"
. addslashes($company). "')";
}
$phpgw->db->query($sql);
}
if($access == "group")
$access = $n_groups;
//echo $access . "
";
parsevcard($filename,$access);
// Delete the temp file.
unlink($filename);
unlink($filename . ".info");
Header("Location: " . $phpgw->link($phpgw_info["server"]["webserver_url"] . "/addressbook/",
"cd=14"));
// End of php.
?>