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

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

$token = get_token();

// DHTML 에디터 사용 필드 추가 : 061021
sql_query(" ALTER TABLE `$g4[board_table]` ADD `bo_use_dhtml_editor` TINYINT NOT NULL AFTER `bo_use_secret` ", false);
// RSS 보이기 사용 필드 추가 : 061106
sql_query(" ALTER TABLE `$g4[board_table]` ADD `bo_use_rss_view` TINYINT NOT NULL AFTER `bo_use_dhtml_editor` ", false);

$sql_common = " from $g4[board_table] a ";
$sql_search = " where (1) ";

if ($is_admin != "super") {
    $sql_common .= " , $g4[group_table] b ";
    $sql_search .= " and (a.gr_id = b.gr_id and b.gr_admin = '$member[mb_id]') ";
}

if ($stx) {
    $sql_search .= " and ( ";
    switch ($sfl) {
        case "bo_table" :
            $sql_search .= " ($sfl like '$stx%') ";
            break;
        case "a.gr_id" :
            $sql_search .= " ($sfl = '$stx') ";
            break;
        default : 
            $sql_search .= " ($sfl like '%$stx%') ";
            break;
    }
    $sql_search .= " ) ";
}

if (!$sst) {
    $sst  = "a.gr_id, a.bo_table";
    $sod = "asc";
}
$sql_order = " order by $sst $sod ";

$sql = " select count(*) as cnt
         $sql_common
         $sql_search
         $sql_order ";
$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
          $sql_order
          limit $from_record, $rows ";
$result = sql_query($sql);

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

$g4[title] = "게시판 목록";
include_once("./admin.head.php");

$colspan = 12;
?>
<style>
.tbl_box	{ border:1px solid #CBCBCB; border-top:2px solid #989898; }
.tbl_box tr th	{ background:#F7F7F7; height:35px; 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; }
span.vline		{ border-right:1px solid #E3E3E3; margin:0 5px 0 5px; height:10px; }
table tr td a:hover	{ text-decoration:underline; }
</style>

<script type="text/javascript">
var list_update_php = 'board_list_update.php';
var list_delete_php = 'board_list_delete.php';
</script>

<?=subtitle("게시판 목록")?>
<div class="subtitle_msg">게시판 생성 및 관리입니다. 모바일 스킨은 게시판 설정 화면에서 변경 할 수 있습니다.</div>

<table width=100% cellpadding=2 cellspacing=1 border=0>
<form name=fsearch method=get>
<tr>
    <td width=100 align=left><input type="button" class="bttn_blue" value="게시판 생성" onclick="zm_gourl('./board_form.php')"></td>
	<td><?=$listall?> (게시판수 : <?=number_format($total_count)?>개)</td>
    <td width=30% align=right>
        <select name=sfl class="csssel">
            <option value='bo_table'>TABLE</option>
            <option value='bo_subject'>제목</option>
            <option value='a.gr_id'>그룹ID</option>
        </select>
        <input type=text name=stx class=ed required itemname='검색어' value='<?=$stx?>'>
        <input type=submit class="bttn_search" value="검색"></td>
</tr>
</form>
</table>

<form name=fboardlist method=post>
<input type=hidden name=sst   value="<?=$sst?>">
<input type=hidden name=sod   value="<?=$sod?>">
<input type=hidden name=sfl   value="<?=$sfl?>">
<input type=hidden name=stx   value="<?=$stx?>">
<input type=hidden name=page  value="<?=$page?>">
<input type=hidden name=token value="<?=$token?>">
<table width=100% cellpadding=0 cellspacing=0 border=0 class="tbl_box">
<tr>
    <th><input type=checkbox name=chkall value="1" onclick="check_all(this.form)"></th>
    <th><?=subject_sort_link("bo_table")?>TABLE</a></th>
	<th><?=subject_sort_link("a.gr_id")?>그룹</a></th>
    <th><?=subject_sort_link("bo_subject")?>제목</a></th>
	<th><?=subject_sort_link("bo_skin", "", "desc")?>스킨</a></th>
    <th title="글읽기 포인트"><?=subject_sort_link("bo_read_point")?>읽기<br>포인트</a></th>
    <th title="글쓰기 포인트"><?=subject_sort_link("bo_write_point")?>쓰기<br>포인트</a></th>
    <th title="코멘트쓰기 포인트"><?=subject_sort_link("bo_comment_point")?>코멘트<br>포인트</a></th>
    <th title="다운로드 포인트"><?=subject_sort_link("bo_download_point")?>다운<br>포인트</a></th>
    <th title="검색사용"><?=subject_sort_link("bo_use_search")?>검색<br>사용</a></th>
    <th title="검색순서"><?=subject_sort_link("bo_order_search")?>검색<br>순서</a></th>
	<th>처리</th>
</tr>
<?
// 스킨디렉토리
$skin_options = "";
$arr = get_skin_dir("board");
for ($k=0; $k<count($arr); $k++) 
{
    $option = $arr[$k];
    if (strlen($option) > 10)
        $option = substr($arr[$k], 0, 18) . "…";

    $skin_options .= "<option value='$arr[$k]'>$option</option>";
}

for ($i=0; $row=sql_fetch_array($result); $i++) {
    $s_upd = "<a href='./board_form.php?w=u&bo_table=$row[bo_table]&$qstr'>수정</a>";
    $s_del = "";
    if ($is_admin == "super") {
        $s_del = "<a href=\"javascript:post_delete('board_delete.php', '$row[bo_table]');\">삭제</a>";
    }
    $s_copy = "<a href=\"javascript:board_copy('$row[bo_table]');\">복사</a>";

    $list = $i % 2;
?>
<input type=hidden name=board_table[<?=$i?>] value='<?=$row[bo_table]?>'>
<tr>
    <td height=25><input type=checkbox name=chk[] value='<?=$i?>'></td>
	<td align=left><img src="./img/icon_new_win.gif" valign="middle">&nbsp;<a href='<?=$g4[bbs_path]?>/board.php?bo_table=<?=$row[bo_table]?>' target="_blank" class="bo_table"><?=$row[bo_table]?></a></td>
<?	if ($is_admin == "super") : ?>	<td align=left><?=get_group_select("gr_id[$i]", $row[gr_id]) ?></td>
<?  else : ?>						<td align=center><input type=hidden name='gr_id[<?=$i?>]' value='<?=$row[gr_id]?>'><?=$row[gr_subject]?></td>
<?	endif; ?>
    <td><input type=text class=ed name=bo_subject[<?=$i?>] value='<? echo get_text($row[bo_subject]) ?>' style='width:140px;'></td>
	<td align=left><select id=bo_skin_<?=$i?> name=bo_skin[<?=$i?>]><?=$skin_options?></select></td>
    <td title='읽기 포인트'><input type=text class=ed name=bo_read_point[<?=$i?>] value='<?=$row[bo_read_point]?>' style='width:33px;'></td>
    <td title='쓰기 포인트'><input type=text class=ed name=bo_write_point[<?=$i?>] value='<?=$row[bo_write_point]?>' style='width:33px;'></td>
    <td title='속글쓰기 포인트'><input type=text class=ed name=bo_comment_point[<?=$i?>] value='<?=$row[bo_comment_point]?>' style='width:33px;'></td>
    <td title='다운로드 포인트'><input type=text class=ed name=bo_download_point[<?=$i?>] value='<?=$row[bo_download_point]?>' style='width:33px;'></td>
    <td title='검색사용'><input type=checkbox name=bo_use_search[<?=$i?>] <?=($row[bo_use_search] ? 'checked' : '') ?> value='1'></td>
    <td title='검색순서'><input type=text class=ed name=bo_order_search[<?=$i?>] value='<?=$row[bo_order_search]?>' size=2></td>
    <td align="center"><?=$s_upd?><span class="vline"></span><?=$s_del?><span class="vline"></span><?=$s_copy?></td>
</tr>
<script type='text/javascript'>document.getElementById('bo_skin_<?=$i?>').value='<?=$row[bo_skin]?>';</script>
<?
}	//-- end for

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

echo "<tr><td colspan='$colspan' class='line2'></td></tr>";
echo "</table>";

$pagelist = get_paging($config[cf_write_pages], $page, $total_page, "$_SERVER[PHP_SELF]?$qstr&page=");
?>
<div style="padding:4px;">
	<input type=button class='bttn_common' value='선택수정' onclick="btn_check(this.form, 'update')">
<?	if ($is_admin == "super") : ?>
    <input type=button class='bttn_common' value='선택삭제' onclick="btn_check(this.form, 'delete')">
<?	endif; ?>
	<input type="button" class="bttn_blue" value="게시판 생성" onclick="zm_gourl('./board_form.php')">
</div>
<div><?=$pagelist?></div>

<?
if ($stx)
    echo "<script>document.fsearch.sfl.value = '$sfl';</script>";
?>
</form>

<script type="text/javascript">
function board_copy(bo_table) {
    window.open("./board_copy.php?bo_table="+bo_table, "BoardCopy", "left=10,top=10,width=500,height=280");
}
</script>

<script>
// POST 방식으로 삭제
function post_delete(action_url, val)
{
	var f = document.fpost;

	if(confirm("한번 삭제한 자료는 복구할 방법이 없습니다.\n\n정말 삭제하시겠습니까?")) {
        f.bo_table.value = val;
		f.action         = action_url;
		f.submit();
	}
}
</script>

<form name='fpost' method='post'>
<input type='hidden' name='sst'   value='<?=$sst?>'>
<input type='hidden' name='sod'   value='<?=$sod?>'>
<input type='hidden' name='sfl'   value='<?=$sfl?>'>
<input type='hidden' name='stx'   value='<?=$stx?>'>
<input type='hidden' name='page'  value='<?=$page?>'>
<input type='hidden' name='token' value='<?=$token?>'>
<input type='hidden' name='bo_table'>
</form>

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