1 | <?php |
---|
2 | /* |
---|
3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
4 | * |
---|
5 | * http://www.lockon.co.jp/ |
---|
6 | */ |
---|
7 | |
---|
8 | require_once("../require.php"); |
---|
9 | require_once(DATA_PATH . "include/page_layout.inc"); |
---|
10 | |
---|
11 | class LC_Page { |
---|
12 | function LC_Page() { |
---|
13 | global $arrSTATUS; |
---|
14 | $this->arrSTATUS = $arrSTATUS; |
---|
15 | global $arrSTATUS_IMAGE; |
---|
16 | $this->arrSTATUS_IMAGE = $arrSTATUS_IMAGE; |
---|
17 | global $arrDELIVERYDATE; |
---|
18 | $this->arrDELIVERYDATE = $arrDELIVERYDATE; |
---|
19 | global $arrPRODUCTLISTMAX; |
---|
20 | $this->arrPRODUCTLISTMAX = $arrPRODUCTLISTMAX; |
---|
21 | /* |
---|
22 | session_start時のno-cacheヘッダーを抑制することで |
---|
23 | 「戻る」ボタン使用時の有効期限切れ表示を抑制する。 |
---|
24 | private-no-expire:クライアントのキャッシュを許可する。 |
---|
25 | */ |
---|
26 | session_cache_limiter('private-no-expire'); |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | $objPage = new LC_Page(); |
---|
31 | $conn = new SC_DBConn(); |
---|
32 | |
---|
33 | //表示件数の選択 |
---|
34 | if(sfIsInt($_POST['disp_number'])) { |
---|
35 | $objPage->disp_number = $_POST['disp_number']; |
---|
36 | } else { |
---|
37 | //最小表示件数を選択 |
---|
38 | $objPage->disp_number = current(array_keys($arrPRODUCTLISTMAX)); |
---|
39 | } |
---|
40 | |
---|
41 | //表示順序の保存 |
---|
42 | $objPage->orderby = $_POST['orderby']; |
---|
43 | |
---|
44 | // GETのカテゴリIDを元に正しいカテゴリIDを取得する。 |
---|
45 | $category_id = sfGetCategoryId("", $_GET['category_id']); |
---|
46 | |
---|
47 | // タイトル編集 |
---|
48 | $tpl_subtitle = ""; |
---|
49 | if($_GET['mode'] == 'search'){ |
---|
50 | $tpl_subtitle = "検索結果"; |
---|
51 | }elseif ($category_id == "" ) { |
---|
52 | $tpl_subtitle = "全商品"; |
---|
53 | }else{ |
---|
54 | $arrFirstCat = sfGetFirstCat($category_id); |
---|
55 | $tpl_subtitle = $arrFirstCat['name']; |
---|
56 | } |
---|
57 | |
---|
58 | $objQuery = new SC_Query(); |
---|
59 | $count = $objQuery->count("dtb_best_products", "category_id = ?", array($category_id)); |
---|
60 | |
---|
61 | // 以下の条件でBEST商品を表示する |
---|
62 | // ・BEST最大数の商品が登録されている。 |
---|
63 | // ・カテゴリIDがルートIDである。 |
---|
64 | // ・検索モードでない。 |
---|
65 | if(($count >= BEST_MIN) && lfIsRootCategory($category_id) && ($_GET['mode'] != 'search') ) { |
---|
66 | // 商品TOPの表示処理 |
---|
67 | /** 必ず指定する **/ |
---|
68 | $objPage->tpl_mainpage = HTML_PATH . "user_data/templates/list.tpl"; // メインテンプレート |
---|
69 | |
---|
70 | $objPage->arrBestItems = sfGetBestProducts($conn, $category_id); |
---|
71 | $objPage->BEST_ROOP_MAX = ceil((BEST_MAX-1)/2); |
---|
72 | } else { |
---|
73 | if ($_GET['mode'] == 'search' && strlen($_GET['category_id']) == 0 ){ |
---|
74 | // 検索時にcategory_idがGETに存在しない場合は、仮に埋めたIDを空白に戻す |
---|
75 | $category_id = ''; |
---|
76 | } |
---|
77 | |
---|
78 | // 商品一覧の表示処理 |
---|
79 | $objPage = lfDispProductsList($category_id, $_GET['name'], $objPage->disp_number, $_POST['orderby']); |
---|
80 | |
---|
81 | // 検索条件を画面に表示 |
---|
82 | // カテゴリー検索条件 |
---|
83 | if (strlen($_GET['category_id']) == 0) { |
---|
84 | $arrSearch['category'] = "指定なし"; |
---|
85 | }else{ |
---|
86 | $arrCat = $conn->getOne("SELECT category_name FROM dtb_category WHERE category_id = ?",array($category_id)); |
---|
87 | $arrSearch['category'] = $arrCat; |
---|
88 | } |
---|
89 | |
---|
90 | // 商品名検索条件 |
---|
91 | if ($_GET['name'] === "") { |
---|
92 | $arrSearch['name'] = "指定なし"; |
---|
93 | }else{ |
---|
94 | $arrSearch['name'] = $_GET['name']; |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | // レイアウトデザインを取得 |
---|
99 | $objPage = sfGetPageLayout($objPage, false, "products/list.php"); |
---|
100 | |
---|
101 | if($_POST['mode'] == "cart" && $_POST['product_id'] != "") { |
---|
102 | // 値の正当性チェック |
---|
103 | if(!sfIsInt($_POST['product_id']) || !sfIsRecord("dtb_products", "product_id", $_POST['product_id'], "del_flg = 0 AND status = 1")) { |
---|
104 | sfDispSiteError(PRODUCT_NOT_FOUND); |
---|
105 | } else { |
---|
106 | // 入力値の変換 |
---|
107 | $objPage->arrErr = lfCheckError($_POST['product_id']); |
---|
108 | if(count($objPage->arrErr) == 0) { |
---|
109 | $objCartSess = new SC_CartSession(); |
---|
110 | $classcategory_id = "classcategory_id". $_POST['product_id']; |
---|
111 | $classcategory_id1 = $_POST[$classcategory_id. '_1']; |
---|
112 | $classcategory_id2 = $_POST[$classcategory_id. '_2']; |
---|
113 | $quantity = "quantity". $_POST['product_id']; |
---|
114 | // 規格1が設定されていない場合 |
---|
115 | if(!$objPage->tpl_classcat_find1[$_POST['product_id']]) { |
---|
116 | $classcategory_id1 = '0'; |
---|
117 | } |
---|
118 | // 規格2が設定されていない場合 |
---|
119 | if(!$objPage->tpl_classcat_find2[$_POST['product_id']]) { |
---|
120 | $classcategory_id2 = '0'; |
---|
121 | } |
---|
122 | $objCartSess->setPrevURL($_SERVER['REQUEST_URI']); |
---|
123 | $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $_POST[$quantity]); |
---|
124 | header("Location: " . URL_CART_TOP); |
---|
125 | exit; |
---|
126 | } |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | $objPage->tpl_subtitle = $tpl_subtitle; |
---|
132 | |
---|
133 | // 支払方法の取得 |
---|
134 | $objPage->arrPayment = lfGetPayment(); |
---|
135 | // 入力情報を渡す |
---|
136 | $objPage->arrForm = $_POST; |
---|
137 | |
---|
138 | lfConvertParam(); |
---|
139 | |
---|
140 | $objPage->category_id = $category_id; |
---|
141 | $objPage->arrSearch = $arrSearch; |
---|
142 | |
---|
143 | sfCustomDisplay($objPage); |
---|
144 | |
---|
145 | //----------------------------------------------------------------------------------------------------------------------------------- |
---|
146 | /* カテゴリIDがルートかどうかの判定 */ |
---|
147 | function lfIsRootCategory($category_id) { |
---|
148 | $objQuery = new SC_Query(); |
---|
149 | $level = $objQuery->get("dtb_category", "level", "category_id = ?", array($category_id)); |
---|
150 | if($level == 1) { |
---|
151 | return true; |
---|
152 | } |
---|
153 | return false; |
---|
154 | } |
---|
155 | |
---|
156 | /* 商品一覧の表示 */ |
---|
157 | function lfDispProductsList($category_id, $name, $disp_num, $orderby) { |
---|
158 | global $objPage; |
---|
159 | $objQuery = new SC_Query(); |
---|
160 | $objPage->tpl_pageno = $_POST['pageno']; |
---|
161 | |
---|
162 | //表示件数でテンプレートを切り替える |
---|
163 | $objPage->tpl_mainpage = HTML_PATH . "user_data/templates/list.tpl"; // メインテンプレート |
---|
164 | |
---|
165 | //表示順序 |
---|
166 | switch($orderby) { |
---|
167 | //価格順 |
---|
168 | case 'price': |
---|
169 | $order = "price02_min ASC"; |
---|
170 | break; |
---|
171 | //新着順 |
---|
172 | case 'date': |
---|
173 | $order = "create_date DESC"; |
---|
174 | break; |
---|
175 | default: |
---|
176 | $order = "category_rank DESC, rank DESC"; |
---|
177 | break; |
---|
178 | } |
---|
179 | |
---|
180 | // 商品検索条件の作成(未削除、表示) |
---|
181 | $where = "del_flg = 0 AND status = 1 "; |
---|
182 | // カテゴリからのWHERE文字列取得 |
---|
183 | if ( $category_id ) { |
---|
184 | list($tmp_where, $arrval) = sfGetCatWhere($category_id); |
---|
185 | if($tmp_where != "") { |
---|
186 | $where.= " AND $tmp_where"; |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | // 商品名をwhere文に |
---|
191 | $name = ereg_replace(",", "", $name); |
---|
192 | if ( strlen($name) > 0 ){ |
---|
193 | $where .= " AND ( name ILIKE ? OR comment3 ILIKE ?) "; |
---|
194 | $ret = sfManualEscape($name); |
---|
195 | $arrval[] = "%$ret%"; |
---|
196 | $arrval[] = "%$ret%"; |
---|
197 | } |
---|
198 | |
---|
199 | // 行数の取得 |
---|
200 | $linemax = $objQuery->count("vw_products_allclass AS allcls", $where, $arrval); |
---|
201 | $objPage->tpl_linemax = $linemax; // 何件が該当しました。表示用 |
---|
202 | |
---|
203 | // ページ送りの取得 |
---|
204 | $objNavi = new SC_PageNavi($_POST['pageno'], $linemax, $disp_num, "fnNaviPage", NAVI_PMAX); |
---|
205 | |
---|
206 | $strnavi = $objNavi->strnavi; |
---|
207 | $strnavi = str_replace('onclick="fnNaviPage', 'onclick="form1.mode.value=\''.'\'; fnNaviPage', $strnavi); |
---|
208 | $objPage->tpl_strnavi = $strnavi; // 表示文字列 |
---|
209 | $startno = $objNavi->start_row; // 開始行 |
---|
210 | |
---|
211 | // 取得範囲の指定(開始行番号、行数のセット) |
---|
212 | $objQuery->setlimitoffset($disp_num, $startno); |
---|
213 | // 表示順序 |
---|
214 | $objQuery->setorder($order); |
---|
215 | |
---|
216 | |
---|
217 | |
---|
218 | |
---|
219 | |
---|
220 | |
---|
221 | |
---|
222 | |
---|
223 | // 検索結果の取得 |
---|
224 | $objPage->arrProducts = $objQuery->select("*", "vw_products_allclass AS allcls", $where, $arrval); |
---|
225 | |
---|
226 | // 規格名一覧 |
---|
227 | $arrClassName = sfGetIDValueList("dtb_class", "class_id", "name"); |
---|
228 | // 規格分類名一覧 |
---|
229 | $arrClassCatName = sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); |
---|
230 | // 企画セレクトボックス設定 |
---|
231 | if($disp_num == 15) { |
---|
232 | for($i = 0; $i < count($objPage->arrProducts); $i++) { |
---|
233 | $objPage = lfMakeSelect($objPage->arrProducts[$i]['product_id'], $arrClassName, $arrClassCatName); |
---|
234 | // 購入制限数を取得 |
---|
235 | $objPage = lfGetSaleLimit($objPage->arrProducts[$i]); |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | return $objPage; |
---|
240 | } |
---|
241 | |
---|
242 | /* 規格セレクトボックスの作成 */ |
---|
243 | function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) { |
---|
244 | global $objPage; |
---|
245 | |
---|
246 | $classcat_find1 = false; |
---|
247 | $classcat_find2 = false; |
---|
248 | // 在庫ありの商品の有無 |
---|
249 | $stock_find = false; |
---|
250 | |
---|
251 | // 商品規格情報の取得 |
---|
252 | $arrProductsClass = lfGetProductsClass($product_id); |
---|
253 | |
---|
254 | // 規格1クラス名の取得 |
---|
255 | $objPage->tpl_class_name1[$product_id] = $arrClassName[$arrProductsClass[0]['class_id1']]; |
---|
256 | // 規格2クラス名の取得 |
---|
257 | $objPage->tpl_class_name2[$product_id] = $arrClassName[$arrProductsClass[0]['class_id2']]; |
---|
258 | |
---|
259 | // すべての組み合わせ数 |
---|
260 | $count = count($arrProductsClass); |
---|
261 | |
---|
262 | $classcat_id1 = ""; |
---|
263 | |
---|
264 | $arrSele = array(); |
---|
265 | $arrList = array(); |
---|
266 | |
---|
267 | $list_id = 0; |
---|
268 | $arrList[0] = "\tlist". $product_id. "_0 = new Array('選択してください'"; |
---|
269 | $arrVal[0] = "\tval". $product_id. "_0 = new Array(''"; |
---|
270 | |
---|
271 | for ($i = 0; $i < $count; $i++) { |
---|
272 | // 在庫のチェック |
---|
273 | if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') { |
---|
274 | continue; |
---|
275 | } |
---|
276 | |
---|
277 | $stock_find = true; |
---|
278 | |
---|
279 | // 規格1のセレクトボックス用 |
---|
280 | if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){ |
---|
281 | $arrList[$list_id].=");\n"; |
---|
282 | $arrVal[$list_id].=");\n"; |
---|
283 | $classcat_id1 = $arrProductsClass[$i]['classcategory_id1']; |
---|
284 | $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1]; |
---|
285 | $list_id++; |
---|
286 | } |
---|
287 | |
---|
288 | // 規格2のセレクトボックス用 |
---|
289 | $classcat_id2 = $arrProductsClass[$i]['classcategory_id2']; |
---|
290 | |
---|
291 | // セレクトボックス表示値 |
---|
292 | if($arrList[$list_id] == "") { |
---|
293 | $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('選択してください', '". $arrClassCatName[$classcat_id2]. "'"; |
---|
294 | } else { |
---|
295 | $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'"; |
---|
296 | } |
---|
297 | |
---|
298 | // セレクトボックスPOST値 |
---|
299 | if($arrVal[$list_id] == "") { |
---|
300 | $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'"; |
---|
301 | } else { |
---|
302 | $arrVal[$list_id].= ", '".$classcat_id2."'"; |
---|
303 | } |
---|
304 | } |
---|
305 | |
---|
306 | $arrList[$list_id].=");\n"; |
---|
307 | $arrVal[$list_id].=");\n"; |
---|
308 | |
---|
309 | // 規格1 |
---|
310 | $objPage->arrClassCat1[$product_id] = $arrSele; |
---|
311 | |
---|
312 | $lists = "\tlists".$product_id. " = new Array("; |
---|
313 | $no = 0; |
---|
314 | foreach($arrList as $val) { |
---|
315 | $objPage->tpl_javascript.= $val; |
---|
316 | if ($no != 0) { |
---|
317 | $lists.= ",list". $product_id. "_". $no; |
---|
318 | } else { |
---|
319 | $lists.= "list". $product_id. "_". $no; |
---|
320 | } |
---|
321 | $no++; |
---|
322 | } |
---|
323 | $objPage->tpl_javascript.= $lists.");\n"; |
---|
324 | |
---|
325 | $vals = "\tvals".$product_id. " = new Array("; |
---|
326 | $no = 0; |
---|
327 | foreach($arrVal as $val) { |
---|
328 | $objPage->tpl_javascript.= $val; |
---|
329 | if ($no != 0) { |
---|
330 | $vals.= ",val". $product_id. "_". $no; |
---|
331 | } else { |
---|
332 | $vals.= "val". $product_id. "_". $no; |
---|
333 | } |
---|
334 | $no++; |
---|
335 | } |
---|
336 | $objPage->tpl_javascript.= $vals.");\n"; |
---|
337 | |
---|
338 | // 選択されている規格2ID |
---|
339 | $classcategory_id = "classcategory_id". $product_id; |
---|
340 | $objPage->tpl_onload .= "lnSetSelect('".$classcategory_id."_1','".$classcategory_id."_2','".$product_id."','".$_POST[$classcategory_id."_2"]."'); "; |
---|
341 | |
---|
342 | // 規格1が設定されている |
---|
343 | if($arrProductsClass[0]['classcategory_id1'] != '0') { |
---|
344 | $classcat_find1 = true; |
---|
345 | } |
---|
346 | |
---|
347 | // 規格2が設定されている |
---|
348 | if($arrProductsClass[0]['classcategory_id2'] != '0') { |
---|
349 | $classcat_find2 = true; |
---|
350 | } |
---|
351 | |
---|
352 | $objPage->tpl_classcat_find1[$product_id] = $classcat_find1; |
---|
353 | $objPage->tpl_classcat_find2[$product_id] = $classcat_find2; |
---|
354 | $objPage->tpl_stock_find[$product_id] = $stock_find; |
---|
355 | |
---|
356 | return $objPage; |
---|
357 | } |
---|
358 | /* 商品規格情報の取得 */ |
---|
359 | function lfGetProductsClass($product_id) { |
---|
360 | $arrRet = array(); |
---|
361 | if(sfIsInt($product_id)) { |
---|
362 | // 商品規格取得 |
---|
363 | $objQuery = new SC_Query(); |
---|
364 | $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited"; |
---|
365 | $table = "vw_product_class AS prdcls"; |
---|
366 | $where = "product_id = ?"; |
---|
367 | $objQuery->setorder("rank1 DESC, rank2 DESC"); |
---|
368 | $arrRet = $objQuery->select($col, $table, $where, array($product_id)); |
---|
369 | } |
---|
370 | return $arrRet; |
---|
371 | } |
---|
372 | |
---|
373 | /* 入力内容のチェック */ |
---|
374 | function lfCheckError($id) { |
---|
375 | global $objPage; |
---|
376 | |
---|
377 | // 入力データを渡す。 |
---|
378 | $objErr = new SC_CheckError(); |
---|
379 | |
---|
380 | $classcategory_id1 = "classcategory_id". $id. "_1"; |
---|
381 | $classcategory_id2 = "classcategory_id". $id. "_2"; |
---|
382 | $quantity = "quantity". $id; |
---|
383 | // 複数項目チェック |
---|
384 | if ($objPage->tpl_classcat_find1[$id]) { |
---|
385 | $objErr->doFunc(array("規格1", $classcategory_id1, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
386 | } |
---|
387 | if ($objPage->tpl_classcat_find2[$id]) { |
---|
388 | $objErr->doFunc(array("規格2", $classcategory_id2, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
389 | } |
---|
390 | $objErr->doFunc(array("個数", $quantity, INT_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
391 | |
---|
392 | return $objErr->arrErr; |
---|
393 | } |
---|
394 | |
---|
395 | // 購入制限数の設定 |
---|
396 | function lfGetSaleLimit($product) { |
---|
397 | global $objPage; |
---|
398 | //在庫が無限または購入制限値が設定値より大きい場合 |
---|
399 | if($product['sale_unlimited'] == 1 || $product['sale_limit'] > SALE_LIMIT_MAX) { |
---|
400 | $objPage->tpl_sale_limit[$product['product_id']] = SALE_LIMIT_MAX; |
---|
401 | } else { |
---|
402 | $objPage->tpl_sale_limit[$product['product_id']] = $product['sale_limit']; |
---|
403 | } |
---|
404 | |
---|
405 | return $objPage; |
---|
406 | } |
---|
407 | |
---|
408 | //支払方法の取得 |
---|
409 | //payment_id 1:代金引換 2:銀行振り込み 3:現金書留 |
---|
410 | function lfGetPayment() { |
---|
411 | $objQuery = new SC_Query; |
---|
412 | $col = "payment_id, rule, payment_method"; |
---|
413 | $from = "dtb_payment"; |
---|
414 | $where = "del_flg = 0"; |
---|
415 | $order = "payment_id"; |
---|
416 | $objQuery->setorder($order); |
---|
417 | $arrRet = $objQuery->select($col, $from, $where); |
---|
418 | return $arrRet; |
---|
419 | } |
---|
420 | |
---|
421 | function lfconvertParam () { |
---|
422 | global $objPage; |
---|
423 | |
---|
424 | foreach ($objPage->arrForm as $key => $value) { |
---|
425 | if (preg_match('/^quantity[0-9]+/', $key)) { |
---|
426 | $objPage->arrForm[$key] |
---|
427 | = htmlspecialchars($objPage->arrForm[$key], ENT_QUOTES, CHAR_CODE); |
---|
428 | } |
---|
429 | } |
---|
430 | } |
---|
431 | ?> |
---|