<?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.Preitem.Download
 * @author      H.Watanabe <hiroshi.watanabe@netnee.jp>
 * @access      public
 */
class Admin_Itemmanage_Preitem_Download
{
    // components
    var $actionChain;
    var $tmaker;
    var $view;
    var $m_name;
    var $castnm;
    var $media_list;
    var $tname;
    var $genreview;
    var $genre_search;
    var $db_preitem;
    var $lg_itemupdate;
    
    var $title;
    var $pagename;

    // param
    var $preitemcd;
    //-- param 
    
    var $result;
    //var $genre;
    //var $basic_option;
    //var $struct_option;
    
    function execute()
    {
        $log =& LogFactory::getLog();
        $log->debug("Admin_Itemmanage_Preitem_Downloadが実行されました", "Admin_Itemmanage_Preitem_Download#execute");
        
        $errorList =& $this->actionChain->getCurErrorList();
        
        $this->result = $this->db_preitem->getOnePreItem($this->preitemcd);
        if ($this->result['download'] == '0') {
            //return 'error';
            exit;
        }

        $filename = glob(IMAGE_DIR ."/7/". 'preitem_' . $this->result['preitemcd']  .".*", GLOB_NOSORT);
        if(count($filename) == 0) {
            return 'error';
        }
        $this->doDownload($filename[0]);
        //$this->genre = $this->db_preitem->getOnePreGenre($this->preitemcd);
        
        //$this->basic_option = $this->lg_itemupdate->getOptionList(100,200);
        //$this->struct_option = $this->lg_itemupdate->getOptionList(200,300);
        
        return 'error';
    }

    function doDownload($down_filename)
    {
        $pathinfo = pathInfo($down_filename);

        header("Content-Transfer-Encoding: binary");
        header("Content-type: application/octet-stream");
        header("Content-Length: ". filesize($down_filename));
        //header("Content-Disposition: inline ; filename=".$pathinfo['basename']);
        header("Content-Disposition: attachment; filename=".$pathinfo['basename']);
        ob_clean();
        flush();
        readfile($down_filename);
        exit;
    }
}
?>
