<?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     [[package名]]
 * @author      Your Name <mail@example.com>
 * @access      public
 */
class Admin_Usermanage_Itemattribute_Taglist
{
    /**
     * [[機能説明]]
     *
     * @access  public
     */

    var $c_itemattr;
    var $session;
    var $row;
    var $taglist;
    var $key;

    var $title;
    var $pagename;

    // 入力パラメータ
    var $cnt;           // 総登録件数
    var $pageID;        // 表示するページID
    var $srcword;       // 検索値
    var $srcdispnum;    // 表示件数 used
    var $srcdispnumlist;// 表示件数リスト
   
	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;

	function getPager()
	{
        // Pager設定
        $pageparams = array(
        'totalItems'    => $this->cnt,
        'perPage'       => $this->Pager_perPage,       // １ページの行数
        'delta'         => $this->Pager_delta,       // 表示ページから、前後に表示するページ数
        'append'        => $this->Pager_append,
        'currentPage'   => $this->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,
        );
        
        // Pager出力
        $pager = & Pager::factory($pageparams);
        $this->pagedata = $pager->getPageData();
        $link =	$pager->getLinks();
        return $link["all"];
	}

	function getTaglist()
	{
	    $res = $this->taglist;
	    return $res;
	}
	
	function outputTaglist()
	{
	    $this->row = $this->c_itemattr->selectAllTag($this->key, $this->srcword, $this->Pager_perPage, $this->Pager_perPage*($this->pageID - 1));
	    //商品名、ユーザ名をコードから取得して新たに配列を組みなおす
	    $newlist = array();
	    $line    = 0;
	    foreach($this->row as $tag){
	        $line        = $line + 1;
	        $itemnm      = $this->c_itemattr->getItemName($tag['itemcd']);
	        $tempusernm  = $this->c_itemattr->getUserName($tag['usercd']);
	        $usernm      = $tempusernm['lastnm'] . " " . $tempusernm['firstnm'];
	        $adddate     = substr(strval($tag['adddate']),0,10);
	        $divideddate = explode("-",$adddate);
	        $newdate     = $divideddate[0] . "/" . $divideddate[1] . "/" . $divideddate[2];
	        $newtag      = array("line"   => $line, 
								 "adddate"  => $newdate, 
								 "tagnm"    => $tag['tagnm'], 
								 "itemnm"   => $itemnm['itemnm'], 
								 "membernm" => $usernm,
								 "tagcd"    => $tag['tagcd'],
								 "icd"      => $tag['itemcd'],
								 "mcd"      => $tag['usercd']);
	        //組みなおした列を新たな配列の最後尾に追加
	        array_push($newlist,$newtag);
	    }
	    $res = $newlist;
	    return $res;
	}
	
    function execute()
    {
		// ページ設定
	    if(is_null($this->pageID))
            $this->pageID = 1;
        
       // 一覧表示件数
        if (!empty($this->srcdispnum)) $this->Pager_perPage = $this->srcdispnum;
        
        $this->srcdispnumlist = array();
        $this->srcdispnumlist[] = 10;
        $this->srcdispnumlist[] = 20;
        $this->srcdispnumlist[] = 50;
        $this->srcdispnumlist[] = 100;
       
        $this->taglist = $this->outputTaglist();

        $this->cnt = $this->c_itemattr->getRegistTagNumber($this->srcword);

        $log =& LogFactory::getLog();
        $log->debug("Admin_Usermanage_Itemattribute_Taglistが実行されました", "Admin_Usermanage_Itemattribute_Taglist#execute");

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

    function getFrom()
    {
        $from = "admin_usermanage_itemattribute_taglist" .
                "&key="        . $this -> key .
                "&srcdispnum=" . $this -> srcdispnum .
                "&srcword="    . $this -> srcword . 
                "&pageID="     . $this -> pageID;
        $encodeFrom = urlencode($from);
        return $encodeFrom;
    }
}
?>