<?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.History.List
 * @author      fuco T.Sakai <sakai@fuco.jp>
 * @access      public
 */
class Seller_Itemexhibit_History_List
{
	var $c_itemexhibit;
	
	var $history;
	var $auth;             //Authオブジェクトを取得
	var $authmembercd;
	
	var $pagename;
	var $title;
	var $pagehead;
	var $cnt;
	    
	//検索キーたち
	var $exno;
	var $itemnm;
	var $membercd;
	var $name;
	var $mailaddr;
	
	var $p_exno;
	var $p_itemnm;
	var $p_membercd;
	var $p_name;
	var $p_mailaddr;
	
	var $pager;
	var $pagerparam;
    var $page;
	
	var $dispatch_seller_itemexhibit_history_list;

    /**
     * [[機能説明]]
     *
     * @access  public
     */
    function execute()
    {
        if (!isset($this->page) || $this->page <= 1) $this->page = "1";
        //return "success";
        $this->authmembercd = $this->auth->getAuthData("membercd");
        
        //if ($this->dispatch_seller_itemexhibit_history_list == "戻る"){
            $this->exno     = $this->p_exno;
            $this->itemnm   = $this->p_itemnm;
            $this->membercd = $this->p_membercd;
            $this->name     = $this->p_name;
            $this->mailaddr = $this->p_mailaddr;
        //}
        
        if (empty($this->exno)){
            $this->exno = "";
        }
        
        if (empty($this->itemnm)){
            $this->itemnm = "";
        }
        
        if (empty($this->membercd)){
            $this->membercd = "";
        }
        
        if (empty($this->name)){
            $this->name = "";
        }
        
        if (empty($this->mailaddr)){
            $this->mailaddr = "";
        }

        //受注番号、受注日、購入者、評価を取得
        $limit = ITEMEXHIBIT_HISTORY;
        $offset = ITEMEXHIBIT_HISTORY*($this->page-1);
        $historyArray = $this->c_itemexhibit->getHistory($this->authmembercd,
                                                         $this->membercd,
                                                         $this->name,
                                                         $this->mailaddr,
                                                         $this->exno,
                                                         $this->itemnm, 
                                                         $limit,
                                                         $offset);
        $this->cnt = $this->c_itemexhibit->getHistoryCount($this->authmembercd,
                                                           $this->membercd,
                                                           $this->name,
                                                           $this->mailaddr,
                                                           $this->exno,
                                                           $this->itemnm);
        
        $tmpArray = array();
        
        foreach($historyArray as $row){
            $tmpArray[$row["orderno"]]["orderdate"] = $row["orderdate"];
            $tmpArray[$row["orderno"]]["customernm"] = (!empty($row["customernm"])) ? $row["customernm"] : $row["customernm2"];
            $tmpArray[$row["orderno"]]["valuation"] = $row["valuation"];
            $tmpArray[$row["orderno"]]["orderrow"][$row["orderrowno"]]["exno"] = $row["exno"];
            $tmpArray[$row["orderno"]]["orderrow"][$row["orderrowno"]]["itemnm"] = $row["itemnm"] ." ". $row["variationnm"];
            $tmpArray[$row["orderno"]]["orderrow"][$row["orderrowno"]]["count"] = $row["count"];
        }
        
        //ページング用にデータを整形＆ページング用の情報を取得
        $params =  $this->pagerparam->getPageParam( $this->cnt, ITEMEXHIBIT_HISTORY, $this->page);
        $params["urlVar"] = "page";
        
        $this->pager = Pager::factory($params);
        $this->link  = $this->pager->getLinks();
        
        $this -> history = $tmpArray;
        
        $log =& LogFactory::getLog();
        $log->debug("Seller_Itemexhibit_History_Listが実行されました", "Seller_Itemexhibit_History_List#execute");
        
        return 'success';
    }
    
    function getHistory()
    {
        return $this -> history;
    }
    
    function getLinks()
    {
        return $this->link["all"];
        
    }
}
?>
