<?php
/**
@brief クラスメソッド集
@author minahito
*/

require_once dirname(__FILE__)."/../framechecker.php";
__exframe_version__('0.8.7');	// @todo ここ書き換えないと……

require_once "xoops/perm.php";

define("_BXPARTY_STATUS_BOTH",0);
define("_BXPARTY_STATUS_PARTY",5);
define("_BXPARTY_STATUS_ENTRY",10);

class bxParty {
	function &getHandler($name) {
		global $xoopsModule;
		global $__bxparty_handelrs_cache__;
		global $xoopsDB;

		$name=strtolower(trim($name));
		if(!isset($__bxparty_handelrs_cache__[$name])) {
			$class = 'bxParty'.ucfirst($name).'Object';

			if(!class_exists($class)) { // １回だけ読み込む
				$filename = XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/class/".$name.".php";
				if(file_exists($filename)) {
					require_once($filename);
				}
			}

			$handler_class = $class."Handler";
			if(class_exists($handler_class)) {
				$__bxparty_handelrs_cache__[$name] = new $handler_class($xoopsDB);
			}
			else { // 一回だけ読み込む
				$__bxparty_handelrs_cache__[$name] = new exXoopsObjectHandler($xoopsDB,$class);
			}
			return $__bxparty_handelrs_cache__[$name];
		}
		else {
			return $__bxparty_handelrs_cache__[$name];
		}
	}

	function Guard($party) {
		global $xoopsUser;
		global $xoopsModule;
		if(!is_object($party)) return false;
		if($party->getVar('private')){
			if(!exPerm::Guard('view_party_private')) return false;

        	$flag = Session::is_registered($xoopsModule->dirname().":"."access".$party->getVar('id'));

        	if(!$flag){
        		if(is_object($xoopsUser))
	        		$flag = (exPerm::Guard('view_private_force') or $xoopsUser->uid()==$party->getVar('uid'));
	        	else
	        		$flag = exPerm::Guard('view_private_force');
        	}
        
			return $flag;
		}
		else
			return exPerm::Guard('view_party_public');
	}
}

?>