source: branches/beta/html/products/list.php @ 16338

Revision 16338, 13.6 KB checked in by adachi, 15 years ago (diff)

merged branches/feature-templates r16325-16337

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        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//ɽ¼¨·ï¿ô¤ÎÁªÂò
34if(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 = "";
49if($_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// ¡¦¸¡º÷¥â¡¼¥É¤Ç¤Ê¤¤¡£
65if(($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
101if($_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
138lfConvertParam();
139
140$objPage->category_id = $category_id;
141$objPage->arrSearch = $arrSearch;
142
143$objView = new SC_SiteView();
144$objView->assignObj($objPage);
145$objView->display(SITE_FRAME);
146//-----------------------------------------------------------------------------------------------------------------------------------
147/* ¥«¥Æ¥´¥êID¤¬¥ë¡¼¥È¤«¤É¤¦¤«¤ÎȽÄê */
148function lfIsRootCategory($category_id) {
149    $objQuery = new SC_Query();
150    $level = $objQuery->get("dtb_category", "level", "category_id = ?", array($category_id));
151    if($level == 1) {
152        return true;
153    }
154    return false;
155}
156
157/* ¾¦ÉÊ°ìÍ÷¤Îɽ¼¨ */
158function lfDispProductsList($category_id, $name, $disp_num, $orderby) {
159    global $objPage;
160    $objQuery = new SC_Query();
161    $objPage->tpl_pageno = $_POST['pageno'];
162
163    //ɽ¼¨·ï¿ô¤Ç¥Æ¥ó¥×¥ì¡¼¥È¤òÀÚ¤êÂؤ¨¤ë
164    $objPage->tpl_mainpage = HTML_PATH . "user_data/templates/list.tpl";        // ¥á¥¤¥ó¥Æ¥ó¥×¥ì¡¼¥È
165
166    //ɽ¼¨½ç½ø
167    switch($orderby) {
168    //²Á³Ê½ç
169    case 'price':
170        $order = "price02_min ASC";
171        break;
172    //¿·Ãå½ç
173    case 'date':
174        $order = "create_date DESC";
175        break;
176    default:
177        $order = "category_rank DESC, rank DESC";
178        break;
179    }
180
181    // ¾¦Éʸ¡º÷¾ò·ï¤ÎºîÀ®¡Ê̤ºï½ü¡¢É½¼¨¡Ë
182    $where = "del_flg = 0 AND status = 1 ";
183    // ¥«¥Æ¥´¥ê¤«¤é¤ÎWHEREʸ»úÎó¼èÆÀ
184    if ( $category_id ) {
185        list($tmp_where, $arrval) = sfGetCatWhere($category_id);
186        if($tmp_where != "") {
187            $where.= " AND $tmp_where";
188        }
189    }
190
191    // ¾¦ÉÊ̾¤òwhereʸ¤Ë
192    $name = ereg_replace(",", "", $name);
193    if ( strlen($name) > 0 ){
194        $where .= " AND ( name ILIKE ? OR comment3 ILIKE ?) ";
195        $ret = sfManualEscape($name);
196        $arrval[] = "%$ret%";
197        $arrval[] = "%$ret%";
198    }
199
200    // ¹Ô¿ô¤Î¼èÆÀ
201    $linemax = $objQuery->count("vw_products_allclass AS allcls", $where, $arrval);
202    $objPage->tpl_linemax = $linemax;   // ²¿·ï¤¬³ºÅö¤·¤Þ¤·¤¿¡£É½¼¨ÍÑ
203
204    // ¥Ú¡¼¥¸Á÷¤ê¤Î¼èÆÀ
205    $objNavi = new SC_PageNavi($_POST['pageno'], $linemax, $disp_num, "fnNaviPage", NAVI_PMAX);
206
207    $strnavi = $objNavi->strnavi;
208    $strnavi = str_replace('onclick="fnNaviPage', 'onclick="form1.mode.value=\''.'\'; fnNaviPage', $strnavi);
209    $objPage->tpl_strnavi = $strnavi;       // ɽ¼¨Ê¸»úÎó
210    $startno = $objNavi->start_row;                 // ³«»Ï¹Ô
211
212    // ¼èÆÀÈϰϤλØÄê(³«»Ï¹ÔÈֹ桢¹Ô¿ô¤Î¥»¥Ã¥È)
213    $objQuery->setlimitoffset($disp_num, $startno);
214    // ɽ¼¨½ç½ø
215    $objQuery->setorder($order);
216
217
218
219
220
221
222
223
224    // ¸¡º÷·ë²Ì¤Î¼èÆÀ
225    $objPage->arrProducts = $objQuery->select("*", "vw_products_allclass AS allcls", $where, $arrval);
226
227    // µ¬³Ê̾°ìÍ÷
228    $arrClassName = sfGetIDValueList("dtb_class", "class_id", "name");
229    // µ¬³ÊʬÎà̾°ìÍ÷
230    $arrClassCatName = sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
231    // ´ë²è¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹ÀßÄê
232    if($disp_num == 15) {
233        for($i = 0; $i < count($objPage->arrProducts); $i++) {
234            $objPage = lfMakeSelect($objPage->arrProducts[$i]['product_id'], $arrClassName, $arrClassCatName);
235            // ¹ØÆþÀ©¸Â¿ô¤ò¼èÆÀ
236            $objPage = lfGetSaleLimit($objPage->arrProducts[$i]);
237        }
238    }
239
240    return $objPage;
241}
242
243/* µ¬³Ê¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹¤ÎºîÀ® */
244function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) {
245    global $objPage;
246
247    $classcat_find1 = false;
248    $classcat_find2 = false;
249    // ºß¸Ë¤¢¤ê¤Î¾¦ÉʤÎ̵ͭ
250    $stock_find = false;
251
252    // ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ
253    $arrProductsClass = lfGetProductsClass($product_id);
254
255    // µ¬³Ê1¥¯¥é¥¹Ì¾¤Î¼èÆÀ
256    $objPage->tpl_class_name1[$product_id] = $arrClassName[$arrProductsClass[0]['class_id1']];
257    // µ¬³Ê2¥¯¥é¥¹Ì¾¤Î¼èÆÀ
258    $objPage->tpl_class_name2[$product_id] = $arrClassName[$arrProductsClass[0]['class_id2']];
259
260    // ¤¹¤Ù¤Æ¤ÎÁȤ߹ç¤ï¤»¿ô
261    $count = count($arrProductsClass);
262
263    $classcat_id1 = "";
264
265    $arrSele = array();
266    $arrList = array();
267
268    $list_id = 0;
269    $arrList[0] = "\tlist". $product_id. "_0 = new Array('ÁªÂò¤·¤Æ¤¯¤À¤µ¤¤'";
270    $arrVal[0] = "\tval". $product_id. "_0 = new Array(''";
271
272    for ($i = 0; $i < $count; $i++) {
273        // ºß¸Ë¤Î¥Á¥§¥Ã¥¯
274        if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
275            continue;
276        }
277
278        $stock_find = true;
279
280        // µ¬³Ê1¤Î¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹ÍÑ
281        if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
282            $arrList[$list_id].=");\n";
283            $arrVal[$list_id].=");\n";
284            $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
285            $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
286            $list_id++;
287        }
288
289        // µ¬³Ê2¤Î¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹ÍÑ
290        $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
291
292        // ¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹É½¼¨ÃÍ
293        if($arrList[$list_id] == "") {
294            $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('ÁªÂò¤·¤Æ¤¯¤À¤µ¤¤', '". $arrClassCatName[$classcat_id2]. "'";
295        } else {
296            $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
297        }
298
299        // ¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹POSTÃÍ
300        if($arrVal[$list_id] == "") {
301            $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'";
302        } else {
303            $arrVal[$list_id].= ", '".$classcat_id2."'";
304        }
305    }
306
307    $arrList[$list_id].=");\n";
308    $arrVal[$list_id].=");\n";
309
310    // µ¬³Ê1
311    $objPage->arrClassCat1[$product_id] = $arrSele;
312
313    $lists = "\tlists".$product_id. " = new Array(";
314    $no = 0;
315    foreach($arrList as $val) {
316        $objPage->tpl_javascript.= $val;
317        if ($no != 0) {
318            $lists.= ",list". $product_id. "_". $no;
319        } else {
320            $lists.= "list". $product_id. "_". $no;
321        }
322        $no++;
323    }
324    $objPage->tpl_javascript.= $lists.");\n";
325
326    $vals = "\tvals".$product_id. " = new Array(";
327    $no = 0;
328    foreach($arrVal as $val) {
329        $objPage->tpl_javascript.= $val;
330        if ($no != 0) {
331            $vals.= ",val". $product_id. "_". $no;
332        } else {
333            $vals.= "val". $product_id. "_". $no;
334        }
335        $no++;
336    }
337    $objPage->tpl_javascript.= $vals.");\n";
338
339    // ÁªÂò¤µ¤ì¤Æ¤¤¤ëµ¬³Ê2ID
340    $classcategory_id = "classcategory_id". $product_id;
341    $objPage->tpl_onload .= "lnSetSelect('".$classcategory_id."_1','".$classcategory_id."_2','".$product_id."','".$_POST[$classcategory_id."_2"]."'); ";
342
343    // µ¬³Ê1¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë
344    if($arrProductsClass[0]['classcategory_id1'] != '0') {
345        $classcat_find1 = true;
346    }
347
348    // µ¬³Ê2¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë
349    if($arrProductsClass[0]['classcategory_id2'] != '0') {
350        $classcat_find2 = true;
351    }
352
353    $objPage->tpl_classcat_find1[$product_id] = $classcat_find1;
354    $objPage->tpl_classcat_find2[$product_id] = $classcat_find2;
355    $objPage->tpl_stock_find[$product_id] = $stock_find;
356
357    return $objPage;
358}
359/* ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ */
360function lfGetProductsClass($product_id) {
361    $arrRet = array();
362    if(sfIsInt($product_id)) {
363        // ¾¦Éʵ¬³Ê¼èÆÀ
364        $objQuery = new SC_Query();
365        $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited";
366        $table = "vw_product_class AS prdcls";
367        $where = "product_id = ?";
368        $objQuery->setorder("rank1 DESC, rank2 DESC");
369        $arrRet = $objQuery->select($col, $table, $where, array($product_id));
370    }
371    return $arrRet;
372}
373
374/* ÆþÎÏÆâÍƤΥÁ¥§¥Ã¥¯ */
375function lfCheckError($id) {
376    global $objPage;
377
378    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
379    $objErr = new SC_CheckError();
380
381    $classcategory_id1 = "classcategory_id". $id. "_1";
382    $classcategory_id2 = "classcategory_id". $id. "_2";
383    $quantity = "quantity". $id;
384    // Ê£¿ô¹àÌÜ¥Á¥§¥Ã¥¯
385    if ($objPage->tpl_classcat_find1[$id]) {
386        $objErr->doFunc(array("µ¬³Ê1", $classcategory_id1, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
387    }
388    if ($objPage->tpl_classcat_find2[$id]) {
389        $objErr->doFunc(array("µ¬³Ê2", $classcategory_id2, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
390    }
391    $objErr->doFunc(array("¸Ä¿ô", $quantity, INT_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
392
393    return $objErr->arrErr;
394}
395
396// ¹ØÆþÀ©¸Â¿ô¤ÎÀßÄê
397function lfGetSaleLimit($product) {
398    global $objPage;
399    //ºß¸Ë¤¬Ìµ¸Â¤Þ¤¿¤Ï¹ØÆþÀ©¸ÂÃͤ¬ÀßÄêÃͤè¤êÂ礭¤¤¾ì¹ç
400    if($product['sale_unlimited'] == 1 || $product['sale_limit'] > SALE_LIMIT_MAX) {
401        $objPage->tpl_sale_limit[$product['product_id']] = SALE_LIMIT_MAX;
402    } else {
403        $objPage->tpl_sale_limit[$product['product_id']] = $product['sale_limit'];
404    }
405
406    return $objPage;
407}
408
409//»ÙʧÊýË¡¤Î¼èÆÀ
410//payment_id    1:Âå¶â°ú´¹¡¡2:¶ä¹Ô¿¶¤ê¹þ¤ß¡¡3:¸½¶â½ñα
411function lfGetPayment() {
412    $objQuery = new SC_Query;
413    $col = "payment_id, rule, payment_method";
414    $from = "dtb_payment";
415    $where = "del_flg = 0";
416    $order = "payment_id";
417    $objQuery->setorder($order);
418    $arrRet = $objQuery->select($col, $from, $where);
419    return $arrRet;
420}
421
422function lfconvertParam () {
423    global $objPage;
424
425    foreach ($objPage->arrForm as $key => $value) {
426        if (preg_match('/^quantity[0-9]+/', $key)) {
427             $objPage->arrForm[$key]
428                = htmlspecialchars($objPage->arrForm[$key], ENT_QUOTES, CHAR_CODE);
429        }
430    }
431}
432?>
Note: See TracBrowser for help on using the repository browser.