[17293] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[20764] | 5 | * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved. |
---|
[17293] | 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 |
---|
[20534] | 25 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
[17293] | 26 | |
---|
| 27 | /** |
---|
| 28 | * 商品選択 のページクラス. |
---|
| 29 | * |
---|
| 30 | * @package Page |
---|
| 31 | * @author LOCKON CO.,LTD. |
---|
| 32 | * @version $Id$ |
---|
| 33 | */ |
---|
[20345] | 34 | class LC_Page_Admin_Order_ProductSelect extends LC_Page_Admin_Ex { |
---|
[17293] | 35 | |
---|
| 36 | // }}} |
---|
| 37 | // {{{ functions |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * Page を初期化する. |
---|
| 41 | * |
---|
| 42 | * @return void |
---|
| 43 | */ |
---|
| 44 | function init() { |
---|
| 45 | parent::init(); |
---|
| 46 | $this->tpl_mainpage = 'order/product_select.tpl'; |
---|
[18075] | 47 | $this->tpl_mainno = 'order'; |
---|
[17293] | 48 | $this->tpl_subno = ""; |
---|
[20911] | 49 | $this->tpl_maintitle = '受注管理'; |
---|
[17293] | 50 | $this->tpl_subtitle = '商品選択'; |
---|
[19687] | 51 | |
---|
| 52 | $masterData = new SC_DB_MasterData_Ex(); |
---|
| 53 | $this->arrPRODUCTSTATUS_COLOR = $masterData->getMasterData("mtb_product_status_color"); |
---|
[17293] | 54 | } |
---|
| 55 | |
---|
| 56 | /** |
---|
| 57 | * Page のプロセス. |
---|
| 58 | * |
---|
| 59 | * @return void |
---|
| 60 | */ |
---|
| 61 | function process() { |
---|
[19661] | 62 | $this->action(); |
---|
| 63 | $this->sendResponse(); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | /** |
---|
| 67 | * Page のアクション. |
---|
| 68 | * |
---|
| 69 | * @return void |
---|
| 70 | */ |
---|
| 71 | function action() { |
---|
[17293] | 72 | $objDb = new SC_Helper_DB_Ex(); |
---|
[20501] | 73 | $objFormParam = new SC_FormParam_Ex(); |
---|
[20272] | 74 | $this->lfInitParam($objFormParam); |
---|
| 75 | $objFormParam->setParam($_POST); |
---|
| 76 | $objFormParam->convParam(); |
---|
[17293] | 77 | |
---|
[20272] | 78 | $this->tpl_no = $this->getNo(array($_GET,$_POST)); |
---|
[17293] | 79 | |
---|
[20044] | 80 | switch ($this->getMode()) { |
---|
[20213] | 81 | case 'search': |
---|
[20487] | 82 | $objProduct = new SC_Product_Ex(); |
---|
[20272] | 83 | $this->arrForm = $objFormParam->getHashArray(); |
---|
| 84 | $wheres = $this->createWhere($objFormParam,$objDb); |
---|
| 85 | $this->tpl_linemax = $this->getLineCount($wheres,$objProduct); |
---|
[17293] | 86 | |
---|
[20272] | 87 | //ぶった斬りポイント================================================================== |
---|
[20213] | 88 | // ページ送りの処理 |
---|
[20380] | 89 | $page_max = SC_Utils_Ex::sfGetSearchPageMax($_POST['search_page_max']); |
---|
[17293] | 90 | |
---|
[20213] | 91 | // ページ送りの取得 |
---|
[20538] | 92 | $objNavi = new SC_PageNavi_Ex($_POST['search_pageno'], $this->tpl_linemax, $page_max, 'fnNaviSearchOnlyPage', NAVI_PMAX); |
---|
[20213] | 93 | $this->tpl_strnavi = $objNavi->strnavi; // 表示文字列 |
---|
| 94 | $startno = $objNavi->start_row; |
---|
[20378] | 95 | $arrProduct_id = $this->getProducts($wheres, $objProduct, $page_max, $startno); |
---|
[20272] | 96 | $productList = $this->getProductList($arrProduct_id,$objProduct); |
---|
[20213] | 97 | //取得している並び順で並び替え |
---|
[20272] | 98 | $this->arrProducts = $this->sortProducts($arrProduct_id,$productList); |
---|
[20213] | 99 | $objProduct->setProductsClassByProductIds($arrProduct_id); |
---|
[20272] | 100 | $this->tpl_javascript .= $this->getTplJavascript($objProduct); |
---|
| 101 | $js_fnOnLoad = $this->getFnOnload($this->arrProducts); |
---|
[20213] | 102 | $this->tpl_javascript .= 'function fnOnLoad(){' . $js_fnOnLoad . '}'; |
---|
[20328] | 103 | $this->tpl_onload .= 'fnOnLoad();'; |
---|
[20213] | 104 | // 規格1クラス名 |
---|
| 105 | $this->tpl_class_name1 = $objProduct->className1; |
---|
| 106 | // 規格2クラス名 |
---|
| 107 | $this->tpl_class_name2 = $objProduct->className2; |
---|
| 108 | // 規格1 |
---|
| 109 | $this->arrClassCat1 = $objProduct->classCats1; |
---|
| 110 | // 規格1が設定されている |
---|
| 111 | $this->tpl_classcat_find1 = $objProduct->classCat1_find; |
---|
| 112 | // 規格2が設定されている |
---|
| 113 | $this->tpl_classcat_find2 = $objProduct->classCat2_find; |
---|
| 114 | $this->tpl_product_class_id = $objProduct->product_class_id; |
---|
| 115 | $this->tpl_stock_find = $objProduct->stock_find; |
---|
| 116 | break; |
---|
| 117 | default: |
---|
| 118 | break; |
---|
[17293] | 119 | } |
---|
| 120 | |
---|
| 121 | // カテゴリ取得 |
---|
| 122 | $this->arrCatList = $objDb->sfGetCategoryList(); |
---|
[19909] | 123 | $this->setTemplate($this->tpl_mainpage); |
---|
[17293] | 124 | } |
---|
| 125 | |
---|
[20274] | 126 | /** |
---|
[21256] | 127 | * 商品取得 |
---|
[20274] | 128 | * |
---|
[21256] | 129 | * @param array $arrProductId |
---|
[20274] | 130 | * @param SC_Product $objProduct |
---|
| 131 | */ |
---|
[21256] | 132 | function getProductList($arrProductId, &$objProduct){ |
---|
[20507] | 133 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21256] | 134 | |
---|
| 135 | // 表示順序 |
---|
| 136 | $order = "update_date DESC, product_id DESC"; |
---|
| 137 | $objQuery->setOrder($order); |
---|
| 138 | |
---|
| 139 | return $objProduct->getListByProductIds($objQuery, $arrProductId); |
---|
[20272] | 140 | } |
---|
| 141 | |
---|
[20274] | 142 | /** |
---|
| 143 | * ロード時に実行するJavascriptを生成 |
---|
| 144 | * @param array $arrProducts |
---|
| 145 | */ |
---|
[20272] | 146 | function getFnOnload($arrProducts){ |
---|
| 147 | foreach ($arrProducts as $arrProduct) { |
---|
[20337] | 148 | $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']});"; |
---|
[20272] | 149 | } |
---|
| 150 | } |
---|
| 151 | |
---|
[20274] | 152 | /** |
---|
| 153 | * 規格クラス用JavaScript生成 |
---|
| 154 | * @param SC_Product $objProduct |
---|
| 155 | */ |
---|
[20272] | 156 | function getTplJavascript(&$objProduct){ |
---|
[20434] | 157 | return 'productsClassCategories = ' . SC_Utils_Ex::jsonEncode($objProduct->classCategories) . '; '; |
---|
[20272] | 158 | } |
---|
| 159 | |
---|
[17293] | 160 | /** |
---|
[20272] | 161 | * 検索結果の取得 |
---|
| 162 | * @param array $whereAndBind string whereと array bindの連想配列 |
---|
| 163 | * @param SC_Product $objProduct |
---|
| 164 | */ |
---|
[20378] | 165 | function getProducts($whereAndBind,&$objProduct, $page_max, $startno){ |
---|
[20272] | 166 | $where = $whereAndBind['where']; |
---|
| 167 | $bind = $whereAndBind['bind']; |
---|
[20507] | 168 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20272] | 169 | $objQuery->setWhere($where); |
---|
| 170 | // 取得範囲の指定(開始行番号、行数のセット) |
---|
| 171 | $objQuery->setLimitOffset($page_max, $startno); |
---|
| 172 | // 表示順序 |
---|
| 173 | $objQuery->setOrder($order); |
---|
[20540] | 174 | |
---|
[20272] | 175 | // 検索結果の取得 |
---|
| 176 | return $objProduct->findProductIdsOrder($objQuery, $bind); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | /** |
---|
| 180 | * |
---|
[20274] | 181 | * 検索結果対象となる商品の数を返す。 |
---|
| 182 | * @param array $whereAndBind |
---|
| 183 | * @param SC_Product $objProduct |
---|
[20272] | 184 | */ |
---|
| 185 | function getLineCount($whereAndBind,&$objProduct){ |
---|
| 186 | $where = $whereAndBind['where']; |
---|
| 187 | $bind = $whereAndBind['bind']; |
---|
| 188 | // 検索結果対象となる商品の数を取得 |
---|
[20507] | 189 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20272] | 190 | $objQuery->setWhere($where); |
---|
| 191 | $linemax = $objProduct->findProductCount($objQuery, $bind); |
---|
| 192 | return $linemax; // 何件が該当しました。表示用 |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | /** |
---|
| 196 | * |
---|
| 197 | * POSTされた値からSQLのWHEREとBINDを配列で返す。 |
---|
| 198 | * @return array ('where' => where string, 'bind' => databind array) |
---|
| 199 | * @param SC_FormParam $objFormParam |
---|
| 200 | */ |
---|
| 201 | function createWhere(&$objFormParam,&$objDb){ |
---|
| 202 | $arrForm = $objFormParam->getHashArray(); |
---|
| 203 | $where = "alldtl.del_flg = 0"; |
---|
| 204 | $bind = array(); |
---|
| 205 | foreach ($arrForm as $key => $val) { |
---|
| 206 | if($val == "") { |
---|
| 207 | continue; |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | switch ($key) { |
---|
| 211 | case 'search_name': |
---|
| 212 | $where .= " AND name ILIKE ?"; |
---|
| 213 | $bind[] = "%".$val."%"; |
---|
| 214 | break; |
---|
| 215 | case 'search_category_id': |
---|
| 216 | list($tmp_where, $tmp_bind) = $objDb->sfGetCatWhere($val); |
---|
| 217 | if($tmp_where != "") { |
---|
| 218 | $where.= " AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")"; |
---|
| 219 | $bind = array_merge((array)$bind, (array)$tmp_bind); |
---|
| 220 | } |
---|
| 221 | break; |
---|
| 222 | case 'search_product_code': |
---|
| 223 | $where .= " AND alldtl.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)"; |
---|
| 224 | $bind[] = '%'.$val.'%'; |
---|
| 225 | break; |
---|
| 226 | |
---|
| 227 | default: |
---|
| 228 | break; |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | return array( |
---|
[20562] | 232 | 'where' => $where, |
---|
| 233 | 'bind' => $bind, |
---|
[20272] | 234 | ); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | /** |
---|
[20970] | 238 | * リクエストパラメーターnoを取ってくる。 |
---|
[20272] | 239 | * @param unknown_type $globalParams |
---|
| 240 | */ |
---|
| 241 | function getNo($globalParams){ |
---|
| 242 | foreach ($globalParams as $params){ |
---|
| 243 | if(isset($params['no']) && $params['no']!= ''){ |
---|
[20767] | 244 | return intval($params['no']); |
---|
[20272] | 245 | } |
---|
| 246 | } |
---|
| 247 | return null; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | /** |
---|
| 251 | * 取得している並び順で並び替え |
---|
| 252 | * @param $arrProduct_id |
---|
| 253 | * @param $productList |
---|
| 254 | */ |
---|
| 255 | function sortProducts($arrProduct_id,$productList){ |
---|
| 256 | $products = array(); |
---|
| 257 | foreach($productList as $item) { |
---|
| 258 | $products[ $item['product_id'] ] = $item; |
---|
| 259 | } |
---|
| 260 | $arrProducts = array(); |
---|
| 261 | foreach($arrProduct_id as $product_id) { |
---|
| 262 | $arrProducts[] = $products[$product_id]; |
---|
| 263 | } |
---|
| 264 | return $arrProducts; |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | /** |
---|
[17293] | 268 | * デストラクタ. |
---|
| 269 | * @return void |
---|
| 270 | */ |
---|
| 271 | function destroy() { |
---|
| 272 | parent::destroy(); |
---|
| 273 | } |
---|
| 274 | |
---|
[20213] | 275 | /** |
---|
[20970] | 276 | * パラメーター情報の初期化 |
---|
[20272] | 277 | * @param SC_FormParam $objFormParam |
---|
| 278 | */ |
---|
| 279 | function lfInitParam(&$objFormParam) { |
---|
[20538] | 280 | $objFormParam->addParam("オーダーID", "order_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 281 | $objFormParam->addParam("商品名", "search_name", STEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK")); |
---|
| 282 | $objFormParam->addParam("カテゴリID", "search_category_id", STEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK", "SPTAB_CHECK")); |
---|
| 283 | $objFormParam->addParam("商品コード", "search_product_code", LTEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK", "SPTAB_CHECK")); |
---|
| 284 | $objFormParam->addParam("フッター", 'footer', LTEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK", "SPTAB_CHECK")); |
---|
[20272] | 285 | } |
---|
[17293] | 286 | } |
---|
| 287 | ?> |
---|