| 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_PATH . "pages/LC_Page.php"); |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * アンケート管理 のページクラス. |
|---|
| 29 | * |
|---|
| 30 | * @package Page |
|---|
| 31 | * @author LOCKON CO.,LTD. |
|---|
| 32 | * @version $Id$ |
|---|
| 33 | */ |
|---|
| 34 | class LC_Page_Admin_Contents_Inquiry extends LC_Page { |
|---|
| 35 | |
|---|
| 36 | // }}} |
|---|
| 37 | // {{{ functions |
|---|
| 38 | |
|---|
| 39 | /** |
|---|
| 40 | * Page を初期化する. |
|---|
| 41 | * |
|---|
| 42 | * @return void |
|---|
| 43 | */ |
|---|
| 44 | function init() { |
|---|
| 45 | parent::init(); |
|---|
| 46 | $this->tpl_mainpage = 'contents/inquiry.tpl'; |
|---|
| 47 | $this->tpl_mainno = 'contents'; |
|---|
| 48 | $this->tpl_subnavi = 'contents/subnavi.tpl'; |
|---|
| 49 | $this->tpl_subno = "inquiry"; |
|---|
| 50 | $this->tpl_subtitle = 'アンケート管理'; |
|---|
| 51 | $this->arrCVSCOL = array( |
|---|
| 52 | |
|---|
| 53 | ); |
|---|
| 54 | |
|---|
| 55 | $this->arrCVSTITLE = array( |
|---|
| 56 | '回答ID', |
|---|
| 57 | '質問ID', |
|---|
| 58 | '回答日時', |
|---|
| 59 | 'アンケートタイトル', |
|---|
| 60 | '顧客名1', |
|---|
| 61 | '顧客名2', |
|---|
| 62 | '顧客名カナ1', |
|---|
| 63 | '顧客名カナ2', |
|---|
| 64 | '郵便番号1', |
|---|
| 65 | '郵便番号2', |
|---|
| 66 | '都道府県', |
|---|
| 67 | '住所1', |
|---|
| 68 | '住所2', |
|---|
| 69 | '電話番号1', |
|---|
| 70 | '電話番号2', |
|---|
| 71 | '電話番号3', |
|---|
| 72 | 'メールアドレス', |
|---|
| 73 | '回答1', |
|---|
| 74 | '回答2', |
|---|
| 75 | '回答3', |
|---|
| 76 | '回答4', |
|---|
| 77 | '回答5', |
|---|
| 78 | '回答6' |
|---|
| 79 | ); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | /** |
|---|
| 83 | * Page のプロセス. |
|---|
| 84 | * |
|---|
| 85 | * @return void |
|---|
| 86 | */ |
|---|
| 87 | function process() { |
|---|
| 88 | $objQuery = new SC_Query(); |
|---|
| 89 | $objView = new SC_AdminView(); |
|---|
| 90 | $objSess = new SC_Session(); |
|---|
| 91 | |
|---|
| 92 | // 認証可否の判定 |
|---|
| 93 | SC_Utils_Ex::sfIsSuccess($objSess); |
|---|
| 94 | |
|---|
| 95 | $arrActive = array( "0"=>"稼働", "1"=>"非稼働" ); |
|---|
| 96 | $arrQuestion = array( "0"=>"使用しない", "1"=>"テキストエリア", "2"=>"テキストボックス" |
|---|
| 97 | , "3"=>"チェックボックス", "4"=>"ラジオボタン" |
|---|
| 98 | ); |
|---|
| 99 | |
|---|
| 100 | $result = $objQuery->select('*, cast(create_date as date) as disp_date', 'dtb_question', 'del_flg = 0 ORDER BY question_id'); |
|---|
| 101 | $this->list_data = $result; |
|---|
| 102 | |
|---|
| 103 | if (!isset($_GET['mode'])) $_GET['mode'] = ""; |
|---|
| 104 | |
|---|
| 105 | // アンケートを作成ボタン押下時 |
|---|
| 106 | if ( $_GET['mode'] == 'regist' ){ |
|---|
| 107 | |
|---|
| 108 | for ( $i=0; $i<count($_POST["question"]); $i++ ) { |
|---|
| 109 | $_POST['question'][$i]['name'] = mb_convert_kana( trim ( $_POST['question'][$i]['name'] ), "K" ); |
|---|
| 110 | for ( $j=0; $j<count( $_POST['question'][$i]['option'] ); $j++ ){ |
|---|
| 111 | $_POST['question'][$i]['option'][$j] = mb_convert_kana( trim ( $_POST['question'][$i]['option'][$j] ) ); |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | for( $i = 0; $i < count( $_POST["question"] ); $i++ ) { |
|---|
| 116 | if( $_POST["question"][$i]["kind"] == 3 || $_POST["question"][$i]["kind"] == 4 ) { |
|---|
| 117 | $temp_data = array(); |
|---|
| 118 | // 項目間(テキストボックス)があいていたら詰めていく |
|---|
| 119 | for( $j = 0; $j < count( $_POST["question"][$i]["option"] ); $j++ ) { |
|---|
| 120 | if( strlen( $_POST["question"][$i]["option"][$j] ) > 0 ) $temp_data[] = mb_convert_kana( trim ( $_POST["question"][$i]["option"][$j] ), "asKVn" ); |
|---|
| 121 | } |
|---|
| 122 | $_POST["question"][$i]["option"] = $temp_data; |
|---|
| 123 | } else { |
|---|
| 124 | $_POST["question"][$i]["option"] = NULL; |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | $error = $this->lfErrCheck(); |
|---|
| 129 | |
|---|
| 130 | if ( ! $error ){ |
|---|
| 131 | // 新規登録 |
|---|
| 132 | if ( ! is_numeric($_POST['question_id']) ){ |
|---|
| 133 | |
|---|
| 134 | //登録 |
|---|
| 135 | $value = serialize($_POST); |
|---|
| 136 | if (DB_TYPE == "pgsql") { |
|---|
| 137 | $question_id = $objQuery->nextval('dtb_question', 'question_id'); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | $sql_val = array( 'question' => $value, 'question_name' => $_POST['title'] ,'question_id' => $question_id ,'create_date' => 'now()'); |
|---|
| 141 | $objQuery->insert('dtb_question', $sql_val); |
|---|
| 142 | $this->MESSAGE = "登録が完了しました"; |
|---|
| 143 | |
|---|
| 144 | if (DB_TYPE == "mysql") { |
|---|
| 145 | $question_id = $objQuery->nextval('dtb_question', 'question_id'); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | $this->QUESTION_ID = $question_id; |
|---|
| 149 | $this->reload(null, true); |
|---|
| 150 | |
|---|
| 151 | // 編集 |
|---|
| 152 | } else { |
|---|
| 153 | //編集 |
|---|
| 154 | $value = serialize($_POST); |
|---|
| 155 | $sql_val = array( 'question'=>$value, 'question_name'=>$_POST['title'] ); |
|---|
| 156 | $objQuery->update('dtb_question', $sql_val, 'question_id = ?', array($_POST['question_id']) ); |
|---|
| 157 | $this->MESSAGE = "編集が完了しました"; |
|---|
| 158 | $this->QUESTION_ID = $_POST['question_id']; |
|---|
| 159 | $this->reload(null, true); |
|---|
| 160 | } |
|---|
| 161 | } else { |
|---|
| 162 | |
|---|
| 163 | //エラー表示 |
|---|
| 164 | $this->ERROR = $error; |
|---|
| 165 | $this->QUESTION_ID = $_REQUEST['question_id']; |
|---|
| 166 | $this->ERROR_COLOR = $this->lfGetErrColor($error, ERR_COLOR); |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | // 削除ボタン押下時 |
|---|
| 170 | } elseif ( ( $_GET['mode'] == 'delete' ) && ( SC_Utils_Ex::sfCheckNumLength($_GET['question_id']) ) ){ |
|---|
| 171 | |
|---|
| 172 | $sqlval = array('del_flg' => 1); |
|---|
| 173 | $objQuery->update('dtb_question', $sqlval, 'question_id = ?', array( $_GET['question_id'] ) ); |
|---|
| 174 | $this->reload(null, true); |
|---|
| 175 | |
|---|
| 176 | // CSVダウンロードボタン押下時 |
|---|
| 177 | } elseif ( ( $_GET['mode'] == 'csv' ) && ( SC_Utils_Ex::sfCheckNumLength($_GET['question_id']) ) ){ |
|---|
| 178 | require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_CSV_Ex.php"); |
|---|
| 179 | |
|---|
| 180 | $objCSV = new SC_Helper_CSV_Ex(); |
|---|
| 181 | $head = SC_Utils_Ex::sfGetCSVList($this->arrCVSTITLE); |
|---|
| 182 | $sql =<<<__EOS__ |
|---|
| 183 | SELECT |
|---|
| 184 | dtb_question_result.result_id |
|---|
| 185 | ,dtb_question_result.question_id |
|---|
| 186 | ,dtb_question_result.create_date |
|---|
| 187 | ,dtb_question.question_name |
|---|
| 188 | ,dtb_question_result.name01 |
|---|
| 189 | ,dtb_question_result.name02 |
|---|
| 190 | ,dtb_question_result.kana01 |
|---|
| 191 | ,dtb_question_result.kana02 |
|---|
| 192 | ,dtb_question_result.zip01 |
|---|
| 193 | ,dtb_question_result.zip02 |
|---|
| 194 | ,dtb_question_result.pref |
|---|
| 195 | ,dtb_question_result.addr01 |
|---|
| 196 | ,dtb_question_result.addr02 |
|---|
| 197 | ,dtb_question_result.tel01 |
|---|
| 198 | ,dtb_question_result.tel02 |
|---|
| 199 | ,dtb_question_result.tel03 |
|---|
| 200 | ,dtb_question_result.mail01 |
|---|
| 201 | ,dtb_question_result.question01 |
|---|
| 202 | ,dtb_question_result.question02 |
|---|
| 203 | ,dtb_question_result.question03 |
|---|
| 204 | ,dtb_question_result.question04 |
|---|
| 205 | ,dtb_question_result.question05 |
|---|
| 206 | ,dtb_question_result.question06 |
|---|
| 207 | FROM dtb_question_result |
|---|
| 208 | LEFT JOIN dtb_question |
|---|
| 209 | ON dtb_question_result.question_id = dtb_question.question_id |
|---|
| 210 | WHERE 0=0 |
|---|
| 211 | AND dtb_question_result.del_flg = 0 |
|---|
| 212 | AND dtb_question_result.question_id = ? |
|---|
| 213 | ORDER BY dtb_question_result.result_id ASC |
|---|
| 214 | __EOS__; |
|---|
| 215 | |
|---|
| 216 | $list_data = $objQuery->getAll($sql, array($_GET['question_id'])); |
|---|
| 217 | $data = ""; |
|---|
| 218 | for($i = 0; $i < count($list_data); $i++) { |
|---|
| 219 | // 各項目をCSV出力用に変換する。 |
|---|
| 220 | $data .= $objCSV->lfMakeCSV($list_data[$i]); |
|---|
| 221 | } |
|---|
| 222 | // CSVを送信する |
|---|
| 223 | SC_Utils_Ex::sfCSVDownload($head.$data); |
|---|
| 224 | exit; |
|---|
| 225 | |
|---|
| 226 | // 初回表示 or 編集ボタン押下時 |
|---|
| 227 | } else { |
|---|
| 228 | if (!isset($_GET['question_id'])) $_GET['question_id'] = ""; |
|---|
| 229 | |
|---|
| 230 | if ( is_numeric($_GET['question_id']) ){ |
|---|
| 231 | |
|---|
| 232 | $sql = "SELECT question FROM dtb_question WHERE question_id = ?"; |
|---|
| 233 | $result = $objQuery->getOne($sql, array($_GET['question_id'])); |
|---|
| 234 | |
|---|
| 235 | if ( $result ){ |
|---|
| 236 | $_POST = unserialize( $result ); |
|---|
| 237 | $this->QUESTION_ID = $_GET['question_id']; |
|---|
| 238 | } |
|---|
| 239 | } |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | //各ページ共通 |
|---|
| 243 | $this->cnt_question = 6; |
|---|
| 244 | $this->arrActive = $arrActive; |
|---|
| 245 | $this->arrQuestion = $arrQuestion; |
|---|
| 246 | |
|---|
| 247 | //---- ページ表示 |
|---|
| 248 | $objView->assignobj($this); |
|---|
| 249 | $objView->display(MAIN_FRAME); |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | /** |
|---|
| 253 | * デストラクタ. |
|---|
| 254 | * |
|---|
| 255 | * @return void |
|---|
| 256 | */ |
|---|
| 257 | function destroy() { |
|---|
| 258 | parent::destroy(); |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | // ------------ エラーチェック処理部 ------------ |
|---|
| 262 | |
|---|
| 263 | function lfGetErrColor( $arr, $err_color ){ |
|---|
| 264 | |
|---|
| 265 | foreach ( $arr as $key=>$val ) { |
|---|
| 266 | if ( is_string($val) && strlen($val) > 0 ){ |
|---|
| 267 | $return[$key] = $err_color; |
|---|
| 268 | } elseif ( is_array( $val ) ) { |
|---|
| 269 | $return[$key] = $this->lfGetErrColor ( $val, $err_color); |
|---|
| 270 | } |
|---|
| 271 | } |
|---|
| 272 | return $return; |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | // ------------ エラーチェック処理部 ------------ |
|---|
| 277 | |
|---|
| 278 | function lfErrCheck (){ |
|---|
| 279 | |
|---|
| 280 | $objErr = new SC_CheckError(); |
|---|
| 281 | $errMsg = ""; |
|---|
| 282 | |
|---|
| 283 | $objErr->doFunc( array( "稼働・非稼働", "active" ), array( "SELECT_CHECK" ) ); |
|---|
| 284 | |
|---|
| 285 | $_POST["title"] = mb_convert_kana( trim ( $_POST["title"] ), "K" ); |
|---|
| 286 | $objErr->doFunc( array( "アンケート名", "title" ), array( "EXIST_CHECK" ) ); |
|---|
| 287 | |
|---|
| 288 | $_POST["contents"] = mb_convert_kana( trim ( $_POST["contents"] ), "K" ); |
|---|
| 289 | $objErr->doFunc( array( "アンケート内容" ,"contents", "3000" ), array( "EXIST_CHECK", "MAX_LENGTH_CHECK" ) ); |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | if ( ! $_POST['question'][0]["name"] ){ |
|---|
| 293 | $objErr->arrErr['question'][0]["name"] = "1つめの質問名が入力されていません"; |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | // チェックボックス、ラジオボタンを選択した場合は最低1つ以上項目を記入させる。 |
|---|
| 297 | for( $i = 0; $i < count( $_POST["question"] ); $i++ ) { |
|---|
| 298 | |
|---|
| 299 | if ( $_POST["question"][$i]["kind"] ) { |
|---|
| 300 | if (strlen($_POST["question"][$i]["name"]) == 0) { |
|---|
| 301 | $objErr->arrErr["question"][$i]["name"] = "タイトルを入力して下さい。"; |
|---|
| 302 | } else if ( strlen($_POST["question"][$i]["name"]) > STEXT_LEN ) { |
|---|
| 303 | $objErr->arrErr["question"][$i]["name"] = "タイトルは". STEXT_LEN ."字以内で入力して下さい。"; |
|---|
| 304 | } |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | if( $_POST["question"][$i]["kind"] == 3 || $_POST["question"][$i]["kind"] == 4 ) { |
|---|
| 308 | |
|---|
| 309 | for( $j = 0; $j < count( $_POST["question"][$i]["option"] ); $j++ ) { |
|---|
| 310 | // 同じ回答がないかチェック |
|---|
| 311 | if (strlen($_POST["question"][$i]["option"][$j]) > 0) { |
|---|
| 312 | $checkArray = $_POST["question"][$i]["option"]; |
|---|
| 313 | // 自身の値をunset |
|---|
| 314 | unset($checkArray[$j]); |
|---|
| 315 | if (in_array($_POST["question"][$i]["option"][$j], $checkArray)) { |
|---|
| 316 | $objErr->arrErr["question"][$i]["option"][$j] = "同じ質問に同じ回答は設定出来ません。"; |
|---|
| 317 | } |
|---|
| 318 | } |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | if( ( strlen( $_POST["question"][$i] ["option"][0] ) == 0 ) || ( strlen( $_POST["question"][$i] ["option"][0] ) > 0 |
|---|
| 322 | && strlen( $_POST["question"][$i] ["option"][1] ) == 0 ) ) $objErr->arrErr["question"][$i]['kind'] = "下記の2つ以上の項目に記入してください。"; |
|---|
| 323 | |
|---|
| 324 | } |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | return $this->lfGetArrInput( $objErr->arrErr ); |
|---|
| 328 | |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | function lfGetArrInput( $arr ){ |
|---|
| 333 | // 値が入力された配列のみを返す |
|---|
| 334 | |
|---|
| 335 | if ( is_array($arr) ){ |
|---|
| 336 | foreach ( $arr as $key=>$val ) { |
|---|
| 337 | if ( is_string($val) && strlen($val) > 0 ){ |
|---|
| 338 | $return[$key] = $val; |
|---|
| 339 | } elseif ( is_array( $val ) ) { |
|---|
| 340 | $data = $this->lfGetArrInput ( $val ); |
|---|
| 341 | if ( $data ){ |
|---|
| 342 | $return[$key] = $data; |
|---|
| 343 | } |
|---|
| 344 | } |
|---|
| 345 | } |
|---|
| 346 | } |
|---|
| 347 | return $return; |
|---|
| 348 | } |
|---|
| 349 | } |
|---|
| 350 | ?> |
|---|