Page
[ class tree: Page ] [ index: Page ] [ all elements ]

Source for file LC_Page_Mypage_DownLoad.php

Documentation is available at LC_Page_Mypage_DownLoad.php

  1. <?php
  2. /*
  3.  * This file is part of EC CUORE
  4.  *
  5.  * Copyright(c) 2009 CUORE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://ec.cuore.jp/
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  */
  23. // {{{ requires
  24. require_once CLASS_EX_REALDIR 'page_extends/LC_Page_Ex.php';
  25.  
  26. /**
  27.  * ダウンロード商品ダウンロード のページクラス.
  28.  *
  29.  * @package Page
  30.  * @author CUORE CO.,LTD.
  31.  * @version $Id: LC_Page_Mypage_DownLoad.php 20970 2011-06-10 10:27:24Z Seasoft $
  32.  */
  33. class LC_Page_Mypage_DownLoad extends LC_Page_Ex {
  34.  
  35.     // {{{ properties
  36.  
  37.     /** フォームパラメーターの配列 */
  38.     var $objFormParam;
  39.  
  40.     /** 基本Content-Type */
  41.     var $defaultContentType = 'Application/octet-stream';
  42.  
  43.     /** 拡張Content-Type配列
  44.      * Application/octet-streamで対応出来ないファイルタイプのみ拡張子をキーに記述する
  45.      * 拡張子が本配列に存在しない場合は $defaultContentTypeを利用する */
  46.  
  47.     var $arrContentType = array('apk' => 'application/vnd.android.package-archive');
  48.  
  49.     // }}}
  50.     // {{{ functions
  51.  
  52.     /**
  53.      * Page を初期化する.
  54.      *
  55.      * @return void 
  56.      */
  57.     function init({
  58.         parent::init();
  59.         $this->allowClientCache();
  60.     }
  61.  
  62.     /**
  63.      * Page のプロセス.
  64.      *
  65.      * @return void 
  66.      */
  67.     function process({
  68.         ob_end_clean();
  69.         parent::process();
  70.         $this->action();
  71.         $this->sendResponse();
  72.     }
  73.  
  74.     /**
  75.      * Page のAction.
  76.      *
  77.      * @return void 
  78.      */
  79.     function action({
  80.         // ログインチェック
  81.         $objCustomer new SC_Customer_Ex();
  82.         if (!$objCustomer->isLoginSuccess()){
  83.             SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
  84.         }
  85.  
  86.         // パラメーターチェック
  87.         $objFormParam new SC_FormParam_Ex();
  88.         $this->lfInitParam($objFormParam);
  89.         // GET、SESSION['customer']値の取得
  90.         $objFormParam->setParam($_SESSION['customer']);
  91.         $objFormParam->setParam($_GET);
  92.         $this->arrErr $this->lfCheckError($objFormParam);
  93.         if (count($this->arrErr)!=0){
  94.             SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
  95.         }
  96.     }
  97.  
  98.     /**
  99.      * Page のResponse.
  100.      *
  101.      * todo たいした処理でないのに異常に処理が重い
  102.      * @return void 
  103.      */
  104.     function sendResponse({
  105.         $this->objDisplay->noAction();
  106.  
  107.         // パラメーター取得
  108.         $customer_id $_SESSION['customer']['customer_id'];
  109.         $order_id $_GET['order_id'];
  110.         $product_id $_GET['product_id'];
  111.         $product_class_id $_GET['product_class_id'];
  112.  
  113.         //DBから商品情報の読込
  114.         $arrForm $this->lfGetRealFileName($customer_id$order_id$product_id$product_class_id);
  115.  
  116.         //ファイル情報が無い場合はNG
  117.         if ($arrForm["down_realfilename"== "" ){
  118.             SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
  119.         }
  120.         //ファイルそのものが無い場合もとりあえずNG
  121.         $realpath DOWN_SAVE_REALDIR $arrForm["down_realfilename"];
  122.         if (!file_exists($realpath)){
  123.             SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
  124.         }
  125.         //ファイル名をエンコードする Safariの対策はUTF-8で様子を見る
  126.         $encoding "Shift_JIS";
  127.         if(isset($_SERVER['HTTP_USER_AGENT']&& strpos($_SERVER['HTTP_USER_AGENT'],'Safari')) {
  128.             $encoding "UTF-8";
  129.         }
  130.         $sdown_filename mb_convert_encoding($arrForm["down_filename"]$encoding'auto');
  131.  
  132.         // flushなどを利用しているので、現行のSC_Displayは利用できません。
  133.         // SC_DisplayやSC_Responseに大容量ファイルレスポンスが実装されたら移行可能だと思います。
  134.  
  135.         // 拡張子を取得
  136.         $extension pathinfo($realpathPATHINFO_EXTENSION);
  137.         $contentType $this->defaultContentType;
  138.         // 拡張ContentType判定(拡張子をキーに拡張ContentType対象か判断)
  139.         if(isset($this->arrContentType[$extension])){
  140.             // 拡張ContentType対象の場合は、ContentTypeを変更
  141.             $contentType $this->arrContentType[$extension];
  142.         }
  143.         header("Content-Type: ".$contentType);
  144.         //ファイル名指定
  145.         header('Content-Disposition: attachment; filename="' $sdown_filename '"');
  146.         header("Content-Transfer-Encoding: binary");
  147.         //キャッシュ無効化
  148.         header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
  149.         header("Last-Modified: " gmdate("D,d M Y H:i:s"" GMT");
  150.         //IE6+SSL環境下は、キャッシュ無しでダウンロードできない
  151.         header("Cache-Control: private");
  152.         header("Pragma: private");
  153.         //ファイルサイズ指定
  154.         $zv_filesize filesize($realpath);
  155.         header("Content-Length: " $zv_filesize);
  156.         set_time_limit(0);
  157.         ob_end_flush();
  158.         flush();
  159.         //ファイル読み込み
  160.         $handle fopen($realpath'rb');
  161.         if ($handle === false{
  162.             SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
  163.             exit;
  164.         }
  165.  
  166.         while (!feof($handle)) {
  167.             echo(fread($handleDOWNLOAD_BLOCK*1024));
  168.             ob_flush();
  169.             flush();
  170.         }
  171.         fclose($handle);
  172.     }
  173.  
  174.     /**
  175.      * 商品情報の読み込みを行う.
  176.      *
  177.      * @param integer $customer_id 会員ID
  178.      * @param integer $order_id 受注ID
  179.      * @param integer $product_id 商品ID
  180.      * @param integer $product_class_id 商品規格ID
  181.      * @return array 商品情報の配列
  182.      */
  183.     function lfGetRealFileName($customer_id$order_id$product_id$product_class_id{
  184.         $objQuery new SC_Query_Ex();
  185.         $col = <<< __EOS__
  186.             pc.product_id AS product_id,
  187.             pc.product_class_id AS product_class_id,
  188.             pc.down_realfilename AS down_realfilename,
  189.             pc.down_filename AS down_filename,
  190.             o.order_id AS order_id,
  191.             o.customer_id AS customer_id,
  192.             o.payment_date AS payment_date,
  193.             o.status AS status
  194. __EOS__;
  195.  
  196.         $table = <<< __EOS__
  197.             dtb_products_class pc,
  198.             dtb_order_detail od,
  199.             dtb_order o
  200. __EOS__;
  201.  
  202.         $dbFactory SC_DB_DBFactory_Ex::getInstance();
  203.         $where "o.customer_id = ? AND o.order_id = ? AND pc.product_id = ? AND pc.product_class_id = ?";
  204.         $where .= " AND " $dbFactory->getDownloadableDaysWhereSql('o');
  205.         $where .= " = 1";
  206.         $arrRet $objQuery->select($col$table$where,
  207.                                     array($customer_id$order_id$product_id$product_class_id));
  208.         return $arrRet[0];
  209.     }
  210.  
  211.     /* パラメーター情報の初期化 */
  212.     function lfInitParam(&$objFormParam{
  213.         $objFormParam->addParam("customer_id""customer_id"INT_LEN'n'array("EXIST_CHECK","NUM_CHECK"));
  214.         $objFormParam->addParam("order_id""order_id"INT_LEN'n'array("EXIST_CHECK""NUM_CHECK"));
  215.         $objFormParam->addParam("product_id""product_id"INT_LEN'n'array("EXIST_CHECK","NUM_CHECK"));
  216.         $objFormParam->addParam("product_class_id""product_class_id"INT_LEN'n'array("EXIST_CHECK","NUM_CHECK"));
  217.     }
  218.  
  219.     /* 入力内容のチェック */
  220.     function lfCheckError(&$objFormParam{
  221.         $objErr new SC_CheckError_Ex($objFormParam->getHashArray());
  222.         $objErr->arrErr $objFormParam->checkError();
  223.         return $objErr->arrErr;
  224.     }
  225.  
  226.     /**
  227.      * デストラクタ.
  228.      *
  229.      * @return void 
  230.      */
  231.     function destroy({
  232.         parent::destroy();
  233.     }
  234. }
  235. ?>

Documentation generated on Fri, 24 Feb 2012 14:02:07 +0900 by Seasoft