| 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 |
---|
| 25 | require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.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_Ex { |
---|
| 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->tpl_mainpage = 'products/review.tpl'; |
---|
| 63 | $this->httpCacheControl('nocache'); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | /** |
---|
| 67 | * Page のプロセス. |
---|
| 68 | */ |
---|
| 69 | function process() { |
---|
| 70 | parent::process(); |
---|
| 71 | $this->action(); |
---|
| 72 | $this->sendResponse(); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | /** |
---|
| 76 | * Page のAction. |
---|
| 77 | * |
---|
| 78 | * @return void |
---|
| 79 | */ |
---|
| 80 | function action() { |
---|
| 81 | $objFormParam = new SC_FormParam_Ex(); |
---|
| 82 | $this->lfInitParam($objFormParam); |
---|
| 83 | $objFormParam->setParam($_POST); |
---|
| 84 | $objFormParam->convParam(); |
---|
| 85 | |
---|
| 86 | switch ($this->getMode()){ |
---|
| 87 | case 'confirm': |
---|
| 88 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
| 89 | |
---|
| 90 | //エラーチェック |
---|
| 91 | if (empty($this->arrErr)) { |
---|
| 92 | //重複タイトルでない |
---|
| 93 | $this->tpl_mainpage = 'products/review_confirm.tpl'; |
---|
| 94 | } |
---|
| 95 | break; |
---|
| 96 | |
---|
| 97 | case 'return': |
---|
| 98 | break; |
---|
| 99 | |
---|
| 100 | case 'complete': |
---|
| 101 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
| 102 | //エラーチェック |
---|
| 103 | if (empty($this->arrErr)) { |
---|
| 104 | //登録実行 |
---|
| 105 | $this->lfRegistRecommendData($objFormParam); |
---|
| 106 | |
---|
| 107 | //レビュー書き込み完了ページへ |
---|
| 108 | SC_Response_Ex::sendRedirect('review_complete.php'); |
---|
| 109 | exit; |
---|
| 110 | } |
---|
| 111 | break; |
---|
| 112 | |
---|
| 113 | default: |
---|
| 114 | // 最初のproduct_idは、$_GETで渡ってくる。 |
---|
| 115 | $objFormParam->setParam($_GET); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | $this->arrForm = $objFormParam->getHashArray(); |
---|
| 119 | |
---|
| 120 | //商品名の取得 |
---|
| 121 | $this->arrForm['name'] = $this->lfGetProductName($this->arrForm['product_id']); |
---|
| 122 | if (empty($this->arrForm['name'])) { |
---|
| 123 | SC_Utils_Ex::sfDispSiteError(PAGE_ERROR); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | $this->setTemplate($this->tpl_mainpage); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /** |
---|
| 130 | * デストラクタ. |
---|
| 131 | * |
---|
| 132 | * @return void |
---|
| 133 | */ |
---|
| 134 | function destroy() { |
---|
| 135 | parent::destroy(); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | /** |
---|
| 139 | * パラメータ情報の初期化を行う. |
---|
| 140 | * |
---|
| 141 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 142 | * @return void |
---|
| 143 | */ |
---|
| 144 | function lfInitParam(&$objFormParam) { |
---|
| 145 | $objFormParam->addParam("レビューID", "review_id", INT_LEN, 'aKV'); |
---|
| 146 | $objFormParam->addParam("商品ID", "product_id", INT_LEN, 'n', array("NUM_CHECK","EXIST_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 147 | $objFormParam->addParam("投稿者名", "reviewer_name", STEXT_LEN, 'aKV', array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 148 | $objFormParam->addParam("投稿者URL", "reviewer_url", MTEXT_LEN, 'a', array("NO_SPTAB", "SPTAB_CHECK", "MAX_LENGTH_CHECK", "URL_CHECK")); |
---|
| 149 | $objFormParam->addParam("性別", 'sex', INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 150 | $objFormParam->addParam("おすすめレベル", "recommend_level", INT_LEN, 'n', array("EXIST_CHECK", "SELECT_CHECK")); |
---|
| 151 | $objFormParam->addParam("タイトル", 'title', STEXT_LEN, 'aKV', array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 152 | $objFormParam->addParam("コメント", 'comment', LTEXT_LEN, 'aKV', array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | /** |
---|
| 156 | * 入力内容のチェックを行う. |
---|
| 157 | * |
---|
| 158 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 159 | * @return array エラーメッセージの配列 |
---|
| 160 | */ |
---|
| 161 | function lfCheckError(&$objFormParam) { |
---|
| 162 | $arrErr = $objFormParam->checkError(); |
---|
| 163 | |
---|
| 164 | $arrForm = $objFormParam->getHashArray(); |
---|
| 165 | |
---|
| 166 | //重複メッセージの判定 |
---|
| 167 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 168 | $flag = $objQuery->count("dtb_review","product_id = ? AND title = ? ", array($arrForm['product_id'], $arrForm['title'])); |
---|
| 169 | if ($flag > 0){ |
---|
| 170 | $arrErr['title'] .= "重複したタイトルは登録できません。"; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | if (REVIEW_ALLOW_URL == false) { |
---|
| 174 | $objErr = new SC_CheckError_Ex($objFormParam->getHashArray()); |
---|
| 175 | // コメント欄へのURLの入力を禁止 |
---|
| 176 | $objErr->doFunc(array('URL', 'comment', $this->arrReviewDenyURL), array("PROHIBITED_STR_CHECK")); |
---|
| 177 | $arrErr += $objErr->arrErr; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | return $arrErr; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | /** |
---|
| 184 | * 商品名を取得 |
---|
| 185 | * |
---|
| 186 | * @param integer $product_id 商品ID |
---|
| 187 | * @return string $product_name 商品名 |
---|
| 188 | */ |
---|
| 189 | function lfGetProductName($product_id) { |
---|
| 190 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 191 | |
---|
| 192 | return $objQuery->get('name', "dtb_products", "product_id = ? ", array($product_id)); |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | //登録実行 |
---|
| 196 | function lfRegistRecommendData (&$objFormParam) { |
---|
| 197 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 198 | $arrRegist = $objFormParam->getDbArray(); |
---|
| 199 | |
---|
| 200 | $arrRegist['create_date'] = 'now()'; |
---|
| 201 | $arrRegist['update_date'] = 'now()'; |
---|
| 202 | $arrRegist['creator_id'] = '0'; |
---|
| 203 | |
---|
| 204 | //-- 登録実行 |
---|
| 205 | $objQuery->begin(); |
---|
| 206 | $arrRegist['review_id'] = $objQuery->nextVal('dtb_review_review_id'); |
---|
| 207 | $objQuery->insert("dtb_review", $arrRegist); |
---|
| 208 | $objQuery->commit(); |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | ?> |
---|