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

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