source: branches/version-2_12-multilang/data/class/pages/admin/basis/LC_Page_Admin_Basis_Holiday.php @ 22496

Revision 22496, 8.6 KB checked in by m_uehara, 11 years ago (diff)

#2084 メッセージIDの振り直し

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2012 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
25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
26
27/**
28 * 定休日管理のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Basis_Holiday extends LC_Page_Admin_Ex {
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_subno = 'holiday';
48        $this->tpl_maintitle = t('c_Basic information_01');
49        $this->tpl_subtitle = t('LC_Page_Admin_Basis_Holiday_002');
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
70        $objDb = new SC_Helper_DB_Ex();
71
72        $objDate = new SC_Date_Ex();
73        $this->arrMonth = $objDate->getMonth();
74        $this->arrDay = $objDate->getDay();
75
76        $mode = $this->getMode();
77
78        if (!empty($_POST)) {
79
80            $objFormParam = new SC_FormParam_Ex();
81            $this->lfInitParam($mode, $objFormParam);
82            $objFormParam->setParam($_POST);
83            $objFormParam->convParam();
84            $holiday_id = $objFormParam->getValue('holiday_id');
85
86            $this->arrErr = $this->lfCheckError($mode, $objFormParam);
87            if (!empty($this->arrErr['holiday_id'])) {
88                trigger_error('', E_USER_ERROR);
89                return;
90            }
91
92            $post = $objFormParam->getHashArray();
93        }
94
95        // 要求判定
96        switch ($mode) {
97            // 編集処理
98            case 'edit':
99                // POST値の引き継ぎ
100                $this->arrForm = $this->arrForm = $_POST;
101
102                if (count($this->arrErr) <= 0) {
103                    // 新規作成
104                    if ($post['holiday_id'] == '') {
105                        $this->lfInsertClass($this->arrForm, $_SESSION['member_id']);
106                    }
107                    // 既存編集
108                    else {
109                        $this->lfUpdateClass($this->arrForm, $post['holiday_id']);
110                    }
111
112                    // 再表示
113                    $this->objDisplay->reload();
114                } else {
115                    // POSTデータを引き継ぐ
116                    $this->tpl_holiday_id = $post['holiday_id'];
117                }
118                break;
119            // 削除
120            case 'delete':
121                $objDb->sfDeleteRankRecord('dtb_holiday', 'holiday_id', $post['holiday_id'], '', true);
122
123                // 再表示
124                $this->objDisplay->reload();
125                break;
126            // 編集前処理
127            case 'pre_edit':
128                // 編集項目を取得する。
129                $arrHolidayData = $this->lfGetHolidayDataByHolidayID($post['holiday_id']);
130
131                // 入力項目にカテゴリ名を入力する。
132                $this->arrForm['title'] = $arrHolidayData[0]['title'];
133                $this->arrForm['month'] = $arrHolidayData[0]['month'];
134                $this->arrForm['day'] = $arrHolidayData[0]['day'];
135                // POSTデータを引き継ぐ
136                $this->tpl_holiday_id = $post['holiday_id'];
137                break;
138            case 'down':
139                $objDb->sfRankDown('dtb_holiday', 'holiday_id', $post['holiday_id']);
140
141                // 再表示
142                $this->objDisplay->reload();
143                break;
144            case 'up':
145                $objDb->sfRankUp('dtb_holiday', 'holiday_id', $post['holiday_id']);
146
147                // 再表示
148                $this->objDisplay->reload();
149                break;
150            default:
151                break;
152        }
153
154        $this->arrHoliday = $this->lfGetHolidayList();
155        // POSTデータを引き継ぐ
156        $this->tpl_holiday_id = $holiday_id;
157
158    }
159
160    /**
161     * デストラクタ.
162     *
163     * @return void
164     */
165    function destroy() {
166        parent::destroy();
167    }
168
169    function lfGetHolidayDataByHolidayID($holiday_id) {
170        $objQuery =& SC_Query_Ex::getSingletonInstance();
171
172        $where = 'holiday_id = ?';
173        return $objQuery->select('title, month, day', 'dtb_holiday', $where, array($holiday_id));
174    }
175
176    function lfGetHolidayList() {
177        $objQuery =& SC_Query_Ex::getSingletonInstance();
178
179        $where = 'del_flg <> 1';
180        $objQuery->setOrder('rank DESC');
181        return $objQuery->select('holiday_id, title, month, day', 'dtb_holiday', $where);
182    }
183
184    /* DBへの挿入 */
185    function lfInsertClass($arrData, $member_id) {
186        $objQuery =& SC_Query_Ex::getSingletonInstance();
187        // INSERTする値を作成する。
188        $sqlval['title'] = $arrData['title'];
189        $sqlval['month'] = $arrData['month'];
190        $sqlval['day'] = $arrData['day'];
191        $sqlval['creator_id'] = $member_id;
192        $sqlval['rank'] = $objQuery->max('rank', 'dtb_holiday') + 1;
193        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
194        $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
195        // INSERTの実行
196        $sqlval['holiday_id'] = $objQuery->nextVal('dtb_holiday_holiday_id');
197        $ret = $objQuery->insert('dtb_holiday', $sqlval);
198        return $ret;
199    }
200
201    /* DBへの更新 */
202    function lfUpdateClass($arrData) {
203        $objQuery =& SC_Query_Ex::getSingletonInstance();
204        // UPDATEする値を作成する。
205        $sqlval['title'] = $arrData['title'];
206        $sqlval['month'] = $arrData['month'];
207        $sqlval['day'] = $arrData['day'];
208        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
209        $where = 'holiday_id = ?';
210        // UPDATEの実行
211        $ret = $objQuery->update('dtb_holiday', $sqlval, $where, array($arrData['holiday_id']));
212        return $ret;
213    }
214
215    function lfInitParam($mode, &$objFormParam) {
216        switch ($mode) {
217            case 'edit':
218                $objFormParam->addParam(t('c_Title_01'), 'title', STEXT_LEN, 'KVa', array('EXIST_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK'));
219                $objFormParam->addParam(t('c_Month_01'), 'month', INT_LEN, 'n', array('SELECT_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK'));
220                $objFormParam->addParam(t('c_Day_01'), 'day', INT_LEN, 'n', array('SELECT_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK'));
221                // breakしない
222            case 'delete':
223            case 'pre_edit':
224            case 'down':
225            case 'up':
226                $objFormParam->addParam(t('c_Regular holiday ID_01'), 'holiday_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
227                break;
228            default:
229                break;
230        }
231    }
232
233    /**
234     * 入力エラーチェック
235     *
236     * @param string $mode
237     * @return array
238     */
239    function lfCheckError($mode, &$objFormParam) {
240        $objFormParam->convParam();
241        $arrErr = $objFormParam->checkError();
242        $post = $objFormParam->getHashArray();
243
244        if (!isset($arrErr['date'])) {
245            $objQuery =& SC_Query_Ex::getSingletonInstance();
246            $where = 'del_flg = 0 AND month = ? AND day = ?';
247            $arrWhereVal = array($post['month'], $post['day']);
248            if (!empty($post['holiday_id'])) {
249                $where .= ' AND holiday_id <> ?';
250                $arrWhereVal[] = $post['holiday_id'];
251            }
252            $arrRet = $objQuery->select('count(holiday_id) as count', 'dtb_holiday', $where, $arrWhereVal);
253
254            // 編集中のレコード以外に同じ日付が存在する場合
255            if ($arrRet[0]['count'] > 0) {
256                $arrErr['date'] = t('LC_Page_Admin_Basis_Holiday_003');
257            }
258        }
259        return $arrErr;
260    }
261}
Note: See TracBrowser for help on using the repository browser.