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

Revision 11983, 12.0 KB checked in by uehara, 17 years ago (diff)
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
138$objPage->category_id = $category_id;
139$objPage->arrSearch = $arrSearch;
140
141sfCustomDisplay($objPage);
142
143//-----------------------------------------------------------------------------------------------------------------------------------
144/* ¥«¥Æ¥´¥êID¤¬¥ë¡¼¥È¤«¤É¤¦¤«¤ÎȽÄê */
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
154/* ¾¦ÉÊ°ìÍ÷¤Îɽ¼¨ */
155function lfDispProductsList($category_id, $name, $disp_num, $orderby) {
156    global $objPage;
157    $objQuery = new SC_Query();
158    $objPage->tpl_pageno = $_POST['pageno'];
159
160    //ɽ¼¨·ï¿ô¤Ç¥Æ¥ó¥×¥ì¡¼¥È¤òÀÚ¤êÂؤ¨¤ë
161    $objPage->tpl_mainpage = HTML_PATH . "user_data/templates/list.tpl";        // ¥á¥¤¥ó¥Æ¥ó¥×¥ì¡¼¥È       
162
163    //ɽ¼¨½ç½ø
164    switch($orderby) {
165    //²Á³Ê½ç
166    case 'price':
167        $order = "price02_min ASC";
168        break;
169    //¿·Ãå½ç
170    case 'date':
171        $order = "create_date DESC";
172        break;
173    default:
174        $order = "category_rank DESC, rank DESC";
175        break;
176    }
177   
178    // ¾¦Éʸ¡º÷¾ò·ï¤ÎºîÀ®¡Ê̤ºï½ü¡¢É½¼¨¡Ë
179    $where = "del_flg = 0 AND status = 1 ";
180    // ¥«¥Æ¥´¥ê¤«¤é¤ÎWHEREʸ»úÎó¼èÆÀ
181    if ( $category_id ) {
182        list($tmp_where, $arrval) = sfGetCatWhere($category_id);
183        if($tmp_where != "") {
184            $where.= " AND $tmp_where";
185        }
186    }
187       
188    // ¾¦ÉÊ̾¤òwhereʸ¤Ë
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           
197    // ¹Ô¿ô¤Î¼èÆÀ
198    $linemax = $objQuery->count("vw_products_allclass AS allcls", $where, $arrval);
199    $objPage->tpl_linemax = $linemax;   // ²¿·ï¤¬³ºÅö¤·¤Þ¤·¤¿¡£É½¼¨ÍÑ
200   
201    // ¥Ú¡¼¥¸Á÷¤ê¤Î¼èÆÀ
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);
206    $objPage->tpl_strnavi = $strnavi;       // ɽ¼¨Ê¸»úÎó
207    $startno = $objNavi->start_row;                 // ³«»Ï¹Ô
208   
209    // ¼èÆÀÈϰϤλØÄê(³«»Ï¹ÔÈֹ桢¹Ô¿ô¤Î¥»¥Ã¥È)
210    $objQuery->setlimitoffset($disp_num, $startno);
211    // ɽ¼¨½ç½ø
212    $objQuery->setorder($order);
213   
214   
215   
216   
217   
218   
219   
220   
221    // ¸¡º÷·ë²Ì¤Î¼èÆÀ
222    $objPage->arrProducts = $objQuery->select("*", "vw_products_allclass AS allcls", $where, $arrval);
223   
224    // µ¬³Ê̾°ìÍ÷
225    $arrClassName = sfGetIDValueList("dtb_class", "class_id", "name");
226    // µ¬³ÊʬÎà̾°ìÍ÷
227    $arrClassCatName = sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
228    // ´ë²è¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹ÀßÄê
229    if($disp_num == 15) {
230        for($i = 0; $i < count($objPage->arrProducts); $i++) {
231            $objPage = lfMakeSelect($objPage->arrProducts[$i]['product_id'], $arrClassName, $arrClassCatName);
232            // ¹ØÆþÀ©¸Â¿ô¤ò¼èÆÀ
233            $objPage = lfGetSaleLimit($objPage->arrProducts[$i]);
234        }
235    }
236
237    return $objPage;
238}
239
240/* µ¬³Ê¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹¤ÎºîÀ® */
241function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) {
242    global $objPage;
243   
244    $classcat_find1 = false;
245    $classcat_find2 = false;
246    // ºß¸Ë¤¢¤ê¤Î¾¦ÉʤÎ̵ͭ
247    $stock_find = false;
248   
249    // ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ   
250    $arrProductsClass = lfGetProductsClass($product_id);
251   
252    // µ¬³Ê1¥¯¥é¥¹Ì¾¤Î¼èÆÀ
253    $objPage->tpl_class_name1[$product_id] = $arrClassName[$arrProductsClass[0]['class_id1']];
254    // µ¬³Ê2¥¯¥é¥¹Ì¾¤Î¼èÆÀ
255    $objPage->tpl_class_name2[$product_id] = $arrClassName[$arrProductsClass[0]['class_id2']];
256   
257    // ¤¹¤Ù¤Æ¤ÎÁȤ߹ç¤ï¤»¿ô
258    $count = count($arrProductsClass);
259   
260    $classcat_id1 = "";
261   
262    $arrSele = array();
263    $arrList = array();
264   
265    $list_id = 0;
266    $arrList[0] = "\tlist". $product_id. "_0 = new Array('ÁªÂò¤·¤Æ¤¯¤À¤µ¤¤'";
267    $arrVal[0] = "\tval". $product_id. "_0 = new Array(''";
268   
269    for ($i = 0; $i < $count; $i++) {
270        // ºß¸Ë¤Î¥Á¥§¥Ã¥¯
271        if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
272            continue;
273        }
274       
275        $stock_find = true;
276       
277        // µ¬³Ê1¤Î¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹ÍÑ
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       
286        // µ¬³Ê2¤Î¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹ÍÑ
287        $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
288       
289        // ¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹É½¼¨ÃÍ
290        if($arrList[$list_id] == "") {
291            $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('ÁªÂò¤·¤Æ¤¯¤À¤µ¤¤', '". $arrClassCatName[$classcat_id2]. "'";
292        } else {
293            $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
294        }
295       
296        // ¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹POSTÃÍ
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       
307    // µ¬³Ê1
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   
336    // ÁªÂò¤µ¤ì¤Æ¤¤¤ëµ¬³Ê2ID
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
340    // µ¬³Ê1¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë
341    if($arrProductsClass[0]['classcategory_id1'] != '0') {
342        $classcat_find1 = true;
343    }
344   
345    // µ¬³Ê2¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë
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}
356/* ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ */
357function lfGetProductsClass($product_id) {
358    $arrRet = array();
359    if(sfIsInt($product_id)) {
360        // ¾¦Éʵ¬³Ê¼èÆÀ
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
371/* ÆþÎÏÆâÍƤΥÁ¥§¥Ã¥¯ */
372function lfCheckError($id) {
373    global $objPage;
374   
375    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
376    $objErr = new SC_CheckError();
377   
378    $classcategory_id1 = "classcategory_id". $id. "_1";
379    $classcategory_id2 = "classcategory_id". $id. "_2";
380    $quantity = "quantity". $id;
381    // Ê£¿ô¹àÌÜ¥Á¥§¥Ã¥¯
382    if ($objPage->tpl_classcat_find1[$id]) {
383        $objErr->doFunc(array("µ¬³Ê1", $classcategory_id1, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
384    }
385    if ($objPage->tpl_classcat_find2[$id]) {
386        $objErr->doFunc(array("µ¬³Ê2", $classcategory_id2, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
387    }
388    $objErr->doFunc(array("¸Ä¿ô", $quantity, INT_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
389           
390    return $objErr->arrErr;
391}
392
393// ¹ØÆþÀ©¸Â¿ô¤ÎÀßÄê
394function lfGetSaleLimit($product) {
395    global $objPage;
396    //ºß¸Ë¤¬Ìµ¸Â¤Þ¤¿¤Ï¹ØÆþÀ©¸ÂÃͤ¬ÀßÄêÃͤè¤êÂ礭¤¤¾ì¹ç
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
406//»ÙʧÊýË¡¤Î¼èÆÀ
407//payment_id    1:Âå¶â°ú´¹¡¡2:¶ä¹Ô¿¶¤ê¹þ¤ß¡¡3:¸½¶â½ñα
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.