source: branches/version-2_13-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_Holiday.php @ 23434

Revision 23434, 6.5 KB checked in by pineray, 10 years ago (diff)

#2393 閏年の処理を修正

  • 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-2013 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
24require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
25
26/**
27 * 定休日管理のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Admin_Basis_Holiday extends LC_Page_Admin_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        parent::init();
43        $this->tpl_mainpage = 'basis/holiday.tpl';
44        $this->tpl_subno = 'holiday';
45        $this->tpl_maintitle = '基本情報管理';
46        $this->tpl_subtitle = '定休日管理';
47        $this->tpl_mainno = 'basis';
48    }
49
50    /**
51     * Page のプロセス.
52     *
53     * @return void
54     */
55    public function process()
56    {
57        $this->action();
58        $this->sendResponse();
59    }
60
61    /**
62     * Page のアクション.
63     *
64     * @return void
65     */
66    public function action()
67    {
68        $objHoliday = new SC_Helper_Holiday_Ex();
69
70        $objDate = new SC_Date_Ex();
71        $this->arrMonth = $objDate->getMonth();
72        $this->arrDay = $objDate->getDay();
73
74        $mode = $this->getMode();
75
76        $objFormParam = new SC_FormParam_Ex();
77        $this->lfInitParam($mode, $objFormParam);
78        $objFormParam->setParam($_POST);
79        $objFormParam->convParam();
80
81        $holiday_id = $objFormParam->getValue('holiday_id');
82
83        // 要求判定
84        switch ($mode) {
85            // 編集処理
86            case 'edit':
87                $this->arrErr = $this->lfCheckError($objFormParam, $objHoliday);
88                if (!SC_Utils_Ex::isBlank($this->arrErr['holiday_id'])) {
89                    trigger_error('', E_USER_ERROR);
90
91                    return;
92                }
93
94                if (count($this->arrErr) <= 0) {
95                    // POST値の引き継ぎ
96                    $arrParam = $objFormParam->getHashArray();
97                    // 登録実行
98                    $res_holiday_id = $this->doRegist($holiday_id, $arrParam, $objHoliday);
99                    if ($res_holiday_id !== FALSE) {
100                        // 完了メッセージ
101                        $holiday_id = $res_holiday_id;
102                        $this->tpl_onload = "alert('登録が完了しました。');";
103                    }
104                }
105                // POSTデータを引き継ぐ
106                $this->tpl_holiday_id = $holiday_id;
107
108                break;
109            // 削除
110            case 'delete':
111                $objHoliday->delete($holiday_id);
112                break;
113            // 編集前処理
114            case 'pre_edit':
115                // 編集項目を取得する。
116                $arrHolidayData = $objHoliday->get($holiday_id);
117                $objFormParam->setParam($arrHolidayData);
118
119                // POSTデータを引き継ぐ
120                $this->tpl_holiday_id = $holiday_id;
121                break;
122            case 'down':
123                $objHoliday->rankDown($holiday_id);
124
125                // 再表示
126                $this->objDisplay->reload();
127                break;
128            case 'up':
129                $objHoliday->rankUp($holiday_id);
130
131                // 再表示
132                $this->objDisplay->reload();
133                break;
134            default:
135                break;
136        }
137
138        $this->arrForm = $objFormParam->getFormParamList();
139
140        $this->arrHoliday = $objHoliday->getList();
141    }
142
143    /**
144     * 登録処理を実行.
145     *
146     * @param  integer  $holiday_id
147     * @param  array    $sqlval
148     * @param  object   $objHoliday
149     * @return multiple
150     */
151    public function doRegist($holiday_id, $sqlval, SC_Helper_Holiday_Ex $objHoliday)
152    {
153        $sqlval['holiday_id'] = $holiday_id;
154        $sqlval['creator_id'] = $_SESSION['member_id'];
155
156        return $objHoliday->save($sqlval);
157    }
158
159    public function lfInitParam($mode, &$objFormParam)
160    {
161        switch ($mode) {
162            case 'edit':
163            case 'pre_edit':
164                $objFormParam->addParam('タイトル', 'title', STEXT_LEN, 'KVa', array('EXIST_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK'));
165                $objFormParam->addParam('月', 'month', INT_LEN, 'n', array('SELECT_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK'));
166                $objFormParam->addParam('日', 'day', INT_LEN, 'n', array('SELECT_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK'));
167                $objFormParam->addParam('定休日ID', 'holiday_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
168                break;
169            case 'delete':
170            case 'down':
171            case 'up':
172            default:
173                $objFormParam->addParam('定休日ID', 'holiday_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
174                break;
175        }
176    }
177
178    /**
179     * 入力エラーチェック
180     *
181     * @param  object $objFormParam
182     * @param  object $objHoliday
183     * @return array
184     */
185    public function lfCheckError(&$objFormParam, SC_Helper_Holiday_Ex &$objHoliday)
186    {
187        $arrErr = $objFormParam->checkError();
188        $arrForm = $objFormParam->getHashArray();
189
190        // 日付の妥当性チェック
191        // 閏年への対応.
192        if ($arrForm['month'] == 2 && $arrForm['day'] == 29) {
193            $valid_date = true;
194        } else {
195            $valid_date = checkdate($arrForm['month'], $arrForm['day'], date('Y'));
196        }
197        if (!$valid_date) {
198            $arrErr['date'] = '※ 妥当な日付ではありません。<br />';
199        }
200
201        // 編集中のレコード以外に同じ日付が存在する場合
202        if ($objHoliday->isDateExist($arrForm['month'], $arrForm['day'], $arrForm['holiday_id'])) {
203            $arrErr['date'] = '※ 既に同じ日付の登録が存在します。<br />';
204        }
205
206        return $arrErr;
207    }
208}
Note: See TracBrowser for help on using the repository browser.