source: branches/mobile/html/mobile/products/list.php @ 11635

Revision 11635, 12.5 KB checked in by rebelt, 15 years ago (diff)

下記の問題点の修正です。

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