<?php
	include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
	include $_SERVER['DOCUMENT_ROOT'].ADMIN_PATH.'common/auth_chk.php';

	if($cd_board == "01"){$mp="50";}else if($cd_board == "02"){$mp="51";}else if($cd_board == "03"){$mp="52";}else{$mp="53";};

	if($cd_board <> "02"){
		AlertRedirect("잘못된 요청입니다.","/index.php");
	}

	if (empty($PageNo)) {$PageNo=1;}else{$PageNo=$PageNo;}
	$PageSize=10; //목록개수설정
	$pagestartpoint=($PageNo-1)*$PageSize;
	$sql = "where cd_board='$cd_board' and ds_delind='N'";
	
	if($searchword != ""){
		if($searchtype=="" || $searchtype==null){
			$sql = $sql. "	and (nm_title like '$searchword%' or nm_content like '$searchword%' or cd_userid like '$searchword%')";
		}else{
			$sql = $sql. "	and $searchtype like '$searchword%'";
		}
	}

	$totalrows = @mysql_result(mysql_query("select count(*) from board_master $sql"),0,0);
?>
<? include("../inc/inc_top.php") ?>
<? include("../inc/inc_header.php") ?>

<section id="contents">
	<h2>커뮤니티</h2>
	<h3><em>▶</em> <?=fnGetBbsTitle($cd_board)?></h3>
	<div class="tbl_wrap">
		<table class="tbl_list">
			<colgroup>
				<col width="7%">
				<col width="*">
				<col width="13%">
				<col width="13%">
				<? if($cd_board=="02"){?>
				<col width="13%">
				<?}?>
			</colgroup>
			<thead>
				<tr>
					<th>번호</th>
					<th>제목</th>
					<th>작성자</th>
					<th>등록일</th>
				<? if($cd_board=="02"){?>
					<th>답변여부</th>
				<?}?>
				</tr>
			</thead>

			<!--form id="frmSearch" name="frmSearch" method="post" action="<?=ADMIN_PATH?>/board/bbs_list.php">
			<input type="hidden" name="cd_board" id="cd_board" value="<?=$cd_board?>"/>
			<table width="330" border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td width="70px;" style="font-weight:bold;">
					검색조건
				</td>
				<td width="80px;">
					<select name="searchtype" id="searchtype">
					<option value="">전체</option>
					<option value="nm_title" <? if($searchtype =="nm_name"){?>selected<?}?>>제목</option>
					<option value="nm_content" <? if($searchtype =="nm_content"){?>selected<?}?>>내용</option>
					</select>
				</td>
				<td width="*" style="padding-left:5px;"><input id="searchword" name="searchword" type="text" size="20"  class="input_txt" value="<?=$searchword?>"/></td>
				<td width="50px;"><input type="button" value="검색" class="btnAdmin" style="width:40px;"  id="btnSearch" onclick="fnSearch();"/></td>
			</tr>
			</table>
			</form-->

<?
		if($totalrows>0) {
			$r = mysql_query("SELECT * FROM board_master  $sql ORDER BY ds_top desc, no_famally ASC, no_order ASC  LIMIT $pagestartpoint,$PageSize");
			$i=1;
			while($col = mysql_fetch_array($r)) { 
				$date = strtotime ($col[dt_insert]);
				$view_date = strtotime ("-1 day",time());
				if($date >= $view_date) {
					$newicon = " <img src='".ADMIN_PATH."img/i_new.gif' style='margin-top:1px;' /> ";
				} else { 
					$newicon = "";
				}

				if($col[no_step]>0){
					$padding = $col[no_step] * 8;
					$step = "<span style=\"padding-left:".$padding."px\"/>";
				}

				$tmpNum =$totalrows-($PageSize*($PageNo-1)); 
				$no = ($tmpNum - $i)+1;

?>
			<tr onclick="location.href='./bbs_view.php?cd_board=<?=$cd_board?>&cd_seq=<?=$col[cd_seq]?>&PageNo=<?=$PageNo?>';" style="cursor: pointer; cursor: hand;">
				<td><?=$no?></td>
				<? if($cd_board=="99"){?>
				<td width="10%" align="center" class="list03"><img src="<?=UPLOAD_PATH?>board/board_<?=$cd_board?>/<?=$col[nm_file]?>" width="50"/></td>
				<?}?>
				<td class="subject"><?=text_cut($col[nm_title],50)?></td>
				<td><?=$col[nm_name]?></td>
				<td><?=$col[dt_insert]?></td>
				<? if($cd_board=="02"){?>
				<td><?=($col[nm_reply] == "") ? "미답변" : "답변완료" ?></td>
				<?}?>
			</tr>
<?
				$i++;
			}
		}else{
?>
			<tr>
				<td colspan="4">등록된 정보가 없습니다.</td>
			</tr>
<?
		}
?>
		</table>
	</div>

	<div class="paging">
		<?
				$url = ADMIN_PATH."board/bbs_list.php?cd_board=$cd_board&searchtype=$searchtype&searchword=$searchword";
				ListPg1($url ,$PageNo,$PageSize,10,$totalrows,$leftboard[1],$rootpath);
		?>
	</div>

<? 
	if($cd_board != "02"){
?>
	<div class="btn_right">
		<a href="./bbs_write.php?cd_board=<?=$cd_board?>" class="rnd_btn gray">등록하기</a>
	</div>
<? 
	}
?>

</section>

<script language="javascript" type="text/javascript">
	function fnSearch(){
		if($("#searchtype").val()!="" && $("#searchword").val()==""){
			alert("검색어를 입력하세요");
			return false;
		}
		$("#frmSearch").submit();
	}
</script>

<? include("../inc/inc_footer.php") ?>
<? include("../inc/inc_bottom.php") ?>
<?
mysql_close($connect);
?>
