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

Revision 17364, 17.5 KB checked in by Seasoft, 16 years ago (diff)

XHTML管理画面の不具合修正

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