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