source: branches/comu/html/products/list.php @ 11983

Revision 11983, 12.0 KB checked in by uehara, 17 years ago (diff)
RevLine 
[5]1<?php
2/*
[15]3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
[5]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        /*
[11730]22         session_start»þ¤Îno-cache¥Ø¥Ã¥À¡¼¤òÍÞÀ©¤¹¤ë¤³¤È¤Ç
23         ¡ÖÌá¤ë¡×¥Ü¥¿¥ó»ÈÍÑ»þ¤ÎÍ­¸ú´ü¸ÂÀÚ¤ìɽ¼¨¤òÍÞÀ©¤¹¤ë¡£
24         private-no-expire:¥¯¥é¥¤¥¢¥ó¥È¤Î¥­¥ã¥Ã¥·¥å¤òµö²Ä¤¹¤ë¡£
[5]25        */
26        session_cache_limiter('private-no-expire');
27    }
28}
29
30$objPage = new LC_Page();
31$conn = new SC_DBConn();
32
[11730]33//ɽ¼¨·ï¿ô¤ÎÁªÂò
[5]34if(sfIsInt($_POST['disp_number'])) {
35    $objPage->disp_number = $_POST['disp_number'];
36} else {
[11730]37    //ºÇ¾®É½¼¨·ï¿ô¤òÁªÂò
[5]38    $objPage->disp_number = current(array_keys($arrPRODUCTLISTMAX));
39}
40
[11730]41//ɽ¼¨½ç½ø¤ÎÊݸ
[5]42$objPage->orderby = $_POST['orderby'];
43
[11730]44// GET¤Î¥«¥Æ¥´¥êID¤ò¸µ¤ËÀµ¤·¤¤¥«¥Æ¥´¥êID¤ò¼èÆÀ¤¹¤ë¡£
[5]45$category_id = sfGetCategoryId("", $_GET['category_id']);
46
[11730]47// ¥¿¥¤¥È¥ëÊÔ½¸
[5]48$tpl_subtitle = "";
49if($_GET['mode'] == 'search'){
[11730]50    $tpl_subtitle = "¸¡º÷·ë²Ì";
[5]51}elseif ($category_id == "" ) {
[11730]52    $tpl_subtitle = "Á´¾¦ÉÊ";
[5]53}else{
[11983]54    $arrFirstCat = sfGetFirstCat($category_id);
[5]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
[11730]61// °Ê²¼¤Î¾ò·ï¤ÇBEST¾¦Éʤòɽ¼¨¤¹¤ë
62// ¡¦BESTºÇÂç¿ô¤Î¾¦Éʤ¬ÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë¡£
63// ¡¦¥«¥Æ¥´¥êID¤¬¥ë¡¼¥ÈID¤Ç¤¢¤ë¡£
64// ¡¦¸¡º÷¥â¡¼¥É¤Ç¤Ê¤¤¡£
[5]65if(($count >= BEST_MIN) && lfIsRootCategory($category_id) && ($_GET['mode'] != 'search') ) {
[11730]66    // ¾¦ÉÊTOP¤Îɽ¼¨½èÍý
67    /** ɬ¤º»ØÄꤹ¤ë **/
68    $objPage->tpl_mainpage = HTML_PATH . "user_data/templates/list.tpl";        // ¥á¥¤¥ó¥Æ¥ó¥×¥ì¡¼¥È   
[5]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 ){
[11730]74        // ¸¡º÷»þ¤Ëcategory_id¤¬GET¤Ë¸ºß¤·¤Ê¤¤¾ì¹ç¤Ï¡¢²¾¤ËËä¤á¤¿ID¤ò¶õÇò¤ËÌ᤹
[5]75        $category_id = ''; 
76    }
77   
[11730]78    // ¾¦ÉÊ°ìÍ÷¤Îɽ¼¨½èÍý
[5]79    $objPage = lfDispProductsList($category_id, $_GET['name'], $objPage->disp_number, $_POST['orderby']);
80   
[11730]81    // ¸¡º÷¾ò·ï¤ò²èÌ̤Ëɽ¼¨
82    // ¥«¥Æ¥´¥ê¡¼¸¡º÷¾ò·ï
[5]83    if (strlen($_GET['category_id']) == 0) {
[11730]84        $arrSearch['category'] = "»ØÄê¤Ê¤·";
[5]85    }else{
86        $arrCat = $conn->getOne("SELECT category_name FROM dtb_category WHERE category_id = ?",array($category_id));
87        $arrSearch['category'] = $arrCat;
88    }
89   
[11730]90    // ¾¦ÉÊ̾¸¡º÷¾ò·ï
[5]91    if ($_GET['name'] === "") {
[11730]92        $arrSearch['name'] = "»ØÄê¤Ê¤·";
[5]93    }else{
94        $arrSearch['name'] = $_GET['name'];
95    }
96}
97
[11730]98// ¥ì¥¤¥¢¥¦¥È¥Ç¥¶¥¤¥ó¤ò¼èÆÀ
[5]99$objPage = sfGetPageLayout($objPage, false, "products/list.php");
100
101if($_POST['mode'] == "cart" && $_POST['product_id'] != "") {
[11730]102    // ÃͤÎÀµÅöÀ­¥Á¥§¥Ã¥¯
[5]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 {
[11730]106        // ÆþÎÏÃͤÎÊÑ´¹
[5]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'];
[11730]114            // µ¬³Ê1¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç
[5]115            if(!$objPage->tpl_classcat_find1[$_POST['product_id']]) {
116                $classcategory_id1 = '0';
117            }
[11730]118            // µ¬³Ê2¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç
[5]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
[11730]133// »ÙʧÊýË¡¤Î¼èÆÀ
[5]134$objPage->arrPayment = lfGetPayment();
[11730]135// ÆþÎϾðÊó¤òÅϤ¹
[5]136$objPage->arrForm = $_POST;
137
138$objPage->category_id = $category_id;
139$objPage->arrSearch = $arrSearch;
140
141sfCustomDisplay($objPage);
142
143//-----------------------------------------------------------------------------------------------------------------------------------
[11730]144/* ¥«¥Æ¥´¥êID¤¬¥ë¡¼¥È¤«¤É¤¦¤«¤ÎȽÄê */
[5]145function lfIsRootCategory($category_id) {
146    $objQuery = new SC_Query();
147    $level = $objQuery->get("dtb_category", "level", "category_id = ?", array($category_id));
148    if($level == 1) {
149        return true;
150    }
151    return false;
152}
153
[11730]154/* ¾¦ÉÊ°ìÍ÷¤Îɽ¼¨ */
[5]155function lfDispProductsList($category_id, $name, $disp_num, $orderby) {
156    global $objPage;
157    $objQuery = new SC_Query();
158    $objPage->tpl_pageno = $_POST['pageno'];
159
[11730]160    //ɽ¼¨·ï¿ô¤Ç¥Æ¥ó¥×¥ì¡¼¥È¤òÀÚ¤êÂؤ¨¤ë
161    $objPage->tpl_mainpage = HTML_PATH . "user_data/templates/list.tpl";        // ¥á¥¤¥ó¥Æ¥ó¥×¥ì¡¼¥È       
[5]162
[11730]163    //ɽ¼¨½ç½ø
[5]164    switch($orderby) {
[11730]165    //²Á³Ê½ç
[5]166    case 'price':
167        $order = "price02_min ASC";
168        break;
[11730]169    //¿·Ãå½ç
[5]170    case 'date':
171        $order = "create_date DESC";
172        break;
173    default:
174        $order = "category_rank DESC, rank DESC";
175        break;
176    }
177   
[11730]178    // ¾¦Éʸ¡º÷¾ò·ï¤ÎºîÀ®¡Ê̤ºï½ü¡¢É½¼¨¡Ë
[5]179    $where = "del_flg = 0 AND status = 1 ";
[11730]180    // ¥«¥Æ¥´¥ê¤«¤é¤ÎWHEREʸ»úÎó¼èÆÀ
[5]181    if ( $category_id ) {
182        list($tmp_where, $arrval) = sfGetCatWhere($category_id);
183        if($tmp_where != "") {
184            $where.= " AND $tmp_where";
185        }
186    }
187       
[11730]188    // ¾¦ÉÊ̾¤òwhereʸ¤Ë
[5]189    $name = ereg_replace(",", "", $name);
190    if ( strlen($name) > 0 ){
191        $where .= " AND ( name ILIKE ? OR comment3 ILIKE ?) ";
192        $ret = sfManualEscape($name);       
193        $arrval[] = "%$ret%";
194        $arrval[] = "%$ret%";
195    }
196           
[11730]197    // ¹Ô¿ô¤Î¼èÆÀ
[5]198    $linemax = $objQuery->count("vw_products_allclass AS allcls", $where, $arrval);
[11730]199    $objPage->tpl_linemax = $linemax;   // ²¿·ï¤¬³ºÅö¤·¤Þ¤·¤¿¡£É½¼¨ÍÑ
[5]200   
[11730]201    // ¥Ú¡¼¥¸Á÷¤ê¤Î¼èÆÀ
[5]202    $objNavi = new SC_PageNavi($_POST['pageno'], $linemax, $disp_num, "fnNaviPage", NAVI_PMAX);
203   
204    $strnavi = $objNavi->strnavi;
205    $strnavi = str_replace('onclick="fnNaviPage', 'onclick="form1.mode.value=\''.'\'; fnNaviPage', $strnavi);
[11730]206    $objPage->tpl_strnavi = $strnavi;       // ɽ¼¨Ê¸»úÎó
207    $startno = $objNavi->start_row;                 // ³«»Ï¹Ô
[5]208   
[11730]209    // ¼èÆÀÈϰϤλØÄê(³«»Ï¹ÔÈֹ桢¹Ô¿ô¤Î¥»¥Ã¥È)
[5]210    $objQuery->setlimitoffset($disp_num, $startno);
[11730]211    // ɽ¼¨½ç½ø
[5]212    $objQuery->setorder($order);
213   
214   
215   
216   
217   
218   
219   
220   
[11730]221    // ¸¡º÷·ë²Ì¤Î¼èÆÀ
[5]222    $objPage->arrProducts = $objQuery->select("*", "vw_products_allclass AS allcls", $where, $arrval);
223   
[11730]224    // µ¬³Ê̾°ìÍ÷
[5]225    $arrClassName = sfGetIDValueList("dtb_class", "class_id", "name");
[11730]226    // µ¬³ÊʬÎà̾°ìÍ÷
[5]227    $arrClassCatName = sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
[11730]228    // ´ë²è¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹ÀßÄê
[5]229    if($disp_num == 15) {
230        for($i = 0; $i < count($objPage->arrProducts); $i++) {
231            $objPage = lfMakeSelect($objPage->arrProducts[$i]['product_id'], $arrClassName, $arrClassCatName);
[11730]232            // ¹ØÆþÀ©¸Â¿ô¤ò¼èÆÀ
[5]233            $objPage = lfGetSaleLimit($objPage->arrProducts[$i]);
234        }
235    }
236
237    return $objPage;
238}
239
[11730]240/* µ¬³Ê¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹¤ÎºîÀ® */
[5]241function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) {
242    global $objPage;
243   
244    $classcat_find1 = false;
245    $classcat_find2 = false;
[11730]246    // ºß¸Ë¤¢¤ê¤Î¾¦ÉʤÎ̵ͭ
[5]247    $stock_find = false;
248   
[11730]249    // ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ   
[5]250    $arrProductsClass = lfGetProductsClass($product_id);
251   
[11730]252    // µ¬³Ê1¥¯¥é¥¹Ì¾¤Î¼èÆÀ
[5]253    $objPage->tpl_class_name1[$product_id] = $arrClassName[$arrProductsClass[0]['class_id1']];
[11730]254    // µ¬³Ê2¥¯¥é¥¹Ì¾¤Î¼èÆÀ
[5]255    $objPage->tpl_class_name2[$product_id] = $arrClassName[$arrProductsClass[0]['class_id2']];
256   
[11730]257    // ¤¹¤Ù¤Æ¤ÎÁȤ߹ç¤ï¤»¿ô
[5]258    $count = count($arrProductsClass);
259   
260    $classcat_id1 = "";
261   
262    $arrSele = array();
263    $arrList = array();
264   
265    $list_id = 0;
[11730]266    $arrList[0] = "\tlist". $product_id. "_0 = new Array('ÁªÂò¤·¤Æ¤¯¤À¤µ¤¤'";
[5]267    $arrVal[0] = "\tval". $product_id. "_0 = new Array(''";
268   
269    for ($i = 0; $i < $count; $i++) {
[11730]270        // ºß¸Ë¤Î¥Á¥§¥Ã¥¯
[5]271        if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
272            continue;
273        }
274       
275        $stock_find = true;
276       
[11730]277        // µ¬³Ê1¤Î¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹ÍÑ
[5]278        if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
279            $arrList[$list_id].=");\n";
280            $arrVal[$list_id].=");\n";
281            $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
282            $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
283            $list_id++;
284        }
285       
[11730]286        // µ¬³Ê2¤Î¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹ÍÑ
[5]287        $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
288       
[11730]289        // ¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹É½¼¨ÃÍ
[5]290        if($arrList[$list_id] == "") {
[11730]291            $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('ÁªÂò¤·¤Æ¤¯¤À¤µ¤¤', '". $arrClassCatName[$classcat_id2]. "'";
[5]292        } else {
293            $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
294        }
295       
[11730]296        // ¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹POSTÃÍ
[5]297        if($arrVal[$list_id] == "") {
298            $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'";
299        } else {
300            $arrVal[$list_id].= ", '".$classcat_id2."'";
301        }
302    }   
303   
304    $arrList[$list_id].=");\n";
305    $arrVal[$list_id].=");\n";
306       
[11730]307    // µ¬³Ê1
[5]308    $objPage->arrClassCat1[$product_id] = $arrSele;
309   
310    $lists = "\tlists".$product_id. " = new Array(";
311    $no = 0;
312    foreach($arrList as $val) {
313        $objPage->tpl_javascript.= $val;
314        if ($no != 0) {
315            $lists.= ",list". $product_id. "_". $no;
316        } else {
317            $lists.= "list". $product_id. "_". $no;
318        }
319        $no++;
320    }
321    $objPage->tpl_javascript.= $lists.");\n";
322   
323    $vals = "\tvals".$product_id. " = new Array(";
324    $no = 0;
325    foreach($arrVal as $val) {
326        $objPage->tpl_javascript.= $val;
327        if ($no != 0) {
328            $vals.= ",val". $product_id. "_". $no;
329        } else {
330            $vals.= "val". $product_id. "_". $no;
331        }
332        $no++;
333    }
334    $objPage->tpl_javascript.= $vals.");\n";
335   
[11730]336    // ÁªÂò¤µ¤ì¤Æ¤¤¤ëµ¬³Ê2ID
[5]337    $classcategory_id = "classcategory_id". $product_id;
338    $objPage->tpl_onload .= "lnSetSelect('".$classcategory_id."_1','".$classcategory_id."_2','".$product_id."','".$_POST[$classcategory_id."_2"]."'); ";
339
[11730]340    // µ¬³Ê1¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë
[5]341    if($arrProductsClass[0]['classcategory_id1'] != '0') {
342        $classcat_find1 = true;
343    }
344   
[11730]345    // µ¬³Ê2¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë
[5]346    if($arrProductsClass[0]['classcategory_id2'] != '0') {
347        $classcat_find2 = true;
348    }
349       
350    $objPage->tpl_classcat_find1[$product_id] = $classcat_find1;
351    $objPage->tpl_classcat_find2[$product_id] = $classcat_find2;
352    $objPage->tpl_stock_find[$product_id] = $stock_find;
353       
354    return $objPage;
355}
[11730]356/* ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ */
[5]357function lfGetProductsClass($product_id) {
358    $arrRet = array();
359    if(sfIsInt($product_id)) {
[11730]360        // ¾¦Éʵ¬³Ê¼èÆÀ
[5]361        $objQuery = new SC_Query();
362        $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited";
363        $table = "vw_product_class AS prdcls";
364        $where = "product_id = ?";
365        $objQuery->setorder("rank1 DESC, rank2 DESC");
366        $arrRet = $objQuery->select($col, $table, $where, array($product_id));
367    }
368    return $arrRet;
369}
370
[11730]371/* ÆþÎÏÆâÍƤΥÁ¥§¥Ã¥¯ */
[5]372function lfCheckError($id) {
373    global $objPage;
374   
[11730]375    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
[5]376    $objErr = new SC_CheckError();
377   
378    $classcategory_id1 = "classcategory_id". $id. "_1";
379    $classcategory_id2 = "classcategory_id". $id. "_2";
380    $quantity = "quantity". $id;
[11730]381    // Ê£¿ô¹àÌÜ¥Á¥§¥Ã¥¯
[5]382    if ($objPage->tpl_classcat_find1[$id]) {
[11730]383        $objErr->doFunc(array("µ¬³Ê1", $classcategory_id1, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
[5]384    }
385    if ($objPage->tpl_classcat_find2[$id]) {
[11730]386        $objErr->doFunc(array("µ¬³Ê2", $classcategory_id2, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
[5]387    }
[11730]388    $objErr->doFunc(array("¸Ä¿ô", $quantity, INT_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
[5]389           
390    return $objErr->arrErr;
391}
392
[11730]393// ¹ØÆþÀ©¸Â¿ô¤ÎÀßÄê
[5]394function lfGetSaleLimit($product) {
395    global $objPage;
[11730]396    //ºß¸Ë¤¬Ìµ¸Â¤Þ¤¿¤Ï¹ØÆþÀ©¸ÂÃͤ¬ÀßÄêÃͤè¤êÂ礭¤¤¾ì¹ç
[5]397    if($product['sale_unlimited'] == 1 || $product['sale_limit'] > SALE_LIMIT_MAX) {
398        $objPage->tpl_sale_limit[$product['product_id']] = SALE_LIMIT_MAX;
399    } else {
400        $objPage->tpl_sale_limit[$product['product_id']] = $product['sale_limit'];
401    }
402   
403    return $objPage;
404}
405
[11730]406//»ÙʧÊýË¡¤Î¼èÆÀ
407//payment_id    1:Âå¶â°ú´¹¡¡2:¶ä¹Ô¿¶¤ê¹þ¤ß¡¡3:¸½¶â½ñα
[5]408function lfGetPayment() {
409    $objQuery = new SC_Query;
410    $col = "payment_id, rule, payment_method";
411    $from = "dtb_payment";
412    $where = "del_flg = 0";
413    $order = "payment_id";
414    $objQuery->setorder($order);
415    $arrRet = $objQuery->select($col, $from, $where);
416    return $arrRet;
417}
418
419?>
Note: See TracBrowser for help on using the repository browser.