<?
	require_once("user__check.php");
	
	// 设置搜索条件和排序方式
	$a=$a==""?"id":trim($a);
	$b=$b=="asc"?"asc":"desc";
	$c=str_replace("\\","",str_replace("\"","'",$c));
	$condition=($c=="" or $role<>"admin")?"1":$c;
	$condition.=$role=="admin"?"":" and status>=0";
	$condition.=" and uid=$uid ";
	
	// 获取当前页数并设定每页记录条数	
	$p=floor(trim($p));
	$p=$p<=0?1:$p;
	$q=floor(trim($q));
	$q=$q<=0?10:$q;

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

	// 获取记录集
	$sql="select * from ".TBL_POST." 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>

<table cellspacing='0' cellpadding='2' border='0'>
	<tr>
		<th width="7%" title="<?=$title="id";?>"			class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">ID</th>
		<th width="14%" title="<?=$title="name";?>"		class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">方案名称</th>
		<th width="12%" title="<?=$title="today";?>"	class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">本日点出</th>
		<th width="12%" title="<?=$title="total";?>"	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="16%" title="<?=$title="status";?>" class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">代码投放状态</th>
		<th width="24%">相关操作</th>
		<th width="3%"><input type="checkbox" id="cb_0" onclick="select_all();" title="全部选中"></th>
	</tr>
	<?
		if(count($lists)>0){
			$status=array(
				-1=>"删除",
				0=>"待审",
				1=>"暂停投放",
				2=>"正常投放",
			);
			foreach($lists as $l){
				$i++;
				$bgcolor=$bgcolor=="#FFFFFF"?"#F8F8F8":"#FFFFFF";
				$bgcolor=$l["status"]<0?"#EEEEFF":$bgcolor;
				$str.="<tr align='center' bgcolor='$bgcolor'>";
				$str.="<td>".$l["id"]."</td>";
				$str.="<td title='".$l["name"]."'>".csubstr($l["name"],0,7)."</td>";
				$str.="<td>".$l["today"]."</td>";
				$str.="<td>".$l["total"]."</td>";
				$str.="<td title='".$l["dt"]."'>".substr($l["dt"],5,11)."</td>";
				$str.="<td>";
				$str.="<img src='images/status_".$l["status"].".gif' border='0' title='".$status[$l["status"]]."'>&nbsp;<font style='font-family:fixedsys;'>-=></font>&nbsp;";
				$str.="<a href='#' onclick=\"document.all.cb_".$i.".click();operate(this,'".basename(__FILE__,".php")."_do.php','status','".$l["id"]."')\" ".($l["status"]<1?"disabled":"")."><img src='images/".($l["status"]==2?"pause":"play").".gif' title='".($l["status"]==2?"暂停":"投放")."' border='0'></a>";
				$str.="</td>";
				$str.="<td>";
				$str.="<a href='#' onclick=\"operate(this,'".basename(__FILE__,".php")."_do_code.php','view','".$l["id"]."')\" ".($l["status"]<2?"disabled":"").">获取投放代码</a>&nbsp;||&nbsp;";
				$str.="<a href='#' onclick=\"operate(this,'".basename(__FILE__,".php")."_do.php','modify','".$l["id"]."')\" ".($l["status"]<0?"title='已被删除'":"").">编辑</a>&nbsp;|&nbsp;";
				$str.="<a href='#' onclick=\"operate(this,'".basename(__FILE__,".php")."_do.php','delete','".$l["id"]."')\" ".($l["status"]<0?"title='已被删除'":"").">删除</a>";
				$str.="</td>";				
				$str.="<td><input type='checkbox' id='cb_".$i."' value='".$l["id"]."'></td>";
				$str.="</tr>";
			}
		}
		else{
			$str="<tr><td colspan='8' style='height:80px;padding-left:20px;color:#666666;'>提示：没有符合条件的任何信息。</td></tr>";
		}
		echo $str;
	?>
	<tr>
		<th colspan="8" 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="8" class="page"><?show_page($total);?></td>
	</tr>
</table>

<div id="toolbar">
	<button class="b1" onclick="operate(this,'<?=basename(__FILE__,".php");?>_do.php','add',0)">添加新的方案</button>
	&nbsp;
	<button class="b1" onclick="operate(this,'<?=basename(__FILE__,".php");?>_do.php','del',0)">删除选中方案</button>
</div>