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 CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
26 | |
---|
27 | /** |
---|
28 | * 商品管理 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_Products extends LC_Page_Admin_Ex { |
---|
35 | |
---|
36 | // }}} |
---|
37 | // {{{ functions |
---|
38 | |
---|
39 | /** |
---|
40 | * Page を初期化する. |
---|
41 | * |
---|
42 | * @return void |
---|
43 | */ |
---|
44 | function init() { |
---|
45 | parent::init(); |
---|
46 | $this->tpl_mainpage = 'products/index.tpl'; |
---|
47 | $this->tpl_mainno = 'products'; |
---|
48 | $this->tpl_subno = 'index'; |
---|
49 | $this->tpl_pager = 'pager.tpl'; |
---|
50 | $this->tpl_maintitle = '商品管理'; |
---|
51 | $this->tpl_subtitle = '商品マスター'; |
---|
52 | |
---|
53 | $masterData = new SC_DB_MasterData_Ex(); |
---|
54 | $this->arrPageMax = $masterData->getMasterData('mtb_page_max'); |
---|
55 | $this->arrDISP = $masterData->getMasterData('mtb_disp'); |
---|
56 | $this->arrSTATUS = $masterData->getMasterData('mtb_status'); |
---|
57 | $this->arrPRODUCTSTATUS_COLOR = $masterData->getMasterData('mtb_product_status_color'); |
---|
58 | |
---|
59 | $objDate = new SC_Date(); |
---|
60 | // 登録・更新検索開始年 |
---|
61 | $objDate->setStartYear(RELEASE_YEAR); |
---|
62 | $objDate->setEndYear(DATE('Y')); |
---|
63 | $this->arrStartYear = $objDate->getYear(); |
---|
64 | $this->arrStartMonth = $objDate->getMonth(); |
---|
65 | $this->arrStartDay = $objDate->getDay(); |
---|
66 | // 登録・更新検索終了年 |
---|
67 | $objDate->setStartYear(RELEASE_YEAR); |
---|
68 | $objDate->setEndYear(DATE('Y')); |
---|
69 | $this->arrEndYear = $objDate->getYear(); |
---|
70 | $this->arrEndMonth = $objDate->getMonth(); |
---|
71 | $this->arrEndDay = $objDate->getDay(); |
---|
72 | |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | * Page のプロセス. |
---|
77 | * |
---|
78 | * @return void |
---|
79 | */ |
---|
80 | function process() { |
---|
81 | $this->action(); |
---|
82 | $this->sendResponse(); |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | * Page のアクション. |
---|
87 | * |
---|
88 | * @return void |
---|
89 | */ |
---|
90 | function action() { |
---|
91 | |
---|
92 | $objDb = new SC_Helper_DB_Ex(); |
---|
93 | $objFormParam = new SC_FormParam_Ex(); |
---|
94 | $objProduct = new SC_Product_Ex(); |
---|
95 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
96 | |
---|
97 | // パラメーター情報の初期化 |
---|
98 | $this->lfInitParam($objFormParam); |
---|
99 | $objFormParam->setParam($_POST); |
---|
100 | $this->arrHidden = $objFormParam->getSearchArray(); |
---|
101 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
102 | |
---|
103 | switch ($this->getMode()) { |
---|
104 | case 'delete': |
---|
105 | // 商品、子テーブル(商品規格)、会員お気に入り商品の削除 |
---|
106 | $this->doDelete('product_id = ?', array($objFormParam->getValue('product_id'))); |
---|
107 | // 件数カウントバッチ実行 |
---|
108 | $objDb->sfCountCategory($objQuery); |
---|
109 | $objDb->sfCountMaker($objQuery); |
---|
110 | // 削除後に検索結果を表示するため breakしない |
---|
111 | |
---|
112 | // 検索パラメーター生成後に処理実行するため breakしない |
---|
113 | case 'csv': |
---|
114 | case 'delete_all': |
---|
115 | |
---|
116 | case 'search': |
---|
117 | $objFormParam->convParam(); |
---|
118 | $objFormParam->trimParam(); |
---|
119 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
120 | $arrParam = $objFormParam->getHashArray(); |
---|
121 | |
---|
122 | if (count($this->arrErr) == 0) { |
---|
123 | $where = 'del_flg = 0'; |
---|
124 | $arrWhereVal = array(); |
---|
125 | foreach ($arrParam as $key => $val) { |
---|
126 | if ($val == '') { |
---|
127 | continue; |
---|
128 | } |
---|
129 | $this->buildQuery($key, $where, $arrWhereVal, $objFormParam, $objDb); |
---|
130 | } |
---|
131 | |
---|
132 | $order = 'update_date DESC'; |
---|
133 | |
---|
134 | /* ----------------------------------------------- |
---|
135 | * 処理を実行 |
---|
136 | * ----------------------------------------------- */ |
---|
137 | switch ($this->getMode()) { |
---|
138 | // CSVを送信する。 |
---|
139 | case 'csv': |
---|
140 | $objCSV = new SC_Helper_CSV_Ex(); |
---|
141 | // CSVを送信する。正常終了の場合、終了。 |
---|
142 | $objCSV->sfDownloadCsv(1, $where, $arrWhereVal, $order, true); |
---|
143 | SC_Response_Ex::actionExit(); |
---|
144 | |
---|
145 | // 全件削除(ADMIN_MODE) |
---|
146 | case 'delete_all': |
---|
147 | $this->doDelete($where, $arrWhereVal); |
---|
148 | break; |
---|
149 | |
---|
150 | // 検索実行 |
---|
151 | default: |
---|
152 | // 行数の取得 |
---|
153 | $this->tpl_linemax = $this->getNumberOfLines($where, $arrWhereVal); |
---|
154 | // ページ送りの処理 |
---|
155 | $page_max = SC_Utils_Ex::sfGetSearchPageMax($objFormParam->getValue('search_page_max')); |
---|
156 | // ページ送りの取得 |
---|
157 | $objNavi = new SC_PageNavi_Ex($this->arrHidden['search_pageno'], |
---|
158 | $this->tpl_linemax, $page_max, |
---|
159 | 'fnNaviSearchPage', NAVI_PMAX); |
---|
160 | $this->arrPagenavi = $objNavi->arrPagenavi; |
---|
161 | |
---|
162 | // 検索結果の取得 |
---|
163 | $this->arrProducts = $this->findProducts($where, $arrWhereVal, $page_max, $objNavi->start_row, |
---|
164 | $order, $objProduct); |
---|
165 | |
---|
166 | // 各商品ごとのカテゴリIDを取得 |
---|
167 | if (count($this->arrProducts) > 0) { |
---|
168 | foreach ($this->arrProducts as $key => $val) { |
---|
169 | $this->arrProducts[$key]['categories'] = $objDb->sfGetCategoryId($val['product_id'], 0, true); |
---|
170 | $objDb->g_category_on = false; |
---|
171 | } |
---|
172 | } |
---|
173 | } |
---|
174 | } |
---|
175 | break; |
---|
176 | } |
---|
177 | |
---|
178 | // カテゴリの読込 |
---|
179 | list($this->arrCatKey, $this->arrCatVal) = $objDb->sfGetLevelCatList(false); |
---|
180 | $this->arrCatList = $this->lfGetIDName($this->arrCatKey, $this->arrCatVal); |
---|
181 | |
---|
182 | } |
---|
183 | |
---|
184 | /** |
---|
185 | * デストラクタ. |
---|
186 | * |
---|
187 | * @return void |
---|
188 | */ |
---|
189 | function destroy() { |
---|
190 | parent::destroy(); |
---|
191 | } |
---|
192 | |
---|
193 | /** |
---|
194 | * パラメーター情報の初期化を行う. |
---|
195 | * |
---|
196 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
197 | * @return void |
---|
198 | */ |
---|
199 | function lfInitParam(&$objFormParam) { |
---|
200 | |
---|
201 | // POSTされる値 |
---|
202 | $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
203 | $objFormParam->addParam('カテゴリID', 'category_id', STEXT_LEN, 'n', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
204 | $objFormParam->addParam('ページ送り番号','search_pageno', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
205 | $objFormParam->addParam('表示件数', 'search_page_max', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
206 | |
---|
207 | // 検索条件 |
---|
208 | $objFormParam->addParam('商品ID', 'search_product_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
209 | $objFormParam->addParam('商品コード', 'search_product_code', STEXT_LEN, 'KVna', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
210 | $objFormParam->addParam('商品名', 'search_name', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
211 | $objFormParam->addParam('カテゴリ', 'search_category_id', STEXT_LEN, 'n', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
212 | $objFormParam->addParam('種別', 'search_status', INT_LEN, 'n', array('MAX_LENGTH_CHECK')); |
---|
213 | // 登録・更新日 |
---|
214 | $objFormParam->addParam('開始年', 'search_startyear', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
215 | $objFormParam->addParam('開始月', 'search_startmonth', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
216 | $objFormParam->addParam('開始日', 'search_startday', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
217 | $objFormParam->addParam('終了年', 'search_endyear', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
218 | $objFormParam->addParam('終了月', 'search_endmonth', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
219 | $objFormParam->addParam('終了日', 'search_endday', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
220 | |
---|
221 | $objFormParam->addParam('商品ステータス', 'search_product_statuses', INT_LEN, 'n', array('MAX_LENGTH_CHECK')); |
---|
222 | } |
---|
223 | |
---|
224 | /** |
---|
225 | * 入力内容のチェックを行う. |
---|
226 | * |
---|
227 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
228 | * @return void |
---|
229 | */ |
---|
230 | function lfCheckError(&$objFormParam) { |
---|
231 | $objErr = new SC_CheckError_Ex($objFormParam->getHashArray()); |
---|
232 | $objErr->arrErr = $objFormParam->checkError(); |
---|
233 | |
---|
234 | $objErr->doFunc(array('開始日', '終了日', 'search_startyear', 'search_startmonth', 'search_startday', 'search_endyear', 'search_endmonth', 'search_endday'), array('CHECK_SET_TERM')); |
---|
235 | |
---|
236 | return $objErr->arrErr; |
---|
237 | } |
---|
238 | |
---|
239 | // カテゴリIDをキー、カテゴリ名を値にする配列を返す。 |
---|
240 | function lfGetIDName($arrCatKey, $arrCatVal) { |
---|
241 | $max = count($arrCatKey); |
---|
242 | for ($cnt = 0; $cnt < $max; $cnt++) { |
---|
243 | $key = isset($arrCatKey[$cnt]) ? $arrCatKey[$cnt] : ''; |
---|
244 | $val = isset($arrCatVal[$cnt]) ? $arrCatVal[$cnt] : ''; |
---|
245 | $arrRet[$key] = $val; |
---|
246 | } |
---|
247 | return $arrRet; |
---|
248 | } |
---|
249 | |
---|
250 | /** |
---|
251 | * 商品、子テーブル(商品規格)、お気に入り商品の削除 |
---|
252 | * |
---|
253 | * @param string $where 削除対象の WHERE 句 |
---|
254 | * @param array $arrParam 削除対象の値 |
---|
255 | * @return void |
---|
256 | */ |
---|
257 | function doDelete($where, $arrParam = array()) { |
---|
258 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
259 | $sqlval['del_flg'] = 1; |
---|
260 | $sqlval['update_date'] = 'CURRENT_TIMESTAMP'; |
---|
261 | $objQuery->begin(); |
---|
262 | $objQuery->update('dtb_products_class', $sqlval, "product_id IN (SELECT product_id FROM dtb_products WHERE $where)", $arrParam); |
---|
263 | $objQuery->delete('dtb_customer_favorite_products', "product_id IN (SELECT product_id FROM dtb_products WHERE $where)", $arrParam); |
---|
264 | $objQuery->delete('dtb_best_products', "product_id IN (SELECT product_id FROM dtb_products WHERE $where)", $arrParam); |
---|
265 | $objQuery->update('dtb_products', $sqlval, $where, $arrParam); |
---|
266 | $objQuery->commit(); |
---|
267 | } |
---|
268 | |
---|
269 | /** |
---|
270 | * クエリを構築する. |
---|
271 | * |
---|
272 | * 検索条件のキーに応じた WHERE 句と, クエリパラメーターを構築する. |
---|
273 | * クエリパラメーターは, SC_FormParam の入力値から取得する. |
---|
274 | * |
---|
275 | * 構築内容は, 引数の $where 及び $arrValues にそれぞれ追加される. |
---|
276 | * |
---|
277 | * @param string $key 検索条件のキー |
---|
278 | * @param string $where 構築する WHERE 句 |
---|
279 | * @param array $arrValues 構築するクエリパラメーター |
---|
280 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
281 | * @param SC_FormParam $objDb SC_Helper_DB_Ex インスタンス |
---|
282 | * @return void |
---|
283 | */ |
---|
284 | function buildQuery($key, &$where, &$arrValues, &$objFormParam, &$objDb) { |
---|
285 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
---|
286 | switch ($key) { |
---|
287 | // 商品ID |
---|
288 | case 'search_product_id': |
---|
289 | $where .= ' AND product_id = ?'; |
---|
290 | $arrValues[] = sprintf('%d', $objFormParam->getValue($key)); |
---|
291 | break; |
---|
292 | // 商品コード |
---|
293 | case 'search_product_code': |
---|
294 | $where .= ' AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code ILIKE ?)'; |
---|
295 | $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key)); |
---|
296 | break; |
---|
297 | // 商品名 |
---|
298 | case 'search_name': |
---|
299 | $where .= ' AND name LIKE ?'; |
---|
300 | $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key)); |
---|
301 | break; |
---|
302 | // カテゴリ |
---|
303 | case 'search_category_id': |
---|
304 | list($tmp_where, $tmp_Values) = $objDb->sfGetCatWhere($objFormParam->getValue($key)); |
---|
305 | if ($tmp_where != '') { |
---|
306 | $where.= ' AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')'; |
---|
307 | $arrValues = array_merge((array)$arrValues, (array)$tmp_Values); |
---|
308 | } |
---|
309 | break; |
---|
310 | // 種別 |
---|
311 | case 'search_status': |
---|
312 | $tmp_where = ''; |
---|
313 | foreach ($objFormParam->getValue($key) as $element) { |
---|
314 | if ($element != '') { |
---|
315 | if (SC_Utils_Ex::isBlank($tmp_where)) { |
---|
316 | $tmp_where .= ' AND (status = ?'; |
---|
317 | } else { |
---|
318 | $tmp_where .= ' OR status = ?'; |
---|
319 | } |
---|
320 | $arrValues[] = $element; |
---|
321 | } |
---|
322 | } |
---|
323 | |
---|
324 | if (!SC_Utils_Ex::isBlank($tmp_where)) { |
---|
325 | $tmp_where .= ')'; |
---|
326 | $where .= " $tmp_where "; |
---|
327 | } |
---|
328 | break; |
---|
329 | // 登録・更新日(開始) |
---|
330 | case 'search_startyear': |
---|
331 | $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_startyear'), |
---|
332 | $objFormParam->getValue('search_startmonth'), |
---|
333 | $objFormParam->getValue('search_startday')); |
---|
334 | $where.= ' AND update_date >= ?'; |
---|
335 | $arrValues[] = $date; |
---|
336 | break; |
---|
337 | // 登録・更新日(終了) |
---|
338 | case 'search_endyear': |
---|
339 | $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_endyear'), |
---|
340 | $objFormParam->getValue('search_endmonth'), |
---|
341 | $objFormParam->getValue('search_endday'), true); |
---|
342 | $where.= ' AND update_date <= ?'; |
---|
343 | $arrValues[] = $date; |
---|
344 | break; |
---|
345 | // 商品ステータス |
---|
346 | case 'search_product_statuses': |
---|
347 | $arrPartVal = $objFormParam->getValue($key); |
---|
348 | $count = count($arrPartVal); |
---|
349 | if ($count >= 1) { |
---|
350 | $where .= ' ' |
---|
351 | . 'AND product_id IN (' |
---|
352 | . ' SELECT product_id FROM dtb_product_status WHERE product_status_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', $count) . ')' |
---|
353 | . ')'; |
---|
354 | $arrValues = array_merge($arrValues, $arrPartVal); |
---|
355 | } |
---|
356 | break; |
---|
357 | default: |
---|
358 | break; |
---|
359 | } |
---|
360 | } |
---|
361 | |
---|
362 | /** |
---|
363 | * 検索結果の行数を取得する. |
---|
364 | * |
---|
365 | * @param string $where 検索条件の WHERE 句 |
---|
366 | * @param array $arrValues 検索条件のパラメーター |
---|
367 | * @return integer 検索結果の行数 |
---|
368 | */ |
---|
369 | function getNumberOfLines($where, $arrValues) { |
---|
370 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
371 | return $objQuery->count('dtb_products', $where, $arrValues); |
---|
372 | } |
---|
373 | |
---|
374 | /** |
---|
375 | * 商品を検索する. |
---|
376 | * |
---|
377 | * @param string $where 検索条件の WHERE 句 |
---|
378 | * @param array $arrValues 検索条件のパラメーター |
---|
379 | * @param integer $limit 表示件数 |
---|
380 | * @param integer $offset 開始件数 |
---|
381 | * @param string $order 検索結果の並び順 |
---|
382 | * @param SC_Product $objProduct SC_Product インスタンス |
---|
383 | * @return array 商品の検索結果 |
---|
384 | */ |
---|
385 | function findProducts($where, $arrValues, $limit, $offset, $order, &$objProduct) { |
---|
386 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
387 | |
---|
388 | // 読み込む列とテーブルの指定 |
---|
389 | $col = 'product_id, name, main_list_image, status, product_code_min, product_code_max, price02_min, price02_max, stock_min, stock_max, stock_unlimited_min, stock_unlimited_max, update_date'; |
---|
390 | $from = $objProduct->alldtlSQL(); |
---|
391 | |
---|
392 | $objQuery->setLimitOffset($limit, $offset); |
---|
393 | $objQuery->setOrder($order); |
---|
394 | |
---|
395 | return $objQuery->select($col, $from, $where, $arrValues); |
---|
396 | } |
---|
397 | } |
---|