1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
---|
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 |
---|
25 | require_once(CLASS_PATH . "pages/admin/LC_Page_Admin.php"); |
---|
26 | |
---|
27 | /** |
---|
28 | * 定休日管理のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id: LC_Page_Admin_Basis_Holiday.php 16741 2007-11-08 00:43:24Z adachi $ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_Basis_Holiday extends LC_Page_Admin { |
---|
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'; |
---|
49 | $this->tpl_subtitle = '定休日管理'; |
---|
50 | $this->tpl_mainno = 'basis'; |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Page のプロセス. |
---|
55 | * |
---|
56 | * @return void |
---|
57 | */ |
---|
58 | function process() { |
---|
59 | $this->action(); |
---|
60 | $this->sendResponse(); |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | * Page のアクション. |
---|
65 | * |
---|
66 | * @return void |
---|
67 | */ |
---|
68 | function action() { |
---|
69 | $objSess = new SC_Session(); |
---|
70 | $objQuery = new SC_Query(); |
---|
71 | $objDb = new SC_Helper_DB_Ex(); |
---|
72 | |
---|
73 | $objDate = new SC_Date(); |
---|
74 | $this->arrMonth = $objDate->getMonth(); |
---|
75 | $this->arrDay = $objDate->getDay(); |
---|
76 | |
---|
77 | // 認証可否の判定 |
---|
78 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
79 | |
---|
80 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
81 | |
---|
82 | // 要求判定 |
---|
83 | switch($_POST['mode']) { |
---|
84 | // 編集処理 |
---|
85 | case 'edit': |
---|
86 | // POST値の引き継ぎ |
---|
87 | $this->arrForm = $_POST; |
---|
88 | // 入力文字の変換 |
---|
89 | $this->arrForm = $this->lfConvertParam($this->arrForm); |
---|
90 | |
---|
91 | // エラーチェック |
---|
92 | $this->arrErr = $this->lfErrorCheck(); |
---|
93 | if(count($this->arrErr) <= 0) { |
---|
94 | if($_POST['holiday_id'] == "") { |
---|
95 | $this->lfInsertClass($this->arrForm); // 新規作成 |
---|
96 | } else { |
---|
97 | $this->lfUpdateClass($this->arrForm); // 既存編集 |
---|
98 | } |
---|
99 | // 再表示 |
---|
100 | $this->objDisplay->reload(); |
---|
101 | } else { |
---|
102 | // POSTデータを引き継ぐ |
---|
103 | $this->tpl_holiday_id = $_POST['holiday_id']; |
---|
104 | } |
---|
105 | break; |
---|
106 | // 削除 |
---|
107 | case 'delete': |
---|
108 | $objDb->sfDeleteRankRecord("dtb_holiday", "holiday_id", $_POST['holiday_id'], "", true); |
---|
109 | // 再表示 |
---|
110 | $this->objDisplay->reload(); |
---|
111 | break; |
---|
112 | // 編集前処理 |
---|
113 | case 'pre_edit': |
---|
114 | // 編集項目をDBより取得する。 |
---|
115 | $where = "holiday_id = ?"; |
---|
116 | $arrRet = $objQuery->select("title, month, day", "dtb_holiday", $where, array($_POST['holiday_id'])); |
---|
117 | // 入力項目にカテゴリ名を入力する。 |
---|
118 | $this->arrForm['title'] = $arrRet[0]['title']; |
---|
119 | $this->arrForm['month'] = $arrRet[0]['month']; |
---|
120 | $this->arrForm['day'] = $arrRet[0]['day']; |
---|
121 | // POSTデータを引き継ぐ |
---|
122 | $this->tpl_holiday_id = $_POST['holiday_id']; |
---|
123 | break; |
---|
124 | case 'down': |
---|
125 | $objDb->sfRankDown("dtb_holiday", "holiday_id", $_POST['holiday_id']); |
---|
126 | // 再表示 |
---|
127 | $this->objDisplay->reload(); |
---|
128 | break; |
---|
129 | case 'up': |
---|
130 | $objDb->sfRankUp("dtb_holiday", "holiday_id", $_POST['holiday_id']); |
---|
131 | // 再表示 |
---|
132 | $this->objDisplay->reload(); |
---|
133 | break; |
---|
134 | default: |
---|
135 | break; |
---|
136 | } |
---|
137 | |
---|
138 | // 規格の読込 |
---|
139 | $where = "del_flg <> 1"; |
---|
140 | $objQuery->setOrder("rank DESC"); |
---|
141 | $this->arrHoliday = $objQuery->select("holiday_id, title, month, day", "dtb_holiday", $where); |
---|
142 | } |
---|
143 | |
---|
144 | /** |
---|
145 | * デストラクタ. |
---|
146 | * |
---|
147 | * @return void |
---|
148 | */ |
---|
149 | function destroy() { |
---|
150 | parent::destroy(); |
---|
151 | } |
---|
152 | |
---|
153 | /* DBへの挿入 */ |
---|
154 | function lfInsertClass($arrData) { |
---|
155 | $objQuery = new SC_Query(); |
---|
156 | // INSERTする値を作成する。 |
---|
157 | $sqlval['title'] = $arrData['title']; |
---|
158 | $sqlval['month'] = $arrData['month']; |
---|
159 | $sqlval['day'] = $arrData['day']; |
---|
160 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
161 | $sqlval['rank'] = $objQuery->max("rank", "dtb_holiday") + 1; |
---|
162 | $sqlval['update_date'] = "Now()"; |
---|
163 | $sqlval['create_date'] = "Now()"; |
---|
164 | // INSERTの実行 |
---|
165 | $sqlval['holiday_id'] = $objQuery->nextVal('dtb_holiday_holiday_id'); |
---|
166 | $ret = $objQuery->insert("dtb_holiday", $sqlval); |
---|
167 | return $ret; |
---|
168 | } |
---|
169 | |
---|
170 | /* DBへの更新 */ |
---|
171 | function lfUpdateClass($arrData) { |
---|
172 | $objQuery = new SC_Query(); |
---|
173 | // UPDATEする値を作成する。 |
---|
174 | $sqlval['title'] = $arrData['title']; |
---|
175 | $sqlval['month'] = $arrData['month']; |
---|
176 | $sqlval['day'] = $arrData['day']; |
---|
177 | $sqlval['update_date'] = "Now()"; |
---|
178 | $where = "holiday_id = ?"; |
---|
179 | // UPDATEの実行 |
---|
180 | $ret = $objQuery->update("dtb_holiday", $sqlval, $where, array($_POST['holiday_id'])); |
---|
181 | return $ret; |
---|
182 | } |
---|
183 | |
---|
184 | /* 取得文字列の変換 */ |
---|
185 | function lfConvertParam($array) { |
---|
186 | // 文字変換 |
---|
187 | $arrConvList['title'] = "KVa"; |
---|
188 | $arrConvList['month'] = "n"; |
---|
189 | $arrConvList['day'] = "n"; |
---|
190 | |
---|
191 | foreach ($arrConvList as $key => $val) { |
---|
192 | // POSTされてきた値のみ変換する。 |
---|
193 | if(isset($array[$key])) { |
---|
194 | $array[$key] = mb_convert_kana($array[$key] ,$val); |
---|
195 | } |
---|
196 | } |
---|
197 | return $array; |
---|
198 | } |
---|
199 | |
---|
200 | /* 入力エラーチェック */ |
---|
201 | function lfErrorCheck() { |
---|
202 | $objErr = new SC_CheckError(); |
---|
203 | $objErr->doFunc(array("タイトル", "title", SMTEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK")); |
---|
204 | $objErr->doFunc(array("月", "month", INT_LEN), array("SELECT_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK")); |
---|
205 | $objErr->doFunc(array("日", "day", INT_LEN), array("SELECT_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK")); |
---|
206 | if(!isset($objErr->arrErr['date'])) { |
---|
207 | $objQuery = new SC_Query(); |
---|
208 | $where = "del_flg = 0 AND month = ? AND day = ?"; |
---|
209 | $arrval = array($_POST['month'], $_POST['day']); |
---|
210 | if (!empty($_POST['holiday_id'])) { |
---|
211 | $where .= " AND holiday_id <> ?"; |
---|
212 | $arrval[] = $_POST['holiday_id']; |
---|
213 | } |
---|
214 | $arrRet = $objQuery->select("count(holiday_id)", "dtb_holiday", $where, $arrval); |
---|
215 | // 編集中のレコード以外に同じ日付が存在する場合 |
---|
216 | if ($arrRet[0]['count'] > 0) { |
---|
217 | $objErr->arrErr['date'] = "※ 既に同じ日付の登録が存在します。<br>"; |
---|
218 | } |
---|
219 | } |
---|
220 | return $objErr->arrErr; |
---|
221 | } |
---|
222 | } |
---|
223 | ?> |
---|