<?php
/*															*/
/* File: definitions.php											*/
/* (c) 2003,2004 by Łukasz Tomicki <tomicki(at)o2(dot)pl> 	*/
/* Most recent version available @ : http://tomicki.net/	*/
/*															*/
/*
/*  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 Library 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.
/*															*/

// account options
$_OPTION['account_active'] = 1;
$_OPTION['account_disabled'] = 2;
$_OPTION['admin'] = 4;
$_OPTION['posting_allowed'] = 8;

// user options
$_OPTION['dont_quote_replies'] = 16;
$_OPTION['public_email'] = 32;
$_OPTION['sign_posts'] = 64;
$_OPTION['reply_notification'] = 128;

// post options 
$_OPTION['banned'] = 1;

class UserOptions 
{
	var $options;
	var $user;
	
	function UserOptions($user = 0)
	{
		global $_OPTION;
		if (!$user)
		{
			$this->options = $_OPTION['account_active'];
			return 0;
		}
			
		$result = mysql_query("select options from users where id = '$user' limit 1");
		$data = mysql_fetch_array($result);
		
		if ($data['options'])
		{
			$this->options = $data['options'];
			$this->user = $user;
		}
		
		else
		{
			$this->options = $_OPTION['account_active'];
			$this->user = 0;
		}
	}
	
	function SetTo($options)
	{
		$this->options = $options;
	}
	
	function Sync()
	{
		if (!$this->user)
			return 0;
			
		$option = $this->options;
		$user = $this->user;
		$query = "update users set options = $option where id = '$user' limit 1";
		mysql_query($query);
	}
	
	function Check($option)
	{
		if (!$option)
			return 0;
		
		return ( $this->options & $option );
	}
	
	function Set($option)
	{
		if (!$option)
			return 0;
		
		$this->options |= $option;
	}
	
	function Delete($option)
	{
		if (!$option)
			return 0;
		
		$this->options &= ~$option;
	}
}	
?>