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


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

/**
 * 構成情報変更
 *
 * @package     Admin.Itemmanage.Change.Struct.Update.Done
 * @author      H.Watanabe <hiroshi.watanabe@netnee.jp>
 * @access      public
 */
class Admin_Itemmanage_Change_Struct_Update_Done
{
    var $itemstruct;
    var $dlitem;
    
    var $actionChain;
    
    var $title;
    var $pagename;
    var $from;
    var $div;
    
    var $itemdiv;
    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 $sort;
    var $genre_select;
    
    var $upduser;
    
    var $cd;
    var $structcd;
    var $itemnm;
    var $variationnm;
    var $jancd;
    var $isbncd;
    var $makeritemcd;
    var $salestartdate;
    var $makerprice;
    var $orderclosedate;
    var $saleformcd;
    var $rectime;
    var $mediacd;
    var $struct_comment;
    var $item_struct_updcnt;
    

    var $option01;
    var $option02;
    var $option03;
    var $option04;
    var $option05;
    var $option06;
    var $option07;
    var $option08;
    var $option09;
    var $option10;

    var $option;


    var $download;
    var $dlperioddays;
    var $sellingprice;
    var $stockcd;
    
    /**
     * execute
     *
     * @access  public
     */
    function execute()
    {
        $errorList =& $this->actionChain->getCurErrorList();
        
        $log =& LogFactory::getLog();
        $log->debug("Admin_Itemmanage_Change_Struct_Update_Doneが実行されました", "Admin_Itemmanage_Change_Struct_Update_Done#execute");
        

        if (!empty($this->salestartdate)) {
            $this->salestartdate = str_replace("/", "-", $this->salestartdate);
        }
        if (!empty($this->orderclosedate)) {
            $this->orderclosedate = str_replace("/", "-", $this->orderclosedate);
        }

        $dldata = $stock = array();
        // ダウンロード
        if (!empty($this->download)) {
            // ダウンロード期間
            if (strlen($this->dlperioddays) <= 0) {
                $errorList -> add("error", "ダウンロード期間を入力してください");
                return 'input';
            }
            if (!is_numeric($this->dlperioddays)) {
                $errorList -> add("error", "ダウンロード期間は半角数字を入力してください");
                return 'input';
            }
            if ($this->dlperioddays < 0) {
                $errorList -> add("error", "ダウンロード期間は0以上を入力してください");
                return 'input';
            }

            // 販売価格
            if (strlen($this->sellingprice) <= 0) {
                $errorList -> add("error", "販売価格を入力してください");
                return 'input';
            }
            if (!is_numeric($this->sellingprice)) {
                $errorList -> add("error", "販売価格は半角数字を入力してください");
                return 'input';
            }
            if ($this->sellingprice < 0) {
                $errorList -> add("error", "販売価格は0以上を入力してください");
                return 'input';
            }

            // 在庫コード
            if (empty($this->stockcd)) {
                return 'input';
            }

            $dl = $this->dlitem->getDownloadItem($this->cd, $this->structcd);

            $dldata = array($dl["itemcd"],
                            $dl["structcd"],
                            $dl["fileexistence"],
                            $dl["dlcount"],
                            $this->dlperioddays,
                            $dl["comment"],
                            $this->upduser,
                            $_SERVER["REMOTE_ADDR"],
                            $dl["updcnt"]);
            $stock = array($this->cd,
                           $this->structcd,
                           $this->stockcd,
                           $this->sellingprice,
                           0,
                           $this->upduser,
                           $_SERVER["REMOTE_ADDR"]);
        }
        
        
        $res = $this->itemstruct->update($this->cd,
                                         $this->structcd, 
                                         $this->variationnm, 
                                         $this->makeritemcd, 
                                         $this->jancd, 
                                         $this->salestartdate, 
                                         $this->orderclosedate,
                                         $this->makerprice, 
                                         $this->struct_comment, 
                                         $this->option01,
                                         $this->option02,
                                         $this->option03,
                                         $this->option04,
                                         $this->option05,
                                         $this->option06,
                                         $this->option07,
                                         $this->option08,
                                         $this->option09,
                                         $this->option10,
                                         $this->download,
                                         $dldata,
                                         $stock,
                                         $this->upduser,
                                         $this->item_struct_updcnt);
        
        if (is_array($res)){
            $errorList -> add("Error", $res["errmsg"]);
            return 'error';
        }
        if (is_object($res)){
            return 'error';
        }
        
        return 'done_success';
    }
}
?>
