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

Revision 17408, 17.6 KB checked in by Seasoft, 16 years ago (diff)

商品規格
文字化け削除。
見出し追加。
ソース整形。

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