<?
	require_once("admin__check.php");

	// 设置搜索条件和排序方式
	$a=$a==""?"id":trim($a);
	$b=$b=="asc"?"asc":"desc";
	$c=str_replace("\\","",str_replace("\"","'",$c));
	$condition=$c==""?"1":$c;
	$condition.=" and status>=0 ";

	// 获取当前页数并设定每页记录条数	
	$p=floor(trim($p));
	$p=$p<=0?1:$p;
	$q=floor(trim($q));
	$q=$q<=0?10:$q;

	// 获取总记录条数
	$sql="select count(id) from ".TBL_BULLETIN." where $condition ";
	$totals=mysql_fetch_array(mysql_query($sql));
	$total=$totals[0];

	// 获取当前页记录集
	$sql="select * from ".TBL_BULLETIN." where $condition order by $a $b limit ".(($p-1)*$q).",$q ";
	$result=mysql_query($sql);
	while($row=mysql_fetch_array($result)){
		$lists[]=$row;
	}
?>

<fieldset>公告管理 - 列表</fieldset>

<div id="toolbar">
	<button class="b1" onclick="operate(this,'<?=basename(__FILE__,".php");?>_do.php','add',0)">添加新的记录</button>
	&nbsp;&nbsp;
	<button class="b2" onclick="operate(this,'<?=basename(__FILE__,".php");?>_do.php','top',0)">置顶显示</button>
	&nbsp;
	<button class="b2" onclick="operate(this,'<?=basename(__FILE__,".php");?>_do.php','commend',0)">重点推荐</button>
	&nbsp;
	<button class="b2" onclick="operate(this,'<?=basename(__FILE__,".php");?>_do.php','status',0)">改变状态</button>
	&nbsp;&nbsp;	
	<button class="b1" onclick="operate(this,'<?=basename(__FILE__,".php");?>_do.php','del',0)">删除选中记录</button>
</div>

<table cellspacing='0' cellpadding='3' border='0'>
	<tr>
		<th width="7%"	title="<?=$title="id";?>"			class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">ID</th>
		<th width="45%"	title="<?=$title="title";?>"	class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">标题</th>
		<th width="12%"	title="<?=$title="dt";?>"			class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">时间</th>
		<th width="8%"	title="<?=$title="click";?>"	class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">点击</th>
		<th width="5%"	title="<?=$title="top";?>"		class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">置顶</th>
		<th width="5%"	title="<?=$title="commend";?>"class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">推荐</th>
		<th width="5%"	title="<?=$title="status";?>"	class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">状态</th>
		<th width="10%">操作</th>
		<th width="3%"><input type="checkbox" id="cb_0" onclick="select_all();" title="全部选中"></th>
	</tr>

	<?
		if(count($lists)>0){
			$i=0;
			foreach($lists as $l){
				$i++;
				$bgcolor=$bgcolor=="#FFFFFF"?"#F8F8F8":"#FFFFFF";
				$str.="<tr align='center' bgcolor='$bgcolor'>";			
				$str.="<td>".$l['id']."</td>";
				$str.="<td align=left><a href='javascript:;' onclick=window.open('bulletin_show.php?id=".$l["id"]."','bulletin','width=400,height=300,left='+(screen.width-400)/2+',top='+(screen.height-300)/2+',scrollbars=1') target='_blank' title='标题：".$l['title']."'>".csubstr($l['title'],0,25)."</a></td>";
				$str.="<td>".substr($l['dt'],0,10)."</td>";
				$str.="<td>".$l['click']."</td>";
				$str.="<td><img src='images/".$l['top'].".gif' border='0'></td>";
				$str.="<td><img src='images/".$l['commend'].".gif' border='0'></td>";
				$str.="<td><img src='images/".$l['status'].".gif' border='0'></td>";
				$str.="<td>";
				$str.="<a href='#' onclick=\"operate(this,'".basename(__FILE__,".php")."_do.php','modify','".$l["id"]."')\" ".($l["status"]<0?"disabled":"").">编辑</a>&nbsp;|&nbsp;";
				$str.="<a href='#' onclick=\"operate(this,'".basename(__FILE__,".php")."_do.php','delete','".$l["id"]."')\" ".($l["status"]<0?"disabled":"").">删除</a>&nbsp;";
				$str.="</td>";
				$str.="<td><input type='checkbox' id=cb_".$i." value=".$l["id"]." ".($l['status']<2?"":"disabled")."></td>";
				$str.="</tr>";			
			}
		}
		else{
			$str="<tr><td colspan='9' style='height:80px;padding-left:20px;color:#666666;'>提示：没有符合条件的任何信息。</td></tr>";
		}
		echo $str;
	?>
	<tr>
		<th colspan="9" align="center" style="display:<?=$role=="admin"?"block":"none";?>;">
			<input id="tatol" type="hidden" value="<?=$i;?>">
			<textarea id="keyword" style="width:600px;height:21px;overflow:hidden;" onkeydown="if(event.keyCode==13){document.all.search.click();}" title="格式：id>1 and email like '%@126.com'"><?=$c;?></textarea>&nbsp;<button id="search" onclick="sort('<?=$a;?>')">查询</button>
		</th>
	</tr>
	<tr>
		<td colspan="9" class="page"><?show_page($total);?></td>
	</tr>
</table>