source: branches/comu-ver2/data/class/pages/admin/products/LC_Page_Admin_Products.php @ 17193

Revision 17193, 18.0 KB checked in by adachi, 16 years ago (diff)

merge r17159 version-2 branch r17159 - r17192

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