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$ |
---|
32 | */ |
---|
33 | class 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 | if ($arrForm["status"] < ORDER_DELIV){ |
---|
108 | SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true); |
---|
109 | } |
---|
110 | //ファイル情報が無い場合はNG |
---|
111 | if ($arrForm["down_realfilename"] == "" ){ |
---|
112 | SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true); |
---|
113 | } |
---|
114 | //ファイルそのものが無い場合もとりあえずNG |
---|
115 | $realpath = DOWN_SAVE_REALDIR . $arrForm["down_realfilename"]; |
---|
116 | if (!file_exists($realpath)){ |
---|
117 | SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true); |
---|
118 | } |
---|
119 | //ファイル名をエンコードする Safariの対策はUTF-8で様子を見る |
---|
120 | $encoding = "Shift_JIS"; |
---|
121 | if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'Safari')) { |
---|
122 | $encoding = "UTF-8"; |
---|
123 | } |
---|
124 | $sdown_filename = mb_convert_encoding($arrForm["down_filename"], $encoding, "auto"); |
---|
125 | |
---|
126 | // flushなどを利用しているので、現行のSC_Displayは利用できません。 |
---|
127 | // SC_DisplayやSC_Responseに大容量ファイルレスポンスが実装されたら移行可能だと思います。 |
---|
128 | |
---|
129 | //タイプ指定 |
---|
130 | header("Content-Type: Application/octet-stream"); |
---|
131 | //ファイル名指定 |
---|
132 | header("Content-Disposition: attachment; filename=" . $sdown_filename); |
---|
133 | header("Content-Transfer-Encoding: binary"); |
---|
134 | //キャッシュ無効化 |
---|
135 | header("Expires: Mon, 26 Nov 1962 00:00:00 GMT"); |
---|
136 | header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT"); |
---|
137 | //IE6+SSL環境下は、キャッシュ無しでダウンロードできない |
---|
138 | header("Cache-Control: private"); |
---|
139 | header("Pragma: private"); |
---|
140 | //ファイルサイズ指定 |
---|
141 | $zv_filesize = filesize($realpath); |
---|
142 | header("Content-Length: " . $zv_filesize); |
---|
143 | set_time_limit(0); |
---|
144 | ob_end_flush(); |
---|
145 | flush(); |
---|
146 | //ファイル読み込み |
---|
147 | $handle = fopen($realpath, "rb"); |
---|
148 | while (!feof($handle)) { |
---|
149 | echo(fread($handle, DOWNLOAD_BLOCK*1024)); |
---|
150 | ob_flush(); |
---|
151 | flush(); |
---|
152 | } |
---|
153 | fclose($handle); |
---|
154 | } |
---|
155 | |
---|
156 | /** |
---|
157 | * 商品情報の読み込みを行う. |
---|
158 | * |
---|
159 | * @param integer $customer_id 顧客ID |
---|
160 | * @param integer $order_id 受注ID |
---|
161 | * @param integer $product_id 商品ID |
---|
162 | * @param integer $product_class_id 商品規格ID |
---|
163 | * @return array 商品情報の配列 |
---|
164 | */ |
---|
165 | function lfGetRealFileName($customer_id, $order_id, $product_id, $product_class_id) { |
---|
166 | $objQuery = new SC_Query_Ex(); |
---|
167 | $col = <<< __EOS__ |
---|
168 | pc.product_id AS product_id, |
---|
169 | pc.product_class_id AS product_class_id, |
---|
170 | pc.down_realfilename AS down_realfilename, |
---|
171 | pc.down_filename AS down_filename, |
---|
172 | o.order_id AS order_id, |
---|
173 | o.customer_id AS customer_id, |
---|
174 | o.payment_date AS payment_date, |
---|
175 | o.status AS status |
---|
176 | __EOS__; |
---|
177 | |
---|
178 | $table = <<< __EOS__ |
---|
179 | dtb_products_class pc, |
---|
180 | dtb_order_detail od, |
---|
181 | dtb_order o |
---|
182 | __EOS__; |
---|
183 | |
---|
184 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
---|
185 | $where = "o.customer_id = ? AND o.order_id = ? AND pc.product_id = ? AND pc.product_class_id = ?"; |
---|
186 | $where .= " AND " . $dbFactory->getDownloadableDaysWhereSql('o'); |
---|
187 | $where .= " = 1"; |
---|
188 | $arrRet = $objQuery->select($col, $table, $where, |
---|
189 | array($customer_id, $order_id, $product_id, $product_class_id)); |
---|
190 | return $arrRet[0]; |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | /* パラメータ情報の初期化 */ |
---|
195 | function lfInitParam(&$objFormParam) { |
---|
196 | $objFormParam->addParam("customer_id", "customer_id", INT_LEN, "n", array("EXIST_CHECK","NUM_CHECK")); |
---|
197 | $objFormParam->addParam("order_id", "order_id", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK")); |
---|
198 | $objFormParam->addParam("product_id", "product_id", INT_LEN, "n", array("EXIST_CHECK","NUM_CHECK")); |
---|
199 | $objFormParam->addParam("product_class_id", "product_class_id", INT_LEN, "n", array("EXIST_CHECK","NUM_CHECK")); |
---|
200 | } |
---|
201 | |
---|
202 | /* 入力内容のチェック */ |
---|
203 | function lfCheckError(&$objFormParam) { |
---|
204 | $objErr = new SC_CheckError_Ex($objFormParam->getHashArray()); |
---|
205 | $objErr->arrErr = $objFormParam->checkError(); |
---|
206 | return $objErr->arrErr; |
---|
207 | } |
---|
208 | |
---|
209 | /** |
---|
210 | * デストラクタ. |
---|
211 | * |
---|
212 | * @return void |
---|
213 | */ |
---|
214 | function destroy() { |
---|
215 | parent::destroy(); |
---|
216 | } |
---|
217 | } |
---|
218 | ?> |
---|