source: branches/version-2_5-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_Kiyaku.php @ 20764

Revision 20764, 7.7 KB checked in by nanasess, 13 years ago (diff)

#601 (コピーライトの更新)

  • 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-2011 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_Kiyaku 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/kiyaku.tpl';
47        $this->tpl_subnavi = 'basis/subnavi.tpl';
48        $this->tpl_subno = 'kiyaku';
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        $objDb = new SC_Helper_DB_Ex();
70
71        $mode = $this->getMode();
72
73        if (!empty($_POST)) {
74            $objFormParam = new SC_FormParam_Ex();
75            $this->lfInitParam($mode, $objFormParam);
76            $objFormParam->setParam($_POST);
77            $objFormParam->convParam();
78            $kiyaku_id = $objFormParam->getValue('kiyaku_id');
79
80            $this->arrErr = $this->lfCheckError($mode, $objFormParam);
81            if (!empty($this->arrErr['kiyaku_id'])) {
82                SC_Utils_Ex::sfDispException();
83                return;
84            }
85            $post = $objFormParam->getHashArray();
86        }
87
88        // 要求判定
89        switch($mode) {
90        // 編集処理
91        case 'edit':
92            // POST値の引き継ぎ
93            $this->arrForm = $_POST;
94
95            if(count($this->arrErr) <= 0) {
96                if($post['kiyaku_id'] == "") {
97                    $this->lfInsertClass($this->arrForm, $_SESSION['member_id']);    // 新規作成
98                } else {
99                    $this->lfUpdateClass($this->arrForm, $post['kiyaku_id']);    // 既存編集
100                }
101                // 再表示
102                $this->objDisplay->reload();
103            } else {
104                // POSTデータを引き継ぐ
105                $this->tpl_kiyaku_id = $post['kiyaku_id'];
106            }
107            break;
108        // 削除
109        case 'delete':
110            $objDb->sfDeleteRankRecord("dtb_kiyaku", "kiyaku_id", $post['kiyaku_id'], "", true);
111            // 再表示
112            $this->objDisplay->reload();
113            break;
114        // 編集前処理
115        case 'pre_edit':
116            // 編集項目を取得する。
117            $arrKiyakuData = $this->lfGetKiyakuDataByKiyakuID($post['kiyaku_id']);
118
119            // 入力項目にカテゴリ名を入力する。
120            $this->arrForm['kiyaku_title'] = $arrKiyakuData[0]['kiyaku_title'];
121            $this->arrForm['kiyaku_text'] = $arrKiyakuData[0]['kiyaku_text'];
122            // POSTデータを引き継ぐ
123            $this->tpl_kiyaku_id = $post['kiyaku_id'];
124        break;
125        case 'down':
126            $objDb->sfRankDown("dtb_kiyaku", "kiyaku_id", $post['kiyaku_id']);
127            // 再表示
128            $this->objDisplay->reload();
129            break;
130        case 'up':
131            $objDb->sfRankUp("dtb_kiyaku", "kiyaku_id", $post['kiyaku_id']);
132            // 再表示
133            $this->objDisplay->reload();
134            break;
135        default:
136            break;
137        }
138
139        $this->arrKiyaku = $this->lfGetKiyakuList();
140        // POSTデータを引き継ぐ
141        $this->tpl_kiyaku_id = $kiyaku_id;
142    }
143
144    /**
145     * デストラクタ.
146     *
147     * @return void
148     */
149    function destroy() {
150        parent::destroy();
151    }
152
153    /* DBへの挿入 */
154    function lfInsertClass($arrData, $member_id) {
155        $objQuery =& SC_Query_Ex::getSingletonInstance();
156        // INSERTする値を作成する。
157        $sqlval['kiyaku_title'] = $arrData['kiyaku_title'];
158        $sqlval['kiyaku_text'] = $arrData['kiyaku_text'];
159        $sqlval['creator_id'] = $member_id;
160        $sqlval['rank'] = $objQuery->max('rank', "dtb_kiyaku") + 1;
161        $sqlval['update_date'] = "Now()";
162        $sqlval['create_date'] = "Now()";
163        // INSERTの実行
164        $sqlval['kiyaku_id'] = $objQuery->nextVal('dtb_kiyaku_kiyaku_id');
165        $ret = $objQuery->insert("dtb_kiyaku", $sqlval);
166        return $ret;
167    }
168
169    function lfGetKiyakuDataByKiyakuID($kiyaku_id) {
170        $objQuery =& SC_Query_Ex::getSingletonInstance();
171
172        $where = "kiyaku_id = ?";
173        return $objQuery->select("kiyaku_text, kiyaku_title", "dtb_kiyaku", $where, array($kiyaku_id));
174    }
175
176    function lfGetKiyakuList() {
177        $objQuery =& SC_Query_Ex::getSingletonInstance();
178
179        $where = "del_flg <> 1";
180        $objQuery->setOrder("rank DESC");
181        return $objQuery->select("kiyaku_title, kiyaku_text, kiyaku_id", "dtb_kiyaku", $where);
182    }
183
184    /* DBへの更新 */
185    function lfUpdateClass($arrData, $kiyaku_id) {
186        $objQuery =& SC_Query_Ex::getSingletonInstance();
187        // UPDATEする値を作成する。
188        $sqlval['kiyaku_title'] = $arrData['kiyaku_title'];
189        $sqlval['kiyaku_text'] = $arrData['kiyaku_text'];
190        $sqlval['update_date'] = "Now()";
191        $where = "kiyaku_id = ?";
192        // UPDATEの実行
193        $ret = $objQuery->update("dtb_kiyaku", $sqlval, $where, array($kiyaku_id));
194        return $ret;
195    }
196
197    function lfInitParam($mode, &$objFormParam) {
198        switch ($mode) {
199            case 'edit':
200                $objFormParam->addParam('規約タイトル', 'kiyaku_title', SMTEXT_LEN, 'KVa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
201                $objFormParam->addParam('規約内容', 'kiyaku_text', MLTEXT_LEN, 'KVa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
202            case 'delete':
203            case 'pre_edit':
204            case 'down':
205            case 'up':
206                $objFormParam->addParam('規約ID', 'kiyaku_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
207                break;
208            default:
209                break;
210        }
211    }
212
213    /**
214     * 入力エラーチェック
215     *
216     * @param string $mode
217     * @return array
218     */
219    function lfCheckError($mode, $objFormParam) {
220        $arrErr = $objFormParam->checkError();
221        if(!isset($arrErr['name']) && $mode == 'edit') {
222            $post = $objFormParam->getHashArray();
223            $objQuery =& SC_Query_Ex::getSingletonInstance();
224            $arrRet = $objQuery->select("kiyaku_id, kiyaku_title", "dtb_kiyaku", "del_flg = 0 AND kiyaku_title = ?", array($post['kiyaku_title']));
225            // 編集中のレコード以外に同じ名称が存在する場合
226            if ($arrRet[0]['kiyaku_id'] != $post['kiyaku_id'] && $arrRet[0]['kiyaku_title'] == $post['kiyaku_title']) {
227                $arrErr['name'] = "※ 既に同じ内容の登録が存在します。<br>";
228            }
229        }
230        return $arrErr;
231    }
232}
233?>
Note: See TracBrowser for help on using the repository browser.