source: branches/version-2_5-dev/data/class/pages/admin/products/LC_Page_Admin_Products.php @ 18815

Revision 18815, 17.8 KB checked in by nanasess, 14 years ago (diff)

規格まわりの内部構成変更に伴う修正(#781)

  • 規格のデータ構造を木構造へ変更
  • 商品検索ロジックを SC_Product クラスへできるだけ集約
  • 以下の VIEW を削除
    • vw_category_count;
    • vw_product_class;
    • vw_products_nonclass;
    • vw_cross_products_class;
    • vw_cross_class;
    • vw_download_class;
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 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
25require_once(CLASS_PATH . "pages/LC_Page.php");
26
27/**
28 * 商品管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id:LC_Page_Admin_Products.php 15532 2007-08-31 14:39:46Z nanasess $
33 */
34class LC_Page_Admin_Products extends LC_Page {
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_subnavi = 'products/subnavi.tpl';
49        $this->tpl_subno = 'index';
50        $this->tpl_pager = TEMPLATE_DIR . 'admin/pager.tpl';
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
60    /**
61     * Page のプロセス.
62     *
63     * @return void
64     */
65    function process() {
66        $objView = new SC_AdminView();
67        $objDb = new SC_Helper_DB_Ex();
68        $objDate = new SC_Date();
69
70        // 登録・更新検索開始年
71        $objDate->setStartYear(RELEASE_YEAR);
72        $objDate->setEndYear(DATE("Y"));
73        $this->arrStartYear = $objDate->getYear();
74        $this->arrStartMonth = $objDate->getMonth();
75        $this->arrStartDay = $objDate->getDay();
76        // 登録・更新検索終了年
77        $objDate->setStartYear(RELEASE_YEAR);
78        $objDate->setEndYear(DATE("Y"));
79        $this->arrEndYear = $objDate->getYear();
80        $this->arrEndMonth = $objDate->getMonth();
81        $this->arrEndDay = $objDate->getDay();
82
83        // 認証可否の判定
84        $objSess = new SC_Session();
85        SC_Utils_Ex::sfIsSuccess($objSess);
86
87        if (!isset($_POST['mode'])) $_POST['mode'] = "";
88
89        //キャンペーンの編集時
90        if(isset($_POST['campaign_id']) && SC_Utils_Ex::sfIsInt($_POST['campaign_id'])
91                && $_POST['mode'] == "camp_search") {
92            $objQuery = new SC_Query();
93            $search_data = $objQuery->get("dtb_campaign", "search_condition", "campaign_id = ? ", array($_POST['campaign_id']));
94            $arrSearch = unserialize($search_data);
95            foreach ($arrSearch as $key => $val) {
96                $_POST[$key] = $val;
97            }
98        }
99
100        // POST値の引き継ぎ
101        $this->arrForm = $_POST;
102
103        // 検索ワードの引き継ぎ
104        foreach ($_POST as $key => $val) {
105            if (ereg("^search_", $key) || ereg("^campaign_", $key)) {
106                switch($key) {
107                    case 'search_product_flag':
108                    case 'search_status':
109                        $this->arrHidden[$key] = SC_Utils_Ex::sfMergeParamCheckBoxes($val);
110                        if(!is_array($val)) {
111                            $this->arrForm[$key] = split("-", $val);
112                        }
113                        break;
114                    default:
115                        $this->arrHidden[$key] = $val;
116                        break;
117                }
118            }
119        }
120
121        // ページ送り用
122        $this->arrHidden['search_pageno'] = isset($_POST['search_pageno']) ? $_POST['search_pageno'] : "";
123
124        // 商品削除
125        if ($_POST['mode'] == "delete") {
126
127            if($_POST['category_id'] != "") {
128                // ランク付きレコードの削除
129                $where = "category_id = " . SC_Utils_Ex::sfQuoteSmart($_POST['category_id']);
130                $objDb->sfDeleteRankRecord("dtb_products", "product_id", $_POST['product_id'], $where);
131            } else {
132                $objDb->sfDeleteRankRecord("dtb_products", "product_id", $_POST['product_id']);
133            }
134            // 子テーブル(商品規格)の削除
135            $objQuery = new SC_Query();
136            $objQuery->delete("dtb_products_class", "product_id = ?", array($_POST['product_id']));
137
138            // お気に入り商品削除
139            $objQuery->delete("dtb_customer_favorite_products", "product_id = ?", array($_POST['product_id']));
140
141            // 件数カウントバッチ実行
142            $objDb->sfCategory_Count($objQuery);
143            $objDb->sfMaker_Count($objQuery);
144        }
145
146
147        if ($_POST['mode'] == "search" || $_POST['mode'] == "csv"  || $_POST['mode'] == "delete" || $_POST['mode'] == "delete_all" || $_POST['mode'] == "camp_search") {
148            // 入力文字の強制変換
149            $this->lfConvertParam();
150            // エラーチェック
151            $this->arrErr = $this->lfCheckError();
152
153            $where = "del_flg = 0";
154            $view_where = "del_flg = 0";
155
156            // 入力エラーなし
157            if (count($this->arrErr) == 0) {
158
159                $arrval = array();
160                foreach ($this->arrForm as $key => $val) {
161
162                    if($val == "") {
163                        continue;
164                    }
165
166                    switch ($key) {
167                        case 'search_product_id': // 商品ID
168                            $where .= " AND product_id = ?";
169                            $view_where .= " AND product_id = ?";
170                            $arrval[] = $val;
171                            break;
172                        case 'search_product_class_name': //規格名称
173                            $where_in = " (SELECT classcategory_id FROM dtb_classcategory WHERE class_id IN (SELECT class_id FROM dtb_class WHERE name LIKE ?)) ";
174                            $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE classcategory_id1 IN " . $where_in;
175                            $where .= " OR classcategory_id2 IN" . $where_in . ")";
176                            $view_where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE classcategory_id1 IN " . $where_in;
177                            $view_where .= " OR classcategory_id2 IN" . $where_in . ")";
178                            $arrval[] = "%$val%";
179                            $arrval[] = "%$val%";
180                            $view_where = $where;
181                            break;
182                        case 'search_name': // 商品名
183                            $where .= " AND name ILIKE ?";
184                            $view_where .= " AND name ILIKE ?";
185                            $arrval[] = "%$val%";
186                            break;
187                        case 'search_category_id': // カテゴリー
188                            list($tmp_where, $tmp_arrval) = $objDb->sfGetCatWhere($val);
189                            if($tmp_where != "") {
190                                $where.= " AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")";
191                                $view_where.= " AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")";
192                                $arrval = array_merge((array)$arrval, (array)$tmp_arrval);
193                            }
194                            break;
195                        case 'search_product_code': // 商品コード
196                            $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code ILIKE ? GROUP BY product_id)";
197                            $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 )";
198                            $arrval[] = "%$val%";
199                            break;
200                        case 'search_startyear': // 登録更新日(FROM)
201                            // FIXME POST の値をチェックする
202                            $date = SC_Utils_Ex::sfGetTimestamp($_POST['search_startyear'], $_POST['search_startmonth'], $_POST['search_startday']);
203                            $where.= " AND update_date >= '" . $_POST['search_startyear'] . "/" . $_POST['search_startmonth']. "/" .$_POST['search_startday'] . "'";
204                            $view_where.= " AND update_date >= '" . $_POST['search_startyear'] . "/" . $_POST['search_startmonth']. "/" .$_POST['search_startday'] . "'";
205                            break;
206                        case 'search_endyear': // 登録更新日(TO)
207                            $date = SC_Utils_Ex::sfGetTimestamp($_POST['search_endyear'], $_POST['search_endmonth'], $_POST['search_endday']);
208                            $date = date('Y/m/d', strtotime($date) + 86400);
209                            $where.= " AND update_date < date('" . $date . "')";
210                            $view_where.= " AND update_date < date('" . $date . "')";
211                            break;
212                        case 'search_product_flag': //種別
213                            global $arrSTATUS;
214                            $search_product_flag = SC_Utils_Ex::sfSearchCheckBoxes($val);
215                            if($search_product_flag != "") {
216                                $where.= " AND product_flag LIKE ?";
217                                $view_where.= " AND product_flag LIKE ?";
218                                $arrval[] = $search_product_flag;
219                            }
220                            break;
221                        case 'search_status': // ステータス
222                            $tmp_where = "";
223                            foreach ($val as $element){
224                                if ($element != ""){
225                                    if ($tmp_where == ""){
226                                        $tmp_where.="AND (status = ? ";
227                                    }else{
228                                        $tmp_where.="OR status = ? ";
229                                    }
230                                    $arrval[]=$element;
231                                }
232                            }
233                            if ($tmp_where != ""){
234                                $tmp_where.=")";
235                                $where.= " $tmp_where";
236                                $view_where.= " $tmp_where";
237                            }
238                            break;
239                        default:
240                            break;
241                    }
242                }
243
244                $order = "update_date DESC, product_id DESC";
245                $objQuery = new SC_Query();
246                $objProduct = new SC_Product();
247                switch($_POST['mode']) {
248                    case 'csv':
249                        require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_CSV_Ex.php");
250
251                        $objCSV = new SC_Helper_CSV_Ex();
252
253                        // CSVを送信する。正常終了の場合、終了。
254                        $objCSV->sfDownloadProductsCsv($where, $arrval, $order) && exit;
255                        break;
256                    case 'delete_all':
257                        // 検索結果をすべて削除
258                        $where = "product_id IN (SELECT product_id FROM "
259                            . $objProduct->alldtlSQL() . " WHERE $where)";
260                        $sqlval['del_flg'] = 1;
261                        $objQuery->update("dtb_products", $sqlval, $where, $arrval);
262                        $objQuery->delete("dtb_customer_favorite_products", $where, $arrval);
263
264                        // 件数カウントバッチ実行
265                        $objDb->sfCategory_Count($objQuery);
266
267                        break;
268                    default:
269                        // 読み込む列とテーブルの指定
270                        $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";
271                        $from = $objProduct->alldtlSQL();
272
273                        // 行数の取得
274                        $linemax = $objQuery->count("dtb_products", $view_where, $arrval);
275                        $this->tpl_linemax = $linemax; // 何件が該当しました。表示用
276
277                        // ページ送りの処理
278                        if(is_numeric($_POST['search_page_max'])) {
279                            $page_max = $_POST['search_page_max'];
280                        } else {
281                            $page_max = SEARCH_PMAX;
282                        }
283
284                        // ページ送りの取得
285                        $objNavi = new SC_PageNavi($this->arrHidden['search_pageno'], $linemax, $page_max, "fnNaviSearchPage", NAVI_PMAX);
286                        $startno = $objNavi->start_row;
287                        $this->arrPagenavi = $objNavi->arrPagenavi;
288
289                        //キャンペーン商品検索時は、全結果の商品IDを変数に格納する
290                        if(isset($_POST['search_mode']) && $_POST['search_mode'] == 'campaign') {
291                            $arrRet = $objQuery->select($col, $from, $where, $arrval);
292                            if(count($arrRet) > 0) {
293                                $arrRet = sfSwapArray($arrRet);
294                                $pid = implode("-", $arrRet['product_id']);
295                                $this->arrHidden['campaign_product_id'] = $pid;
296                            }
297                        }
298
299                        // 取得範囲の指定(開始行番号、行数のセット)
300                        $objQuery->setLimitOffset($page_max, $startno);
301                        // 表示順序
302                        $objQuery->setOrder($order);
303
304                        // 検索結果の取得
305                        $this->arrProducts = $objQuery->select($col, $from, $where, $arrval);
306                       
307                        // 各商品ごとのカテゴリIDを取得
308                        if (count($this->arrProducts) > 0) {
309                            foreach ($this->arrProducts as $key => $val) {
310                                $this->arrProducts[$key]["categories"] = $objDb->sfGetCategoryId($val["product_id"], 0, true);
311                                $objDb->g_category_on = false;
312                            }
313                        }
314                }
315            }
316        }
317
318        // カテゴリの読込
319        list($this->arrCatKey, $this->arrCatVal) = $objDb->sfGetLevelCatList(false);
320        $this->arrCatList = $this->lfGetIDName($this->arrCatKey, $this->arrCatVal);
321
322        // 画面の表示
323        $objView->assignobj($this);
324        $objView->display(MAIN_FRAME);
325    }
326
327    /**
328     * デストラクタ.
329     *
330     * @return void
331     */
332    function destroy() {
333        parent::destroy();
334    }
335
336    // 取得文字列の変換
337    function lfConvertParam() {
338        global $objPage;
339        /*
340         *  文字列の変換
341         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
342         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
343         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
344         *  n :  「全角」数字を「半角(ハンカク)」に変換
345         */
346        $arrConvList['search_name'] = "KVa";
347        $arrConvList['search_product_code'] = "KVa";
348
349        // 文字変換
350        foreach ($arrConvList as $key => $val) {
351            // POSTされてきた値のみ変換する。
352            if(isset($objPage->arrForm[$key])) {
353                $objPage->arrForm[$key] = mb_convert_kana($objPage->arrForm[$key] ,$val);
354            }
355        }
356    }
357
358    // エラーチェック
359    // 入力エラーチェック
360    function lfCheckError() {
361        $objErr = new SC_CheckError();
362        $objErr->doFunc(array("商品ID", "search_product_id"), array("NUM_CHECK"));
363        $objErr->doFunc(array("開始日", "search_startyear", "search_startmonth", "search_startday"), array("CHECK_DATE"));
364        $objErr->doFunc(array("終了日", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_DATE"));
365        $objErr->doFunc(array("開始日", "終了日", "search_startyear", "search_startmonth", "search_startday", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_SET_TERM"));
366        return $objErr->arrErr;
367    }
368
369    // チェックボックス用WHERE文作成
370    function lfGetCBWhere($key, $max) {
371        $str = "";
372        $find = false;
373        for ($cnt = 1; $cnt <= $max; $cnt++) {
374            if ($_POST[$key . $cnt] == "1") {
375                $str.= "1";
376                $find = true;
377            } else {
378                $str.= "_";
379            }
380        }
381        if (!$find) {
382            $str = "";
383        }
384        return $str;
385    }
386
387    // カテゴリIDをキー、カテゴリ名を値にする配列を返す。
388    function lfGetIDName($arrCatKey, $arrCatVal) {
389        $max = count($arrCatKey);
390        for ($cnt = 0; $cnt < $max; $cnt++ ) {
391            $key = isset($arrCatKey[$cnt]) ? $arrCatKey[$cnt] : "";
392            $val = isset($arrCatVal[$cnt]) ? $arrCatVal[$cnt] : "";
393            $arrRet[$key] = $val;
394        }
395        return $arrRet;
396    }
397}
398?>
Note: See TracBrowser for help on using the repository browser.