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

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

$token		= get_token();
$sql_where	= "where 1";

$now		= date("Y-m-d H:i:s", $g4[server_time]);
if($sfl == "id")	{ $sql_where .= " and db_block_id='$stx'"; }
if($sfl == "block")	{ $sql_where .= " and db_block_end>='$now'"; }

$sql	= "select count(*) as cnt from $zmb[table_blacklist_mem] $sql_where";
$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 * from $zmb[table_blacklist_mem] $sql_where limit $from_record, $rows";
$result = sql_query($sql);

$listall = "<a href='$_SERVER[PHP_SELF]'>처음</a>";

$g4[title] = "블랙리스트";
include_once("./admin.head.php");

$colspan = 6;
?>

<table width=100% cellpadding=2 cellspacing=1 border=0>
<form name=fsearch method=get>
<tr>
    <td width=40% align=left><?=$listall?> (블랙리스트 : <?=number_format($total_count)?>명) <a href="?sfl=block">차단된 회원만 보기▼</a> <a href="?">모두 보기▼</a></td>
	<td width=>	</td>
    <td width=30% align=right>
        <select name=sfl>
            <option value='id'>아이디</option>
        </select>
        <input type=text name=stx class=ed required itemname='검색어' value='<?=$stx?>'>
        <input type=image src='<?=$g4[admin_path]?>/img/btn_search.gif' align=absmiddle></td>
</tr>
</form>
</table>
<?=subtitle("블랙리스트")?>
<form name=fboardlist method=post>
<input type="hidden" name="mode" value="bl_update">
<table width=100% cellpadding=0 cellspacing=1 border=0>
<colgroup width=30>
<colgroup width=20%>
<colgroup width=20%>
<colgroup width=20%>
<colgroup width=20%>
<colgroup width=>
<tr><td colspan='<?=$colspan?>' class='line1'></td></tr>
<tr class='bgcol1 bold col1 ht center'>
    <td><input type=checkbox name=chkall value="1" onclick="check_all(this.form)"></td>
    <td><?=subject_sort_link("bo_table")?>닉네임</a></td>
	<td>누적신고 수</td>
    <td>차단 마감일 (영구차단)</td>
	<td>이용제한 서비스</td>
    <td></td>
</tr>
<?	$i	= 0;
	while($rd = sql_fetch_array($result)) : 
	$mb		= get_member($rd[db_block_id]);
	$nick	= get_sideview($rd[db_block_id], $mb[mb_nick], $mb[mb_email], $mb[mb_homepage]);
	if(!$rd[db_block_id])	$nick	="<span class='txtsmall'>(탈퇴회원)</span>";
	$tmp	= explode("/", $rd[db_block_service]);
	if($tmp[0]) $service_write = "checked"; else $service_write = "";
	if($tmp[1]) $service_memo = "checked"; else $service_memo = "";
	if($rd[db_flag] == "1") $forever_block = "checked"; else $forever_block = "";
?>
<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
<tr class='list<?=$list?> col1 ht center' onMouseOver="this.style.backgroundColor='#F6F8FA'" onMouseOut="this.style.backgroundColor=''">
    <td height=25><input type=checkbox name=chk[] value="<?=$rd[db_recno]?>"></td>
	<td><?=$nick?> <?=$rd[db_block_id]?></td>
    <td><input size=4 name="in_report_cnt[<?=$rd[db_recno]?>]" value="<?=$rd[db_report_count]?>">(숫자만)</td>
	<td><input name="in_block_end[<?=$rd[db_recno]?>]" value="<?=$rd[db_block_end]?>" title="날짜 형식을 지켜주세요. <?=date("Y-m-d H:i:s")?>"> (<input type="checkbox" name="in_flag[<?=$rd[db_recno]?>]" <?=$forever_block?> value="1" onClick="chkAlert(this, 'f', '<?=$i?>');">)</td>
    <td><input type="checkbox" name="in_write[<?=$rd[db_recno]?>]" <?=$service_write?> value="1" onClick="chkAlert(this, 'w', '<?=$i?>');">글쓰기, 
	<input type="checkbox" name="in_memo[<?=$rd[db_recno]?>]" <?=$service_memo?> value="1" onClick="chkAlert(this, 'm', '<?=$i?>');">쪽지발송</td>
    <td><input type="button" value="삭제" class="btn1" onClick="if(confirm('회원을 블랙리스트에서 제외 할까요?')) zm_gourl('./zm.report_process.php?mode=bl_delete&recno=<?=$rd[db_recno]?>');"></td>
</tr>
<?	$i++;
	endwhile; ?>
 
<?
if ($i == 0)
    echo "<tr><td colspan='$colspan' align=center height=100 bgcolor=#ffffff>자료가 없습니다.</td></tr>"; 
?>
	<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
	</table>
<?
$pagelist = get_paging($config[cf_write_pages], $page, $total_page, "$_SERVER[PHP_SELF]?$qstr&page=");
?>
<div>※ 목록에 있어도 차단 마감일이 오늘보다 크고 이용제한 서비스에 체크 된 항목이 있어야 서비스 제한을 받습니다.</div>
	<table width=100% cellpadding=3 cellspacing=1>
	<tr><td width=50%>
		<input type=button class='btn1' value='수정적용' onClick="btn_chk(this.form, 'bl_update')">
<?
if ($is_admin == "super")
    echo "<input type=button class='btn1' value='선택삭제' onclick=\"btn_chk(this.form, 'bl_delete_all')\">";
?>
		</td>
		<td align=right><?=$pagelist?></td></tr></table>
<?
if ($stx)
    echo "<script>document.fsearch.sfl.value = '$sfl';</script>";
?>
</form>
<script language="javascript">
function btn_chk(f, m) {
	var chk = document.getElementsByName("chk[]");

	f.mode.value = m;
	
	var sw = 0;
	for(i=0; i<chk.length; i++) {
		if(chk[i].checked) sw = 1;
	}
	if(!sw) { alert("선택 된 리스트가 없습니다."); return false; }

	f.action	= "./zm.report_process.php";
	f.submit();
}

function chkAlert(th, d, idx) {
	var	s = "";
	var fi = document.getElementsByName("chk[]");

	if(d == "w") s = "글쓰기";
	if(d == "m") s = "쪽지발송";
	if(d == "f") s = "영구히";
	if(th.checked) {
		alert(s+" 서비스를 제한 합니다.");
		fi[idx].checked	= true;
	}
}

</script>

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