<?php
include_once('./_common.php');

include_once(AMINA_PATH.'/lib/head.lib.php');

if (!$is_admin) {
	alert_close("관리자만 접속할 수 있습니다.");
}

if (!($bo_table && $wr_id)) {
	alert_close("값이 제대로 넘어오지 않았습니다.");
}

?>
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<? if (G5_IS_MOBILE) {?>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=0,maximum-scale=10,user-scalable=yes">
	<meta name="HandheldFriendly" content="true">
	<meta name="format-detection" content="telephone=no">
<? } ?>
<title>게시물 통계보기</title>
<style>
	body, table, form { margin:0; padding:0; font:normal 12px dotum; -webkit-text-size-adjust:100%; }
	input, button {	border-radius:0;-webkit-appearance:none; }
	.title { padding:12px; text-align:center; font:bold 12px dotum; color:gold; background:#333 !important; border:0px; }
	.tbl { border-collapse:collapse; width:100%; } 
	.tbl th { width:16%; text-align:center; background:#fafafa; border:1px solid #ddd; padding: 6px 10px; line-height:1.6; font-size:12px; -webkit-text-size-adjust:100%;}
	.tbl td { width:16%; background:#fff; border:1px solid #ddd; padding:0px; line-height:1.6; font-size:12px; -webkit-text-size-adjust:100%;}
	.tbl ol { }
	.tbl ol li { }
	ul li { line-height:1.6 }
</style>
</head>
<body>
<div class="title">제목 : <?=$write['wr_subject']?></div>

<table border="1" class="tbl">
<tr>
<th>추천회원</th>
<th>비추천회원</th>
<th>별점회원</th>
<th>투표회원</th>
<th>열람회원</th>
<th>다운회원</th>
</tr>
<tr>
<td valign=top>
<ol>
<?
	$result = sql_query("select mb_id from {$g5['board_good_table']} where bo_table = '$bo_table' and wr_id = '$wr_id' and mb_id != '' and bg_flag = 'good' group by mb_id order by mb_id");
	for ($i=0; $row=sql_fetch_array($result); $i++) {
		$row1 = sql_fetch(" select mb_nick from {$g5['member_table']} where mb_id = '{$row['mb_id']}' ");
		echo '<li><b>'.$row1['mb_nick'].'</b>('.$row['mb_id'].')</li>';
	}
?>
</ol>
</td>
<td valign=top>
<ol>
<?
	$result = sql_query("select mb_id from {$g5['board_good_table']} where bo_table = '$bo_table' and wr_id = '$wr_id' and mb_id != '' and bg_flag = 'nogood' group by mb_id order by mb_id");
	for ($i=0; $row=sql_fetch_array($result); $i++) {
		$row1 = sql_fetch(" select mb_nick from {$g5['member_table']} where mb_id = '{$row['mb_id']}' ");
		echo '<li><b>'.$row1['mb_nick'].'</b>('.$row['mb_id'].')</li>';
	}
?>
</ol>
</td>
<td valign=top>
<ol>
<?
	$result = sql_query("select mb_id, bg_ip from {$g5['amina_star']} where bo_table = '$bo_table' and wr_id = '$wr_id' and mb_id != '' group by mb_id order by bg_ip");
	for ($i=0; $row=sql_fetch_array($result); $i++) {
		$row1 = sql_fetch(" select mb_nick from {$g5['member_table']} where mb_id = '{$row['mb_id']}' ");
		echo '<li><b>'.$row1['mb_nick'].'</b>('.$row['mb_id'].')<br />'.$row['bg_ip'].'</li>';
	}
?>
</ol>
</td>
<td valign=top>
<ol>
<?
	$result = sql_query("select mb_id, poll_ip from {$g5['amina_polllog']} where bo_table = '$bo_table' and wr_id = '$wr_id' and mb_id != '' group by mb_id order by poll_ip");
	for ($i=0; $row=sql_fetch_array($result); $i++) {
		$row1 = sql_fetch(" select mb_nick from {$g5['member_table']} where mb_id = '{$row['mb_id']}' ");
		echo '<li><b>'.$row1['mb_nick'].'</b>('.$row['mb_id'].')<br />'.$row['poll_ip'].'</li>';
	}
?>
</ol>
</td>
<td valign=top>
<ol>
<?
	$list = array();
	$list1 = array();
	$list2 = array();

	$result = sql_query("select mb_id from {$g5['amina_point']} where bo_table = '$bo_table' and wr_id = '$wr_id' and mb_id != '' and po_flag = '@po_view' group by mb_id order by mb_id");
	for ($i=0; $row=sql_fetch_array($result); $i++) {
		$list1[$i] = $row['mb_id'];
	}

	$result = sql_query("select mb_id from {$g5['point_table']} where po_rel_table = '$bo_table' and po_rel_id = '$wr_id' and po_rel_action = '읽기'");
	for ($k=0; $row=sql_fetch_array($result); $k++) {
		$list2[$k] = $row['mb_id'];
	}
	
	if($i > 0 &&  $k > 0) {
		$list = sort(array_unique(array_merge($list1, $list2)));
	} else if($i > 0 && $k == 0) {
		$list = $list1;
	} else if($i == 0 && $k > 0) {
		$list = $list2;
	}

	for ($i=0; $i < count($list); $i++) {
		$row1 = sql_fetch(" select mb_nick from {$g5['member_table']} where mb_id = '{$list[$i]}' ");
		echo '<li><b>'.$row1['mb_nick'].'</b>('.$list[$i].')</li>';
	}
?>
</ol>
</td>
<td valign=top>
<ol>
<?
	$result = sql_query("select mb_id from {$g5['amina_point']} where bo_table = '$bo_table' and wr_id = '$wr_id' and mb_id != '' and po_flag = '@po_down' group by mb_id order by mb_id");
	for ($i=0; $row=sql_fetch_array($result); $i++) {
		$list1[$i] = $row['mb_id'];
	}

	$result = sql_query("select mb_id from {$g5['point_table']} where po_rel_table = '$bo_table' and po_rel_id = '$wr_id' and po_rel_action = '다운로드'");
	for ($k=0; $row=sql_fetch_array($result); $k++) {
		$list2[$k] = $row['mb_id'];
	}
	
	if($i > 0 &&  $k > 0) {
		$list = sort(array_unique(array_merge($list1, $list2)));
	} else if($i > 0 && $k == 0) {
		$list = $list1;
	} else if($i == 0 && $k > 0) {
		$list = $list2;
	}

	for ($i=0; $i < count($list); $i++) {
		$row1 = sql_fetch(" select mb_nick from {$g5['member_table']} where mb_id = '{$list[$i]}' ");
		echo '<li><b>'.$row1['mb_nick'].'</b>('.$list[$i].')</li>';
	}
?>
</ol>
</td>
</tr>
</table>
<ul>
	<li>모든 내역은 회원만 체크되며, 열람과 다운회원은 포인트 사용시에만 체크됩니다.</li>
	<li>v3.1.5 이전에 이동 또는 복사된 글일 경우 내역이 정상출력되지 않을 수 있습니다.</li>
</ul>
</body>
</html>