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