<?php
include_once "./_common.php";
$g4['title'] = "게시물 " . $act;
include_once "{$g4[g4m_path]}/head.sub.php";

if ($sw == "move")
    $act = "이동";
else if ($sw == "copy")
    $act = "복사";
else
    alert("sw 값이 제대로 넘어오지 않았습니다.");

// 게시판 관리자 이상 복사, 이동 가능
if ($is_admin != "board" && $is_admin != "group" && $is_admin != "super")
    alert_close("게시판 관리자 이상 접근이 가능합니다.");



$wr_id_list = "";
if ($wr_id)
    $wr_id_list = $wr_id;
else {
    $comma = "";
    for ($i = 0; $i < count($_POST['chk_wr_id']); $i++) {
        $wr_id_list .= $comma . $_POST['chk_wr_id'][$i];
        $comma = ",";
    }
}

$sql = " select * from {$g4['board_table']} a, {$g4['group_table']} b where a.gr_id = b.gr_id and bo_table <> '$bo_table' ";
if ($is_admin == 'group')
    $sql .= " and b.gr_admin = '{$member['mb_id']}' ";
else if ($is_admin == 'board')
    $sql .= " and a.bo_admin = '{$member['mb_id']}' ";
$sql .= " order by a.gr_id, a.bo_order_search, a.bo_table ";
$result = sql_query($sql);
for ($i = 0; $row = sql_fetch_array($result); $i++) {
    $list[$i] = $row;
}
?>
<div class="page-header">
    <h2>게시물<?php echo $act ?></h2>
</div>
<div class="alert alert-info">
    ※ <?php echo $act ?>할 게시판을 한개 이상 선택하여 주십시오.
</div>



<form name="fboardmoveall" method="post" onsubmit="return fboardmoveall_submit(this);" class="form-horizontal">
    <input type='hidden' name='sw'          value='<?php echo $sw ?>'/>
    <input type='hidden' name='bo_table'    value='<?php echo $bo_table ?>'/>
    <input type='hidden' name='wr_id_list'  value="<?php echo $wr_id_list ?>"/>
    <input type='hidden' name='sfl'         value='<?php echo $sfl ?>'/>
    <input type='hidden' name='stx'         value='<?php echo $stx ?>'/>
    <input type='hidden' name='spt'         value='<?php echo $spt ?>'/>
    <input type='hidden' name='page'        value='<?php echo $page ?>'/>
    <input type='hidden' name='act'         value='<?php echo $act ?>'/>


    <table class="table">

        <?php for ($i = 0; $i < count($list); $i++) { ?>
            <tr> 
                <td><input type=checkbox id='chk<?php echo $i ?>' name='chk_bo_table[]' value="<?php echo $list[$i]['bo_table'] ?>"></td>
                <td>
                    <span style="cursor:pointer;" onclick="document.getElementById('chk<?php echo $i ?>').checked=document.getElementById('chk<?php echo $i ?>').checked?'':'checked';">
                        <?php
                        if ($save_gr_subject == $list[$i]['gr_subject'])
                            echo "<span style='color:#cccccc;'>";
                        else
                            echo "<span>";
                        echo $list[$i]['gr_subject'] . " > ";
                        echo "</span>";
                        $save_gr_subject = $list[$i]['gr_subject'];
                        ?>
                        <?php echo $list[$i]['bo_subject'] ?> (<?php echo $list[$i]['bo_table'] ?>)</span>
                </td>
            </tr>
        <?php } ?>
    </table>
    <div class="form-actions">
        <input id="btn_submit" type='submit' class="btn btn-primary" value="확인"/>
        <a href="javascript:window.close();" class="btn">창닫기</a>
    </div>

</form>

<script type='text/javascript'>
    function fboardmoveall_submit(f)    {
        var check = false;

        if (typeof(f.elements['chk_bo_table[]']) == 'undefined') 
            ;
        else {
            if (typeof(f.elements['chk_bo_table[]'].length) == 'undefined') {
                if (f.elements['chk_bo_table[]'].checked) 
                    check = true;
            } else {
                for (i=0; i<f.elements['chk_bo_table[]'].length; i++) {
                    if (f.elements['chk_bo_table[]'][i].checked) {
                        check = true;
                        break;
                    }
                }
            }
        }

        if (!check) {
            alert('게시물을 '+f.act.value+'할 게시판을 한개 이상 선택해 주십시오.');
            return false;
        }

        document.getElementById("btn_submit").disabled = true;

        f.action = "./move_update.php";
        return true;
    }
</script>


<?
include_once "{$g4['g4m_path']}/tail.sub.php";