


<?php
preg_match("/오늘:(.*),어제:(.*),최대:(.*),전체:(.*)/", $config['cf_visit'], $visit);

if(!$visit[0]) $visit[0]=0;
if(!$visit[1]) $visit[1]=0;
if(!$visit[2]) $visit[2]=0;
if(!$visit[3]) $visit[3]=0;
if(!$visit[4]) $visit[4]=0;
if(!$visit[5]) $visit[5]=0;

$new_member_rows = 5;
$new_point_rows = 5;
$new_write_rows = 5;
$to_date=date("Y-m-d",G5_SERVER_TIME);

$sql_common = " from {$g5['member_table']} ";

$sql_search = " where (1) ";

if ($is_admin != 'super')
    $sql_search .= " and mb_level <= '{$member['mb_level']}' ";

if (!$sst) {
    $sst = "mb_datetime";
    $sod = "desc";
}

$sql_order = " order by {$sst} {$sod} ";

$sql = " select count(*) as cnt {$sql_common} {$sql_search} {$sql_order} ";
$row = sql_fetch($sql);
$total_mb_count = $row['cnt'];

$sql = " select count(*) as cnt {$sql_common} {$sql_search} and mb_datetime like '%{$to_date}%' {$sql_order} ";
$row = sql_fetch($sql);
$new_mb_count = $row['cnt'];

// 탈퇴회원수
$sql = " select count(*) as cnt {$sql_common} {$sql_search} and mb_leave_date <> '' {$sql_order} ";
$row = sql_fetch($sql);
$leave_count = $row['cnt'];

// 차단회원수
$sql = " select count(*) as cnt {$sql_common} {$sql_search} and mb_intercept_date <> '' {$sql_order} ";
$row = sql_fetch($sql);
$intercept_count = $row['cnt'];

$sql = " select * {$sql_common} {$sql_search} {$sql_order} limit {$new_member_rows} ";
$result = sql_query($sql);


//게시글 관련
$board_sql_common = " from {$g5['board_new_table']} a, {$g5['board_table']} b, {$g5['group_table']} c where a.bo_table = b.bo_table and b.gr_id = c.gr_id ";

if ($gr_id)
    $board_sql_common .= " and b.gr_id = '$gr_id' ";
if ($view) {
    if ($view == 'w')
        $board_sql_common .= " and a.wr_id = a.wr_parent ";
    else if ($view == 'c')
        $board_sql_common .= " and a.wr_id <> a.wr_parent ";
}
$board_sql_order = " order by a.bn_id desc ";

$board_sql = " select count(*) as cnt {$board_sql_common} ";
$board_row = sql_fetch($board_sql);
$board_total_count = $board_row['cnt'];

$board_sql2 = " select count(*) as cnt {$board_sql_common} where bn_datetime like '%{$to_date}%'";
$board_row2 = sql_fetch($board_sql2);
$board_today_count = $board_row2['cnt'];

$point_sql_common = " from {$g5['point_table']} ";
$point_sql_search = " where (1) ";
$point_sql_order = " order by po_id desc ";

$point_sql = " select count(*) as cnt {$point_sql_common} {$point_sql_search} {$point_sql_order} ";
$point_row = sql_fetch($point_sql);
$point_total_count = $point_row['cnt'];

$point_sql2 = " select count(*) as cnt {$point_sql_common} where po_datetime like '%{$to_date}%' ";
$point_row2 = sql_fetch($point_sql2);
$point_today_count = $point_row2['cnt'];

$point_sql = " select * {$point_sql_common} {$point_sql_search} {$point_sql_order} limit {$new_point_rows} ";
$point_result = sql_query($point_sql);
?>
<div class='row' style='padding:0;'>
	<div class='gc-box col-lg-3 col-md-6 col-sm-12 col-xs-12'>
		<div class='gc-item gc-bg-1'>
			<div class='gc-table'>
				<div class='gc-icon'>
					<i class='fa fa-user-circle-o'></i>
				</div>
				<div class='gc-data'>
					<div class='gc-title'>
						방문자 집계 
						<span class='gc-more pull-right'>
							<a href='./visit_list.php'><i class='fa fa-angle-double-right'></i></a>
						</span>
					</div>
					<div class='gc-conn'>
						<?php echo number_format($visit[2]) ?> <span class='gc-s'>(금일)</span>
					</div>
					<div class='gc-conn'>
						<?php echo number_format($visit[4]) ?> <span class='gc-s'>(전체)</span>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class='gc-box col-lg-3 col-md-6 col-sm-12 col-xs-12'>
		<div class='gc-item gc-bg-2'>
			<div class='gc-table'>
				<div class='gc-icon'>
					<i class='fa fa-list-alt'></i>
				</div>
				<div class='gc-data'>
					<div class='gc-title'>
						게시글 현황
						<span class='gc-more pull-right'>
							<a href='./write_count.php'><i class='fa fa-angle-double-right'></i></a>
						</span>
					</div>
					<div class='gc-conn'>
						<?php echo number_format($board_today_count) ?> <span class='gc-s'>(금일)</span>
					</div>
					<div class='gc-conn'>
						<?php echo number_format($board_total_count) ?> <span class='gc-s'>(전체)</span>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class='gc-box col-lg-3 col-md-6 col-sm-12 col-xs-12'>
		<div class='gc-item gc-bg-3'>
			<div class='gc-table'>
				<div class='gc-icon'>
					<i class='fa fa-users'></i>
				</div>
				<div class='gc-data'>
					<div class='gc-title'>
						회원 현황
						<span class='gc-more pull-right'>
							<a href='./member_list.php'><i class='fa fa-angle-double-right'></i></a>
						</span>
					</div>
					<div class='gc-conn'>
						<?php echo number_format($new_mb_count) ?> <span class='gc-s'>(금일)</span>
					</div>
					<div class='gc-conn'>
						<?php echo number_format($total_mb_count) ?> <span class='gc-s'>(전체)</span>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class='gc-box col-lg-3 col-md-6 col-sm-12 col-xs-12'>
		<div class='gc-item gc-bg-4'>
			<div class='gc-table'>
				<div class='gc-icon'>
					<i class='fa fa-diamond'></i>
				</div>
				<div class='gc-data'>
					<div class='gc-title'>
						포인트 발생
						<span class='gc-more pull-right'>
							<a href='./point_list.php'><i class='fa fa-angle-double-right'></i></a>
						</span>
					</div>
					<div class='gc-conn'>
						<?php echo number_format($point_today_count) ?> <span class='gc-s'>(금일)</span>
					</div>
					<div class='gc-conn'>
						<?php echo number_format($point_total_count) ?> <span class='gc-s'>(전체)</span>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
	
<div class='row' style='padding:0;'>
	<div class='mc-box col-lg-9 col-md-12 col-sm-12 col-xs-12'>
		<div class='mc-item chart-visit'>
			<div class='mc-head'>
				<div class='mc-title'>접속자 현황</div>
				<div class='pull-right btn-group btn-group-sm hidden-sm hidden-xs'>
					<button type='button' class='visit-btn btn btn-default btn-sm active' data-type='hour'>시간</button>
					<button type='button' class='visit-btn btn btn-default btn-sm' data-type='week'>요일</button>
					<button type='button' class='visit-btn btn btn-default btn-sm' data-type='day'>일별</button>
					<button type='button' class='visit-btn btn btn-default btn-sm' data-type='month'>월별</button>
					<button type='button' class='visit-btn btn btn-default btn-sm' data-type='year'>년별</button>
				</div>
				<div class='pull-right hidden-md hidden-lg' style='position:relative;'>
					<a class='dropdown-toggle' data-toggle='dropdown' aria-expanded='false' id="visit-label">
						<i class='fa fa-ellipsis-v'></i>
					</a>
					<ul class="dropdown-menu" role="menu" aria-labelledby="visit-label">
					<li><a href="#visit-dm" class='visit-dm' data-type='hour'><i class='fa fa-check'></i> 시간</a></li>
					<li><a href="#visit-dm" class='visit-dm' data-type='week'><i class='fa fa-check' style='display:none;'></i> 요일</a></li>
					<li><a href="#visit-dm" class='visit-dm' data-type='day'><i class='fa fa-check' style='display:none;'></i> 일별</a></li>
					<li><a href="#visit-dm" class='visit-dm' data-type='month'><i class='fa fa-check' style='display:none;'></i> 월별</a></li>
					<li><a href="#visit-dm" class='visit-dm' data-type='year'><i class='fa fa-check' style='display:none;'></i> 년별</a></li>
					</ul>
				</div>
			</div>
			<div id='chart-visit' class="chart"></div>
		</div>
	</div>
	<div class='mc-box col-lg-3 col-md-12 col-sm-12 col-xs-12'>
		<div class='mc-item chart-browser'>
			<div class='mc-head'>
				<div class='mc-title'>브라우저별 동향</div>
			</div>
			<div id='chart-browser' class="chart"></div>
		</div>
	</div>
</div>

<div class='row' style='padding:0;'>
	<div class='mc-box'>
		<div class='mc-item'>
			<div class='mc-head'>
				<div class='mc-title'>
				최근 가입 회원
				<small class='hidden-xs'>(총회원수 <?php echo number_format($total_mb_count) ?>명 / 차단 <?php echo number_format($intercept_count) ?>명 / 탈퇴 <?php echo number_format($leave_count) ?>명)</small>
				<span class='mc-more-link'><a href='./member_list.php' target='_blank'>더보기 <i class='fa fa-angle-double-right'></i></a></span>
				</div>
			</div>
			<div class="res-tbl">
			<table id='main-tbl-comm-1' class="table footable table-bordered-2 sw-table" data-empty="표시할 데이터가 없습니다.">
			<thead>
				<tr>
					<th class='hidden-lg' style='min-width:30px;width:30px;'>
						<i class='fa fa-ellipsis-h'></i>
					</th>
					<th scope="col" data-breakpoints="xs" style='min-width:150px;width:150px;'>회원아이디</th>
					<th scope="col" style='min-width:100px;'>이름</th>
					<th scope="col" style='min-width:100px;'>닉네임</th>
					<th scope="col" data-breakpoints="xs" style='min-width:80px;width:80px;'>권한</th>
					<th scope="col" data-breakpoints="xs" style='min-width:100px;width:100px;'>포인트</th>
					<th scope="col" data-breakpoints="xs sm" style='min-width:80px;width:80px;'>수신</th>
					<th scope="col" data-breakpoints="xs sm" style='min-width:80px;width:80px;'>공개</th>
					<th scope="col" data-breakpoints="xs sm" style='min-width:80px;width:80px;'>인증</th>
					<th scope="col" data-breakpoints="xs sm" style='min-width:80px;width:80px;'>차단</th>
					<th scope="col" data-breakpoints="xs sm md" style='min-width:80px;width:80px;'>그룹</th>
				</tr>
			</thead>
			<tbody>
			<?php
			for ($i=0; $row=sql_fetch_array($result); $i++){
				// 접근가능한 그룹수
				$sql2 = " select count(*) as cnt from {$g5['group_member_table']} where mb_id = '{$row['mb_id']}' ";
				$row2 = sql_fetch($sql2);
				$group = "";
				if ($row2['cnt'])
					$group = '<a href="./boardgroupmember_form.php?mb_id='.$row['mb_id'].'">'.$row2['cnt'].'</a>';

				if ($is_admin == 'group')
				{
					$s_mod = '';
					$s_del = '';
				}
				else
				{
					$s_mod = '<a href="./member_form.php?$qstr&amp;w=u&amp;mb_id='.$row['mb_id'].'">수정</a>';
					$s_del = '<a href="./member_delete.php?'.$qstr.'&amp;w=d&amp;mb_id='.$row['mb_id'].'&amp;url='.$_SERVER['SCRIPT_NAME'].'" onclick="return delete_confirm(this);">삭제</a>';
				}
				$s_grp = '<a href="./boardgroupmember_form.php?mb_id='.$row['mb_id'].'">그룹</a>';

				$leave_date = $row['mb_leave_date'] ? $row['mb_leave_date'] : date("Ymd", G5_SERVER_TIME);
				$intercept_date = $row['mb_intercept_date'] ? $row['mb_intercept_date'] : date("Ymd", G5_SERVER_TIME);

				$mb_nick = mb_sidemenu($row['mb_id'], get_text($row['mb_nick']), $row['mb_email'], $row['mb_homepage']);

				$mb_id = $row['mb_id'];
				if ($row['mb_leave_date'])
					$mb_id = $mb_id;
				else if ($row['mb_intercept_date'])
					$mb_id = $mb_id;

			?>
			<tr>
				<td class='hidden-lg'></td>
				<td><?php echo $mb_id ?></td>
				<td><?php echo get_text($row['mb_name']); ?></td>
				<td><?php echo $mb_nick ?></td>
				<td><?php echo $row['mb_level'] ?></td>
				<td>
				<a href="./point_list.php?sfl=mb_id&amp;stx=<?php echo $row['mb_id'] ?>"><?php echo number_format($row['mb_point']) ?></a>
				</td>
				<td><?php echo $row['mb_mailling']?'<span class="square-success">예</span>':'<span class="square">아니오</span>'; ?></td>
				<td><?php echo $row['mb_open']?'<span class="square-success">예</span>':'<span class="square">아니오</span>'; ?></td>
				<td><?php echo preg_match('/[1-9]/', $row['mb_email_certify'])?'<span class="square-success">예</span>':'<span class="square">아니오</span>'; ?></td>
				<td><?php echo $row['mb_intercept_date']?'<span class="square-success">예</span>':'<span class="square">아니오</span>'; ?></td>
				<td><?php echo $group ?></td>
			</tr>
			<?php
				}
			?>
			</tbody>
			</table>
			</div>
		</div>
	</div>
</div>		
<div class='row' style='padding:0;'>
	<div class='mc-box'>
		<div class='mc-item'>
			<div class='mc-head'>
				<div class='mc-title'>
					최근게시물
					<small class='hidden-xs'>(전체 게시물 <?php echo number_format($board_total_count) ?>개 중 <?php echo number_format($new_write_rows) ?>개)</small>
					<span class='mc-more-link'><a href='<?php echo G5_BBS_URL ?>/new.php' target='_blank'>더보기 <i class='fa fa-angle-double-right'></i></a></span>
				</div>
			</div>
			<div class="res-tbl">
			<table id='main-tbl-comm-2' class="table footable table-bordered-2 sw-table" data-empty="최근 게시물이 없습니다.">
			<thead>
				<tr>
					<th class='hidden-lg' style='min-width:30px;width:30px;'>
						<i class='fa fa-ellipsis-h'></i>
					</th>
					<th scope="col" style='min-width:100px;'>제목</th>
					<th scope="col" data-breakpoints="xs" style='min-width:100px;width:100px;'>게시판</th>
					<th scope="col" data-breakpoints="xs sm md" style='min-width:100px;width:100px;'>그룹</th>
					<th scope="col" data-breakpoints="xs" style='min-width:150px;width:150px;'>이름</th>
					<th scope="col" data-breakpoints="xs sm" style='min-width:150px;width:150px;'>일시</th>
				</tr>
			</thead>
			<tbody>
			<?php
			$sql = " select a.*, b.bo_subject, c.gr_subject, c.gr_id {$board_sql_common} {$board_sql_order} limit {$new_write_rows} ";
			$result = sql_query($sql);
			for ($i=0; $row=sql_fetch_array($result); $i++)
			{
				$tmp_write_table = $g5['write_prefix'] . $row['bo_table'];

				if ($row['wr_id'] == $row['wr_parent']) // 원글
				{
					$comment = "";
					$comment_link = "";
					$row2 = sql_fetch(" select * from $tmp_write_table where wr_id = '{$row['wr_id']}' ");
					
					$name = mb_sidemenu($row2['mb_id'], get_text(cut_str($row2['wr_name'], $config['cf_cut_name'])), $row2['wr_email'], $row2['wr_homepage']);
					// 당일인 경우 시간으로 표시함
					$datetime = substr($row2['wr_datetime'],0,10);
					$datetime2 = $row2['wr_datetime'];
					if ($datetime == G5_TIME_YMD)
						$datetime2 = substr($datetime2,11,5);
					else
						$datetime2 = substr($datetime2,5,5);

				}
				else // 코멘트
				{
					$comment = "<span class='label label-info'>comment</span> ";
					$comment_link = '#c_'.$row['wr_id'];
					$row2 = sql_fetch(" select * from {$tmp_write_table} where wr_id = '{$row['wr_parent']}' ");
					$row3 = sql_fetch(" select mb_id, wr_name, wr_email, wr_homepage, wr_datetime from {$tmp_write_table} where wr_id = '{$row['wr_id']}' ");

					$name = mb_sidemenu($row3['mb_id'], get_text(cut_str($row3['wr_name'], $config['cf_cut_name'])), $row3['wr_email'], $row3['wr_homepage']);
					// 당일인 경우 시간으로 표시함
					$datetime = substr($row3['wr_datetime'],0,10);
					$datetime2 = $row3['wr_datetime'];
					if ($datetime == G5_TIME_YMD)
						$datetime2 = substr($datetime2,11,5);
					else
						$datetime2 = substr($datetime2,5,5);
				}
			?>
				<tr>
				<td class='hidden-lg'></td>
				<td style='text-align:left;'>
					<a href="<?php echo G5_BBS_URL ?>/board.php?bo_table=<?php echo $row['bo_table'] ?>&amp;wr_id=<?php echo $row2['wr_id'] ?><?php echo $comment_link ?>">
					<?php echo $comment ?><?php echo conv_subject($row2['wr_subject'], 20,'…') ?>
					</a>
				</td>
				<td>
					<a href="<?php echo G5_BBS_URL ?>/board.php?bo_table=<?php echo $row['bo_table'] ?>">
					<?php echo cut_str($row['bo_subject'],20) ?>
					</a>
				</td>
				<td>
					<a href="<?php echo G5_BBS_URL ?>/new.php?gr_id=<?php echo $row['gr_id'] ?>"><?php echo cut_str($row['gr_subject'],10) ?></a>
				</td>
				<td><?php echo $name ?></td>
				<td><?php echo $datetime ?></td>
				</tr>

			<?php
			}
			?>
			</tbody>
			</table>
			</div>
		</div>
	</div>
</div>
<div class='row' style='padding:0;'>
	<div class='mc-box'>
		<div class='mc-item'>
			<div class='mc-head'>
				<div class='mc-title'>
					최근 포인트 발생내역
					<small class='hidden-xs'>(전체 <?php echo number_format($point_total_count) ?> 건 중 <?php echo $new_point_rows ?>건)</small>
					<span class='mc-more-link'><a href='./point_list.php' target='_blank'>더보기 <i class='fa fa-angle-double-right'></i></a></span>
				</div>
			</div>

			<div class="res-tbl">
			<table id='main-tbl-comm-3' class="table footable table-bordered-2 sw-table" data-empty="최근 포인트 발생내역이 없습니다.">
			<thead>
				<tr>
					<th class='hidden-lg' style='min-width:30px;width:30px;'>
						<i class='fa fa-ellipsis-h'></i>
					</th>
					<th scope="col" data-breakpoints="xs" style='min-width:100px;width:100px;'>회원아이디</th>
					<th scope="col" style='min-width:150px;'>이름</th>
					<th scope="col" data-breakpoints="xs" style='min-width:150px;width:150px;'>닉네임</th>
					<th scope="col" data-breakpoints="xs sm" style='min-width:150px;width:150px;'>일시</th>
					<th scope="col" data-breakpoints="xs sm md" style='min-width:150px;width:150px;'>포인트 내용</th>
					<th scope="col" style='min-width:100px;'>포인트</th>
					<th scope="col" data-breakpoints="xs sm" style='min-width:100px;width:100px;'>포인트합</th>
				</tr>
			</thead>
			<tbody>
			<?php
			$row2['mb_id'] = '';
			for ($i=0; $row=sql_fetch_array($point_result); $i++)
			{
				if ($row2['mb_id'] != $row['mb_id'])
				{
					$sql2 = " select mb_id, mb_name, mb_nick, mb_email, mb_homepage, mb_point from {$g5['member_table']} where mb_id = '{$row['mb_id']}' ";
					$row2 = sql_fetch($sql2);
				}

				$mb_nick = mb_sidemenu($row['mb_id'], $row2['mb_nick'], $row2['mb_email'], $row2['mb_homepage']);

				$link1 = $link2 = "";
				if (!preg_match("/^\@/", $row['po_rel_table']) && $row['po_rel_table'])
				{
					$link1 = '<a href="'.G5_BBS_URL.'/board.php?bo_table='.$row['po_rel_table'].'&amp;wr_id='.$row['po_rel_id'].'" target="_blank">';
					$link2 = '</a>';
				}
			?>

			<tr>
				<td class='hidden-lg'></td>
				<td>
				<a href="./point_list.php?sfl=mb_id&amp;stx=<?php echo $row['mb_id'] ?>"><?php echo $row['mb_id'] ?></a>
				</td>
				<td><?php echo get_text($row2['mb_name']); ?></td>
				<td><?php echo $mb_nick ?></td>
				<td><?php echo $row['po_datetime'] ?></td>
				<td><?php echo $link1.$row['po_content'].$link2 ?></td>
				<td><?php echo number_format($row['po_point']) ?></td>
				<td><?php echo number_format($row['po_mb_point']) ?></td>
			</tr>

			<?php
			}
			?>
			</tbody>
			</table>
			</div>
		</div>
	</div>
</div>

<script type='text/javascript'>
$(document).ready(function(){
	chart_visit_view(); //방문자 집계 차트 실행
	chart_browser_view(); //브라우저별 동향 차트 실행
	
	//방문자 집계 차트 버튼 클릭 이벤트 - md 이상 사이즈
	$(".visit-btn").click(function(){
		$(".chart-visit").find(".visit-btn").removeClass("active");
		$(".chart-visit").find(".visit-dm").find("i").hide();
		$(this).addClass("active");
		$(".chart-visit").find(".dropdown-menu").find("li").eq($(this).index()).find("i").show();

		visit_types=$(this).attr("data-type");

		chart_visit_view();
	});
	
	//방문자 집계 차트 버튼 클릭 이벤트 - sm 이하 사이즈
	$(".visit-dm").click(function(){
		$(".chart-visit").find("button").removeClass("active");
		$(".chart-visit").find(".visit-dm").find("i").hide();
		$(this).find("i").show();
		$(".chart-visit").find(".visit-btn").eq($(this).parent().index()).addClass("active");

		visit_types=$(this).attr("data-type");

		chart_visit_view();
	});
});
</script>