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

Revision 19957, 7.4 KB checked in by eccuore, 13 years ago (diff)

#792(ダウンロード販売機能) TODOの対応、暫定的な修正をしていた部分の対応

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_REALDIR . "pages/LC_Page.php");
25
26/**
27 * ダウンロード商品ダウンロード のページクラス.
28 *
29 * @package Page
30 * @author CUORE CO.,LTD.
31 * @version $Id: LC_Page_Mypage_DownLoad.php 1 2009-08-04 00:00:00Z $
32 */
33class LC_Page_Mypage_DownLoad extends LC_Page {
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();
73        if (!$objCustomer->isLoginSuccess()){
74            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
75        }
76
77        // パラメータチェック
78        $this->objFormParam = new SC_FormParam();
79        $this->lfInitParam();
80        // GET、SESSION['customer']値の取得
81        $this->objFormParam->setParam($_SESSION['customer']);
82        $this->objFormParam->setParam($_GET);
83        $this->arrErr = $this->lfCheckError();
84        if (count($this->arrErr)!=0){
85            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
86        }
87    }
88
89    /**
90     * Page のResponse.
91     * @return void
92     */
93    function sendResponse() {
94        $this->objDisplay->noAction();
95
96        // パラメータ取得
97        $customer_id = $_SESSION['customer']['customer_id'];
98        $order_id = $_GET['order_id'];
99        $product_id = $_GET['product_id'];
100        $product_class_id = $_GET['product_class_id'];
101
102        //DBから商品情報の読込
103        $arrForm = $this->lfGetRealFileName($customer_id, $order_id, $product_id, $product_class_id);
104        //ステータスが支払済み以上である事
105        if ($arrForm["status"] < ORDER_DELIV){
106            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
107        }
108        //ファイル情報が無い場合はNG
109        if ($arrForm["down_realfilename"] == "" ){
110            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
111        }
112        //ファイルそのものが無い場合もとりあえずNG
113        $realpath = DOWN_SAVE_REALDIR . $arrForm["down_realfilename"];
114        if (!file_exists($realpath)){
115            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
116        }
117        //ファイル名をエンコードする Safariの対策はUTF-8で様子を見る
118        $encoding = "Shift_JIS";
119        if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'Safari')) {
120            $encoding = "UTF-8";
121        }
122        $sdown_filename = mb_convert_encoding($arrForm["down_filename"], $encoding, "auto");
123
124        // flushなどを利用しているので、現行のSC_Displayは利用できません。
125        // SC_DisplayやSC_Responseに大容量ファイルレスポンスが実装されたら移行可能だと思います。
126
127        //タイプ指定
128        header("Content-Type: Application/octet-stream");
129        //ファイル名指定
130        header("Content-Disposition: attachment; filename=" . $sdown_filename);
131        header("Content-Transfer-Encoding: binary");
132        //キャッシュ無効化
133        header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
134        header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
135        //IE6+SSL環境下は、キャッシュ無しでダウンロードできない
136        header("Cache-Control: private");
137        header("Pragma: private");
138        //ファイルサイズ指定
139        $zv_filesize = filesize($realpath);
140        header("Content-Length: " . $zv_filesize);
141        set_time_limit(0);
142        ob_end_flush();
143        flush();
144        //ファイル読み込み
145        $handle = fopen($realpath, "rb");
146        while (!feof($handle)) {
147            echo(fread($handle, DOWNLOAD_BLOCK*1024));
148            ob_flush();
149            flush();
150        }
151        fclose($handle);
152    }
153
154    /**
155     * 商品情報の読み込みを行う.
156     *
157     * @param integer $customer_id 顧客ID
158     * @param integer $order_id 受注ID
159     * @param integer $product_id 商品ID
160     * @param integer $product_class_id 商品規格ID
161     * @return array 商品情報の配列
162     */
163    function lfGetRealFileName($customer_id, $order_id, $product_id, $product_class_id) {
164        $objQuery = new SC_Query();
165        $col = <<< __EOS__
166            pc.product_id AS product_id,
167            pc.product_class_id AS product_class_id,
168            pc.down_realfilename AS down_realfilename,
169            pc.down_filename AS down_filename,
170            o.order_id AS order_id,
171            o.customer_id AS customer_id,
172            o.payment_date AS payment_date,
173            o.status AS status
174__EOS__;
175
176        $table = <<< __EOS__
177            dtb_products_class pc,
178            dtb_order_detail od,
179            dtb_order o
180__EOS__;
181
182        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
183        $where = "o.customer_id = ? AND o.order_id = ? AND pc.product_id = ? AND pc.product_class_id = ?";
184        $where .= " AND " . $dbFactory->getDownloadableDaysWhereSql();
185        $where .= " = 1";
186        $arrRet = $objQuery->select($col, $table, $where,
187                                    array($customer_id, $order_id, $product_id, $product_class_id));
188        return $arrRet[0];
189    }
190
191
192    /* パラメータ情報の初期化 */
193    function lfInitParam() {
194        $this->objFormParam->addParam("customer_id", "customer_id", INT_LEN, "n", array("EXIST_CHECK","NUM_CHECK"));
195        $this->objFormParam->addParam("order_id", "order_id", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK"));
196        $this->objFormParam->addParam("product_id", "product_id", INT_LEN, "n", array("EXIST_CHECK","NUM_CHECK"));
197        $this->objFormParam->addParam("product_class_id", "product_class_id", INT_LEN, "n", array("EXIST_CHECK","NUM_CHECK"));
198    }
199
200    /* 入力内容のチェック */
201    function lfCheckError() {
202        // 入力データを渡す。
203        $arrRet = $this->objFormParam->getHashArray();
204        $objErr = new SC_CheckError($arrRet);
205        $objErr->arrErr = $this->objFormParam->checkError();
206        return $objErr->arrErr;
207    }
208
209    /**
210     * デストラクタ.
211     *
212     * @return void
213     */
214    function destroy() {
215        parent::destroy();
216    }
217}
218?>
Note: See TracBrowser for help on using the repository browser.