Location: PHPKode > projects > simpleMVC > myGifts/includes/Gift.class.php
<?php

class Gift {

	var $userId;
	var $id;
	var $name;
	var $comment;
	var $url;
	var $restricted;
	
	function Gift($id = "")
	{
		global $database, $user;
		
		$this->userId = $user->id;
		if (!empty($id)) {
			$this->id = (int) $id;
			$database->loadObject($this, "select * from gft_gift where forUser='".addslashes($this->userId)."' and id=".$this->id);
		}
	}
	
	function saveGift($name, $comment, $url, $restricted, $offered, $offeredOn)
	{
		global $database;

		$restricted = Tools::checkboxToInt($restricted);
		$offered = Tools::checkboxToInt($offered);

		if (!empty($this->id)) {
			$database->query("update gft_gift set name='".addslashes($name)."', comment='".addslashes($comment)."', url='".addslashes($url)."', restricted=$restricted, offered=$offered, offeredOn='".addslashes($offeredOn)."' where id=".$this->id." and forUser='".addslashes($this->userId)."'"); 
		} else
			$database->query("insert into gft_gift (forUser, name, comment, url, restricted, offered, offeredOn) values('".addslashes($this->userId)."', '".addslashes($name)."', '".addslashes($comment)."', '".addslashes($url)."', $restricted, $offered, '".addslashes($offeredOn)."')"); 

		return 0;
	}
	
	function removeGift()
	{
		global $database;
		
		$database->query("delete from gft_gift where id=".$this->id." and forUser='".addslashes($this->userId)."'"); 

		return 0;
	}

	function claimGift($userId)
	{
		global $database;
		
		$database->query("insert into gft_claim (giftId, userId) values(".$this->id.", '".addslashes($userId)."')"); 

		return 0;
	}

	function unclaimGift($userId)
	{
		global $database;
		
		$database->query("delete from gft_claim where giftId=".$this->id." and userId='".addslashes($userId)."'"); 

		return 0;
	}
	
	function offeredGift($offeredOn)
	{
		global $database;
		
		$database->query("delete from gft_claim where giftId=".$this->id." and userId='".addslashes($userId)."'"); 

		return 0;
	}
	
	function getParams()
	{
	}
}

Controler::registerHandler("modifyGift", "action", "Gift", array("id"), 1);
Controler::registerHandler("saveGift", "action", "Gift", array("id", "name", "comment", "url", "restricted", "offered", "offeredOn"), 1);
Controler::registerNextAction("saveGift", "myList");
Controler::registerHandler("removeGift", "action", "Gift", array("id"), 1);
Controler::registerHandler("claimGift", "action", "Gift", array("id", "user"), 1);
Controler::registerHandler("unclaimGift", "action", "Gift", array("id", "user"), 1);

?>
Return current item: simpleMVC