<?
	require_once("user__check.php");

	// 如果已经提交表单
	$job=trim($job);
	if($check=="ok"){
		// 隐藏
		if($job=="delete"){
			$ids=split(",",$ids);
			foreach($ids as $id){
				$sql="update ".TBL_PAGE." set status=0 where uid=".$uid." and id=".floor($id);
				mysql_query($sql);		
			}
		}
	}

	// 分类显示
	if(substr($job,0,4)=="view"){
		$id=floor(trim($id));
		$sql="select domain from ".TBL_PICK." where id=".$id." and uid=".$uid;
		$row=mysql_fetch_array(mysql_query($sql));
		$type=" and uri like '%".$row[0]."%' ";
	}

	// 设置搜索条件和排序方式
	$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>=".floor(str_replace("view","",$job));
	$condition.=" and uid=$uid ".$type;
	
	// 获取当前页数并设定每页记录条数	
	$p=floor(trim($p));
	$p=$p<=0?1:$p;
	$q=floor(trim($q));
	$q=$q<=0?10:$q;

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

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

<fieldset>数据采集 - 页面列表<?=($job==""?"（所有采集页面）":"");?></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="45%" title="<?=$title="title";?>"	class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">页面名称</th>
		<th width="12%" title="<?=$title="click";?>"	class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">点击次数</th>
		<th width="20%" title="<?=$title="dt";?>"			class="<?=$a==$title?$b:""?>" onclick="sort(this.title)">最后更新</th>
		<th width="13%" 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";
				$str.="<tr align='center' bgcolor='$bgcolor'>";
				$str.="<td>".$l["id"]."</td>";
				$str.="<td align='left'><a href='".$l["uri"]."' target='_blank'>".$l["title"]."</a></td>";
				$str.="<td>".$l["click"]."</td>";
				$str.="<td>".$l["dt"]."</td>";
				$str.="<td><img src='images/status_".$l["status"].".gif' border='0'>&nbsp;".$status[$l["status"]]."</td>";
				$str.="<td><input type='checkbox' id='cb_".$i."' value='".$l["id"]."' ".(strstr($l["uri"],"#")=="#eachgain"?"title='默认采集页面' disabled":"")."></td>";
				$str.="</tr>";
			}
		}
		else{
			$str="<tr><td colspan='6' style='height:80px;padding-left:20px;color:#666666;'>提示：没有符合条件的任何信息。</td></tr>";
		}
		echo $str;
	?>
	<tr>
		<th colspan="6" align="center" style="display:<?=$role=="admin"?"block":"none";?>;">
			<input id="tatol" type="hidden" value="<?=$i;?>">
			<input id="keyword" type="text" value="<?=$c;?>" style="width:600px;" onkeydown="if(event.keyCode==13){document.all.search.click();}" title="格式：id>1 and email like '%@126.com'">&nbsp;<button id="search" onclick="sort('<?=$a;?>')">查询</button>
		</th>
	</tr>
	<tr>
		<td colspan="6" class="page"><?show_page($total);?></td>
	</tr>
</table>

<div id="toolbar">
	<button class="b1" onclick="go('')">返回方案列表</button>
	&nbsp;
	<button class="b1" onclick="operate(this,'<?=basename(__FILE__);?>','del',0)">删除所选页面</button>	
</div>