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

class Admin_Portalmanage_Recommend_Regist
{
 // ページ情報
 var $pagename;
 var $title;

 // DB
 var $recommend;
 var $data;          // 商品情報

 // 保持パラメータ
 var $div;
 var $fromaction;    // 転送元アクション
 var $sort;          // ソートキー
 var $pageID;        // ページ番号
 var $srcword;       // 検索
 var $srcdispnum;    // 表示件数
  
 //追加
 var $fromdetai;
 var $from;
 
 
 // 表示件数
 var $srcdispnumlist;// 表示件数リスト


 // 商品検索用パラメータ
    var $jancode;
    var $hinban;
    var $itemtitle;
    var $release_date_start;
    var $release_date_end;
    var $publish_date_start;
    var $publish_date_end;
    var $maker_capital;
    var $maker_name;
    var $media;
    var $cast;
    var $situation;
    var $photo_situation;
    var $publish_situation;
    var $genre_select;


 // 入力パラメータ
    var $kubun;
    var $itemcd;
    var $updcnt;
    
    var $startdate;
    var $closedate;
    var $priority;
    
    var $change;  //　ページ遷移チェック
    
    var $item;
    
    var $prockbn;
    
    // エラー処理
    var $errormsg;
    
    function execute()
    {
      
        $this->data = array();

        // 必要なデータを取得する
        if($this->kubun==0) // 自動判別  
        {
            $row = $this->recommend->getOneRecommend($this->itemcd);
            if(count($row) != 0) { //データがある
                if ($row[0]["delflg"] == "f") { //delflgがたってない
                    $this->data = $row[0];
                    $this->prockbn = 2;
                } else { //delflgがたってる
                    $row2 = $this->recommend->getOneItem($this->itemcd);
                    $this->data = $row2[0];
                    $this->data["updcnt"] = $row[0]["updcnt"];
                    $this->prockbn = 1;
                }
                    
                $this->kubun = 2;
            } else { //データがない
   			    $row = $this->recommend->getOneItem($this->itemcd);
   			    if( count($row) != 0) {
   			        $this->data = $row[0];
   			        $this->kubun = 1;
   			        $this->prockbn = 1;
                } else {
                	$this->errormsg = "指定された商品コードが存在しません。";
                	return "error";
                }
            }
        } else if($this->kubun==1) { // 新規  
            $row = $this->recommend->getOneItem($this->itemcd);
            $this->data = $row[0];
            $this->prockbn = 1;
        } elseif($this->kubun==2 && !empty($this->itemcd)) { // 修正  
            $row = $this->recommend->getOneRecommend($this->itemcd);
            if ($row[0]["delflg"] == "f") {
                $this->data = $row[0];
                $this->prockbn = 2;
            } else {
   			    $row2 = $this->recommend->getOneItem($this->itemcd);
   			    $this->data = $row2[0];
   			    $this->data["updcnt"] = $row[0]["updcnt"];
   			    $this->prockbn = 1;
            }
        }
        
        // 入力エラー反映処理 (呼び出し元のActionからエラーメッセージ取得)
        $container =& DIContainerFactory::getContainer();
        $actionChain =& $container->getComponent("ActionChain");
        $errorListOfConfirm = &$actionChain->getErrorListByName("admin_portalmanage_recommend_confirm");
        if (!empty($errorListOfConfirm)) {
        	$errorList =& $actionChain->getCurErrorList();
        	$error = $errorListOfConfirm->getSelfMessages();
        	foreach( $error as $key=>$val)
        	    $errorList->Add($key, $val);
        }
         
        $log =& LogFactory::getLog();
        $log->debug("Admin_Portalmanage_Recommend_Registが実行されました", "Admin_Portalmanage_Recommend_Regist#execute");
        return 'success';
    }
    /**
     * リスト復帰用の検索条件保持URLパラメータ出力
     *
     * @return object
     */
    function getExtraParam()
    {
		return  '<input type="hidden" name="fromaction" value="'.$this->fromaction.'">'.
 				'<input type="hidden" name="sort" value="'.$this->sort.'">'.
				'<input type="hidden" name="pageID" value="'.$this->pageID.'">'.
				'<input type="hidden" name="srcword" value="'.$this->srcword.'">'.
				'<input type="hidden" name="srcdispnum" value="'.$this->srcdispnum.'">';
    }
    /**
     * リスト復帰用URLパラメータ出力
     *
     * @return object
     */
    function getReturnParam()
    {
		   if ( $this->fromaction == 'admin_portalmanage_recommend_list' ) {
                return  'div='.$this->div.
                        '&action='.$this->fromaction.
	                    '&sort='.$this->sort.
	                    '&pageID='.$this->pageID.
	                    '&srcword='.$this->srcword.
	                    '&srcdispnum='.$this->srcdispnum;
            } else {
                $return='div='.$this->div.
                        '&action='.$this->fromaction.
                        '&cd='.$this->itemcd.
                        '&jancode='.urlencode($this->jancode).
                        '&hinban='.urlencode($this->hinban).
                        '&itemtitle='.urlencode($this->itemtitle).
                        '&release_date_start='.$this->release_date_start.
                        '&release_date_end='.$this->release_date_end.
                        '&publish_date_start='.$this->publish_date_start.
                        '&publish_date_end='.$this->publish_date_end.
                        '&maker_capital='.$this->maker_capital.
                        '&maker_name='.$this->maker_name.
                        '&media='.$this->media.
                        '&cast='.urlencode($this->cast).
                        '&situation='.$this->situation.
                        '&photo_situation='.$this->photo_situation.
                        '&publish_situation='.$this->publish_situation.
                        '&sort='.$this->sort.
                        '&from='.$this->from;
                foreach ($this->genre_select as $val) {
                    $return .= '&genre_select[]='.$val;
                }
                return $return;
            }
    }
    
    
    function getProcKbnMsg()
    {
        if($this->prockbn == 1){
            return "登録";
        } else {
            return "変更";
        }
    }
    
    function getReturnMsg()
    {
        if($this->fromdetai == 1){
            return "詳細画面へ";
        } else {
            return "一覧へ戻る";
        }
    }
}
?>