enquete.php 5.49 KB
<?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');

$limit = $_POST['csv_export'] ? NULL : 100;
$limit_query = $limit ? ' LIMIT '.$limit : '';

$sql = 'SELECT * FROM d_feedback WHERE id > 9 ORDER BY id DESC'.$limit_query;
$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;
	$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[] = $page_id ? $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(isset($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>