{:tpl head}
<table cellpadding="0" cellspacing="1" class="table_list">
 <caption>采集管理</caption>
  <tr>
    <td><strong>管理选项：</strong><a href="?c=spider&a=add">添加任务</a>&nbsp;|&nbsp;<a href="?c=spider">管理任务</a>&nbsp;|&nbsp;<a href="?c=spider&a=content">管理内容</a>&nbsp;|&nbsp;<a href="?c=spider&a=import">导入规则</a>
	</td>
  </tr>
</table>
<!--{:if $a == 'add' || $a == 'edit'}-->
<script language=javascript>
<!--
function doCheck(obj){
   var val;
   if(obj.name.value==''){
      alert("请填写任务名称");
      obj.name.focus();
      return false;
   }
   val=obj.catid.value;
   if(val=='0'){
      alert('请选择分类！');
      obj.catid.focus();
      return false;
   }
   val=val.slice(-1);
   if(val=='*'){
      alert('指定的分类不允许发布内容，请选择子分类！');
      obj.catid.focus();
      return false;
   }
   return true;
}
function set_basetype(t){
	if(t==2) $('#span_baseurl').show();
	else $('#span_baseurl').hide();
}
function addSimilar(){
	var obj =document.myform;
	var SimilarUrl = obj.SimilarUrl.value;
	var StarNumStart = obj.StarNumStart.value;
	var StarNumEnd = obj.StarNumEnd.value;
	var StarNumTime = obj.StarNumTime.value;
	var ckBackSort = obj.ckBackSort.checked;
	var AutoZero = obj.AutoZero.checked;
	var StartUrl = obj.starturl.value;
	if(SimilarUrl==''||SimilarUrl=='http://'){
		alert('请填写多页URL形式！变化的页码部分用通配符(*)代替');
		return false;
	}
	if(SimilarUrl.indexOf('(*)')==-1){
		if(confirm('多页URL中不包含通配符(*)，将被认为单条网址生成！您确认吗？')){
			obj.starturl.value=(StartUrl=='')?SimilarUrl:(StartUrl+"\n"+SimilarUrl);
			return false;
		}
	}else{
		if(StarNumStart==''||StarNumEnd==''){
			return alert('请填写通配符范围起始地址！');
		}
		if(StarNumTime==''){
			return alert('请填写通配符步长倍数！');
		}
		var curr='';
		var tmplist='';
		var AutoZeroStr='0000000000';
		var totallen=StarNumEnd.length;
		StarNumStart = parseInt(StarNumStart);
		StarNumEnd = parseInt(StarNumEnd);
		StarNumTime = parseInt(StarNumTime);
		if(isNaN(StarNumStart)||isNaN(StarNumStart)||isNaN(StarNumTime)){
			return alert('通配符范围及步长倍数都必须为数字！');
		}
		if(ckBackSort){
			for(i=StarNumEnd;i>=StarNumStart;i-=StarNumTime){
				if(AutoZero){
					curr=AutoZeroStr+String(i);
					startpos = AutoZeroStr.length+String(i).length-totallen;
					curr=curr.substr(startpos,totallen);
				}else{
					curr=String(i);
				}
				tmplist+=(tmplist=='')?SimilarUrl.replace('(*)',curr):("\n"+SimilarUrl.replace('(*)',curr));
			}
		}else{
			for(i=StarNumStart;i<=StarNumEnd;i+=StarNumTime){
				if(AutoZero){
					curr=AutoZeroStr+String(i);
					startpos = AutoZeroStr.length+String(i).length-totallen;
					curr=curr.substr(startpos,totallen);
				}else{
					curr=String(i);
				}
				tmplist+=(tmplist=='')?SimilarUrl.replace('(*)',curr):("\n"+SimilarUrl.replace('(*)',curr));
			}
		}
		obj.starturl.value=(StartUrl=='')?tmplist:(StartUrl+"\n"+tmplist);
		if(StarNumStart>StarNumEnd){
			return alert('通配符范围开始数大于结束数');
		}
	}
 
	//AutoZero
}
-->
</script>
<table cellpadding="0" cellspacing="1" class="table_form">
 <caption>{:if $a == 'add'}添加{:else}修改{:/if}任务</caption>
  <form name="myform" action="?c={:$c}&a={:$a}" method="post" onsubmit="return doCheck(this);">
  <input name="info[rid]" type="hidden" value="{:$data['rid']}">
  <input name="forward" type="hidden" value="{:$referer}">
  <tr>
    <td width="14%" align="right">任务名称：</td>
    <td><input name="info[name]" type="text" size="30" value="{:$data['name']}">&nbsp;<span class="fred">*</span></td>
  </tr>
  <tr>
    <td align="right">发布栏目：</td>
    <td>
	<select name="info[catid]" id="catid">
      <option value="0">请选择…</option>
      {:Tag::tree("<option value='\$catid'\$selected>\$tab\$name</option>",$data['catid'],$category,0,0,1)}
    </select>&nbsp;<span class="fred">*</span>
   </td>
  </tr>
  <tr>
    <td align="right">简单描述：</td>
    <td><input name="info[description]" type="text" size="60" value="{:$data['description']}"></td>
  </tr>
  <tr>
    <td align="right">基准网址：</td>
    <td>
	 <input type="radio" name="info[basetype]" value="0" onclick="set_basetype(0)"{:Tag::checked($data['basetype'], 0)} />对应的域名&nbsp;&nbsp;
	 <input type="radio" name="info[basetype]" value="1" onclick="set_basetype(1)"{:Tag::checked($data['basetype'], 1)} />对应的域名及目录&nbsp;&nbsp;
	 <input type="radio" name="info[basetype]" value="2" onclick="set_basetype(2)"{:Tag::checked($data['basetype'], 2)} />自定义
	 <span id="span_baseurl"{:if $data['basetype'] != 2} style="display:none"{:/if}><input name="info[baseurl]" type="text" size="30" value="{:$data['baseurl']}"></span>
	 &nbsp;<span class="fblue">目标网站相对地址对应的基准网址</span>
	</td>
  </tr>
  <tr>
   <td align="right">批量添加：</td>
   <td>
    <table width="98%"  border="0">
     <tr>
      <td colspan="3">
	   多页URL形式：<input name='SimilarUrl' type='text' id='SimilarUrl' value="http://" size='60'>
       &nbsp;通配符: <a href="javascript:AddOnPos(document.myform.SimilarUrl,'(*)');"  class="fred">(*)</a><br>
	   通配符范围：从<input name='StarNumStart' type='text' id='StarNumStart' size='4'>
	   到<input name='StarNumEnd' type='text' id='StarNumEnd' size='4'>&nbsp;&nbsp;&nbsp;&nbsp;
	   步长倍数:<input name='StarNumTime' type='text' id='StarNumTime' value="1" size='4'>&nbsp;&nbsp;&nbsp;
	   <input type="checkbox" name="ckBackSort">倒序生成&nbsp;&nbsp;&nbsp;&nbsp;补零:
	   <input type="checkbox" name='AutoZero' id='AutoZero' value="1">&nbsp;
	   <input type="button" name="add" value="添加" onclick="addSimilar()">
      </td>
     </tr>
    </table>
   </td>
  </tr>
  <tr>
    <td align="right">开始采集地址：<br /><span class="fblue">一行一个</span>&nbsp;&nbsp;&nbsp;</td>
    <td>
     <textarea name="info[starturl]" style="width:584px;height:86px">{:$data['starturl']}</textarea>
    </td>
  </tr>
  <tr>
    <td align="right">列表网址区域：</td>
    <td>
	 从&nbsp;<textarea name="info[listbegin]" style="width:265px;height:40px">{:htmlspecialchars($data['listbegin'])}</textarea>
	 <a href="javascript:void(0);" onclick="AddOnPos(document.myform.listbegin,'(*)');" title="插入通配符" class="fred">(*)</a>
	 到&nbsp;<textarea name="info[listend]" style="width:265px;height:40px">{:htmlspecialchars($data['listend'])}</textarea>
	 <a href="javascript:void(0);" onclick="AddOnPos(document.myform.listend,'(*)');" title="插入通配符" class="fred">(*)</a>
    </td>
  </tr>
  <tr>
    <td align="right">内容网址筛选：</td>
    <td>
	 网址中<span class="fred">必须</span>包含&nbsp;<input name="info[urlin]" type="text" size="28" value="{:$data['urlin']}">
	 网址中<span class="fred">不得</span>包含&nbsp;<input name="info[urlout]" type="text" size="28" value="{:$data[urlout]}">
	</td>
  </tr>
  <tr>
    <td align="right">每批操作数量：</td>
    <td>采集&nbsp;<input name="info[getnum]" type="text" size="8" value="{:$data['getnum']}"> 篇&nbsp;&nbsp;发布&nbsp;<input name="info[postnum]" type="text" size="8" value="{:$data['postnum']}"> 篇&nbsp;&nbsp;<span class="fblue">设置合适的数值，可以提高效率及避免超时！</span></td>
  </tr>
  <tr>
    <td align="right">远程上传类型：</td>
    <td><input name="info[remotetype]" type="text" size="32" value="{:$data['remotetype']}">&nbsp;<span class="fblue">相关远程文件在发布时自动上传到本地服务器，不想上传，请留空</span></td>
  </tr>
  <tr>
    <td align="right">随机浏览数范围：</td>
    <td>从&nbsp;<input name="info[hitsmin]" type="text" size="8" value="{:$data['hitsmin']}">&nbsp;到&nbsp;<input name="info[hitsmax]" type="text" size="8" value="{:$data['hitsmax']}">&nbsp;<span class="fblue">发布的时候设置一个浏览数</span></td>
  </tr>
  <tr>
    <td align="right">可选参数设置：</td>
    <td>
	 <input type="checkbox" name="info[passed]" value="1"{:Tag::checked($data['passed'], 1)} />免审&nbsp;
	 <input type="checkbox" name="info[isdesc]" value="1"{:Tag::checked($data['isdesc'], 1)} />倒序发布&nbsp;
	 <input type="checkbox" name="info[unrepeat]" value="1"{:Tag::checked($data['unrepeat'], 1)} />防重复&nbsp;
	 <input type="checkbox" name="info[pic1_default]" value="1"{:Tag::checked($data['pic1_default'], 1)} />内容中提取第1张图片为标题图片&nbsp;
	 <input type="checkbox" name="info[sim_browser]" value="1"{:Tag::checked($data['sim_browser'], 1)} />模拟浏览器(<span class="fred">采集失败时，试用本选项</span>)
	</td>
  </tr>
  <tr>
    <td align="right">目标内容编码：</td>
    <td>
	 <input type="text" name="info[c_charset]" value="{:$data['c_charset']}" size="6" />&nbsp;<span class="fblue">*在程序不能自动识别编码（采集结果为乱码）时，可以手工指定，常用编码：UTF-8，GBK</span>
	</td>
  </tr>
  <tr>
    <td></td>
    <td>
	 <button type="submit" name="submit" value="submit">提 交</button>&nbsp; <button type="reset" name="reset">重 置</button>&nbsp;<button type="button" name="back" onclick="history.go(-1)">返 回</button>
	 <span class="fblue">{:if $a == 'add'}提示：提交后进入内容采集规则设置{:/if}</span>
	</td>
  </tr>
  </form>
</table>
<!--{:elseif $a == 'content_rule'}-->
<script type="text/javascript">
function select_field(obj){
	var name=obj.value;
	if (obj.checked) {
		$('#begin_'+name).removeAttr('disabled');
		$('#end_'+name).removeAttr('disabled');
		$('#old_'+name).removeAttr('disabled');
		$('#new_'+name).removeAttr('disabled');
		$('#set_'+name).show();
	} else {
		$('#begin_'+name).attr('disabled', 'disabled');
		$('#end_'+name).attr('disabled', 'disabled');
		$('#old_'+name).attr('disabled', 'disabled');
		$('#new_'+name).attr('disabled', 'disabled');
		$('#set_'+name).hide();
	}
}

function AddSeperate(objstart,objend,charvalue)
{
	objstart.value=objstart.value+charvalue;
	objend.value=objend.value+charvalue;
	objstart.focus();
}
</script>
<table cellpadding="0" cellspacing="1" class="table_form">
 <caption>内容采集规则</caption>
  <form name="myform" action="?c={:$c}&a={:$a}" method="post">
  <input name="rid" type="hidden" value="{:$rid}" />
  <input name="forward" type="hidden" value="{:$referer}" />
  {:loop $all_fields $k $v}
  <tbody id="set_{:$k}"{:if !in_array($k, $myfield)} style="display:none"{:/if}>
  <tr>
    <td width="10%" rowspan="2" align="right">{:$v['name']}：</td>
    <td>
	  区域设置：从&nbsp;<textarea name="af[{:$k}][begin]" id="begin_{:$k}" style="width:275px;height:36px"{:if !in_array($k, $myfield)} disabled="disabled"{:/if}>{:htmlspecialchars($af[$k]['begin'])}</textarea>
	  到&nbsp;<textarea name="af[{:$k}][end]" id="end_{:$k}" style="width:275px;height:36px"{:if !in_array($k, $myfield)} disabled="disabled"{:/if}>{:htmlspecialchars($af[$k]['end'])}</textarea>
    </td>
  </tr>
  <tr>
   <td>
     替换规则：从&nbsp;<textarea name="arp[{:$k}][old]" id="old_{:$k}" style="width:275px;height:36px"{:if !in_array($k, $myfield)} disabled="disabled"{:/if}>{:htmlspecialchars($arp[$k]['old'])}</textarea>
	 到&nbsp;<textarea name="arp[{:$k}][new]" id="new_{:$k}" style="width:275px;height:36px"{:if !in_array($k, $myfield)} disabled="disabled"{:/if}>{:htmlspecialchars($arp[$k]['new'])}</textarea>
   </td>
  </tr>
  </tbody>
  {:/loop}
  <tr>
   <td align="right">可选字段：</td>
   <td>{:loop $select_fields $k $v}<input type="checkbox" name="select_field[{:$k}]" value="{:$k}" onclick="select_field(this)" />{:$v['name']}{:/loop}</td>
  </tr>
  <tr>
   <td align="right">常量：</td>
   <td>当前时间 {TIME} ，当前用户名 {USERNAME} </td>
  </tr>
  <tr>
   <td align="right"><span class="fred">提示信息：</span></td>
   <td>
    <span class="fred">区域设置和替换开始规则支持通配符 (*) ，多项替换用 (|) 分隔，仅设置区域开始则作为默认值，替换目标支持反向引用 ($n)<br />替换目标留空表示排除，多个替换规则设置时请务必遵循先排除后替换，只有这样，才能达到最高的效率和最大程度的准确</span><br />
   </td>
  </tr>
  <tr>
    <td align="right">分页规则：</td>
    <td>
	  开始&nbsp;<textarea name="pagerule[begin]" style="width:255px;height:36px">{:htmlspecialchars($pagerule['begin'])}</textarea>
	  结束&nbsp;<textarea name="pagerule[end]" style="width:255px;height:36px">{:htmlspecialchars($pagerule['end'])}</textarea>&nbsp;<input type="checkbox" name="pagerule[ismerge]" value="1"{:Tag::checked($pagerule['ismerge'], 1)} />合并分页
    </td>
  </tr>
  <tr>
    <td align="right">保护规则：</td>
    <td>
	 <input type="text" id="protect" name="protect" value="{:$protect}" size="47" />
	 <span class="fblue">设置一些要保护的内容不被替换规则替换，多个用 <a href="javascript:void(0)" onclick="set_value('protect', '(|)', 'append')">(|)</a> 隔开</span>
	</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
	 <button type="submit" name="submit" value="submit">提 交</button>&nbsp; <button type="reset" name="reset">重 置</button>&nbsp;<button type="button" name="back" onclick="history.go(-1)">返 回</button>
	</td>
  </tr>
  </form>
</table>
{:elseif $a == 'view'}
<form name="myform" action="?c={:$c}&a={:$a}" method="post">
<table cellpadding="0" cellspacing="1" class="table_list">
 <caption>已采集内容查看</caption>
  <input name="urlid" type="hidden" value="{:$urlid}" />
  <input name="forward" type="hidden" value="{:$referer}" />
{:loop $data $k $v}
 <tr><td width="100" align="right">{:$fields[$k]['name']}：</td><td>{:if $k == 'title'}<input type="text" name="info[title]" value="{:$v}" size="80" />{:elseif $k == 'content'}{:Tag::editor('content', 'info[content]', $data['content'], 'article')}{:else}$v{:/if}</td></tr>
{:/loop}
 <tr>
  <td>&nbsp;</td>
  <td>
   <button type="submit" name="submit" value="submit">提 交</button>
   <button type="button" name="back" onclick="history.go(-1)">返 回</button>
  </td>
 </tr>
</table>
</form>
{:elseif $a == 'export'}
<script type="text/javascript">
function copyruleToClipBoard(){
	window.clipboardData.setData("Text",$('#rule').html());
	alert("您已复规则内容，请粘贴到QQ/MSN/论坛等分享!");
}
</script>
<table cellpadding="0" cellspacing="1" class="table_list">
 <caption>采集规则导出</caption>
 <tr><td><div id="rule" style="margin:5px;">{:$rule_str}</div></td></tr>
 <tr>
  <td align="center">
   <button onclick="copyruleToClipBoard()">分享规则</button>
   <button type="button" name="back" onclick="history.go(-1)">返 回</button>
  </td>
 </tr>
</table>
{:elseif $a == 'import'}
<table cellpadding="0" cellspacing="1" class="table_form">
 <caption>采集规则导入</caption>
  <form name="myform" action="?c={:$c}&a={:$a}" method="post">
  <tr>
   <td width="20%" align="right">规则：</td>
   <td><textarea name="rule" cols="90" rows="20"></textarea></td>
  </tr>
  <tr>
   <td></td>
   <td><button type="submit" name="submit" value="submit">提 交</button>&nbsp;<button type="button" name="back" onclick="history.go(-1)">返 回</button></td>
  </tr>
  </form>
</table>
{:elseif $a == 'defaults'}
<table cellpadding="0" cellspacing="1" class="table_list">
 <caption>管理任务</caption>
 <form method="post" action="">
 <input type="hidden" name="selids" value="">
  <tr align="center">
   <th width="5%">选中</th>
   <th width="10%">名称</th>
   <th width="10%">栏目</th>
   <th>简单描述</th>
   <th width="9%">时间</th>
   <th width="29%">操作</th>
   <th width="21%">采集</th>
  </tr>
  {:loop $data $v}
  <tr align="center">
   <td><input type="checkbox" name="rids" value="{:$v['rid']}"></td>
   <td align="left">{:$v['name']}</td>
   <td><a href="list.php?catid={:$v['catid']}" target="_blank">{:get_category($v['catid'], 'name')}</a></td>
   <td align="left">{:$v['description']}</td>
   <td>{:Tag::date($v['addtime'],1)}</td>
   <td>
	<a href="?c=spider&a=edit&rid={:$v['rid']}">任务规则</a>|
	<a href="?c=spider&a=content_rule&rid={:$v['rid']}">内容规则</a>|
	<a href="?c=spider&a=test&rid={:$v['rid']}" target="_blank">测试</a>|
	<a href="?c=spider&a=copy&rid={:$v['rid']}">复制</a>|
	<a href="?c=spider&a=export&rid={:$v['rid']}">导出</a>|
	<a href="?c=spider&a=del&selids={:$v['rid']}">删除</a>
   </td>
   <td>
    <a href="?c=spider&a=get_url&rid={:$v['rid']}">采集网址</a>|
	<a href="?c=spider&a=get_content&rid={:$v['rid']}">采集内容</a>|
	<a href="?c=spider&a=post&rid={:$v['rid']}">发布</a>|
	<a href="?c=spider&a=content&rid={:$v['rid']}">管理</a>
   </td>
  </tr>
  {:/loop}
  <tr align='center'>
   <td colspan="7">
   <button name="select1" onClick="selAll(this.form.rids)" type="button">全选</button>
   <button name="select2" onClick="noSelAll(this.form.rids)" type="button">反选</button>
   <button name="submitsc" type="button" onClick="subform(this.form,this.form.rids,'?c=spider&a=del','确认删除吗？此操作不可恢复。')">删除选定任务</button>
   </td>
  </tr>
 </form>
</table>
{:if $pages}<div class="pages">{:$pages}</div>{:/if}
{:elseif $a == 'content'}
<table cellpadding="0" cellspacing="1" class="table_list">
 <caption>管理内容</caption>
 <form method="post" action="">
 <input type="hidden" name="selids" value="">
  <tr align="center">
   <th width="5%">选中</th>
   <th>标题 & 缩略图</th>
   <th width="10%">栏目</th>
   <th width="6%">已采集</th>
   <th width="10%">采集时间</th>
   <th width="10%">操作</th>
  </tr>
  {:loop $data $v}
  <tr align="center">
   <td><input type="checkbox" name="urlids" value="{:$v['urlid']}"></td>
   <td align="left">
    <a href="{:$v['url']}" target="_blank">{:$v['title']}</a>
	{:if $v['img']}<br /><a href="{:$v['img']}" target="_blank">{:$v['img']}</a>{:/if}
   </td>
   <td>{:get_category($v['catid'], 'name')}</td>
   <td>{:if $v['isdata']==1}是{:elseif $v['isdata']==2}<span class="fred">失败</span>{:else}<span class="fblue">否</span>{:/if}</td>
   <td>{:Tag::date($v['addtime'],1)}</td>
   <td>
    <a href="?c=spider&a=view&urlid={:$v['urlid']}">查看</a> | 
	<a href="?c=spider&a=delall&selids={:$v['urlid']}">删除</a>
   </td>
  </tr>
  {:loopelse}
  <tr>
   <td colspan="6">您还没有要处理的内容！</td>
  </tr>
  {:/loop}
  <tr align='center'>
   <td colspan="6">
   <button name="select1" onClick="selAll(this.form.urlids)" type="button">全选</button>
   <button name="select2" onClick="noSelAll(this.form.urlids)" type="button">反选</button>
   <!--{:if $rid}-->
   <button name="postbyurlid" type="button" onClick="subform(this.form,this.form.urlids,'?c=spider&a=postbyid&rid={:$rid}','')">发布</button>
   <!--{:/if}-->
   <button name="delall" type="button" onClick="subform(this.form,this.form.urlids,'?c=spider&a=del_all','确认删除吗？此操作不可恢复。')">删除</button>
   <button name="delcontent" type="button" onClick="subform(this.form,this.form.urlids,'?c=spider&a=del_content','删除内容后，可以重新采集内容！')">删除内容</button>
   <button name="truncate" type="button" onClick="subforms(this.form,'?c=spider&a=truncate','清空内容，将删除全部内容及网址！')">清空内容</button>
   <select name="jump" onchange="if(this.options[this.selectedIndex].value!=''){location='?c=spider&a=content&rid='+this.options[this.selectedIndex].value;}">
    <option value=''>跳转内容至…</option>
    {:Tag::option($rule, $rid)}
   </select>
   </td>
  </tr>
 </form>
</table>
{:if $pages}<div class="pages">{:$pages}</div>{:/if}
{:/if}
{:tpl foot}