<?php
/* $Id: vcard_adr.php,v 1.1 2002/10/22 13:45:10 kfish Exp $ */

class VCard_ADR {

/*
 This property specifies a structured representation of the physical delivery address 
 for the vCard object. The property is made up of components that are based on the X.500 
 Post Office Box attribute, the X.520 Street Address geographical attribute, the X.520 
 Locality Name geographical attribute, the X.520 State or Province Name geographical attribute, 
 the X.520 Postal Code attribute, and the X.520 Country Name geographical attribute.
 This property is identified by the property name ADR. The property value consists of components 
 of the address specified as positional fields separated by the Field Delimiter character 
 (ASCII decimal 59). The property value is a concatenation of the Post Office Address (first field) 
 Extended Address (second field), Street (third field), Locality (fourth field), Region (fifth field), 
 Postal Code (six field), and Country (seventh field) strings. An example of this property follows:
 ADR;DOM;HOME:P.O. Box 101;Suite 101;123 Main Street;Any Town;CA;91921-1234;
 Support for this property is optional for vCard Writers conforming to this specification.
 Delivery Address Type
 This property parameter specifies the sub-types of physical delivery that is associated with the 
 delivery address. For example, the label may need to be differentiated for Home, Work, Parcel, 
 Postal, Domestic, and International physical delivery. One or more sub-types can be specified for 
 a given delivery address.
 The property parameter can have one or more of the following values:

 TYPE=
 DOM    - Indicates a domestic address
 INTL   - Indicates an international address (Default)
 POSTAL - Indicates a postal delivery address  (Default)
 PARCEL - Indicates a parcel delivery address  (Default)
 HOME   - Indicates a home delivery address
 WORK   - Indicates a work delivery address  (Default)

 The default property parameter is overridden to some other set of values by specifying one or 
 more alternate values. For example, the default of a delivery for INTL, WORK, POSTAL and PARCEL 
 can be reset to DOM, POSTAL, WORK and HOME in the following example:
  ADR;DOM;WORK;HOME;POSTAL:P.O. Box 101;;;Any Town;CA;91921-1234;
  
 */

    var $type;
    var $value;
    var $pobox;
    var $extadr;
    var $street;
    var $city;
    var $region;
    var $code;
    var $country; 

    function setIsHomeAddress() {
	$this->type["HOME"] = true;  
    }

    function resetHomeAddress() {
	$this->type["HOME"] = false;  
    }

    function IsHomeAddress() {
	return $this->type["HOME"];	
    }

    function setIsWorkAddress() {
	$this->type["WORK"] = true;  
    }

    function resetWorkAddress() {
	$this->type["WORK"] = false;  
    }

    function IsWorkAddress() {
	return $this->type["WORK"];	
    } 

    function getKey() {
	$tmpString = "ADR";
	while (list ($key, $val) = each ($this->type)) {
	    if ($val===true){
		$tmpString = $tmpString.";".$key;	
	    }
	}
	return $tmpString.":";
    }

    function getAddress() {
	return $this->pobox.";".$this->extadr.";".$this->street.";".$this->city.";".$this->region.";".$this->code.";".$this->country;
    }

    function setAddress($street,$city,$region,$code,$country,$pobox="",$extadr="") {
	$this->pobox = $pobox;
	$this->extadr = $extadr;
	$this->street = $street;
	$this->city = $city;
	$this->region = $region;
	$this->code = $code;
	$this->country = $country;
    }
 
    function VCard_ADR () {
	$numargs = func_num_args();
	$arg_list = func_get_args();

	$this->type["WORK"] = false;
	$this->type["HOME"] = false; 	
      
	switch ($numargs) {
    	case 5:
	    $this->setAddress($arg_list[0],$arg_list[1],$arg_list[2],$arg_list[3],$arg_list[4],"","");
	    break;
    	case 7:
	    $this->setAddress($arg_list[0],$arg_list[1],$arg_list[2],$arg_list[3],$arg_list[4],$arg_list[5],$arg_list[6]);
	    break;
	default:
	    break;
	}
    }

}

class VCard_WorkAddress extends VCard_ADR {
    function VCard_WorkAddress() {
	$numargs = func_num_args();
	$arg_list = func_get_args();

	$this->type["WORK"] = true;
	$this->type["HOME"] = false; 	
      
	switch ($numargs) {
    	case 5:
	    $this->setAddress($arg_list[0],$arg_list[1],$arg_list[2],$arg_list[3],$arg_list[4],"","");
	    break;
    	case 7:
	    $this->setAddress($arg_list[0],$arg_list[1],$arg_list[2],$arg_list[3],$arg_list[4],$arg_list[5],$arg_list[6]);
	    break;
	default:
	    break;
	}
    }
}

class VCard_HomeAddress extends VCard_ADR {
    function VCard_HomeAddress() {
	$numargs = func_num_args();
	$arg_list = func_get_args();

	$this->type["WORK"] = false;
	$this->type["HOME"] = true; 	

	switch ($numargs) {
    	case 5:
	    $this->setAddress($arg_list[0],$arg_list[1],$arg_list[2],$arg_list[3],$arg_list[4],"","");
	    break;
    	case 7:
	    $this->setAddress($arg_list[0],$arg_list[1],$arg_list[2],$arg_list[3],$arg_list[4],$arg_list[5],$arg_list[6]);
	    break;
	default:
	    break;
	}
    }
}

?>