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

Revision 19911, 5.8 KB checked in by eccuore, 13 years ago (diff)

#792(ダウンロード販売機能) 現在エラーが発生するため、暫定的に修正

RevLine 
[18777]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
[19805]24require_once(CLASS_REALDIR . "pages/LC_Page.php");
[18777]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    // }}}
36    // {{{ functions
37
38    /**
39     * Page を初期化する.
40     *
41     * @return void
42     */
43    function init() {
44        parent::init();
45        $this->allowClientCache();
46    }
47
48    /**
49     * Page のプロセス.
50     *
51     * @return void
52     */
53    function process() {
[19911]54        ob_end_clean();
[19661]55
[18793]56        $customer_id = $_SESSION['customer']['customer_id'];
57        $order_id = $_GET['order_id'];
58        $product_id = $_GET['product_id'];
[18824]59        $product_class_id = $_GET['product_class_id'];
[18793]60
61        // ID の数値チェック
62        // TODO SC_FormParam でチェックした方が良い?
63        if (!is_numeric($customer_id)
64            || !is_numeric($order_id)
[18819]65            || !is_numeric($product_id)
[18824]66            || !is_numeric($product_class_id)) {
[18793]67            SC_Utils_Ex::sfDispSiteError("");
68        }
69
[18777]70        $objCustomer = new SC_Customer();
[19661]71        //ログインしていない場合エラー
[18777]72        if (!$objCustomer->isLoginSuccess()){
73            SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
[19661]74        }
75
76        //DBから商品情報の読込
77        $arrForm = $this->lfGetRealFileName($customer_id, $order_id, $product_id, $product_class_id);
78        //ステータスが支払済み以上である事
79        if ($arrForm["status"] < ORDER_DELIV){
80            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
81        }
82        //ファイル情報が無い場合はNG
83        if ($arrForm["down_realfilename"] == "" ){
84            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
85        }
86        //ファイルそのものが無い場合もとりあえずNG
[19805]87        $realpath = DOWN_SAVE_REALDIR . $arrForm["down_realfilename"];
[19661]88        if (!file_exists($realpath)){
89            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
90        }
91        //ファイル名をエンコードする Safariの対策はUTF-8で様子を見る
92        $encoding = "Shift_JIS";
93        if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'Safari')) {
94            $encoding = "UTF-8";
95        }
96        $sdown_filename = mb_convert_encoding($arrForm["down_filename"], $encoding, "auto");
97
98        //TODO SC_Display利用に変更
99        //タイプ指定
100        header("Content-Type: Application/octet-stream");
101        //ファイル名指定
102        header("Content-Disposition: attachment; filename=" . $sdown_filename);
103        header("Content-Transfer-Encoding: binary");
104        //キャッシュ無効化
105        header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
106        header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
107        //IE6+SSL環境下は、キャッシュ無しでダウンロードできない
108        header("Cache-Control: private");
109        header("Pragma: private");
110        //ファイルサイズ指定
111        $zv_filesize = filesize($realpath);
112        header("Content-Length: " . $zv_filesize);
113        set_time_limit(0);
114        ob_end_flush();
115        flush();
116        //ファイル読み込み
117        $handle = fopen($realpath, "rb");
118        while (!feof($handle)) {
119            echo(fread($handle, DOWNLOAD_BLOCK*1024));
120            ob_flush();
[18777]121            flush();
122        }
[19661]123        fclose($handle);
[18777]124    }
125
[18793]126    /**
127     * 商品情報の読み込みを行う.
128     *
129     * @param integer $customer_id 顧客ID
130     * @param integer $order_id 受注ID
131     * @param integer $product_id 商品ID
[18824]132     * @param integer $product_class_id 商品規格ID
[18793]133     * @return array 商品情報の配列
134     */
[18824]135    function lfGetRealFileName($customer_id, $order_id, $product_id, $product_class_id) {
[18777]136        $objQuery = new SC_Query();
[18824]137        $col = <<< __EOS__
138            pc.product_id AS product_id,
139            pc.product_class_id AS product_class_id,
140            pc.down_realfilename AS down_realfilename,
141            pc.down_filename AS down_filename,
142            o.order_id AS order_id,
143            o.customer_id AS customer_id,
144            o.payment_date AS payment_date,
145            o.status AS status
146__EOS__;
147
148        $table = <<< __EOS__
149            dtb_products_class pc,
150            dtb_order_detail od,
151            dtb_order o
152__EOS__;
153
[18793]154        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
[18824]155        $where = "o.customer_id = ? AND o.order_id = ? AND pc.product_id = ? AND pc.product_class_id = ?";
156        $where .= " AND " . $dbFactory->getDownloadableDaysWhereSql();
[18793]157        $where .= " = 1";
158        $arrRet = $objQuery->select($col, $table, $where,
[18824]159                                    array($customer_id, $order_id, $product_id, $product_class_id));
[18777]160        return $arrRet[0];
161    }
162
163    /**
164     * デストラクタ.
165     *
166     * @return void
167     */
168    function destroy() {
169        parent::destroy();
170    }
171}
172?>
Note: See TracBrowser for help on using the repository browser.