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

Revision 17845, 12.6 KB checked in by kajiwara, 15 years ago (diff)

#12 MySQL環境下でのみ、管理画面でアンケートの登録ができない不具合を修正

  • 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            $error = $this->lfErrCheck();
116
117            if ( ! $error  ){
118                // 新規登録
119                if ( ! is_numeric($_POST['question_id']) ){
120
121                    //登録
122                    $value = serialize($_POST);
123                    if (DB_TYPE == "pgsql") {
124                        $question_id = $objQuery->nextval('dtb_question', 'question_id');
125                    }
126
127                    $sql_val = array( 'question' => $value, 'question_name' => $_POST['title'] ,'question_id' => $question_id ,'create_date' => 'now()');
128                    $objQuery->insert('dtb_question', $sql_val);
129                    $this->MESSAGE = "登録が完了しました";
130
131                    if (DB_TYPE == "mysql") {
132                        $question_id = $objQuery->nextval('dtb_question', 'question_id');
133                    }
134
135                    $this->QUESTION_ID = $question_id;
136                    $this->reload(null, true);
137
138                // 編集
139                } else {
140                    //編集
141                    $value = serialize($_POST);
142                    $sql_val = array( 'question'=>$value, 'question_name'=>$_POST['title'] );
143                    $objQuery->update('dtb_question', $sql_val, 'question_id = ?',  array($_POST['question_id']) );
144                    $this->MESSAGE = "編集が完了しました";
145                    $this->QUESTION_ID = $_POST['question_id'];
146                    $this->reload(null, true);
147                }
148            } else {
149
150                //エラー表示
151                $this->ERROR = $error;
152                $this->QUESTION_ID = $_REQUEST['question_id'];
153                $this->ERROR_COLOR = $this->lfGetErrColor($error, ERR_COLOR);
154            }
155
156        // 削除ボタン押下時
157        } elseif ( ( $_GET['mode'] == 'delete' ) && ( SC_Utils_Ex::sfCheckNumLength($_GET['question_id']) )  ){
158
159            $sqlval = array('del_flg' => 1);
160            $objQuery->update('dtb_question', $sqlval, 'question_id = ?', array( $_GET['question_id'] ) );
161            $this->reload(null, true);
162
163        // CSVダウンロードボタン押下時
164        } elseif ( ( $_GET['mode'] == 'csv' ) && ( SC_Utils_Ex::sfCheckNumLength($_GET['question_id']) ) ){
165            require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_CSV_Ex.php");
166
167            $objCSV = new SC_Helper_CSV_Ex();
168            $head = SC_Utils_Ex::sfGetCSVList($this->arrCVSTITLE);
169            $sql =<<<__EOS__
170                    SELECT
171                         dtb_question_result.result_id
172                        ,dtb_question_result.question_id
173                        ,dtb_question_result.create_date
174                        ,dtb_question.question_name
175                        ,dtb_question_result.name01
176                        ,dtb_question_result.name02
177                        ,dtb_question_result.kana01
178                        ,dtb_question_result.kana02
179                        ,dtb_question_result.zip01
180                        ,dtb_question_result.zip02
181                        ,dtb_question_result.pref
182                        ,dtb_question_result.addr01
183                        ,dtb_question_result.addr02
184                        ,dtb_question_result.tel01
185                        ,dtb_question_result.tel02
186                        ,dtb_question_result.tel03
187                        ,dtb_question_result.mail01
188                        ,dtb_question_result.question01
189                        ,dtb_question_result.question02
190                        ,dtb_question_result.question03
191                        ,dtb_question_result.question04
192                        ,dtb_question_result.question05
193                        ,dtb_question_result.question06
194                    FROM dtb_question_result
195                        LEFT JOIN dtb_question
196                            ON dtb_question_result.question_id = dtb_question.question_id
197                    WHERE 0=0
198                        AND dtb_question_result.del_flg = 0
199                        AND dtb_question_result.question_id = ?
200                    ORDER BY dtb_question_result.result_id ASC
201__EOS__;
202
203            $list_data = $objQuery->getAll($sql, array($_GET['question_id']));
204            $data = "";
205            for($i = 0; $i < count($list_data); $i++) {
206                // 各項目をCSV出力用に変換する。
207                $data .= $objCSV->lfMakeCSV($list_data[$i]);
208            }
209            // CSVを送信する
210            SC_Utils_Ex::sfCSVDownload($head.$data);
211            exit;
212
213        // 初回表示 or 編集ボタン押下時
214        } else {
215            if (!isset($_GET['question_id'])) $_GET['question_id'] = "";
216
217            if ( is_numeric($_GET['question_id']) ){
218
219                $sql = "SELECT question FROM dtb_question WHERE question_id = ?";
220                $result = $objQuery->getOne($sql, array($_GET['question_id']));
221
222                if ( $result ){
223                    $_POST = unserialize( $result );
224                    $this->QUESTION_ID = $_GET['question_id'];
225                }
226            }
227        }
228
229        //各ページ共通
230        $this->cnt_question = 6;
231        $this->arrActive = $arrActive;
232        $this->arrQuestion = $arrQuestion;
233
234        //---- ページ表示
235        $objView->assignobj($this);
236        $objView->display(MAIN_FRAME);
237    }
238
239    /**
240     * デストラクタ.
241     *
242     * @return void
243     */
244    function destroy() {
245        parent::destroy();
246    }
247
248    // ------------  エラーチェック処理部 ------------
249
250    function lfGetErrColor( $arr, $err_color ){
251
252        foreach ( $arr as $key=>$val ) {
253            if ( is_string($val) && strlen($val) > 0 ){
254                $return[$key] = $err_color;
255            } elseif ( is_array( $val ) ) {
256                $return[$key] = $this->lfGetErrColor ( $val, $err_color);
257            }
258        }
259        return $return;
260    }
261
262
263    // ------------  エラーチェック処理部 ------------
264
265    function lfErrCheck (){
266
267        $objErr = new SC_CheckError();
268        $errMsg = "";
269
270        $objErr->doFunc( array( "稼働・非稼働", "active" ), array( "SELECT_CHECK" ) );
271
272        $_POST["title"] = mb_convert_kana( trim (  $_POST["title"] ), "K" );
273        $objErr->doFunc( array( "アンケート名", "title" ), array( "EXIST_CHECK" ) );
274
275        $_POST["contents"] = mb_convert_kana( trim (  $_POST["contents"] ), "K" );
276        $objErr->doFunc( array( "アンケート内容" ,"contents", "3000" ), array( "EXIST_CHECK", "MAX_LENGTH_CHECK" ) );
277
278
279        if ( ! $_POST['question'][0]["name"] ){
280            $objErr->arrErr['question'][0]["name"] = "1つめの質問名が入力されていません";
281        }
282
283        // チェックボックス、ラジオボタンを選択した場合は最低1つ以上項目を記入させる。
284        for( $i = 0; $i < count( $_POST["question"] ); $i++ ) {
285
286            if ( $_POST["question"][$i]["kind"] ) {
287                if (strlen($_POST["question"][$i]["name"]) == 0) {
288                    $objErr->arrErr["question"][$i]["name"] = "タイトルを入力して下さい。";
289                } else if ( strlen($_POST["question"][$i]["name"]) > STEXT_LEN ) {
290                    $objErr->arrErr["question"][$i]["name"] = "タイトルは". STEXT_LEN  ."字以内で入力して下さい。";
291                }
292            }
293
294            if( $_POST["question"][$i]["kind"] == 3 || $_POST["question"][$i]["kind"] == 4  ) {
295
296                $temp_data = array();
297                for( $j = 0; $j < count( $_POST["question"][$i]["option"] ); $j++ ) {
298
299                    // 項目間(テキストボックス)があいていたら詰めていく
300                    if( strlen( $_POST["question"][$i]["option"][$j] ) > 0 ) $temp_data[] = mb_convert_kana( trim ( $_POST["question"][$i]["option"][$j]  ), "asKVn" );
301
302                }
303
304                $_POST["question"][$i]["option"] = $temp_data;
305
306                if( ( strlen( $_POST["question"][$i] ["option"][0] ) == 0 ) || ( strlen( $_POST["question"][$i] ["option"][0] ) > 0
307                                                                                 && strlen( $_POST["question"][$i] ["option"][1] ) == 0 ) ) $objErr->arrErr["question"][$i]['kind'] = "下記の2つ以上の項目に記入してください。";
308            }
309        }
310
311        return $this->lfGetArrInput( $objErr->arrErr );
312
313    }
314
315
316    function lfGetArrInput( $arr ){
317        // 値が入力された配列のみを返す
318
319        if ( is_array($arr) ){
320            foreach ( $arr as $key=>$val ) {
321                if ( is_string($val) && strlen($val) > 0 ){
322                    $return[$key] = $val;
323                } elseif ( is_array( $val ) ) {
324                    $data = $this->lfGetArrInput ( $val );
325                    if ( $data ){
326                        $return[$key] = $data;
327                    }
328                }
329            }
330        }
331        return $return;
332    }
333}
334?>
Note: See TracBrowser for help on using the repository browser.