<?
	require_once("user__check.php");

	// 获取或设置参数
	$job=trim($job);

	// 已提交表单 (添加|修改|删除|改变状态)
	if($check=="ok"){	

		if($job==""){
			$flag="error";
			show_msg("错误：未知操作！");
		}
		else{
			if($job=="add" or $job=="modify"){
				$name=trim($name);
				$domain=trim($domain);
				if(strlen($name)<1){
					$flag="error";
					show_msg("错误：没有输入方案名称！","-1");
				}
				if(strlen($domain)<1){
					$flag="error";
					show_msg("错误：没有输入网站域名！","-1");
				}
			}
			else{
				if($id<>""){
					$ids=array($id);
				}
				else{
					$ids=split(",",$ids);
				}
			}
		}

		if($flag<>"error"){

			switch($job){
				case "add":
					// 添加内容
					$sql="update ".TBL_PICK." set name='".$name."',deny='".str_replace("\r\n","|",$deny)."',dt='".date("Y-m-d H:i:s")."' where uid=".$uid." and domain='".$domain."' and status>0";
					mysql_query($sql);
					if(mysql_affected_rows()<=0){
						$sql="insert into ".TBL_PICK."(name,domain,deny,status,uid) values('".$name."','".$domain."','".str_replace("\r\n","|",$deny)."',2,".$uid.")";
						mysql_query($sql);
						$id=mysql_insert_id();
					}
					break;
				case "modify":
					// 修改内容
					$sql="update ".TBL_PICK." set name='".$name."',deny='".str_replace("\r\n","|",$deny)."',dt='".date("Y-m-d H:i:s")."' where uid=".$uid." and id=".floor($id);
					mysql_query($sql);
					break;
				case "delete":
					// 删除内容
					/*
					foreach($ids as $id){
						$sql="update ".TBL_PICK." set status=-1 where uid=".$uid." and id=".floor($id);
						mysql_query($sql);
						$sql="select domain from ".TBL_PICK." where id=".floor($id);
						$row=mysql_fetch_array(mysql_query($sql));
						$sql="update ".TBL_PAGE." set status=-1 where uid=".$uid." and uri like 'http://".$row[0]."%'";
						mysql_query($sql);		
					}				
					break;
					*/
				case "change1":
				case "change2":
					// 改变状态
					$status=$job=="delete"?"-1":str_replace("change","",$job);
					foreach($ids as $id){
						$sql="update ".TBL_PICK." set status=$status where uid=".$uid." and id=".floor($id);
						mysql_query($sql);
						if($job=="change2" and floor($cfg["审核设置"]["页面采集审核"])<>1){
							continue;
						}
						$sql="select domain from ".TBL_PICK." where id=".floor($id);
						$row=mysql_fetch_array(mysql_query($sql));
						$sql="update ".TBL_PAGE." set status=$status where uid=".$uid." and status>=0 and uri like 'http://".$row[0]."%'";
						mysql_query($sql);
					}
					break;		
			}

			if(mysql_error()<>""){
				show_msg("数据库操作出错，请联系客服！");			
			}
			else{
				// 数据添加成功则变成修改数据
				$job=$job=="add"?"modify":$job;
				if($job=="modify"){
					show_msg("数据更新成功！","-2");
				}
				else{
					show_msg("数据更新成功！","-1");
				}
			}

		}

	}

	// 未提交表单
	$content=array();
	if($job=="modify"){
		$content=mysql_fetch_array(mysql_query("select * from ".TBL_PICK." where uid=".$uid." and id=".floor($id)));
	}
?>

<fieldset>数据采集 - 方案配置</fieldset>

<form method="post" onsubmit="return validate(this);">
<table cellspacing='0' cellpadding='3' border='0'>
	<tr>
		<td width="150" align="right">方案名称：</td>
		<td><input type="text" name="name" value="<?=$content["name"]?>"></td>
	</tr>
	<tr>
		<td align="right">需采集的网站域名：</td>
		<td><input type="text" name="domain" value="<?=$content["domain"]?>" <?=$job=="modify"?"readonly title='不可修改'":"title='格式：www.xxxx.com'";?>><span class="help" onclick="show_help(1101)"></span>	</td>
	</tr>
	<tr>
		<td align="right">从该域名采集的内容&nbsp;&nbsp;<br><br>拒绝在这些域名中显示：<br><br>（每个域名换一行）</td>
		<td>
			<textarea name="deny" style="width:240px;height:100px;overflow:auto;"><?=str_replace("|","\r\n",$content["deny"]);?></textarea>
			<span class="help" onclick="show_help(1102)"></span>			
		</td>
	</tr>
	<tr align="left">
		<td>
			<input type="hidden" name="check" value="ok">
		</td>
		<td>
			<button type="submit">保存</button>
			&nbsp;
			<button type="button" onclick="location.reload()">还原</button>
		</td>
	</tr>
</table>
</form>

<div id="toolbar">
	<button class="b1" onclick="go('')">返回方案列表</button>
</div>

<script language="javascript">
function validate(obj)
{
	flag=true;
	if(obj.name.value.length<1)
	{
		flag=false;
		show_tip("请输入方案名称");
	}	
	if(obj.domain.value.length<1)
	{
		flag=false;
		show_tip("请输入网站域名");
	}
	return flag;
}
</script>