<?
$sub_menu = "200800";
include_once("./_common.php");

auth_check($auth[$sub_menu], "r");

$g4[title] = "접속자현황";
include_once("./admin.head.php");
?>
<?=subtitle($g4[title])?>
<div class="subtitle_msg">접속 로그를 보여줍니다.</div>
<?
include_once("./visit.sub.php");
$colspan = 5;
?>
<style>
#ui-datepicker-div	{ display:none; }

.tbl_box	{ border:1px solid #CBCBCB; border-top:2px solid #989898; }
.tbl_box tr th	{ background:#F7F7F7; height:30px; border-right:1px solid #EFEFEF; border-bottom:1px solid #EFEFEF; }
.tbl_box tr th:last-child	{ border-right:0; }
.tbl_box tr td	{ padding:6px; border-right:1px solid #EFEFEF; border-bottom:1px solid #EFEFEF; }
.tbl_box tr td:last-child	{ border-right:0; }
.tbl_box tr:last-child td	{ border-bottom:0; }

span.member:hover	{ text-decoration:underline; }

table tr td a:hover	{ text-decoration:underline; }
</style>

<table width=100% cellpadding=0 cellspacing=0 border=0 class="tbl_box">
<colgroup width=100>
<colgroup width=350>
<colgroup width=100>
<colgroup width=100>
<colgroup width=''>
<tr>
    <th>IP</th>
    <th>접속 경로</th>
    <th>브라우저</th>
    <th>OS</th>
    <th>일시</th>
</tr>
<?
//unset($br); // 브라우저
//unset($os); // OS

$sql_common = " from $g4[visit_table] ";
$sql_search = " where vi_date between '$fr_date' and '$to_date' ";
if ($domain) {
    $sql_search .= " and vi_referer like '%$domain%' ";
}

$sql = " select count(*) as cnt
         $sql_common 
         $sql_search ";
$row = sql_fetch($sql);
$total_count = $row[cnt];

$rows = $config[cf_page_rows];
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page == "") $page = 1; // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함

$sql = " select * 
          $sql_common
          $sql_search
          order by vi_id desc
          limit $from_record, $rows ";
$result = sql_query($sql);

for ($i=0; $row=sql_fetch_array($result); $i++) {
	$row['vi_agent'] = get_text($row['vi_agent']);
    $brow = get_brow($row[vi_agent]);
    $os   = get_os($row[vi_agent]);

    $link = "";
    $referer = "";
    $title = "";
    if ($row[vi_referer]) {

        $referer = get_text(cut_str($row[vi_referer], 255, ""));
        $referer = urldecode($referer);

        if (strtolower($g4['charset']) == 'utf-8') {
            if (!is_utf8($referer)) {
                $referer = iconv('euc-kr', 'utf-8', $referer);
            }
        }
        else {
            if (is_utf8($referer)) {
                $referer = iconv('utf-8', 'euc-kr', $referer);
            }
        }

        $title = str_replace(array("<", ">"), array("&lt;", "&gt;"), $referer);
        $link = "<a href='".htmlspecialchars($row['vi_referer'])."' target=_blank title='$title '>";
    }

    if ($is_admin == 'super')
        $ip = $row[vi_ip];
    else
        $ip = preg_replace("/([0-9]+).([0-9]+).([0-9]+).([0-9]+)/", "\\1.♡.\\3.\\4", $row[vi_ip]);

    if ($brow == '기타') { $brow = "<span title='$row[vi_agent]'>$brow</span>"; }
    if ($os == '기타') { $os = "<span title='$row[vi_agent]'>$os</span>"; }

    $list = ($i%2);
    echo "
    <tr class='list$list col1 ht center'>
        <td width=10% align='left'>$ip</td>
        <td width=55% align=left>$link".cut_str($title, 100)."</a></td>
        <td width=10%>$brow</td>
        <td width=10%>$os</td>
        <td width=15%>$row[vi_date] $row[vi_time]</td>
    </tr>";
}

if ($i == 0)
    echo "<tr><td colspan='$colspan' height=100 align=center>자료가 없습니다.</td></tr>"; 

echo "</table>";

$page = get_paging($config[cf_write_pages], $page, $total_page, "$_SERVER[PHP_SELF]?$qstr&domain=$domain&page=");
if ($page) {
    echo "$page";
}

include_once("./admin.tail.php");
?>