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

Revision 19807, 17.3 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある)

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