enquete.php
5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
$html_hyo = "";
$q1_ask = array("","良いね!","もう少し!");
$q2_ask = array("","見つけやすかった","見つけにくかった");
$q1_count_g = $q1_count_b = 0;
$q2_count_g = $q2_count_b = 0;
$total_count = 0;
$db = new mysqli("127.0.0.1","root","KanoyaMbc1124","ad1216tnc7_kanoya","3306");
$db->set_charset('utf8');
$sql = 'SELECT * FROM d_feedback WHERE id > 9 ORDER BY id DESC';
$row = $db->query($sql);
//mysqli_query($db, $sql);
while( $data = $row->fetch_object()){
$q1_ans = $data->q1;
$q2_ans = $data->q2;
$page_id = $data-> page_id;
if($total_count < 100){
$html_hyo .= '<tr><td>';
if($page_id){
$sql_p = 'SELECT * FROM v4vfh_menu WHERE id = '.$page_id.' LIMIT 1';
$row_p = $db->query($sql_p);
$data_p = $row_p->fetch_object();
$html_hyo .= $data_p->title;
}
$html_hyo .= '</td><td>'.$q1_ask[$q1_ans].'</td><td>'.$q2_ask[$q2_ans].'</td><td>'.$data->input_date.'</td>';
$total_count ++;
if($q1_ans == 1) { $q1_count_g++; }elseif($q1_ans == 2) { $q1_count_b++; }
if($q2_ans == 1) { $q2_count_g++; }elseif($q2_ans == 2) { $q2_count_b++; }
$html_hyo .= '</tr>';
}
//CSV書出用
$csv_page[] = $data_p->title;
$csv_q1[] = $q1_ask[$q1_ans];
$csv_q2[] = $q2_ask[$q2_ans];
$csv_input[] = $data->input_date;
}
$db->close();
//CSV書出
if($_POST['csv_export']) {
$test_array = [
mb_convert_encoding("ページ", 'SJIS-win', 'UTF-8'),
mb_convert_encoding("ページの情報について", 'SJIS-win', 'UTF-8'),
mb_convert_encoding("情報の見つけやすさ", 'SJIS-win', 'UTF-8'),
mb_convert_encoding("登録日", 'SJIS-win', 'UTF-8')
];
$csv_c = 0;
$csv_array = [];
while($csv_page[$csv_c]){
$csv_array[$csv_c][] = mb_convert_encoding($csv_page[$csv_c], 'SJIS-win', 'UTF-8');
$csv_array[$csv_c][] = mb_convert_encoding($csv_q1[$csv_c], 'SJIS-win', 'UTF-8');
$csv_array[$csv_c][] = mb_convert_encoding($csv_q2[$csv_c], 'SJIS-win', 'UTF-8');
$csv_array[$csv_c][] = $csv_input[$csv_c];
/*
$csv_array[$csv_c][] = mb_convert_encoding($csv_ans[1][$csv_c], 'SJIS-win', 'UTF-8');
$csv_array[$csv_c][] = mb_convert_encoding($csv_ans[2][$csv_c], 'SJIS-win', 'UTF-8');
$csv_array[$csv_c][] = mb_convert_encoding($csv_ans[3][$csv_c], 'SJIS-win', 'UTF-8');
$csv_array[$csv_c][] = mb_convert_encoding($csv_ans[4][$csv_c], 'SJIS-win', 'UTF-8');
*/
$csv_c++;
}
if($csv_array){
$file = fopen('export.csv', 'w');
fputcsv($file, $test_array);
foreach($csv_array as $da) {
fputcsv($file, $da);
}
fclose($file);
}
// ダウンロードさせるファイル名
$tmp_file = "export.csv";
$j_file = "フィードバック集計_".date('Y').date('m').date('d').".csv";
$j_file = mb_convert_encoding($j_file, "SJIS", "auto");
// ヘッダ
header("Content-Type: application/octet-stream");
// ダイアログボックスに表示するファイル名
header("Content-Disposition: attachment; filename=$j_file");
// 対象ファイルを出力する。
readfile($tmp_file);
exit;
}
$q1_good_par = round($q1_count_g / $total_count * 100, 0);
$q1_bad_par = round($q1_count_b / $total_count * 100, 0);
$q2_good_par = round($q2_count_g / $total_count * 100, 0);
$q2_bad_par = round($q2_count_b / $total_count * 100, 0);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="/administrator/templates/isis/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />
<title>鹿屋体育大学</title>
<style type="text/css">
body {
margin: 0;
}
#contents {
padding: 0 15px;
}
h1 {
background: #1a3867;
color: #fff;
font-weight: normal;
padding: 10px 30px;
margin: 0 0 50px;
font-size: 1.8em;
}
h2 {
color: #1a3867;
font-weight: normal;
border-bottom: 1px solid #1a3867;
margin: 0 0 15px;
}
table {
width: 100%;
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
margin-bottom: 50px;
}
table th,
table td {
padding: 10px;
border-left: 1px solid #ccc;
border-top: 1px solid #ccc;
}
table th {
background: #1a3867;
color: #fff;
font-weight: normal;
}
table td {
text-align: center;
width: 25%;
}
form {
margin: 20px 0;
}
form input[type="submit"] {
padding: 10px 50px;
border-radius: 8px;
border: 1px solid #ccc;
}
form input[type="submit"]:hover {
opacity: 0.8;
}
</style>
</head>
<body>
<h1>フィードバック集計</h1>
<div id="contents">
<h2>割合</h2>
<table cellspacing="0" cellpadding="0" class="table1">
<tr>
<th colspan="2">情報について</th>
<th colspan="2">情報の見つけやすさ</th></tr>
<tr>
<th>良いね!</th><th>もう少し!</th>
<th>見つけやすかった</th><th>見つけにくかった</th></tr>
<tr>
<td><?php echo $q1_count_g; ?>(<?php echo $q1_good_par; ?> %)</td>
<td><?php echo $q1_count_b; ?>(<?php echo $q1_bad_par; ?> %)</td>
<td><?php echo $q2_count_g; ?>(<?php echo $q2_good_par; ?> %)</td>
<td><?php echo $q2_count_b; ?>(<?php echo $q2_bad_par; ?> %)</td>
</tr>
</table>
<h2>アンケート一覧</h2>
<form action="" method="post">
<input type="hidden" name="csv_export" value="ok">
<input type="submit" value="CSVエクスポート">
</form>
<table cellspacing="0" cellpadding="0" class="table2">
<tr><th>ページ</th><th>ページの情報について</th><th>情報の見つけやすさ</th><th>登録日</th></tr>
<?php echo $html_hyo; ?>
</table>
</div>
</body>
</html>