source: branches/rel/html/mobile/products/list.php @ 12157

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