[15486] | 1 | <?php |
---|
| 2 | /* |
---|
[16582] | 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[20764] | 5 | * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved. |
---|
[15486] | 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. |
---|
[15486] | 22 | */ |
---|
| 23 | |
---|
| 24 | // {{{ requires |
---|
[20534] | 25 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
[15486] | 26 | |
---|
| 27 | /** |
---|
| 28 | * 規格分類 のページクラス. |
---|
| 29 | * |
---|
| 30 | * @package Page |
---|
| 31 | * @author LOCKON CO.,LTD. |
---|
[16379] | 32 | * @version $Id:LC_Page_Admin_Products_ClassCategory.php 15532 2007-08-31 14:39:46Z nanasess $ |
---|
[15486] | 33 | */ |
---|
[20345] | 34 | class LC_Page_Admin_Products_ClassCategory extends LC_Page_Admin_Ex { |
---|
[15486] | 35 | |
---|
| 36 | // }}} |
---|
| 37 | // {{{ functions |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * Page を初期化する. |
---|
| 41 | * |
---|
| 42 | * @return void |
---|
| 43 | */ |
---|
| 44 | function init() { |
---|
| 45 | parent::init(); |
---|
| 46 | $this->tpl_mainpage = 'products/classcategory.tpl'; |
---|
| 47 | $this->tpl_subno = 'class'; |
---|
[20911] | 48 | $this->tpl_maintitle = '商品管理'; |
---|
| 49 | $this->tpl_subtitle = '規格管理>分類登録'; |
---|
[15486] | 50 | $this->tpl_mainno = 'products'; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | * Page のプロセス. |
---|
| 55 | * |
---|
| 56 | * @return void |
---|
| 57 | */ |
---|
| 58 | function process() { |
---|
[19661] | 59 | $this->action(); |
---|
| 60 | $this->sendResponse(); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * Page のアクション. |
---|
| 65 | * |
---|
| 66 | * @return void |
---|
| 67 | */ |
---|
| 68 | function action() { |
---|
[21591] | 69 | |
---|
[20501] | 70 | $objFormParam = new SC_FormParam_Ex(); |
---|
[15486] | 71 | |
---|
[20182] | 72 | $this->lfInitParam($objFormParam); |
---|
[20185] | 73 | $objFormParam->setParam($_REQUEST); |
---|
[20182] | 74 | $objFormParam->convParam(); |
---|
| 75 | $class_id = $objFormParam->getValue('class_id'); |
---|
| 76 | $classcategory_id = $objFormParam->getValue('classcategory_id'); |
---|
[15486] | 77 | |
---|
[21441] | 78 | switch ($this->getMode()) { |
---|
[21526] | 79 | // 登録ボタン押下 |
---|
| 80 | // 新規作成 or 編集 |
---|
| 81 | case 'edit': |
---|
| 82 | // パラメーター値の取得 |
---|
| 83 | $this->arrForm = $objFormParam->getHashArray(); |
---|
| 84 | // 入力パラメーターチェック |
---|
| 85 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
| 86 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
| 87 | //新規規格追加かどうかを判定する |
---|
| 88 | $is_insert = $this->lfCheckInsert($classcategory_id); |
---|
| 89 | if ($is_insert) { |
---|
| 90 | //新規追加 |
---|
| 91 | $this->lfInsertClass($this->arrForm); |
---|
| 92 | } else { |
---|
| 93 | //更新 |
---|
| 94 | $this->lfUpdateClass($this->arrForm); |
---|
| 95 | } |
---|
[21591] | 96 | |
---|
[21526] | 97 | // 再表示 |
---|
| 98 | SC_Response_Ex::reload(); |
---|
[15486] | 99 | } |
---|
[21526] | 100 | break; |
---|
| 101 | // 削除 |
---|
| 102 | case 'delete': |
---|
| 103 | // ランク付きレコードの削除 |
---|
| 104 | $this->lfDeleteClassCat($class_id, $classcategory_id); |
---|
[21591] | 105 | |
---|
[20484] | 106 | SC_Response_Ex::reload(); |
---|
[21526] | 107 | break; |
---|
| 108 | // 編集前処理 |
---|
| 109 | case 'pre_edit': |
---|
| 110 | // 規格名を取得する。 |
---|
| 111 | $classcategory_name = $this->lfGetClassCatName($classcategory_id); |
---|
| 112 | // 入力項目にカテゴリ名を入力する。 |
---|
| 113 | $this->arrForm['name'] = $classcategory_name; |
---|
| 114 | break; |
---|
| 115 | case 'down': |
---|
| 116 | //並び順を下げる |
---|
| 117 | $this->lfDownRank($class_id, $classcategory_id); |
---|
[21591] | 118 | |
---|
[21526] | 119 | SC_Response_Ex::reload(); |
---|
| 120 | break; |
---|
| 121 | case 'up': |
---|
| 122 | //並び順を上げる |
---|
| 123 | $this->lfUpRank($class_id, $classcategory_id); |
---|
[21591] | 124 | |
---|
[21526] | 125 | SC_Response_Ex::reload(); |
---|
| 126 | break; |
---|
| 127 | default: |
---|
| 128 | break; |
---|
[15486] | 129 | } |
---|
[20182] | 130 | //規格分類名の取得 |
---|
| 131 | $this->tpl_class_name = $this->lfGetClassName($class_id); |
---|
| 132 | //規格分類情報の取得 |
---|
| 133 | $this->arrClassCat = $this->lfGetClassCat($class_id); |
---|
| 134 | // POSTデータを引き継ぐ |
---|
| 135 | $this->tpl_classcategory_id = $classcategory_id; |
---|
[21591] | 136 | |
---|
[15486] | 137 | } |
---|
| 138 | |
---|
| 139 | /** |
---|
| 140 | * デストラクタ. |
---|
| 141 | * |
---|
| 142 | * @return void |
---|
| 143 | */ |
---|
| 144 | function destroy() { |
---|
| 145 | parent::destroy(); |
---|
| 146 | } |
---|
| 147 | |
---|
[20182] | 148 | /** |
---|
[20970] | 149 | * パラメーターの初期化を行う. |
---|
[20182] | 150 | * |
---|
| 151 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 152 | * @return void |
---|
| 153 | */ |
---|
| 154 | function lfInitParam(&$objFormParam) { |
---|
[21514] | 155 | $objFormParam->addParam('規格ID', 'class_id', INT_LEN, 'n', array('NUM_CHECK')); |
---|
| 156 | $objFormParam->addParam('規格分類名', 'name', STEXT_LEN, 'KVa', array('EXIST_CHECK' ,'SPTAB_CHECK' ,'MAX_LENGTH_CHECK')); |
---|
| 157 | $objFormParam->addParam('規格分類ID', 'classcategory_id', INT_LEN, 'n', array('NUM_CHECK')); |
---|
[20182] | 158 | } |
---|
| 159 | |
---|
[21527] | 160 | /** |
---|
[20182] | 161 | * 有効な規格分類情報の取得 |
---|
| 162 | * |
---|
| 163 | * @param integer $class_id 規格ID |
---|
| 164 | * @return array 規格分類情報 |
---|
| 165 | */ |
---|
| 166 | function lfGetClassCat($class_id) { |
---|
[20507] | 167 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20182] | 168 | |
---|
[21514] | 169 | $where = 'del_flg <> 1 AND class_id = ?'; |
---|
| 170 | $objQuery->setOrder('rank DESC'); // XXX 降順 |
---|
| 171 | $arrClassCat = $objQuery->select('name, classcategory_id', 'dtb_classcategory', $where, array($class_id)); |
---|
[20182] | 172 | return $arrClassCat; |
---|
| 173 | } |
---|
| 174 | |
---|
[21527] | 175 | /** |
---|
[20182] | 176 | * 規格名の取得 |
---|
| 177 | * |
---|
| 178 | * @param integer $class_id 規格ID |
---|
| 179 | * @return string 規格名 |
---|
| 180 | */ |
---|
| 181 | function lfGetClassName($class_id) { |
---|
[20507] | 182 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20182] | 183 | |
---|
[21514] | 184 | $where = 'class_id = ?'; |
---|
[21481] | 185 | $name = $objQuery->get('name', 'dtb_class', $where, array($class_id)); |
---|
[20182] | 186 | return $name; |
---|
| 187 | } |
---|
[21527] | 188 | |
---|
| 189 | /** |
---|
[20182] | 190 | * 規格分類名を取得する |
---|
| 191 | * |
---|
| 192 | * @param integer $classcategory_id 規格分類ID |
---|
| 193 | * @return string 規格分類名 |
---|
| 194 | */ |
---|
| 195 | function lfGetClassCatName($classcategory_id) { |
---|
[20507] | 196 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21514] | 197 | $where = 'classcategory_id = ?'; |
---|
[21481] | 198 | $name = $objQuery->get('name', 'dtb_classcategory', $where, array($classcategory_id)); |
---|
[20182] | 199 | return $name; |
---|
| 200 | } |
---|
| 201 | |
---|
[21527] | 202 | /** |
---|
[20182] | 203 | * 規格分類情報を新規登録 |
---|
| 204 | * |
---|
| 205 | * @param array $arrForm フォームパラメータークラス |
---|
| 206 | * @return integer 更新件数 |
---|
| 207 | */ |
---|
| 208 | function lfInsertClass($arrForm) { |
---|
[20507] | 209 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[15486] | 210 | $objQuery->begin(); |
---|
| 211 | // 親規格IDの存在チェック |
---|
[21514] | 212 | $where = 'del_flg <> 1 AND class_id = ?'; |
---|
[21481] | 213 | $class_id = $objQuery->get('class_id', 'dtb_class', $where, array($arrForm['class_id'])); |
---|
[21441] | 214 | if (!SC_Utils_Ex::isBlank($class_id)) { |
---|
[15486] | 215 | // INSERTする値を作成する。 |
---|
[20182] | 216 | $sqlval['name'] = $arrForm['name']; |
---|
| 217 | $sqlval['class_id'] = $arrForm['class_id']; |
---|
[15486] | 218 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
[21481] | 219 | $sqlval['rank'] = $objQuery->max('rank', 'dtb_classcategory', $where, array($arrForm['class_id'])) + 1; |
---|
[21185] | 220 | $sqlval['create_date'] = 'CURRENT_TIMESTAMP'; |
---|
| 221 | $sqlval['update_date'] = 'CURRENT_TIMESTAMP'; |
---|
[15486] | 222 | // INSERTの実行 |
---|
[18788] | 223 | $sqlval['classcategory_id'] = $objQuery->nextVal('dtb_classcategory_classcategory_id'); |
---|
[21481] | 224 | $ret = $objQuery->insert('dtb_classcategory', $sqlval); |
---|
[15486] | 225 | } |
---|
| 226 | $objQuery->commit(); |
---|
| 227 | return $ret; |
---|
| 228 | } |
---|
| 229 | |
---|
[21527] | 230 | /** |
---|
[20797] | 231 | * 規格分類情報を更新 |
---|
| 232 | * |
---|
| 233 | * @param array $arrForm フォームパラメータークラス |
---|
| 234 | * @return integer 更新件数 |
---|
| 235 | */ |
---|
| 236 | function lfUpdateClass($arrForm) { |
---|
[21750] | 237 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[15486] | 238 | // UPDATEする値を作成する。 |
---|
[20797] | 239 | $sqlval['name'] = $arrForm['name']; |
---|
[21185] | 240 | $sqlval['update_date'] = 'CURRENT_TIMESTAMP'; |
---|
[21514] | 241 | $where = 'classcategory_id = ?'; |
---|
[15486] | 242 | // UPDATEの実行 |
---|
[21481] | 243 | $ret = $objQuery->update('dtb_classcategory', $sqlval, $where, array($arrForm['classcategory_id'])); |
---|
[15486] | 244 | return $ret; |
---|
| 245 | } |
---|
| 246 | |
---|
[21527] | 247 | /** |
---|
[20182] | 248 | * エラーチェック |
---|
| 249 | * |
---|
| 250 | * @param array $objFormParam フォームパラメータークラス |
---|
| 251 | * @return array エラー配列 |
---|
| 252 | */ |
---|
| 253 | function lfCheckError(&$objFormParam) { |
---|
[20507] | 254 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20182] | 255 | $arrForm = $objFormParam->getHashArray(); |
---|
| 256 | // パラメーターの基本チェック |
---|
| 257 | $arrErr = $objFormParam->checkError(); |
---|
| 258 | if (!SC_Utils_Ex::isBlank($arrErr)) { |
---|
| 259 | return $arrErr; |
---|
[21441] | 260 | } else { |
---|
[20182] | 261 | $arrForm = $objFormParam->getHashArray(); |
---|
| 262 | } |
---|
[15486] | 263 | |
---|
[21514] | 264 | $where = 'class_id = ? AND name = ?'; |
---|
| 265 | $arrRet = $objQuery->select('classcategory_id, name', 'dtb_classcategory', $where, array($arrForm['class_id'], $arrForm['name'])); |
---|
[20182] | 266 | // 編集中のレコード以外に同じ名称が存在する場合 |
---|
| 267 | if ($arrRet[0]['classcategory_id'] != $arrForm['classcategory_id'] && $arrRet[0]['name'] == $arrForm['name']) { |
---|
[21514] | 268 | $arrErr['name'] = '※ 既に同じ内容の登録が存在します。<br>'; |
---|
[15486] | 269 | } |
---|
[20182] | 270 | return $arrErr; |
---|
[15486] | 271 | } |
---|
| 272 | |
---|
[20182] | 273 | /** |
---|
| 274 | * 新規規格分類追加かどうかを判定する. |
---|
| 275 | * |
---|
| 276 | * @param integer $classcategory_id 規格分類ID |
---|
| 277 | * @return boolean 新規商品追加の場合 true |
---|
| 278 | */ |
---|
| 279 | function lfCheckInsert($classcategory_id) { |
---|
| 280 | //classcategory_id のあるなしで新規規格分類化かどうかを判定 |
---|
[21441] | 281 | if (empty($classcategory_id)) { |
---|
[20182] | 282 | return true; |
---|
[21441] | 283 | } else { |
---|
[20182] | 284 | return false; |
---|
[15486] | 285 | } |
---|
| 286 | } |
---|
[20182] | 287 | |
---|
| 288 | /** |
---|
| 289 | * 規格分類情報を削除する |
---|
| 290 | * |
---|
| 291 | * @param integer $class_id 規格ID |
---|
| 292 | * @param integer $classcategory_id 規格分類ID |
---|
| 293 | * @return void |
---|
| 294 | */ |
---|
| 295 | function lfDeleteClassCat($class_id, $classcategory_id) { |
---|
| 296 | $objDb = new SC_Helper_DB_Ex(); |
---|
[21514] | 297 | $where = 'class_id = ' . SC_Utils_Ex::sfQuoteSmart($class_id); |
---|
[21481] | 298 | $objDb->sfDeleteRankRecord('dtb_classcategory', 'classcategory_id', $classcategory_id, $where, true); |
---|
[20182] | 299 | } |
---|
| 300 | /** |
---|
| 301 | * 並び順を上げる |
---|
| 302 | * |
---|
| 303 | * @param integer $class_id 規格ID |
---|
| 304 | * @param integer $classcategory_id 規格分類ID |
---|
| 305 | * @return void |
---|
| 306 | */ |
---|
| 307 | function lfUpRank($class_id, $classcategory_id) { |
---|
| 308 | $objDb = new SC_Helper_DB_Ex(); |
---|
[21514] | 309 | $where = 'class_id = ' . SC_Utils_Ex::sfQuoteSmart($class_id); |
---|
[21481] | 310 | $objDb->sfRankUp('dtb_classcategory', 'classcategory_id', $classcategory_id, $where); |
---|
[20182] | 311 | } |
---|
| 312 | /** |
---|
| 313 | * 並び順を下げる |
---|
| 314 | * |
---|
| 315 | * @param integer $class_id 規格ID |
---|
| 316 | * @param integer $classcategory_id 規格分類ID |
---|
| 317 | * @return void |
---|
| 318 | */ |
---|
| 319 | function lfDownRank($class_id, $classcategory_id) { |
---|
| 320 | $objDb = new SC_Helper_DB_Ex(); |
---|
[21514] | 321 | $where = 'class_id = ' . SC_Utils_Ex::sfQuoteSmart($class_id); |
---|
[21481] | 322 | $objDb->sfRankDown('dtb_classcategory', 'classcategory_id', $classcategory_id, $where); |
---|
[20182] | 323 | } |
---|
[15486] | 324 | } |
---|