From 7999df83bd340b2dcf8ed0e0de4c39caf525d2fe Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Fri, 23 Jan 2004 17:54:22 +0000 Subject: [PATCH] Nouveau fichier --- htdocs/contact/vcard.php | 58 ++++++++++++ htdocs/lib/vcard/vcard.class.php | 156 +++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+) create mode 100644 htdocs/contact/vcard.php create mode 100644 htdocs/lib/vcard/vcard.class.php diff --git a/htdocs/contact/vcard.php b/htdocs/contact/vcard.php new file mode 100644 index 00000000000..71e4ca5b9a9 --- /dev/null +++ b/htdocs/contact/vcard.php @@ -0,0 +1,58 @@ + + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + * + */ +require("./pre.inc.php"); +require("../contact.class.php"); +require (DOL_DOCUMENT_ROOT."/lib/vcard/vcard.class.php"); + +/* + * + * + */ +$contact = new Contact($db); +$contact->fetch($_GET["id"]); + +$v = new vCard(); + +$v->setName($contact->name, $contact->firstname, "", ""); + +$v->setPhoneNumber($contact->phone_perso, "PREF;HOME;VOICE"); + +if ($contact->birthday) + $v->setBirthday($contact->birthday); + +$v->setAddress("", "", "Musterstrasse 20", "Musterstadt", "", "98765", "Deutschland"); +$v->setEmail($contact->email); +//$v->setNote("You can take some notes here.\r\nMultiple lines are supported via \\r\\n."); +//$v->setURL("http://www.thomas-mustermann.de", "WORK"); + +$output = $v->getVCard(); +$filename = $v->getFileName(); + +Header("Content-Disposition: attachment; filename=$filename"); +Header("Content-Length: ".strlen($output)); +//Header("Connection: close"); +Header("Content-Type: text/x-vCard; name=$filename"); + +echo $output; + +$db->close(); +?> diff --git a/htdocs/lib/vcard/vcard.class.php b/htdocs/lib/vcard/vcard.class.php new file mode 100644 index 00000000000..5537d7365e3 --- /dev/null +++ b/htdocs/lib/vcard/vcard.class.php @@ -0,0 +1,156 @@ + 126) ) { // always encode "\t", which is *not* required + $h2 = floor($dec/16); $h1 = floor($dec%16); + $c = $escape.$hex["$h2"].$hex["$h1"]; + } + if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted + $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay + $newline = " "; + } + $newline .= $c; + } // end of for + $output .= $newline; + if ($jproperties[$key] = quoted_printable_encode($number); + } + + // UNTESTED !!! + function setPhoto($type, $photo) { // $type = "GIF" | "JPEG" + $this->properties["PHOTO;TYPE=$type;ENCODING=BASE64"] = base64_encode($photo); + } + + function setFormattedName($name) { + $this->properties["FN"] = quoted_printable_encode($name); + } + + function setName($family="", $first="", $additional="", $prefix="", $suffix="") { + $this->properties["N"] = "$family;$first;$additional;$prefix;$suffix"; + $this->filename = "$first%20$family.vcf"; + if ($this->properties["FN"]=="") $this->setFormattedName(trim("$prefix $first $additional $family $suffix")); + } + + function setBirthday($date) { // $date format is YYYY-MM-DD + $this->properties["BDAY"] = $date; + } + + function setAddress($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL") { + // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL" + $key = "ADR"; + if ($type!="") $key.= ";$type"; + $key.= ";ENCODING=QUOTED-PRINTABLE"; + $this->properties[$key] = encode($name).";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country); + + if ($this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] == "") { + //$this->setLabel($postoffice, $extended, $street, $city, $region, $zip, $country, $type); + } + } + + function setLabel($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL") { + $label = ""; + if ($postoffice!="") $label.= "$postoffice\r\n"; + if ($extended!="") $label.= "$extended\r\n"; + if ($street!="") $label.= "$street\r\n"; + if ($zip!="") $label.= "$zip "; + if ($city!="") $label.= "$city\r\n"; + if ($region!="") $label.= "$region\r\n"; + if ($country!="") $country.= "$country\r\n"; + + $this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($label); + } + + function setEmail($address) { + $this->properties["EMAIL;INTERNET"] = $address; + } + + function setNote($note) { + $this->properties["NOTE;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($note); + } + + function setURL($url, $type="") { + // $type may be WORK | HOME + $key = "URL"; + if ($type!="") $key.= ";$type"; + $this->properties[$key] = $url; + } + + function getVCard() { + $text = "BEGIN:VCARD\r\n"; + $text.= "VERSION:2.1\r\n"; + foreach($this->properties as $key => $value) { + $text.= "$key:$value\r\n"; + } + $text.= "REV:".date("Y-m-d")."T".date("H:i:s")."Z\r\n"; + $text.= "MAILER:PHP vCard class by Kai Blankenhorn\r\n"; + $text.= "END:VCARD\r\n"; + return $text; + } + + function getFileName() { + return $this->filename; + } +} +?>