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

//Naver Style
function search_paging($write_pages, $cur_page, $total_page, $url, $add="") {

		if(!$cur_page) $cur_page = 1;
		if(!$total_page) $total_page = 1;

		$str = '';

		if ($cur_page < 2) {
			//$str .= '<a class="direction" title="맨앞페이지"><span>‹‹</span><em>맨앞</em></a>';
		} else {
			$str .= '<a href="'.$url.'1'.$add.'" class="direction" title="맨앞페이지"><span>처음</span></a>';
		}

		$start_page = ( ( (int)( ($cur_page - 1 ) / $write_pages ) ) * $write_pages ) + 1;
        $end_page = $start_page + $write_pages - 1;

        if ($end_page >= $total_page) { 
			$end_page = $total_page;
		}

        if ($start_page > 1) { 
			$str .= '<a href="'.$url.($start_page-1).$add.'" class="direction" title="이전페이지"><span>이전</span></a>'; 
		} else {
			//$str .= '<a class="direction" title="이전페이지"><span>‹</span><em>이전</em></a>'; 
		}

        if ($total_page > 0){
                for ($k=$start_page;$k<=$end_page;$k++){
                        if ($cur_page != $k) {
		                    $str .= '<a href="'.$url.$k.$add.'">'.$k.'</a>';
                        } else {
	                        $str .= '<strong>'.$k.'</strong> ';
						}
                }
        }

        if ($total_page > $end_page) {
			$str .= '<a href="'.$url.($end_page+1).$add.'" class="direction" title="다음페이지"><span>다음</span></a>';
		} else {
			//$str .= '<a class="direction" title="다음페이지"><em>다음</em><span>›</span></a>';
		}

		if ($cur_page < $total_page) {
			$str .= '<a href="'.$url.($total_page).$add.'" class="direction" title="맨뒤페이지"><span>맨뒤</span></a>';
		} else {
			//$str .= '<a class="direction" title="맨뒤페이지"><em>맨뒤</em><span>››</span></a>';
		}

		return $str;
}

function search_get_selected($field, $value) {
    return ($field==$value) ? ' selected="selected"' : '';
}

?>

<!-- 전체검색 시작 { -->
<link rel="stylesheet" href="<?php echo $search_skin_url ?>/search.css">
<div id="at-search">
	<div id="at-search-form">	
		<form name="fsearch" onsubmit="return amina_search(this);" method="get">
		<input type="hidden" name="srows" value="<?php echo $srows ?>">
	    <?php echo $group_select ?>
	    <script>document.getElementById("gr_id").value = "<?php echo $gr_id ?>";</script>
		<select name="sfl" id="sfl">
			<option value="wr_subject||wr_content"<?php echo search_get_selected($_GET['sfl'], "wr_subject||wr_content") ?>>제목+내용</option>
	        <option value="wr_subject"<?php echo search_get_selected($_GET['sfl'], "wr_subject") ?>>제목</option>
		    <option value="wr_content"<?php echo search_get_selected($_GET['sfl'], "wr_content") ?>>내용</option>
			<option value="mb_id"<?php echo search_get_selected($_GET['sfl'], "mb_id") ?>>회원아이디</option>
	        <option value="wr_name"<?php echo search_get_selected($_GET['sfl'], "wr_name") ?>>이름</option>
		</select>
	    <select name="sop" id="sop">
		    <option value="and"<?php echo search_get_selected($_GET['sop'], "and") ?>>그리고</option>
			<option value="or"<?php echo search_get_selected($_GET['sfl'], "or") ?>>또는</option>
	    </select>
		<input type="text" name="stx" value="<?php echo $text_stx ?>" id="stx" required class="frm_input required" maxlength="20">
		<button type="submit"><i class="fa fa-search fa-lg"></i></button>
		</form>
	</div>

	<div id="at-search-result">

    <?php
    if ($stx) {
        if ($board_count) {
    ?>
		<div class="s-box s-black s-nobr">
			<i class="fa fa-check-circle"></i> <?php echo $stx ?> 검색결과
			- 
			게시판 (<?php echo $board_count ?>개),
			게시물 (<?php echo number_format($total_count) ?>개)
		</div>
    <?php
        }
    } else {
    ?>
		<div class="s-box s-black s-nobr">
			<i class="fa fa-check-circle"></i> 검색어는 두글자 이상 / 공백은 하나만 입력해 주세요.
		</div>
	<?php } ?>
    <?php
    if ($stx) {
        if ($board_count) {
     ?>
    <ul id="at-search-board">
        <li><a href="?<?php echo $search_query ?>&amp;gr_id=<?php echo $gr_id ?>" <?php echo $sch_all ?>>전체게시판</a></li>
        <?php echo $str_board_list; ?>
    </ul>
	<div class="clear"></div>
    <?php
        } else {
     ?>
    <p>검색된 자료가 하나도 없습니다.</p>
    <?php } }  ?>

    <?php
	$sm = G5_IS_MOBILE ? ' class="sm"' : '';
	$k=0;
    for ($idx=$table_index, $k=0; $idx<count($search_table) && $k<$rows; $idx++) {
        $comment_def = "";
        $comment_href = "";
     ?>
        <div class="s-box s-black s-nobr">
			<a href="./board.php?bo_table=<?php echo $search_table[$idx] ?>&<?php echo $search_query ?>">
				<i class="fa fa-chevron-circle-right"></i> <?php echo $bo_subject[$idx] ?> 게시판 내 결과
			</a>
		</div>
        <ul class="s-list">
        <?php
        for ($i=0; $i<count($list[$idx]) && $k<$rows; $i++, $k++) {
            if ($list[$idx][$i]['wr_is_comment']) {
                $comment_def = '<i class="fa fa-comments"></i> ';
                $comment_href = "#c_".$list[$idx][$i][wr_id];
			} 

			if($list[$idx][$i]['content']) $list[$idx][$i]['content'] = search_font($stx, amina_cut($list[$idx][$i]['wr_content'], 255));

			$list[$idx][$i]['name'] = $is_sideview ? amina_sideview($list[$idx][$i]['mb_id'], $list[$idx][$i]['wr_name'], $list[$idx][$i]['wr_email'], $list[$idx][$i]['wr_homepage']) : $list[$idx][$i]['name'];
		 ?>

            <li>
                <strong<?php echo $sm; ?>>
	                <span class="new-win">
						<a href="<?php echo $list[$idx][$i]['href'] ?><?php echo $comment_href ?>" target="_blank" title="새창으로 보기"><i class="fa fa-external-link-square"></i></a>
					</span>
					<a href="<?php echo $list[$idx][$i]['href'] ?><?php echo $comment_href ?>"><?php echo $comment_def ?><?php echo $list[$idx][$i]['subject'] ?></a>
				</strong>
				<div class="txt"><?php echo $list[$idx][$i]['content']; ?></div>
                <p>
					<i class="fa fa-user"></i> <?php echo $list[$idx][$i]['wr_name'] ?>
					&nbsp;&nbsp;
					<i class="fa fa-clock-o"></i> <?php echo $list[$idx][$i]['wr_datetime'] ?>
				</p>
            </li>
        <?php }  ?>
        </ul>
        <div class="search-more"><a href="./board.php?bo_table=<?php echo $search_table[$idx] ?>&<?php echo $search_query ?>"><i class="fa fa-chevron-circle-down"></i> <strong><?php echo $bo_subject[$idx] ?></strong> 결과 더보기</a></div>

    <?php }  ?>

	<?php if ($stx) { ?>
		<div class="paginate">
			<?php echo search_paging($page_rows, $page, $total_page, $search_paging_href); ?>
		</div>
	<?php } ?>

</div>

</div>
<!-- } 전체검색 끝 -->