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

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

$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];
$rows = 30;
$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 = 13;
?>

<script language="JavaScript">
var list_update_php = 'board_list_update.php';
var list_delete_php = 'board_list_delete.php';
</script>

<table width=100% cellpadding=3 cellspacing=1>
<form name=fsearch method=get>
<tr>
    <td width=50% align=left><?=$listall?> (게시판수 : <?=number_format($total_count)?>개)</td>
    <td width=50% align=right>
        <select name=sfl>
            <option value='bo_table'>TABLE</option>
            <option value='bo_subject'>제목</option>
            <option value='a.gr_id'>그룹ID</option>
        </select>
        <input type=text name=stx required itemname='검색어' value='<?=$stx?>'>
        <input type=image src='<?=$g4[admin_path]?>/img/btn_search.gif' align=absmiddle></td>
</tr>
</form>
</table>

<table width=100% cellpadding=0 cellspacing=1>
<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?>">
<colgroup width=30>   <!-- 체크박스 -->
<colgroup width=100>  <!-- TABLE -->
<colgroup width=>     <!-- 그룹 -->
<colgroup width=>     <!-- 스킨 -->
<colgroup width=150>  <!-- 파일경로 -->
<colgroup width=100>   <!-- 추가 -->
<colgroup width=50>   <!-- 추가 -->
<colgroup width=40>   <!-- 추가 -->

<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
<tr class='bgcol2 bold col1 ht center'>
    <td rowspan=2><input type=checkbox name=chkall value="1" onclick="check_all(this.form)"></td>
    <td rowspan=2>TABLE</a></td>
    <td colspan=2>제목</a></td>
    <td title="상단 파일 경로">상단 파일 경로</td>
    <td rowspan=2 title="읽기">권한설정</td>
    <td rowspan=2 title="읽기">편집기<br>사용</td>
	<td rowspan=2><a href="./board_form.php"><img src='<?=$g4[admin_path]?>/img/icon_insert.gif' border=0 title='생성'></a></td>
</tr>
<tr class='bgcol2 bold col1 ht center'>
    <td>그룹</a></td>
    <td>스킨</a></td>
	<td>하단 파일 경로</td>
</tr>

<tr><td colspan='<?=$colspan?>' class='line2'></td></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'><img src='img/icon_modify.gif' border=0 title='수정'></a>";
    $s_del = "";
    if ($is_admin == "super") 
        $s_del = "<a href=\"javascript:del('./board_delete.php?bo_table=$row[bo_table]&$qstr');\"><img src='img/icon_delete.gif' border=0 title='삭제'></a>";
    $s_copy = "<a href=\"javascript:board_copy('$row[bo_table]');\"><img src='img/icon_copy.gif' border=0 title='복사'></a>";

    /*
    // 스킨디렉토리
    $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]'";
        if ($arr[$k] == $row[bo_skin])
            $skin_options .= " selected";
        $skin_options .= ">$option</option>";
    }
    */

    $list = $i % 2;
    echo "<input type=hidden name=board_table[$i] value='$row[bo_table]'>";
    echo "<tr class='list$list col1 ht center'>";
    echo "<td rowspan=3 height=25><input type=checkbox name=chk[] value='$i'></td>";
    echo "<td rowspan=3><a href='$g4[bbs_path]/board.php?bo_table=$row[bo_table]'><b>$row[bo_table]</b></a></td>";
    echo "<td colspan=2 align=left height=25><input type=text class=ed name=bo_subject[$i] value='".get_text($row[bo_subject])."' style='width:99%'></td>";

    echo "<td title='상단파일경로'><input type=text class=ed name=bo_include_head[$i] value='$row[bo_include_head]' style='width:100%;'></td>";

    echo "<td rowspan=3 title='읽기'><TABLE>
	<TR>
		<TD align='right'>읽기</TD>
		<TD>".get_member_level_select('bo_read_level['.$i.']', 1, 10,  $row[bo_read_level])."</TD>
	</TR>
	<TR>
		<TD align='right'>쓰기</TD>
		<TD>".get_member_level_select('bo_write_level['.$i.']', 1, 10,  $row[bo_write_level])."</TD>
	</TR>
	<TR>
		<TD align='right'>답변</TD>
		<TD>".get_member_level_select('bo_reply_level['.$i.']', 1, 10,  $row[bo_reply_level])."</TD>
	</TR>
	<TR>
		<TD align='right'>코멘트</TD>
		<TD>".get_member_level_select('bo_comment_level['.$i.']', 1, 10,  $row[bo_comment_level])."</TD>
	</TR>
	</TABLE></td>";
    echo "<td rowspan=3><input type=checkbox name=bo_use_dhtml_editor ".($row[bo_use_dhtml_editor]?'checked':'')." value='1'><br>사용</td>";
    echo "<td rowspan=3><table><tr><td>$s_upd</td></tr><tr><td>$s_del</td></tr><tr><td>$s_copy</td></tr></table></td>";
    echo "</tr>";
    echo "<tr class='list$list col1 ht center'>";
	
    if ($is_admin == "super")
        echo "<td align=right>".get_group_select("gr_id[$i]", $row[gr_id])."</td>";
    else
        echo "<td align=center><input type=hidden name='gr_id[$i]' value='$row[gr_id]'>$row[gr_subject]</td>";

    echo "<td align=left><select id=bo_skin_$i name=bo_skin[$i]>$skin_options</select></td>";
    echo "<td align='left'><input type=text class=ed name=bo_include_tail[$i] value='$row[bo_include_tail]' style='width:100%;'></td>";
    echo "</tr>\n";
	echo "<tr><td colspan=3>&nbsp;카테고리 <input type=text class=ed name=bo_category_list[$i] style='width:70%;' value='".get_text($row[bo_category_list])."'><input type=checkbox name=bo_use_category[$i] value='1' ".($row[bo_use_category]?'checked':'')."><b>사용</b>";
	echo "</td></tr>";
	echo "<tr><td colspan='$colspan' height='1' bgcolor='#CCCCCC'></td></tr>\n";
    echo "<script language='JavaScript'>document.getElementById('bo_skin_$i').value='$row[bo_skin]';</script>";
} 

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=");
echo "<table width=100% cellpadding=3 cellspacing=1>";
echo "<tr><td width=70%>";
echo "<input type=button class='btn1' value='선택수정' onclick=\"btn_check(this.form, 'update')\"> ";

if ($is_admin == "super")
    echo "<input type=button class='btn1' value='선택삭제' onclick=\"btn_check(this.form, 'delete')\">";

echo "</td>";
echo "<td width=30% align=right>$pagelist</td></tr></table>\n";

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

<script language="JavaScript">
function board_copy(bo_table)
{
    window.open("./board_copy.php?bo_table="+bo_table, "BoardCopy", "left=10,top=10,width=640,height=650");
}
</script>

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