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

// 최신글 추출 - 선택한 그룹별로 원하는 수만큼 보여줌 
function latest_group($skin_dir="", $gr_id, $bo_table, $rows=10, $subject_len=40, $category="", $orderby="", $options="") 
{ 
	global $config; 
	global $g4; 


	/*        그릅명을 출력함    */

	// bo_table 값이 넘어올 경우 gr_id 를 축출한다.
	if($bo_table){ 
	$gr_id        = "";
	$board_sql    = " select bo_subject from {$g4[board_table]} where bo_table = '$bo_table'"; 
	$board_result = sql_fetch($board_sql);
	$gr_id       .= $board_result[gr_id];
	}

	//bo_table || gr_id  가 넘어오지 않은경우

	if(!$bo_table && !$gr_id){

	$gr_id       = "notice";   // 메인에서 노출시킬경우 조정하세요.
	}



	// 그릅변수가 넘어왔을경우
	if($gr_id){  
	$group_name = "";
	$group_sql    = " select gr_subject from {$g4[group_table]} where gr_id = '$gr_id'"; 
	$group_result = sql_fetch($group_sql); 
	$group_name  .= $group_result[gr_subject];
	}


	$list = array(); 
	$limitrows = $rows; 

	$sqlgroup = " select bo_table, bo_subject from $g4[board_table] where gr_id = '$gr_id' and  bo_use_search=1 order by bo_order_search"; 
	$rsgroup = sql_query($sqlgroup); 


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

	for ($j=0, $k=0; $rowgroup=sql_fetch_array($rsgroup); $j++) { 
	$bo_table = $rowgroup[bo_table]; 





	// 테이블 이름구함 
	$sql = " select * from {$g4[board_table]} where bo_table = '$bo_table'"; 
	$board = sql_fetch($sql); 

	$tmp_write_table = $g4[write_prefix] . $bo_table; // 게시판 테이블 실제이름 

	// 옵션에 따라 정렬 
	$sql = "select * from $tmp_write_table where wr_is_comment = 0 "; 
	$sql .= (!$category) ? "" : " and ca_name = '$category' "; 
	$sql .= (!$orderby) ? "  order by wr_id desc " : "  order by $orderby desc, wr_id desc "; 
	$sql .= " limit $limitrows"; 

	$result = sql_query($sql); 

	for ($i=0; $row = sql_fetch_array($result); $i++, $k++) { 

	if(!$orderby) $op_list[$k] = $row[wr_datetime]; 
	else  { 
	$op_list[$k] = is_string($row[$orderby]) ? sprintf("%-256s", $row[$orderby]) : sprintf("%016d", $row[$orderby]); 
	$op_list[$k] .= $row[wr_datetime]; 
	} 

	$list[$k] = get_list($row, $board, $latest_skin_path, $subject_len); 

	$list[$k][bo_table] = $board[bo_table]; 
	$list[$k][bo_subject] = $board[bo_subject]; 

	$list[$k][bo_wr_subject] = cut_str($board[bo_subject] . $list[$k][wr_subject], $subject_len); 

	} 
	}
	
	if($k>0) array_multisort($op_list, SORT_DESC, $list); 
	if($k>$rows) array_splice($list, $rows); 

	ob_start(); 
	include "$latest_skin_path/latest.skin.php"; 
	$content = ob_get_contents(); 
	ob_end_clean(); 
	return $content; 
} 
/// 함수 정의 끝 

// 최신글 추출 - 선택한 그룹별로 원하는 수만큼 보여줌 
function latest_group2($skin_dir="", $gr_id, $bo_table, $rows=10, $subject_len=40, $category="", $orderby="", $options="") 
{ 
	global $config; 
	global $g4; 


	/*        그릅명을 출력함    */

	// bo_table 값이 넘어올 경우 gr_id 를 축출한다.
	if($bo_table){ 
	$gr_id        = "";
	$board_sql    = " select bo_subject from {$g4[board_table]} where bo_table = '$bo_table'"; 
	$board_result = sql_fetch($board_sql);
	$gr_id       .= $board_result[gr_id];
	}

	//bo_table || gr_id  가 넘어오지 않은경우

	if(!$bo_table && !$gr_id){

	$gr_id       = "notice";   // 메인에서 노출시킬경우 조정하세요.
	}



	// 그릅변수가 넘어왔을경우
	if($gr_id){  
	$group_name = "";
	$group_sql    = " select gr_subject from {$g4[group_table]} where gr_id = '$gr_id'"; 
	$group_result = sql_fetch($group_sql); 
	$group_name  .= $group_result[gr_subject];
	}


	$list = array(); 
	$limitrows = $rows; 

	$sqlgroup = " select bo_table, bo_subject from $g4[board_table] where gr_id = '$gr_id' and  bo_use_search=1 order by bo_order_search"; 
	$rsgroup = sql_query($sqlgroup); 


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

	for ($j=0, $k=0; $rowgroup=sql_fetch_array($rsgroup); $j++) { 
	$bo_table = $rowgroup[bo_table]; 





	// 테이블 이름구함 
	$sql = " select * from {$g4[board_table]} where bo_table = '$bo_table'"; 
	$board = sql_fetch($sql); 

	$tmp_write_table = $g4[write_prefix] . $bo_table; // 게시판 테이블 실제이름 

	// 옵션에 따라 정렬 
	$sql = "select * from $tmp_write_table where wr_is_comment = 0 "; 
	$sql .= (!$category) ? "" : " and ca_name = '$category' "; 
	$sql .= (!$orderby) ? "  order by wr_id desc " : "  order by $orderby desc, wr_id desc "; 
	$sql .= " limit 1, $limitrows"; 

	$result = sql_query($sql); 

	for ($i=0; $row = sql_fetch_array($result); $i++, $k++) { 

	if(!$orderby) $op_list[$k] = $row[wr_datetime]; 
	else  { 
	$op_list[$k] = is_string($row[$orderby]) ? sprintf("%-256s", $row[$orderby]) : sprintf("%016d", $row[$orderby]); 
	$op_list[$k] .= $row[wr_datetime]; 
	} 

	$list[$k] = get_list($row, $board, $latest_skin_path, $subject_len); 

	$list[$k][bo_table] = $board[bo_table]; 
	$list[$k][bo_subject] = $board[bo_subject]; 

	$list[$k][bo_wr_subject] = cut_str($board[bo_subject] . $list[$k][wr_subject], $subject_len); 

	} 
	}
	
	if($k>0) array_multisort($op_list, SORT_DESC, $list); 
	if($k>$rows) array_splice($list, $rows); 

	ob_start(); 
	include "$latest_skin_path/latest.skin.php"; 
	$content = ob_get_contents(); 
	ob_end_clean(); 
	return $content; 
}

// 최신글 추출 - 선택한 그룹별로 원하는 수만큼 보여줌 
function latest_group3($skin_dir="", $gr_id, $bo_table, $rows=10, $subject_len=40, $category="", $orderby="", $options="") 
{ 
	global $config; 
	global $g4; 


	/*        그릅명을 출력함    */

	// bo_table 값이 넘어올 경우 gr_id 를 축출한다.
	if($bo_table){ 
	$gr_id        = "";
	$board_sql    = " select bo_subject from {$g4[board_table]} where bo_table = '$bo_table'"; 
	$board_result = sql_fetch($board_sql);
	$gr_id       .= $board_result[gr_id];
	}

	//bo_table || gr_id  가 넘어오지 않은경우

	if(!$bo_table && !$gr_id){

	$gr_id       = "notice";   // 메인에서 노출시킬경우 조정하세요.
	}



	// 그릅변수가 넘어왔을경우
	if($gr_id){  
	$group_name = "";
	$group_sql    = " select gr_subject from {$g4[group_table]} where gr_id = '$gr_id'"; 
	$group_result = sql_fetch($group_sql); 
	$group_name  .= $group_result[gr_subject];
	}


	$list = array(); 
	$limitrows = $rows; 

	$sqlgroup = " select bo_table, bo_subject from $g4[board_table] where gr_id = '$gr_id' and  bo_use_search=1 order by bo_order_search"; 
	$rsgroup = sql_query($sqlgroup); 


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

	for ($j=0, $k=0; $rowgroup=sql_fetch_array($rsgroup); $j++) { 
	$bo_table = $rowgroup[bo_table]; 





	// 테이블 이름구함 
	$sql = " select * from {$g4[board_table]} where bo_table = '$bo_table'"; 
	$board = sql_fetch($sql); 

	$tmp_write_table = $g4[write_prefix] . $bo_table; // 게시판 테이블 실제이름 

	// 옵션에 따라 정렬 
	$sql = "select * from $tmp_write_table where wr_is_comment = 0 "; 
	$sql .= (!$category) ? "" : " and ca_name = '$category' "; 
	$sql .= (!$orderby) ? "  order by wr_id desc " : "  order by $orderby desc, wr_id desc "; 
	$sql .= " limit 2, $limitrows"; 

	$result = sql_query($sql); 

	for ($i=0; $row = sql_fetch_array($result); $i++, $k++) { 

	if(!$orderby) $op_list[$k] = $row[wr_datetime]; 
	else  { 
	$op_list[$k] = is_string($row[$orderby]) ? sprintf("%-256s", $row[$orderby]) : sprintf("%016d", $row[$orderby]); 
	$op_list[$k] .= $row[wr_datetime]; 
	} 

	$list[$k] = get_list($row, $board, $latest_skin_path, $subject_len); 

	$list[$k][bo_table] = $board[bo_table]; 
	$list[$k][bo_subject] = $board[bo_subject]; 

	$list[$k][bo_wr_subject] = cut_str($board[bo_subject] . $list[$k][wr_subject], $subject_len); 

	} 
	}
	
	if($k>0) array_multisort($op_list, SORT_DESC, $list); 
	if($k>$rows) array_splice($list, $rows); 

	ob_start(); 
	include "$latest_skin_path/latest.skin.php"; 
	$content = ob_get_contents(); 
	ob_end_clean(); 
	return $content; 
}
?>