<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Miles Lott <milos@yahoo.com>            *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  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: contact.personal.class.php,v 1.1 2000/12/31 16:13:49 milosch Exp $ */

  /* This file is to be considered broken and wip */

class cdb_contact_personal_class extends cdb_generic_class {

  /////////////////////////////////////////////////
 ////////////// Public Variables /////////////////
/////////////////////////////////////////////////
/* These vars are declared like: 'var $varname;' */
/* These vars will be accessed directly.  There 
   should be very few of these as most will be 
   accessed through get and let functions.       */

  /////////////////////////////////////////////////
 /////////////// Local Variables /////////////////
/////////////////////////////////////////////////
/* PHP does not support local vars.  Use         */
/* 'var $_varname;' to signify local vars.       */
/* These vars are either not accessed by outside
   functions, or are accessed only through get 
   and let functions.                            */

  /////////////////////////////////////////////////
 //////////// Constructor Functions //////////////
/////////////////////////////////////////////////
	function cdb_entity_class() {
	  $this->_=array(
	    /* add vars that have get/let interface
	       to this array.                       */
	    "birthday" => "",
	    "children" => ""
	    "gender" => "",
	    "gov_id" => "",
	    "hobbies" => "",
	    "language" => "",
	    "language_id" => "",
	    "language_data" => "",
	    "spouse" => "",
	    "anniversary" => ""
	  );
	}

  /////////////////////////////////////////////////
 ////////////// Public Functions /////////////////
/////////////////////////////////////////////////
	function get_birthday() {
		return $this->get("birthday");
	}

	function let_birthday($new_birthday) {
		return $this->let("birthday", $new_birthday);
	}

	function get_children() {
		return $this->get("children");
	}

	function let_children($new_children) {
		return $this->let("children", $new_children);
	}

	function get_gender() {
		return $this->get("gender");
		#returns "unspecified"|"male"|"female"
	}

	function let_gender($new_gender) {
		return $this->let("gender", $new_gender);
	}

	function get_gov_id() {
		return $this->get("gov_id");
	}

	function let_gov_id($new_gov_id) {
		return $this->let("gov_id", $new_gov_id);
	}

	function get_hobbies() {
		return $this->get("hobbies");
	}

	function let_hobbies($new_hobbies) {
		return $this->let("hobbies", $new_hobbies);
	}

	function get_language() {
		return $this->get("language");
	}

	function let_language($new_language) {
		return $this->let("language", $new_language);
	}

	function get_language_id() {
		return $this->get("language_id");
		#returns int
	}

	function let_language_id($new_language_id) {
		return $this->let("language_id", $new_language_id);
	}

	function get_language_data() {
		return $this->get("language_data");
		return languages.class;
	}

	function get_spouse() {
		return $this->get("spouse");
	}

	function let_spouse($new_spouse) {
		return $this->let("spouse", $new_spouse);
	}

	function get_anniversary() {
		return $this->get("anniversary");
	}

	function let_anniversary($new_anniversary) {
		return $this->let("anniversary", $new_anniversary);
	}

	function save() {
		$mySuccess = FALSE;
		
		if($this->id() && $this->exists($this->id())) {
			$query = "UPDATE pgw_cdb_contact_personal SET ".
				 "birthday='".$this->get(birthday)."',".
				 "children='".$this->get(children)."',".
				 "gender='".$this->get(gender)."',".
				 "gov_id_num='".$this->get(gov_id_num)."',".
				 "hobbies='".$this->get(hobbies)."',".
				 "language='".$this->get(language)."',".
				 "spouse='".$this->get(spouse)."',".
				 "anniversary='".$this->get(anniversary)."' ".
				 "WHERE contact_id=".$this->id();

			$cdb = $phpgw->db;
			$cdb->query($query);
			$mySuccess = TRUE;
		}
		return $mySuccess;
	}

	function load($intID) {
		$query = "SELECT * FROM pgw_cdb_contact_personal WHERE contact_id='$intID'";
		$cdb = $phpgw->db;
		$cdb->query($query);
		$cdb->next_record();

		$personal["birthday"]		= $cdb->f("birthday");
		$personal["children"]		= $cdb->f("children");
		$personal["gender"]		= $cdb->f("gender");
		$personal["gov_id_num"]		= $cdb->f("gov_id_num");
		$personal["hobbies"]		= $cdb->f("hobbies");
		$personal["language"]		= $cdb->f("language");
		$personal["spouse"]		= $cdb->f("spouse");
		$personal["anniversary"]	= $cdb->f("anniversary");
		
		return $personal;
	}

	function delete() {
		/* NOTE: I assume someone with write access (can_write($intID) evaluates */
		/* to TRUE, has delete access as well */
		$mySuccess = FALSE;
		if($this->can_write($this->_id)) // check for write permission
		{
			if($this->meta->let_status("delete")) // try to set status to 'delete'
			{
				$mySuccess = TRUE; // report TRUE on success
			}
		}
	return $mySuccess;
	}

}
?>
