[17073] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[18701] | 5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
---|
[17073] | 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'; |
---|
[17073] | 26 | |
---|
| 27 | /** |
---|
[17362] | 28 | * 定休日管理のページクラス. |
---|
[17073] | 29 | * |
---|
| 30 | * @package Page |
---|
| 31 | * @author LOCKON CO.,LTD. |
---|
[20116] | 32 | * @version $Id$ |
---|
[17073] | 33 | */ |
---|
[20345] | 34 | class LC_Page_Admin_Basis_Holiday extends LC_Page_Admin_Ex { |
---|
[17073] | 35 | |
---|
| 36 | // }}} |
---|
| 37 | // {{{ functions |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * Page を初期化する. |
---|
| 41 | * |
---|
| 42 | * @return void |
---|
| 43 | */ |
---|
| 44 | function init() { |
---|
| 45 | parent::init(); |
---|
| 46 | $this->tpl_mainpage = 'basis/holiday.tpl'; |
---|
| 47 | $this->tpl_subnavi = 'basis/subnavi.tpl'; |
---|
| 48 | $this->tpl_subno = 'holiday'; |
---|
[17362] | 49 | $this->tpl_subtitle = '定休日管理'; |
---|
[17073] | 50 | $this->tpl_mainno = 'basis'; |
---|
| 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() { |
---|
[17073] | 69 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 70 | |
---|
[20499] | 71 | $objDate = new SC_Date_Ex(); |
---|
[17073] | 72 | $this->arrMonth = $objDate->getMonth(); |
---|
| 73 | $this->arrDay = $objDate->getDay(); |
---|
| 74 | |
---|
[20177] | 75 | $mode = $this->getMode(); |
---|
| 76 | |
---|
| 77 | if (!empty($_POST)) { |
---|
[20321] | 78 | |
---|
[20501] | 79 | $objFormParam = new SC_FormParam_Ex(); |
---|
[20321] | 80 | $this->lfInitParam($mode, $objFormParam); |
---|
| 81 | $objFormParam->setParam($_POST); |
---|
[20326] | 82 | $objFormParam->convParam(); |
---|
[20321] | 83 | |
---|
| 84 | $this->arrErr = $this->lfCheckError($mode, $objFormParam); |
---|
[20177] | 85 | if (!empty($this->arrErr['holiday_id'])) { |
---|
| 86 | SC_Utils_Ex::sfDispException(); |
---|
| 87 | return; |
---|
| 88 | } |
---|
[20326] | 89 | |
---|
| 90 | $post = $objFormParam->getHashArray(); |
---|
[20177] | 91 | } |
---|
| 92 | |
---|
[17073] | 93 | // 要求判定 |
---|
[20177] | 94 | switch($mode) { |
---|
[17073] | 95 | // 編集処理 |
---|
| 96 | case 'edit': |
---|
| 97 | // POST値の引き継ぎ |
---|
[20326] | 98 | $this->arrForm = $this->arrForm = $_POST; |
---|
[17073] | 99 | |
---|
| 100 | if(count($this->arrErr) <= 0) { |
---|
[20326] | 101 | if($post['holiday_id'] == "") { |
---|
[20297] | 102 | $this->lfInsertClass($this->arrForm, $_SESSION['member_id']); // 新規作成 |
---|
[17073] | 103 | } else { |
---|
[20326] | 104 | $this->lfUpdateClass($this->arrForm, $post['holiday_id']); // 既存編集 |
---|
[17073] | 105 | } |
---|
| 106 | // 再表示 |
---|
[19661] | 107 | $this->objDisplay->reload(); |
---|
[17073] | 108 | } else { |
---|
| 109 | // POSTデータを引き継ぐ |
---|
[20326] | 110 | $this->tpl_holiday_id = $post['holiday_id']; |
---|
[17073] | 111 | } |
---|
| 112 | break; |
---|
| 113 | // 削除 |
---|
| 114 | case 'delete': |
---|
[20326] | 115 | $objDb->sfDeleteRankRecord("dtb_holiday", "holiday_id", $post['holiday_id'], "", true); |
---|
[17073] | 116 | // 再表示 |
---|
[19661] | 117 | $this->objDisplay->reload(); |
---|
[17073] | 118 | break; |
---|
| 119 | // 編集前処理 |
---|
| 120 | case 'pre_edit': |
---|
[20168] | 121 | // 編集項目を取得する。 |
---|
[20326] | 122 | $arrHolidayData = $this->lfGetHolidayDataByHolidayID($post['holiday_id']); |
---|
[20168] | 123 | |
---|
[17073] | 124 | // 入力項目にカテゴリ名を入力する。 |
---|
[20168] | 125 | $this->arrForm['title'] = $arrHolidayData[0]['title']; |
---|
| 126 | $this->arrForm['month'] = $arrHolidayData[0]['month']; |
---|
| 127 | $this->arrForm['day'] = $arrHolidayData[0]['day']; |
---|
[17073] | 128 | // POSTデータを引き継ぐ |
---|
[20326] | 129 | $this->tpl_holiday_id = $post['holiday_id']; |
---|
[17073] | 130 | break; |
---|
| 131 | case 'down': |
---|
[20326] | 132 | $objDb->sfRankDown("dtb_holiday", "holiday_id", $post['holiday_id']); |
---|
[17073] | 133 | // 再表示 |
---|
[19661] | 134 | $this->objDisplay->reload(); |
---|
[17073] | 135 | break; |
---|
| 136 | case 'up': |
---|
[20326] | 137 | $objDb->sfRankUp("dtb_holiday", "holiday_id", $post['holiday_id']); |
---|
[17073] | 138 | // 再表示 |
---|
[19661] | 139 | $this->objDisplay->reload(); |
---|
[17073] | 140 | break; |
---|
| 141 | default: |
---|
| 142 | break; |
---|
| 143 | } |
---|
| 144 | |
---|
[20168] | 145 | $this->arrHoliday = $this->lfGetHolidayList(); |
---|
[17073] | 146 | } |
---|
| 147 | |
---|
| 148 | /** |
---|
| 149 | * デストラクタ. |
---|
| 150 | * |
---|
| 151 | * @return void |
---|
| 152 | */ |
---|
| 153 | function destroy() { |
---|
| 154 | parent::destroy(); |
---|
| 155 | } |
---|
| 156 | |
---|
[20168] | 157 | function lfGetHolidayDataByHolidayID($holiday_id) { |
---|
[20507] | 158 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20168] | 159 | |
---|
| 160 | $where = "holiday_id = ?"; |
---|
| 161 | return $objQuery->select("title, month, day", "dtb_holiday", $where, array($holiday_id)); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | function lfGetHolidayList() { |
---|
[20507] | 165 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20168] | 166 | |
---|
| 167 | $where = "del_flg <> 1"; |
---|
| 168 | $objQuery->setOrder("rank DESC"); |
---|
| 169 | return $objQuery->select("holiday_id, title, month, day", "dtb_holiday", $where); |
---|
| 170 | } |
---|
| 171 | |
---|
[17073] | 172 | /* DBへの挿入 */ |
---|
[20297] | 173 | function lfInsertClass($arrData, $member_id) { |
---|
[20507] | 174 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[17073] | 175 | // INSERTする値を作成する。 |
---|
| 176 | $sqlval['title'] = $arrData['title']; |
---|
| 177 | $sqlval['month'] = $arrData['month']; |
---|
| 178 | $sqlval['day'] = $arrData['day']; |
---|
[20297] | 179 | $sqlval['creator_id'] = $member_id; |
---|
[19732] | 180 | $sqlval['rank'] = $objQuery->max("rank", "dtb_holiday") + 1; |
---|
[17073] | 181 | $sqlval['update_date'] = "Now()"; |
---|
| 182 | $sqlval['create_date'] = "Now()"; |
---|
| 183 | // INSERTの実行 |
---|
[18788] | 184 | $sqlval['holiday_id'] = $objQuery->nextVal('dtb_holiday_holiday_id'); |
---|
[17073] | 185 | $ret = $objQuery->insert("dtb_holiday", $sqlval); |
---|
| 186 | return $ret; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | /* DBへの更新 */ |
---|
[20326] | 190 | function lfUpdateClass($arrData) { |
---|
[20507] | 191 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[17073] | 192 | // UPDATEする値を作成する。 |
---|
| 193 | $sqlval['title'] = $arrData['title']; |
---|
| 194 | $sqlval['month'] = $arrData['month']; |
---|
| 195 | $sqlval['day'] = $arrData['day']; |
---|
| 196 | $sqlval['update_date'] = "Now()"; |
---|
| 197 | $where = "holiday_id = ?"; |
---|
| 198 | // UPDATEの実行 |
---|
[20326] | 199 | $ret = $objQuery->update("dtb_holiday", $sqlval, $where, array($arrData['holiday_id'])); |
---|
[17073] | 200 | return $ret; |
---|
| 201 | } |
---|
| 202 | |
---|
[20321] | 203 | function lfInitParam($mode, &$objFormParam) |
---|
| 204 | { |
---|
[20177] | 205 | switch ($mode) { |
---|
| 206 | case 'edit': |
---|
[20321] | 207 | $objFormParam->addParam('タイトル', 'title', STEXT_LEN, 'KVa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK")); |
---|
| 208 | $objFormParam->addParam('月', 'month', INT_LEN, 'n', array("SELECT_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK")); |
---|
| 209 | $objFormParam->addParam('日', 'day', INT_LEN, 'n', array("SELECT_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK")); |
---|
[20177] | 210 | // breakしない |
---|
| 211 | case 'delete': |
---|
| 212 | case 'pre_edit': |
---|
| 213 | case 'down': |
---|
| 214 | case 'up': |
---|
[20321] | 215 | $objFormParam->addParam('定休日ID', 'holiday_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
[20177] | 216 | break; |
---|
| 217 | default: |
---|
| 218 | break; |
---|
[17073] | 219 | } |
---|
| 220 | } |
---|
[20321] | 221 | |
---|
| 222 | /** |
---|
| 223 | * 入力エラーチェック |
---|
| 224 | * |
---|
| 225 | * @param string $mode |
---|
| 226 | * @return array |
---|
| 227 | */ |
---|
| 228 | function lfCheckError($mode, &$objFormParam) { |
---|
| 229 | $objFormParam->convParam(); |
---|
| 230 | $arrErr = $objFormParam->checkError(); |
---|
| 231 | $post = $objFormParam->getHashArray(); |
---|
| 232 | |
---|
| 233 | if(!isset($arrErr['date'])) { |
---|
[20507] | 234 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20321] | 235 | $where = "del_flg = 0 AND month = ? AND day = ?"; |
---|
| 236 | $arrval = array($post['month'], $post['day']); |
---|
| 237 | if (!empty($post['holiday_id'])) { |
---|
| 238 | $where .= " AND holiday_id <> ?"; |
---|
| 239 | $arrval[] = $post['holiday_id']; |
---|
| 240 | } |
---|
[20322] | 241 | $arrRet = $objQuery->select("count(holiday_id) as count", "dtb_holiday", $where, $arrval); |
---|
[20321] | 242 | |
---|
| 243 | // 編集中のレコード以外に同じ日付が存在する場合 |
---|
| 244 | if ($arrRet[0]['count'] > 0) { |
---|
| 245 | $arrErr['date'] = "※ 既に同じ日付の登録が存在します。<br>"; |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | return $arrErr; |
---|
| 249 | } |
---|
[17073] | 250 | } |
---|
| 251 | ?> |
---|