source: branches/version-2_4-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_Inquiry.php @ 18469

Revision 18469, 13.6 KB checked in by Yammy, 14 years ago (diff)

http://svn.ec-cube.net/open_trac/ticket/535
[アンケート管理]チェックボックスの回答に同じ回答を登録した場合に不具合となる場合がある

  • Property svn:eol-style set to LF
  • Property svn:keywords set to "Id Revision Date"
Line 
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
25require_once(CLASS_PATH . "pages/LC_Page.php");
26
27/**
28 * アンケート管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class 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;
165var_dump($this->ERROR);
166                $this->QUESTION_ID = $_REQUEST['question_id'];
167                $this->ERROR_COLOR = $this->lfGetErrColor($error, ERR_COLOR);
168            }
169
170        // 削除ボタン押下時
171        } elseif ( ( $_GET['mode'] == 'delete' ) && ( SC_Utils_Ex::sfCheckNumLength($_GET['question_id']) )  ){
172
173            $sqlval = array('del_flg' => 1);
174            $objQuery->update('dtb_question', $sqlval, 'question_id = ?', array( $_GET['question_id'] ) );
175            $this->reload(null, true);
176
177        // CSVダウンロードボタン押下時
178        } elseif ( ( $_GET['mode'] == 'csv' ) && ( SC_Utils_Ex::sfCheckNumLength($_GET['question_id']) ) ){
179            require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_CSV_Ex.php");
180
181            $objCSV = new SC_Helper_CSV_Ex();
182            $head = SC_Utils_Ex::sfGetCSVList($this->arrCVSTITLE);
183            $sql =<<<__EOS__
184                    SELECT
185                         dtb_question_result.result_id
186                        ,dtb_question_result.question_id
187                        ,dtb_question_result.create_date
188                        ,dtb_question.question_name
189                        ,dtb_question_result.name01
190                        ,dtb_question_result.name02
191                        ,dtb_question_result.kana01
192                        ,dtb_question_result.kana02
193                        ,dtb_question_result.zip01
194                        ,dtb_question_result.zip02
195                        ,dtb_question_result.pref
196                        ,dtb_question_result.addr01
197                        ,dtb_question_result.addr02
198                        ,dtb_question_result.tel01
199                        ,dtb_question_result.tel02
200                        ,dtb_question_result.tel03
201                        ,dtb_question_result.mail01
202                        ,dtb_question_result.question01
203                        ,dtb_question_result.question02
204                        ,dtb_question_result.question03
205                        ,dtb_question_result.question04
206                        ,dtb_question_result.question05
207                        ,dtb_question_result.question06
208                    FROM dtb_question_result
209                        LEFT JOIN dtb_question
210                            ON dtb_question_result.question_id = dtb_question.question_id
211                    WHERE 0=0
212                        AND dtb_question_result.del_flg = 0
213                        AND dtb_question_result.question_id = ?
214                    ORDER BY dtb_question_result.result_id ASC
215__EOS__;
216
217            $list_data = $objQuery->getAll($sql, array($_GET['question_id']));
218            $data = "";
219            for($i = 0; $i < count($list_data); $i++) {
220                // 各項目をCSV出力用に変換する。
221                $data .= $objCSV->lfMakeCSV($list_data[$i]);
222            }
223            // CSVを送信する
224            SC_Utils_Ex::sfCSVDownload($head.$data);
225            exit;
226
227        // 初回表示 or 編集ボタン押下時
228        } else {
229            if (!isset($_GET['question_id'])) $_GET['question_id'] = "";
230
231            if ( is_numeric($_GET['question_id']) ){
232
233                $sql = "SELECT question FROM dtb_question WHERE question_id = ?";
234                $result = $objQuery->getOne($sql, array($_GET['question_id']));
235
236                if ( $result ){
237                    $_POST = unserialize( $result );
238                    $this->QUESTION_ID = $_GET['question_id'];
239                }
240            }
241        }
242
243        //各ページ共通
244        $this->cnt_question = 6;
245        $this->arrActive = $arrActive;
246        $this->arrQuestion = $arrQuestion;
247
248        //---- ページ表示
249        $objView->assignobj($this);
250        $objView->display(MAIN_FRAME);
251    }
252
253    /**
254     * デストラクタ.
255     *
256     * @return void
257     */
258    function destroy() {
259        parent::destroy();
260    }
261
262    // ------------  エラーチェック処理部 ------------
263
264    function lfGetErrColor( $arr, $err_color ){
265
266        foreach ( $arr as $key=>$val ) {
267            if ( is_string($val) && strlen($val) > 0 ){
268                $return[$key] = $err_color;
269            } elseif ( is_array( $val ) ) {
270                $return[$key] = $this->lfGetErrColor ( $val, $err_color);
271            }
272        }
273        return $return;
274    }
275
276
277    // ------------  エラーチェック処理部 ------------
278
279    function lfErrCheck (){
280
281        $objErr = new SC_CheckError();
282        $errMsg = "";
283
284        $objErr->doFunc( array( "稼働・非稼働", "active" ), array( "SELECT_CHECK" ) );
285
286        $_POST["title"] = mb_convert_kana( trim (  $_POST["title"] ), "K" );
287        $objErr->doFunc( array( "アンケート名", "title" ), array( "EXIST_CHECK" ) );
288
289        $_POST["contents"] = mb_convert_kana( trim (  $_POST["contents"] ), "K" );
290        $objErr->doFunc( array( "アンケート内容" ,"contents", "3000" ), array( "EXIST_CHECK", "MAX_LENGTH_CHECK" ) );
291
292
293        if ( ! $_POST['question'][0]["name"] ){
294            $objErr->arrErr['question'][0]["name"] = "1つめの質問名が入力されていません";
295        }
296
297        // チェックボックス、ラジオボタンを選択した場合は最低1つ以上項目を記入させる。
298        for( $i = 0; $i < count( $_POST["question"] ); $i++ ) {
299
300            if ( $_POST["question"][$i]["kind"] ) {
301                if (strlen($_POST["question"][$i]["name"]) == 0) {
302                    $objErr->arrErr["question"][$i]["name"] = "タイトルを入力して下さい。";
303                } else if ( strlen($_POST["question"][$i]["name"]) > STEXT_LEN ) {
304                    $objErr->arrErr["question"][$i]["name"] = "タイトルは". STEXT_LEN  ."字以内で入力して下さい。";
305                }
306            }
307
308            if( $_POST["question"][$i]["kind"] == 3 || $_POST["question"][$i]["kind"] == 4  ) {
309
310                for( $j = 0; $j < count( $_POST["question"][$i]["option"] ); $j++ ) {
311                    // 同じ回答がないかチェック
312                    if (strlen($_POST["question"][$i]["option"][$j]) > 0) {
313                        $checkArray = $_POST["question"][$i]["option"];
314                        // 自身の値をunset
315                        unset($checkArray[$j]);
316                        if (in_array($_POST["question"][$i]["option"][$j], $checkArray)) {
317                            $objErr->arrErr["question"][$i]["option"][$j] = "同じ質問に同じ回答は設定出来ません。";
318                        }
319                    }
320                }
321
322                if( ( strlen( $_POST["question"][$i] ["option"][0] ) == 0 ) || ( strlen( $_POST["question"][$i] ["option"][0] ) > 0
323                                                                                 && strlen( $_POST["question"][$i] ["option"][1] ) == 0 ) ) $objErr->arrErr["question"][$i]['kind'] = "下記の2つ以上の項目に記入してください。";
324
325            }
326        }
327
328        return $this->lfGetArrInput( $objErr->arrErr );
329
330    }
331
332
333    function lfGetArrInput( $arr ){
334        // 値が入力された配列のみを返す
335
336        if ( is_array($arr) ){
337            foreach ( $arr as $key=>$val ) {
338                if ( is_string($val) && strlen($val) > 0 ){
339                    $return[$key] = $val;
340                } elseif ( is_array( $val ) ) {
341                    $data = $this->lfGetArrInput ( $val );
342                    if ( $data ){
343                        $return[$key] = $data;
344                    }
345                }
346            }
347        }
348        return $return;
349    }
350}
351?>
Note: See TracBrowser for help on using the repository browser.