Update vcard import/export to use new vcard class

This commit is contained in:
Miles Lott 2001-03-21 08:18:32 +00:00
parent 7e157b369a
commit aa803fa670
2 changed files with 13 additions and 549 deletions

View File

@ -169,187 +169,14 @@
} }
function export_end_file($buffer) { function export_end_file($buffer) {
$vcard = CreateObject("phpgwapi.vcard");
reset($this->ids); reset($this->ids);
for ($i=0;$i<count($this->ids);$i++) { for ($i=0;$i<count($this->ids);$i++) {
$work = ""; $workaddr = ""; $workattr = ""; $wlabel = ""; $vcards .= $vcard->out($buffer[$i]);
$home = ""; $homeaddr = ""; $homeattr = ""; $hlabel = "";
$org_name = ""; $org_unit = "";
$firstname = ""; $middle = ""; $lastname = "";
$prefix = ""; $suffix = "";
$entry = "";
$header = "BEGIN:VCARD\r\n";
$header .= "VERSION:2.1\r\n";
$header .= "X-PHPGROUPWARE-FILE-AS:phpGroupWare.org\r\n";
reset($this->export);
while (list($name,$value)=each($this->export)) {
if (!empty($buffer[$i][$value])) {
$mult = explode(";",$value);
if (!$mult[1]) { // Normal
if (strstr($buffer[$i][$value],"\n")) {
$buffer[$i][$value] = ereg_replace("\r\n","=0D=0A",$buffer[$i][$value]);
$entry .= $value . ";QUOTED-PRINTABLE:".$buffer[$i][$value]."\r\n";
} elseif ($value=="BDAY") {
$tmp = split("/",$buffer[$i][$value]); # 12/31/1969 -> 1969-12-31
if ($tmp[0]) {
$entry .= "BDAY:". $tmp[2]."-".$tmp[0]."/".$tmp[1]."\r\n";
}
} else {
$entry .= $value . ":".$buffer[$i][$value]."\r\n";
}
} else {
switch ($mult[0]) {
case "N":
switch ($mult[1]) {
case "PREFIX":
$prefix = ";" . $buffer[$i][$value];
break;
case "GIVEN":
$firstname = ";" . $buffer[$i][$value];
break;
case "MIDDLE":
$middle = ";" . $buffer[$i][$value];
break;
case "FAMILY":
$lastname = $buffer[$i][$value];
break;
case "SUFFIX":
$suffix = ";" . $buffer[$i][$value];
break;
}
break;
case "ORG":
switch ($mult[1]) {
case "NAME":
$org_name = $buffer[$i][$value];
break;
case "UNIT":
$org_unit = ";".$buffer[$i][$value];
break;
}
break;
case "ADR":
switch ($mult[1]) {
case "TYPE":
$types = explode(";",$buffer[$i][$value]);
if ($types[1]) {
while ( $type = each($types) ) {
$typei[$i][$mult[2]] .= ";".strtoupper($type[1]);
}
} elseif ($types[0]) {
$typei[$i][$mult[2]] .= ";".strtoupper($types[0]);
} else {
$typei[$i][$mult[2]] .= ";".strtoupper($buffer[$i][$value]);
}
//echo "TYPE=".$typei[$i][$mult[2]];
break;
case "WORK":
$workaddr .= $buffer[$i][$value].";";
$workattr = $mult[0].";".$mult[1].$typei[$i][$mult[1]];
break;
case "HOME":
$homeaddr .= $buffer[$i][$value].";";
$homeattr = $mult[0].";".$mult[1].$typei[$i][$mult[1]];
break;
default:
break;
}
break;
case "TEL":
switch($mult[1]) {
case "PREFER":
$prefer = explode(";",$buffer[$i][$value]);
if ($prefer[1]) {
while ($pref = strtoupper(each($prefer))) {
$prefi[$i][$pref] = ";PREF";
}
//echo "PREF1";
} elseif ($prefer[0]) {
$prefi[$i][strtoupper($prefer[0])] = ";PREF";
//echo "PREF=".strtoupper($prefer[0]);
} elseif ($buffer[$i][$value]) {
$prefi[$i][$buffer[$i][$value]] = ";PREF";
//echo "PREF3";
}
break;
case "WORK":
// Wow, this is fun!
$entry .= "A.".$mult[0].";".$mult[1].$prefi[$i][$mult[1]].":".$buffer[$i][$value]."\r\n";
break;
case "HOME":
$entry .= "B.".$mult[0].";".$mult[1].$prefi[$i][$mult[1]].":".$buffer[$i][$value]."\r\n";
break;
default:
$entry .= $mult[0].";".$mult[1].$prefi[$i][$mult[1]].":".$buffer[$i][$value]."\r\n";
break;
}
break;
case "EMAIL":
switch($mult[1]) {
case "TYPE":
if ($mult[2] == "WORK") { $emailtype = ";".$buffer[$i][$value]; }
if ($mult[2] == "HOME") { $hemailtype = ";".$buffer[$i][$value]; }
break;
case "WORK":
$newval = "A.".$value;
$entry .= $newval.$emailtype.":".$buffer[$i][$value]."\r\n";
break;
case "HOME":
$newval = "B.".$value;
$entry .= $newval.$hemailtype.":".$buffer[$i][$value]."\r\n";
break;
default:
break;
}
break;
default:
break;
}
}
}
}
if ($lastname && $firstname) {
$entries .= $header;
$entries .= "N:".$lastname.$firstname.$middle.$prefix.$suffix."\r\n";
$entries .= $entry;
if (!$buffer[$i]["FN"]) {
if ($lastname || $firstname ) {
$entries .= "FN:".substr($firstname,1)." ".$lastname."\r\n";
}
}
if ($org_name || $org_unit) {
$entries .= "ORG:".$org_name.$org_unit."\r\n";
}
$workattr = ereg_replace("ADR;","",$workattr);
$homeattr = ereg_replace("ADR;","",$homeattr);
if (!$buffer[$i]['EXT']) { $buffer[$i]['EXT'] = ";"; }
if ($workaddr) {
$work = "A.ADR;".$workattr.":;".$buffer[$i]['EXT'].substr($workaddr,0,-1)."\r\n";
$wlabel = substr($workaddr,0,-1);
$wlabel = ereg_replace(";","=0D=0A",$wlabel);
//$wlabel = ereg_replace("(",",",$wlabel);
//$wlabel = ereg_replace(")",",",$wlabel);
$wlabel = "LABEL;WORK;QUOTED-PRINTABLE:".$wlabel."\r\n";
}
if ($homeaddr) {
$home = "B.ADR;".$homeattr.":;;".substr($homeaddr,0,-1)."\r\n";
$hlabel = substr($homeaddr,0,-1);
$hlabel = ereg_replace(";","=0D=0A",$hlabel);
//$hlabel = ereg_replace("(",",",$hlabel);
//$hlabel = ereg_replace(")",",",$hlabel);
$hlabel = "LABEL;HOME;QUOTED-PRINTABLE:".$hlabel."\r\n";
}
$entries .= $work.$home.$wlabel.$hlabel."END:VCARD\r\n";
$entries .= "\r\n";
}
} }
$buffer = $entries; $buffer = $vcards;
return $buffer; return $buffer;
} }
} } // end export class
?> ?>

View File

@ -46,42 +46,6 @@
"email" => "email" "email" => "email"
); );
var $grouping = array("A\.","B\.","C\.","D\.");
var $names = array(
"family" => "family",
"given" => "given",
"middle" => "middle",
"prefix" => "prefix",
"suffix" => "suffix"
);
var $adr_types = array(
"DOM" => "dom",
"INTL" => "intl",
"PARCEL" => "parcel",
"POSTAL" => "postal",
"WORK" => "one",
"HOME" => "two"
);
// Used to set preferred number field
var $tel_types = array(
"PREF" => "tel_prefer",
"WORK" => "tel_work",
"HOME" => "tel_home",
"VOICE" => "tel_voice",
"FAX" => "tel_fax",
"MSG" => "tel_msg",
"CELL" => "tel_cell",
"PAGER" => "tel_pager",
"BBS" => "tel_bbs",
"MODEM" => "tel_modem",
"CAR" => "tel_car",
"ISDN" => "tel_isdn",
"VIDEO" => "tel_video"
);
function import_start_file($buffer,$j="",$k="") { function import_start_file($buffer,$j="",$k="") {
$this->id = 0; $this->id = 0;
return $buffer; return $buffer;
@ -117,342 +81,15 @@
global $phpgw,$phpgw_info; global $phpgw,$phpgw_info;
$contacts = CreateObject("phpgwapi.contacts"); $contacts = CreateObject("phpgwapi.contacts");
echo '<br>'; $vcard = CreateObject("phpgwapi.vcard");
for ($i=1;$i<=count($buffer);$i++) { for ($i=1;$i<=count($buffer);$i++) {
while ( list($name,$value) = @each($buffer[$i]) ) { // Send the entire array to the vcard class in function.
$field = split(";",$name); // It will parse the vcard fields and clean the array of extra
reset($this->grouping); // bogus values that get stuffed in.
$field[0] = ereg_replace("A\.","",$field[0]); $entry = $vcard->in($buffer[$i]);
$field[0] = ereg_replace("B\.","",$field[0]); // Now actually add the new entry
$field[0] = ereg_replace("C\.","",$field[0]); $contacts->add($phpgw_info["user"]["account_id"],$entry);
$field[0] = ereg_replace("D\.","",$field[0]);
$values = split(";",$value);
if ($field[1]) {
//echo $field[0];
switch ($field[0]) {
case "LABEL":
$buffer[$i]["label"] = ereg_replace("=0D=0A","\n",$values[0]);
break;
case "NOTE":
$buffer[$i]["note"] = ereg_replace("=0D=0A","\n",$values[0]);
break;
case "ADR":
switch ($field[1]) {
case "INTL":
switch ($field[2]) {
case "WORK":
if ( !stristr($buffer[$i]["adr_one_type"],$field[1])) {
$buffer[$i]["adr_one_type"] .= "intl;";
}
if (!$buffer[$i]["adr_one_street"]) {
$buffer[$i]["address2"] = $values[1];
$buffer[$i]["adr_one_street"] = $values[2];
$buffer[$i]["adr_one_locality"] = $values[3];
$buffer[$i]["adr_one_region"] = $values[4];
$buffer[$i]["adr_one_postalcode"] = $values[5];
$buffer[$i]["adr_one_countryname"] = $values[6];
}
break;
case "HOME":
if ( !stristr($buffer[$i]["adr_two_type"],$field[1]) ) {
$buffer[$i]["adr_two_type"] .= "intl;";
}
if (!$buffer[$i]["adr_two_street"]) {
$buffer[$i]["adr_two_street"] = $values[2];
$buffer[$i]["adr_two_locality"] = $values[3];
$buffer[$i]["adr_two_region"] = $values[4];
$buffer[$i]["adr_two_postalcode"] = $values[5];
$buffer[$i]["adr_two_countryname"] = $values[6];
}
break;
default:
break;
}
break;
case "DOM":
switch ($field[2]) {
case "WORK":
if ( !stristr($buffer[$i]["adr_one_type"],$field[1])) {
$buffer[$i]["adr_one_type"] .= "dom;";
}
if (!$buffer[$i]["adr_one_street"]) {
$buffer[$i]["address2"] = $values[1];
$buffer[$i]["adr_one_street"] = $values[2];
$buffer[$i]["adr_one_locality"] = $values[3];
$buffer[$i]["adr_one_region"] = $values[4];
$buffer[$i]["adr_one_postalcode"] = $values[5];
$buffer[$i]["adr_one_countryname"] = $values[6];
}
break;
case "HOME":
if ( !stristr($buffer[$i]["adr_two_type"],$field[1]) ) {
$buffer[$i]["adr_two_type"] .= "dom;";
}
if (!$buffer[$i]["adr_two_street"]) {
$buffer[$i]["adr_two_street"] = $values[2];
$buffer[$i]["adr_two_locality"] = $values[3];
$buffer[$i]["adr_two_region"] = $values[4];
$buffer[$i]["adr_two_postalcode"] = $values[5];
$buffer[$i]["adr_two_countryname"] = $values[6];
}
break;
default:
break;
}
break;
case "PARCEL":
switch ($field[2]) {
case "WORK":
if ( !stristr($buffer[$i]["adr_one_type"],$field[1])) {
$buffer[$i]["adr_one_type"] .= "parcel;";
}
if (!$buffer[$i]["adr_one_street"]) {
$buffer[$i]["address2"] = $values[1];
$buffer[$i]["adr_one_street"] = $values[2];
$buffer[$i]["adr_one_locality"] = $values[3];
$buffer[$i]["adr_one_region"] = $values[4];
$buffer[$i]["adr_one_postalcode"] = $values[5];
$buffer[$i]["adr_one_countryname"] = $values[6];
}
break;
case "HOME":
if ( !stristr($buffer[$i]["adr_two_type"],$field[1]) ) {
$buffer[$i]["adr_two_type"] .= "parcel;";
}
if (!$buffer[$i]["adr_two_street"]) {
$buffer[$i]["adr_two_street"] = $values[2];
$buffer[$i]["adr_two_locality"] = $values[3];
$buffer[$i]["adr_two_region"] = $values[4];
$buffer[$i]["adr_two_postalcode"] = $values[5];
$buffer[$i]["adr_two_countryname"] = $values[6];
}
break;
default:
break;
}
break;
case "POSTAL":
switch ($field[2]) {
case "WORK":
if ( !stristr($buffer[$i]["adr_one_type"],$field[1])) {
$buffer[$i]["adr_one_type"] .= "postal;";
}
if (!$buffer[$i]["adr_one_street"]) {
$buffer[$i]["address2"] = $values[1];
$buffer[$i]["adr_one_street"] = $values[2];
$buffer[$i]["adr_one_locality"] = $values[3];
$buffer[$i]["adr_one_region"] = $values[4];
$buffer[$i]["adr_one_postalcode"] = $values[5];
$buffer[$i]["adr_one_countryname"] = $values[6];
}
break;
case "HOME":
if ( !stristr($buffer[$i]["adr_two_type"],$field[1]) ) {
$buffer[$i]["adr_two_type"] .= "postal;";
}
if (!$buffer[$i]["adr_two_street"]) {
$buffer[$i]["adr_two_street"] = $values[2];
$buffer[$i]["adr_two_locality"] = $values[3];
$buffer[$i]["adr_two_region"] = $values[4];
$buffer[$i]["adr_two_postalcode"] = $values[5];
$buffer[$i]["adr_two_countryname"] = $values[6];
}
break;
default:
break;
}
break;
case "WORK":
if (!$buffer[$i]["adr_one_street"]) {
$buffer[$i]["address2"] = $values[1];
$buffer[$i]["adr_one_street"] = $values[2];
$buffer[$i]["adr_one_locality"] = $values[3];
$buffer[$i]["adr_one_region"] = $values[4];
$buffer[$i]["adr_one_postalcode"] = $values[5];
$buffer[$i]["adr_one_countryname"] = $values[6];
}
break;
case "HOME":
$buffer[$i]["adr_two_street"] = $values[2];
$buffer[$i]["adr_two_locality"] = $values[3];
$buffer[$i]["adr_two_region"] = $values[4];
$buffer[$i]["adr_two_postalcode"] = $values[5];
$buffer[$i]["adr_two_countryname"] = $values[6];
break;
default:
if (!$buffer[$i]["adr_one_street"]) {
$buffer[$i]["address2"] = $values[1];
$buffer[$i]["adr_one_street"] = $values[2];
$buffer[$i]["adr_one_locality"] = $values[3];
$buffer[$i]["adr_one_region"] = $values[4];
$buffer[$i]["adr_one_postalcode"] = $values[5];
$buffer[$i]["adr_one_countryname"] = $values[6];
}
break;
}
break;
case "TEL":
switch ($field[1]) {
case "PREF":
//echo $field[2]." is preferred";
if ($field[2]) {
$buffer[$i]["tel_prefer"] .= strtolower($field[2]) . ";";
}
break;
case "WORK":
$buffer[$i]["tel_work"] = $values[0];
if ($field[2] == "PREF") {
$buffer[$i]["tel_prefer"] .= strtolower($field[1]) . ";";
}
break;
case "HOME":
$buffer[$i]["tel_home"] = $values[0];
if ($field[2] == "PREF") {
$buffer[$i]["tel_prefer"] .= strtolower($field[1]) . ";";
}
break;
case "VOICE":
$buffer[$i]["tel_voice"] = $values[0];
if ($field[2] == "PREF") {
$buffer[$i]["tel_prefer"] .= strtolower($field[1]) . ";";
}
break;
case "FAX":
$buffer[$i]["tel_fax"] = $values[0];
if ($field[2] == "PREF") {
$buffer[$i]["tel_prefer"] .= strtolower($field[1]) . ";";
}
break;
case "MSG":
$buffer[$i]["tel_msg"] = $values[0];
if ($field[2] == "PREF") {
$buffer[$i]["tel_prefer"] .= strtolower($field[1]) . ";";
}
break;
case "CELL":
$buffer[$i]["tel_cell"] = $values[0];
if ($field[2] == "PREF") {
$buffer[$i]["tel_prefer"] .= strtolower($field[1]) . ";";
}
break;
case "PAGER":
$buffer[$i]["tel_pager"] = $values[0];
if ($field[2] == "PREF") {
$buffer[$i]["tel_prefer"] .= strtolower($field[1]) . ";";
}
break;
case "BBS":
$buffer[$i]["tel_bbs"] = $values[0];
if ($field[2] == "PREF") {
$buffer[$i]["tel_prefer"] .= strtolower($field[1]) . ";";
}
break;
case "MODEM":
$buffer[$i]["tel_modem"] = $values[0];
if ($field[2] == "PREF") {
$buffer[$i]["tel_prefer"] .= strtolower($field[1]) . ";";
}
break;
case "CAR":
$buffer[$i]["tel_car"] = $values[0];
if ($field[2] == "PREF") {
$buffer[$i]["tel_prefer"] .= strtolower($field[1]) . ";";
}
break;
case "ISDN":
$buffer[$i]["tel_isdn"] = $values[0];
if ($field[2] == "PREF") {
$buffer[$i]["tel_prefer"] .= strtolower($field[1]) . ";";
}
break;
case "VIDEO":
$buffer[$i]["tel_video"] = $values[0];
if ($field[2] == "PREF") {
$buffer[$i]["tel_prefer"] .= strtolower($field[1]) . ";";
}
break;
default:
break;
}
break;
case "EMAIL":
switch ($field[1]) {
case "WORK":
$buffer[$i]["email"] = $values[0];
$buffer[$i]["email_type"] = $field[2];
break;
case "HOME":
$buffer[$i]["email_home"] = $values[0];
$buffer[$i]["email_home_type"] = $field[2];
break;
default:
if($buffer[$i]["email"]) {
$buffer[$i]["email_type"] = $field[2];
} elseif (!$buffer[$i]["email"]) {
$buffer[$i]["email"] = $values[0];
$buffer[$i]["email_type"] = $field[1];
}
break;
}
default:
break;
}
} else {
switch ($field[0]) {
case "N":
reset($this->names);
$j=0;
while(list($myname,$myval) = each($this->names) ) {
$namel = "n_".$myname;
$buffer[$i][$namel] = $values[$j];
$j++;
}
break;
case "FN":
$buffer[$i]["fn"] = $values[0];
break;
case "TITLE":
$buffer[$i]["title"] = $values[0];
break;
case "TZ":
$buffer[$i]["tz"] = $values[0];
break;
case "GEO":
$buffer[$i]["geo"] = $values[0];
break;
case "URL":
$buffer[$i]["url"] = $values[0];
break;
case "NOTE":
$buffer[$i]["note"] = ereg_replace("=0D=0A","\n",$values[0]);
break;
case "KEY":
$buffer[$i]["key"] = ereg_replace("=0D=0A","\n",$values[0]);
break;
case "LABEL":
$buffer[$i]["label"] = ereg_replace("=0D=0A","\n",$values[0]);
break;
case "BDAY": #1969-12-31
$tmp = split("-",$values[0]);
if ($tmp[0]) {
$buffer[$i]["bday"] = $tmp[1]."/".$tmp[2]."/".$tmp[0];
}
break;
}
}
}
$buffer[$i]["tel_prefer"] = substr($buffer[$i]["tel_prefer"],0,-1);
$buffer[$i]["adr_one_type"] = substr($buffer[$i]["adr_one_type"],0,-1);
$buffer[$i]["adr_two_type"] = substr($buffer[$i]["adr_two_type"],0,-1);
/*
echo '<br>';
reset($contacts->stock_contact_fields);
while (list($fname,$fvalue) = each($contacts->stock_contact_fields)) {
echo '<br>'.$i.': '.$fname.' => '.$buffer[$i][$fvalue];
}
echo '<br>';
*/
$contacts->add($phpgw_info["user"]["account_id"],$buffer[$i]);
} }
$num = $i - 1; $num = $i - 1;
return "Successfully imported $num records into your addressbook."; return "Successfully imported $num records into your addressbook.";