<?php
function listTitle($id){
	global $db_tablepre;
	$sql = "SELECT BC_channel  FROM ".$db_tablepre."channel  WHERE BC_id=".$id;
	$str = sql_return($sql,2);
	return $str['BC_channel'];
}

function listContents($id,$num=10,$type_sql=false){
	global $db_tablepre;
	if ($type_sql == 1) $return_str = listContents_str($id,$num,$type_sql);
	else {
		$sql = "SELECT BC_id, BC_channel  FROM ".$db_tablepre."channel  WHERE BC_Tschannel=".$id;
		$r = sql_return($sql,3);
		if ($r) {
			$r = sql_return($sql);
			$return_str = '';
			while ($row = sql_return($r,'FetchRow')) {
				$return_str .= '<div id="listTitle"><h1><span><a href="content/index.php?id='.$row['BC_id'].'"><img src="images/right.gif" alt="goto" /></a></span> ◎ <a href="content/index.php?id='.$row['BC_id'].'">'.$row['BC_channel'].'</a></h1></div>';
				$return_str .= listContentStr($row['BC_id'],$num,$type_sql);
			}
		}
		else $return_str = listContents_str($id,$num,$type_sql=2);
	}
	return  $return_str;
}

function listContents_str($id,$num=10,$type_sql){
	global $db_tablepre;
	$return_str = '';
	$sql = "SELECT BC_id,BC_channel  FROM ".$db_tablepre."channel  WHERE BC_id=".$id;
	$r = sql_return($sql,2);
	$return_str .= '<div id="listTitle"><h1><span><a href="content/index.php?id='.$r['BC_id'].'"><img src="images/right.gif" alt="goto" /></a></span> ◎ <a href="content/index.php?id='.$r['BC_id'].'">'.$r['BC_channel'].'</a></h1></div>';
	$return_str .= listContentStr($id,$num,$type_sql);

	return  $return_str;
}

function listContentStr($id,$num,$type_sql){
	global $db_tablepre;
	$sql = "SELECT content_id,content_bc_id,content_channel,content_title,content_uptimes";

	switch ($type_sql){
		case 1:
			$sql .= ",u.BC_channel FROM ".$db_tablepre."content c LEFT JOIN ".$db_tablepre."channel  u ON c.content_channel=u.BC_id   WHERE content_bc_id=".$id;
			break;
		case 2:
			$num = $num*2;
			
			$sql = "SELECT  * FROM ".$db_tablepre."content  WHERE content_channel=".$id;
			$result  = sql_return($sql);
			$pageNum = sql_return($result,'count');
			$page = page_top($num,$pageNum);
			$num_2 = $num;
			$num = ($page*$num).",".$num;
			break;
		default:
			$sql .= " FROM ".$db_tablepre."content WHERE content_channel=".$id;
			break;
	}
	$sql .=" order by content_uptimes desc limit ".$num;
	$result = sql_return($sql);
	while ($row = sql_return($result,'FetchRow')) {
		$return_str .= '
		<div id="listContents_div">
		<ul>
<li id="listContents_div_1i_1">·';

		if ($type_sql == 1) $return_str .= '  [<a href="/content/index.php?id='.$row['content_channel'].'"  target="_blank">'.$row['BC_channel'].'</a>] ';

		$return_str .= '  <a href="/content/content.php?id='.$row['content_id'].'&channel='.$row['content_bc_id'].'"  target="_blank">'.$row['content_title'].'</a>
</li>
<li id="listContents_div_1i_2">'.date("Y-m-d H:i:s",$row['content_uptimes']).'
</li>
</ul>
</div>';
	}
	if ($type_sql == 2){
		$page_foot = page_foot($page,$num_2,$pageNum);
		$return_str .= '<div id="listPage">'.$page_foot.'</div>';
	}

	return  $return_str;
}




?>