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