<?
	require_once("user__check.php");

	// 更新采集记录中页面采集数和收录数
	$sql="select id , domain from ".TBL_PICK." where status>0 and uid=".$uid;
	$result=mysql_query($sql);
	while($row=mysql_fetch_array($result)){
		$sql1="select count(id) from ".TBL_PAGE." where status>0 and uri like '%".trim($row[1])."%' and uid=".$uid;
		$row1=mysql_fetch_array(mysql_query($sql1));
		$sql2="select count(id) from ".TBL_PAGE." where status>1 and uri like '%".trim($row[1])."%' and uid=".$uid;
		$row2=mysql_fetch_array(mysql_query($sql2));
		$sql="update ".TBL_PICK." set pages1=".floor($row1[0])." , pages2=".floor($row2[0])." where id=".floor($row[0]);
		mysql_query($sql);
	}	

	// 设置搜索条件和排序方式
	$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_PICK." where $condition";
	$totals=mysql_fetch_array(mysql_query($sql));
	$total=floor($totals[0]);

	// 获取记录集
	$sql="select * from ".TBL_PICK." 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="18%" 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="14%" title="<?=$title="pages1";?>"	class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">采集页数</th>
		<th width="14%" title="<?=$title="pages2";?>"	class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">收录页数</th>
		<th width="14%" title="<?=$title="dt";?>"			class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">最后更新</th>
		<th width="6%" title="<?=$title="status";?>"	class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">状态</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;
				$status1=$status2=($l["status"]<0)?"title='已删方案' disabled":"";
				$status2=($l["domain"]==$user["domain"])?"title='默认方案' disabled":$status2;				
				$str.="<tr align='center' bgcolor='$bgcolor'>";
				$str.="<td>".$l["id"]."</td>";
				$str.="<td title='域名：".$l["domain"]."'><a href='http://".$l["domain"]."' target='_blank'>".csubstr($l["name"],0,6)."</a></td>";
				$str.="<td>".$l["today"]."</td>";
				$str.="<td>".$l["total"]."</td>";
				$str.="<td><a href='#' onclick=\"operate(this,'".basename(__FILE__,".php")."_do_page.php','view1','".$l["id"]."')\">".$l["pages1"]."</a></td>";
				$str.="<td><a href='#' onclick=\"operate(this,'".basename(__FILE__,".php")."_do_page.php','view2','".$l["id"]."')\">".$l["pages2"]."</a></td>";
				$str.="<td title='".$l["dt"]."'>".substr($l["dt"],5,11)."</td>";
				$str.="<td><img src='images/status_".$l["status"].".gif' border='0' title='".$status[$l["status"]]."'></td>";
				$str.="<td><input type='checkbox' id=cb_".$i." value=".$l["id"]." ".$status2."></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>

<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','change1',0)">暂停采集和点入</button>
	&nbsp;
	<button class="b1" onclick="operate(this,'<?=basename(__FILE__,".php");?>_do.php','change2',0)">恢复到正常状态</button>
	&nbsp;
	<button class="b1" onclick="operate(this,'<?=basename(__FILE__,".php");?>_do.php','del',0)">删除选中的方案</button>
</div>