Ignore:
Timestamp:
2009/06/28 19:24:15 (15 years ago)
Author:
ramrun
Message:

商品一覧ページでcategory_id、商品詳細ページでproduct_idの正当性をチェック

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/comu-ver2/data/class/pages/products/LC_Page_Products_Detail.php

    r18069 r18142  
    7878     */ 
    7979    function process() { 
     80        // プロダクトIDの正当性チェック 
     81        $product_id = $this->lfCheckProductId(); 
     82 
    8083        $objView = new SC_SiteView(); 
    8184        $objCustomer = new SC_Customer(); 
     
    114117        $this->lfInitFile(); 
    115118 
    116         // 管理機能からの確認の場合は、非公開の商品も表示する。 
    117         if(isset($_GET['admin']) && $_GET['admin'] == 'on') { 
    118             SC_Utils_Ex::sfIsSuccess(new SC_Session()); 
    119             $status = true; 
    120             $where = "del_flg = 0"; 
    121         } else { 
    122             $status = false; 
    123             $where = "del_flg = 0 AND status = 1"; 
    124         } 
    125  
    126         if(isset($_POST['mode']) && $_POST['mode'] != "") { 
    127             $tmp_id = $_POST['product_id']; 
    128         } else { 
    129             $tmp_id = $_GET['product_id']; 
    130         } 
    131  
    132         // 値の正当性チェック 
    133         if(!SC_Utils_Ex::sfIsInt($_GET['product_id']) 
    134                 || !$objDb->sfIsRecord("dtb_products", "product_id", $tmp_id, $where)) { 
    135             SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND); 
    136         } 
    137119        // ログイン判定 
    138120        if ($objCustomer->isLoginSuccess() === true) { 
     
    151133            if ($rpcnt < CUSTOMER_READING_MAX){ 
    152134                //閲覧履歴に新規追加 
    153                 lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id')); 
     135                lfRegistReadingData($product_id, $objCustomer->getValue('customer_id')); 
    154136            } else { 
    155137                //閲覧履歴の中で一番古いものを削除して新規追加 
     
    161143                $objQuery->delete($table, $where, $arrval); 
    162144                //追加 
    163                 lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id')); 
     145                lfRegistReadingData($product_id, $objCustomer->getValue('customer_id')); 
    164146            } 
    165147        */ 
    166148        } 
    167149 
    168  
    169150        // 規格選択セレクトボックスの作成 
    170         $this->lfMakeSelect($tmp_id); 
     151        $this->lfMakeSelect($product_id); 
    171152 
    172153        // 商品IDをFORM内に保持する。 
    173         $this->tpl_product_id = $tmp_id; 
     154        $this->tpl_product_id = $product_id; 
    174155 
    175156        if (!isset($_POST['mode'])) $_POST['mode'] = ""; 
     
    223204        $objQuery = new SC_Query(); 
    224205        // DBから商品情報を取得する。 
    225         $arrRet = $objQuery->select("*, (SELECT count(*) FROM dtb_customer_favorite_products WHERE product_id = alldtl.product_id AND customer_id = ?) AS favorite_count", "vw_products_allclass_detail AS alldtl", "product_id = ?", array($objCustomer->getValue('customer_id'), $tmp_id)); 
     206        $arrRet = $objQuery->select("*, (SELECT count(*) FROM dtb_customer_favorite_products WHERE product_id = alldtl.product_id AND customer_id = ?) AS favorite_count", "vw_products_allclass_detail AS alldtl", "product_id = ?", array($objCustomer->getValue('customer_id'), $product_id)); 
    226207        $this->arrProduct = $arrRet[0]; 
    227208 
    228209        // 商品コードの取得 
    229210        $code_sql = "SELECT product_code FROM dtb_products_class AS prdcls WHERE prdcls.product_id = ? GROUP BY product_code ORDER BY product_code"; 
    230         $arrProductCode = $objQuery->getall($code_sql, array($tmp_id)); 
     211        $arrProductCode = $objQuery->getall($code_sql, array($product_id)); 
    231212        $arrProductCode = SC_Utils_Ex::sfswaparray($arrProductCode); 
    232213        $this->arrProductCode = $arrProductCode["product_code"]; 
     
    243224         
    244225        // 関連カテゴリを取得 
    245         $this->arrRelativeCat = $objDb->sfGetMultiCatTree($tmp_id); 
     226        $this->arrRelativeCat = $objDb->sfGetMultiCatTree($product_id); 
    246227         
    247228        // 画像ファイル指定がない場合の置換処理 
     
    257238        $this->arrForm = $this->objFormParam->getFormParamList(); 
    258239        //レビュー情報の取得 
    259         $this->arrReview = $this->lfGetReviewData($tmp_id); 
     240        $this->arrReview = $this->lfGetReviewData($product_id); 
    260241        // トラックバック情報の取得 
    261242 
     
    265246        } else { 
    266247            $this->arrTrackbackView = "ON"; 
    267             $this->arrTrackback = $this->lfGetTrackbackData($tmp_id); 
    268         } 
    269         $this->trackback_url = TRACKBACK_TO_URL . $tmp_id; 
     248            $this->arrTrackback = $this->lfGetTrackbackData($product_id); 
     249        } 
     250        $this->trackback_url = TRACKBACK_TO_URL . $product_id; 
    270251        //関連商品情報表示 
    271         $this->arrRecommend = $this->lfPreGetRecommendProducts($tmp_id); 
     252        $this->arrRecommend = $this->lfPreGetRecommendProducts($product_id); 
    272253        //この商品を買った人はこんな商品も買っています 
    273         $this->arrRelateProducts = $this->lfGetRelateProducts($tmp_id); 
     254        $this->arrRelateProducts = $this->lfGetRelateProducts($product_id); 
    274255 
    275256        $this->lfConvertParam(); 
     
    306287     */ 
    307288    function mobileProcess() { 
     289        // プロダクトIDの正当性チェック 
     290        $product_id = $this->lfCheckProductId(); 
     291         
    308292        $objView = new SC_MobileView(); 
    309293        $objCustomer = new SC_Customer(); 
     
    323307        $this->lfInitFile(); 
    324308 
    325         if (!isset($_POST['mode'])) $_POST['mode'] = ""; 
    326  
    327         if(!empty($_POST['mode'])) { 
    328             $tmp_id = $_POST['product_id']; 
    329         } else { 
    330             $tmp_id = $_GET['product_id']; 
    331         } 
    332  
    333         // 値の正当性チェック 
    334         if(!SC_Utils_Ex::sfIsInt($tmp_id) 
    335                 || !$objDb->sfIsRecord("dtb_products", "product_id", $tmp_id, 'del_flg = 0 AND status = 1')) { 
    336             SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND); 
    337         } 
    338  
    339309        // ログイン判定 
    340310        if($objCustomer->isLoginSuccess(true)) { 
     
    353323               if ($rpcnt < CUSTOMER_READING_MAX){ 
    354324               //閲覧履歴に新規追加 
    355                lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id')); 
     325               lfRegistReadingData($product_id, $objCustomer->getValue('customer_id')); 
    356326               } else { 
    357327               //閲覧履歴の中で一番古いものを削除して新規追加 
     
    363333               $objQuery->delete($table, $where, $arrval); 
    364334               //追加 
    365                lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id')); 
     335               lfRegistReadingData($product_id, $objCustomer->getValue('customer_id')); 
    366336               } 
    367337            */ 
     
    370340 
    371341        // 規格選択セレクトボックスの作成 
    372         $this->lfMakeSelectMobile($this, $tmp_id); 
     342        $this->lfMakeSelectMobile($this, $product_id); 
    373343 
    374344        // 商品IDをFORM内に保持する。 
    375         $this->tpl_product_id = $tmp_id; 
     345        $this->tpl_product_id = $product_id; 
    376346 
    377347        switch($_POST['mode']) { 
     
    447417        $objQuery = new SC_Query(); 
    448418        // DBから商品情報を取得する。 
    449         $arrRet = $objQuery->select("*", "vw_products_allclass_detail AS alldtl", "product_id = ?", array($tmp_id)); 
     419        $arrRet = $objQuery->select("*", "vw_products_allclass_detail AS alldtl", "product_id = ?", array($product_id)); 
    450420        $this->arrProduct = $arrRet[0]; 
    451421 
    452422        // 商品コードの取得 
    453423        $code_sql = "SELECT product_code FROM dtb_products_class AS prdcls WHERE prdcls.product_id = ? GROUP BY product_code ORDER BY product_code"; 
    454         $arrProductCode = $objQuery->getall($code_sql, array($tmp_id)); 
     424        $arrProductCode = $objQuery->getall($code_sql, array($product_id)); 
    455425        $arrProductCode = SC_Utils_Ex::sfswaparray($arrProductCode); 
    456426        $this->arrProductCode = $arrProductCode["product_code"]; 
     
    479449        $this->arrForm = $this->objFormParam->getFormParamList(); 
    480450        //レビュー情報の取得 
    481         $this->arrReview = $this->lfGetReviewData($tmp_id); 
     451        $this->arrReview = $this->lfGetReviewData($product_id); 
    482452        // タイトルに商品名を入れる 
    483453        $this->tpl_title = "商品詳細 ". $this->arrProduct["name"]; 
    484454        //関連商品情報表示 
    485         $this->arrRecommend = $this->lfPreGetRecommendProducts($tmp_id); 
     455        $this->arrRecommend = $this->lfPreGetRecommendProducts($product_id); 
    486456        //この商品を買った人はこんな商品も買っています 
    487         $this->arrRelateProducts = $this->lfGetRelateProducts($tmp_id); 
     457        $this->arrRelateProducts = $this->lfGetRelateProducts($product_id); 
    488458 
    489459        $objView->assignobj($this); 
    490460        $objView->display(SITE_FRAME); 
     461    } 
     462 
     463    /* プロダクトIDの正当性チェック */ 
     464    function lfCheckProductId() { 
     465        // 管理機能からの確認の場合は、非公開の商品も表示する。 
     466        if (isset($_GET['admin']) && $_GET['admin'] == 'on') { 
     467            SC_Utils_Ex::sfIsSuccess(new SC_Session()); 
     468            $status = true; 
     469            $where = 'del_flg = 0'; 
     470        } else { 
     471            $status = false; 
     472            $where = 'del_flg = 0 AND status = 1'; 
     473        } 
     474 
     475        if (defined('MOBILE_SITE')) { 
     476            if (!isset($_POST['mode'])) $_POST['mode'] = ""; 
     477            if (!empty($_POST['mode'])) { 
     478                $product_id = $_POST['product_id']; 
     479            } else { 
     480                $product_id = $_GET['product_id']; 
     481            } 
     482        } else { 
     483            if(isset($_POST['mode']) && $_POST['mode'] != '') { 
     484                $product_id = $_POST['product_id']; 
     485            } else { 
     486                $product_id = $_GET['product_id']; 
     487            } 
     488        } 
     489 
     490        $objDb = new SC_Helper_DB_Ex(); 
     491        if(!SC_Utils_Ex::sfIsInt($product_id) 
     492            || SC_Utils_Ex::sfIsZeroFilling($product_id) 
     493            || !$objDb->sfIsRecord('dtb_products', 'product_id', (array)$product_id, $where)) 
     494            SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND); 
     495        return $product_id; 
    491496    } 
    492497 
     
    779784 
    780785    //閲覧履歴新規登録 
    781     function lfRegistReadingData($tmp_id, $customer_id){ 
     786    function lfRegistReadingData($product_id, $customer_id){ 
    782787        $objQuery = new SC_Query; 
    783788        $sqlval['customer_id'] = $customer_id; 
    784         $sqlval['reading_product_id'] = $tmp_id; 
     789        $sqlval['reading_product_id'] = $product_id; 
    785790        $sqlval['create_date'] = 'NOW()'; 
    786791        $sqlval['update_date'] = 'NOW()'; 
     
    789794 
    790795    //この商品を買った人はこんな商品も買っています FIXME 
    791     function lfGetRelateProducts($tmp_id) { 
     796    function lfGetRelateProducts($product_id) { 
    792797        $objQuery = new SC_Query; 
    793798        //自動抽出 
     
    799804        $from = "vw_products_allclass AS allcls "; 
    800805        $where = "del_flg = 0 AND status = 1 AND (stock_max <> 0 OR stock_max IS NULL) AND product_id = ? "; 
    801         $arrval[] = $tmp_id; 
     806        $arrval[] = $product_id; 
    802807        //結果の取得 
    803808        $arrProducts = $objQuery->select($col, $from, $where, $arrval); 
Note: See TracChangeset for help on using the changeset viewer.