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