<?php
/**
 * @copyright ONE/DEPO Project
 * @license   PHP License 3.01 <http://www.php.net/license/3_01.txt>
 */


require_once 'Pager.php';

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * 出品中リスト
 *
 * @package     Seller.Itemexhibit.Now.List
 * @author      S.Oguma <shinichiro.oguma@netnee.jp>
 * @access      public
 */
class Seller_Itemexhibit_Now_List
{
    var $view;
    var $auth;
    var $session;

    var $bodyid;
    var $title;

    var $results;
    var $itemregist;
    var $itemregist_serial;
    var $actionChain;

    var $list_check;
    var $list_check_serial;
    
	//DB
	var $itemexhibit;
	var $data;
	var $cnt;
	
	// 入力パラメータ
	var $sort;
	var $pageID;
	var $listsize;
	var $size;
	
	// 検索条件のURLパラメータ
    var $extrastr;
    var $extratag;

	// 検索パラメータ
	var $stockcd;
	var $exdate;
	var $titlenm;
	var $scdcompdate;
	var $membercd;
	var $membernm;
	var $mailaddr;
	var $image;
	var $status;
	
	// リストのページング
	var $pagedata;    // Pagerデータ
	var $nowpages;
	var $totalpages;
	var $links;       // Pagerリンク

	var $Pager_perPage;
	var $Pager_delta;
	var $Pager_append;
	var $Pager_clearIfVoid;
	var $Pager_urlVar;
	var $Pager_useSessions;
	var $Pager_closeSession;
	var $Pager_mode;
	var $Pager_prevImg;
	var $Pager_nextImg;
	var $Pager_altPage;
	var $Pager_altPrev;
	var $Pager_altNext;
	var $Pager_altFirst;
	var $Pager_altLast;
	var $Pager_firstPagePre;
	var $Pager_firstPageText;
	var $Pager_firstPagePost;
	var $Pager_lastPagePre;
	var $Pager_lastPageText;
	var $Pager_lastPagePost;
	var $Pager_separator;
	var $Pager_spacesBeforeSeparator;
	var $Pager_spacesAfterSeparator;
	var $Pager_curPageSpanPre;
	var $Pager_curPageSpanPost;

    /**
     * Actionの実行
     *
     * @access  public
     */
    function execute()
    {
        $log =& LogFactory::getLog();
        $log->debug("Seller_Itemexhibit_Now_Listが実行されました", "Seller_Itemexhibit_Now_List#execute");

		// ページングデフォルト値設定 
		$pageID   = isset($this->pageID)  ?$this->pageID  :1;
		$listsize = isset($this->listsize)?$this->listsize:$this->Pager_perPage;
		$this->listsize = $listsize;

        // 並び替え
        $sorttype = array(
        "exdate"       => "adddate ",
        "-exdate"      => "adddate DESC ",
        "title"        => "itemnm ",
        "-title"       => "itemnm DESC "
        );
        if (empty($sorttype[$this->sort]))
            $this->sort = "-exdate";

        $sort = $sorttype[$this->sort];
        
        // 検索パラメータ
        $extraval = array();   // ソーティング、ページングなどで検索パラメータの保持に使用
        $where = array();  //　問い合わせに使用
        $where[] = "s.delflg='f'";
        if( isset($this->stockcd) && $this->stockcd!="" ) {
            $where[] = "s.stockcd = ".$this->stockcd;
            $extraval["stockcd"]=$this->stockcd;
        }
        if( isset($this->titlenm) && $this->titlenm!="" ) {
            $where[] = "i.itemnm like '%".$this->titlenm."%'";
            $extraval["titlenm"]=$this->titlenm;
        }
        if( $this->auth->auth->session['data']['membercd'] == "" ) {
            return 'login';
        }
        $where[] = "s.sellercd =".$this->auth->auth->session['data']['membercd'];

        $this->data = $this->itemexhibit->getItemexhibitList2($listsize,
                                                             $listsize*($pageID-1),
                                                             array($where),
                                                             array(),
                                                             $sort);
    	$this->cnt  = array_pop($this->data);
    	$this->size = sizeof($this->data);

    	
    	// Pager設定
    	$pageparams = array(
    	'totalItems'    => $this->cnt,
    	'perPage'       => $listsize,         // １ページの行数
    	'delta'         => $this->Pager_delta,       // 表示ページから、前後に表示するページ数
    	'append'        => $this->Pager_append,
    	'currentPage'   => $pageID,
    	'clearIfVoid'   => $this->Pager_clearIfVoid,
    	'urlVar'        => $this->Pager_urlVar,
    	'useSessions'   => $this->Pager_useSessions,
    	'closeSession'  => $this->Pager_closeSession,
    	'mode'          => $this->Pager_mode,
    	'prevImg'       => $this->Pager_prevImg,
    	'nextImg'       => $this->Pager_nextImg,
    	'altPage'       => $this->Pager_altPage,
    	'altPrev'       => $this->Pager_altPrev,
    	'altNext'       => $this->Pager_altNext,
    	'altFirst'      => $this->Pager_altFirst,
    	'altLast'       => $this->Pager_altLast,
    	'firstPagePre'  => $this->Pager_firstPagePre,
    	'firstPageText' => $this->Pager_firstPageText,
    	'firstPagePost' => $this->Pager_firstPagePost,
    	'lastPagePre'   => $this->Pager_lastPagePre,
    	'lastPageText'  => $this->Pager_lastPageText,
    	'lastPagePost'  => $this->Pager_lastPagePost,
    	'separator'     => $this->Pager_separator,
    	'spacesBeforeSeparator' => $this->Pager_spacesBeforeSeparator,
    	'spacesAfterSeparator'  => $this->Pager_spacesAfterSeparator,
        'curPageSpanPre'        => $this->Pager_curPageSpanPre,
        'curPageSpanPost'       => $this->Pager_curPageSpanPost,
    	'extraVars' => array_merge($extraval, array(
    	                          "sort"=>$this->sort,
    	                          "listsize"=>$this->listsize,
    	                          "action"=>"seller_itemexhibit_now_list"))
    	);

    	// Pager出力
    	$pager = & Pager::factory($pageparams);
    	$this->pagedata = $pager->getPageData();
    	$this->nowpages = $pager->getCurrentPageID();
    	$this->totalpages = $pager->numPages();
    	$this->links = $pager->getLinks();
    	
    	// URLパラメータ・タグ作成
    	$this->extrastr ="";
    	$this->extratag ="";
        foreach( $extraval as $key=>$val ) {
            if($this->extrastr=="")	$this->extrastr = "$key=$val";
            else $this->extrastr .="&$key=$val";
            $this->extratag .= "<input type='hidden' name='$key' value='$val'>\n";
        }

        return 'success';
    }
    
    function getLink()
    {
        return $this->links;
    }

	function setList_check(&$list_check)
	{
   		 $this -> list_check =& $list_check;
	}

    function getList_check()
	{
    	return $this -> list_check;
	}

    function setList_check_serial($value)
    {
        $value = urldecode($value);
        $this -> list_check_serial = $value;
        $this -> list_check = unserialize($value);
    }

    function getList_check_serial()
    {
        return urlencode(serialize($this -> list_check));
    }

    function getVariationNm($params)
    {
        return $this->itemexhibit->getVariationNm($params["itemcd"], $params["structcd"]);
    }
}
?>