<?php
/**
 * ユーザーがログインしているかのチェック。
 * ログイン後のページのtopで呼び出され、通過した場合、$_accountにユーザーインスタンスが入ることが保証される。
 * $Id: check_login.inc,v 1.2 2015/10/08 11:49:32 wanggb Exp $
 * @author iimuro
 * @package manager.public_html
 */

ErrorLogger::doOutput("login check", 0);


if (isset($_SESSION["account"]) && (strtolower(get_class($_SESSION["account"])) == "accountmst")) {
	global $_account;
	// セッションに存在すれば、それを利用→通過
	$_account = $_SESSION["account"];
	ErrorLogger::doOutput($_account->login, 0);
} else {
	// 存在していなければ、ログイン画面表示
	$layout_pages = array();
	$layout_pages["top"] = "tab_login.inc";
	$layout_pages["middle"] = "login_form.inc";
	require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/topmenutopsub_layout.inc");
	exit;
}

/**
 * 権限チェックを行います。事前に$_accountがセットされていることが必須です。
 * @param unknown $allow_types  空 = 全部
 */
function checkAuthority($allow_types = null) {
	global $_account;
	if (empty($_account)) {
		$layout_pages = array();
		$layout_pages["top"] = "tab_login.inc";
		$layout_pages["middle"] = "login_form.inc";
		require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/topmenutopsub_layout.inc");
		exit;
	}
	
	ErrorLogger::doOutput($allow_types . $_account->modules,0);
	return true;
// 	// 超级管理员 或 无限制的场合,返回true
// 	if (empty($allow_types)) {
// 		return false;
// 	}
	
// 	$account_authority_type_list = explode("|", $_account->modules);
// 	foreach ($account_authority_type_list as $account_authority_type) {
// 	  if ($allow_types == $account_authority_type) {
// 			return true;
// 		}
// 	}
// 	return false;
}
?>