[15486] | 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. |
---|
[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 |
---|
[19805] | 25 | require_once(CLASS_REALDIR . "pages/admin/LC_Page_Admin.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 | */ |
---|
[19661] | 34 | class LC_Page_Admin_Products_ClassCategory extends LC_Page_Admin { |
---|
[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_subnavi = 'products/subnavi.tpl'; |
---|
| 48 | $this->tpl_subno = 'class'; |
---|
| 49 | $this->tpl_subtitle = '規格登録'; |
---|
| 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() { |
---|
[20182] | 69 | $objFormParam = new SC_FormParam(); |
---|
[15486] | 70 | |
---|
| 71 | // 認証可否の判定 |
---|
[20182] | 72 | SC_Utils_Ex::sfIsSuccess(new SC_Session()); |
---|
[15486] | 73 | |
---|
[20182] | 74 | $this->lfInitParam($objFormParam); |
---|
[20185] | 75 | $objFormParam->setParam($_REQUEST); |
---|
[20182] | 76 | $objFormParam->convParam(); |
---|
| 77 | $class_id = $objFormParam->getValue('class_id'); |
---|
| 78 | $classcategory_id = $objFormParam->getValue('classcategory_id'); |
---|
[15486] | 79 | |
---|
[20182] | 80 | switch($this->getMode()) { |
---|
| 81 | // 登録ボタン押下 |
---|
[15486] | 82 | // 新規作成 or 編集 |
---|
| 83 | case 'edit': |
---|
[20182] | 84 | // パラメータ値の取得 |
---|
| 85 | $this->arrForm = $objFormParam->getHashArray(); |
---|
| 86 | // 入力パラメーターチェック |
---|
| 87 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
| 88 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
| 89 | //新規規格追加かどうかを判定する |
---|
| 90 | $is_insert = $this->lfCheckInsert($classcategory_id); |
---|
| 91 | if($is_insert) { |
---|
| 92 | //新規追加 |
---|
| 93 | $this->lfInsertClass($this->arrForm); |
---|
[15486] | 94 | } else { |
---|
[20182] | 95 | //更新 |
---|
| 96 | $this->lfUpdateClass($this->arrForm); |
---|
[15486] | 97 | } |
---|
| 98 | // 再表示 |
---|
[20182] | 99 | SC_Response::reload(); |
---|
[15486] | 100 | } |
---|
| 101 | break; |
---|
| 102 | // 削除 |
---|
| 103 | case 'delete': |
---|
| 104 | // ランク付きレコードの削除 |
---|
[20182] | 105 | $this->lfDeleteClassCat($class_id, $classcategory_id); |
---|
[15486] | 106 | break; |
---|
| 107 | // 編集前処理 |
---|
| 108 | case 'pre_edit': |
---|
[20182] | 109 | // 規格名を取得する。 |
---|
| 110 | $classcategory_name = $this->lfGetClassCatName($classcategory_id); |
---|
[15486] | 111 | // 入力項目にカテゴリ名を入力する。 |
---|
[20182] | 112 | $this->arrForm['name'] = $classcategory_name; |
---|
[15486] | 113 | break; |
---|
| 114 | case 'down': |
---|
[20182] | 115 | //並び順を下げる |
---|
| 116 | $this->lfDownRank($class_id, $classcategory_id); |
---|
[15486] | 117 | break; |
---|
| 118 | case 'up': |
---|
[20182] | 119 | //並び順を上げる |
---|
| 120 | $this->lfUpRank($class_id, $classcategory_id); |
---|
[15486] | 121 | break; |
---|
| 122 | default: |
---|
| 123 | break; |
---|
| 124 | } |
---|
[20182] | 125 | //規格分類名の取得 |
---|
| 126 | $this->tpl_class_name = $this->lfGetClassName($class_id); |
---|
| 127 | //規格分類情報の取得 |
---|
| 128 | $this->arrClassCat = $this->lfGetClassCat($class_id); |
---|
| 129 | // POSTデータを引き継ぐ |
---|
| 130 | $this->tpl_classcategory_id = $classcategory_id; |
---|
[15486] | 131 | } |
---|
| 132 | |
---|
| 133 | /** |
---|
| 134 | * デストラクタ. |
---|
| 135 | * |
---|
| 136 | * @return void |
---|
| 137 | */ |
---|
| 138 | function destroy() { |
---|
| 139 | parent::destroy(); |
---|
| 140 | } |
---|
| 141 | |
---|
[20182] | 142 | /** |
---|
| 143 | * パラメータの初期化を行う. |
---|
| 144 | * |
---|
| 145 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 146 | * @return void |
---|
| 147 | */ |
---|
| 148 | function lfInitParam(&$objFormParam) { |
---|
| 149 | $objFormParam->addParam("規格ID", "class_id", INT_LEN, "n", array("NUM_CHECK")); |
---|
| 150 | $objFormParam->addParam("規格分類名", "name", STEXT_LEN, "KVa", array("EXIST_CHECK" ,"SPTAB_CHECK" ,"MAX_LENGTH_CHECK")); |
---|
| 151 | $objFormParam->addParam("規格分類ID", "classcategory_id", INT_LEN, "n", array("NUM_CHECK")); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | /** |
---|
| 155 | * 有効な規格分類情報の取得 |
---|
| 156 | * |
---|
| 157 | * @param integer $class_id 規格ID |
---|
| 158 | * @return array 規格分類情報 |
---|
| 159 | */ |
---|
| 160 | function lfGetClassCat($class_id) { |
---|
| 161 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 162 | |
---|
| 163 | $where = "del_flg <> 1 AND class_id = ?"; |
---|
| 164 | $objQuery->setOrder("rank DESC"); |
---|
| 165 | $arrClassCat = $objQuery->select("name, classcategory_id", "dtb_classcategory", $where, array($class_id)); |
---|
| 166 | return $arrClassCat; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | /** |
---|
| 170 | * 規格名の取得 |
---|
| 171 | * |
---|
| 172 | * @param integer $class_id 規格ID |
---|
| 173 | * @return string 規格名 |
---|
| 174 | */ |
---|
| 175 | function lfGetClassName($class_id) { |
---|
| 176 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 177 | |
---|
| 178 | $where = "class_id = ?"; |
---|
| 179 | $name = $objQuery->get("name", "dtb_class", $where, array($class_id)); |
---|
| 180 | return $name; |
---|
| 181 | } |
---|
| 182 | /** |
---|
| 183 | * 規格分類名を取得する |
---|
| 184 | * |
---|
| 185 | * @param integer $classcategory_id 規格分類ID |
---|
| 186 | * @return string 規格分類名 |
---|
| 187 | */ |
---|
| 188 | function lfGetClassCatName($classcategory_id) { |
---|
| 189 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 190 | $where = "classcategory_id = ?"; |
---|
| 191 | $name = $objQuery->get("name", "dtb_classcategory", $where, array($classcategory_id)); |
---|
| 192 | return $name; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | /** |
---|
| 196 | * 規格分類情報を新規登録 |
---|
| 197 | * |
---|
| 198 | * @param array $arrForm フォームパラメータークラス |
---|
| 199 | * @return integer 更新件数 |
---|
| 200 | */ |
---|
| 201 | function lfInsertClass($arrForm) { |
---|
| 202 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
[15486] | 203 | $objQuery->begin(); |
---|
| 204 | // 親規格IDの存在チェック |
---|
| 205 | $where = "del_flg <> 1 AND class_id = ?"; |
---|
[20182] | 206 | $class_id = $objQuery->get("class_id", "dtb_class", $where, array($arrForm['class_id'])); |
---|
| 207 | if(!SC_Utils_Ex::isBlank($class_id)) { |
---|
[15486] | 208 | // INSERTする値を作成する。 |
---|
[20182] | 209 | $sqlval['name'] = $arrForm['name']; |
---|
| 210 | $sqlval['class_id'] = $arrForm['class_id']; |
---|
[15486] | 211 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
[20182] | 212 | $sqlval['rank'] = $objQuery->max("rank", "dtb_classcategory", $where, array($arrForm['class_id'])) + 1; |
---|
[15486] | 213 | $sqlval['create_date'] = "now()"; |
---|
| 214 | $sqlval['update_date'] = "now()"; |
---|
| 215 | // INSERTの実行 |
---|
[18788] | 216 | $sqlval['classcategory_id'] = $objQuery->nextVal('dtb_classcategory_classcategory_id'); |
---|
[15486] | 217 | $ret = $objQuery->insert("dtb_classcategory", $sqlval); |
---|
| 218 | } |
---|
| 219 | $objQuery->commit(); |
---|
| 220 | return $ret; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | /* DBへの更新 */ |
---|
| 224 | function lfUpdateClass() { |
---|
| 225 | $objQuery = new SC_Query(); |
---|
| 226 | // UPDATEする値を作成する。 |
---|
| 227 | $sqlval['name'] = $_POST['name']; |
---|
| 228 | $sqlval['update_date'] = "Now()"; |
---|
| 229 | $where = "classcategory_id = ?"; |
---|
| 230 | // UPDATEの実行 |
---|
| 231 | $ret = $objQuery->update("dtb_classcategory", $sqlval, $where, array($_POST['classcategory_id'])); |
---|
| 232 | return $ret; |
---|
| 233 | } |
---|
| 234 | |
---|
[20182] | 235 | /** |
---|
| 236 | * エラーチェック |
---|
| 237 | * |
---|
| 238 | * @param array $objFormParam フォームパラメータークラス |
---|
| 239 | * @return array エラー配列 |
---|
| 240 | */ |
---|
| 241 | function lfCheckError(&$objFormParam) { |
---|
| 242 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 243 | $arrForm = $objFormParam->getHashArray(); |
---|
| 244 | // パラメーターの基本チェック |
---|
| 245 | $arrErr = $objFormParam->checkError(); |
---|
| 246 | if (!SC_Utils_Ex::isBlank($arrErr)) { |
---|
| 247 | return $arrErr; |
---|
| 248 | }else{ |
---|
| 249 | $arrForm = $objFormParam->getHashArray(); |
---|
| 250 | } |
---|
[15486] | 251 | |
---|
[20182] | 252 | $where = "class_id = ? AND name = ?"; |
---|
| 253 | $arrRet = $objQuery->select("classcategory_id, name", "dtb_classcategory", $where, array($arrForm['class_id'], $arrForm['name'])); |
---|
| 254 | // 編集中のレコード以外に同じ名称が存在する場合 |
---|
| 255 | if ($arrRet[0]['classcategory_id'] != $arrForm['classcategory_id'] && $arrRet[0]['name'] == $arrForm['name']) { |
---|
| 256 | $arrErr['name'] = "※ 既に同じ内容の登録が存在します。<br>"; |
---|
[15486] | 257 | } |
---|
[20182] | 258 | return $arrErr; |
---|
[15486] | 259 | } |
---|
| 260 | |
---|
[20182] | 261 | /** |
---|
| 262 | * 新規規格分類追加かどうかを判定する. |
---|
| 263 | * |
---|
| 264 | * @param integer $classcategory_id 規格分類ID |
---|
| 265 | * @return boolean 新規商品追加の場合 true |
---|
| 266 | */ |
---|
| 267 | function lfCheckInsert($classcategory_id) { |
---|
| 268 | //classcategory_id のあるなしで新規規格分類化かどうかを判定 |
---|
| 269 | if (empty($classcategory_id)){ |
---|
| 270 | return true; |
---|
| 271 | }else{ |
---|
| 272 | return false; |
---|
[15486] | 273 | } |
---|
| 274 | } |
---|
[20182] | 275 | |
---|
| 276 | /** |
---|
| 277 | * 規格分類情報を削除する |
---|
| 278 | * |
---|
| 279 | * @param integer $class_id 規格ID |
---|
| 280 | * @param integer $classcategory_id 規格分類ID |
---|
| 281 | * @return void |
---|
| 282 | */ |
---|
| 283 | function lfDeleteClassCat($class_id, $classcategory_id) { |
---|
| 284 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 285 | $where = "class_id = " . SC_Utils_Ex::sfQuoteSmart($class_id); |
---|
| 286 | $objDb->sfDeleteRankRecord("dtb_classcategory", "classcategory_id", $classcategory_id, $where, true); |
---|
| 287 | } |
---|
| 288 | /** |
---|
| 289 | * 並び順を上げる |
---|
| 290 | * |
---|
| 291 | * @param integer $class_id 規格ID |
---|
| 292 | * @param integer $classcategory_id 規格分類ID |
---|
| 293 | * @return void |
---|
| 294 | */ |
---|
| 295 | function lfUpRank($class_id, $classcategory_id) { |
---|
| 296 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 297 | $where = "class_id = " . SC_Utils_Ex::sfQuoteSmart($class_id); |
---|
| 298 | $objDb->sfRankUp("dtb_classcategory", "classcategory_id", $classcategory_id, $where); |
---|
| 299 | } |
---|
| 300 | /** |
---|
| 301 | * 並び順を下げる |
---|
| 302 | * |
---|
| 303 | * @param integer $class_id 規格ID |
---|
| 304 | * @param integer $classcategory_id 規格分類ID |
---|
| 305 | * @return void |
---|
| 306 | */ |
---|
| 307 | function lfDownRank($class_id, $classcategory_id) { |
---|
| 308 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 309 | $where = "class_id = " . SC_Utils_Ex::sfQuoteSmart($class_id); |
---|
| 310 | $objDb->sfRankDown("dtb_classcategory", "classcategory_id", $classcategory_id, $where); |
---|
| 311 | } |
---|
[15486] | 312 | } |
---|
| 313 | ?> |
---|