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