source: tmp/version-2_5-test/data/class/pages/admin/order/LC_Page_Admin_Order_ProductSelect.php @ 18609

Revision 18609, 13.2 KB checked in by kajiwara, 14 years ago (diff)

正式版にナイトリービルド版をマージしてみるテスト

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_Order_ProductSelect 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 = 'order/product_select.tpl';
47        $this->tpl_mainno = 'order';
48        $this->tpl_subnavi = '';
49        $this->tpl_subno = "";
50        $this->tpl_subtitle = '商品選択';
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process() {
59        $conn = new SC_DBConn();
60        $objView = new SC_AdminView();
61        $objSess = new SC_Session();
62        $objDb = new SC_Helper_DB_Ex();
63        $objQuery = new SC_Query();
64
65        // 認証可否の判定
66        SC_Utils_Ex::sfIsSuccess($objSess);
67
68        if (!isset($_POST['mode'])) $_POST['mode'] = "";
69
70        if ($_GET['no'] != '') {
71            $this->tpl_no = strval($_GET['no']);
72        } elseif ($_POST['no'] != '') {
73            $this->tpl_no = strval($_POST['no']);
74        }
75
76        if ($_POST['mode'] == "search") {
77
78            // POST値の引き継ぎ
79            $this->arrForm = $_POST;
80            // 入力文字の強制変換
81            $this->lfConvertParam();
82
83            $where = "del_flg = 0";
84
85            /* 入力エラーなし */
86            foreach ($this->arrForm as $key => $val) {
87                if($val == "") {
88                    continue;
89                }
90
91                switch ($key) {
92                case 'search_name':
93                    $where .= " AND name ILIKE ?";
94                    $arrval[] = "%$val%";
95                    break;
96                case 'search_category_id':
97                    list($tmp_where, $tmp_arrval) = $objDb->sfGetCatWhere($val);
98                    if($tmp_where != "") {
99                        $where.= " AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")";
100                        $arrval = array_merge((array)$arrval, (array)$tmp_arrval);
101                    }
102                    break;
103                case 'search_product_code':
104                    $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)";
105                    $arrval[] = "$val%";
106                    break;
107                default:
108                    break;
109                }
110            }
111
112            // 読み込む列とテーブルの指定
113            $col = "DISTINCT T1.product_id, product_code_min, product_code_max,"
114                . " price01_min, price01_max, price02_min, price02_max,"
115                . " stock_min, stock_max, stock_unlimited_min,"
116                . " stock_unlimited_max, del_flg, status, name, comment1,"
117                . " comment2, comment3, main_list_comment, main_image,"
118                . " main_list_image, product_flag, deliv_date_id, sale_limit,"
119                . " point_rate, create_date, deliv_fee, "
120                . " T4.product_rank, T4.category_rank";
121            $from = "vw_products_allclass AS T1"
122                . " JOIN ("
123                . " SELECT max(T3.rank) AS category_rank,"
124                . "        max(T2.rank) AS product_rank,"
125                . "        T2.product_id"
126                . "   FROM dtb_product_categories T2"
127                . "   JOIN dtb_category T3 USING (category_id)"
128                . " GROUP BY product_id) AS T4 USING (product_id)";
129            $order = "T4.category_rank DESC, T4.product_rank DESC";
130
131            // 行数の取得
132            if (empty($arrval)) {
133                $arrval = array();
134            }
135            $linemax = $objQuery->count("dtb_products", $where, $arrval);
136            $this->tpl_linemax = $linemax;              // 何件が該当しました。表示用
137
138            // ページ送りの処理
139            if(isset($_POST['search_page_max'])
140               && is_numeric($_POST['search_page_max'])) {
141                $page_max = $_POST['search_page_max'];
142            } else {
143                $page_max = SEARCH_PMAX;
144            }
145
146            // ページ送りの取得
147            $objNavi = new SC_PageNavi($_POST['search_pageno'], $linemax, $page_max, "fnNaviSearchOnlyPage", NAVI_PMAX);
148            $this->tpl_strnavi = $objNavi->strnavi;     // 表示文字列
149            $startno = $objNavi->start_row;
150
151            // 取得範囲の指定(開始行番号、行数のセット)
152            if(DB_TYPE != "mysql") $objQuery->setlimitoffset($page_max, $startno);
153            // 表示順序
154            $objQuery->setorder($order);
155
156            // viewも絞込みをかける(mysql用)
157            //sfViewWhere("&&noncls_where&&", $where, $arrval, $objQuery->order . " " .  $objQuery->setlimitoffset($page_max, $startno, true));
158
159            // 検索結果の取得
160            $this->arrProducts = $objQuery->select($col, $from, $where, $arrval);
161
162            // 規格名一覧
163            $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name");
164
165            // 規格分類名一覧
166            $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
167
168            // 規格セレクトボックス設定
169            for($i = 0; $i < count($this->arrProducts); $i++) {
170                $this->lfMakeSelect($this->arrProducts[$i]['product_id'], $arrClassName, $arrClassCatName);
171                // 購入制限数を取得
172                $this->lfGetSaleLimit($this->arrProducts[$i]);
173            }
174        }
175
176        // カテゴリ取得
177        $this->arrCatList = $objDb->sfGetCategoryList();
178
179        //---- ページ表示
180        $objView->assignobj($this);
181        $objView->display($this->tpl_mainpage);
182    }
183
184    /**
185     * デストラクタ.
186     *
187     * @return void
188     */
189    function destroy() {
190        parent::destroy();
191    }
192
193    /* 取得文字列の変換 */
194    function lfConvertParam() {
195        /*
196         *  文字列の変換
197         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
198         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
199         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
200         *  n :  「全角」数字を「半角(ハンカク)」に変換
201         */
202        $arrConvList['search_name'] = "KVa";
203        $arrConvList['search_product_code'] = "KVa";
204
205        // 文字変換
206        foreach ($arrConvList as $key => $val) {
207            // POSTされてきた値のみ変換する。
208            if(isset($this->arrForm[$key])) {
209                $this->arrForm[$key] = mb_convert_kana($this->arrForm[$key] ,$val);
210            }
211        }
212    }
213
214    /* 規格セレクトボックスの作成 */
215    function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) {
216
217        $classcat_find1 = false;
218        $classcat_find2 = false;
219        // 在庫ありの商品の有無
220        $stock_find = false;
221
222        // 商品規格情報の取得
223        $arrProductsClass = $this->lfGetProductsClass($product_id);
224
225        // 規格1クラス名の取得
226        $this->tpl_class_name1[$product_id] =
227            isset($arrClassName[$arrProductsClass[0]['class_id1']])
228            ? $arrClassName[$arrProductsClass[0]['class_id1']]
229            : "";
230
231        // 規格2クラス名の取得
232        $this->tpl_class_name2[$product_id] =
233            isset($arrClassName[$arrProductsClass[0]['class_id2']])
234            ? $arrClassName[$arrProductsClass[0]['class_id2']]
235            : "";
236
237        // すべての組み合わせ数
238        $count = count($arrProductsClass);
239
240        $classcat_id1 = "";
241
242        $arrSele = array();
243        $arrList = array();
244
245        $list_id = 0;
246        $arrList[0] = "\tlist". $product_id. "_0 = new Array('選択してください'";
247        $arrVal[0] = "\tval". $product_id. "_0 = new Array(''";
248
249        for ($i = 0; $i < $count; $i++) {
250            // 在庫のチェック
251            if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
252                continue;
253            }
254
255            $stock_find = true;
256
257            // 規格1のセレクトボックス用
258            if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
259                $arrList[$list_id].=");\n";
260                $arrVal[$list_id].=");\n";
261                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
262                $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
263                $list_id++;
264
265                $arrList[$list_id] = "";
266                $arrVal[$list_id] = "";
267            }
268
269            // 規格2のセレクトボックス用
270            $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
271
272            // セレクトボックス表示値
273            if($arrList[$list_id] == "") {
274                $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('選択してください', '". $arrClassCatName[$classcat_id2]. "'";
275            } else {
276                $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
277            }
278
279            // セレクトボックスPOST値
280            if($arrVal[$list_id] == "") {
281                $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'";
282            } else {
283                $arrVal[$list_id].= ", '".$classcat_id2."'";
284            }
285        }
286
287        $arrList[$list_id].=");\n";
288        $arrVal[$list_id].=");\n";
289
290        // 規格1
291        $this->arrClassCat1[$product_id] = $arrSele;
292
293        $lists = "\tlists".$product_id. " = new Array(";
294        $no = 0;
295        foreach($arrList as $val) {
296            $this->tpl_javascript.= $val;
297            if ($no != 0) {
298                $lists.= ",list". $product_id. "_". $no;
299            } else {
300                $lists.= "list". $product_id. "_". $no;
301            }
302            $no++;
303        }
304        $this->tpl_javascript.= $lists.");\n";
305
306        $vals = "\tvals".$product_id. " = new Array(";
307        $no = 0;
308        foreach($arrVal as $val) {
309            $this->tpl_javascript.= $val;
310            if ($no != 0) {
311                $vals.= ",val". $product_id. "_". $no;
312            } else {
313                $vals.= "val". $product_id. "_". $no;
314            }
315            $no++;
316        }
317        $this->tpl_javascript.= $vals.");\n";
318
319        // 選択されている規格2ID
320        $classcategory_id = "classcategory_id". $product_id;
321
322        $classcategory_id_2 = $classcategory_id . "_2";
323        if (!isset($classcategory_id_2)) $classcategory_id_2 = "";
324        if (!isset($_POST[$classcategory_id_2])) $_POST[$classcategory_id_2] = "";
325
326        $this->tpl_onload .= "lnSetSelect('" . $classcategory_id ."_1', "
327            . "'" . $classcategory_id_2 . "',"
328            . "'" . $product_id . "',"
329            . "'" . $_POST[$classcategory_id_2] ."'); ";
330
331        // 規格1が設定されている
332        if($arrProductsClass[0]['classcategory_id1'] != '0') {
333            $classcat_find1 = true;
334        }
335
336        // 規格2が設定されている
337        if($arrProductsClass[0]['classcategory_id2'] != '0') {
338            $classcat_find2 = true;
339        }
340
341        $this->tpl_classcat_find1[$product_id] = $classcat_find1;
342        $this->tpl_classcat_find2[$product_id] = $classcat_find2;
343        $this->tpl_stock_find[$product_id] = $stock_find;
344    }
345
346    /* 商品規格情報の取得 */
347    function lfGetProductsClass($product_id) {
348        $arrRet = array();
349        if(SC_Utils_Ex::sfIsInt($product_id)) {
350            // 商品規格取得
351            $objQuery = new SC_Query();
352            $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited";
353            $table = "vw_product_class AS prdcls";
354            $where = "product_id = ?";
355            $objQuery->setorder("rank1 DESC, rank2 DESC");
356            $arrRet = $objQuery->select($col, $table, $where, array($product_id));
357        }
358        return $arrRet;
359    }
360
361    // 購入制限数の設定
362    function lfGetSaleLimit($arrProduct) {
363        //在庫が無限または購入制限値が設定値より大きい場合
364        if (!SC_Utils_Ex::sfIsInt($arrProduct['sale_limit']) || $arrProduct['sale_limit'] > SALE_LIMIT_MAX) {
365            $this->tpl_sale_limit[$arrProduct['product_id']] = SALE_LIMIT_MAX;
366        } else {
367            $this->tpl_sale_limit[$arrProduct['product_id']] = $arrProduct['sale_limit'];
368        }
369    }
370}
371?>
Note: See TracBrowser for help on using the repository browser.