<?php

/**
 * @package     Maple.filter
 * @author      netnee
 * @access      public
 */
class Filter_SellerState extends Filter
{
    /**
     * コンストラクター
     *
     * @access  public
     */
    function Filter_SellerState()
    {
        parent::Filter();
    }

    /**
     */
    function execute()
    {
        $log =& LogFactory::getLog();
        $log->trace("Filter_SellerStateの前処理が実行されました", "Filter_SellerState#execute");

        $through = FALSE;
        $container =& DIContainerFactory::getContainer();


        // 出品機能のチェックを行わない
        if ($this->getSize() > 0) {
            $through = $this->getAttribute("through");
            $log->debug("through " . $through, "Filter_SellerState#execute");
        }

        if (!$through) {
            // 出品機能無効
            if (!USE_FUNCTIONAL_EXHIBIT) {
                $log->error("出品不可", "Filter_SellerState#execute");
                header("location: ".ERROR_URL); 
                exit; 
            }

            if ($this->getSize() > 0) {
                $value = $this->getAttribute("seller");
                if (preg_match("/^ref:/", $value)) {
                    $value = preg_replace("/^ref:/", "", $value);
                    $component =& $container->getComponent($value);
                    if (is_object($component)) {
                        $seller =& $component;
                    } else {
                        $log->error("不正なコンポーネントが設定ファイルで指定されています($value)", "Filter_SellerState#execute");
                    }
                }
                $value = $this->getAttribute("auth");
                if (preg_match("/^ref:/", $value)) {
                    $value = preg_replace("/^ref:/", "", $value);
                    $component =& $container->getComponent($value);
                    if (is_object($component)) {
                        $auth =& $component;
                    } else {
                        $log->error("不正なコンポーネントが設定ファイルで指定されています($value)", "Filter_SellerState#execute");
                    }
                }
            }

            if (!$auth->checkAuth()) {
                $f = TRUE;
            } else {
                $membercd = $auth->getAuthData("membercd");
                $status = $seller->checkStatus($membercd);
                if (!$status["scd"]) {
                    $f = TRUE;
                }
            }

            if ($f===TRUE) {
                $log->error("出品不可", "Filter_SellerState#execute");
                header("location: ".ERROR_URL); 
                exit; 
            }
        }


        $filterChain =& $container->getComponent("FilterChain");
        $filterChain->execute();
    }
}
?>
