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

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

merged branches/feature-templates r16325-16337

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