source: branches/version-2_5-dev/data/class/pages/products/LC_Page_Products_Review.php @ 19832

Revision 19832, 9.2 KB checked in by Seasoft, 13 years ago (diff)

#714(パス指定によるリダイレクトの記述を簡潔にする) 共通処理実装、個別処理の一部を実装
#869(create_date, update_date 列の定義が、表やDBによるバラツキがある)

  • NOT NULL 制約により実装漏れに気づいたので修正

#893(SC_Response#reload を使うべきであろう箇所で SC_Response#sendRedirect を利用している)
#628(未使用処理・定義などの削除)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • 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-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
25require_once(CLASS_REALDIR . "pages/LC_Page.php");
26
27/**
28 * お客様の声投稿のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id:LC_Page_Products_Review.php 15532 2007-08-31 14:39:46Z nanasess $
33 */
34class LC_Page_Products_Review extends LC_Page {
35
36    // {{{ properties
37
38    /** おすすめレベル */
39    var $arrRECOMMEND;
40
41    /** 性別 */
42    var $arrSex;
43
44    /** 入力禁止URL */
45    var $arrReviewDenyURL;
46
47    // }}}
48    // {{{ functions
49
50    /**
51     * Page を初期化する.
52     *
53     * @return void
54     */
55    function init() {
56        parent::init();
57
58        $masterData = new SC_DB_MasterData_Ex();
59        $this->arrRECOMMEND = $masterData->getMasterData("mtb_recommend");
60        $this->arrSex = $masterData->getMasterData("mtb_sex");
61        $this->arrReviewDenyURL = $masterData->getMasterData("mtb_review_deny_url");
62        $this->httpCacheControl('nocache');
63    }
64
65    /**
66     * Page のプロセス.
67     */
68    function process() {
69        parent::process();
70        $this->action();
71        $this->sendResponse();
72    }
73
74    /**
75     * Page のAction.
76     *
77     * @return void
78     */
79    function action() {
80        //$objView = new SC_SiteView();
81        $objQuery = new SC_Query();
82
83        if ($_SERVER["REQUEST_METHOD"] == "POST") {
84            if (!SC_Helper_Session_Ex::isValidToken()) {
85                SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, "", true);
86            }
87        }
88
89        //---- 登録用カラム配列
90        $arrRegistColumn = array(
91                                     array(  "column" => "review_id", "convert" => "aKV" ),
92                                     array(  "column" => "product_id", "convert" => "aKV" ),
93                                     array(  "column" => "reviewer_name", "convert" => "aKV" ),
94                                     array(  "column" => "reviewer_url", "convert" => "a"),
95                                     array(  "column" => "sex", "convert" => "n" ),
96                                     array(  "column" => "email", "convert" => "a" ),
97                                     array(  "column" => "recommend_level", "convert" => "n" ),
98                                     array(  "column" => "title", "convert" => "aKV" ),
99                                     array(  "column" => "comment", "convert" => "aKV" ),
100
101                                );
102
103        if (!isset($_POST['mode'])) $_POST['mode'] = "";
104        switch ($_POST['mode']){
105        case 'confirm':
106            $arrForm = $this->lfConvertParam($_POST, $arrRegistColumn);
107            $this->arrErr = $this->lfErrorCheck($arrForm);
108            //重複メッセージの判定
109            $flag = $objQuery->count("dtb_review","product_id = ? AND title = ? ", array($arrForm['product_id'], $arrForm['title']));
110
111            if ($flag > 0){
112                $this->arrErr['title'] .= "重複したタイトルは登録できません。";
113            }
114
115            //エラーチェック
116            if (empty($this->arrErr)) {
117                //重複タイトルでない
118                if($flag == 0){
119                    //商品名の取得
120                    $arrForm['name'] = $objQuery->get("name", "dtb_products", "product_id = ? ", array($arrForm['product_id']));
121                    $this->arrForm = $arrForm;
122                    $this->tpl_mainpage = 'products/review_confirm.tpl';
123                }
124            } else {
125                //商品名の取得
126                $arrForm['name'] = $objQuery->get("name", "dtb_products", "product_id = ? ", array($arrForm['product_id']));
127                $this->arrForm = $arrForm;
128            }
129            break;
130
131        case 'return':
132            foreach($_POST as $key => $val){
133                $this->arrForm[ $key ] = $val;
134            }
135
136            //商品名の取得
137            $this->arrForm['name'] = $objQuery->get("name", "dtb_products", "product_id = ? ", array($this->arrForm['product_id']));
138            if(empty($this->arrForm['name'])) {
139                SC_Utils_Ex::sfDispSiteError(PAGE_ERROR);
140            }
141            break;
142
143        case 'complete':
144            $arrForm = $this->lfConvertParam($_POST, $arrRegistColumn);
145            $arrErr = $this->lfErrorCheck($arrForm);
146            //重複メッセージの判定
147            $flag = $objQuery->count("dtb_review","product_id = ? AND title = ? ", array($arrForm['product_id'], $arrForm['title']));
148            //エラーチェック
149            if (empty($this->arrErr)) {
150                //重複タイトルでない
151                if($flag == 0) {
152                    //登録実行
153                    $this->lfRegistRecommendData($arrForm, $arrRegistColumn);
154                    //レビュー書き込み完了ページへ
155                    SC_Response_Ex::sendRedirect('review_complete.php');
156                    exit;
157                }
158            } else {
159                if($flag > 0) {
160                    SC_Utils_Ex::sfDispSiteError(PAGE_ERROR);
161                }
162            }
163            break;
164
165        default:
166            if(SC_Utils_Ex::sfIsInt($_GET['product_id'])) {
167                //商品情報の取得
168                $arrForm = $objQuery->select("product_id, name", "dtb_products", "del_flg = 0 AND status = 1 AND product_id=?", array($_GET['product_id']));
169                if(empty($arrForm)) {
170                    SC_Utils_Ex::sfDispSiteError(PAGE_ERROR);
171                }
172                $this->arrForm = $arrForm[0];
173            }
174            break;
175
176        }
177
178        $this->transactionid = SC_Helper_Session_Ex::getToken();
179        $this->setTemplate('products/review.tpl');
180    }
181
182    /**
183     * デストラクタ.
184     *
185     * @return void
186     */
187    function destroy() {
188        parent::destroy();
189    }
190
191    //エラーチェック
192
193    function lfErrorCheck() {
194        $objErr = new SC_CheckError();
195        $objErr->doFunc(array("商品ID", "product_id", INT_LEN), array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
196        $objErr->doFunc(array("投稿者名", "reviewer_name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
197        $objErr->doFunc(array("投稿者URL", "reviewer_url", MTEXT_LEN), array("NO_SPTAB", "SPTAB_CHECK", "MAX_LENGTH_CHECK", "URL_CHECK"));
198        $objErr->doFunc(array("おすすめレベル", "recommend_level"), array("SELECT_CHECK"));
199        $objErr->doFunc(array("タイトル", "title", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
200        $objErr->doFunc(array("コメント", "comment", LTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
201
202        if (REVIEW_ALLOW_URL == false) {
203            // コメント欄へのURLの入力を禁止
204            $objErr->doFunc(array("URL", "comment", $this->arrReviewDenyURL), array("PROHIBITED_STR_CHECK"));
205        }
206
207        return $objErr->arrErr;
208    }
209
210    //---- 取得文字列の変換
211    function lfConvertParam($array, $arrRegistColumn) {
212        /*
213         *  文字列の変換
214         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
215         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
216         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
217         *  n :  「全角」数字を「半角(ハンカク)」に変換
218         *  a :  全角英数字を半角英数字に変換する
219         */
220        // カラム名とコンバート情報
221        foreach ($arrRegistColumn as $data) {
222            $arrConvList[ $data["column"] ] = $data["convert"];
223        }
224        // 文字変換
225        foreach ($arrConvList as $key => $val) {
226            // POSTされてきた値のみ変換する。
227            if(!empty($array[$key])) {
228                $array[$key] = mb_convert_kana($array[$key] ,$val);
229            }
230        }
231        return $array;
232    }
233
234    //登録実行
235    function lfRegistRecommendData ($array, $arrRegistColumn) {
236        // 仮登録
237        foreach ($arrRegistColumn as $data) {
238            if (strlen($array[ $data["column"] ]) > 0 ) {
239                $arrRegist[ $data["column"] ] = $array[ $data["column"] ];
240            }
241        }
242        $arrRegist['create_date'] = 'now()';
243        $arrRegist['update_date'] = 'now()';
244        $arrRegist['creator_id'] = '0';
245        //-- 登録実行
246        $objQuery = new SC_Query();
247        $objQuery->begin();
248        $arrRegist['review_id'] = $objQuery->nextVal('dtb_review_review_id');
249        $objQuery->insert("dtb_review", $arrRegist);
250        $objQuery->commit();
251    }
252}
253?>
Note: See TracBrowser for help on using the repository browser.