source: branches/feature-module-update/data/class/pages/admin/contents/LC_Page_Admin_Contents_Inquiry.php @ 15662

Revision 15662, 10.3 KB checked in by nanasess, 17 years ago (diff)

クラス化に伴う修正

  • Property svn:keywords set to "Id Revision Date"
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8// {{{ requires
9require_once(CLASS_PATH . "pages/LC_Page.php");
10
11/**
12 * アンケート管理 のページクラス.
13 *
14 * @package Page
15 * @author LOCKON CO.,LTD.
16 * @version $Id$
17 */
18class LC_Page_Admin_Contents_Inquiry extends LC_Page {
19
20    // }}}
21    // {{{ functions
22
23    /**
24     * Page を初期化する.
25     *
26     * @return void
27     */
28    function init() {
29        parent::init();
30        $this->tpl_mainpage = 'contents/inquiry.tpl';
31        $this->tpl_mainno = 'contents';
32        $this->tpl_subnavi = 'contents/subnavi.tpl';
33        $this->tpl_subno = "inquiry";
34        $this->tpl_subtitle = 'アンケート管理';
35        $this->arrCVSCOL = array(
36
37                );
38
39        $this->arrCVSTITLE = array(
40                             '回答ID',
41                             '質問ID',
42                             '回答日時',
43                             '回答名',
44                             '顧客名1',
45                             '顧客名2',
46                             '顧客名カナ1',
47                             '顧客名カナ2',
48                             '郵便番号1',
49                             '郵便番号2',
50                             '都道府県',
51                             '住所1',
52                             '住所2',
53                             '電話番号1',
54                             '電話番号2',
55                             '電話番号3',
56                             'メールアドレス',
57                             '回答1',
58                             '回答2',
59                             '回答3',
60                             '回答4',
61                             '回答5',
62                             '回答6'
63                             );
64    }
65
66    /**
67     * Page のプロセス.
68     *
69     * @return void
70     */
71    function process() {
72        $conn = new SC_DBConn();
73        $objView = new SC_AdminView();
74        $objSess = new SC_Session();
75
76        // 認証可否の判定
77        SC_Utils_Ex::sfIsSuccess($objSess);
78
79        $arrActive = array( "0"=>"稼働", "1"=>"非稼働" );
80        $arrQuestion = array( "0"=>"使用しない", "1"=>"テキストエリア", "2"=>"テキストボックス"
81                              , "3"=>"チェックボックス", "4"=>"ラジオボタン"
82                              );
83
84        $sql = "SELECT *, cast(substring(create_date, 1, 10) as date) as disp_date FROM dtb_question WHERE del_flg = 0 ORDER BY question_id";
85        $result = $conn->getAll($sql);
86        $this->list_data = $result;
87
88        if (!isset($_GET['mode'])) $_GET['mode'] = "";
89
90        if ( $_GET['mode'] == 'regist' ){
91
92            for ( $i=0; $i<count($_POST["question"]); $i++ ) {
93                $_POST['question'][$i]['name'] = mb_convert_kana( trim ( $_POST['question'][$i]['name'] ), "K" );
94                for ( $j=0; $j<count( $_POST['question'][$i]['option'] ); $j++ ){
95                    $_POST['question'][$i]['option'][$j] = mb_convert_kana( trim ( $_POST['question'][$i]['option'][$j] ) );
96                }
97            }
98
99            $error = $this->lfErrCheck();
100
101            if ( ! $error  ){
102
103                if ( ! is_numeric($_POST['question_id']) ){
104                    $objQuery = new SC_Query();
105
106                    //登録
107                    $value = serialize($_POST);
108                    if (DB_TYPE == "pgsql") {
109                        $question_id = $objQuery->nextval('dtb_question', 'question_id');
110                    }
111
112                    $sql_val = array( $value, $_POST['title'] ,$question_id );
113                    $conn->query("INSERT INTO dtb_question ( question, question_name, question_id, create_date) VALUES (?, ?, ?, now())", $sql_val );
114                    $this->MESSAGE = "登録が完了しました";
115
116                    if (DB_TYPE == "mysql") {
117                        $question_id = $objQuery->nextval('dtb_question', 'question_id');
118                    }
119
120                    $this->QUESTION_ID = $question_id;
121                    $this->reload();
122                } else {
123                    //編集
124                    $value = serialize($_POST);
125                    $sql_val = array( $value, $_POST['title'] ,$_POST['question_id'] );
126                    $conn->query("UPDATE dtb_question SET question = ?, question_name = ? WHERE question_id = ?", $sql_val );
127                    $this->MESSAGE = "編集が完了しました";
128                    $this->QUESTION_ID = $_POST['question_id'];
129                    $this->reload();
130                }
131            } else {
132
133                //エラー表示
134                $this->ERROR = $error;
135                $this->QUESTION_ID = $_REQUEST['question_id'];
136                $this->ERROR_COLOR = $this->lfGetErrColor($error, ERR_COLOR);
137
138            }
139        } elseif ( ( $_GET['mode'] == 'delete' ) && ( SC_Utils_Ex::sfCheckNumLength($_GET['question_id']) )  ){
140
141            $sql = "UPDATE dtb_question SET del_flg = 1 WHERE question_id = ?";
142            $conn->query( $sql, array( $_GET['question_id'] ) );
143            $this->reload();
144
145        } elseif ( ( $_GET['mode'] == 'csv' ) && ( SC_Utils_Ex::sfCheckNumLength($_GET['question_id']) ) ){
146            require_once(CLASS_PATH . "helper_extends/SC_Helper_CSV_Ex.php");
147
148            $objCSV = new SC_Helper_CSV_Ex();
149            $head = SC_Utils_Ex::sfGetCSVList($this->arrCVSTITLE);
150            $list_data = $conn->getAll("SELECT result_id,question_id,question_date,question_name,name01,name02,kana01,kana02,zip01,zip02,pref,addr01,addr02,tel01,tel02,tel03,mail01,question01,question02,question03,question04,question05,question06 FROM dtb_question_result WHERE del_flg = 0 AND question_id = ? ORDER BY result_id ASC",array($_GET['question_id']));
151            $data = "";
152            for($i = 0; $i < count($list_data); $i++) {
153                // 各項目をCSV出力用に変換する。
154                $data .= $objCSV->lfMakeCSV($list_data[$i]);
155            }
156            // CSVを送信する
157            SC_Utils_Ex::sfCSVDownload($head.$data);
158            exit;
159
160        } else {
161            if (!isset($_GET['question_id'])) $_GET['question_id'] = "";
162
163            if ( is_numeric($_GET['question_id']) ){
164
165                $sql = "SELECT question FROM dtb_question WHERE question_id = ?";
166                $result = $conn->getOne($sql, array($_GET['question_id']));
167
168                if ( $result ){
169                    $_POST = unserialize( $result );
170                    $this->QUESTION_ID = $_GET['question_id'];
171                }
172            }
173        }
174
175        //各ページ共通
176        $this->cnt_question = 6;
177        $this->arrActive = $arrActive;
178        $this->arrQuestion = $arrQuestion;
179
180        //---- ページ表示
181        $objView->assignobj($this);
182        $objView->display(MAIN_FRAME);
183    }
184
185    /**
186     * デストラクタ.
187     *
188     * @return void
189     */
190    function destroy() {
191        parent::destroy();
192    }
193
194    // ------------  エラーチェック処理部 ------------
195
196    function lfGetErrColor( $arr, $err_color ){
197
198        foreach ( $arr as $key=>$val ) {
199            if ( is_string($val) && strlen($val) > 0 ){
200                $return[$key] = $err_color;
201            } elseif ( is_array( $val ) ) {
202                $return[$key] = $this->lfGetErrColor ( $val, $err_color);
203            }
204        }
205        return $return;
206    }
207
208
209    // ------------  エラーチェック処理部 ------------
210
211    function lfErrCheck (){
212
213        $objErr = new SC_CheckError();
214        $errMsg = "";
215
216        $objErr->doFunc( array( "稼働・非稼働", "active" ), array( "SELECT_CHECK" ) );
217
218        $_POST["title"] = mb_convert_kana( trim (  $_POST["title"] ), "K" );
219        $objErr->doFunc( array( "アンケート名", "title" ), array( "EXIST_CHECK" ) );
220
221        $_POST["contents"] = mb_convert_kana( trim (  $_POST["contents"] ), "K" );
222        $objErr->doFunc( array( "アンケート内容" ,"contents", "3000" ), array( "EXIST_CHECK", "MAX_LENGTH_CHECK" ) );
223
224
225        if ( ! $_POST['question'][0]["name"] ){
226            $objErr->arrErr['question'][0]["name"] = "1つめの質問名が入力されていません";
227        }
228
229        // チェックボックス、ラジオボタンを選択した場合は最低1つ以上項目を記入させる。
230        for( $i = 0; $i < count( $_POST["question"] ); $i++ ) {
231
232            if ( $_POST["question"][$i]["kind"] ) {
233                if (strlen($_POST["question"][$i]["name"]) == 0) {
234                    $objErr->arrErr["question"][$i]["name"] = "タイトルを入力して下さい。";
235                } else if ( strlen($_POST["question"][$i]["name"]) > STEXT_LEN ) {
236                    $objErr->arrErr["question"][$i]["name"] = "タイトルは". STEXT_LEN  ."字以内で入力して下さい。";
237                }
238            }
239
240            if( $_POST["question"][$i]["kind"] == 3 || $_POST["question"][$i]["kind"] == 4  ) {
241
242                $temp_data = array();
243                for( $j = 0; $j < count( $_POST["question"][$i]["option"] ); $j++ ) {
244
245                    // 項目間(テキストボックス)があいていたら詰めていく
246                    if( strlen( $_POST["question"][$i]["option"][$j] ) > 0 ) $temp_data[] = mb_convert_kana( trim ( $_POST["question"][$i]["option"][$j]  ), "asKVn" );
247
248                }
249
250                $_POST["question"][$i]["option"] = $temp_data;
251
252                if( ( strlen( $_POST["question"][$i] ["option"][0] ) == 0 ) || ( strlen( $_POST["question"][$i] ["option"][0] ) > 0
253                                                                                 && strlen( $_POST["question"][$i] ["option"][1] ) == 0 ) ) $objErr->arrErr["question"][$i]['kind'] = "下記の2つ以上の項目に記入してください。";
254            }
255        }
256
257        return $this->lfGetArrInput( $objErr->arrErr );
258
259    }
260
261
262    function lfGetArrInput( $arr ){
263        // 値が入力された配列のみを返す
264
265        if ( is_array($arr) ){
266            foreach ( $arr as $key=>$val ) {
267                if ( is_string($val) && strlen($val) > 0 ){
268                    $return[$key] = $val;
269                } elseif ( is_array( $val ) ) {
270                    $data = $this->lfGetArrInput ( $val );
271                    if ( $data ){
272                        $return[$key] = $data;
273                    }
274                }
275            }
276        }
277        return $return;
278    }
279}
280?>
Note: See TracBrowser for help on using the repository browser.