source: branches/comu-ver2/data/class/pages/admin/products/LC_Page_Admin_Products_ProductClass.php @ 18234

Revision 18234, 18.6 KB checked in by Seasoft, 15 years ago (diff)

#528(改行コードが混在している)

  • SVN属性の変更。ただし、以下は除外。
    • /data/module
    • /data/pdf
    • /html/test
  • 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$
33 */
34class LC_Page_Admin_Products_ProductClass 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/product_class.tpl';
47        $this->tpl_subnavi = 'products/subnavi.tpl';
48        $this->tpl_mainno = 'products';
49        $this->tpl_subno = 'product';
50        $this->tpl_subtitle = '商品登録(商品規格)';
51
52        $masterData = new SC_DB_MasterData_Ex();
53        $this->arrSRANK = $masterData->getMasterData("mtb_srank");
54        $this->arrDISP = $masterData->getMasterData("mtb_disp");
55        $this->arrCLASS = $masterData->getMasterData("mtb_class");
56        $this->arrSTATUS = $masterData->getMasterData("mtb_status");
57        $this->tpl_onload = "";
58    }
59
60    /**
61     * Page のプロセス.
62     *
63     * @return void
64     */
65    function process() {
66        $objView = new SC_AdminView();
67        // 認証可否の判定
68        $objSess = new SC_Session();
69        SC_Utils_Ex::sfIsSuccess($objSess);
70
71        // 検索パラメータの引き継ぎ
72        foreach ($_POST as $key => $val) {
73            if (ereg("^search_", $key)) {
74                $this->arrSearchHidden[$key] = $val;
75            }
76        }
77
78        $this->tpl_product_id =
79            isset($_POST['product_id']) ? $_POST['product_id'] : "" ;
80
81        $this->tpl_pageno = isset($_POST['pageno']) ? $_POST['pageno'] : "";
82
83        if (!isset($_POST['mode'])) $_POST['mode'] = "";
84
85        switch($_POST['mode']) {
86        // 規格削除要求
87        case 'delete':
88            $objQuery = new SC_Query();
89            $objDb = new SC_Helper_DB_Ex();
90
91            $objQuery->setLimitOffset(1);
92            $where = "product_id = ? AND NOT (classcategory_id1 = 0 AND classcategory_id2 = 0)";
93            $objQuery->setOrder("rank1 DESC, rank2 DESC");
94            $arrRet = $objQuery->select("*", "vw_cross_products_class AS crs_prd", $where, array($_POST['product_id']));
95
96            if(count($arrRet) > 0) {
97
98                $sqlval['product_id'] = $arrRet[0]['product_id'];
99                $sqlval['classcategory_id1'] = '0';
100                $sqlval['classcategory_id2'] = '0';
101                $sqlval['product_code'] = $arrRet[0]['product_code'];
102                $sqlval['stock'] = $arrRet[0]['stock'];
103                $sqlval['price01'] = $arrRet[0]['price01'];
104                $sqlval['price02'] = $arrRet[0]['price02'];
105                $sqlval['creator_id'] = $_SESSION['member_id'];
106                $sqlval['create_date'] = "now()";
107                $sqlval['update_date'] = "now()";
108
109                $objQuery->begin();
110                $where = "product_id = ?";
111                $objQuery->delete("dtb_products_class", $where, array($_POST['product_id']));
112                $objQuery->insert("dtb_products_class", $sqlval);
113
114                $objQuery->commit();
115            }
116           
117            // 在庫無し商品の非表示対応
118            if (NOSTOCK_HIDDEN === true) {
119                // 件数カウントバッチ実行
120                $objDb->sfCategory_Count($objQuery);
121            }
122           
123            $this->lfProductClassPage();   // 規格登録ページ
124            break;
125
126        // 編集要求
127        case 'pre_edit':
128            $objQuery = new SC_Query();
129            $where = "product_id = ? AND NOT(classcategory_id1 = 0 AND classcategory_id2 = 0) ";
130            $ret = $objQuery->count("dtb_products_class", $where, array($_POST['product_id']));
131
132            if($ret > 0) {
133                // 規格組み合わせ一覧の取得(DBの値を優先する。)
134                $this->arrClassCat = $this->lfGetClassCatListEdit($_POST['product_id']);
135            }
136            $this->lfProductClassPage();   // 規格登録ページ
137            break;
138           
139        // 規格組み合わせ表示
140        case 'disp':
141            $this->arrForm['select_class_id1'] = $_POST['select_class_id1'];
142            $this->arrForm['select_class_id2'] = $_POST['select_class_id2'];
143
144            $this->arrErr = $this->lfClassError();
145            if (count($this->arrErr) == 0) {
146                // 規格組み合わせ一覧の取得
147                $this->arrClassCat = $this->lfGetClassCatListDisp($_POST['select_class_id1'], $_POST['select_class_id2']);
148            }
149            $this->lfProductClassPage();   // 規格登録ページ
150            break;
151           
152        // 規格登録要求
153        case 'edit':
154            // 入力値の変換
155            $this->arrForm = $this->lfConvertParam($_POST);
156            // エラーチェック
157            $this->arrErr = $this->lfProductClassError($this->arrForm);
158
159            if(count($this->arrErr) == 0) {
160                // 確認ページ設定
161                $this->tpl_mainpage = 'products/product_class_confirm.tpl';
162                $this->lfProductConfirmPage(); // 確認ページ表示
163            } else {
164                // 規格組み合わせ一覧の取得
165                $this->arrClassCat = $this->lfGetClassCatListDisp($_POST['class_id1'], $_POST['class_id2'], false);
166                $this->lfProductClassPage();   // 規格登録ページ
167            }
168            break;
169           
170        // 確認ページからの戻り
171        case 'confirm_return':
172            // フォームパラメータの引き継ぎ
173            $this->arrForm = $_POST;
174            // 規格の選択情報は引き継がない。
175            $this->arrForm['select_class_id1'] = "";
176            $this->arrForm['select_class_id2'] = "";
177            // 規格組み合わせ一覧の取得(デフォルト値は出力しない)
178            $this->arrClassCat = $this->lfGetClassCatListDisp($_POST['class_id1'], $_POST['class_id2'], false);
179            $this->lfProductClassPage();   // 規格登録ページ
180            break;
181           
182        case 'complete':
183            // 完了ページ設定
184            $this->tpl_mainpage = 'products/product_class_complete.tpl';
185            // 商品規格の登録
186            $this->lfInsertProductClass($_POST, $_POST['product_id']);
187            break;
188           
189        default:
190            $this->lfProductClassPage();   // 規格登録ページ
191            break;
192        }
193
194        $objView->assignobj($this);
195        $objView->display(MAIN_FRAME);
196    }
197
198    /**
199     * デストラクタ.
200     *
201     * @return void
202     */
203    function destroy() {
204        parent::destroy();
205    }
206
207    /* 規格登録ページ表示用 */
208    function lfProductClassPage() {
209        $objDb = new SC_Helper_DB_Ex();
210
211        $this->arrHidden = $_POST;
212        $this->arrHidden['select_class_id1'] = "";
213        $this->arrHidden['select_class_id2'] = "";
214        $arrClass = $objDb->sfGetIDValueList("dtb_class", 'class_id', 'name');
215
216        // 規格分類が登録されていない規格は表示しないようにする。
217        $arrClassCatCount = SC_Utils_Ex::sfGetClassCatCount();
218        if (count($arrClass) > 0) {
219            foreach($arrClass as $key => $val) {
220                if($arrClassCatCount[$key] > 0) {
221                    $this->arrClass[$key] = $arrClass[$key];
222                }
223            }
224        }
225        // 商品名を取得
226        $objQuery = new SC_Query();
227        $product_name = $objQuery->getOne("SELECT name FROM dtb_products WHERE product_id = ?", array($_POST['product_id']));
228        $this->arrForm['product_name'] = $product_name;
229    }
230   
231    /**
232     * デフォルトの表示
233     *
234     * @param object $objQuery
235     * @param integer $product_id 製品のID
236     * @param integer $max 表示される最大値
237     */
238    function lfSetDefaultClassCat($objQuery, $product_id, $max) {
239
240        // デフォルト値の読込
241        $col = "product_class_id, product_code, price01, price02, stock, stock_unlimited";
242        $arrRet = $objQuery->select($col, "dtb_products_class", "product_id = ? AND classcategory_id1 = 0 AND classcategory_id2 = 0", array($product_id));;
243
244        if(count($arrRet) > 0) {
245            $no = 1;
246            for($cnt = 0; $cnt < $max; $cnt++) {
247                $this->arrForm["product_class_id:".$no] = $arrRet[0]['product_class_id'];
248                $this->arrForm["product_code:".$no] = $arrRet[0]['product_code'];
249                $this->arrForm['stock:'.$no] = $arrRet[0]['stock'];
250                $this->arrForm['price01:'.$no] = $arrRet[0]['price01'];
251                $this->arrForm['price02:'.$no] = $arrRet[0]['price02'];
252                $this->arrForm['stock_unlimited:'.$no] = $arrRet[0]['stock_unlimited'];
253                $no++;
254            }
255        }
256    }
257
258    /* 規格組み合わせ一覧の取得 */
259    function lfGetClassCatListDisp($class_id1, $class_id2, $default = true) {
260        $objQuery = new SC_Query();
261
262        if($class_id2 != "") {
263            // 規格1と規格2
264            $sql = "SELECT * ";
265            $sql.= "FROM vw_cross_class AS crs_cls ";
266            $sql.= "WHERE class_id1 = ? AND class_id2 = ? ORDER BY rank1 DESC, rank2 DESC;";
267            $arrRet = $objQuery->getall($sql, array($class_id1, $class_id2));
268        } else {
269            // 規格1のみ
270            $sql = "SELECT * ";
271            $sql.= "FROM vw_cross_class AS crs_cls ";
272            $sql.= "WHERE class_id1 = ? AND class_id2 = 0 ORDER BY rank1 DESC;";
273            $arrRet = $objQuery->getall($sql, array($class_id1));
274           
275        }
276
277        $max = count($arrRet);
278
279        if($default) {
280            // デフォルト値を設定
281            $this->lfSetDefaultClassCat($objQuery, $_POST['product_id'], $max);
282        }
283
284        $this->arrForm["class_id1"] = $arrRet[0]['class_id1'];
285        $this->arrForm["class_id2"] = $arrRet[0]['class_id2'];
286        $this->tpl_onload.= "fnCheckAllStockLimit('$max', '" . DISABLED_RGB . "');";
287
288        return $arrRet;
289    }
290
291    /* 規格組み合わせ一覧の取得(編集画面) */
292    function lfGetClassCatListEdit($product_id) {
293        // 既存編集の場合
294        $objQuery = new SC_Query();
295
296        $col = "class_id1, class_id2, name1, name2, rank1, rank2, ";
297        $col.= "product_class_id, product_id, T1_classcategory_id AS classcategory_id1, T2_classcategory_id AS classcategory_id2, ";
298        $col.= "product_code, stock, stock_unlimited, sale_limit, price01, price02, status";
299
300        $sql = "SELECT $col FROM ";
301        $sql.= "( ";
302        $sql.= "SELECT T1.class_id AS class_id1, T2.class_id AS class_id2, T1.classcategory_id AS T1_classcategory_id, T2.classcategory_id AS T2_classcategory_id, T1.name AS name1, T2.name AS name2, T1.rank AS rank1, T2.rank AS rank2 ";
303        $sql.= "FROM dtb_classcategory AS T1, dtb_classcategory AS T2 ";
304        $sql.= "WHERE T1.class_id IN (SELECT class_id1 FROM vw_cross_products_class AS crs_prd WHERE product_id = ? GROUP BY class_id1, class_id2) AND T2.class_id IN (SELECT class_id2 FROM vw_cross_products_class AS crs_prd WHERE product_id = ? GROUP BY class_id1, class_id2)";
305        $sql.= ") AS T1 ";
306
307        $sql.= "LEFT JOIN (SELECT * FROM dtb_products_class WHERE product_id = ?) AS T3 ";
308        $sql.= "ON T1_classcategory_id = T3.classcategory_id1 AND T2_classcategory_id = T3.classcategory_id2 ";
309        $sql.= "ORDER BY rank1 DESC, rank2 DESC";
310
311        $arrList =  $objQuery->getAll($sql, array($product_id, $product_id, $product_id));
312
313        $this->arrForm["class_id1"] = $arrList[0]['class_id1'];
314        $this->arrForm["class_id2"] = $arrList[0]['class_id2'];
315
316        $max = count($arrList);
317
318        // デフォルト値を設定
319        $this->lfSetDefaultClassCat($objQuery, $product_id, $max);
320        $no = 1;
321        for($cnt = 0; $cnt < $max; $cnt++) {
322            $this->arrForm["classcategory_id1:".$no] = $arrList[$cnt]['classcategory_id1'];
323            $this->arrForm["classcategory_id2:".$no] = $arrList[$cnt]['classcategory_id2'];
324            $this->arrForm["product_class_id:".$no] = $arrList[$cnt]['product_class_id'];
325            if($arrList[$cnt]['product_id'] != "") {
326                $this->arrForm["product_code:".$no] = $arrList[$cnt]['product_code'];
327                $this->arrForm['stock:'.$no] = $arrList[$cnt]['stock'];
328                $this->arrForm['stock_unlimited:'.$no] = $arrList[$cnt]['stock_unlimited'];
329                $this->arrForm['price01:'.$no] = $arrList[$cnt]['price01'];
330                $this->arrForm['price02:'.$no] = $arrList[$cnt]['price02'];
331                // JavaScript初期化用文字列
332                $line.= "'check:".$no."',";
333            }
334            $no++;
335        }
336
337        $line = ereg_replace(",$", "", $line);
338        $this->tpl_javascript = "list = new Array($line);";
339        $color = DISABLED_RGB;
340        $this->tpl_onload.= "fnListCheck(list); fnCheckAllStockLimit('$max', '$color');";
341
342        return $arrList;
343    }
344
345    /* 規格の登録 */
346    function lfInsertProductClass($arrList, $product_id) {
347        $objQuery = new SC_Query();
348        $objDb = new SC_Helper_DB_Ex();
349
350        $objQuery->begin();
351
352        // 既存規格の削除
353        $where = "product_id = ?";
354        $objQuery->delete("dtb_products_class", $where, array($product_id));
355
356        $cnt = 1;
357        // すべての規格を登録する。
358        while($arrList["classcategory_id1:".$cnt] != "") {
359            if($arrList["check:".$cnt] == 1) {
360                $sqlval = array();
361                $sqlval['product_id'] = $product_id;
362                $sqlval['classcategory_id1'] = $arrList["classcategory_id1:".$cnt];
363                $sqlval['classcategory_id2'] = $arrList["classcategory_id2:".$cnt];
364                if( strlen($arrList["product_class_id:".$cnt]) > 0 ){
365                    $sqlval['product_class_id'] = $arrList["product_class_id:".$cnt];
366                }
367                $sqlval['product_code'] = $arrList["product_code:".$cnt];
368                $sqlval['stock'] = $arrList["stock:".$cnt];
369                $sqlval['stock_unlimited'] = ($arrList["stock_unlimited:".$cnt]) ? '1' : '0';
370                $sqlval['price01'] = $arrList['price01:'.$cnt];
371                $sqlval['price02'] = $arrList['price02:'.$cnt];
372                $sqlval['creator_id'] = $_SESSION['member_id'];
373                $sqlval['create_date'] = "now()";
374                $sqlval['update_date'] = "now()";
375                // INSERTの実行
376                $objQuery->insert("dtb_products_class", $sqlval);
377            }
378            $cnt++;
379        }
380       
381        // 件数カウントバッチ実行
382        $objDb->sfCategory_Count($objQuery);
383       
384        $objQuery->commit();
385    }
386
387    // 規格選択エラーチェック
388    function lfClassError() {
389        $objErr = new SC_CheckError();
390        $objErr->doFunc(array("規格1", "select_class_id1"), array("EXIST_CHECK"));
391        $objErr->doFunc(array("規格", "select_class_id1", "select_class_id2"), array("TOP_EXIST_CHECK"));
392        $objErr->doFunc(array("規格1", "規格2", "select_class_id1", "select_class_id2"), array("DIFFERENT_CHECK"));
393        return $objErr->arrErr;
394    }
395
396    /* 取得文字列の変換 */
397    function lfConvertParam($array) {
398        /*
399         *  文字列の変換
400         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
401         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
402         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
403         *  n :  「全角」数字を「半角(ハンカク)」に変換
404         */
405
406        $no = 1; // FIXME 未定義変数の修正
407        while($array["classcategory_id1:".$no] != "") {
408            $arrConvList["product_code:".$no] = "KVa";
409            $arrConvList["price01:".$no] = "n";
410            $arrConvList["price02:".$no] = "n";
411            $arrConvList["stock:".$no] = "n";
412            $no++;
413        }
414
415        // 文字変換
416        foreach ($arrConvList as $key => $val) {
417            // POSTされてきた値のみ変換する。
418            if(isset($array[$key])) {
419                $array[$key] = mb_convert_kana($array[$key] ,$val);
420            }
421        }
422        return $array;
423    }
424
425    // 商品規格エラーチェック
426    function lfProductClassError($array) {
427        $objErr = new SC_CheckError($array);
428        $no = 1; // FIXME 未定義変数の修正
429        while($array["classcategory_id1:".$no] != "") {
430            if($array["check:".$no] == 1) {
431                $objErr->doFunc(array("商品コード", "product_code:".$no, STEXT_LEN), array("MAX_LENGTH_CHECK"));
432                $objErr->doFunc(array(NORMAL_PRICE_TITLE, "price01:".$no, PRICE_LEN), array("NUM_CHECK", "MAX_LENGTH_CHECK"));
433                $objErr->doFunc(array(SALE_PRICE_TITLE, "price02:".$no, PRICE_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
434
435                if($array["stock_unlimited:".$no] != '1') {
436                    $objErr->doFunc(array("在庫数", "stock:".$no, AMOUNT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
437                }
438            }
439            if(count($objErr->arrErr) > 0) {
440                $objErr->arrErr["error:".$no] = $objErr->arrErr["product_code:".$no];
441                $objErr->arrErr["error:".$no].= $objErr->arrErr["price01:".$no];
442                $objErr->arrErr["error:".$no].= $objErr->arrErr["price02:".$no];
443                $objErr->arrErr["error:".$no].= $objErr->arrErr["stock:".$no];
444            }
445            $no++;
446        }
447        return $objErr->arrErr;
448    }
449
450    /* 確認ページ表示用 */
451    function lfProductConfirmPage() {
452        $objDb = new SC_Helper_DB_Ex();
453        $this->arrForm['mode'] = 'complete';
454        $this->arrClass = $objDb->sfGetIDValueList("dtb_class", 'class_id', 'name');
455        $cnt = 0;
456        $check = 0;
457        $no = 1;
458        while($_POST["classcategory_id1:".$no] != "") {
459            if($_POST["check:".$no] != "") {
460                $check++;
461            }
462            $no++;
463            $cnt++;
464        }
465        $this->tpl_check = $check;
466        $this->tpl_count = $cnt;
467    }
468}
469?>
Note: See TracBrowser for help on using the repository browser.