source: branches/version-2_5-dev/data/class/pages/admin/products/LC_Page_Admin_Products_ProductClass.php @ 18788

Revision 18788, 18.7 KB checked in by nanasess, 14 years ago (diff)

シーケンス値の出力に SC_Query::nextVal() を使用するよう修正(#780)

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