[15342] | 1 | <?php |
---|
| 2 | /* |
---|
[16582] | 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[18701] | 5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
---|
[15342] | 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
[16582] | 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. |
---|
[15342] | 22 | */ |
---|
| 23 | |
---|
| 24 | // {{{ requires |
---|
[20345] | 25 | require_once(CLASS_EX_REALDIR . "page_extends/admin/LC_Page_Admin_Ex.php"); |
---|
[15342] | 26 | |
---|
| 27 | /** |
---|
| 28 | * 商品管理 のページクラス. |
---|
| 29 | * |
---|
| 30 | * @package Page |
---|
| 31 | * @author LOCKON CO.,LTD. |
---|
[20016] | 32 | * @version $Id$ |
---|
[15342] | 33 | */ |
---|
[20345] | 34 | class LC_Page_Admin_Products extends LC_Page_Admin_Ex { |
---|
[15342] | 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'; |
---|
[20128] | 50 | $this->tpl_pager = 'pager.tpl'; |
---|
[15342] | 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 | |
---|
| 60 | /** |
---|
| 61 | * Page のプロセス. |
---|
| 62 | * |
---|
| 63 | * @return void |
---|
| 64 | */ |
---|
| 65 | function process() { |
---|
[19661] | 66 | $this->action(); |
---|
| 67 | $this->sendResponse(); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | /** |
---|
| 71 | * Page のアクション. |
---|
| 72 | * |
---|
| 73 | * @return void |
---|
| 74 | */ |
---|
| 75 | function action() { |
---|
[15350] | 76 | $objDb = new SC_Helper_DB_Ex(); |
---|
[15342] | 77 | $objDate = new SC_Date(); |
---|
[20200] | 78 | $objFormParam = new SC_FormParam(); |
---|
| 79 | $objProduct = new SC_Product(); |
---|
[20201] | 80 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
[15342] | 81 | |
---|
| 82 | // 登録・更新検索開始年 |
---|
| 83 | $objDate->setStartYear(RELEASE_YEAR); |
---|
| 84 | $objDate->setEndYear(DATE("Y")); |
---|
| 85 | $this->arrStartYear = $objDate->getYear(); |
---|
| 86 | $this->arrStartMonth = $objDate->getMonth(); |
---|
| 87 | $this->arrStartDay = $objDate->getDay(); |
---|
| 88 | // 登録・更新検索終了年 |
---|
| 89 | $objDate->setStartYear(RELEASE_YEAR); |
---|
| 90 | $objDate->setEndYear(DATE("Y")); |
---|
| 91 | $this->arrEndYear = $objDate->getYear(); |
---|
| 92 | $this->arrEndMonth = $objDate->getMonth(); |
---|
| 93 | $this->arrEndDay = $objDate->getDay(); |
---|
| 94 | |
---|
[20200] | 95 | // パラメータ情報の初期化 |
---|
| 96 | $this->lfInitParam($objFormParam); |
---|
| 97 | $objFormParam->setParam($_POST); |
---|
| 98 | $this->arrHidden = $objFormParam->getSearchArray(); |
---|
| 99 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
[15342] | 100 | |
---|
[20044] | 101 | switch ($this->getMode()) { |
---|
| 102 | case 'delete': |
---|
[20201] | 103 | // 商品、子テーブル(商品規格)、会員お気に入り商品の削除 |
---|
[20200] | 104 | $this->doDelete("product_id = ?", array($objFormParam->getValue('product_id'))); |
---|
[15342] | 105 | // 件数カウントバッチ実行 |
---|
[20032] | 106 | $objDb->sfCountCategory($objQuery); |
---|
| 107 | $objDb->sfCountMaker($objQuery); |
---|
[20200] | 108 | // 削除後に検索結果を表示するため breakしない |
---|
| 109 | |
---|
| 110 | // 検索パラメータ生成後に処理実行するため breakしない |
---|
[20044] | 111 | case 'csv': |
---|
| 112 | case 'delete_all': |
---|
[15342] | 113 | |
---|
[20200] | 114 | case 'search': |
---|
| 115 | $objFormParam->convParam(); |
---|
| 116 | $objFormParam->trimParam(); |
---|
| 117 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
| 118 | $arrParam = $objFormParam->getHashArray(); |
---|
[15342] | 119 | |
---|
| 120 | if (count($this->arrErr) == 0) { |
---|
[20200] | 121 | $where = "del_flg = 0"; |
---|
| 122 | foreach ($arrParam as $key => $val) { |
---|
[15342] | 123 | if($val == "") { |
---|
| 124 | continue; |
---|
| 125 | } |
---|
[20202] | 126 | $this->buildQuery($key, $where, $arrval, $objFormParam, $objDb); |
---|
[15342] | 127 | } |
---|
| 128 | |
---|
[20200] | 129 | $order = "update_date DESC"; |
---|
[15551] | 130 | |
---|
[20200] | 131 | /* ----------------------------------------------- |
---|
| 132 | * 処理を実行 |
---|
| 133 | * ----------------------------------------------- */ |
---|
| 134 | switch($this->getMode()) { |
---|
| 135 | // CSVを送信する。 |
---|
| 136 | case 'csv': |
---|
[20276] | 137 | require_once(CLASS_EX_REALDIR . "helper_extends/SC_Helper_CSV_Ex.php"); |
---|
| 138 | |
---|
| 139 | $objCSV = new SC_Helper_CSV_Ex(); |
---|
| 140 | // CSVを送信する。正常終了の場合、終了。 |
---|
[20280] | 141 | $objCSV->sfDownloadCsv(1, $where, $arrval, $order, true); |
---|
[20200] | 142 | exit; |
---|
| 143 | // 全件削除(ADMIN_MODE) |
---|
| 144 | case 'delete_all': |
---|
| 145 | $this->doDelete($where, $arrval); |
---|
| 146 | break; |
---|
[18327] | 147 | |
---|
[20200] | 148 | // 検索実行 |
---|
| 149 | default: |
---|
| 150 | // 行数の取得 |
---|
| 151 | $this->tpl_linemax = $this->getNumberOfLines($where, $arrval); |
---|
| 152 | // ページ送りの処理 |
---|
[20380] | 153 | $page_max = SC_Utils_Ex::sfGetSearchPageMax($objFormParam->getValue('search_page_max')); |
---|
[20200] | 154 | // ページ送りの取得 |
---|
| 155 | $objNavi = new SC_PageNavi($this->arrHidden['search_pageno'], |
---|
| 156 | $this->tpl_linemax, $page_max, |
---|
| 157 | "fnNaviSearchPage", NAVI_PMAX); |
---|
| 158 | $this->arrPagenavi = $objNavi->arrPagenavi; |
---|
[18327] | 159 | |
---|
[20200] | 160 | // 検索結果の取得 |
---|
| 161 | $this->arrProducts = $this->findProducts($where, $arrval, |
---|
| 162 | $page_max, $objNavi->start_row, $order, $objProduct); |
---|
[20201] | 163 | |
---|
[20200] | 164 | // 各商品ごとのカテゴリIDを取得 |
---|
| 165 | if (count($this->arrProducts) > 0) { |
---|
| 166 | foreach ($this->arrProducts as $key => $val) { |
---|
| 167 | $this->arrProducts[$key]["categories"] = $objDb->sfGetCategoryId($val["product_id"], 0, true); |
---|
| 168 | $objDb->g_category_on = false; |
---|
[17799] | 169 | } |
---|
[20200] | 170 | } |
---|
[15342] | 171 | } |
---|
| 172 | } |
---|
[20044] | 173 | break; |
---|
[15342] | 174 | } |
---|
| 175 | |
---|
| 176 | // カテゴリの読込 |
---|
[17569] | 177 | list($this->arrCatKey, $this->arrCatVal) = $objDb->sfGetLevelCatList(false); |
---|
| 178 | $this->arrCatList = $this->lfGetIDName($this->arrCatKey, $this->arrCatVal); |
---|
[15342] | 179 | } |
---|
| 180 | |
---|
| 181 | /** |
---|
| 182 | * デストラクタ. |
---|
| 183 | * |
---|
| 184 | * @return void |
---|
| 185 | */ |
---|
| 186 | function destroy() { |
---|
| 187 | parent::destroy(); |
---|
| 188 | } |
---|
| 189 | |
---|
[20200] | 190 | /** |
---|
| 191 | * パラメータ情報の初期化を行う. |
---|
| 192 | * |
---|
| 193 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 194 | * @return void |
---|
| 195 | */ |
---|
| 196 | function lfInitParam(&$objFormParam) { |
---|
[20201] | 197 | |
---|
| 198 | // POSTされる値 |
---|
| 199 | $objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 200 | $objFormParam->addParam("カテゴリID", "category_id", STEXT_LEN, "n", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 201 | $objFormParam->addParam("ページ送り番号","search_pageno", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 202 | $objFormParam->addParam("表示件数", "search_page_max", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 203 | |
---|
[20200] | 204 | // 検索条件 |
---|
| 205 | $objFormParam->addParam("商品ID", "search_product_id", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 206 | $objFormParam->addParam("商品コード", "search_product_code", STEXT_LEN, "KVna", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 207 | $objFormParam->addParam("商品名", "search_name", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 208 | $objFormParam->addParam("カテゴリ", "search_category_id", STEXT_LEN, "n", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 209 | $objFormParam->addParam("種別", "search_status", INT_LEN, "n", array("MAX_LENGTH_CHECK")); |
---|
| 210 | // 登録・更新日 |
---|
| 211 | $objFormParam->addParam("開始年", "search_startyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 212 | $objFormParam->addParam("開始月", "search_startmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 213 | $objFormParam->addParam("開始日", "search_startday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 214 | $objFormParam->addParam("終了年", "search_endyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 215 | $objFormParam->addParam("終了月", "search_endmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 216 | $objFormParam->addParam("終了日", "search_endday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
[15342] | 217 | |
---|
[20200] | 218 | $objFormParam->addParam("ステータス", "search_product_flag", INT_LEN, "n", array("MAX_LENGTH_CHECK")); |
---|
[15342] | 219 | } |
---|
| 220 | |
---|
[20200] | 221 | /** |
---|
| 222 | * 入力内容のチェックを行う. |
---|
| 223 | * |
---|
| 224 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 225 | * @return void |
---|
| 226 | */ |
---|
| 227 | function lfCheckError(&$objFormParam) { |
---|
| 228 | $objErr = new SC_CheckError($objFormParam->getHashArray()); |
---|
| 229 | $objErr->arrErr = $objFormParam->checkError(); |
---|
| 230 | |
---|
[15342] | 231 | $objErr->doFunc(array("開始日", "終了日", "search_startyear", "search_startmonth", "search_startday", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_SET_TERM")); |
---|
[20200] | 232 | |
---|
[15342] | 233 | return $objErr->arrErr; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | // カテゴリIDをキー、カテゴリ名を値にする配列を返す。 |
---|
[17569] | 237 | function lfGetIDName($arrCatKey, $arrCatVal) { |
---|
| 238 | $max = count($arrCatKey); |
---|
[15342] | 239 | for ($cnt = 0; $cnt < $max; $cnt++ ) { |
---|
[17569] | 240 | $key = isset($arrCatKey[$cnt]) ? $arrCatKey[$cnt] : ""; |
---|
| 241 | $val = isset($arrCatVal[$cnt]) ? $arrCatVal[$cnt] : ""; |
---|
[15342] | 242 | $arrRet[$key] = $val; |
---|
| 243 | } |
---|
| 244 | return $arrRet; |
---|
| 245 | } |
---|
[20200] | 246 | |
---|
| 247 | /** |
---|
[20201] | 248 | * 商品、子テーブル(商品規格)、お気に入り商品の削除 |
---|
[20200] | 249 | * |
---|
| 250 | * @param string $where 削除対象の WHERE 句 |
---|
| 251 | * @param array $arrParam 削除対象の値 |
---|
| 252 | * @return void |
---|
| 253 | */ |
---|
| 254 | function doDelete($where, $arrParam = array()) { |
---|
| 255 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 256 | $objQuery->update("dtb_products", array('del_flg' => 1), $where, $arrParam); |
---|
| 257 | $objQuery->update("dtb_products_class", array('del_flg' => 1), $where, $arrParam); |
---|
[20201] | 258 | $objQuery->delete("dtb_customer_favorite_products", $where, $arrParam); |
---|
[20200] | 259 | } |
---|
| 260 | |
---|
| 261 | /** |
---|
| 262 | * クエリを構築する. |
---|
| 263 | * |
---|
| 264 | * 検索条件のキーに応じた WHERE 句と, クエリパラメータを構築する. |
---|
| 265 | * クエリパラメータは, SC_FormParam の入力値から取得する. |
---|
| 266 | * |
---|
[20202] | 267 | * 構築内容は, 引数の $where 及び $arrValues にそれぞれ追加される. |
---|
[20200] | 268 | * |
---|
| 269 | * @param string $key 検索条件のキー |
---|
| 270 | * @param string $where 構築する WHERE 句 |
---|
| 271 | * @param array $arrValues 構築するクエリパラメータ |
---|
| 272 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 273 | * @param SC_FormParam $objDb SC_Helper_DB_Ex インスタンス |
---|
| 274 | * @return void |
---|
| 275 | */ |
---|
[20202] | 276 | function buildQuery($key, &$where, &$arrValues, &$objFormParam, &$objDb) { |
---|
[20200] | 277 | $dbFactory = SC_DB_DBFactory::getInstance(); |
---|
| 278 | switch ($key) { |
---|
| 279 | // 商品ID |
---|
| 280 | case 'search_product_id': |
---|
| 281 | $where .= " AND product_id = ?"; |
---|
| 282 | $arrValues[] = sprintf('%d', $objFormParam->getValue($key)); |
---|
| 283 | break; |
---|
| 284 | // 商品コード |
---|
| 285 | case 'search_product_code': |
---|
| 286 | $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code ILIKE ? GROUP BY product_id)"; |
---|
| 287 | $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key)); |
---|
| 288 | break; |
---|
| 289 | // 商品名 |
---|
| 290 | case 'search_name': |
---|
| 291 | $where .= " AND name LIKE ?"; |
---|
| 292 | $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key)); |
---|
| 293 | break; |
---|
| 294 | // カテゴリ |
---|
| 295 | case 'search_category_id': |
---|
| 296 | list($tmp_where, $tmp_Values) = $objDb->sfGetCatWhere($objFormParam->getValue($key)); |
---|
| 297 | if($tmp_where != "") { |
---|
| 298 | $where.= " AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")"; |
---|
| 299 | $arrValues = array_merge((array)$arrValues, (array)$tmp_Values); |
---|
| 300 | } |
---|
| 301 | break; |
---|
| 302 | // 種別 |
---|
| 303 | case 'search_status': |
---|
| 304 | $tmp_where = ""; |
---|
| 305 | foreach($objFormParam->getValue($key) as $element) { |
---|
| 306 | if($element != "") { |
---|
| 307 | if(SC_Utils_Ex::isBlank($tmp_where)) { |
---|
| 308 | $tmp_where .= " AND (status = ?"; |
---|
| 309 | } else { |
---|
| 310 | $tmp_where .= " OR status = ?"; |
---|
| 311 | } |
---|
| 312 | $arrValues[] = $element; |
---|
| 313 | } |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | if(!SC_Utils_Ex::isBlank($tmp_where)) { |
---|
| 317 | $tmp_where .= ")"; |
---|
| 318 | $where .= " $tmp_where "; |
---|
| 319 | } |
---|
| 320 | break; |
---|
| 321 | // 登録・更新日(開始) |
---|
| 322 | case 'search_startyear': |
---|
| 323 | $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_startyear'), |
---|
| 324 | $objFormParam->getValue('search_startmonth'), |
---|
| 325 | $objFormParam->getValue('search_startday')); |
---|
| 326 | $where.= " AND update_date >= ?"; |
---|
| 327 | $arrValues[] = $date; |
---|
| 328 | break; |
---|
| 329 | // 登録・更新日(終了) |
---|
| 330 | case 'search_endyear': |
---|
| 331 | $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_endyear'), |
---|
| 332 | $objFormParam->getValue('search_endmonth'), |
---|
| 333 | $objFormParam->getValue('search_endday'), true); |
---|
| 334 | $where.= " AND update_date <= ?"; |
---|
| 335 | $arrValues[] = $date; |
---|
| 336 | break; |
---|
| 337 | //ステータス |
---|
| 338 | case 'search_product_flag': |
---|
| 339 | if(count($objFormParam->getValue($key)) > 0) { |
---|
| 340 | $where .= " AND product_id IN (SELECT product_id FROM dtb_product_status WHERE product_status_id IN ("; |
---|
| 341 | foreach($objFormParam->getValue($key) as $param) { |
---|
| 342 | $where .= "?,"; |
---|
| 343 | $arrValues[] = $param; |
---|
| 344 | } |
---|
| 345 | $where = preg_replace("/,$/", "))", $where); |
---|
| 346 | } |
---|
| 347 | break; |
---|
| 348 | } |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | /** |
---|
| 352 | * 検索結果の行数を取得する. |
---|
| 353 | * |
---|
| 354 | * @param string $where 検索条件の WHERE 句 |
---|
| 355 | * @param array $arrValues 検索条件のパラメータ |
---|
| 356 | * @return integer 検索結果の行数 |
---|
| 357 | */ |
---|
| 358 | function getNumberOfLines($where, $arrValues) { |
---|
| 359 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 360 | return $objQuery->count('dtb_products', $where, $arrValues); |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | /** |
---|
| 364 | * 商品を検索する. |
---|
| 365 | * |
---|
| 366 | * @param string $where 検索条件の WHERE 句 |
---|
| 367 | * @param array $arrValues 検索条件のパラメータ |
---|
| 368 | * @param integer $limit 表示件数 |
---|
| 369 | * @param integer $offset 開始件数 |
---|
| 370 | * @param string $order 検索結果の並び順 |
---|
| 371 | * @param SC_Product $objProduct SC_Product インスタンス |
---|
| 372 | * @return array 商品の検索結果 |
---|
| 373 | */ |
---|
| 374 | function findProducts($where, $arrValues, $limit, $offset, $order, &$objProduct) { |
---|
| 375 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 376 | |
---|
| 377 | // 読み込む列とテーブルの指定 |
---|
| 378 | $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"; |
---|
| 379 | $from = $objProduct->alldtlSQL(); |
---|
| 380 | |
---|
| 381 | $objQuery->setLimitOffset($limit, $offset); |
---|
| 382 | $objQuery->setOrder($order); |
---|
| 383 | |
---|
| 384 | return $objQuery->select($col, $from, $where, $arrValues); |
---|
| 385 | } |
---|
[15342] | 386 | } |
---|
[20380] | 387 | ?> |
---|