1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
6 | * |
---|
7 | * http://www.lockon.co.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 | |
---|
24 | // {{{ requires |
---|
25 | require_once 'LC_Page_Upgrade_Base.php'; |
---|
26 | |
---|
27 | /** |
---|
28 | * オーナーズストア購入商品一覧を返すページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Upgrade_ProductsList extends LC_Page_Upgrade_Base { |
---|
35 | |
---|
36 | // }}} |
---|
37 | // {{{ functions |
---|
38 | |
---|
39 | /** |
---|
40 | * Page を初期化する. |
---|
41 | * |
---|
42 | * @return void |
---|
43 | */ |
---|
44 | function init() { |
---|
45 | parent::init(); |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * Page のプロセス. |
---|
50 | * |
---|
51 | * @return void |
---|
52 | */ |
---|
53 | function process($mode) { |
---|
54 | $objLog = new LC_Upgrade_Helper_Log; |
---|
55 | $objJson = new LC_Upgrade_Helper_Json; |
---|
56 | |
---|
57 | $objLog->start($mode); |
---|
58 | |
---|
59 | // 管理画面ログインチェック |
---|
60 | $objLog->log('* admin auth start'); |
---|
61 | if ($this->isLoggedInAdminPage() !== true) { |
---|
62 | $objJson->setError(OSTORE_E_C_ADMIN_AUTH); |
---|
63 | $objJson->display(); |
---|
64 | $objLog->error(OSTORE_E_C_ADMIN_AUTH); |
---|
65 | return; |
---|
66 | } |
---|
67 | |
---|
68 | // 認証キーの取得 |
---|
69 | $public_key = $this->getPublicKey(); |
---|
70 | $sha1_key = $this->createSeed(); |
---|
71 | |
---|
72 | $objLog->log('* public key check start'); |
---|
73 | if (empty($public_key)) { |
---|
74 | $objJson->setError(OSTORE_E_C_NO_KEY); |
---|
75 | $objJson->display(); |
---|
76 | $objLog->error(OSTORE_E_C_NO_KEY); |
---|
77 | return; |
---|
78 | } |
---|
79 | |
---|
80 | // リクエストを開始 |
---|
81 | $objLog->log('* http request start'); |
---|
82 | $arrPostData = array( |
---|
83 | 'eccube_url' => HTTP_URL, |
---|
84 | 'public_key' => sha1($public_key . $sha1_key), |
---|
85 | 'sha1_key' => $sha1_key, |
---|
86 | 'ver' => ECCUBE_VERSION |
---|
87 | ); |
---|
88 | $objReq = $this->request('products_list', $arrPostData); |
---|
89 | |
---|
90 | // リクエストチェック |
---|
91 | $objLog->log('* http request check start'); |
---|
92 | if (PEAR::isError($objReq)) { |
---|
93 | $objJson->setError(OSTORE_E_C_HTTP_REQ); |
---|
94 | $objJson->display(); |
---|
95 | $objLog->error(OSTORE_E_C_HTTP_REQ, $objReq); |
---|
96 | return; |
---|
97 | } |
---|
98 | |
---|
99 | // レスポンスチェック |
---|
100 | $objLog->log('* http response check start'); |
---|
101 | if ($objReq->getResponseCode() !== 200) { |
---|
102 | $objJson->setError(OSTORE_E_C_HTTP_RESP); |
---|
103 | $objJson->display(); |
---|
104 | $objLog->error(OSTORE_E_C_HTTP_RESP, $objReq); |
---|
105 | return; |
---|
106 | } |
---|
107 | |
---|
108 | $body = $objReq->getResponseBody(); |
---|
109 | $objRet = $objJson->decode($body); |
---|
110 | |
---|
111 | // JSONデータのチェック |
---|
112 | $objLog->log('* json deta check start'); |
---|
113 | if (empty($objRet)) { |
---|
114 | $objJson->setError(OSTORE_E_C_FAILED_JSON_PARSE); |
---|
115 | $objJson->display(); |
---|
116 | $objLog->error(OSTORE_E_C_FAILED_JSON_PARSE, $objReq); |
---|
117 | return; |
---|
118 | } |
---|
119 | |
---|
120 | // ステータスチェック |
---|
121 | $objLog->log('* json status check start'); |
---|
122 | if ($objRet->status === OSTORE_STATUS_SUCCESS) { |
---|
123 | $objLog->log('* get products list ok'); |
---|
124 | |
---|
125 | $arrProducts = array(); |
---|
126 | |
---|
127 | foreach ($objRet->data as $product) { |
---|
128 | $arrProducts[] = get_object_vars($product); |
---|
129 | } |
---|
130 | $objView = new SC_AdminView_Ex(); |
---|
131 | $objView->assign('arrProducts', $arrProducts); |
---|
132 | |
---|
133 | $template = 'ownersstore/products_list.tpl'; |
---|
134 | |
---|
135 | if (!$objView->_smarty->template_exists($template)) { |
---|
136 | $objLog->log('* template not exist, use default template'); |
---|
137 | // デフォルトテンプレートを使用 |
---|
138 | $template = DATA_REALDIR . 'Smarty/templates/default/admin/' . $template; |
---|
139 | } |
---|
140 | |
---|
141 | $html = $objView->fetch('ownersstore/products_list.tpl'); |
---|
142 | $objJson->setSuccess(array(), $html); |
---|
143 | $objJson->display(); |
---|
144 | $objLog->end(); |
---|
145 | return; |
---|
146 | } else { |
---|
147 | // 配信サーバー側でエラーを補足 |
---|
148 | echo $body; |
---|
149 | $objLog->error($objRet->errcode, $objReq); |
---|
150 | return; |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | /** |
---|
155 | * デストラクタ. |
---|
156 | * |
---|
157 | * @return void |
---|
158 | */ |
---|
159 | function destroy() { |
---|
160 | parent::destroy(); |
---|
161 | } |
---|
162 | } |
---|