 <?php
require_once(dirname(__FILE__)."/admin_inc.php");
/*******************************************************************************************
' Software name: DJCMS Content Management System
' Version:3.0
' Web: http://www.djcms.net
' Author: 心情(qq:1130731)
' Copyright (C) 2009-2010 DJCMS官方 版权所有
' 法律申明：DJCMS程序所有代码100%原创、未引入任何网上代码,对一切抄袭行为、坚决严肃追究法律责任
'*******************************************************************************************/
@error_reporting(0);
@set_time_limit(0);
@session_start();
$action = getForm("action", "get");
switch ($action) {
	case "wizard2save":wizard2save();break;
	case "ghost":ghost();break;
	case "remove":removeesfile();break;
	case "delall" : delAll();break;
	case "exec":Heades();execesfile();Footer();break;
	case "proxy" : proxy();break;
	case "saveVideo":saveVideo();break;
	case "import":Heades();import();Footer();break;
	case "editVideo":Heades();editVideo();popDiv();Footer();break;
	case "tempdatabase" : Heades();tempdatabase();Footer();break;
	case "delallTempData":delallTempData();break;
	case "delTempData":delTempData();break;
	case "customerdelcls":customerdelcls();break;
	case "customerdelallcls":customerdelallcls();break;
	case "customersavecls":customersavecls();break;
	case "customercls":Heades();customercls();Footer();break;
	case "customernewcls":customernewcls();break;
	case "saveeditoradd":saveeditoradd();break;
	case "filtersban":filtersban();break;
	case "filtersdel":filtersdel();break;
	case "filtersdelall":filtersdelall();break;
	case "filters":Heades();filtersDictionary();Footer();break;
	case "filtersadd":
	case "filtersedit":Heades();EditOrAdd();Footer();break;
	case "wizard":
	case "edit":Heades();wizard();Footer();break;
	default : Heades();itemlist();Footer();break;
}

function proxy() {
	$txt = GetHttpTextFile(getForm("url", "get"),getForm("charset", "get"));
	echo ifthen(getForm("result", "get") == "false", "OK", $txt);
}

function Heades() {
	global $menuList;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>DjCMS智能采集工具</title>
<link href="imgs/admin.css" rel="stylesheet" type="text/css" />
<script src="../js/common.js" type="text/javascript"></script>
<script src="imgs/main.js" type="text/javascript"></script>
<script>if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?=$menuList[6][0]?>&nbsp;&raquo;&nbsp;智能采集工具';</script>
<style type="text/css">
input{height:12px;}
.txt{width:250px;}
.tb2 td{padding:2px 5px 2px 5px;height:25px}
.tb2 .thc{text-align:center;line-height:30px; background-color: #F5F7F8;font-size:18px;font-weight:bold;color:#000}
.tb2 .thr{text-align:center;height:20px}
.label{padding:0;width:150px;text-align:right;border-right:1px solid #DEEFFA;}
.btn{height:22px}
.red{color:red}
.blue{color:blue}
</style>
<script type="text/javascript">
function show(){
	var arg=arguments;
	for(var i=0;i<arg.length;i++){
		$(arg[i]).style.display="";
	}
}

function hide(){
	var arg=arguments;
	for(var i=0;i<arg.length;i++){
		$(arg[i]).style.display="none";
	}
}
</script>
</head>
<body bgcolor="#F7FBFF">
<div class="container" id="cpcontainer">
<?php
}

function Footer(){
	global $t1;
?></div>
<div align=center><?php echo getRunTime($t1);?></div>
<div align=center>Copyright 2005-2010 All rights reserved. <a target="_blank" href="http://www.djcms.net/">djCms3.0</a></div>
</body>
<iframe frameborder="0" scrolling="no" height="0" width="0" name="hiddensubmit" id="hiddensubmit" src="about:blank"></iframe>
</html>
<?php
}

function wizard2save() {
	$id = getForm("id","post");
	$feedarr = array(
	'itemname' => getForm("itemname","post"),
	'siteurl' => getForm("siteurl","post"),
	'charset' => getForm("charset","post"),
	'playfrom' => getForm("playfrom","post"),
	'enable' => getForm("enable","post"),
	'intoa' => getForm("intoa","post"),
	'autocls' => getForm("autocls","post"),
	'classid' => getForm("classid","post"),
	'isupdate' => getForm("isupdate","post"),
	'getherday' => getForm("getherday","post"),
	'inithit' => getForm("inithit","post"),
	'pageset' => getForm("pageset","post"),
	'pageurl0' => getForm("pageurl0","post"),
	'pageurl1' => getForm("pageurl1","post"),
	'pageurl2' => getForm("pageurl2","post"),
	'istart' => getForm("istart","post"),
	'iend' => getForm("iend","post"),
	'reverse' => getForm("reverse","post"),
	'removecode' => getForm("removecode","post"),
	'listA' => getForm("listA","post"),
	'listB' => getForm("listB","post"),
	'mlinkA' => getForm("mlinkA","post"),
	'mlinkB' => getForm("mlinkB","post"),
	'picmode' => getForm("picmode","post"),
	'mdataA' => getForm("mdataA","post"),
	'mdataB' => getForm("mdataB","post"),
	'nameA' => getForm("nameA","post"),
	'nameB' => getForm("nameB","post"),
	'actorA' => getForm("actorA","post"),
	'actorB' => getForm("actorB","post"),
	'clsA' => getForm("clsA","post"),
	'clsB' => getForm("clsB","post"),
	'dateA' => getForm("dateA","post"),
	'dateB' => getForm("dateB","post"),
	'yearA' => getForm("yearA","post"),
	'yearB' => getForm("yearB","post"),
	'areaA' => getForm("areaA","post"),
	'areaB' => getForm("areaB","post"),
	'stateA' => getForm("stateA","post"),
	'stateB' => getForm("stateB","post"),
	'noteA' => getForm("noteA","post"),
	'noteB' => getForm("noteB","post"),
	'picA' => getForm("picA","post"),
	'picB' => getForm("picB","post"),
	'picvar' => getForm("picvar","post"),
	'desA' => getForm("desA","post"),
	'desB' => getForm("desB","post"),
	'splay' => getForm("splay","post"),
	'plistA' => getForm("plistA","post"),
	'plistB' => getForm("plistB","post"),
	'playgetsrc' => getForm("playgetsrc","post"),
	'playlinkA' => getForm("playlinkA","post"),
	'playlinkB' => getForm("playlinkB","post"),
	'isspecial' => getForm("isspecial","post"),
	'linkRF' => getForm("linkRF","post"),
	'msrcA' => getForm("msrcA","post"),
	'msrcB' => getForm("msrcB","post"),
	'getpart' => getForm("getpart","post"),
	'partA' => getForm("partA","post"),
	'partB' => getForm("partB","post"),
	'CollectTime' => time(),
	);
	if ($id) {
	    DB::update('collect', $feedarr, array('id' => $id));
	    alertMsg("修改成功","admin_gather.php?action=main");
	} else {
		DB::insert('collect', $feedarr);
	    alertMsg("保存成功","admin_gather.php?action=main");
	}
}

function wizard() {
	global $action,$menuList;
	$id = intval(getForm("id","get"));
	if ($action == "edit") {
	    $row = DB::fetch_first("select itemname,siteurl,charset,playfrom,enable,intoa,autocls,classid,isupdate,getherday,inithit,pageset,pageurl0,pageurl1,pageurl2,istart,iend,reverse,removecode,listA,listB,mlinkA,mlinkB,picmode,mdataA,mdataB,nameA,nameB,actorA,actorB,clsA,clsB,dateA,dateB,yearA,yearB,areaA,areaB,stateA,stateB,noteA,noteB,picA,picB,picvar,desA,desB,splay,plistA,plistB,playgetsrc,playlinkA,playlinkB,isspecial,linkRF,linkRR,msrcA,msrcB,getpart,partA,partB,CollectTime from ".DB::table('collect')." where id=$id");
		foreach ($row as $k => $v) {
		    if (!isset($$k)) {
			    $$k = stripslashes($v);
		    }
	    }
	} else {
	    global $itemname,$siteurl,$charset,$playfrom,$enable,$intoa,$autocls,$classid,$isupdate,$getherday,$inithit,$pageset,$pageurl0,$pageurl1,$pageurl2,$istart,$iend,$reverse,$removecode,$listA,$listB,$mlinkA,$mlinkB,$picmode,$mdataA,$mdataB,$nameA,$nameB,$actorA,$actorB,$clsA,$clsB,$dateA,$dateB,$yearA,$yearB,$areaA,$areaB,$stateA,$stateB,$noteA,$noteB,$picA,$picB,$picvar,$desA,$desB,$splay,$plistA,$plistB,$playgetsrc,$playlinkA,$playlinkB,$isspecial,$linkRF,$linkRR,$msrcA,$msrcB,$getpart,$partA,$partB,$savefiles;
	}
?>
<table class="tb">
	<thead>
		<tr class="thead"><th>&nbsp;<font color="#000000">操作选项： </font><a href="?childdir=">管理采集规则</a> | <a href="?action=wizard">添加采集规则</a></span></th></tr>
	</thead>
	<tbody>
		<tr>
			<td>1. 通过本向导将传统的采集规则转换成采集规则文件</td>
		</tr>
	</tbody>
</table>
 
<table class="tb2">
	<thead>
		<tr>
			<th colspan="2" height="20"><span id="showurl"></span></th>
		</tr>
		<tr id="htmltable" style="display:none">
			<th colspan="2"><textarea id="htmlcode" style="width:100%;height:200px;font-family:Fixedsys" wrap="off" readonly></textarea></th>
		</tr>
		<tr>
			<th colspan="2" class="thc">使用采集规则向导生成采集规则文件</th>
		</tr>
		<tr>
			<th colspan="2" class="thr"><font id="stephit1" color="red">１. 设置基本参数</font>&nbsp;&nbsp;<font id="stephit2">２. 采集列表连接设置</font>&nbsp;&nbsp;<font id="stephit3">３. 采集内容与数据地址设置</font>&nbsp;&nbsp;<font id="stephit4">４. 在线模拟预览结果</font>&nbsp;&nbsp;<font id="stephit5">５. 完成向导并保持规则</font></th>
		</tr>
	</thead>
</table>
<form name="wizardform" id="wizardform" method="post" action="?action=wizard2save" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="referer" value="<?php echo getRefer();?>" />
 <?php
if ($action == "edit") {
	echo "<input type='hidden' name='id' value=".$id." />"; 
}
?>
<table class="tb2" id="step1" style="display:.none">
	<tbody>
		<tr>
			<td class="label">项目名称：</td>
			<td><input type="text" class="txt" name="itemname" value="<?=$itemname?>" /></td>
		</tr>
        <?php $t = $intoa?>
		<tr>
			<td class="label">入库方式：</td>
			<td><input type="radio" class="radio" name="intoa" value="0" <?=ifthen($t==0,"checked","")?>/><span class="red">临时库</span> <input type="radio" class="radio" name="intoa" value="1" <?=ifthen($t==0,"","checked")?>/>直接入库(不建议使用，会损成数据库很大 或 损坏)</td>
		</tr>
      <?php $t = $isupdate?>
		<tr>
			<td class="label">是否更新时间：</td>
			<td><input type="radio" class="radio" name="isupdate" value="0" <?=ifthen($t==true,"","checked");?>/>否 <input type="radio" class="radio" name="isupdate" value="1" <?=ifthen($t==true,"checked","");?>/>是</td>
		</tr>
		<tr>
			<td class="label">只采集最近：</td>
			<td><select name="getherday" onchange="if(this.value=='0'){hide('datebody')}else{show('datebody')}"><option value="0">不限</option><?php for($i=1;$i<=31;$i++){echo "<option value='".$i."'".ifthen($getherday==$i," selected","").">".$i."</option>";}?></select> 天 * 选择天数还要填写第3步的 <span class="red">数据日期 开始代码 和 结束代码</span>才有效</td>
		</tr>
		<tr>
			<td class="label">目标站点URL：</td>
			<td><input type="text" class="txt" name="siteurl" value="<?=$siteurl?>" /></td>
		</tr>
		<tr>
			<td class="label">网页编码：</td>
			<td><input type="text" name="charset" value="<?=$charset?>" style="width: 85px" />&nbsp;&nbsp;<font color="#0000FF">请选择编码→</font><select onchange="this.form.charset.value=this.value"><option value="">请选择编码</option><option value="GB2312">GB2312</option><option value="GBK">GBK</option><option value="BIG5">BIG5</option><option value="UTF-8">UTF-8</option></select></td>
		</tr>
		<tr>
			<td class="label">播放来源：</td>
			<td><select name='playfrom'><option value=''>暂没有数据</option><?=makePlayerSelect($playfrom)?></select></td>
		</tr>
		<tr>
			<td class="label red">数据分类设置：</td>
			<td><input type="radio" class="radio" name="autocls" value="0" onclick="hide('autoclsbody');show('selcls');" <?=ifthen($autocls==true,"","checked")?>/>固定分类<input type="radio" class="radio" name="autocls" value="1" onclick="hide('selcls');show('autoclsbody');"<?=ifthen($autocls==true,"checked","")?>/>智能归类(若归类失败，数据将自动加到临时库)</td>
		</tr>
		<tr id="selcls" style="<?=ifthen($autocls==true,"display:none","")?>">
			<td class="label">所属分类：</td>
			<td><select name="classid"><option value="0">请选择数据分类</option><?=makeTypeOptionSelected(0,"&nbsp;|&nbsp;","",$classid)?></select></td>
		</tr>
		<tr>
			<td class="label">初始点击数：</td>
			<td><input type="text" name="inithit" value="<?=empty($inithit) ? '-1' : $inithit?>" />&nbsp;<font color="red">-1为随机点击数</font></td>
		</tr>
		<tr>
			<td class="label">分页设置：</td>
			<td>
			<input type="radio" class="radio" name="pageset" value="0" onclick="hide('page_0','page_1','page_2');show('page_0');"<?=ifthen($pageset==0,"checked","");?>/>不分页
			<input type="radio" class="radio" name="pageset" value="1" onclick="hide('page_0','page_1','page_2');show('page_1');"<?=ifthen($pageset==1,"checked","");?>/>批量分页
			<input type="radio" class="radio" name="pageset" value="2" onclick="hide('page_0','page_1','page_2');show('page_2');"<?=ifthen($pageset==2,"checked","");?>/>手动分页
			<input type="radio" class="radio" name="pageset" value="3" onclick="hide('page_0','page_1','page_2');show('page_0');"<?=ifthen($pageset==3,"checked","");?>/>直接采集内容页
			</td>
		</tr>
		<tr id="page_0" style="<?=ifthen($pageset==0 || $pageset==3,"","display:none")?>">
			<td class="label">采集网址：</td>
			<td><input type="text" class="txt" name="pageurl0" value="<?=$pageurl0?>" /></td>
		</tr>
		</tbody>
		<tbody id="page_1" style="<?=ifthen($pageset==1,"","display:none")?>">
		<tr>
			<td class="label">远程列表分页URL：</td>
			<td><input type="text" class="txt" name="pageurl1" value="<?=$pageurl1?>" />&nbsp;ID变量<font color="red">{id}</font></td>
		</tr>
		<tr>
			<td class="label">远程列表起始页：</td>
			<td>标准格式：Http://www.damin.com/list/list_{id}.html<br />开始页：<input type="text" name="istart" value="<?php $t = $istart;echo ifthen($t<1,1,$t);?>" style="width: 60px"/> - 结束页：<input type="text" name="iend" value="<?php $t=$iend;echo ifthen($t<1,1,$t);?>" style="width: 60px" />&nbsp;例如：1 - 10</td>
		</tr>
		</tbody>
		<tbody id="page_2" style="<?=ifthen($pageset==2,"","display:none")?>">
		<tr>
			<td class="label">手动分页：</td>
			<td><textarea name="pageurl2" rows="6" cols="80" wrap="off"><?=$pageurl2;?></textarea></td>
		</tr>
		</tbody>
		<tbody>
		<tr>
			<td class="label">采集方式：</td>
			<td><input type="checkbox" class="checkbox" name="reverse" value="1"<?=ifthen($reverse==1,"checked","");?>/>倒序采集</td>
		</tr>
		</tbody>
	</tbody>
</table>
<table class="tb2" id="step2" style="display:none">
	<tbody>
		<tr>
			<td class="label">数据列表开始代码：</td>
			<td><textarea name="listA" rows="6" cols="80" wrap="off"><?=new_htmlspecialchars($listA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">数据列表结束代码：</td>
			<td><textarea name="listB" rows="6" cols="80" wrap="off"><?=new_htmlspecialchars($listB)?></textarea></td>
		</tr>
		<tbody>
		<tr>
			<td class="label red">获取数据图片方式：</td>
			<td><input type="radio" class="radio" name="picmode" value="1" onclick="show('picbody');$('step2').insertBefore($('picbody'),parentNode.parentNode.parentNode.nextSibling);this.form.elements['fields'][4].checked=true;"<?php if  ($picmode == 1) echo "checked";?>/>在列表页<input type="radio" class="radio" name="picmode" value="0" onclick="$('step3').insertBefore($('picbody'),$('step3').firstChild.nextSibling);"<?php if ($picmode==0) echo "checked";?>/>在内容页</td>
		</tr>
		</tbody>
 
		<tbody>
		<tr>
			<td class="label">数据链接开始代码：</td>
			<td><textarea name="mlinkA" rows="6" cols="80" wrap="off"><?=new_htmlspecialchars($mlinkA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">数据链接结束代码：</td>
			<td><textarea name="mlinkB" rows="6" cols="80" wrap="off"><?=new_htmlspecialchars($mlinkB)?></textarea></td>
		</tr>
	</tbody>
</table>
<table class="tb2" id="step3" style="display:none">
	<tbody>
		<tr>
			<td class="label">可选采集字段</td>
			<td>
				<input type="checkbox" class="checkbox" name="fields" value="actor" onclick="if(this.checked){show('actorbody')}else{hide('actorbody')}"<?=ifthen($actorA.$actorB<>"","checked","");?>/>演员
				<input type="checkbox" class="checkbox" name="fields" value="area" onclick="if(this.checked){show('areabody')}else{hide('areabody')}"<?=ifthen($areaA.$areaB<>"","checked","");?>/>地区
				<input type="checkbox" class="checkbox" name="fields" value="state" onclick="if(this.checked){show('statebody')}else{hide('statebody')}"<?=ifthen($stateA.$stateB<>"","checked","");?>/>连载
				<input type="checkbox" class="checkbox" name="fields" value="note" onclick="if(this.checked){show('notebody')}else{hide('notebody')}"<?=ifthen($noteA.$noteB<>"","checked","");?>/>备注
				<input type="checkbox" class="checkbox" name="fields" value="pic" onclick="if(this.checked){show('picbody')}else{hide('picbody')}"<?=ifthen($picA.$picB<>"","checked","");?>/>图片
				<input type="checkbox" class="checkbox" name="fields" value="year" onclick="if(this.checked){show('yearbody')}else{hide('yearbody')}"<?=ifthen($yearA.$yearB<>"","checked","");?>/>年份
				<input type="checkbox" class="checkbox" name="fields" value="des" onclick="if(this.checked){show('desbody')}else{hide('desbody')}"<?=ifthen($desA.$desB<>"","checked","");?>/>介绍
			</td>
		</tr>
		<tr>
			<td class="label">资料范围开始代码：<div class="blue">数据资料开始标签<br />是指包含有:<br>名称 演员 日期 图片 <br>地区 备注 分类 <br>等基本信息开始位置</div></td>
			<td><textarea name="mdataA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($mdataA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">资料范围结束代码：<div class="blue">数据资料结束标签<br>不包含数据介绍<br>（开始标签 和 结束标签 为空，则不指定范围）</div></td>
			<td><textarea name="mdataB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($mdataB)?></textarea></td>
		</tr>
	</tbody>
	<tbody id="datebody" style="<?=ifthen($getherday>0,"","display:none")?>">
		<tr>
			<td class="label red">数据日期开始代码：<br>必填</td>
			<td><textarea name="dateA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($dateA)?></textarea></td>
		</tr>
		<tr>
			<td class="label red">数据日期结束代码：<br>必填</td>
			<td><textarea name="dateB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($dateB)?></textarea></td>
		</tr>
	</tbody>
	<tbody id="namebody">
		<tr>
			<td class="label">数据名称开始代码：</td>
			<td><textarea name="nameA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($nameA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">数据名称结束代码：</td>
			<td><textarea name="nameB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($nameB)?></textarea></td>
		</tr>
	</tbody>
	<tbody id="actorbody" style="<?=ifthen($actorA.$actorB=="","display:none","");?>">
		<tr>
			<td class="label">数据演员开始代码：</td>
			<td><textarea name="actorA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($actorA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">数据演员结束代码：<div class="blue">开始标签 和 结束标签<br />为空不截取演员</div></td>
			<td><textarea name="actorB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($actorB)?></textarea></td>
		</tr>
	</tbody>
	<tbody id="autoclsbody" style="<?=ifthen($autocls==true,"","display:none");?>">
		<tr>
			<td class="label red">数据分类开始代码：</td>
			<td><textarea name="clsA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($clsA)?></textarea></td>
		</tr>
		<tr>
			<td class="label red">数据分类结束代码：</td>
			<td><textarea name="clsB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($clsB)?></textarea></td>
		</tr>
	</tbody>
	<tbody id="areabody" style="<?=ifthen($areaA.$areaB=="","display:none","");?>">
		<tr>
			<td class="label">数据地区开始代码：</td>
			<td><textarea name="areaA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($areaA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">数据地区结束代码：<div class="blue">开始标签 和 结束标签<br />为空不截取地区</div></td>
			<td><textarea name="areaB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($areaB)?></textarea></td>
		</tr>
	</tbody>
	<tbody id="yearbody" style="<?=ifthen($yearA.$yearB=="","display:none","");?>">
		<tr>
			<td class="label">数据年份开始代码：</td>
			<td><textarea name="yearA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($yearA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">数据年份结束代码：<div class="blue">开始标签 和 结束标签<br />为空不截取年份</div></td>
			<td><textarea name="yearB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($yearB)?></textarea></td>
		</tr>
	</tbody>
	<tbody id="statebody" style="<?=ifthen($stateA.$stateB=="","display:none","");?>">
		<tr>
			<td class="label">数据连载开始代码：</td>
			<td><textarea name="stateA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($stateA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">数据连载结束代码：<div class="blue">开始标签 和 结束标签<br />为空不截取连载</div></td>
			<td><textarea name="stateB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($stateB)?></textarea></td>
		</tr>
	</tbody>
	<tbody id="notebody" style="<?=ifthen($noteA.$noteB=="","display:none","");?>">
		<tr>
			<td class="label">数据备注开始代码：</td>
			<td><textarea name="noteA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($noteA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">数据备注结束代码：<div class="blue">开始标签 和 结束标签<br />为空不截取备注</div></td>
			<td><textarea name="noteB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($noteB)?></textarea></td>
		</tr>
	</tbody>
<?php if ($picmode != 1){;?> 
	<tbody id="picbody" style="<?=ifthen($picA.$picB=="","display:none","");?>">
		<tr>
			<td class="label">数据图片开始代码：</td>
			<td><textarea name="picA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($picA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">数据图片结束代码：<div class="blue">开始标签 和 结束标签<br />为空不截取图片</div></td>
			<td><textarea name="picB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($picB)?></textarea></td>
		</tr>
		<tr>
			<td class="label">数据图片替换变量：<p class="red">图片地址前后加[变量]<br />不加变量请留空</p></td>
			<td><textarea name="picvar" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($picvar)?></textarea></td>
		</tr>
	</tbody>
<?php
}
?>
	<tbody id="desbody" style="display:none">
		<tr>
			<td class="label">数据介绍开始代码：</td>
			<td><textarea name="desA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($desA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">数据介绍结束代码：<div class="blue">开始标签 和 结束标签<br />为空不截取介绍</div></td>
			<td><textarea name="desB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($desB)?></textarea></td>
		</tr>
	</tbody>
 <?php $t = $splay;?>
	<tbody>
		<tr>
			<td class="label red">数据列表范围：</td>
			<td><input type="radio" class="radio" name="splay" value="0" onclick="hide('plistbody');"<?php if ($splay==0) echo "checked";?>/>关闭<input type="radio" class="radio" name="splay" value="1" onclick="show('plistbody')"<?php if ($splay==1) echo "checked";?>/>开启</td>
		</tr>
	</tbody>
	<tbody id="plistbody" style="<?=ifthen($t==true,"","display:none");?>">
		<tr>
			<td class="label">播放列表开始代码：</td>
			<td><textarea name="plistA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($plistA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">播放列表结束代码：</td>
			<td><textarea name="plistB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($plistB)?></textarea></td>
		</tr>
	</tbody>
 <?php $t = $playgetsrc;?>
	<tbody>
		<tr>
			<td class="label red">获取数据地址方式：</td>
			<td><input type="radio" class="radio" name="playgetsrc" value="1" onclick="show('playlinkbody')"<?php if ($playgetsrc==1) echo "checked";?>/>播放页获取单个数据地址<input type="radio" class="radio" name="playgetsrc" value="2" onclick="show('playlinkbody')"<?php if ($playgetsrc==2) echo "checked";?>/>播放页获取所有数据地址<input type="radio" class="radio" name="playgetsrc" value="0" onclick="hide('playlinkbody');clearvalue('playlinkA','playlinkB');"<?php if ($playgetsrc==0) echo "checked";?>/>内容页直接获取数据地址</td>
		</tr>
	</tbody>
	<tbody id="playlinkbody" style="<?=ifthen($t==1 or $t==2,"","display:none");?>">
		<tr>
			<td class="label">播放链接开始代码：</td>
			<td><textarea name="playlinkA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($playlinkA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">播放链接结束代码：</td>
			<td><textarea name="playlinkB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($playlinkB)?></textarea></td>
		</tr>
	</tbody>
	<tbody>
 <?php $t = $isspecial;?> 
		<tr>
			<td class="label red">特殊链接处理：</td>
			<td><input type="radio" class="radio" name="isspecial" value="0" onclick="hide('specialbody');"<?php if ($isspecial==0) echo "checked";?>/>不作设置<input type="radio" class="radio" name="isspecial" value="1" onclick="show('specialbody')"<?php if ($isspecial==1) echo "checked";?>/>替换地址<br>对于使用了JavaScript:openwindow形式的连接请使用此功能</td>
		</tr>
	</tbody>
	<tbody id="specialbody" style="<?=ifthen($t==true,"","display:none");?>">
		<tr>
			<td class="label">要替换的地址：</td>
			<td><p class="red">要替换的连接:javaScript:OpenWnd([变量])</p><textarea name="linkRF" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($linkRF)?></textarea></td>
		</tr>
		<tr>
			<td class="label">替换为的地址：</td>
			<td><p class="red">实际连接:play.php?id=$1</p><textarea name="linkRR" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($linkRR)?></textarea></td>
		</tr>
	</tbody>
	<tbody>
		<tr>
			<td class="label">数据地址开始代码：</td>
			<td><textarea name="msrcA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($msrcA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">数据地址结束代码：</td>
			<td><textarea name="msrcB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($msrcB)?></textarea></td>
		</tr>
 <?php $t  =$getpart;?> 
		<tr>
			<td class="label red">采集数据分集名称：</td>
			<td><input type="radio" class="radio" name="getpart" value="0" onclick="hide('getpartbody');"<?=ifthen($t==true,"","checked");?>/>系统预设<input type="radio" class="radio" name="getpart" value="1" onclick="show('getpartbody')"<?=ifthen($t==true,"checked","");?>/>截取分集名称</td>
		</tr>
	</tbody>
	<tbody id="getpartbody" style="<?=ifthen($t==true,"","display:none");?>">
		<tr>
			<td class="label">分集名称开始代码：</td>
			<td><textarea name="partA" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($partA)?></textarea></td>
		</tr>
		<tr>
			<td class="label">分集名称结束代码：</td>
			<td><textarea name="partB" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($partB)?></textarea></td>
		</tr>
	</tbody>
</table>
<div id="step4" style="display:none">
</div>
<div id="step5" style="display:none">
</div>
<table class="tb2">
	<tbody>
		<tr>
			<td class="label"></td>
			<td><?php if ($action=="edit") echo "<input type='submit' class='btn' value='快速保存'/>&nbsp;&nbsp;";?><input type="button" class="btn" name="back" value="返回上一步" onclick="prestep()" />&nbsp;&nbsp;<input type="button" class="btn" name="next" value="下一步" onclick="nextstep()" />&nbsp;&nbsp;<input type="checkbox" class="checkbox" name="showcode" id="showcode" value="1"/>下一步显示源码</td>
		</tr>
	</tbody>
</table>
</form>
<script type="text/javascript">
function trim(s){
	return (""+s).replace(/(^\s*)|(\s*$)/g,"");
}

function trimall(s){
	return (""+s).replace(/(\s*)/g,"");
}

function addcslashes(str){
	return (""+str).replace(/([\(\)\[\]\""\'\.\?\+\*\/\\\^\$])/ig,"\\$1").replace(/\r\n/g,"\\r\\n");
}

function StrSlice(Str,sStr,eStr){
	var ms=(new RegExp(addcslashes(sStr)+"([\\w\\W]+?)"+addcslashes(eStr),"i")).exec(Str);
	return ms!=null ? ms[1] : false;
}

function StrSliceB(Str,sStr,eStr){
	var ms=(new RegExp(addcslashes(sStr)+"([\\w\\W]+)"+addcslashes(eStr),"i")).exec(Str);
	return ms!=null ? ms[1] : false;
}
//分割文件段
function StrSplits(Str,sStr,eStr){
	var ret=[];
	try{
	Str.replace(new RegExp(addcslashes(sStr)+"([\\w\\W]+?)"+addcslashes(eStr),"ig"),function ($0,$1){
		ret.push($1);
	});
	}catch(ignore){}
	return ret;
}

function paseAbsURI(aLink,currUrl){
	var b,t,H,i,j,k,siteUrl,rg=/^\s*[\/\\]/i,ab=/^http:\/\//i,qt=/\\([\\\/])/ig;
	currUrl=trim(currUrl).replace(qt,"/"),siteUrl=currUrl.replace(/(https?\:\/\/)((\w+)(\.\w+)*(:\d+)?)\/.*/i,"$1$2"),currUrl=currUrl.replace(siteUrl,"")
	for(var i=0;i<aLink.length;i++){
		H=""+aLink[i];
		if(ab.test(H)){
		}else if(rg.test(H)){
			aLink[i]=siteUrl+H
		}else{
			j=H.split("../").length,t=currUrl.split("/"),k=t.length
			t.length=j<k ? k-j : 0
			aLink[i]=siteUrl+t.join("/")+"/"+H.replace(/([\.]{2}\/)/g,"")
		}
	}
	return aLink;
}

function speciallink(sLink,fLink,rLink){
	var a=fLink.split('[变量]');
	rLink=rLink.split('[变量]').join("$1");
	for(var i=0;i<a.length;i++){
		a[i]=addcslashes(a[i]);
	};
	var rg=new RegExp(a.join("([\\w\\W]+)"),"ig");
	return a.length>1 ? sLink.replace(rg,rLink) : sLink;
}

function removeHTMLCode(Str,cHas){
	if(cHas=="") return Str;
	cHas=cHas.toUpperCase().split("|"),Str=""+Str;
	for(var i=0;i<cHas.length;i++){
		switch(cHas[i]){
			case "TABLE":
				Str=Str.replace(/<\/?(table|thead|tbody|tr|th|td).*>/ig,"");
			break;
			case "OBJECT":
				Str=Str.replace(/<\/?(object|param|embed).*>/ig,"");
			break;
			case "SCRIPT":
				Str=Str.replace(new RegExp("<scr"+"ipt.*>[\\w\\W]+?<\\/scr"+"ipt>","ig"),"").replace(new RegExp("\\son[\\w]+=[\\'\\\"].+?[\\'\\\"](\\s|>)(\\s|\\>)","ig"),"$1");
			break;
			case "STYLE":
				Str=Str.replace(/<style.*>[\w\W]+?<\/style>/ig,"");
				Str=Str.replace(/\sstyle=.+(\s|\>)/ig,"$1");
			break;
			case "CLASS":
				Str=Str.replace(/\sclass=.+(\s|\>)/ig,"$1");
			break;
			default:
				Str=Str.replace(new RegExp("<\\/?"+addcslashes(cHas[i])+".*?>","ig"),"");
			break;
		}
	}
	return Str
}

var f=$('wizardform'),hurl={1:"",2:"",3:"",4:""},url,cache={},step=[],stephit=[],istep=1;
for(var i=1;i<6;i++){
	step.push($("step"+i));
	stephit.push($("stephit"+i));
}

function clearvalue(){
	var arg=arguments;
	for(var i=0;i<arg.length;i++){
		try{f.elements[arg[i]].value='';}catch(ignore){}
	}
};

function showBody(n){
	n--;
	for(var i=0;i<step.length;i++){
		step[i].style.display= n!=i ? "none" : "";
		stephit[i].color= n==i ? "red" : "";
	};
}

function prestep(){
	if(istep>1){
		showurl(url=hurl[--istep]);
		showBody(istep);
		if(url!="") request(url,function (Q){$('htmlcode').value=Q.responseText});
	}else{
		if(confirm("确实要离开该页面吗？\n\n这将会导致规则页面上未保存的数据丢失，确定？\n\n按“确定”继续，或按“取消”留在当前页面。")){
			history.go(-1);
		}
	}
}

function request(url,fun){
	url="admin_gather.php?action=proxy&result=true&charset="+f.elements['charset'].value+"&url="+escape(url);
	if(cache[url]==undefined){
		ajax.get(url,function (Q){
			var txt=Q.responseText;
			if(txt!="err" && txt!="ok") cache[url]=txt;
			fun(Q);
		});
	}else{
		fun({responseText:cache[url]})
	}
};

function _nextstep(Q){
	var txt=Q.responseText;
	if(txt!="err"){
		showBody(++istep);
		$('htmltable').style.display=$('showcode').checked ? '' : 'none'
		if(txt!="OK") $('htmlcode').value=txt;
	}else{
		alert("err")
	}
}
function showurl(s){
	$('showurl').innerHTML="&nbsp;&nbsp;当前采集地址：<font color=red>"+s+"</font>";
}
var hPic="",rg=/\[\u53d8\u91cf\]/g;
function nextstep(){
	var es=f.elements,showcode=es['showcode'].checked;
	if(trim(es["charset"].value)==""){alert("请选择网页编码");return;}
	if(istep==1){
		for(var i=0,ps;i<es['pageset'].length;i++){
			if(es['pageset'][i].checked){
				ps=i;
				break;
			}
		};
		if(ps==0 || ps==3){
			url = es['pageurl0'].value
		}else if(ps==1){
			url = es['pageurl1'].value.replace("{id}",trim(es['istart'].value));
		}else if(ps==2){
			url = trim(es['pageurl2'].value).split("\r\n")[0]
		}else{
			alert("请选择分类设置")
		};
		if(es['playfrom'].value==""){
			alert("请选择播放来源");
			return;
		};
		if(es['autocls'][0].checked && es['classid'].value==""){
			alert("请选择所属分类");
			return;
		};
		if(trim(url) == ""){
			alert("请输入采集列表网址");
			return;
		};
		/*
		if(es['getherday'].value=="0"){
			es['dateA'].value=es['dateB'].value='';
		};
		*/
		showurl(hurl[2]=url);
		request(url,function (Q){
				if(ps==3) istep=2;
				_nextstep(Q);
		});
	}else if(istep == 2){
		request(url,function (Q){
			var txt=Q.responseText,ls=StrSliceB(txt,es["listA"].value,es["listB"].value);
			if(ls===false){if(!confirm("截取 数据列表开始代码~数据列表结束代码 失败\n\n点[确定]忽略这错误提示，[取消]返回修改")){return;}}
			var mlink=StrSlice(ls,es["mlinkA"].value,es["mlinkB"].value);
			if(mlink===false){if(!confirm("截取 数据链接开始代码~数据链接结束代码 失败\n\n点[确定]忽略这错误提示，[取消]返回修改")){return;}}
			if(es['picmode'][0].checked){
				var sa=es["picA"].value,sb=es["picB"].value,t=es['picvar'].value;
				if(t!=""){
					hPic = sa+sb!='' ? (rg.test(sa) ? t : '')+StrSlice(txt,sa.replace(rg,""),sb.replace(rg,""))+((rg.test(sb) ? t : '')) : '-';
				}else{
					hPic = sa+sb!='' ? StrSlice(txt,sa,sb) : '-';
				};
				if(hPic===false){
						if(!confirm("截取 数据图片开始代码 ~ 数据结束代码 失败\n\n点[确定]忽略这错误提示，[取消]返回修改")){
							return;
						}
				};
			}
			mlink=paseAbsURI([mlink],url);
			$('htmlcode').value=mlink;
			showurl(hurl[3]=url=mlink);
			request(url,function (W){
				_nextstep(W);
			});
		});
	}else if(istep == 3){
		request(url,function (Q){
			var t,sa,sb,ttxt,txt=Q.responseText,val={},has={'name':"数据名称",'actor': "主要演员",'cls': '数据分类','date': '数据日期','area': '数据地区','note': '数据备注','state': '数据连载','year': '数据年份'};
			sa=es["mdataA"].value,sb=es["mdataB"].value;
			ttxt = sa+sb!='' ? StrSlice(txt,sa,sb) : txt;
			if(ttxt === false){
				if(!confirm("截取 资料范围开始代码 ~ 资料范围结束代码 失败\n\n点[确定]忽略这错误提示，[取消]返回修改")){
					return;
				}
			}
			for(var k in has){
				try{
				sa=es[k+"A"].value,sb=es[k+"B"].value;
				val[k] = sa+sb!='' ? removeHTMLCode(StrSlice(ttxt,sa,sb),"SCRIPT|STYLE|*") : '-';
				}catch(ignore){}
			};
			if(!es['picmode'][0].checked){
				sa=es["picA"].value,sb=es["picB"].value,t=es['picvar'].value;
				if(t!=""){
					val['pic'] = sa+sb!='' ? (rg.test(sa) ? t : '')+StrSlice(ttxt,sa.replace(rg,""),sb.replace(rg,""))+((rg.test(sb) ? t : '')) : '-';
				}else{
					val['pic'] = sa+sb!='' ? StrSlice(ttxt,sa,sb) : '-';
				};
			}else{
				val['pic']=hPic;
			}
			if(es["autocls"][1].checked && val['cls']=="-"){
				if(!confirm("截取 "+has['cls']+"开始代码 ~ "+has['cls']+"结束代码 失败\n\n点[确定]忽略这错误提示，[取消]返回修改")){
					return;
				}
			}
			sa=es["desA"].value,sb=es["desB"].value;
			val['des'] = sa+sb!='' ? StrSlice(txt,sa,sb) : "-";
			has['des']='数据介绍',has['pic']='数据图片',has['msrc']='数据地址',has['plist']='播放列表',has['playlink']='播放链接',has['linkR']='特殊链接处理';
			var ch=function (R){
			var txt=R.responseText;
				sa=es["msrcA"].value,sb=es["msrcB"].value;
				val['msrc']=StrSplits(txt,sa,sb).join("\r\n");
				if(val['msrc']=='') val['msrc']=false;
				for(var k in has){
					if(val[k]===false){
						if(!confirm("截取 "+has[k]+"开始代码 ~ "+has[k]+"结束代码 失败\n\n点[确定]忽略这错误提示，[取消]返回修改")){
							return;
						}
					};
				};
				if(val['pic']!='-') val['pic']=paseAbsURI([val['pic']],url).join();
				var dc=$('step4');
var s="\
数据名称："+trim(val['name'])+"\r\n\
数据分类："+trim(val['cls'])+"\r\n\
主要演员："+trimall(val['actor'])+"\r\n\
数据时间："+trim(val['date'])+"\r\n\
数据年份："+trim(val['year'])+"\r\n\
数据地区："+trim(val['area'])+"\r\n\
数据备注："+trim(val['note'])+"\r\n\
数据连载："+trim(val['state'])+"\r\n\
数据图片："+trim(val['pic'])+"\r\n\
数据地址：\r\n"+trim(val['msrc'])+"\r\n\r\n\
数据介绍："+trim(val['des'])+"\r\n\
";
				dc.innerHTML="<pre>"+s.replace(/\</g,"&lt;").replace(/\>/g,"&gt;")+"</pre>";
				_nextstep(R);
				//f.submit();
			};
			if(es['splay'][1].checked){
				k='plist',sa=es[k+"A"].value,sb=es[k+"B"].value;
				val[k] = sa+sb!='' ? StrSlice(txt,sa,sb) : '-';
				txt= val[k];
			}
			if(es['playgetsrc'][0].checked || es['playgetsrc'][1].checked){
				k='playlink',sa=es[k+"A"].value,sb=es[k+"B"].value;
				val[k] = sa+sb!='' ? StrSlice(txt,sa,sb) : '-';
				if(val[k]===false){
					if(!confirm("截取 "+has[k]+"开始代码 ~ "+has[k]+"结束代码 失败\n\n点[确定]忽略这错误提示，[取消]返回修改")){
						return;
					}
				};
				if(es['isspecial'][1].checked) val[k]=speciallink(val[k],es["linkRF"].value,es["linkRR"].value);
				showurl(hurl[4]=paseAbsURI([val[k]],url).join());
				request(hurl[4],function (R){
					$('htmlcode').value=R.responseText;
					ch(R);
				});
			}else{
				ch({'responseText':txt});
			}
		});
	}else if(istep == 4){
		f.submit()
		//ajax.postf(f,function (Q){
		//	_nextstep(Q);
		//});
	}
}
</script>
<?php
}

function itemlist() {
	global $menuList;
	$page = getForm("page", "get");$page=ifthen($page<1,1,$page);
	$number = 10;
    $sqlStr = "select * from ".DB::table('collect')." order by `id` desc";
	$allRecordset = DB::getCount($sqlStr);
	$tpagecount = ceil($allRecordset / $number);
	if ($page > $tpagecount) $page = $tpagecount;
	switch (gatherSet) {
		case 0:$iMode="智能覆盖";break;
		case 1:$iMode="地址头部追加";break;
		case 2:$iMode="地址尾部追加";break;
		case 3:$iMode="覆盖地址";break;
		case 4:$iMode="新增数据";break;
		case 5:$iMode="仅更新地址以外的信息";break;
	}
?>
<table class="tb">
	<tr class="thead"><th colspan="7"><div style="float:left">采集规则列表 <a href="?">管理采集规则</a> | <a href="?action=wizard">添加采集规则</a></span></div><div style="float:right">入库方式：<span class=red><?=$iMode;?></span> <a href="admin_config.php#rule">更改设置</a></div></th></tr>
    <tr>
 <td colspan="7">小提示：第一次采集在批量分页里填写完整的页码，以后采集时更改为前几页可以大大提高采集效率！</td>
 <form action="" method="post" name="linkform">
 </tr>
     <TR align="center">
	  <TD>&nbsp;</TD>
      <TD width="6%">ID</TD>
      <TD>采集名称</TD>
      <TD>播放器/分类</TD>
      <TD>目标站点</TD>
      <TD>最后采集时间</TD>
      <TD>操作</TD>
    </TR>

	<?php
$page = max(intval($page), 1);
$offset = $number*($page-1);
$query = DB::query("$sqlStr LIMIT $offset, $number");
while($row = DB::fetch($query)) {
 ?>
	<TR align="center">
        <TD>&nbsp;</TD>
        <TD align="left"><input type="checkbox" value="<?=$row['id']?>" name="m_id[]"  class="checkbox" /><?=$row['id']?></TD>
		<td><img width="16" height="16" src="imgs/icon01.GIF" align="absmiddle"/> <?=$row['itemname']?></td>
		<td align="center"><?php if(empty($row['playfrom'])) echo "没有指定播放器"; else echo $row['playfrom'];?>/
		<?php if($row['autocls']){echo "<font color=\"red\">自动转换分类</font>";}else{if($row['classid']) echo viewDataType($row['classid']); else echo "<font color=\"red\">没有分类，请修改</font>";}?></td>
		<td><a href="javascript:void(0);" onclick="window.open('<?=$row['siteurl']?>','_blank');" title="<?=$row['siteurl']?>"><?php echo msubstr($row['siteurl'],20);?></a></td>
        <?php if($row['CollectTime']==0){echo " <td>从未采集过"; }else {?><td title="<?=MyDate('Y-m-d H:i:s',$row['CollectTime'])?>"><span style='font-size:9px'><?=MyDate('Y-m-d',$row['CollectTime'])?></span><?php }?></td>
		<td align="center" colspan="2"><a href="?action=exec&id=<?=$row['id']?>">采集</a> <a href="?action=ghost&id=<?=$row['id']?>">克隆</a> <a href="?action=edit&id=<?=$row['id']?>">编辑</a> <a href="#" onclick="if(confirm('确定要永久删除<?=$row['itemname']?>采集规则吗？')) $('hiddensubmit').src='?action=remove&id=<?=$row['id']?>'">删除</a></td>
	</tr>
	<?php
}
?>
<tr><td  colspan="7"><label>全选<input type="checkbox" name="chkall" id="chkall" class="checkbox" onclick="checkAll(this.checked,'input','m_id[]')" /></label><label>反选<input type="checkbox" name="chkothers" id="chkothers" class="checkbox" onclick="checkOthers('input','m_id[]')" /></label><input type="submit" value="批量删除" onclick="if(confirm('确定要删除吗')){linkform.action='?action=delall';}else{return false}" class="btn"  />&nbsp;&nbsp; <?=fPageCount($allRecordset, $number, $page)?></td></tr>
</table>
<?php
}

function tempdatabase() {
	$inbase=getForm("inbase","get");$keyword=getForm("keyword","both");$m_type=getForm("type","both");$m_typename=getForm("typename","both");$playfrom=getForm("playfrom","both");$page=getForm("page","get");$page=ifthen($page<1,1,$page);
	$whereStr = " where 1=1";
	if ($inbase == 'true') {
       $whereStr .= " and `m_inbase`=1";
	} else if ($inbase == 'false') {
       $whereStr.=" and `m_inbase`=0";
    }
	if (is_numeric($m_type)) {
	   if ($m_type == '0') {
		   $whereStr .= " and `m_type` in (0)";
	   } else {
		   $whereStr .= " and `m_type` in (".getTypeIdOnCache($m_type).")";
	   }
	}
    $number = 30;
	if (!empty($m_typename)) $whereStr .= " and m_typename='".$m_typename."";
	if (!empty($keyword)) $whereStr .= " and `m_name` like '%".$keyword."%' or `m_actor` like '%".$keyword."%' ";
    if (!empty($playfrom)) $whereStr .= " and m_playdata like '%".$playfrom."$$%' ";
    $whereorder = str_replace("where and", "where", $whereStr);
    $sqlStr = "SELECT m_id,m_name,m_inbase,m_state,m_type,m_typename,m_addtime,m_playdata FROM ".DB::table('tempdata')." ".$whereorder." ORDER BY m_addtime DESC";
	$allRecordset = db::getCount($sqlStr);
	$tpagecount = ceil($allRecordset / $number);
	if ($page > $tpagecount) $page = $tpagecount;
    switch (gatherSet) {
	    case "0":$iMode="智能覆盖";break;
	    case "1":$iMode="地址头部追加";break;
	    case "2":$iMode="地址尾部追加";break;
	    case "3":$iMode="覆盖地址";break;
	    case "4":$iMode="新增数据";break;
	    case "5":$iMode="仅更新地址以外的信息";break;
    }
?>
<table class="tb">
	<tr class="thead"><th colspan="5">&nbsp;<font color="#000000">管理临时库： </font><a href="?action=tempdatabase&inbase=true">显示已入库的</a> | <a href="?action=tempdatabase&inbase=false">显示未入库的</a> | <a href="?action=tempdatabase&type=0">显示未分类的</a> | <a href="?action=tempdatabase">显示所有</a></th><th colspan="4">入库方式：<span class=red><?php echo $iMode;?></span> <a href="admin_config.php#rule">更改设置</a></th></tr>
	<form action="?action=tempdatabase" method="post">
	<tr>
		<td align="left" colspan="9">
		关键字<input name="keyword" type="text" id="keyword" size="20">
		<select name="type" id="type"><option value="">请选择数据分类</option><?php makeTypeOption(0,"&nbsp;|&nbsp;")?></select>
		<input type="submit" name="selectBtn"  value="查 询..." class="btn" />&nbsp;
		<select onchange="self.location.href='?action=tempdatabase&type='+this.options[this.selectedIndex].value"><option value="">按数据分类查看</option><?php makeTypeOption(0,"&nbsp;|&nbsp;")?></select>
		<select id='m_playfrom' name='m_playfrom' style="width:120px" onChange="self.location.href='?action=tempdatabase&playfrom='+this.options[this.selectedIndex].value"><option value=''>按视频来源查看</option><?php echo makePlayerSelect("");?></select>
		</td>
	</tr>
</form>
<?php
    if($allRecordset == 0) {
	    if (!empty($keyword))  echo "<tr align='center'><td>关键字  <font color=red>\"".$keyword."\"</font>   没有记录</td></tr>"; 
    } else {
	    if (!empty($keyword)) {
?>
  <tr ><td colspan="10">关键字  <font color=red> <?=$keyword?> </font>   的记录如下</td></tr>
<?php
    }
?>
	<tr>
		<td width="50">编号</td>
		<td>数据名称</td>
		<td width="50">状态</td>
		<td width="80">播放器</td>
		<td width="80">绑定分类</td>
		<td width="80">旧分类名</td>
		<td width="200">采集时间</td>
		<td width="50" colspan="2" align="center">操作</td>
	</tr>
	<form method="post" name="tempdataform" action="?action=delallTempData">
<?php
    $page = max(intval($page), 1);
    $offset = $number*($page-1);
	$query = DB::query("$sqlStr LIMIT $offset, $number");
    while($row = DB::fetch($query)) {
        $m_id=$row['m_id'];
?>
    <tr>
		<td><input type="checkbox" value="<?=$m_id?>" name="m_id[]" class="checkbox" /><?=$m_id?></td>
		<td><?=$row['m_name']?></td>
		<td><?php if ($row['m_inbase']) echo "已入库"; else echo "未入库";?></td>
		<td>&nbsp;<?php echo getFromStr($row['m_playdata']);?></td>
		<td><?php if ($row['m_type'] != 0) echo viewDataType($row['m_type']); else echo "<font color=red>没找到相关分类</font>";?></td>
		<td>&nbsp;<?=$row['m_typename']?></td>
		<td><span title="<?=MyDate('Y-m-d H:i:s',$row['m_addtime'])?>"><?=isCurrentDay($row['m_addtime'])?></span></td>
		<td colspan="2" align="center"><a href="?action=editVideo&id=<?=$m_id?>">编辑</a> <a href="?action=delTempData&id=<?=$m_id?>" onClick="return confirm('确定要删除吗')">删除</a></td>
	</tr>
<?php }?>
	<tr>
		<td colspan="9">全选<input type="checkbox" name="chkall" id="chkall" class="checkbox" onclick="checkAll(this.checked,'input','m_id[]')" />反选<input type="checkbox" name="chkothers" id="chkothers" class="checkbox" onclick="checkOthers('input','m_id[]')" />&nbsp;&nbsp;<input type="submit" value="批量删除" onclick="if(confirm('确定要批量删除吗')){return true}else{return false}" class="btn" /><span class=red>没找到相关分类全导入到</span><select name="type" id="type"><option value="">请选择数据分类</option><?php makeTypeOption(0,"&nbsp;|&nbsp;")?></select>&nbsp;<input type="submit" value="导入选中数据" onclick="this.form.action='?action=import';" class="btn" style="width:85px"/>&nbsp;<input type="submit" value="导入全部数据" onclick="this.form.action='?action=import&smode=all';" class="btn" style="width:85px"/>&nbsp;<input type="submit" value="导入未入库" onclick="this.form.action='?action=import&smode=noinbase';" class="btn" style="width:85px"/></td>
	</tr>
	<tr>
	<td colspan="9"><?=fPageCount($allRecordset, $number, $page)?>入库方式：<span class=red><?=$iMode?></span> &nbsp;&nbsp;<a href="?action=delallTempData&do=all" onclick="if(confirm('确定要删除所有吗')){return true;}else{return false;}"><u>清空临时库</u></a></td></tr>
</form>
<?php }?>
</table>
<?php
}

function popDiv() {
?>
<div id="gathervideo" style="top:100px; display:none;" class="popdiv">
<div class="poptitie"><img src="../pic/btn_close.gif" alt="关闭" onClick="$('gathervideo').style.display='none';selectTogg()" />WEB采集助手</div>
	<div class="popbody"><div>
	<table ><tr><td><input name='areaid' id='areaid' type='hidden' value=""><input type="text" name="gatherurl" id="gatherurl" size="60" /> <input type="button" onclick="gather()"   class="btn" value="分   析"/><span id="loading" style="display:none"><img src="imgs/loading2.gif" width="16" height="16"><font color="#FF0000">分析数据中</font></span></td></tr>
	<tr><td><textarea id="gathercontent" cols="72" rows="9"></textarea></td></tr>
	<tr><td><input type="button" onclick="insertResult(1);selectTogg()"   class="btn" value="添  加"/> <input type="button" value="倒 序" style="margin-left:30px;margin-right:10px" onclick="reverseOrder()" class="btn"   />将<input type="text" size="10" id='replace1' />替换成<input type="text" id='replace2' size="10" />&nbsp;
	<input type="button" value="替 换"  onclick="replaceStr()" class="btn" /></td></tr>
	</table>	
	 </div></div>
</div>
<script type="text/javascript" src="imgs/drag.js"></script>
<?php
}

function editVideo() {
	global $menuList;
	$id = intval(getForm("id","get"));
	$makePlayerSelectStr = str_replace("'","\'",makePlayerSelect(""));
	$makeDownSelectStr = str_replace("'","\'",makeDownSelect(""));
	$vrow = DB::fetch_first("SELECT * FROM ".DB::table('tempdata')." WHERE m_id='$id'");
	if (!is_array($vrow)) { die("没找到记录");}
	$m_color = $vrow['m_color'];
	$m_type = $vrow['m_type'];
?>
<div class="container" id="cpcontainer">
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?=$menuList[1][0]?>&nbsp;&raquo;&nbsp;修改数据';</script>
<form action="?action=saveVideo&acttype=edit" method="post" name="editform" id="editform" >
<input type="hidden" id="m_commend" name="m_commend" value="<?=$vrow['m_commend']?>">
<table class="tb">
<tr class="thead"><th colspan="2">修改数据(<font color='red'>＊</font>为必填,其它选填)</th></tr>
	<tr>
		<td align="right" height="22" width="73">名称：</td>
		<td><input id="m_name" name="m_name" size="23" autocomplete="off" value="<?=$vrow['m_name']?>"/>&nbsp;<font color='red'>＊</font><label>连载？<input type="checkbox" onclick="isViewState()" class="checkbox"  id="m_statebox"  <?=$vrow['m_state'] != 0 ? 'checked' : ''?>/></label><span id="m_statespan" <?=$vrow['m_state'] == 0 ? "style=\"display:none\"" : ''?>>到第<input name="m_state" id="m_state" value="<?php echo $vrow['m_state'];?>" type="text" size="5" />集</span>
		<span id="m_name_ok"></span>颜色：
		<select name="m_color" >
		<?php 
		if($m_color)
		{
		?>
         <option style="background-color:<?=$m_color;?>;color: <?=$m_color;?>" value="<?=$m_color;?>"><?=$m_color;?></option>
		<?php 
		}
		else
		{
		?>
		<option style="" value="">无色</option> 
		<?php }?>
		<option style="background-color:#FF0000;color: #FF0000" value="#FF0000">红色</option> 
		<option style="background-color:#FF33CC;color: #FF33CC" value="#FF33CC">粉红</option>  
		<option style="background-color:#00FF00;color: #00FF00" value="#00FF00">绿色</option>
		<option style="background-color:#0000CC;color: #0000CC" value="#0000CC">深蓝</option>
		<option style="background-color:#FFFF00;color: #FFFF00" value="#FFFF00">黄色</option>
		<option style="background-color:#660099;color: #660099" value="#660099">紫色</option>
		<option style="" value="">无色</option> 
		</select>
类 型：<select name="m_type" id="m_type"  ><option value="">请选择数据分类</option>
	<?php makeTypeOptionSelected(0,"&nbsp;|&nbsp;&nbsp;","",$vrow['m_type'])?>
	</select>&nbsp;&nbsp;<font color='red'>＊</font></td>
	</tr>
	<tr> 
		<td height="22" align="right">图片地址：</td>
		<td><input name="m_pic" id="m_pic" type="text" size="40" value="<?=$vrow['m_pic']?>">&nbsp;←<input size="10" value="清除" type="button" onClick="javascript:document.editform.m_pic.value=''" class="btn" />&nbsp;<iframe src="fckeditor/upload.htm" scrolling="no" topmargin="0" width="300" height="24" marginwidth="0" marginheight="0" frameborder="0" align="center"></iframe></td>
  </tr>

    <tr>
	 <td align="right" height="22">主 演：</td>
	 <td><input type="text" size="30" name="m_actor" value="<?=$vrow['m_actor']?>">&nbsp;&nbsp;导&nbsp;&nbsp;&nbsp;演：<input type="text" size="10" name="m_director" value="<?=$vrow['m_director']?>">&nbsp;星级：<span id="star0" style="width:85px;display:inline-block"><script>starView(<?=$vrow['m_commend']?>,0)</script></span>&nbsp;&nbsp;&nbsp;&nbsp;主演、导演用逗号或空格隔开</td>
	</tr>
    
    <tr>
		<td align="right" height="22">备 注：</td>
		<td><input type="text" size="30" name="m_note" value="<?php if (!empty($vrow['m_note'])) echo decodeHtml($vrow['m_note']);?>">&nbsp;&nbsp;关键词：<input type="text" size="30" name="keyword" value="<?=$vrow['m_keyword']?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;备注如：高清,无水印 (配合标题一起显示)</td>
	</tr>
	<tr>
		<td align="right" height="22">发行年份：</td>
		<td><input size="5" name="m_publishyear" id="m_publishyear" value="<?=$vrow['m_publishyear']?>"  />年&nbsp;&nbsp;语言：<input type="text" size="10" name="m_lang" value="<?=$vrow['m_lang']?>">&nbsp;&nbsp;地&nbsp;&nbsp;&nbsp;区：<?php echo getAreaSelect("m_publisharea","选择地区",$vrow["m_publisharea"]);?>&nbsp;&nbsp;专题：<?=makeTopicSelect("m_topic", "选择专题", $vrow["m_topic"])?>  &nbsp;&nbsp;点击率：<input type="text" name="m_hit" id="m_hit" maxlength="9"  value="<?=$vrow['m_hit']?>"/>&nbsp;<input type="checkbox" name="isupdatetime" value="1" checked class="checkbox" />更新时间</td>
	</tr>
	<tr><td colspan="2" style="padding:0" class="noborder"><div style="" id="m_playarea"><?php
	$playArray=getPlayurlArray($vrow['m_playdata']);
	$playTypeCount=count($playArray);$m=0;
	if($vrow['m_playdata'] != "") {
		for ($i = 0;$i < $playTypeCount;$i++) {
			$m=$i+1;
			$playStr=$playArray[$i];
			$playArray2=explode("$$",$playStr) ; $playfrom=$playArray2[0];
			$playUrl=replaceStr($playArray2[1],chr(10),"");
			$playUrl=replaceStr($playUrl,"#",chr(13));
		?>
        <table width='100%' id='playfb<?=$m?>'><tr><td align='right' height='22'  width='70'>播放来源<?=$m?>：</td><td>
		<select id='m_playfrom<?=$m?>' name='m_playfrom[<?=$m?>]'>
		<option value=''>暂没有数据<?=$m?></option>
	   <?=makePlayerSelect($playfrom)?>
		</select>
		<input type='button' class='btn' value='WEB采集' onclick='viewGatherWin(<?=$m?>);selectTogg();'/>&nbsp;&nbsp;<img onclick="var tb=$('playfb<?=$m?>');tb.parentNode.removeChild(tb);" src='imgs/btn_dec.gif' class='pointer' alt="删除播放来源<?=$m?>" align="absmiddle"/>&nbsp;&nbsp;<font color='red'>＊</font>&nbsp;&nbsp;<a href="javascript:moveTableUp($('playfb<?=$m?>'))">上移</a>&nbsp;&nbsp;<a href="javascript:moveTableDown($('playfb<?=$m?>'))">下移</a></td></tr><tr><td align='right' height='22'>数据地址<?=$m?>：<br/><input type='button' value='校正' title='校正右侧文本框中的数据格式' class='btn' onclick='repairUrl(<?=$m?>)' /></td><td><textarea id='m_playurl<?=$m?>' name='m_playurl[<?=$m?>]' rows='8' cols='100'><?=$playUrl;?></textarea>&nbsp;&nbsp;<font color='red'>＊</font></td></tr>
		</table>
		<?php
    }
}
?>
	</div></td></tr>
	<tr><td colspan='2'>&nbsp;<img onclick="expendPlayArea(<?=$m+1?>,escape('<?=$makePlayerSelectStr?>'),0)" src='imgs/btn_add.gif' class='pointer' align="absmiddle"/>&nbsp;&nbsp;<font color="red">您可以单击前面的按钮添加一组播放来源</font></td></tr>
    <tr><td colspan="2" style="padding:0" class="noborder"><div style="" id="m_downarea">
    <?php
	$downArray=getPlayurlArray($vrow['m_downdata']);
	$downTypeCount=count($downArray);$n=0;
	if($vrow['m_downdata'] != "") {
	    for($j = 0;$j < $downTypeCount;$j++){
			$n=$j+1;
			$downStr=$downArray[$j];
			$downArray2=explode("$$", $downStr) ; $downfrom=$downArray2[0];
			$downUrl=replaceStr($downArray2[1],chr(10),"") ; $downUrl=replaceStr($downUrl,"#",chr(13));
		?>
		<table width="100%" id='downfb<?=$n?>'><tr><td align='right' height='22'  width='70'>下载来源<?=$n?>：</td><td>
		<select id='m_downfrom<?=$n?>' name='m_downfrom[<?=$n?>]'>
		<option value=''>暂无数据<?=$n?></option>
        <?=makeDownSelect($downfrom)?>
		</select>
		&nbsp;&nbsp;<img onclick="var tb=$('downfb<?=$n?>');tb.parentNode.removeChild(tb);" src='imgs/btn_dec.gif' class='pointer' alt="删除下载来源<?=$n?>" align="absmiddle"/>&nbsp;&nbsp;
		</td></tr><tr><td align='right' height='22'>下载地址<?=$n?>：</td><td><textarea id='m_downurl<?=$n?>' name='m_downurl[<?=$n;?>]' rows='8' cols='100'><?=$downUrl;?></textarea></td></tr>
		</table>
		<?php
         }
	}
	?>
	</div></td></tr> 
	<tr><td colspan='2'>&nbsp;<img onclick="expendDownArea(<?=$n+1?>,escape('<?=$makeDownSelectStr?>'),0)" src='imgs/btn_add.gif' class='pointer' align="absmiddle"/>&nbsp;&nbsp;<font color="red">您可以单击前面的按钮添加一组下载来源</font></td></tr>
    <tr>
		<td align="right" height="22"></td>
		<td>说明:程序默认每行为一个播放地址，多集请分行，不能有空行</td>
	</tr>
	<tr>
		<td align="right" height="22">相关介绍：</td>
		<td>
  <?php
        GetEditor('m_des', $vrow['m_des']);
	?>
  		</td>
	</tr>

	<tr><input type="hidden" name="m_id" value="<?=$id?>"><input type="hidden" name="m_back" value="<?=getRefer()?>" />
	<td></td><td class="forumRow"><input type="submit" name="submit" class="btn" value="确认保存" onClick="return chform();">&nbsp;<input type=reset name=Submit2 class="btn" value="清 除">&nbsp;<input type=button class="btn" value="返　回" onClick="javascript:history.go(-1);"></td>
  </tr>
</table>
</form>
<script type="text/javascript">
window.commendVideo=function (id,n){
	$('m_commend').value=n;
	starView(n,id);
}
function chform(){
	if($('m_name').value.length==0){
		alert('请填写名称');
		return false;
	};
	if($('m_type').value.length==0){
		alert('请选择分类');
		return false;
	};
	if($('m_publishyear').value.length>0){
		if(isNaN($('m_publishyear').value)){
			alert('年份请填写数字');
			return false;
		}
	}
	var c=document.getElementsByName("m_playfrom"),
	ct=document.getElementsByName("m_playurl"),
	d=document.getElementsByName("m_downfrom"),
	dt=document.getElementsByName("m_downurl");
	for(var i=0;i<c.length;i++){
		if(c[i].selectedIndex==0 && ct[i].value!=''){
			alert('请选择每个播放来源');c[i].focus();
			return false;
		}
	}
	for(var i=0;i<d.length;i++){
		if(d[i].selectedIndex==0 && dt[i].value!=''){
			alert('请选择每个下载来源');d[i].focus();
			return false;
		}
	}
	return true;
}
$('editform').m_name.focus();</script>
</div>
<?php
}

function customercls() {
	global $menuList;
?>
<table class="tb">
	<tr class="thead"><th colspan="4">自定义分类</th></tr>
	<tr>
		<td>ID</td>
		<td>要转换的分类名</td>
		<td>影射到系统分类</td>
		<td>操作</td>
	</tr>

<form action="?action=customersavecls" method="post" name="form1">
<?php
$number=20;
$page=getForm("page","get");$page=ifthen($page<1,1,$page);
$page = max(intval($page), 1);
$offset = $number*($page-1);
$sqlStr="select `id`,`clsname`,`sysclsid` from ".DB::table('cls')."";
$allRecordset = DB::getCount($sqlStr);
if ($allRecordset == 0) {
?>
	<tr>
		<td colspan="4" align="center">没找到自定义分类</td>
	</tr>
<?php
} else {
	$query = DB::query("$sqlStr limit $offset, $number");
    while($row = DB::fetch($query)) {
        $id=$row['id'];
?>
	<tr>
		<td><input type="checkbox" name="id[]" value="<?=$id?>"  class="checkbox" /></td>
		<td><input type="text" name="clsname<?=$id?>" value="<?=$row['clsname']?>" /></td>
		<td><select name="m_type<?php echo $id;?>"><option value="">请选择数据分类</option><?php makeTypeOptionSelected(0,"&nbsp;|&nbsp;","",$row['sysclsid']); ?></select></td>
		<td><a href="?action=customerdelcls&id=<?=$id?>">删除</a></td>
	</tr>
<?php 
    }
}
?>
	<tr>
		<td colspan="4"><label>全选<input type="checkbox" name="chkall" id="chkall" class="checkbox" onclick="checkAll(this.checked,'input','id[]')" /></label><label>反选<input type="checkbox" name="chkothers" id="chkothers" class="checkbox" onclick="checkOthers('input','id[]')" /></label><input type="submit" value="批量删除" onclick="if(confirm('确定要删除吗')){this.form.action='?action=customerdelallcls';}else{return false}" class="btn"/>&nbsp;&nbsp;<input type="submit" value="批量修改选中分类" name="Submit" class="btn" onclick="this.form.action='?action=customersavecls';"/>&nbsp;&nbsp;<?=fPageCount($allRecordset,$number,$page)?></td>
	</tr>
</form>
	<tr class="thead"><th colspan="4"></th></tr>
<form action="?action=customernewcls" method="post" name="form2">
	<tr>
		<td>添加</td>
		<td><input type="text" name="clsname" value="" /></td>
		<td><select name="m_type" id="m_type"><option value="">请选择数据分类</option><?php makeTypeOption(0,"&nbsp;|&nbsp;"); ?></select></td>
		<td><input type="submit" value="确定" name="Submit" class="btn"/></td>
	</tr>
</form>
</table>
<?php
}

function filtersDictionary() {
	global $menuList;
	$page=getForm("page","get");$page = ifthen($page<1,1,$page);
    $number = 30;
    $sqlStr = "select * from ".DB::table('fword')."";
	$allRecordset = db::getCount($sqlStr);
	$tpagecount = ceil($allRecordset / $number);
	if ($page > $tpagecount) $page = $tpagecount;
?>
<table class="tb">
	<tr class="thead"><th colspan="6">过滤字典: <a href="?action=filters">字典列表</a> | <a href="?action=filtersadd">添加过滤</a></th></tr>
	<tr>
		<td>ID</td>
		<td>过滤名称</td>
		<td>过滤字段</td>
		<td>过滤模式</td>
		<td>状态</td>
		<td>操作</td>
	</tr>
<?php if($allRecordset==0){?>
	<tr>
		<td colspan="6" align="center">没找到内容</td>
	</tr>
<?php
}else{
?>
<form action="" method="post" name="form1">
<?php
$page = max(intval($page), 1);
$offset = $number*($page-1);
$query = DB::query("$sqlStr limit $offset, $number");
while($row = DB::fetch($query)) {
$id=$row['m_id'];
?>
	<tr>
		<td><input type="checkbox" value="<?=$id?>" name="m_id[]" class="checkbox"/><?=$id?></td>
		<td><?=$row['m_name']?></td>
		<td><?=ifthen($row['m_rcolumn']==0,"标题替换","剧情替换")?></td>
		<td><?=ifthen($row['m_uesmode']==0,"简单替换","高级替换")?></td>
		<td><?=ifthen($row['m_flag']==1,"√","<font color=red>×</font>")?></td>
		<td><a href="?action=filtersban&id=<?=$id?>"><?=ifthen($row['m_flag']==1,"禁用","启用")?></a> <a href="?action=filtersedit&id=<?=$id?>">编缉</a> <a href="?action=filtersdel&id=<?=$id?>">删除</a></td>
	</tr>
<?php 
}
?>
	<tr>
		<td colspan="6"><label>全选<input type="checkbox" name="chkall" id="chkall" class="checkbox" onclick="checkAll(this.checked,'input','m_id[]')" /></label><label>反选<input type="checkbox" name="chkothers" id="chkothers" class="checkbox" onclick="checkOthers('input','m_id[]')" /></label><input type="submit" value="批量删除" onclick="if(confirm('确定要删除吗')){this.form.action='?action=filtersdelall';}else{return false}" class="btn"/><?=fPageCount($allRecordset, $number, $page)?></td>
	</tr>
</form>
<?php
}
?>
</table>
<?php
}

function EditOrAdd() {
	global $id,$Name,$sFind,$sStart,$sEnd,$sReplace;
	$id = getForm("id","get");
    $rColumn = 0;$uesMode = 0;$Flag = 1;
	if ($id > 0) { 
	    $row = DB::fetch_first("SELECT `m_id`,`m_name`,`m_rcolumn`,`m_uesmode`,`m_sfind`,`m_sstart`,`m_send`,`m_sreplace`,`m_flag` FROM ".DB::table('fword')." WHERE `m_id`=$id");
	    if (is_array($row)) {
		    $id = $row['m_id'];$Name = $row['m_name'];$rColumn = $row['m_rcolumn'];$uesMode = $row['m_uesmode'];
		    $sFind = $row['m_sfind'];$sStart = $row['m_sstart'];$sEnd = $row['m_send'];$sReplace = $row['m_sreplace'];$Flag = $row['m_flag'];
	    }
	}
?>
<table class="tb">
	<tr class="thead"><th colspan="2">过滤字典: <a href="?action=filters">字典列表</a> | <a href="?action=filtersadd">添加过滤</a></th></tr>
	<form action="?action=saveeditoradd" method="post" name="form1">
	<input type="hidden" name="m_id" value="<?=$id?>" />
	<tr>
		<td class="label">过滤器名称</td>
		<td><input type="text" class="txt" name="m_name" value="<?=$Name?>" /></td>
	</tr>
	<tr>
		<td class="label">过滤字段</td>
		<td><select name="m_rcolumn"><option value="0"<?=ifthen($rColumn==1,""," selected")?>>数据名称</option><option value="1"<?=ifthen($rColumn==1," selected","")?>>数据简介</option></select></td>
	</tr>
	<tr>
		<td class="label">过滤模式</td>
		<td><input type="radio" class="radio" name="m_uesmode" value="0" onclick="hide('sStartBody','sEndBody');show('sFindBody');"<?=ifthen($uesMode==1,"","checked")?>/>简单替换 <input type="radio" class="radio" name="m_uesmode" value="1" onclick="hide('sFindBody');show('sStartBody','sEndBody');"<?=ifthen($uesMode==1,"checked","")?>/>高级替换</td>
	</tr>
	<tr id="sFindBody" style="<?=ifthen($uesMode==1,"display:none","")?>">
		<td class="label">查找</td>
		<td><textarea name="m_sfind" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($sFind)?></textarea></td>
	</tr>
	<tr id="sStartBody" style="<?=ifthen($uesMode==1,"","display:none")?>">
		<td class="label">开始标记</td>
		<td><textarea name="m_sstart" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($sStart)?></textarea></td>
	</tr>
	<tr id="sEndBody" style="<?=ifthen($uesMode==1,"","display:none")?>">
		<td class="label">结束标记</td>
		<td><textarea name="m_send" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($sEnd)?></textarea></td>
	</tr>
	<tr>
		<td class="label">替换</td>
		<td><textarea name="m_sreplace" rows="4" cols="80" wrap="off"><?=new_htmlspecialchars($sReplace)?></textarea></td>
	</tr>
	<tr>
		<td class="label">启用</td>
		<td><input type="radio" class="radio" name="m_flag" value="1"<?=ifthen($Flag==1," checked","")?>/>启用 <input type="radio" class="radio" name="m_flag" value="0"<?=ifthen($Flag==1,""," checked")?>/>禁用</td>
	</tr>
	<tr>
		<td colspan=2><input  type="submit" class="btn" name="Submit" value="确&nbsp;&nbsp;定" >&nbsp;&nbsp;&nbsp;&nbsp;<input name="Cancel" class="btn" type="button" id="Cancel" value="取&nbsp;&nbsp;消" onClick="window.location.href='?action=filters'"></td>
	</tr>
	</form>
</table>
<?php
}

function filtersban() {
	$back = getRefer();$id = getForm("id","get");
	if ($id > 0) DB::query("UPDATE ".DB::table('fword')." SET m_flag=(!m_flag) WHERE m_id=$id");
	alertMsg("", $back);
}

function filtersdel() {
	$back = getRefer();$id = getForm("id","get");
	DB::delete('fword', array('m_id' => $id));
	alertMsg("", $back);
}

function filtersdelall() {
	$ids = getForm("m_id","post");
	if (!empty($ids)) DB::delete('fword', 'm_id IN ('.dimplode($ids).')');
	alertMsg("", "?action=filters");
}

function saveeditoradd(){
	$m_id = getForm("m_id","post");
	$m_name=getForm("m_name","post");$m_rcolumn=getForm("m_rcolumn","post");$m_uesmode=getForm("m_uesmode","post");
	$m_sfind=getForm("m_sfind","post");$m_sstart=getForm("m_sstart","post");$m_send=getForm("m_send","post");$m_sreplace=getForm("m_sreplace","post");
	$m_flag=getForm("m_flag","post")==1;
	if (trim($m_name) == "") { alertMsg("请填写过滤器名称","javascript:history.go(-1)");exit;}
	if ($m_uesmode == 0 && strlen($m_sfind) == 0) { alertMsg("请填写查找的字符","javascript:history.go(-1)");exit;}
	if ($m_uesmode == 1 && strlen($m_sstart) == 0) { alertMsg("请填写开始标记","javascript:history.go(-1)");exit;}
	if ($m_uesmode == 1 && strlen($m_send) == 0) { alertMsg("请填写结束标记","javascript:history.go(-1)");exit;}
	if (!empty($m_id)) {
		$fwordarr = array(
		'm_name' => $m_name,
		'm_rcolumn' => $m_rcolumn,
		'm_uesmode' => $m_uesmode,
		'm_sfind' => $m_sfind,
		'm_sstart' => $m_sstart,
		'm_send' => $m_send,
		'm_sreplace' => $m_sreplace,
		'm_flag' => $m_flag,
		);
		DB::update('fword', $fwordarr, array('m_id' => $m_id));
	} else {
		$fwordarr = array(
		'm_name' => $m_name,
		'm_rcolumn' => $m_rcolumn,
		'm_uesmode' => $m_uesmode,
		'm_sfind' => $m_sfind,
		'm_sstart' => $m_sstart,
		'm_send' => $m_send,
		'm_sreplace' => $m_sreplace,
		'm_flag' => $m_flag,
		);
	    DB::insert('fword', $fwordarr);
	}
	alertMsg("", "?action=filters");
}

function customernewcls() {
	$clsname = getForm("clsname","post");$m_type=getForm("m_type","post");
	if (empty($clsname)) { alertMsg("要转换有分类名还没填写","javascript:history.go(-1)");exit;}
	if (!is_numeric($m_type)) { alertMsg("未选择影射到系统分类","javascript:history.go(-1)");exit;}
	$clsarr = array(
	'clsname' => $clsname,
	'sysclsid' => $m_type,
	);
	DB::insert('cls', $clsarr);
	alertMsg("", "?action=customercls");
}

function customersavecls() {
	$ids = getForm("id","post");
	$back = getRefer();
	if (empty($ids)) { alertMsg("",$back);exit;}
	foreach ($ids as $id) {
		$clsname = getForm("clsname".$id,"post");
		if (empty($clsname)){ alertMsg("ID为".$id." 要转换有分类名还没填写","javascript:history.go(-1)");exit;}
		$m_type = getForm("m_type".$id,"post");
		if (!is_numeric($m_type)){ alertMsg("ID为".$id." 未选择影射到系统分类","javascript:history.go(-1)");exit;}
		DB::update('cls', array('clsname' => $clsname,'sysclsid' => $m_type),array('id' => $id));
	}
	alertMsg("", "?action=customercls");
}

function customerdelallcls() {
	$ids = getForm("id","post");$back = getRefer();
	if (!empty($ids)) DB::delete('cls', 'id IN ('.dimplode($ids).')');
	alertMsg("", "?action=customercls");
}

function customerdelcls(){
	$id = getForm("id","get");
	$back = getRefer();
	DB::delete('cls', array('id' => $id));
	alertMsg("", $back);
}

function replaceSpecial($str){
	return replaceStr($str, "'", "".chr(34).chr(34)."");
}

function saveVideo() {
	$actType = getForm("acttype","get");
	$m_id = getForm("m_id","post");if (!is_numeric($m_id)) $m_id = 0;
	$m_name = getForm("m_name","post");
	$m_keyword = replaceStr(replaceStr(getForm("keyword","post"),chr(13),""),chr(10),"");
	$isuppingyin = getForm("isuppingyin","post")=="1";
	$m_enname = getForm("m_enname","post");if (empty($m_enname)) $m_enname = MoviePinYin($m_name);
	$m_hit = getForm("m_hit","post");if (!is_numeric($m_hit)) $m_hit = 0;
	$m_back = getForm("m_back","post");
	$m_color = getForm("m_color","post");
	$m_state = getForm("m_state","post");if (empty($m_state)) $m_state=0;
	$m_type = getForm("m_type","post");if (empty($m_type)){ alertMsg("请选择分类","javascript:history.go(-1);");die("");}
	$m_pic = getForm("m_pic","post");
	$m_actor = getForm("m_actor","post");
	$m_note = replaceSpecial(getForm("m_note","post"));
	$m_des = replaceSpecial(getForm("m_des","post"));
	$m_addtime = getForm("m_addtime","post");
	$m_publishyear = getForm("m_publishyear","post");if (empty($m_publishyear)) $m_publishyear = 0;
	$m_publisharea = getForm("m_publisharea","post");if (empty($m_publisharea)) $m_publisharea = "";
	$m_topic = getForm("m_topic","post");if (empty($m_topic)) $m_topic = 0;
	$m_director = getForm("m_director","post");
	$m_lang = getForm("m_lang","post");
	$m_commend = getForm("m_commend","post");if (is_numeric($m_commend)){ $m_commend = intval($m_commend);}else{;$m_commend = 0;}
	$m_playfrom = getForm("m_playfrom","post");
	$m_playurl = getForm("m_playurl","post");
	if (!empty($m_playurl)){
		$m_playurl = repairUrlForm($m_playurl,$m_playfrom);
    }
	$m_playdata=transferUrl($m_playfrom,$m_playurl);
	$m_downfrom=getForm("m_downfrom","post");
	$m_downurl=getForm("m_downurl","post");
	if (!empty($m_downurl)){
		$m_downurl = repairDownUrl($m_downurl,$m_downfrom);
	}
	$m_downdata=transferUrl($m_downfrom,$m_downurl);
	$isupdatetime=getForm("isupdatetime","post");
	switch (trim($actType)) {
		case "edit":
		    $m_id=getForm("m_id","post");
		    $feedarr = array(
			'm_keyword' => $m_keyword,
			'm_hit' => $m_hit,
			'm_letter' => msubstr($m_enname,1),
			'm_name' => $m_name,
			'm_color' => $m_color,
			'm_state' => $m_state,
			'm_type' => $m_type,
			'm_pic' => $m_pic,
			'm_actor' => $m_actor,
			'm_note' => $m_note,
			'm_des' => $m_des,
			'm_publishyear' => $m_publishyear,
			'm_publisharea' => $m_publisharea,
			'm_topic' => $m_topic,
			'm_playdata' => $m_playdata,
			'm_downdata' => $m_downdata,
			'm_director' => $m_director,
			'm_lang' => $m_lang,
			'm_enname' => $m_enname,
			'm_commend' => $m_commend,
			);
			if (!empty($isupdatetime)){ DB::update('tempdata', array('m_addtime' => time()), array('m_id' => $m_id));}
			DB::update('tempdata', $feedarr, array('m_id' => $m_id));
			alertMsg("", $m_back);
	   break;
   }
}

function delallTempData(){
	$ids = getForm("m_id","post");
	if (getForm("do","get") == "all") {
		DB::delete('tempdata');
	} else {
		DB::delete('tempdata', 'm_id IN ('.dimplode($ids).')');
	}
	alertMsg("", "?action=tempdatabase");
}

function delTempData(){
	$back = getRefer();$id = getForm("id","get");
	DB::delete('tempdata', array('m_id' => $id));
	alertMsg("", $back);
}

function import(){
	global $action;
	$result=trim(getForm("result","both"));$result=ifthen($result<>"",$result,getRefer());$smode=getForm("smode","both");$vtype=getForm("type","post");$rcount=getForm("rcount","both");$pcount=getForm("pcount","both");$m_typename=getForm("typename","both");
	if (!empty($smode)) {
		$number = 250;
		$page=getForm("page","both");$page = ifthen($page < 1,1,$page);
		$idsArray = array();
		$whereStr=" WHERE 1";
		if ($smode<>"all") $whereStr .= " and m_inbase=0";
		if (!empty($m_typename)) $whereStr .= " and m_typename='".$m_typename."'";
		
		$sqlStr = "select m_id from ".DB::table('tempdata')." ".$whereStr."";
		$allRecordset = db::getCount($sqlStr);
		$tpagecount = ceil($allRecordset / $number);
		$page = max(intval($page), 1);
        $offset = $number * ($page - 1);
		$rcount = ifthen($rcount > 0, $rcount, $allRecordset);$pcount = ifthen($pcount > 0, $pcount, $tpagecount);
		$query = DB::query("$sqlStr limit $offset, $number");
        while($row = DB::fetch($query)) {
		      $idsArray[] = $row['m_id'];
		}
		if (count($idsArray) > 0) {
			echo "正在导入数据,当前是第<font color='red'>".$page."</font>页,共<font color='red'>".$pcount."</font>页,共<font color='red'>".$rcount."</font>部数据<hr />";
			import2Base($idsArray, $vtype);
			unset($idsArray);
			echo "<br>暂停3秒后继续导入<script language='javascript'>setTimeout(function (){location.href='?action=".$action."&smode=".$smode."&type=".$vtype."&typename=".urlencode($m_typename)."&page=".($page+1)."&pcount=".$pcount."&rcount=".$rcount."&result=".urlencode($result)."';},3000);</script>";
		} else {
			alertMsg("导入完成", $result);
        }
    } else {
		$ids = getForm("m_id","post");
		if (empty($ids)) {alertMsg("请选择数据",$result);exit();}
		import2Base($ids, $vtype);
		alertMsg("", $result);
   }
}

function import2Base($idsArray, $vtype) {
	if (count($idsArray)>0) {
		$ids = dimplode($idsArray);
		$query = DB::query("SELECT m_id,m_name,m_type,m_state,m_pic,m_actor,m_des,m_playdata,m_publishyear,m_publisharea,m_hit,m_note,m_keyword,m_lang,m_director,m_datetime,m_addtime FROM ".DB::table('tempdata')." WHERE m_id IN (".$ids.") ORDER BY m_addtime ASC");
        while($row = DB::fetch($query)) {
			$m_where = "";$sql = "";$title = $row['m_name'];$titleArray = explode("/",$title);
			$m_type = ifthen($row['m_type']>0, $row['m_type'], $vtype);
			if (!empty($m_type)) {
				foreach ($titleArray as $m_title) {
					if (!empty($m_title)) $m_where .= " or concat('/',m_name,'/') like '%/".$m_title."/%' ";
				}
				$m_where = ltrim($m_where," or");$m_enname=MoviePinYin($title);
				$rs = DB::fetch_first("select m_id,m_playdata,m_state,m_type,m_pic from ".DB::table('data')." where ".$m_where."");
				if (!is_array($rs)) {
					$feedarr = array(
					'm_name' => $row['m_name'],
					'm_type' => $m_type,
					'm_state' => $row['m_state'],
					'm_pic' => $row['m_pic'],
					'm_actor' => $row['m_actor'],
					'm_des' => $row['m_des'],
					'm_playdata' => $row['m_playdata'],
					'm_isunion' => 1,
					'm_publishyear' => $row['m_publishyear'],
					'm_publisharea' => $row['m_publisharea'],
					'm_letter' => msubstr($m_enname,1),
					'm_hit' => $row['m_hit'],
					'm_note' => $row['m_note'],
					'm_keyword' => $row['m_keyword'],
					'm_lang' => $row['m_lang'],
					'm_addtime' => time(),
					'm_director' =>$row['m_director'],
					'm_datetime' => time(),
					'm_enname' => $m_enname,
					);
			        DB::insert('data', $feedarr);
				} else {
					if (gatherSet != 4) {
						$m_type = ($rs['m_type']!=0) ? $rs['m_type'] : $m_type;
						$m_state = ($rs['m_state']>$row['m_state']) ? $rs['m_state'] : $row['m_state'];
						$m_pic = (trim($rs['m_pic'])=='') ? $row['m_pic'] : $rs['m_pic'];
					}
					if (gatherSet == 0 || gatherSet == 1 || gatherSet == 2 || gatherSet == 3) {
						$m_playdata = gatherIntoLibTransfer($rs['m_playdata'],$row['m_playdata'],gatherSet);
						$feedarr = array(
						'm_name' => $row['m_name'],
						'm_type' => $m_type,
						'm_state' => $m_state,
						'm_playdata' => $m_playdata,
						'm_note' => $row['m_note'],
						'm_pic' => $m_pic,
						'm_isunion' => 1,
						'm_addtime' => time(),
						);
						DB::update('data', $feedarr, array('m_id' => $m_id));
					} else if (gatherSet == 4) {
						$feedarr = array(
						'm_name' => $row['m_name'],
						'm_type' => $m_type,
						'm_state' => $row['m_state'],
						'm_pic' => $row['m_pic'],
						'm_actor' => $row['m_actor'],
						'm_des' => $row['m_des'],
						'm_playdata' => $row['m_playdata'],
						'm_isunion' => 1,
						'm_publishyear' => $row['m_publishyear'],
						'm_publisharea' => $row['m_publisharea'],
						'm_letter' => msubstr($m_enname,1),
						'm_hit' => $row['m_hit'],
						'm_note' => $row['m_note'],
						'm_keyword' => $row['m_keyword'],
						'm_lang' => $row['m_lang'],
						'm_addtime' => time(),
						'm_director' =>$row['m_director'],
						'm_enname' => $m_enname,
						);
						DB::insert('data', $feedarr);
					} else if(gatherSet == 5) {
						$feedarr = array(
						'm_pic' => $m_pic,
						'm_actor' => $row['m_actor'],
						'm_des' => $row['m_des'],
						'm_publishyear' => $row['m_publishyear'],
						'm_publisharea' => $row['m_publisharea'],
						'm_note' => $row['m_note'],
						'm_addtime' => time(),
						);
						DB::update('data', $feedarr, array('m_id' => $m_id));
					}
				}
				DB::update('tempdata', array('m_inbase' => true,'m_type' => $m_type), array('m_id' => $row['m_id']));
				echo "<font color=blue>导入成功 ID:".$row['m_id']."	".$row['m_name']."</font><br>";
			} else {
				echo "<font color=red>没选择分类</font> 导入失败 ID:".$row['m_id']."	".$row['m_name']."<br>";
			}
		}
	}
}

function getAreaSelect($selectName, $strSelect, $areaId)
{
	$publishareatxt = DJ_ROOT."inc/publisharea.txt";
	$publisharea = array();
	if (filesize($publishareatxt) > 0) {
		$publisharea = file($publishareatxt);
	}
	$str = "<select name='".$selectName."' >";
	if (!empty($strSelect)) $str .= "<option value=''>".$strSelect."</option>";
	foreach ($publisharea as $area) {
		$area = str_replace("\r\n", "", $area);
		if (!empty($areaId) && ($area == $areaId)) $str .= "<option value='".$area."' selected>$area</option>";
		$str .= "<option value='".$area."'>$area</option>";
	}
	$str .= "</select>";
	return $str;
}

function makePlayerSelect($flag) {
	$playerArray = array();
	$allstr = '';
	$m_file = DJ_ROOT."inc/playerKinds.inc";
	if (filesize($m_file) > 0) {
		$playerArray = file($m_file);
	}
	foreach ($playerArray as $v) {
		$v = trim($v);
		if (!empty($v)) {
		    $vstr = explode("|", $v);
		    if(count($vstr) > 0) {
			    if($flag == $vstr[0]) {
			        $selectstr = " selected";
			    } else {
			        $selectstr = "";
			    }
		        $allstr .= "<option value='$vstr[0]'$selectstr>$vstr[0]--$vstr[1]</option>";
		    }
		}
	}
	return $allstr;
}

function makeDownSelect($flag) {
	$playerArray = array();
	$allstr = '';
	$m_file = DJ_ROOT."inc/downKinds.inc";
	if (filesize($m_file) > 0) {
		$playerArray = file($m_file);
	}
	foreach ($playerArray as $v) {
		$v = trim($v);
		if(!empty($v)) {
		    $vstr = explode("|", $v);
		    if (count($vstr) > 0) {
			    if ($flag == $vstr[0]) {
			        $selectstr = " selected";
			    } else {
			        $selectstr = "";
			    }
		        $allstr .= "<option value='$vstr[0]'$selectstr>$vstr[0]--$vstr[1]</option>";
		    }
		}
	}
	return $allstr;
}

function repairUrlForm($vstr, $formstr) {
	$strlen = count($vstr);
	$formlen  = count($formstr);
	$rstr = '';
	if ($strlen != $formlen) {
		die("未为每个数据选择数据来源");
	} else {
		foreach ($vstr as $k => $v) {
			 if (trim($v) != "") $rstr = $rstr.repairStr($v, getReferedId($formstr[$k])).", "; else $rstr = $rstr.", ";
	    }
	}
	return rtrim($rstr, ", ");
}

function repairStr($vstr, $playfrom) {
	$vstr = str_replace(chr(10), "", $vstr);
	$vstr = explode(chr(13), $vstr);
	$stru = "";
	foreach ($vstr as $j => $playurl) {
	    $strurl = explode('$', $playurl);
	    $i = count($strurl);
	    if ($i == 1) {
	        $jj = $j + 1;
	        $stru = $stru.'第'.$jj.'集$'.$playurl.'$'.$playfrom.chr(13).chr(10);
	    } else if ($i == 2) {
	        $stru = $stru.$playurl.'$'.$playfrom.chr(13).chr(10);
	    } else {
	        $stru = $stru.$playurl.chr(13).chr(10);
	    }
	}
    return $stru;
}

function transferUrl($fromStr, $playStr) {
	if (empty($fromStr) && empty($playStr)) return "";
	$resultStr = "";
	$fromStr = replaceStr($fromStr, "$$", "") ; $playStr = replaceStr(replaceStr($playStr, "#", ""), "$$", "");
	$playStr = replaceStr($playStr, chr(10), "");
	$playStr = replaceStr($playStr, chr(13), "#");
	$playStr = rtrim($playStr, "#");
	$playStr = rtrim($playStr, ",");
	$fromArray = $fromStr ; $fromLen = count($fromArray);
	$playArray = explode(", ", $playStr) ; $playLen = count($playArray);
	if ($fromLen != $playLen) die("来源或者地址没有填写完整");
	if ($fromLen == 0) {
		$transferUrl = trim($fromArray[0])."$$".trim($playArray[0]);return  $transferUrl;
    }
	for ($i = 1;$i <= $fromLen;$i++) {
		$j = $i - 1;
		if (!empty($fromArray[$i]) &&  !empty($playArray[$j])) {
			$resultStr = trim($resultStr).trim($fromArray[$i])."$$".trim(rtrim($playArray[$j], "#"))."$$$";
        } else if (empty($fromArray[$i]) &&  !empty($playArray[$j])) {
			die("来源没有填写完整");
        }
    }
	return rtrim($resultStr, "$$$");
}

function jsIndexOf($Str, $substr) {
    $Pos = strpos(chr(0).$Str,$substr);
    return ifthen($Pos==0,-1,$Pos-1);
}

function ghost() {
	$id = getForm("id","get");
	$row = DB::fetch_first("select * from ".DB::table('collect')." where id=".$id);
	$feedarr = array(
	'itemname' => $row["itemname"]."[复制]",
	'siteurl' => $row["siteurl"],
	'charset' => $row["charset"],
	'playfrom' => $row["playfrom"],
	'enable' => $row["enable"],
	'intoa' => $row["intoa"],
	'autocls' => $row["autocls"],
	'classid' => $row["classid"],
	'isupdate' => $row["isupdate"],
	'getherday' => $row["getherday"],
	'inithit' => $row["inithit"],
	'pageset' => $row["pageset"],
	'pageurl0' => $row["pageurl0"],
	'pageurl1' => $row["pageurl1"],
	'pageurl2' => $row["pageurl2"],
	'istart' => $row["istart"],
	'iend' => $row["iend"],
	'reverse' => $row["reverse"],
	'removecode' => $row["removecode"],
	'listA' => $row["listA"],
	'listB' => $row["listB"],
	'mlinkA' => $row["mlinkA"],
	'mlinkB' => $row["mlinkB"],
	'picmode' => $row["picmode"],
	'mdataA' => $row["mdataA"],
	'mdataB' => $row["mdataB"],
	'nameA' => $row["nameA"],
	'nameB' => $row["nameB"],
	'actorA' => $row["actorA"],
	'actorB' => $row["actorB"],
	'clsA' => $row["clsA"],
	'clsB' => $row["clsB"],
	'dateA' => $row["dateA"],
	'dateB' => $row["dateB"],
	'yearA' => $row["yearA"],
	'yearB' => $row["yearB"],
	'areaA' => $row["areaA"],
	'areaB' => $row["areaB"],
	'stateA' => $row["stateA"],
	'stateB' => $row["stateB"],
	'noteA' => $row["noteA"],
	'noteB' => $row["noteB"],
	'picA' => $row["picA"],
	'picB' => $row["picB"],
	'picvar' => $row["picvar"],
	'desA' => $row["desA"],
	'desB' => $row["desB"],
	'splay' => $row["splay"],
	'plistA' => $row["plistA"],
	'plistB' => $row["plistB"],
	'playgetsrc' => $row["playgetsrc"],
	'playlinkA' => $row["playlinkA"],
	'playlinkB' => $row["playlinkB"],
	'isspecial' => $row["isspecial"],
	'linkRF' => $row["linkRF"],
	'msrcA' => $row["msrcA"],
	'msrcB' => $row["msrcB"],
	'getpart' => $row["getpart"],
	'partA' => $row["partA"],
	'partB' => $row["partB"],
	'CollectTime' => time(),
	);
	DB::insert('collect', $feedarr);
	alertMsg("克隆成功","admin_gather.php?action=main");
}

function removeesfile() {
	$id = getForm("id","get");
	DB::delete('collect', array('id' => $id));
	die("<script>parent.location.reload();</script>");
}

function delAll() {
	$ids = getForm("m_id","post");
	DB::delete('collect', 'id IN ('.dimplode($ids).')');
	alertMsg("","admin_gather.php?action=main");
}

function execesfile() {
	$id = getForm("id","get");$listnum = getForm("listnum");$movienum = getForm("movienum");$sb = getForm("sb");$cg = getForm("cg");$listurl = getForm("listurl");
	$txt = "";$listend = 0;
	if (!$listnum)
	    $listnum = 0;
    if (!$movienum)
	    $movienum = 0;
	if (!$sb && !$cg) {
		DB::update('collect', array('CollectTime' => time()),array('id' => $id));
	    $sb = 0;$cg = 0;
	    session_unset();
	    session_destroy();
    }
    $row = DB::fetch_first("select * from ".DB::table('collect')." where id=$id");
	$itemname = $row["itemname"];
	$siteurl = $row["siteurl"];
	$charset = $row["charset"];
	$playfrom = $row["playfrom"];
	$enable = $row["enable"];
	$intoa = $row["intoa"];
	$autocls = $row["autocls"];
	$classid = $row["classid"];
	$isupdate = $row["isupdate"];
	$getherday = $row["getherday"];
	$inithit = $row["inithit"];
	$pageset = $row["pageset"];
	$pageurl0 = $row["pageurl0"];
	$pageurl1 = $row["pageurl1"];
	$pageurl2 = $row["pageurl2"];
	$istart = $row["istart"];
	$iend = $row["iend"];
	$reverse = $row["reverse"];
	$removecode = $row["removecode"];
	$listA = $row["listA"];
	$listB = $row["listB"];
	$mlinkA = $row["mlinkA"];
	$mlinkB = $row["mlinkB"];
	$picmode = $row["picmode"];
	$mdataA = $row["mdataA"];
	$mdataB = $row["mdataB"];
	$nameA = $row["nameA"];
	$nameB = $row["nameB"];
	$actorA = $row["actorA"];
	$actorB = $row["actorB"];
	$clsA = $row["clsA"];
	$clsB = $row["clsB"];
	$dateA = $row["dateA"];
	$dateB = $row["dateB"];
	$yearA = $row["yearA"];
	$yearB = $row["yearB"];
	$areaA = $row["areaA"];
	$areaB = $row["areaB"];
	$stateA = $row["stateA"];
	$stateB = $row["stateB"];
	$noteA = $row["noteA"];
	$noteB = $row["noteB"];
	$picA = $row["picA"];
	$picB = $row["picB"];
	$picvar = $row["picvar"];
	$desA = $row["desA"];
	$desB = $row["desB"];
	$splay = $row["splay"];
	$plistA = $row["plistA"];
	$plistB = $row["plistB"];
	$playgetsrc = $row["playgetsrc"];
	$playlinkA = $row["playlinkA"];
	$playlinkB = $row["playlinkB"];
	$isspecial = $row["isspecial"];
	$linkRF = $row["linkRF"];
	$msrcA = $row["msrcA"];
	$msrcB = $row["msrcB"];
	$getpart = $row["getpart"];
	$partA = $row["partA"];
	$partB = $row["partB"];
	switch ($pageset){
	    case "0":if($listnum < 1) $listurl=  $pageurl0;else $listend = 1;break;
	    case "1":
	    case "3":
		    if ($pageset == 3) $pageurl1 = $pageurl0;
		    if ($reverse == 1){
			    if (($iend - $listnum) < $istart || (($iend - $listnum) < 0)) {
				    $listend = 1;
			    } else {
				    $listurl = replaceStr($pageurl1, "{id}", ($iend-$listnum));
	            }
			} else {
			    if (($istart + $listnum) > $iend) {
				    $listend = 1;
			    } else {
				    $listurl = replaceStr($pageurl1, "{id}", ($istart + $listnum));
			    }
			}
		break; 
		case 2:
		    $listarray = explode(chr(13),$pageurl2);
            if (($listnum) >= count($listarray)) {
                $listend = 1;
			}else{
               $listurl = str_replace("\n","",$listarray[$listnum]);
			}
	    break; 
    }
    if ($listend == 1) {
        unset($_SESSION[$id.$listnum]);
        session_unset();
        session_destroy();
        $txt.="采集完成";
    } else {
	    $movienumid = $movienum;
	    $listcode = GetHttpTextFile($listurl, $charset);
	    if ($listcode == false) {
		     showerr("在获取:".$listurl."网页源码时发生错误","admin_gather.php");
	    }
	    if ($pageset == 3) {
		    $listnum = $listnum + 1;
		    $newscode = $listcode;
		    $urltest = $listurl;
	    } else {
		    $acad = isset($_SESSION[$id.$listnum]) ? $_SESSION[$id.$listnum] : '';
		    if (!$acad) {
			    //判断数据列表开始代码
		        if (!empty($listA) && !empty($listB)) {
			        $listcode = GetBodyc($listcode, $listA, $listB);
			    }
			    //判断数据列表图片开始代码
			    if ($picmode == 1) {
			        if (!empty($picA) && !empty($picB)) {
			            $moviepic=  GetBodyc($listcode, $picA, $picB);
			        }
		        }
			    //判断数据链接开始代码
		        if (!empty($mlinkA) && !empty($mlinkB)) {
			        $newsarraycode = GetArray($listcode, $mlinkA, $mlinkB);
		        }
			if (count($newsarraycode) == 0) {
				$txt.="<font color=red><b>在获取链接列表时出错</b></font>";
				$sb++;
			}
			$_SESSION[$id.$listnum] = $newsarraycode;
			unset($_SESSION[$id.$listnum-1]);
		}
			$newsarray = $_SESSION[$id.$listnum];
			if (count($newsarray)-$movienum <= 1) {
				$listnum=  $listnum + 1;
				$movienum = 0;
			} else {
				$movienum++;
			}
		$urltest = FixPath($newsarray[$movienumid], $listurl);
		$newscode = GetHttpTextFile($urltest, $charset);
	}
	if ($newscode == false) {
	    $txt.="<font color=red><b>在获取内容页时出错。</b></font>";
	    $sb++;
	} else {
		//判断资料范围开始代码
		if (!empty($mdataA) && !empty($mdataB)) {
			$newscodel = strip_tags(GetBodyc($newscode, $mdataA, $mdataB));
		} else {
			$newscodel = $newscode;
		}
		//判断数据日期开始代码
		if ($getherday) {
		    if (!empty($dateA) && !empty($dateB)) {
		        $date = strip_tags(GetBodyc($newscodel, $dateA, $dateB));
		    }
			if (isLeftDates($date,$getherday)) {
			//$newscodel=$newscode;
		    }else{
			//$newscodel=$newscode;
		    }
		}
		//判断数据名称开始代码
		if (!empty($nameA) && !empty($nameB)) {
		    $m_name = strip_tags(GetBodyc($newscodel, $nameA, $nameB));
		}
		//判断数据演员开始代码
		if (!empty($actorA) && !empty($actorB)) {
		    $m_actor = strip_tags(GetBodyc($newscodel, $actorA, $actorB));
		}
		//判断数据分类开始代码
		if ($autocls == 1) {
			if (!empty($clsA) && !empty($clsB)) {
			    $typename = strip_tags(GetBodyc($newscodel, $clsA, $clsB));
			    $tid = getTidFromCls($typename);
			} else {
				$typename = strip_tags(GetBodyc($newscodel, $clsA, $clsB));
			    $tid = 0;
			}
	    } else {
			$typename = viewDataType($classid);
			$tid = $classid;
		}
		//判断数据地区开始代码
		if (!empty($areaA) && !empty($areaB)) {
		    $m_publisharea=strip_tags(GetBodyc($newscodel, $areaA, $areaB));
		} else {
			$m_publisharea="";
		}
		//判断数据年份开始代码
		if (!empty($yearA) && !empty($yearB)) {
		    $m_publishyear=strip_tags(GetBodyc($newscodel, $yearA, $yearB));
		} else {
			$m_publishyear="";
		}
		//判断数据连载开始代码
		if (!empty($stateA) && !empty($stateB)) {
		    $m_state = strip_tags(GetBodyc($newscodel, $stateA, $stateB));
		} else {
			$m_state = "";
		}
		//判断数据连载开始代码
		if (!empty($noteA) && !empty($noteB)) {
		    $m_note = strip_tags(GetBodyc($newscodel, $noteA, $noteB));
		} else {
			$m_note = "";
		}
		if ($picmode == 0) {
			if (!empty($picA) && !empty($picB)) {
			   $moviepic = FixPath(GetBodyc($newscodel, $picA, $picB), $urltest);
			}
		}
		//判断数据介绍开始代码
		if (!empty($desA) && !empty($desB)) {
		    $content = strip_tags(GetBodyc($newscode, $desA, $desB));
		}
		//判断初始点击数
		if ($inithit == '-1') {
			$m_hit = mt_rand(1,9999);
		} else if ($inithit >= '1') {
			$m_hit = $inithit;
		} else {
			$m_hit = 0;
		}
		//判断数据列表范围
		if ($splay == 1) {
			//判断播放列表开始代码
			if (!empty($plistA) && !empty($plistB)) {
			    $newscode = GetBodyc($newscode, $plistA, $plistB);
			}
			if ($playgetsrc == 1 || $playgetsrc == 2) {
				if (!empty($playlinkA) && !empty($playlinkB)) {
			        $weburl=GetArray($newscode, $playlinkA, $playlinkB);
			    }
			} else{
				if (!empty($msrcA) && !empty($msrcB)) {
			        $weburl=GetArray($newscode, $msrcA, $msrcB);
				}
			}
		} else {
			//判断播放链接开始代码
			if ($playgetsrc == 1 || $playgetsrc == 2) {
				if (!empty($playlinkA) && !empty($playlinkB)) {
			        $weburl=GetArray($newscode, $playlinkA, $playlinkB);
			    }
			} else{
				if (!empty($msrcA) && !empty($msrcB)) {
			        $weburl=GetArray($newscode, $msrcA, $msrcB);
				}
			}
		}
		$m_enname = MoviePinYin($m_name);
		$letter = msubstr($m_enname,1);
		$txt = "来源地址：".$urltest."<br>电影名称：".$m_name."<br>演员：".$m_actor."<br>图片：".$moviepic."<br>栏目：".$typename."<br>地区：".$m_publisharea."<br>介绍：".$content."<br>";
		if ($weburl == false) {
			$txt .= "<font color=red><b>在获取播放列表链接时出错。</b></font>";
			$sb++;
		} else {
		 //判断获取数据地址方式
	        $m_playurl = array();
		    $m_playfrom = array();
		    $movieurl = '';
		    if ($playgetsrc == 1) {
				$WebTest = $weburl[0];
				if ($isspecial == 1) {
					$Keyurl = explode("[变量]",$linkRF);
					$urli = GetBodyc($webArray,$Keyurl[0],$Keyurl[1]);
					if ($urli)
						$WebTest = str_replace("[变量]",$urli,$linkRF);
					else
						break 2;
				}
				$WebTest = FixPath($WebTest,$urltest);
				$webCode = GetHttpTextFile($WebTest,$charset);
				$movieurla = GetBodyc($webCode,$msrcA,$msrcB);
				$part = GetBodyc($movieurla,$partA,$partB);
				$movieurl = $movieurla."\r";
				$txt .= "播放列表：".$WebTest."<br>影片地址：".$movieurla."<br>";
		    } else if ($playgetsrc == 2) {
			    foreach ($weburl as $webArray) {
				    $WebTest = $webArray;
				    if ($isspecial == 1) {
					    $Keyurl = explode("[变量]",$linkRF);
					    $urli = GetBodyc($webArray,$Keyurl[0],$Keyurl[1]);
					    if ($urli)
						    $WebTest = str_replace("[变量]",$urli,$linkRF);
					    else
						    break 2;
					}
				    $WebTest = FixPath($WebTest,$urltest);
				    $webCode = GetHttpTextFile($WebTest,$charset);
				    $movieurla = GetBodyc($webCode,$msrcA,$msrcB);
				    $txt .= "播放列表：".$WebTest."<br>影片地址：".$movieurla."<br>";
				    $part = GetBodyc($movieurla,$partA,$partB);
				    $movieurl .= $movieurla."\r";
			    }
			} else{
			     foreach ($weburl as $webArray) {
				    $WebTest = $webArray;
				    $txt .= "影片地址：".$WebTest."<br>";
				    $part = GetBodyc($WebTest,$partA,$partB);
				    $movieurl .= $WebTest."\r";
			    }
		    }
			if (!empty($m_name)) {
			    $m_name = fword($m_name, 0);
			}
			if (!empty($content)) {
			    $content = fword($content, 1);
			}
			$m_playurl[1] = addslashes(rtrim($movieurl,"\r"));
			$m_playfrom[1] = replaceStr(replaceStr(filterQuote($playfrom),"#",""),"$","");
			if (!empty($m_playurl)) {
		         $m_playurl = repairUrlForm($m_playurl, $m_playfrom);
	        }
	        $m_playurl = transferUrl($m_playfrom, $m_playurl);
			//判断入库方式
			if ($intoa == 1 && $tid != 0) {
				$sburl = 0;$cg++;
                $tablename = DB::table('data');
			    $whereStr = " where m_name like '%$m_name%'";
			} else {
                $intoa = 0;
                $tablename = DB::table('tempdata');
			    $whereStr = " where ".ifthen(!empty($urltest),"m_from='$urltest' or ","")." m_name like '%$m_name%'";
			}
			$r = DB::fetch_first("select m_id,m_playdata,m_state,m_type,m_pic from $tablename$whereStr");
			if (!is_array($r)) {
				//die('gggggg'.$tablename);
				DB::query("insert into $tablename(m_name,m_type,m_state,m_pic,m_actor,m_des,m_playdata,m_isunion,m_publishyear,m_publisharea,m_note,m_letter,m_addtime,m_enname,m_datetime".ifthen($intoa==0,",m_typename","").") values('$m_name','$tid','$m_state','$moviepic','$m_actor','$content','$m_playurl',1,'$m_publishyear','m_publisharea','$m_note','$letter','".time()."','$m_enname','".time()."'".ifthen($intoa==0,",'$typename'","").")");
				$cg++;
			} else {
				$sb++;
				$k = 1;
				$addset = "";
				if (gatherSet != 4) {
				    if (!empty($m_state)) {
					    $addset .= ",m_state=".ifthen($m_state > $r['m_state'], $m_state, $r['m_state']);
			        }
				    if (!empty($m_note)){
                        $addset .= ",m_note='$m_note'";
			        }
				    if ($intoa == 0) {
                        $addset .= ",m_inbase=0";
			        }
					$type = ifthen($r['m_type']<>0, $r['m_type'], $tid);
				    if (!empty($moviepic)) {
                        $addset .= ",m_pic='$moviepic'";
			        }
				}
				switch (gatherSet) {
				    case 0 :case 1 :case 2 :case 3 :
					    $m_playdata = gatherIntoLibTransfer($r['m_playdata'],$m_playurl,gatherSet);
                        $sql = "update $tablename set m_name='$m_name',m_type=".$r['m_type'].",m_playdata='$m_playdata'".ifthen($isupdate!=1,",m_addtime='".time()."'","").$addset." where m_id=".$r['m_id'];
						break;
                    case 4 :
					    $sql = "insert into $tablename(m_name,m_type,m_state,m_pic,m_actor,m_des,m_playdata,m_isunion,m_publishyear,m_publisharea,m_note,m_letter,m_addtime,m_letter,m_enname,m_datetime".ifthen($intoa==0,",m_typename","").") values('".$m_name."','".$tid."','".$m_state."','".$moviepic."','".$m_actor."','".addslashes($content)."','".$m_playurl."',1,'".$m_publishyear."','".$m_publisharea."','".$m_note."','".$letter."','".time()."','".msubstr($m_enname,1)."','$m_enname','".time()."'".ifthen($intoa==0,",'$typename'","").")";
						break;
                    case 5 :
					    $sql = "update $tablename set m_actor='$m_actor',m_type='$type',m_hit='$m_hit',m_state='$m_state',m_des='".addslashes($content)."',m_publishyear='$m_publishyear',m_publisharea='$m_publisharea',m_addtime='".time()."'$addset where m_id=".$r['m_id'];
						break;
			    }
			    switch (gatherSet) {
	                case "0":$iMode="智能覆盖";break;
	                case "1":$iMode="地址头部追加";break;
	                case "2":$iMode="地址尾部追加";break;
	                case "3":$iMode="覆盖地址";break;
	                case "4":$iMode="新增数据";break;
	                case "5":$iMode="仅更新地址以外的信息";break;
                }
			    $txt .= "<font color=red><b>采集过该数据,进行'".$iMode."'！。</b></font>";
			    db::query($sql);
			}
		}
	}
	echo "<meta http-equiv=\"refresh\" content=\"0;url=admin_gather.php?action=exec&id=".$id."&listnum=".$listnum."&movienum=".$movienum."&sb=".$sb."&cg=".$cg."\">";
}
?>
	<table class="tb">
	<thead>
		<tr class="thead"><th>正在执行:<?=$itemname?>&nbsp;</span>重新修改请点这 <a href="?action=edit&id=<?=$id?>">编辑</a> <a href="?action=main">返回项目列表</a></th></tr>
	</thead>
</table>
</table>
<hr style="border:1px solid #DEEFFA" />
<table>
<tr>
<td width=224>项目: <font color='red'><?=$itemname?></font></td>
<td>地址: <a href="javascript:void(0);" onclick="window.open('<?=$listurl?>','_blank');"><font color='red'><?=$listurl?></font></a></td>
</tr>
</table>
<table>
<td width=120>采集统计：</td>
<td width=100>成功采集 <font color=red><?=$cg;?></font></td>
<td width=120><?php switch (gatherSet) {
	                    case "0":echo "智能覆盖";break;
	                    case "1":echo "地址头部追加";break;
	                    case "2":echo "地址尾部追加";break;
	                    case "3":echo "覆盖地址";break;
	                    case "4":echo "新增数据";break;
	                    case "5":echo "仅更新地址以外的信息";break;
                    };?> <font color=red><?=$sb?></font></td>
</tr>
</table>
<hr style="border:1px solid #DEEFFA" /><pre><?=$txt?>
</pre></div>
<?php
}

function GetHttpTextFile($httpurl, $cset) {
	if (strlen($httpurl) < 18 || !$httpurl)
		return false;
	$httpcontent=getRemoteContent($httpurl);
	if ($httpcontent)
		if ($cset != "GB2312")
		    return iconv($cset,"gbk",$httpcontent);
		else
		    return $httpcontent;
	else
		return false;
}

function GetBodyc($string, $start, $end) {
	$start = stripcslashes($start);
	$end = stripcslashes($end);
	$message = @explode($start,$string);
	$message = @explode($end,$message[1]);
	if (count($message) > 1) {
		return $message[0];
	} else {
		return false;
	}
}

function GetArray($content, $start, $end) {
	$start = stripcslashes($start);
	$end = stripcslashes($end);
	$m = @explode($start,$content); 
	$a = array(); 
	$sum = count($m); 
	for ( $i = 1;$i < $sum;$i++ ) { 
		$my = @explode($end,$m[$i]); 
		$a[] = $my[0];
		unset($my); 
	} 
	return $a; 
}

function FixPath($aim, $baseUrl) { 
    $strSource = $baseUrl; 
    if (preg_match_all('/([^:\\/]+)\//', $strSource, $aryResult1, PREG_PATTERN_ORDER)) { 
        $intUrlLevel= count($aryResult1[0]); 
    } else { 
        $intUrlLevel = 0; 
        preg_match_all('/http:\/\/(.+?)$/', $strSource, $aryResult1, PREG_PATTERN_ORDER); 
        $aryResult1[0][0] = $aryResult1[1][0] . "/"; 
    }
    $strSource = $aim; 
    if (substr($strSource,0,7) == 'http://') { 
        return $aim; 
    } else {
	    if (preg_match_all("/^\//",$strSource, $aryResult2, PREG_PATTERN_ORDER)){ 
		    $strAimUrl = "http://" . $aryResult1[1][0] . str_replace("../","",$aim); 
		} else { 
			preg_match_all('/(\\.\\.\/)/', $strSource, $aryResult2, PREG_PATTERN_ORDER); 
			$intAimUrlLevel= count($aryResult2[0]); 
			if ($intUrlLevel<=$intAimUrlLevel){ 
		        $strAimUrl = "http://" . $aryResult1[0][0] . str_replace("../","",$aim); 
			} else { 
				$strAimUrl = "http://" . implode("",array_slice ($aryResult1[0], 0, $intUrlLevel - $intAimUrlLevel)) . str_replace("../","",$aim); 
			} 
		} 
	    return $strAimUrl; 
	}
}

function isLeftDates($pdate, $getherday) {
	if (empty($pdate)) return false;
	$date2 = time();
	$dt_regtime = explode(" ",$pdate);
	$dateArr = explode("-",$dt_regtime[0]);
	$date1Int = mktime(0,0,0,$dateArr[1],$dateArr[2],$dateArr[0]);
	$daysleft = floor(($date1Int-$date2) / 86400);
	if ($getherday >= $daysleft) return true; else return false;
}

function getTidFromCls($name){
	$trow = DB::fetch_first("SELECT sysclsid FROM ".DB::table('cls')." WHERE clsname='$name'");
	if (is_array($trow)) return $trow['sysclsid'];
	else return 0;
}

function fword($Str, $rCol) {
	if (empty($Str)) return $Str;
	$sqlStr = "select `m_rcolumn`,`m_uesmode`,`m_sfind`,`m_sreplace`,`m_sstart`,`m_send` from ".DB::table('fword')." where `m_flag`=1";
	$query = DB::query($sqlStr);
    while($row = DB::fetch($query)) {
		if ($row["m_rcolumn"] == $rCol) {
            if ($row["m_uesmode"] == 1){
	            if ($row["m_sstart"].$row["m_send"] != "") {
					$labelRule = $row["m_sstart"]."(.*?)".$row["m_send"];
					preg_match_all(buildregx($labelRule, "is"), $Str, $ar);
					$Str=replaceStr($Str,$ar[1],$row["m_sreplace"]);
	            }
	        } else {
	            if ($row["m_sfind"] != "") {
	                $Str=replaceStr($Str,$row["m_sfind"],$row["m_sreplace"]);
	            }
	        }
	    }
	}
	return $Str;
}

function filterQuote($Str) {
   return replaceStr("".$Str,"'","");
}

function viewDataType($str){
	$viewDataType=explode(",", getTypeNameTemplateArrayOnCache(intval($str)));
	if(empty($viewDataType[0])) $viewDataType[0]="<font color=red >数据分类错误</font>";
	return $viewDataType[0];
}
?>
