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

/*
 * Created on 2007/02/04
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
class Onedepo_Logic_Itemupdate
{
    var $tname;
    var $series;
    var $maker;
    var $label;
    var $genre;

    var $seriesopt;
    var $itemdivradio;
    var $examopt;
    var $eirinadio;
    var $mediaradio;
    var $saleformradio;
    
    var $medianm;
    var $salefornm;
    
    var $supplidiv;

    function getSeriesOptions()
    {
        $this->seriesopt = $this->series->selectAll();
        return $this->seriesopt;
    }
    
    // 作品区分
    function getItemdivRadio($shopdiv=null)
    {
        if (empty($shopdiv)) {
            $this->itemdivradio = $this->tname->selectDivAll(1);
        } elseif ($shopdiv==1) {
            $where = " AND namecd <= 10 ";
            $this->itemdivradio = $this->tname->selectDivTerm(1, $where);
        } elseif ($shopdiv==2) {
            $where = " AND namecd >= 11 ";
            $this->itemdivradio = $this->tname->selectDivTerm(1, $where);
        }
        return $this->itemdivradio;
    }
    
    // 受審団体区分
    function getExamOptions($shopdiv=null)
    {
        if (empty($shopdiv)) {
            $this->examopt = $this->tname->selectDivAll(2);
        } elseif ($shopdiv==1) {
            $where = " AND namecd <= 20 ";
            $this->examopt = $this->tname->selectDivTerm(2, $where);
        } elseif ($shopdiv==2) {
            $where = " AND namecd >= 21 ";
            $this->examopt = $this->tname->selectDivTerm(2, $where);
        }
        return $this->examopt;
    }
    
    // 映倫規定
    function getEirinRadio()
    {
        $this->eirinadio = $this->tname->selectDivAll(3);
        return $this->eirinadio;
    }
    
    // メディア
    function getMediaRadio()
    {
        $this->mediaradio = $this->tname->selectDivAll(4);
        return $this->mediaradio;
    }
    
    // 販売形態
    function getSaleformRadio()
    {
        $this->saleformradio = $this->tname->selectDivAll(5);
        return $this->saleformradio;
    }
    
    // 仕入区分
    function SupplidivList()
    {
        $this->supplidiv = $this->tname->selectDivAll(8);
        return $this->supplidiv;
    }
    
    // コンディション
    function ConditionList()
    {
        $this->condition = $this->tname->selectDivAll(9);
        return $this->condition;
    }
    
    // 在庫状態
    function StockstateList()
    {
        $this->stockstate = $this->tname->selectDivAll(10);

        return $this->stockstate;
    }

    // 在庫状態 ケース分岐
    function StockstateListbyCase($case)
    {
        if($case == "insert" or $case == "1" or $case == "2" or $case == "3"){ 
           $this->stockstate = $this->tname->selectDivAll(10);
           
           $state[] = $this->stockstate[2];
        
           return $state;
        }
        elseif($case == "5"){
        $this->stockstate = $this->tname->selectDivAll(10);
        
           $state[] = $this->stockstate[0];
           $state[] = $this->stockstate[2];
        
           return $state;
        }

    }


    // メーカー名
    function getMakernm($cd)
    {
        if (empty($cd)) return "";
        $maker = $this->maker->selectKey($cd);
        if (empty($maker["makernm"])) return "";
        return $maker["makernm"];
    }
    
    // レーベル名
    function getLabelnm($makercd, $cd)
    {
        if (empty($cd)) return "";
        $label = $this->label->selectKey($makercd, $cd);
        if (empty($label["labelnm"])) return "";
        return $label["labelnm"];
    }
    
    
    
    
    
    // シリーズ名
    function getSeriesnm($makercd,$seriescd)
    {
        if (empty($makercd)) return "";
        if (empty($seriescd)) return "";

        $series = $this->series->selectKeyView($makercd,$seriescd);

        if (empty($series["seriesnm"])) return "";
        return $series["seriesnm"];
    }
    
    
    
    
    
    
    // 作品区分名
    function getItemdivnm($cd)
    {
        if (empty($cd)) return "";
        $itemdiv = $this->tname->selectKey(1, $cd);
        if (empty($itemdiv["name"])) return "";
        return $itemdiv["name"];
    }
    
    // 受審団体区分名
    function getExamnm($cd)
    {
        if (empty($cd)) return "";
        $exam = $this->tname->selectKey(2, $cd);
        if (empty($exam["name"])) return "";
        return $exam["name"];
    }
    
    // 映倫規定名
    function getEirinnm($cd)
    {
        if (empty($cd)) return "";
        $eirin = $this->tname->selectKey(3, $cd);
        if (empty($eirin["name"])) return "";
        return $eirin["name"];
    }
    
    // メディア名
    function getMediaName($cd)
    {
        //$this->medianm = $this->tname->selectKey(4, $cd);
        //return $this->medianm;
        return $this->tname->selectKey(4, $cd);
    }
    
    // 販売形態名
    function getSaleforName($cd)
    {
        //$this->salefornm = $this->tname->selectKey(5, $cd);
        //return $this->salefornm;
        return $this->tname->selectKey(5, $cd);
    }
    
    // 仕入区分名
    function getSupplidivName($cd)
    {
        if (empty($cd)) return "";
        $eirin = $this->tname->selectKey(8, $cd);
        if (empty($eirin["name"])) return "";
        return $eirin["name"];

    }
    
    // コンディション名
    function getConditionName($cd)
    {
        if (empty($cd)) return "";
        $eirin = $this->tname->selectKey(9, $cd);
        if (empty($eirin["name"])) return "";
        return $eirin["name"];

    }
    
    // 在庫状態名
    function getStockstateName($cd)
    {
        if (empty($cd)) return "";
        $eirin = $this->tname->selectKey(10, $cd);
        if (empty($eirin["name"])) return "";
        return $eirin["name"];

    }



    function getGenreCheckbox($itemcd, $shopdiv=null)
    {
        $genredata = $this->genre->selectAll($shopdiv);
        $genrecd = $this->genre->getGenrecdForItemcd($itemcd);

        $genrechk = array();
        for ($i = 0; $i < count($genredata); $i++) {
            if (!empty($genredata[$i]["parentcd"])) {
                $genrechk[$i]["genrecd"] = $genredata[$i]["genrecd"];
                $genrechk[$i]["genrenm"] = $genredata[$i]["genrenm"];
                $genrechk[$i]["checked"] = "";
                if (in_array($genredata[$i]["genrecd"], $genrecd)) {
                    $genrechk[$i]["checked"] = " checked";
                }
            }
        }
        return $genrechk;
    }

    function getGenrenmList($genrecd)
    {
        $genredata = $this->genre->getGenrenmList($genrecd);
        return $genredata;
    }
    
    function setItemImage($cd, $size)
    {
        $work = IMAGE_WORKDIR ."/". $cd . $size . ".jpg";
        $item = IMAGE_DIR ."/1/". $cd . $size . ".jpg";
        
        if( file_exists($work) ) {
            
            if( copy($work, $item) ) {
                return true;
            }
            
        } else {
            return false;
        }
    }
    
    function delWorkImage($cd)
    {
        foreach (glob(IMAGE_WORKDIR ."/".$cd."*", GLOB_NOSORT) as $filename) {
            @unlink($filename);
        }
    }


    /**
     * オプション情報の取得
     **/
    function getOptionList($term1,$term2) {
        $opt = $this->tname->selectOptionTerm($term1,$term2);
        $option = array();
        foreach ($opt as $val) {
            if ($val["namecd"] == 1) {
                $option[$val["namediv"]]["name"] = $val["name"];
            } elseif ($val["namecd"] >= 2) {
                // nameを登録する場合
                $option[$val["namediv"]]["attributes"][$val["name"]] = $val["name"];
                // namecdを登録する場合
                //$option[$val["namediv"]]["attributes"][$val["namecd"]] = $val["name"];
            }
        }
        return $option;
    }
    
}
?>
