<?php
/*
	+-----------------------------------------------------------------------------+
	| ILIAS open source                                                           |
	+-----------------------------------------------------------------------------+
	| Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
	|                                                                             |
	| 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. |
	+-----------------------------------------------------------------------------+
*/

/**
* Class ilPaymentBillVendor
* 
* @author Stefan Meyer <smeyer@databay.de>
* @version $Id: class.ilPaymentBillVendor.php 15697 2008-01-08 20:04:33Z hschottm $
*
* @extends ilObject
* @package ilias-core
*/

class ilPaymentBillVendor
{
	var $db = null;
	var $lang = null;
	var $pobject_id = null;

	var $has_data = false;


	/**
	* Constructor
	* @access	public
	*/
	function ilPaymentBillVendor($a_pobject_id)
	{
		global $ilDB,$lng;

		$this->db =& $ilDB;
		$this->lng =& $lng;
		$this->pobject_id = $a_pobject_id;

		$this->__read();
	}

	// METHODS FOR INTERNAL ERROR HANDLING
	function getMessage()
	{
		return $this->message;
	}
	function setMessage($a_message)
	{
		$this->message = $a_message;
	}
	function appendMessage($a_message)
	{
		$this->message .= "<br />".$a_message;
	}

	function delete()
	{
		$query = "DELETE FROM payment_bill_vendor ".
			"WHERE pobject_id = '".$this->pobject_id."'";

		$this->db->query($query);

		return true;
	}




	// SET GET
	function getPobjectId()
	{
		return $this->pobject_id;
	}
	function hasData()
	{
		return (bool) $this->has_data;
	}
	function setGender($a_gender)
	{
		$this->gender = $a_gender;
	}
	function getGender()
	{
		return $this->gender;
	}
	function setFirstname($a_firstname)
	{
		$this->firstname = $a_firstname;
	}
	function getFirstname()
	{
		return $this->firstname;
	}
	function setLastname($a_lastname)
	{
		$this->lastname = $a_lastname;
	}
	function getLastname()
	{
		return $this->lastname;
	}
	function getTitle()
	{
		return $this->title;
	}
	function setTitle($a_title)
	{
		$this->title = $a_title;
	}
	function getInstitution()
	{
		return $this->institution;
	}
	function setInstitution($a_institution)
	{
		$this->institution = $a_institution;
	}
	function getDepartment()
	{
		return $this->department;
	}
	function setDepartment($a_department)
	{
		$this->department = $a_department;
	}
	function getStreet()
	{
		return $this->street;
	}
	function setStreet($a_street)
	{
		$this->street = $a_street;
	}
	function getZipcode()
	{
		return $this->zipcode;
	}
	function setZipcode($a_zipcode)
	{
		$this->zipcode = $a_zipcode;
	}
	function getCity()
	{
		return $this->city;
	}
	function setCity($a_city)
	{
		$this->city = $a_city;
	}
	function getCountry()
	{
		return $this->country;
	}
	function setCountry($a_country)
	{
		$this->country = $a_country;
	}
	function getPhone()
	{
		return $this->phone;
	}
	function setPhone($a_phone)
	{
		$this->phone = $a_phone;
	}
	function getFax()
	{
		return $this->fax;
	}
	function setFax($a_fax)
	{
		$this->fax = $a_fax;
	}
	function getEmail()
	{
		return $this->email;
	}
	function setEmail($a_email)
	{
		$this->email = $a_email;
	}
	function getAccountNumber()
	{
		return $this->account_number;
	}
	function setAccountNumber($a_account_number)
	{
		$this->account_number = $a_account_number;
	}
	function getBankcode()
	{
		return $this->bankcode;
	}
	function setBankcode($a_bankcode)
	{
		$this->bankcode = $a_bankcode;
	}
	function getIban()
	{
		return $this->iban;
	}
	function setIban($a_iban)
	{
		$this->iban = $a_iban;
	}
	function getBic()
	{
		return $this->bic;
	}
	function setBic($a_bic)
	{
		$this->bic = $a_bic;
	}
	function getBankname()
	{
		return $this->bankname;
	}
	function setBankname($a_bankname)
	{
		$this->bankname = $a_bankname;
	}

	function validate()
	{
		$this->setMessage('');

		if(!$this->getGender())
		{
			$this->appendMessage($this->lng->txt('gender'));
		}
		if(!$this->getFirstname())
		{
			$this->appendMessage($this->lng->txt('firstname'));
		}
		if(!$this->getLastname())
		{
			$this->appendMessage($this->lng->txt('lastname'));
		}
		if(!$this->getStreet())
		{
			$this->appendMessage($this->lng->txt('street'));
		}
		if(!$this->getZipcode())
		{
			$this->appendMessage($this->lng->txt('zipcode'));
		}
		if(!$this->getCity())
		{
			$this->appendMessage($this->lng->txt('city'));
		}
		if(!$this->getCountry())
		{
			$this->appendMessage($this->lng->txt('country'));
		}
		if(!$this->getEmail())
		{
			$this->appendMessage($this->lng->txt('email'));
		}
		if(!$this->getAccountNumber())
		{
			$this->appendMessage($this->lng->txt('account_number'));
		}
		if(!$this->getBankcode())
		{
			$this->appendMessage($this->lng->txt('bankcode'));
		}
		if(!$this->getBankname())
		{
			$this->appendMessage($this->lng->txt('bankname'));
		}

		return $this->getMessage() ? false : true;
	}
	function update()
	{
		if(!$this->hasData())
		{
			$query = "INSERT INTO payment_bill_vendor ".
				"SET pobject_id = '".$this->getPobjectId()."'";

			$this->db->query($query);
		}
		$query = "UPDATE payment_bill_vendor ".
			"SET ".
			"gender = '".ilUtil::prepareDBString($this->getGender())."',".
			"firstname = '".ilUtil::prepareDBString($this->getFirstname())."',".
			"lastname = '".ilUtil::prepareDBString($this->getLastname())."',".
			"title = '".ilUtil::prepareDBString($this->getTitle())."',".
			"institution = '".ilUtil::prepareDBString($this->getInstitution())."',".
			"department = '".ilUtil::prepareDBString($this->getDepartment())."',".
			"street = '".ilUtil::prepareDBString($this->getStreet())."',".
			"zipcode = '".ilUtil::prepareDBString($this->getZipcode())."',".
			"city = '".ilUtil::prepareDBString($this->getCity())."',".
			"country = '".ilUtil::prepareDBString($this->getCountry())."',".
			"phone = '".ilUtil::prepareDBString($this->getPhone())."',".
			"fax = '".ilUtil::prepareDBString($this->getFax())."',".
			"email = '".ilUtil::prepareDBString($this->getEmail())."', ".
			"account_number = '".ilUtil::prepareDBString($this->getAccountNumber())."',".
			"bankcode = '".ilUtil::prepareDBString($this->getBankcode())."',".
			"iban = '".ilUtil::prepareDBString($this->getIban())."',".
			"bic = '".ilUtil::prepareDBString($this->getBic())."',".
			"bankname = '".ilUtil::prepareDBString($this->getBankname())."'".
			"WHERE pobject_id = '".$this->getPobjectId()."'";

		$this->db->query($query);
		$this->__read();
	}


	// PIRVATE
	function __read()
	{
		$query = "SELECT * FROM payment_bill_vendor ".
			"WHERE pobject_id = '".$this->getPobjectId()."'";

		$res = $this->db->query($query);
		while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
		{
			$this->has_data = true;

			$this->setGender($row->gender);
			$this->setFirstname($row->firstname);
			$this->setLastname($row->lastname);
			$this->setTitle($row->title);
			$this->setInstitution($row->institution);
			$this->setDepartment($row->department);
			$this->setStreet($row->street);
			$this->setZipcode($row->zipcode);
			$this->setCity($row->city);
			$this->setCountry($row->country);
			$this->setPhone($row->phone);
			$this->setFax($row->fax);
			$this->setEmail($row->email);
			$this->setAccountNumber($row->account_number);
			$this->setBankcode($row->bankcode);
			$this->setIban($row->iban);
			$this->setBic($row->bic);
			$this->setBankname($row->bankname);
		}
		return true;
	}


} 
?>
