source: branches/camp/camp-2_5-C/data/class/pages/admin/products/LC_Page_Admin_Products.php @ 19226

Revision 19226, 18.6 KB checked in by kishik, 13 years ago (diff)

商品一覧での価格変更テスト

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