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