source: branches/feature-module-update/data/class/pages/admin/products/LC_Page_Admin_Products_ProductClass.php @ 15559

Revision 15559, 16.7 KB checked in by nanasess, 17 years ago (diff)

クラス化に伴う修正

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