1 | <?php |
---|
2 | /* |
---|
3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
4 | * |
---|
5 | * http://www.lockon.co.jp/ |
---|
6 | */ |
---|
7 | |
---|
8 | // {{{ requires |
---|
9 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
---|
10 | |
---|
11 | /** |
---|
12 | * 商品管理 のページクラス. |
---|
13 | * |
---|
14 | * @package Page |
---|
15 | * @author LOCKON CO.,LTD. |
---|
16 | * @version $Id$ |
---|
17 | */ |
---|
18 | class LC_Page_Admin_Products extends LC_Page { |
---|
19 | |
---|
20 | // }}} |
---|
21 | // {{{ functions |
---|
22 | |
---|
23 | /** |
---|
24 | * Page を初期化する. |
---|
25 | * |
---|
26 | * @return void |
---|
27 | */ |
---|
28 | function init() { |
---|
29 | parent::init(); |
---|
30 | $this->tpl_mainpage = 'products/index.tpl'; |
---|
31 | $this->tpl_mainno = 'products'; |
---|
32 | $this->tpl_subnavi = 'products/subnavi.tpl'; |
---|
33 | $this->tpl_subno = 'index'; |
---|
34 | $this->tpl_pager = DATA_PATH . 'Smarty/templates/admin/pager.tpl'; |
---|
35 | $this->tpl_subtitle = '商品マスタ'; |
---|
36 | |
---|
37 | $masterData = new SC_DB_MasterData_Ex(); |
---|
38 | $this->arrPageMax = $masterData->getMasterData("mtb_page_max"); |
---|
39 | $this->arrDISP = $masterData->getMasterData("mtb_disp"); |
---|
40 | $this->arrSTATUS = $masterData->getMasterData("mtb_status"); |
---|
41 | $this->arrPRODUCTSTATUS_COLOR = $masterData->getMasterData("mtb_product_status_color"); |
---|
42 | |
---|
43 | $this->allowClientCache(); |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * Page のプロセス. |
---|
48 | * |
---|
49 | * @return void |
---|
50 | */ |
---|
51 | function process() { |
---|
52 | $objView = new SC_AdminView(); |
---|
53 | $objDb = new SC_Helper_DB_Ex(); |
---|
54 | $objDate = new SC_Date(); |
---|
55 | |
---|
56 | // 登録・更新検索開始年 |
---|
57 | $objDate->setStartYear(RELEASE_YEAR); |
---|
58 | $objDate->setEndYear(DATE("Y")); |
---|
59 | $this->arrStartYear = $objDate->getYear(); |
---|
60 | $this->arrStartMonth = $objDate->getMonth(); |
---|
61 | $this->arrStartDay = $objDate->getDay(); |
---|
62 | // 登録・更新検索終了年 |
---|
63 | $objDate->setStartYear(RELEASE_YEAR); |
---|
64 | $objDate->setEndYear(DATE("Y")); |
---|
65 | $this->arrEndYear = $objDate->getYear(); |
---|
66 | $this->arrEndMonth = $objDate->getMonth(); |
---|
67 | $this->arrEndDay = $objDate->getDay(); |
---|
68 | |
---|
69 | // 認証可否の判定 |
---|
70 | $objSess = new SC_Session(); |
---|
71 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
72 | |
---|
73 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
74 | |
---|
75 | //キャンペーンの編集時 |
---|
76 | if(isset($_POST['campaign_id']) && SC_Utils_Ex::sfIsInt($_POST['campaign_id']) |
---|
77 | && $_POST['mode'] == "camp_search") { |
---|
78 | $objQuery = new SC_Query(); |
---|
79 | $search_data = $objQuery->get("dtb_campaign", "search_condition", "campaign_id = ? ", array($_POST['campaign_id'])); |
---|
80 | $arrSearch = unserialize($search_data); |
---|
81 | foreach ($arrSearch as $key => $val) { |
---|
82 | $_POST[$key] = $val; |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | // POST値の引き継ぎ |
---|
87 | $this->arrForm = $_POST; |
---|
88 | |
---|
89 | // 検索ワードの引き継ぎ |
---|
90 | foreach ($_POST as $key => $val) { |
---|
91 | if (ereg("^search_", $key) || ereg("^campaign_", $key)) { |
---|
92 | switch($key) { |
---|
93 | case 'search_product_flag': |
---|
94 | case 'search_status': |
---|
95 | $this->arrHidden[$key] = SC_Utils_Ex::sfMergeParamCheckBoxes($val); |
---|
96 | if(!is_array($val)) { |
---|
97 | $this->arrForm[$key] = split("-", $val); |
---|
98 | } |
---|
99 | break; |
---|
100 | default: |
---|
101 | $this->arrHidden[$key] = $val; |
---|
102 | break; |
---|
103 | } |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | // ページ送り用 |
---|
108 | $this->arrHidden['search_pageno'] = isset($_POST['search_pageno']) ? $_POST['search_pageno'] : ""; |
---|
109 | |
---|
110 | // 商品削除 |
---|
111 | if ($_POST['mode'] == "delete") { |
---|
112 | |
---|
113 | if($_POST['category_id'] != "") { |
---|
114 | // ランク付きレコードの削除 |
---|
115 | $where = "category_id = " . addslashes($_POST['category_id']); |
---|
116 | $objDb->sfDeleteRankRecord("dtb_products", "product_id", $_POST['product_id'], $where); |
---|
117 | } else { |
---|
118 | $objDb->sfDeleteRankRecord("dtb_products", "product_id", $_POST['product_id']); |
---|
119 | } |
---|
120 | // 子テーブル(商品規格)の削除 |
---|
121 | $objQuery = new SC_Query(); |
---|
122 | $objQuery->delete("dtb_products_class", "product_id = ?", array($_POST['product_id'])); |
---|
123 | |
---|
124 | // 件数カウントバッチ実行 |
---|
125 | $objDb->sfCategory_Count($objQuery); |
---|
126 | } |
---|
127 | |
---|
128 | |
---|
129 | if ($_POST['mode'] == "search" || $_POST['mode'] == "csv" || $_POST['mode'] == "delete" || $_POST['mode'] == "delete_all" || $_POST['mode'] == "camp_search") { |
---|
130 | // 入力文字の強制変換 |
---|
131 | $this->lfConvertParam(); |
---|
132 | // エラーチェック |
---|
133 | $this->arrErr = $this->lfCheckError(); |
---|
134 | |
---|
135 | $where = "del_flg = 0"; |
---|
136 | $view_where = "del_flg = 0"; |
---|
137 | |
---|
138 | // 入力エラーなし |
---|
139 | if (count($this->arrErr) == 0) { |
---|
140 | |
---|
141 | $arrval = array(); |
---|
142 | foreach ($this->arrForm as $key => $val) { |
---|
143 | $val = SC_Utils_Ex::sfManualEscape($val); |
---|
144 | |
---|
145 | if($val == "") { |
---|
146 | continue; |
---|
147 | } |
---|
148 | |
---|
149 | switch ($key) { |
---|
150 | case 'search_product_id': // 商品ID |
---|
151 | $where .= " AND product_id = ?"; |
---|
152 | $view_where .= " AND product_id = ?"; |
---|
153 | $arrval[] = $val; |
---|
154 | break; |
---|
155 | case 'search_product_class_name': //規格名称 |
---|
156 | $where_in = " (SELECT classcategory_id FROM dtb_classcategory WHERE class_id IN (SELECT class_id FROM dtb_class WHERE name LIKE ?)) "; |
---|
157 | $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE classcategory_id1 IN " . $where_in; |
---|
158 | $where .= " OR classcategory_id2 IN" . $where_in . ")"; |
---|
159 | $view_where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE classcategory_id1 IN " . $where_in; |
---|
160 | $view_where .= " OR classcategory_id2 IN" . $where_in . ")"; |
---|
161 | $arrval[] = "%$val%"; |
---|
162 | $arrval[] = "%$val%"; |
---|
163 | $view_where = $where; |
---|
164 | break; |
---|
165 | case 'search_name': // 商品名 |
---|
166 | $where .= " AND name ILIKE ?"; |
---|
167 | $view_where .= " AND name ILIKE ?"; |
---|
168 | $arrval[] = "%$val%"; |
---|
169 | break; |
---|
170 | case 'search_category_id': // カテゴリー |
---|
171 | list($tmp_where, $tmp_arrval) = SC_Utils_Ex::sfGetCatWhere($val); |
---|
172 | if($tmp_where != "") { |
---|
173 | $where.= " AND $tmp_where"; |
---|
174 | $view_where.= " AND $tmp_where"; |
---|
175 | $arrval = array_merge((array)$arrval, (array)$tmp_arrval); |
---|
176 | } |
---|
177 | break; |
---|
178 | case 'search_product_code': // 商品コード |
---|
179 | $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code ILIKE ? GROUP BY product_id)"; |
---|
180 | $view_where .= " AND EXISTS (SELECT product_id FROM dtb_products_class as cls WHERE cls.product_code ILIKE ? AND dtb_products.product_id = cls.product_id GROUP BY cls.product_id )"; |
---|
181 | $arrval[] = "%$val%"; |
---|
182 | break; |
---|
183 | case 'search_startyear': // 登録更新日(FROM) |
---|
184 | $date = SC_Utils_Ex::sfGetTimestamp($_POST['search_startyear'], $_POST['search_startmonth'], $_POST['search_startday']); |
---|
185 | $where.= " AND update_date >= '" . $_POST['search_startyear'] . "/" . $_POST['search_startmonth']. "/" .$_POST['search_startday'] . "'"; |
---|
186 | $view_where.= " AND update_date >= '" . $_POST['search_startyear'] . "/" . $_POST['search_startmonth']. "/" .$_POST['search_startday'] . "'"; |
---|
187 | break; |
---|
188 | case 'search_endyear': // 登録更新日(TO) |
---|
189 | $date = SC_Utils_Ex::sfGetTimestamp($_POST['search_endyear'], $_POST['search_endmonth'], $_POST['search_endday']); |
---|
190 | $date = date('Y/m/d', strtotime($date) + 86400); |
---|
191 | $where.= " AND update_date < date('" . $date . "')"; |
---|
192 | $view_where.= " AND update_date < date('" . $date . "')"; |
---|
193 | break; |
---|
194 | case 'search_product_flag': //種別 |
---|
195 | global $arrSTATUS; |
---|
196 | $search_product_flag = SC_Utils_Ex::sfSearchCheckBoxes($val); |
---|
197 | if($search_product_flag != "") { |
---|
198 | $where.= " AND product_flag LIKE ?"; |
---|
199 | $view_where.= " AND product_flag LIKE ?"; |
---|
200 | $arrval[] = $search_product_flag; |
---|
201 | } |
---|
202 | break; |
---|
203 | case 'search_status': // ステータス |
---|
204 | $tmp_where = ""; |
---|
205 | foreach ($val as $element){ |
---|
206 | if ($element != ""){ |
---|
207 | if ($tmp_where == ""){ |
---|
208 | $tmp_where.="AND (status LIKE ? "; |
---|
209 | }else{ |
---|
210 | $tmp_where.="OR status LIKE ? "; |
---|
211 | } |
---|
212 | $arrval[]=$element; |
---|
213 | } |
---|
214 | } |
---|
215 | if ($tmp_where != ""){ |
---|
216 | $tmp_where.=")"; |
---|
217 | $where.= " $tmp_where"; |
---|
218 | $view_where.= " $tmp_where"; |
---|
219 | } |
---|
220 | break; |
---|
221 | default: |
---|
222 | break; |
---|
223 | } |
---|
224 | } |
---|
225 | |
---|
226 | $order = "update_date DESC, product_id DESC"; |
---|
227 | $objQuery = new SC_Query(); |
---|
228 | |
---|
229 | switch($_POST['mode']) { |
---|
230 | case 'csv': |
---|
231 | // オプションの指定 |
---|
232 | $option = "ORDER BY $order"; |
---|
233 | // CSV出力タイトル行の作成 |
---|
234 | $arrOutput = SC_Utils_Ex::sfSwapArray(sfgetCsvOutput(1, " WHERE csv_id = 1 AND status = 1")); |
---|
235 | |
---|
236 | if (count($arrOutput) <= 0) break; |
---|
237 | |
---|
238 | $arrOutputCols = $arrOutput['col']; |
---|
239 | $arrOutputTitle = $arrOutput['disp_name']; |
---|
240 | |
---|
241 | $head = SC_Utils_Ex::sfGetCSVList($arrOutputTitle); |
---|
242 | |
---|
243 | $data = $this->lfGetProductsCSV($where, $option, $arrval, $arrOutputCols); |
---|
244 | |
---|
245 | // CSVを送信する。 |
---|
246 | SC_Utils_Ex::sfCSVDownload($head.$data); |
---|
247 | exit; |
---|
248 | break; |
---|
249 | case 'delete_all': |
---|
250 | // 検索結果をすべて削除 |
---|
251 | $where = "product_id IN (SELECT product_id FROM vw_products_nonclass AS noncls WHERE $where)"; |
---|
252 | $sqlval['del_flg'] = 1; |
---|
253 | $objQuery->update("dtb_products", $sqlval, $where, $arrval); |
---|
254 | break; |
---|
255 | default: |
---|
256 | // 読み込む列とテーブルの指定 |
---|
257 | $col = "product_id, name, category_id, main_list_image, status, product_code, price01, price02, stock, stock_unlimited"; |
---|
258 | $from = "vw_products_nonclass AS noncls "; |
---|
259 | |
---|
260 | // 行数の取得 |
---|
261 | $linemax = $objQuery->count("dtb_products", $view_where, $arrval); |
---|
262 | $this->tpl_linemax = $linemax; // 何件が該当しました。表示用 |
---|
263 | |
---|
264 | // ページ送りの処理 |
---|
265 | if(is_numeric($_POST['search_page_max'])) { |
---|
266 | $page_max = $_POST['search_page_max']; |
---|
267 | } else { |
---|
268 | $page_max = SEARCH_PMAX; |
---|
269 | } |
---|
270 | |
---|
271 | // ページ送りの取得 |
---|
272 | $objNavi = new SC_PageNavi($this->arrHidden['search_pageno'], $linemax, $page_max, "fnNaviSearchPage", NAVI_PMAX); |
---|
273 | $startno = $objNavi->start_row; |
---|
274 | $this->arrPagenavi = $objNavi->arrPagenavi; |
---|
275 | |
---|
276 | //キャンペーン商品検索時は、全結果の商品IDを変数に格納する |
---|
277 | if(isset($_POST['search_mode']) && $_POST['search_mode'] == 'campaign') { |
---|
278 | $arrRet = $objQuery->select($col, $from, $where, $arrval); |
---|
279 | if(count($arrRet) > 0) { |
---|
280 | $arrRet = sfSwapArray($arrRet); |
---|
281 | $pid = implode("-", $arrRet['product_id']); |
---|
282 | $this->arrHidden['campaign_product_id'] = $pid; |
---|
283 | } |
---|
284 | } |
---|
285 | |
---|
286 | // 取得範囲の指定(開始行番号、行数のセット) |
---|
287 | if(DB_TYPE != "mysql") $objQuery->setlimitoffset($page_max, $startno); |
---|
288 | // 表示順序 |
---|
289 | $objQuery->setorder($order); |
---|
290 | // |
---|
291 | // // viewも絞込みをかける(mysql用) TODO |
---|
292 | // sfViewWhere("&&noncls_where&&", $view_where, $arrval, $objQuery->order . " " . $objQuery->setlimitoffset($page_max, $startno, true)); |
---|
293 | // |
---|
294 | // 検索結果の取得 |
---|
295 | $this->arrProducts = $objQuery->select($col, $from, $where, $arrval); |
---|
296 | |
---|
297 | break; |
---|
298 | } |
---|
299 | } |
---|
300 | } |
---|
301 | |
---|
302 | // カテゴリの読込 |
---|
303 | $this->arrCatList = $objDb->sfGetCategoryList(); |
---|
304 | $this->arrCatIDName = $this->lfGetIDName($this->arrCatList); |
---|
305 | |
---|
306 | // 画面の表示 |
---|
307 | $objView->assignobj($this); |
---|
308 | $objView->display(MAIN_FRAME); |
---|
309 | } |
---|
310 | |
---|
311 | /** |
---|
312 | * デストラクタ. |
---|
313 | * |
---|
314 | * @return void |
---|
315 | */ |
---|
316 | function destroy() { |
---|
317 | parent::destroy(); |
---|
318 | } |
---|
319 | |
---|
320 | // 取得文字列の変換 |
---|
321 | function lfConvertParam() { |
---|
322 | global $objPage; |
---|
323 | /* |
---|
324 | * 文字列の変換 |
---|
325 | * K : 「半角(ハンカク)片仮名」を「全角片仮名」に変換 |
---|
326 | * C : 「全角ひら仮名」を「全角かた仮名」に変換 |
---|
327 | * V : 濁点付きの文字を一文字に変換。"K","H"と共に使用します |
---|
328 | * n : 「全角」数字を「半角(ハンカク)」に変換 |
---|
329 | */ |
---|
330 | $arrConvList['search_name'] = "KVa"; |
---|
331 | $arrConvList['search_product_code'] = "KVa"; |
---|
332 | |
---|
333 | // 文字変換 |
---|
334 | foreach ($arrConvList as $key => $val) { |
---|
335 | // POSTされてきた値のみ変換する。 |
---|
336 | if(isset($objPage->arrForm[$key])) { |
---|
337 | $objPage->arrForm[$key] = mb_convert_kana($objPage->arrForm[$key] ,$val); |
---|
338 | } |
---|
339 | } |
---|
340 | } |
---|
341 | |
---|
342 | // エラーチェック |
---|
343 | // 入力エラーチェック |
---|
344 | function lfCheckError() { |
---|
345 | $objErr = new SC_CheckError(); |
---|
346 | $objErr->doFunc(array("商品ID", "search_product_id"), array("NUM_CHECK")); |
---|
347 | $objErr->doFunc(array("開始日", "search_startyear", "search_startmonth", "search_startday"), array("CHECK_DATE")); |
---|
348 | $objErr->doFunc(array("終了日", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_DATE")); |
---|
349 | $objErr->doFunc(array("開始日", "終了日", "search_startyear", "search_startmonth", "search_startday", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_SET_TERM")); |
---|
350 | return $objErr->arrErr; |
---|
351 | } |
---|
352 | |
---|
353 | // チェックボックス用WHERE文作成 |
---|
354 | function lfGetCBWhere($key, $max) { |
---|
355 | $str = ""; |
---|
356 | $find = false; |
---|
357 | for ($cnt = 1; $cnt <= $max; $cnt++) { |
---|
358 | if ($_POST[$key . $cnt] == "1") { |
---|
359 | $str.= "1"; |
---|
360 | $find = true; |
---|
361 | } else { |
---|
362 | $str.= "_"; |
---|
363 | } |
---|
364 | } |
---|
365 | if (!$find) { |
---|
366 | $str = ""; |
---|
367 | } |
---|
368 | return $str; |
---|
369 | } |
---|
370 | |
---|
371 | // カテゴリIDをキー、カテゴリ名を値にする配列を返す。 |
---|
372 | function lfGetIDName($arrCatList) { |
---|
373 | $max = count($arrCatList); |
---|
374 | for ($cnt = 0; $cnt < $max; $cnt++ ) { |
---|
375 | $key = isset($arrCatList[$cnt]['category_id']) ? $arrCatList[$cnt]['category_id'] : ""; |
---|
376 | $val = isset($arrCatList[$cnt]['category_name']) ? $arrCatList[$cnt]['category_name'] : ""; |
---|
377 | $arrRet[$key] = $val; |
---|
378 | } |
---|
379 | return $arrRet; |
---|
380 | } |
---|
381 | } |
---|
382 | ?> |
---|