Source for file LC_Page_Admin_Products.php

Documentation is available at LC_Page_Admin_Products.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.lockon.co.jp/
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  */
  23.  
  24. // {{{ requires
  25. require_once(CLASS_PATH "pages/LC_Page.php");
  26.  
  27. /**
  28.  * 商品管理 のページクラス.
  29.  *
  30.  * @package Page
  31.  * @author LOCKON CO.,LTD.
  32.  * @version $Id:LC_Page_Admin_Products.php 15532 2007-08-31 14:39:46Z nanasess $
  33.  */
  34. class LC_Page_Admin_Products extends LC_Page {
  35.  
  36.     // }}}
  37.     // {{{ functions
  38.  
  39.     /**
  40.      * Page を初期化する.
  41.      *
  42.      * @return void 
  43.      */
  44.     function init({
  45.         parent::init();
  46.         $this->tpl_mainpage = 'products/index.tpl';
  47.         $this->tpl_mainno = 'products';
  48.         $this->tpl_subnavi 'products/subnavi.tpl';
  49.         $this->tpl_subno 'index';
  50.         $this->tpl_pager TEMPLATE_DIR 'admin/pager.tpl';
  51.         $this->tpl_subtitle '商品マスタ';
  52.  
  53.         $masterData new SC_DB_MasterData_Ex();
  54.         $this->arrPageMax $masterData->getMasterData("mtb_page_max");
  55.         $this->arrDISP $masterData->getMasterData("mtb_disp");
  56.         $this->arrSTATUS $masterData->getMasterData("mtb_status");
  57.         $this->arrPRODUCTSTATUS_COLOR $masterData->getMasterData("mtb_product_status_color");
  58.  
  59.         $this->allowClientCache();
  60.     }
  61.  
  62.     /**
  63.      * Page のプロセス.
  64.      *
  65.      * @return void 
  66.      */
  67.     function process({
  68.         $objView new SC_AdminView();
  69.         $objDb new SC_Helper_DB_Ex();
  70.         $objDate new SC_Date();
  71.  
  72.         // 登録・更新検索開始年
  73.         $objDate->setStartYear(RELEASE_YEAR);
  74.         $objDate->setEndYear(DATE("Y"));
  75.         $this->arrStartYear $objDate->getYear();
  76.         $this->arrStartMonth $objDate->getMonth();
  77.         $this->arrStartDay $objDate->getDay();
  78.         // 登録・更新検索終了年
  79.         $objDate->setStartYear(RELEASE_YEAR);
  80.         $objDate->setEndYear(DATE("Y"));
  81.         $this->arrEndYear $objDate->getYear();
  82.         $this->arrEndMonth $objDate->getMonth();
  83.         $this->arrEndDay $objDate->getDay();
  84.  
  85.         // 認証可否の判定
  86.         $objSess new SC_Session();
  87.         SC_Utils_Ex::sfIsSuccess($objSess);
  88.  
  89.         if (!isset($_POST['mode'])) $_POST['mode'"";
  90.  
  91.         //キャンペーンの編集時
  92.         if(isset($_POST['campaign_id']&& SC_Utils_Ex::sfIsInt($_POST['campaign_id'])
  93.                 && $_POST['mode'== "camp_search"{
  94.             $objQuery new SC_Query();
  95.             $search_data $objQuery->get("dtb_campaign""search_condition""campaign_id = ? "array($_POST['campaign_id']));
  96.             $arrSearch unserialize($search_data);
  97.             foreach ($arrSearch as $key => $val{
  98.                 $_POST[$key$val;
  99.             }
  100.         }
  101.  
  102.         // POST値の引き継ぎ
  103.         $this->arrForm $_POST;
  104.  
  105.         // 検索ワードの引き継ぎ
  106.         foreach ($_POST as $key => $val{
  107.             if (ereg("^search_"$key|| ereg("^campaign_"$key)) {
  108.                 switch($key{
  109.                     case 'search_product_flag':
  110.                     case 'search_status':
  111.                         $this->arrHidden[$keySC_Utils_Ex::sfMergeParamCheckBoxes($val);
  112.                         if(!is_array($val)) {
  113.                             $this->arrForm[$keysplit("-"$val);
  114.                         }
  115.                         break;
  116.                     default:
  117.                         $this->arrHidden[$key$val;
  118.                         break;
  119.                 }
  120.             }
  121.         }
  122.  
  123.         // ページ送り用
  124.         $this->arrHidden['search_pageno'= isset($_POST['search_pageno']$_POST['search_pageno'"";
  125.  
  126.         // 商品削除
  127.         if ($_POST['mode'== "delete"{
  128.  
  129.             if($_POST['category_id'!= ""{
  130.                 // ランク付きレコードの削除
  131.                 $where "category_id = " SC_Utils_Ex::sfQuoteSmart($_POST['category_id']);
  132.                 $objDb->sfDeleteRankRecord("dtb_products""product_id"$_POST['product_id']$where);
  133.             else {
  134.                 $objDb->sfDeleteRankRecord("dtb_products""product_id"$_POST['product_id']);
  135.             }
  136.             // 子テーブル(商品規格)の削除
  137.             $objQuery new SC_Query();
  138.             $objQuery->delete("dtb_products_class""product_id = ?"array($_POST['product_id']));
  139.  
  140.             // お気に入り商品削除
  141.             $objQuery->delete("dtb_customer_favorite_products""product_id = ?"array($_POST['product_id']));
  142.  
  143.             // 件数カウントバッチ実行
  144.             $objDb->sfCategory_Count($objQuery);
  145.             $objDb->sfMaker_Count($objQuery);
  146.         }
  147.  
  148.  
  149.         if ($_POST['mode'== "search" || $_POST['mode'== "csv"  || $_POST['mode'== "delete" || $_POST['mode'== "delete_all" || $_POST['mode'== "camp_search"{
  150.             // 入力文字の強制変換
  151.             $this->lfConvertParam();
  152.             // エラーチェック
  153.             $this->arrErr $this->lfCheckError();
  154.  
  155.             $where "del_flg = 0";
  156.             $view_where "del_flg = 0";
  157.  
  158.             // 入力エラーなし
  159.             if (count($this->arrErr== 0{
  160.  
  161.                 $arrval array();
  162.                 foreach ($this->arrForm as $key => $val{
  163.                     $val SC_Utils_Ex::sfManualEscape($val);
  164.  
  165.                     if($val == ""{
  166.                         continue;
  167.                     }
  168.  
  169.                     switch ($key{
  170.                         case 'search_product_id'// 商品ID
  171.                             $where .= " AND product_id = ?";
  172.                             $view_where .= " AND product_id = ?";
  173.                             $arrval[$val;
  174.                             break;
  175.                         case 'search_product_class_name'//規格名称
  176.                             $where_in " (SELECT classcategory_id FROM dtb_classcategory WHERE class_id IN (SELECT class_id FROM dtb_class WHERE name LIKE ?)) ";
  177.                             $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE classcategory_id1 IN " $where_in;
  178.                             $where .= " OR classcategory_id2 IN" $where_in ")";
  179.                             $view_where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE classcategory_id1 IN " $where_in;
  180.                             $view_where .= " OR classcategory_id2 IN" $where_in ")";
  181.                             $arrval["%$val%";
  182.                             $arrval["%$val%";
  183.                             $view_where $where;
  184.                             break;
  185.                         case 'search_name'// 商品名
  186.                             $where .= " AND name ILIKE ?";
  187.                             $view_where .= " AND name ILIKE ?";
  188.                             $arrval["%$val%";
  189.                             break;
  190.                         case 'search_category_id'// カテゴリー
  191.                             list($tmp_where$tmp_arrval$objDb->sfGetCatWhere($val);
  192.                             if($tmp_where != ""{
  193.                                 $where.= " AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE " $tmp_where ")";
  194.                                 $view_where.= " AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE " $tmp_where ")";
  195.                                 $arrval array_merge((array)$arrval(array)$tmp_arrval);
  196.                             }
  197.                             break;
  198.                         case 'search_product_code'// 商品コード
  199.                             $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code ILIKE ? GROUP BY product_id)";
  200.                             $view_where .= " AND EXISTS (SELECT product_id FROM dtb_products_class as cls WHERE cls.product_code ILIKE ? AND dtb_products.product_id = cls.product_id GROUP BY cls.product_id )";
  201.                             $arrval["%$val%";
  202.                             break;
  203.                         case 'search_startyear'// 登録更新日(FROM)
  204.                             $date SC_Utils_Ex::sfGetTimestamp($_POST['search_startyear']$_POST['search_startmonth']$_POST['search_startday']);
  205.                             $where.= " AND update_date >= '" $_POST['search_startyear'"/" $_POST['search_startmonth']"/" .$_POST['search_startday'"'";
  206.                             $view_where.= " AND update_date >= '" $_POST['search_startyear'"/" $_POST['search_startmonth']"/" .$_POST['search_startday'"'";
  207.                             break;
  208.                         case 'search_endyear'// 登録更新日(TO)
  209.                             $date SC_Utils_Ex::sfGetTimestamp($_POST['search_endyear']$_POST['search_endmonth']$_POST['search_endday']);
  210.                             $date date('Y/m/d'strtotime($date86400);
  211.                             $where.= " AND update_date < date('" $date "')";
  212.                             $view_where.= " AND update_date < date('" $date "')";
  213.                             break;
  214.                         case 'search_product_flag'//種別
  215.                             global $arrSTATUS;
  216.                             $search_product_flag SC_Utils_Ex::sfSearchCheckBoxes($val);
  217.                             if($search_product_flag != ""{
  218.                                 $where.= " AND product_flag LIKE ?";
  219.                                 $view_where.= " AND product_flag LIKE ?";
  220.                                 $arrval[$search_product_flag;
  221.                             }
  222.                             break;
  223.                         case 'search_status'// ステータス
  224.                             $tmp_where "";
  225.                             foreach ($val as $element){
  226.                                 if ($element != ""){
  227.                                     if ($tmp_where == ""){
  228.                                         $tmp_where.="AND (status = ? ";
  229.                                     }else{
  230.                                         $tmp_where.="OR status = ? ";
  231.                                     }
  232.                                     $arrval[]=$element;
  233.                                 }
  234.                             }
  235.                             if ($tmp_where != ""){
  236.                                 $tmp_where.=")";
  237.                                 $where.= " $tmp_where";
  238.                                 $view_where.= " $tmp_where";
  239.                             }
  240.                             break;
  241.                         default:
  242.                             break;
  243.                     }
  244.                 }
  245.  
  246.                 $order "update_date DESC, product_id DESC";
  247.                 $objQuery new SC_Query();
  248.  
  249.                 switch($_POST['mode']{
  250.                     case 'csv':
  251.                         require_once(CLASS_EX_PATH "helper_extends/SC_Helper_CSV_Ex.php");
  252.  
  253.                         $objCSV new SC_Helper_CSV_Ex();
  254.  
  255.                         // CSVを送信する。正常終了の場合、終了。
  256.                         $objCSV->sfDownloadProductsCsv($where$arrval$order&& exit;
  257.                         
  258.                         break;
  259.                     case 'delete_all':
  260.                         // 検索結果をすべて削除
  261.                         $where "product_id IN (SELECT product_id FROM vw_products_allclass_detail AS alldtl WHERE $where)";
  262.                         $sqlval['del_flg'1;
  263.                         $objQuery->update("dtb_products"$sqlval$where$arrval);
  264.                         $objQuery->delete("dtb_customer_favorite_products"$where$arrval);
  265.                         break;
  266.                     default:
  267.                         // 読み込む列とテーブルの指定
  268.                         $col "product_id, name, main_list_image, status, product_code_min, product_code_max, price02_min, price02_max, stock_min, stock_max, stock_unlimited_min, stock_unlimited_max, update_date";
  269.                         $from "vw_products_allclass_detail AS alldtl ";
  270.  
  271.                         // 行数の取得
  272.                         $linemax $objQuery->count("dtb_products"$view_where$arrval);
  273.                         $this->tpl_linemax $linemax// 何件が該当しました。表示用
  274.  
  275.                         // ページ送りの処理
  276.                         if(is_numeric($_POST['search_page_max'])) {
  277.                             $page_max $_POST['search_page_max'];
  278.                         else {
  279.                             $page_max SEARCH_PMAX;
  280.                         }
  281.  
  282.                         // ページ送りの取得
  283.                         $objNavi new SC_PageNavi($this->arrHidden['search_pageno']$linemax$page_max"fnNaviSearchPage"NAVI_PMAX);
  284.                         $startno $objNavi->start_row;
  285.                         $this->arrPagenavi $objNavi->arrPagenavi;
  286.  
  287.                         //キャンペーン商品検索時は、全結果の商品IDを変数に格納する
  288.                         if(isset($_POST['search_mode']&& $_POST['search_mode'== 'campaign'{
  289.                             $arrRet $objQuery->select($col$from$where$arrval);
  290.                             if(count($arrRet0{
  291.                                 $arrRet sfSwapArray($arrRet);
  292.                                 $pid implode("-"$arrRet['product_id']);
  293.                                 $this->arrHidden['campaign_product_id'$pid;
  294.                             }
  295.                         }
  296.  
  297.                         // 取得範囲の指定(開始行番号、行数のセット)
  298.                         //                    if(DB_TYPE != "mysql") $objQuery->setlimitoffset($page_max, $startno);
  299.                         $objQuery->setlimitoffset($page_max$startno);
  300.                         // 表示順序
  301.                         $objQuery->setorder($order);
  302.  
  303.                         // 検索結果の取得
  304.                         $this->arrProducts $objQuery->select($col$from$where$arrval);
  305.                         
  306.                         // 各商品ごとのカテゴリIDを取得
  307.                         if (count($this->arrProducts0{
  308.                             foreach ($this->arrProducts as $key => $val{
  309.                                 $this->arrProducts[$key]["categories"$objDb->sfGetCategoryId($val["product_id"]0true);
  310.                                 $objDb->g_category_on false;
  311.                             }
  312.                         }
  313.                 }
  314.             }
  315.         }
  316.  
  317.         // カテゴリの読込
  318.         list($this->arrCatKey$this->arrCatVal$objDb->sfGetLevelCatList(false);
  319.         $this->arrCatList $this->lfGetIDName($this->arrCatKey$this->arrCatVal);
  320.  
  321.         // 画面の表示
  322.         $objView->assignobj($this);
  323.         $objView->display(MAIN_FRAME);
  324.     }
  325.  
  326.     /**
  327.      * デストラクタ.
  328.      *
  329.      * @return void 
  330.      */
  331.     function destroy({
  332.         parent::destroy();
  333.     }
  334.  
  335.     // 取得文字列の変換
  336.     function lfConvertParam({
  337.         global $objPage;
  338.         /*
  339.          *  文字列の変換
  340.          *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
  341.          *  C :  「全角ひら仮名」を「全角かた仮名」に変換
  342.          *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
  343.          *  n :  「全角」数字を「半角(ハンカク)」に変換
  344.          */
  345.         $arrConvList['search_name'"KVa";
  346.         $arrConvList['search_product_code'"KVa";
  347.  
  348.         // 文字変換
  349.         foreach ($arrConvList as $key => $val{
  350.             // POSTされてきた値のみ変換する。
  351.             if(isset($objPage->arrForm[$key])) {
  352.                 $objPage->arrForm[$keymb_convert_kana($objPage->arrForm[$key,$val);
  353.             }
  354.         }
  355.     }
  356.  
  357.     // エラーチェック
  358.     // 入力エラーチェック
  359.     function lfCheckError({
  360.         $objErr new SC_CheckError();
  361.         $objErr->doFunc(array("商品ID""search_product_id")array("NUM_CHECK"));
  362.         $objErr->doFunc(array("開始日""search_startyear""search_startmonth""search_startday")array("CHECK_DATE"));
  363.         $objErr->doFunc(array("終了日""search_endyear""search_endmonth""search_endday")array("CHECK_DATE"));
  364.         $objErr->doFunc(array("開始日""終了日""search_startyear""search_startmonth""search_startday""search_endyear""search_endmonth""search_endday")array("CHECK_SET_TERM"));
  365.         return $objErr->arrErr;
  366.     }
  367.  
  368.     // チェックボックス用WHERE文作成
  369.     function lfGetCBWhere($key$max{
  370.         $str "";
  371.         $find false;
  372.         for ($cnt 1$cnt <= $max$cnt++{
  373.             if ($_POST[$key $cnt== "1"{
  374.                 $str.= "1";
  375.                 $find true;
  376.             else {
  377.                 $str.= "_";
  378.             }
  379.         }
  380.         if (!$find{
  381.             $str "";
  382.         }
  383.         return $str;
  384.     }
  385.  
  386.     // カテゴリIDをキー、カテゴリ名を値にする配列を返す。
  387.     function lfGetIDName($arrCatKey$arrCatVal{
  388.         $max count($arrCatKey);
  389.         for ($cnt 0$cnt $max$cnt++ {
  390.             $key = isset($arrCatKey[$cnt]$arrCatKey[$cnt"";
  391.             $val = isset($arrCatVal[$cnt]$arrCatVal[$cnt"";
  392.             $arrRet[$key$val;
  393.         }
  394.         return $arrRet;
  395.     }
  396. }
  397. ?>

Documentation generated on Tue, 28 Apr 2009 18:11:31 +0900 by phpDocumentor 1.4.2