<?
if (!defined('_GNUBOARD_')) exit;

// 최신글 추출
function latest_num($skin_dir="", $bo_table, $rows=10, $subject_len="", $brch="", $la_num="", $options="", $f_rows="")
{
    global $g4;

    if ($skin_dir)
        $latest_skin_path = "$g4[path]/skin/latest/$skin_dir";
    else
        $latest_skin_path = "$g4[path]/skin/latest/basic";

    $list = array();

    $sql = " select * from $g4[board_table] where bo_table = '$bo_table'";
    $board = sql_fetch($sql);

    $tmp_write_table = $g4['write_prefix'] . $bo_table; // 게시판 테이블 전체이름

    if ($brch == "H") {

        $brch = "wr_hit desc";

    }

    else if ($brch == "C") {

        $brch ="wr_comment desc";

    }

    else if ($brch == "R") {

        $brch = "rand()";

    }

    else if ($brch == "G") {

        $brch = "wr_good desc";

    }

    else if ($brch == "N") {

        $brch = "wr_nogood desc";

    }

    else if ($brch == "RE") {

        $brch = "wr_num asc, wr_reply";

    }

    else if ($brch == "B") {

        $brch = "wr_num";

    } else {

        $brch = "wr_num";

    }

    // 최근 값 뽑음
    $sql0 = " select wr_num from $tmp_write_table where wr_is_comment = '0' order by wr_id desc limit 0, 1 ";
    $check = sql_fetch($sql0);

    // 값
    $sql_num = $check[wr_num] + $la_num;
	if(!$la_num){
	$sql = " select wr_id, wr_subject, wr_content, wr_name, wr_hit, wr_link1, ca_name, wr_1, wr_2, wr_3, wr_4, wr_5, wr_6, wr_7, wr_8, wr_9, wr_10, wr_datetime from $tmp_write_table where wr_is_comment = '0' order by $brch limit $f_rows, $rows ";
	}else{
    $sql = " select wr_id, wr_subject, wr_content, wr_name, wr_hit, wr_link1, ca_name, wr_1, wr_2, wr_3, wr_4, wr_5, wr_6, wr_7, wr_8, wr_9, wr_10, wr_datetime from $tmp_write_table where wr_is_comment = '0' and wr_num <= '$sql_num' order by $brch limit $f_rows, $rows ";
	}
    $result = sql_query($sql);
    for ($i=0; $row = sql_fetch_array($result); $i++) 
        $list[$i] = get_list($row, $board, $latest_skin_path, $subject_len);
		if($list[$i]['is_notice'] ) $notice++;
    
    ob_start();
    include "$latest_skin_path/latest.skin.php";
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
} 
?>