<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가 

//CSS Load
include_once(AMINA_PATH.'/css.php');

// Link Reset
if($sca) $qstr2 .= '&sca='.urlencode($sca);
$qstr2 = $qstr2.$frame_opt;

$no_list = '게시물이 없습니다.';

//Search Form
$is_sch_form = ($frame || $bo_table == $amina['tag_board']) ? false : true;

//Deco List
$is_deco_list = ($amina['deco_list'] && $amina['deco_list'] != 'none') ? true : false;

echo '<div id="bo_list_wrap" class="deco-list">'."\n";

//Setting
if(!$amina['list_skin']) { 
	if($is_admin) {
		alert("아미나 스킨을 설정합니다.", G4_ADMIN_URL.'/amina.admin.php?bo_table='.$bo_table);
	} else {
		alert("아미나 스킨을 설정합니다.", './login.php?wr_id='.$wr_id.$qstr.'&url='.urlencode(G4_ADMIN_URL.'/amina.admin.php?bo_table='.$bo_table));
	}
} else { 
	if($amina['addon_skin'] && $amina['addon_skin'] != "none") {
		$addon_skin_path = AMINA_PATH.'/skin/addon/'.$amina['addon_skin'];
		$addon_skin_url = AMINA_URL.'/skin/addon/'.$amina['addon_skin'];
		include_once ($addon_skin_path.'/addon.skin.php');
	}

	if($amina['tag_board'] && $bo_table == $amina['tag_board']) {
		include_once (AMINA_PATH.'/tag.list.php');
	} else {
		//bo_type
		if(file_exists($list_skin_path.'/list.rows.php')) {
			@include_once ($list_skin_path.'/list.rows.php');
		} else {
			switch($amina['bo_type']) {
				case '1'	: include_once (AMINA_PATH.'/list.linked.php'); break;
				case '2'	: include_once (AMINA_PATH.'/list.1vs1.php'); break;
				default		: include_once (AMINA_PATH.'/list.rows.php'); break;
			}
		}
	}

	if(!$frame && $amina['info_skin'] && $amina['info_skin'] != "none") { //Addon Skin
		$info_skin_path = AMINA_PATH.'/skin/info/'.$amina['info_skin'];
		$info_skin_url = AMINA_URL.'/skin/info/'.$amina['info_skin'];
		include_once ($info_skin_path.'/info.skin.php');
	}

	if($is_deco_list) {
		echo '<link rel="stylesheet" href="'.AMINA_URL.'/skin/deco/list/'.$amina['deco_list'].'.css" />'."\n";
		echo '<div class="deco-list-head-back"><div class="deco-list-head-front"><div class="deco-list-head"></div></div></div>'."\n";
		echo '<div class="deco-list-body-back"><div class="deco-list-body-front">'."\n";
	}

	if($is_category) { //Category
		$cate_skin_path = AMINA_PATH.'/skin/cate/'.$amina['cate_skin'];
		$cate_skin_url = AMINA_URL.'/skin/cate/'.$amina['cate_skin'];
		include($cate_skin_path.'/cate.skin.php');
	}

?>
	<form id="fboardlist" name="fboardlist" method="post" data-ajax="false">
	<input type="hidden" name="bo_table" value="<?php echo $bo_table; ?>">
	<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="frame" value="<?php echo $frame; ?>">
	<input type="hidden" name="bo_it" value="<?php echo $bo_it; ?>">
	<input type="hidden" name="sw"   value="">
	<?php
		if($is_tag_cloud) { //Tag Cloud
			include(AMINA_PATH.'/tag.cloud.php'); 
			$total_count = 0;
		} else { //List Skin
			$list_skin_path = AMINA_PATH.'/skin/list/'.$amina['list_skin'];
			$list_skin_url = AMINA_URL.'/skin/list/'.$amina['list_skin'];
			if(G4_IS_MOBILE && file_exists($list_skin_path.'/m.list.skin.php')) {
				include($list_skin_path.'/m.list.skin.php'); 
			} else {
				include($list_skin_path.'/list.skin.php'); 
			}
		}
	?>
	</form>
	<div id="amina_list_ui">
		<div class="right">
			<?php 
				if($write_href) { 
					if($sca) $write_href .= '&sca='.urlencode($sca);
					echo '<a href="'.$write_href.$frame_opt.$search_opt.'" class="abtn list_write" title="글쓰기"><b>글쓰기</b><em>Write</em></a>'."\n";
				} else {
					echo '<a href="javascript:alert(\'로그인을 하지 않았거나 권한이 없는 레벨입니다.\')" class="abtn list_write" title="글쓰기"><b>글쓰기</b><em>Write</em></a>'."\n";
				} 
			?>
		</div>
		<div align="left">
			<?php
				if($rss_href) echo '<a href="'.AMINA_URL.'/rss.php?bo_table='.$bo_table.'" target="_blank" class="abtn list_rss" title="RSS 2.0"><b>RSS</b><em>RSS</em></a>'."\n";
				if($is_sch_form) echo '<a href="javascript:amina_show(\'list_sch\');" class="abtn list_search" title="검색하기"><b>검색</b><em>Search</em></a>'."\n";
			?>
		</div>
		<div class="clear"></div>
	</div>
	<div class="clear"></div>
	<?php 
		if ($is_sch_form) { 
			$display_search = $stx ? 'block' : 'none';
	?>
	<div id="list_sch" style="display:<?php echo $display_search; ?>;">
		<?php if(file_exists($list_skin_path.'/search.form.php')) {
			@include_once ($list_skin_path.'/search.form.php');
		} else { ?>
			<div class="list-search-form">
			<form name="fsearch" method="get" onsubmit="return amina_search(this);" data-ajax="false">
			<input type="hidden" name="bo_table" value="<?php echo $bo_table; ?>">
		    <input type="hidden" name="sca"      value="<?php echo $sca; ?>">
			<fieldset>
			<legend>게시물 검색</legend>
			<label for="list_sch_sfl">검색종류</label>
			<select id="list_sch_sfl" name="sfl" required="required">
				<option value="wr_subject||wr_content">제목+내용</option>
				<option value="wr_subject">제목</option>
				<option value="wr_content">내용</option>
				<option value="mb_id,1">회원아이디</option>
				<option value="mb_id,0">회원아이디(댓글)</option>
				<option value="wr_name,1">글쓴이</option>
				<option value="wr_name,0">글쓴이(댓글)</option>
			</select>
		    <label for="list_sch_stx">검색어</label>
			<input type="text" id="list_sch_stx" name="stx" size=10 required="required" value="<?php echo stripslashes($stx);?>"/>
			<input type="image" src="<?php echo AMINA_URL; ?>/img/btn_search.png" alt="검색" data-role="none"/>
			</fieldset>
			</form>
			</div>
		<? } ?>
	</div>
	<div class="clear"></div>
	<?php } ?>

	<?php //Page Skin
		$page_skin_path = AMINA_PATH.'/skin/page/'.$amina['page_skin'];
		$page_skin_url = AMINA_URL.'/skin/page/'.$amina['page_skin'];
		$page_rows = $amina['page_rows'] ? $amina['page_rows'] : $config['cf_write_pages'];
		if(G4_IS_MOBILE && file_exists($page_skin_path.'/m.page.skin.php')) {
			include($page_skin_path.'/m.page.skin.php');
		} else {
			include($page_skin_path.'/page.skin.php');
		}
	?>
<?php } ?>

<?php if (!$frame && ($is_checkbox || $admin_href)) { ?>
	<div id="amina_admin_ui">
		<ul class="bar11c">
		<?php if ($is_checkbox) { ?>
			<li class="first"><a href="javascript:select_delete();">삭제</a></li>
			<li><a href="javascript:select_copy('copy');">복사</a></li>
			<li><a href="javascript:select_copy('move');">이동</a></li>
		<?php } ?>
		<?php if ($admin_href) { ?>
			<li<?php if(!$is_checkbox) echo ' class="first"'; ?>><a href="<?php echo $admin_href.$frame_opt; ?>">그누설정</a></li>
			<li><a href="<?php echo G4_ADMIN_URL; ?>/amina.admin.php?bo_table=<?php echo $bo_table; ?>">아미나설정</a></li>
			<li class="last"><a href="<?php echo AMINA_URL; ?>/blind.list.php">블라인드글</a></li>
		<?php } ?>
		</ul>
	</div>
<?php } ?>
<?php
	if($is_deco_list) {
		echo '</div></div>'."\n";
		echo '<div class="deco-list-tail-back"><div class="deco-list-tail-front"><div class="deco-list-tail"></div></div></div>'."\n";
	}
?>
</div>

<script type="text/javascript">
if ('<?php echo $stx; ?>') {
    document.fsearch.sfl.value = '<?php echo $sfl; ?>';

    //if ('<?=$sop?>' == 'and') 
    //    document.fsearch.sop[0].checked = true;

    //if ('<?=$sop?>' == 'or')
    //    document.fsearch.sop[1].checked = true;
} else {
    //document.fsearch.sop[0].checked = true;
}
</script>

<?php if ($is_checkbox) { ?>
<script>
function all_checked(sw) {
    var f = document.fboardlist;

    for (var i=0; i<f.length; i++) {
        if (f.elements[i].name == "chk_wr_id[]")
            f.elements[i].checked = sw;
    }
}
function check_confirm(str) {
    var f = document.fboardlist;
    var chk_count = 0;

    for (var i=0; i<f.length; i++) {
        if (f.elements[i].name == "chk_wr_id[]" && f.elements[i].checked)
            chk_count++;
    }

    if (!chk_count) {
        alert(str + "할 게시물을 하나 이상 선택하세요.");
        return false;
    }
    return true;
}
// 선택한 게시물 삭제
function select_delete() {
    var f = document.fboardlist;

    str = "삭제";
    if (!check_confirm(str))
        return;

    if (!confirm("선택한 게시물을 정말 "+str+" 하시겠습니까?\n\n한번 "+str+"한 자료는 복구할 수 없습니다"))
        return;

    f.action = "<?php echo AMINA_URL; ?>/delete_all.php";
    f.submit();
}
// 선택한 게시물 복사 및 이동
function select_copy(sw) {
    var f = document.fboardlist;

    if (sw == "copy")
        str = "복사";
    else
        str = "이동";
                       
    if (!check_confirm(str))
        return;

    var sub_win = window.open("", "move", "left=50, top=50, width=500, height=550, scrollbars=1");

    f.sw.value = sw;
    f.target = "move";
    f.action = "<?php echo AMINA_URL; ?>/move.php";
    f.submit();
}
</script>
<?php } ?>
<!-- 게시판 목록 끝 -->