source: branches/feature-module-update/html/products/detail.php @ 15078

Revision 15078, 15.6 KB checked in by nanasess, 17 years ago (diff)

r15064 から svn cp
とりあえず暫定コミット.

  • UTF-8 に変更
  • slib.php, glib.php のクラス化
  • LC_Page の抽象化(一部)
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8require_once("../require.php");
9require_once(DATA_PATH . "include/page_layout.inc");
10
11class LC_Page {
12    function LC_Page() {
13        /** 必ず指定する **/
14        global $arrSTATUS;
15        $this->arrSTATUS = $arrSTATUS;
16        global $arrSTATUS_IMAGE;
17        $this->arrSTATUS_IMAGE = $arrSTATUS_IMAGE;
18        global $arrDELIVERYDATE;
19        $this->arrDELIVERYDATE = $arrDELIVERYDATE;
20        global $arrRECOMMEND;
21        $this->arrRECOMMEND = $arrRECOMMEND;
22       
23        //$this->tpl_mainpage="products/detail.tpl";
24       
25        /*
26         session_start時のno-cacheヘッダーを抑制することで
27         「戻る」ボタン使用時の有効期限切れ表示を抑制する。
28         private-no-expire:クライアントのキャッシュを許可する。
29        */
30        session_cache_limiter('private-no-expire');
31    }
32}
33
34$objPage = new LC_Page();
35$objView = new SC_SiteView();
36$objCustomer = new SC_Customer();
37$objQuery = new SC_Query();
38
39// レイアウトデザインを取得
40$objPage = sfGetPageLayout($objPage, false, "products/detail.php");
41
42// パラメータ管理クラス
43$objFormParam = new SC_FormParam();
44// パラメータ情報の初期化
45lfInitParam();
46// POST値の取得
47$objFormParam->setParam($_POST);
48
49// ファイル管理クラス
50$objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
51// ファイル情報の初期化
52lfInitFile();
53
54// 管理ページからの確認の場合は、非公開の商品も表示する。
55if($_GET['admin'] == 'on') {
56    $where = "del_flg = 0";
57} else {
58    $where = "del_flg = 0 AND status = 1";
59}
60
61if($_POST['mode'] != "") {
62    $tmp_id = $_POST['product_id'];
63} else {
64    $tmp_id = $_GET['product_id'];
65}
66
67// 値の正当性チェック
68if(!sfIsInt($_GET['product_id']) || !sfIsRecord("dtb_products", "product_id", $tmp_id, $where)) {
69    sfDispSiteError(PRODUCT_NOT_FOUND);
70}
71// ログイン判定
72if($objCustomer->isLoginSuccess()) {
73    //お気に入りボタン表示
74    $objPage->tpl_login = true;
75
76/* 閲覧ログ機能は現在未使用
77   
78    $table = "dtb_customer_reading";
79    $where = "customer_id = ? ";
80    $arrval[] = $objCustomer->getValue('customer_id');
81    //顧客の閲覧商品数
82    $rpcnt = $objQuery->count($table, $where, $arrval);
83
84    //閲覧数が設定数以下
85    if ($rpcnt < CUSTOMER_READING_MAX){
86        //閲覧履歴に新規追加
87        lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
88    } else {
89        //閲覧履歴の中で一番古いものを削除して新規追加
90        $oldsql = "SELECT MIN(update_date) FROM ".$table." WHERE customer_id = ?";
91        $old = $objQuery->getone($oldsql, array($objCustomer->getValue("customer_id")));
92        $where = "customer_id = ? AND update_date = ? ";
93        $arrval = array($objCustomer->getValue("customer_id"), $old);
94        //削除
95        $objQuery->delete($table, $where, $arrval);
96        //追加
97        lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
98    }
99*/
100}
101
102
103// 規格選択セレクトボックスの作成
104$objPage = lfMakeSelect($objPage, $tmp_id);
105
106// 商品IDをFORM内に保持する。
107$objPage->tpl_product_id = $tmp_id;
108
109switch($_POST['mode']) {
110case 'cart':
111    // 入力値の変換
112    $objFormParam->convParam();
113    $objPage->arrErr = lfCheckError();
114    if(count($objPage->arrErr) == 0) {
115        $objCartSess = new SC_CartSession();
116        $classcategory_id1 = $_POST['classcategory_id1'];
117        $classcategory_id2 = $_POST['classcategory_id2'];
118               
119        // 規格1が設定されていない場合
120        if(!$objPage->tpl_classcat_find1) {
121            $classcategory_id1 = '0';
122        }
123       
124        // 規格2が設定されていない場合
125        if(!$objPage->tpl_classcat_find2) {
126            $classcategory_id2 = '0';
127        }
128       
129        $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
130        $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $objFormParam->getValue('quantity'));
131        header("Location: " . URL_CART_TOP);
132
133        exit;
134    }
135    break;
136       
137default:
138    break;
139}
140
141$objQuery = new SC_Query();
142// DBから商品情報を取得する。
143$arrRet = $objQuery->select("*", "vw_products_allclass_detail AS alldtl", "product_id = ?", array($tmp_id));
144$objPage->arrProduct = $arrRet[0];
145
146// 商品コードの取得
147$code_sql = "SELECT product_code FROM dtb_products_class AS prdcls WHERE prdcls.product_id = ? GROUP BY product_code ORDER BY product_code";
148$arrProductCode = $objQuery->getall($code_sql, array($tmp_id));
149$arrProductCode = sfswaparray($arrProductCode);
150$objPage->arrProductCode = $arrProductCode["product_code"];
151
152// 購入制限数を取得
153if($objPage->arrProduct['sale_unlimited'] == 1 || $objPage->arrProduct['sale_limit'] > SALE_LIMIT_MAX) {
154  $objPage->tpl_sale_limit = SALE_LIMIT_MAX;
155} else {
156  $objPage->tpl_sale_limit = $objPage->arrProduct['sale_limit'];
157}
158
159// サブタイトルを取得
160$arrFirstCat = sfGetFirstCat($arrRet[0]['category_id']);
161$tpl_subtitle = $arrFirstCat['name'];
162$objPage->tpl_subtitle = $tpl_subtitle;
163
164// DBからのデータを引き継ぐ
165$objUpFile->setDBFileList($objPage->arrProduct);
166// ファイル表示用配列を渡す
167$objPage->arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL, true);
168// 支払方法の取得
169$objPage->arrPayment = lfGetPayment();
170// 入力情報を渡す
171$objPage->arrForm = $objFormParam->getFormParamList();
172//レビュー情報の取得
173$objPage->arrReview = lfGetReviewData($tmp_id);
174// トラックバック情報の取得
175
176// トラックバック機能の稼働状況チェック
177if (sfGetSiteControlFlg(SITE_CONTROL_TRACKBACK) != 1) {
178    $objPage->arrTrackbackView = "OFF";
179} else {
180    $objPage->arrTrackbackView = "ON";
181    $objPage->arrTrackback = lfGetTrackbackData($tmp_id);
182}
183$objPage->trackback_url = TRACKBACK_TO_URL . $tmp_id;
184// タイトルに商品名を入れる
185$objPage->tpl_title = "商品詳細 ". $objPage->arrProduct["name"];
186//オススメ商品情報表示
187$objPage->arrRecommend = lfPreGetRecommendProducts($tmp_id);
188//この商品を買った人はこんな商品も買っています
189$objPage->arrRelateProducts = lfGetRelateProducts($tmp_id);
190
191// 拡大画像のウィンドウサイズをセット
192$image_path = IMAGE_SAVE_DIR . basename($objPage->arrFile["main_large_image"]["filepath"]);
193list($large_width, $large_height) = getimagesize($image_path);
194$objPage->tpl_large_width = $large_width + 60;
195$objPage->tpl_large_height = $large_height + 80;
196
197lfConvertParam();
198
199$objView->assignobj($objPage);
200$objView->display(SITE_FRAME);
201//-----------------------------------------------------------------------------------------------------------------------------------
202/* ファイル情報の初期化 */
203function lfInitFile() {
204    global $objUpFile;
205    $objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg','gif'),IMAGE_SIZE, true, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
206    $objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg'), IMAGE_SIZE, true, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT);
207    $objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg'), IMAGE_SIZE, false, LARGE_IMAGE_HEIGHT, LARGE_IMAGE_HEIGHT);
208    for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
209        $objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_HEIGHT, NORMAL_SUBIMAGE_HEIGHT);   
210        $objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg'), IMAGE_SIZE, false, LARGE_SUBIMAGE_HEIGHT, LARGE_SUBIMAGE_HEIGHT);
211    }
212    $objUpFile->addFile("商品比較画像", 'file1', array('jpg'), IMAGE_SIZE, false, NORMAL_IMAGE_HEIGHT, NORMAL_IMAGE_HEIGHT);
213    $objUpFile->addFile("商品詳細ファイル", 'file2', array('pdf'), PDF_SIZE, false, 0, 0, false);
214}
215
216/* 規格選択セレクトボックスの作成 */
217function lfMakeSelect($objPage, $product_id) {
218    global $objPage;
219    $classcat_find1 = false;
220    $classcat_find2 = false;
221    // 在庫ありの商品の有無
222    $stock_find = false;
223   
224    // 規格名一覧
225    $arrClassName = sfGetIDValueList("dtb_class", "class_id", "name");
226    // 規格分類名一覧
227    $arrClassCatName = sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
228    // 商品規格情報の取得   
229    $arrProductsClass = lfGetProductsClass($product_id);
230   
231    // 規格1クラス名の取得
232    $objPage->tpl_class_name1 = $arrClassName[$arrProductsClass[0]['class_id1']];
233    // 規格2クラス名の取得
234    $objPage->tpl_class_name2 = $arrClassName[$arrProductsClass[0]['class_id2']];
235   
236    // すべての組み合わせ数   
237    $count = count($arrProductsClass);
238   
239    $classcat_id1 = "";
240   
241    $arrSele = array();
242    $arrList = array();
243   
244    $list_id = 0;
245    $arrList[0] = "\tlist0 = new Array('選択してください'";
246    $arrVal[0] = "\tval0 = new Array(''";
247   
248    for ($i = 0; $i < $count; $i++) {
249        // 在庫のチェック
250        if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
251            continue;
252        }
253       
254        $stock_find = true;
255       
256        // 規格1のセレクトボックス用
257        if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
258            $arrList[$list_id].=");\n";
259            $arrVal[$list_id].=");\n";
260            $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
261            $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
262            $list_id++;
263        }
264       
265        // 規格2のセレクトボックス用
266        $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
267       
268        // セレクトボックス表示値
269        if($arrList[$list_id] == "") {
270            $arrList[$list_id] = "\tlist".$list_id." = new Array('選択してください', '".$arrClassCatName[$classcat_id2]."'";
271        } else {
272            $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
273        }
274       
275        // セレクトボックスPOST値
276        if($arrVal[$list_id] == "") {
277            $arrVal[$list_id] = "\tval".$list_id." = new Array('', '".$classcat_id2."'";
278        } else {
279            $arrVal[$list_id].= ", '".$classcat_id2."'";
280        }
281    }   
282   
283    $arrList[$list_id].=");\n";
284    $arrVal[$list_id].=");\n";
285       
286    // 規格1
287    $objPage->arrClassCat1 = $arrSele;
288   
289    $lists = "\tlists = new Array(";
290    $no = 0;
291   
292    foreach($arrList as $val) {
293        $objPage->tpl_javascript.= $val;
294        if ($no != 0) {
295            $lists.= ",list".$no;
296        } else {
297            $lists.= "list".$no;
298        }
299        $no++;
300    }
301    $objPage->tpl_javascript.=$lists.");\n";
302   
303    $vals = "\tvals = new Array(";
304    $no = 0;
305   
306    foreach($arrVal as $val) {
307        $objPage->tpl_javascript.= $val;
308        if ($no != 0) {
309            $vals.= ",val".$no;
310        } else {
311            $vals.= "val".$no;
312        }
313        $no++;
314    }
315    $objPage->tpl_javascript.=$vals.");\n";
316   
317    // 選択されている規格2ID
318    $objPage->tpl_onload = "lnSetSelect('form1', 'classcategory_id1', 'classcategory_id2', '" . $_POST['classcategory_id2'] . "');";
319
320    // 規格1が設定されている
321    if($arrProductsClass[0]['classcategory_id1'] != '0') {
322        $classcat_find1 = true;
323    }
324   
325    // 規格2が設定されている
326    if($arrProductsClass[0]['classcategory_id2'] != '0') {
327        $classcat_find2 = true;
328    }
329       
330    $objPage->tpl_classcat_find1 = $classcat_find1;
331    $objPage->tpl_classcat_find2 = $classcat_find2;
332    $objPage->tpl_stock_find = $stock_find;
333       
334    return $objPage;
335}
336
337/* パラメータ情報の初期化 */
338function lfInitParam() {
339    global $objFormParam;
340
341    $objFormParam->addParam("規格1", "classcategory_id1", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
342    $objFormParam->addParam("規格2", "classcategory_id2", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
343    $objFormParam->addParam("個数", "quantity", INT_LEN, "n", array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
344}
345
346/* 商品規格情報の取得 */
347function lfGetProductsClass($product_id) {
348    $arrRet = array();
349    if(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/* 登録済みオススメ商品の読み込み */
362function lfPreGetRecommendProducts($product_id) {
363    $objQuery = new SC_Query();
364    $objQuery->setorder("rank DESC");
365    $arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id));
366    $max = count($arrRet);
367    $no = 0;
368    for($i = 0; $i < $max; $i++) {
369        $where = "del_flg = 0 AND product_id = ? AND status = 1";
370        $arrProductInfo = $objQuery->select("main_list_image, price02_min, price02_max, price01_min, price01_max, name, point_rate", "vw_products_allclass  AS allcls", $where, array($arrRet[$i]['recommend_product_id']));
371               
372        if(count($arrProductInfo) > 0) {
373            $arrRecommend[$no] = $arrProductInfo[0];
374            $arrRecommend[$no]['product_id'] = $arrRet[$i]['recommend_product_id'];
375            $arrRecommend[$no]['comment'] = $arrRet[$i]['comment'];
376            $no++;
377        }   
378    }
379    return $arrRecommend;
380}
381
382/* 入力内容のチェック */
383function lfCheckError() {
384    global $objFormParam;
385    global $objPage;
386    // 入力データを渡す。
387    $arrRet =  $objFormParam->getHashArray();
388    $objErr = new SC_CheckError($arrRet);
389    $objErr->arrErr = $objFormParam->checkError();
390       
391    // 複数項目チェック
392    if ($objPage->tpl_classcat_find1) {
393        $objErr->doFunc(array("規格1", "classcategory_id1"), array("EXIST_CHECK"));
394    }
395    if ($objPage->tpl_classcat_find2) {
396        $objErr->doFunc(array("規格2", "classcategory_id2"), array("EXIST_CHECK"));
397    }
398           
399    return $objErr->arrErr;
400}
401
402//閲覧履歴新規登録
403function lfRegistReadingData($tmp_id, $customer_id){
404    $objQuery = new SC_Query;
405    $sqlval['customer_id'] = $customer_id;
406    $sqlval['reading_product_id'] = $tmp_id;
407    $sqlval['create_date'] = 'NOW()';
408    $sqlval['update_date'] = 'NOW()';
409    $objQuery->insert("dtb_customer_reading", $sqlval);
410}
411
412//この商品を買った人はこんな商品も買っています
413function lfGetRelateProducts($tmp_id) {
414    $objQuery = new SC_Query;
415    //自動抽出
416    $objQuery->setorder("random()");
417    //表示件数の制限
418    $objQuery->setlimit(RELATED_PRODUCTS_MAX);
419    //検索条件
420    $col = "name, main_list_image, price01_min, price02_min, price01_max, price02_max, point_rate";
421    $from = "vw_products_allclass AS allcls ";
422    $where = "del_flg = 0 AND status = 1 AND (stock_max <> 0 OR stock_max IS NULL) AND product_id = ? ";
423    $arrval[] = $tmp_id;
424    //結果の取得
425    $arrProducts = $objQuery->select($col, $from, $where, $arrval);
426   
427    return $arrProducts;
428}
429
430//商品ごとのレビュー情報を取得する
431function lfGetReviewData($id) {
432    $objQuery = new SC_Query;
433    //商品ごとのレビュー情報を取得する
434    $col = "create_date, reviewer_url, reviewer_name, recommend_level, title, comment";
435    $from = "dtb_review";
436    $where = "del_flg = 0 AND status = 1 AND product_id = ? ORDER BY create_date DESC LIMIT " . REVIEW_REGIST_MAX;
437    $arrval[] = $id;
438    $arrReview = $objQuery->select($col, $from, $where, $arrval);
439    return $arrReview;
440}
441
442/*
443 * 商品ごとのトラックバック情報を取得する
444 *
445 * @param $product_id
446 * @return $arrTrackback
447 */
448function lfGetTrackbackData($product_id) {
449
450    $arrTrackback = array();
451
452    $objQuery = new SC_Query;
453    //商品ごとのトラックバック情報を取得する
454    $col = "blog_name, url, title, excerpt, title, create_date";
455    $from = "dtb_trackback";
456    $where = "del_flg = 0 AND status = 1 AND product_id = ? ORDER BY create_date DESC LIMIT " . TRACKBACK_VIEW_MAX;
457    $arrval[] = $product_id;
458    $arrTrackback = $objQuery->select($col, $from, $where, $arrval);
459    return $arrTrackback;
460}
461
462//支払方法の取得
463//payment_id    1:クレジット 2:ショッピングローン
464function lfGetPayment() {
465    $objQuery = new SC_Query;
466    $col = "payment_id, rule, payment_method";
467    $from = "dtb_payment";
468    $where = "del_flg = 0";
469    $order = "payment_id";
470    $objQuery->setorder($order);
471    $arrRet = $objQuery->select($col, $from, $where);
472    return $arrRet;
473}
474
475function lfConvertParam() {
476    global $objPage;
477   
478    $value = $objPage->arrForm['quantity']['value'];
479    $objPage->arrForm['quantity']['value'] = htmlspecialchars($value, ENT_QUOTES, CHAR_CODE);
480}
481?>
Note: See TracBrowser for help on using the repository browser.