source: branches/version-2_11-dev/data/class/pages/mypage/LC_Page_Mypage_DownLoad.php @ 20891

Revision 20891, 7.2 KB checked in by kajiwara, 13 years ago (diff)

#1273 ダウンロード商品取得部分もリンク表示と同じ条件に設定

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
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
24require_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$
32 */
33class LC_Page_Mypage_DownLoad extends LC_Page_Ex {
34
35    // {{{ properties
36
37    /** フォームパラメータの配列 */
38    var $objFormParam;
39
40    // }}}
41    // {{{ functions
42
43    /**
44     * Page を初期化する.
45     *
46     * @return void
47     */
48    function init() {
49        parent::init();
50        $this->allowClientCache();
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process() {
59        ob_end_clean();
60        parent::process();
61        $this->action();
62        $this->sendResponse();
63    }
64
65    /**
66     * Page のAction.
67     *
68     * @return void
69     */
70    function action() {
71        // ログインチェック
72        $objCustomer = new SC_Customer_Ex();
73        if (!$objCustomer->isLoginSuccess()){
74            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
75        }
76
77        // パラメータチェック
78        $objFormParam = new SC_FormParam_Ex();
79        $this->lfInitParam($objFormParam);
80        // GET、SESSION['customer']値の取得
81        $objFormParam->setParam($_SESSION['customer']);
82        $objFormParam->setParam($_GET);
83        $this->arrErr = $this->lfCheckError($objFormParam);
84        if (count($this->arrErr)!=0){
85            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
86        }
87    }
88
89    /**
90     * Page のResponse.
91     *
92     * todo たいした処理でないのに異常に処理が重い
93     * @return void
94     */
95    function sendResponse() {
96        $this->objDisplay->noAction();
97
98        // パラメータ取得
99        $customer_id = $_SESSION['customer']['customer_id'];
100        $order_id = $_GET['order_id'];
101        $product_id = $_GET['product_id'];
102        $product_class_id = $_GET['product_class_id'];
103
104        //DBから商品情報の読込
105        $arrForm = $this->lfGetRealFileName($customer_id, $order_id, $product_id, $product_class_id);
106
107        //ファイル情報が無い場合はNG
108        if ($arrForm["down_realfilename"] == "" ){
109            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
110        }
111        //ファイルそのものが無い場合もとりあえずNG
112        $realpath = DOWN_SAVE_REALDIR . $arrForm["down_realfilename"];
113        if (!file_exists($realpath)){
114            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
115        }
116        //ファイル名をエンコードする Safariの対策はUTF-8で様子を見る
117        $encoding = "Shift_JIS";
118        if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'Safari')) {
119            $encoding = "UTF-8";
120        }
121        $sdown_filename = mb_convert_encoding($arrForm["down_filename"], $encoding, 'auto');
122
123        // flushなどを利用しているので、現行のSC_Displayは利用できません。
124        // SC_DisplayやSC_Responseに大容量ファイルレスポンスが実装されたら移行可能だと思います。
125
126        //タイプ指定
127        header("Content-Type: Application/octet-stream");
128        //ファイル名指定
129        header("Content-Disposition: attachment; filename=" . $sdown_filename);
130        header("Content-Transfer-Encoding: binary");
131        //キャッシュ無効化
132        header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
133        header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
134        //IE6+SSL環境下は、キャッシュ無しでダウンロードできない
135        header("Cache-Control: private");
136        header("Pragma: private");
137        //ファイルサイズ指定
138        $zv_filesize = filesize($realpath);
139        header("Content-Length: " . $zv_filesize);
140        set_time_limit(0);
141        ob_end_flush();
142        flush();
143        //ファイル読み込み
144        $handle = fopen($realpath, 'rb');
145        while (!feof($handle)) {
146            echo(fread($handle, DOWNLOAD_BLOCK*1024));
147            ob_flush();
148            flush();
149        }
150        fclose($handle);
151    }
152
153    /**
154     * 商品情報の読み込みを行う.
155     *
156     * @param integer $customer_id 顧客ID
157     * @param integer $order_id 受注ID
158     * @param integer $product_id 商品ID
159     * @param integer $product_class_id 商品規格ID
160     * @return array 商品情報の配列
161     */
162    function lfGetRealFileName($customer_id, $order_id, $product_id, $product_class_id) {
163        $objQuery = new SC_Query_Ex();
164        $col = <<< __EOS__
165            pc.product_id AS product_id,
166            pc.product_class_id AS product_class_id,
167            pc.down_realfilename AS down_realfilename,
168            pc.down_filename AS down_filename,
169            o.order_id AS order_id,
170            o.customer_id AS customer_id,
171            o.payment_date AS payment_date,
172            o.status AS status
173__EOS__;
174
175        $table = <<< __EOS__
176            dtb_products_class pc,
177            dtb_order_detail od,
178            dtb_order o
179__EOS__;
180
181        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
182        $where = "o.customer_id = ? AND o.order_id = ? AND pc.product_id = ? AND pc.product_class_id = ?";
183        $where .= " AND " . $dbFactory->getDownloadableDaysWhereSql('o');
184        $where .= " = 1";
185        $arrRet = $objQuery->select($col, $table, $where,
186                                    array($customer_id, $order_id, $product_id, $product_class_id));
187        return $arrRet[0];
188    }
189
190    /* パラメータ情報の初期化 */
191    function lfInitParam(&$objFormParam) {
192        $objFormParam->addParam("customer_id", "customer_id", INT_LEN, 'n', array("EXIST_CHECK","NUM_CHECK"));
193        $objFormParam->addParam("order_id", "order_id", INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK"));
194        $objFormParam->addParam("product_id", "product_id", INT_LEN, 'n', array("EXIST_CHECK","NUM_CHECK"));
195        $objFormParam->addParam("product_class_id", "product_class_id", INT_LEN, 'n', array("EXIST_CHECK","NUM_CHECK"));
196    }
197
198    /* 入力内容のチェック */
199    function lfCheckError(&$objFormParam) {
200        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
201        $objErr->arrErr = $objFormParam->checkError();
202        return $objErr->arrErr;
203    }
204
205    /**
206     * デストラクタ.
207     *
208     * @return void
209     */
210    function destroy() {
211        parent::destroy();
212    }
213}
214?>
Note: See TracBrowser for help on using the repository browser.