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

if ($is_admin != 'super')
    alert('최고관리자만 접근 가능합니다.');

$token = get_token();

$sql_common = 'FROM '.$bt['page_table'];

//===========================================================================
// 조건절 처리
//===========================================================================
$sql_search = " WHERE (1) ";
if ($stx) {
    $sql_search .= " AND ( ";
    switch ($sfl) {
        default :
            $sql_search .= " ({$sfl} LIKE '%{$stx}%') ";
            break;
    }
    $sql_search .= " ) ";
}

//===========================================================================
// 출력순서 처리
//===========================================================================
if (!$sst) {
    $sst  = "bp_id";
    $sod = "";
}
$sql_order = " ORDER BY $sst $sod ";

//===========================================================================
// 레코드 개수 구함
//===========================================================================
$sql = " SELECT COUNT(*) AS cnt
            {$sql_common}
            {$sql_search}
            {$sql_order} ";
$total_count = $bdb->result($sql);

//===========================================================================
// 페이징 계산
//===========================================================================
$rows = $config['cf_page_rows'];
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
$page = Str::binValue($_GET['page'], 1);
$from_record = ($page - 1) * $rows; // 시작 열을 구함

//===========================================================================
// 목록 쿼리
//===========================================================================
$sql = "SELECT * FROM ".$bt['page_table'].$sql_search.$sql_order;
$result = $bdb->query($sql);

//===========================================================================
// 검색 SelectBox 옵션
//===========================================================================
$search_s = new SelectBox();
$search_s->add('bp_title', '페이지 제목');
$search_s->add('bp_id', '페이지 아이디');
if($sfl) $search_s->selectedFromValue = $sfl;

$g5['title'] = '페이지관리';
$administrator = 1;
include_once(G5_ADMIN_PATH.'/admin.head.php');
?>

<script type="text/javascript">
<!--
function delCheck(bp_id){
	if(!confirm('삭제할까요?')) return;
	locaion.href = './page_update.php?w=d&bp_id=' + bp_id + '&<?php echo $qstr?>';
}
//-->
</script>

<div class="local_ov01 local_ov">
    <?php echo $listall ?>
    페이지관리 <?php echo number_format($total_count) ?>건
</div>

<form name="fsearch" id="fsearch" class="local_sch01 local_sch" method="get">
<label for="sfl" class="sound_only">검색대상</label>
<select name="sfl"><?php echo $search_s->getOption()?></select>
<label for="stx" class="sound_only">검색어<strong class="sound_only"> 필수</strong></label>
<input type="text" name="stx" value="<?php echo $stx ?>" id="stx" required class="required frm_input">
<input type="submit" value="검색" id="fsearch_submit" class="btn_submit">
</form>

<?php if ($is_admin == 'super') { ?>
<div class="btn_add01 btn_add">
    <a href="./page_form.php" id="bp_add">페이지 추가</a>
</div>
<?php } ?>

<form name="fpagelist" id="fpagelist" method="post" action="./page_update.php" onsubmit="return fauthlist_submit(this);">
<input type="hidden" name="sst" value="<?php echo $sst ?>">
<input type="hidden" name="sod" value="<?php echo $sod ?>">
<input type="hidden" name="sfl" value="<?php echo $sfl ?>">
<input type="hidden" name="stx" value="<?php echo $stx ?>">
<input type="hidden" name="page" value="<?php echo $page ?>">
<input type="hidden" name="token" value="<?php echo $token ?>">
<input type="hidden" name="w" value="md">

<div class="tbl_head01 tbl_wrap">
    <table>
    <caption><?php echo $g5['title']; ?> 목록</caption>
    <thead>
    <tr>
        <th scope="col">
            <label for="chkall" class="sound_only">전체</label>
            <input type="checkbox" name="chkall" value="1" id="chkall" onclick="check_all(this.form)">
        </th>
        <th scope="col"><?php echo subject_sort_link('bp_id') ?>페이지아이디</a></th>
        <th scope="col"><?php echo subject_sort_link('bp_title') ?>페이지제목</a></th>
        <th scope="col">수정</th>
        <th scope="col">삭제</th>
    </tr>
    </thead>
    <tbody>
<?php for ($i=0; $row=sql_fetch_array($result); $i++){?>
	<tr>
		<td class="td_chk">
			<input type="hidden" name="bp_id[<?php echo $i ?>]" value="<?php echo $row['bp_id'] ?>">
            <label for="chk_<?php echo $i; ?>" class="sound_only">선택</label>
            <input type="checkbox" name="chk[]" value="<?php echo $i ?>" id="chk_<?php echo $i ?>">
		</td>
		<td class="td_id"><?php echo $row['bp_id']?></td>
		<td class="td_subject"><?php echo $row['bp_title']?></td>
		<td class="td_grid"><a href="./page_form.php?bp_id=<?php echo $row['bp_id']?>&<?php echo $qstr?>">수정</a></td>
		<td class="td_grid"><a href="./page_update.php?w=d&bp_id=<?php echo $row['bp_id']?>&<?php echo $qstr?>" onclick="delCheck('<?php echo $row['bp_id']?>');return false">삭제</a></td>
	</tr>
<?php }?>
    </tbody>
	</table>
</div>

<div class="btn_list01 btn_list">
    <input type="submit" name="act_button" value="선택삭제" onclick="document.pressed=this.value">
</div>

</form>


<?php
$pagelist = get_paging(G5_IS_MOBILE ? $config['cf_mobile_pages'] : $config['cf_write_pages'], $page, $total_page, $_SERVER['PHP_SELF'].'?'.$qstr.'&amp;page=');
echo $pagelist;
?>


<?php
include_once(G5_ADMIN_PATH.'/admin.tail.php');