source: temp/branches/mobile/html/mobile/products/list.php @ 11398

Revision 11398, 11.7 KB checked in by rebelt, 17 years ago (diff)

以下のモバイルサイト用ページ・機能を作成いたしました。

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