<?php
require_once(dirname(__FILE__)."/admin_inc.php");
ob_implicit_flush(true);
@set_time_limit(0);
/*******************************************************************************************
' Software name: DJCMS Content Management System
' Version:3.0
' Web: http://www.djcms.net
' Author: 心情(qq:1130731)
' Copyright (C) 2009-2010 DJCMS官方 版权所有
' 法律申明：DJCMS程序所有代码100%原创、未引入任何网上代码,对一切抄袭行为、坚决严肃追究法律责任
'*******************************************************************************************/
viewHead("采集管理"."-" .$menuList[1][0]);
$gatherWaitTime=3;		//采集每页数据间隔时间
$backurl=getForm("backurl","get");
$ac=getForm("ac","both");$h=getForm("h","both");$wd=getForm("wd","both");$rid=getForm("rid","both");$t=getForm("t","both");$pg=getForm("pg","both");

if (!is_numeric($pg)){
	$pg=1;
}else{
	$pg=intval($pg);
}

if (!is_numeric($t)){
	$t=0;
}else{
	$t=intval($t);
}
$res = array(
	'1' => "http://www.qvodzy.com.cn/api/max.asp",
	'2' => "http://www.hacow.me/xml/maxresxml.asp", 
	'3' => "http://www.kuaizy.com/xml/max.asp",
	'4' => "http://www.439p.com/api/maxresxml.asp",
	'5' => "http://www.gvodfk.com/max/maxresxml.asp", 
	'6' => "http://www.369ys.org/ls/maxresxml.asp", 
	'7' => "http://www.baduzy.com/xml/caiji.asp",
);
$resl = array(
	'1' => "【QVOD】<font color=\"#FF0000\">qvodzy.me在站长中使用非常广泛、稳定、快速、更新及时---推荐 </font>",
	'2' => "【QVOD】<font color=\"#0000FF\">hacow.me无弹窗、速度快、更新多</font>", 
	'3' => "【QVOD】<font color=\"#0000FF\">kuaizy.com无弹窗、速度快、更新多</font>",
	'4' => "【GVOD】<font color=\"#FF0000\">gvodzi.com更新较为及时,有良性广告,gvodzi站长每日更新---推荐 </font>",
	'5' => "【GVOD】<font color=\"#0000FF\">FK字幕组每日手动更新 ,数量多 </font>", 
	'6' => "【GVOD】<font color=\"#0000FF\">369ys.org原创首发最新热门</font>", 
	'7' => "【BDHD】<font color=\"#00FF00\">八度影音(百度影音）影视资源站、无弹窗、质量高、更新快 www.qqcop.com </font>",
);
Headera();
switch ($ac) {
	case "list":getlist();break;
	case "bind":bindType();break;
	case "bindsubmit":bindSubmit();break;
	case "select":gather();break;
	case "type":gatherType();break;
	case "day":gatherDay();break;
	case "all":gatherALl();break;
	default : main();break;
}
Footer();
function unescapseCode($str)
{
	if(empty($str)) return ""; else return urldecode(UnicodeUrl2Gbk($str));
}
function intoDatabase($url,$gtype){
	global $ac,$res,$rid,$t,$h,$pg,$wd,$backurl;
	$pagecount=0;$page=$pg;
	echo "<div style='font-size:13px'><font color=red>视频采集开始：</font>".$url."<br>";
	$xml=utf82gb(file_get_contents($url));
	if ($gtype == "type" || $gtype == "day"){
		$pagecount = StrSlice($xml,'pagecount="','"');
	}
	if (!is_numeric($pagecount)) $pagecount=1; else $pagecount=intval($pagecount);
	$nodes=getrulevaluearr($xml,'video');
	foreach ($nodes as $v) {
	    $m_where="";$vid="";
		$vidas=getrulevaluearr($v,'dl');
		foreach ($vidas as $y) {
		    $flag = StrSlice($y,'<dd flag="','">');
		    $vods = StrSlice($y,'<dd flag="'.$flag.'"><![CDATA[',']]></dd>');
		    if ($vid=="") {
				$vid = $flag."$$".$vods;
			} else {
			    $vid .= "$$$".$flag."$$".$vods;
		    }
		}
		$vtype = StrSlice($v,'<tid>','</tid>');
		$libid = $rid."_".$vtype;
		$title = new_addslashes(StrSlice($v,'<name><![CDATA[',']]></name>'));
		if (computeStrLen($title)>115) $title=getStrByLen($title,115);
		$pic = StrSlice($v,'<pic>','</pic>');
		$des = new_addslashes(StrSlice($v,'<des><![CDATA[',']]></des>'));
		$m_lang = new_addslashes(StrSlice($v,'<lang>','</lang>'));
		if (computeStrLen($m_lang)>30) $m_lang=getStrByLen($m_lang,30);
		$publisharea = new_addslashes(StrSlice($v,'<area>','</area>'));
		if (computeStrLen($publisharea)>30) $publisharea=getStrByLen($publisharea,30);
		$publishyear = StrSlice($v,'<year>','</year>');
		$states = StrSlice($v,'<state>','</state>');
		$m_note = new_addslashes(StrSlice($v,'<note><![CDATA[',']]></note>'));
		$actor = new_addslashes(StrSlice($v,'<actor><![CDATA[',']]></actor>'));
		if (computeStrLen($actor)>250) $actor=getStrByLen($actor,250);
		$director = StrSlice($v,'<director><![CDATA[',']]></director>');
		if (computeStrLen($director)>40) $director=getStrByLen($director,40);
		$publishyear = empty($publishyear) ? date('Y') : intval($publishyear);
		$states = empty($states) ? 0 : intval($states);
		$localId = getBindedLocalId($libid);$m_enname=MoviePinYin($title);
		if (!empty($title)) {
			$title = str_replace("]","】",str_replace("[","【",$title));
			if (is_numeric($localId)) {
				$titleArray = explode("/", $title);
				foreach ($titleArray as $v_title) {
					if (!empty($v_title)) $m_where .= " or concat('/',m_name,'/') like '%/".$v_title."/%' ";
				}
				$m_where = ltrim($m_where," or");
				$rs = DB::fetch_first("SELECT m_id,m_playdata FROM ".DB::table('data')." WHERE ".$m_where." order by m_id desc");
				if (!is_array($rs)) {
					$feedarr = array(
					    'm_name' => $title,
						'm_type' => $localId,
						'm_state' => $state,
						'm_pic' => $pic,
						'm_actor' => $actor,
						'm_des' => $des,
						'm_playdata' => $vid,
						'm_isunion' => 1,
						'm_publishyear' => $publishyear,
						'm_publisharea' => $publisharea,
						'm_note' => $m_note,
						'm_letter' => msubstr($m_enname,1),
						'm_enname' => $m_enname,
						'm_director' => $director,
						'm_lang' => $m_lang,
						'm_addtime' => time(),
					);
					DB::insert('data', $feedarr);
				}else{
					switch (gatherSet) {
						case 0 :case 1 :case 2 :case 3 :
							$m_playdata = gatherIntoLibTransfer($rs['m_playdata'],$vid,gatherSet);
							$feedarr = array(
								'm_state' => $state,
								'm_lang' => $m_lang,
								'm_playdata' => $m_playdata,
								'm_isunion' => 1,
								'm_addtime' => time(),
							);
							ifthen(isSpecial($vtype),$feedarr['m_note'] = $m_note,"");
							DB::update('data', $feedarr, array('m_id' => $rs['m_id']));
						break;
						case 4:
						    $feedarr = array(
							    'm_name' => $title,
								'm_type' => $localId,
								'm_state' => $state,
								'm_pic' => $pic,
								'm_actor' => $actor,
								'm_des' => $des,
								'm_playdata' => $vid,
								'm_isunion' => 1,
								'm_publishyear' => $publishyear,
								'm_publisharea' => $publisharea,
								'm_note' => $m_note,
								'm_letter' => msubstr($m_enname,1),
								'm_enname' => $m_enname,
								'm_director' => $director,
								'm_lang' => $m_lang,
								'm_addtime' => time(),
							);
							DB::insert('data', $feedarr);
						break;
						case 5:
						    $feedarr = array(
								'm_actor' => $actor,
								'm_director' => $director,
								'm_lang' => $m_lang,
								'm_pic' => $pic,
								'm_des' => $des,
								'm_publishyear' => $publishyear,
								'm_publisharea' => $publisharea,
								'm_addtime' => time(),
							);
							ifthen(isSpecial($vtype),$feedarr['m_note'] = $m_note,"");
							DB::update('data', $feedarr, array('m_id' => $rs['m_id']));
						break;
					}
				}
				//echo "OK<br>";
			} else {
				$libid=000000;
				$titleArray = explode("/", $title);
				foreach ($titleArray as $v_title) {
					if (!empty($v_title)) $m_where .= " or concat('/',m_name,'/') like '%/".$v_title."/%' ";
				}
				$m_where = ltrim($m_where," or");
				$rs = DB::fetch_first("SELECT m_id,m_playdata FROM ".DB::table('temp')." WHERE ".$m_where." order by m_id desc");
				if (!is_array($rs)) {
					$feedarr = array(
					    'm_name' => $title,
						'm_type' => $localId,
						'm_state' => $state,
						'm_pic' => $pic,
						'm_actor' => $actor,
						'm_des' => $des,
						'm_playdata' => $vid,
						'm_publishyear' => $publishyear,
						'm_publisharea' => $publisharea,
						'm_director' => $director,
						'm_lang' => $m_lang,
						'm_addtime' => time(),
					);
					DB::insert('temp', $feedarr);
				} else {
					switch (gatherSet) {
						case 0 :case 1 :case 2 :case 3 :
						    $m_playdata = gatherIntoLibTransfer($rs['m_playdata'],$vid,gatherSet);
							$feedarr = array(
							    'm_name' => $title,
								'm_state' => $state,
								'm_lang' => $m_lang,
								'm_playdata' => $m_playdata,
								'm_addtime' => time(),
							);
							DB::update('temp', $darr, array('m_id' => $rs['m_id']));
						break;
						case 4:
							$feedarr = array(
							    'm_name' => $title,
								'm_type' => $localId,
								'm_state' => $state,
								'm_pic' => $pic,
								'm_actor' => $actor,
								'm_des' => $des,
								'm_playdata' => $vid,
								'm_publishyear' => $publishyear,
								'm_publisharea' => $publisharea,
								'm_director' => $director,
								'm_lang' => $m_lang,
								'm_addtime' => time(),
							);
							DB::insert('temp', $feedarr);
						break;
						case 5:
							$feedarr = array(
								'm_actor' => $actor,
								'm_director' => $director,
								'm_lang' => $m_lang,
								'm_pic' => $pic,
								'm_des' => $des,
								'm_publishyear' => $publishyear,
								'm_publisharea' => $publisharea,
								'm_addtime' => time(),
							);
							DB::update('temp', $feedarr, array('m_id' => $rs['m_id']));
						break;
					}
				}
			}
		}
		echo "数据<font color=red>".$title."</font>已经采集成功<br>";
	}
	if ($page < $pagecount) {
		$page=$page+1;$backurl=urlencode($backurl);
		echo "<br/>暂停2秒--<font color=red>即将开始同步第".$page."/".$pagecount."页</font><br/></div>";
		if ($gtype == "day") {
			echo "<script language=\"javascript\">setTimeout(\"makeNextPage();\",2000);function makeNextPage(){location.href='?ac=".$ac."&rid=".$rid."&pg=".$page."&h=24&backurl=".$backurl."';}</script>";
		} else if ($gtype == "type") {
			echo "<script language=\"javascript\">setTimeout(\"makeNextPage();\",2000);function makeNextPage(){location.href='?ac=".$ac."&rid=".$rid."&pg=".$page."&t=".$t."&backurl=".$backurl."';}</script>";
		}
	} else {
		if ($gtype == "select") {
			die("<script>alert('恭喜，全部搞定');history.go(-1);</script>");
		} else {
			die("<script>alert('恭喜，全部搞定');location.href='".$backurl."'</script>");
		}
	}
}

function makePageNumbera($curPage,$pageline,$maxpage){
	global $ac,$res,$rid,$t,$h,$pg,$wd;
	$ret = "";
	$curPage=intval($curPage);
	$j = (($pageline % 2) == 0) ? ($pageline / 2) : (ceil($pageline / 2) - 1);
	if  ($curPage < 1){  
	    $curPage=1; 
	} else if ($curPage > $maxpage) { 
		$curPage=$maxpage;
	}
	if ($pageline > $maxpage) $pageline = $maxpage;
	if ($curPage - $j < 1) {
		$iStart = 1;$iEnd = $pageline;
	} else if ($curPage - $j + $pageline > $maxpage) {
		$iStart=$maxpage - $pageline + 1;$iEnd=$maxpage;
	} else {
		$iStart=$curPage - $j;$iEnd=$curPage - $j + $pageline - 1;
	}
	for ($i = $iStart;$i <= $iEnd;$i++) {
		if (intval($i) == intval($curPage)){
			$ret .= "<span><font color=red>".$i."</font></span>";
		} else {
			$ret .= "<a href='?ac=".$ac."&rid=".$rid."&t=".$t."&h=".$h."&wd=".$wd."&pg=".$i."'>".$i."</a>";
		}
	}
	return $ret;
}

function getlist(){
	global $ac,$res,$rid,$t,$h,$pg,$wd,$resl;
	$url=$res[$rid]."?ac=list&t=".$t."&h=".$h."&pg=".$pg."&wd=".urlencode(gb2utf8($wd));
	$xml=utf82gb(getRemoteContent($url));
    $page = StrSlice($xml,'page="','"');
	$pagecount = StrSlice($xml,'pagecount="','"');
	$pagesize = StrSlice($xml,'pagesize="','"');
	$recordcount = StrSlice($xml,'recordcount="','"');
	$recordcount = StrSlice($xml,'recordcount="','"');
	$pagestr = "<div class=\"cuspages\" style=\"margin:0\"><div class=\"pages\" style=\"margin:0\">共 ".$recordcount." 条数据 每页 ".$pagesize." 条 当前 ".$page."/".$pagecount." 页码";
	$pagestr .= "<a href=\"?ac=".$ac."&rid=".$rid."&t=".$t."&h=".$h."&wd=".urlencode($wd)."&pg=1\">首页</a> <a href=\"?ac=".$ac."&rid=".$rid."&t=".$t."&h=".$h."&wd=".urlencode($wd)."&pg=".($page-1)."\">上一页</a>";
	$pagestr .= makePageNumbera($page,10,$pagecount);
	$pagestr .= "<a href=\"?ac=".$ac."&rid=".$rid."&t=".$t."&h=".$h."&wd=".urlencode($wd)."&pg=".($page+1)."\">下一页</a> <a href=\"?ac=".$ac."&rid=".$rid."&t=".$t."&h=".$h."&wd=".urlencode($wd)."&pg=".$pagecount."\">尾页</a>";
	$pagestr .= "&nbsp;&nbsp;跳转<input type=\"text\" id=\"skip\" value=\"\" onkeyup=\"this.value=this.value.replace(/[^\d]+/,'')\" style=\"width:40px\"/>&nbsp;&nbsp;<input type=\"button\" value=\"确定\" class=\"btn\" onclick=\"location.href='?ac=".$ac."&rid=".$rid."&t=".$t."&h=".$h."&wd=".urlencode($wd)."&pg='+$('skip').value;\"/></div></div>";
?>
<table class="tb">
<thead>
	<tr class="thead"><th colspan="4">&nbsp;<a href="?">采集平台</a>&nbsp;&raquo;&nbsp;<a href="?ac=list&rid=<?=$rid?>"><?=$resl[$rid]?></a></th></tr>
	<tr><th colspan="4">
	<ul class="ul">
	<?php
		echo "<li><a href=\"?ac=list&rid=".$rid."\">全部</a></li>";
		$typenodes = getruleval($xml,'ty');
		foreach($typenodes as $v){
			$typeid = StrSlice($v,'id="','"');
			$typename = StrSlice($v,'">','"');
			$z = $rid."_".$typeid;
			$y = getBindedLocalId($z);if (!is_numeric($y)) $y=0;
			if ($y == 0){
				$x = "<font color=blue>[<b>未绑定</b>]</font>";
		    }else{
				$x = "<font color=red>[<b>已绑定</b>]</font>";
		    }
			echo "<li><a href=\"?ac=list&rid=".$rid."&t=".$typeid."\">".$typename."</a>&nbsp;&nbsp;<a href=\"?ac=bind&curid=".$z."&class=".$y."&tname=".urlencode($typename)."\">" .$x."</a></li>";
		}
	?>
	</ul>
	</th></tr>
	<tr><th colspan="4">
	<?=$pagestr?>
	</th></tr>
	<form action="?" method="get">
	<input type="hidden" name="ac" value="<?=$ac?>">
	<input type="hidden" name="rid" value="<?=$rid?>">
	<input type="hidden" name="t" value="<?=$t?>">
	<input type="hidden" name="h" value="<?=$h?>">
	<tr><th colspan="4">
	&nbsp;<input type="button" class="btn" style="width:65px" onClick="checkOthers('input','ids[]')" value="全选反选" />
	&nbsp;<input type="button" class="btn" style="width:45px" onClick="$('choose').submit()" value="采集"/>
	&nbsp;<input type="button" class="btn" style="width:65px" onClick="location.href='?ac=day&rid=<?=$rid?>&t=<?=$t?>&h=24&backurl='+encodeURIComponent(location.href);" value="采集当天"/>
	&nbsp;<input type="button" class="btn" style="width:103px"onclick="location.href='?ac=type&rid=<?=$rid?>&t=<?=$t?>&backurl='+encodeURIComponent(location.href);" value="一键采集该分类"<?if ($t<1) echo "disabled";?>/>
	&nbsp;<input type="button" class="btn" style="width:65px" onClick="location.reload()" value="刷新网页"/>
	&nbsp;&nbsp;查询：<input type="text" name="wd" value="<?=$wd?>" style="width:100px">
	&nbsp;<input type="submit" class="btn" name="submit" value="搜 索" />
	&nbsp;<select onChange="self.location.href='?ac=list&rid=<?=$rid?>&t='+this.options[this.selectedIndex].value+'&h=<?=$h?>&pg=&wd='">
	<option value="">按分类查看</option>
	<?php
	    foreach($typenodes as $typenode){
			$typeid = StrSlice($typenode,'id="','"');
			$typename = StrSlice($typenode,'">','"');
			echo "<option value=\"".$typeid."\">".$typename."</option>";
	    }
	?>
	</select>
	</th></tr>
	</form>
	<tr>
		<th>名称</th>
		<th>分类</th>
		<th>来源</th>
		<th width="135">时间</th>
	</tr>
</thead>
<tbody>
<form action="?" method="post" name="choose" id="choose">
<input type="hidden" name="ac" value="select">
<input type="hidden" name="rid" value="<?=$rid?>">
<?php
    $nodes=getrulevaluearr($xml,'video');
	foreach ($nodes as $v) {
		$la = StrSlice($v,'<last>','</last>');
		$id = StrSlice($v,'<id>','</id>');
		$ti = StrSlice($v,'<tid>','</tid>');
		$na = StrSlice($v,'<name><![CDATA[',']]></name>');
		$ty = StrSlice($v,'<type>','</type>');
		$dt = StrSlice($v,'<dt>','</dt>');
		$no = StrSlice($v,'<note><![CDATA[',']]></note>');
		$ch = "" ;
		if(date("Y-m-d",strtotime($la))==date('Y-m-d')){
			$ch = " checked"  ; $la="<font color=red>".$la."</font>" ;
		}
?>
	<tr>
		<td><input type="checkbox" class="checkbox" name="ids[]" value="<?=$id?>" id="<?=$id?>"<?=$ch?>/><label for="<?=$id?>"><?=$na?><font color="#FF0000"><?=$no?></font></label></td>
		<td><a href="?ac=list&t=<?=$ti?>&rid=<?=$rid?>"><?=$ty?></a></td>
		<td><?=$dt?></td>
		<td><?=$la?></td>
	</tr>
<?php
	}
?>
</form>
	<tr><td colspan="4">
	<?=$pagestr?>
	</td></tr>
</tbody>
</table>
<?php
}

function main() {
	global $res;
?>
<table class="tb">
	<thead>
		<tr class="thead"><th>&nbsp;采集平台</th></tr>
	</thead>
</table>
<table class="tb2">
<tbody>
    <tr>
		<td colspan="2"><h3>百度（八度）影音资源库</h3></td>
	</tr>
 
	<tr id="res7">
		<td><a href="?ac=list&rid=7">(7)【BDHD】<font color=""#00FF00"">八度影音(百度影音）影视资源站、无弹窗、质量高、更新快 www.qqcop.com </font></a></td>
		<td width="200"><a href="#" onClick="location.href='?ac=day&rid=7&backurl='+encodeURIComponent(location.href);">采集当天</a> <a href="#" onClick="location.href='?ac=type&rid=7&backurl='+encodeURIComponent(location.href);">一键采集所有</a> <a href="?ac=list&rid=7">视频列表</a></td>
	</tr>
 
	<tr>
		<td colspan="2"><h3>优秀</h3></td>
	</tr>
 
	<tr id="res10">
		<td><a href="?ac=list&rid=1">(1)【QVOD】<font color="#FF0000">qvodzy.me在站长中使用非常广泛、稳定、快速、更新及时---推荐 </font></a></td>
		<td width="200"><a href="#" onClick="location.href='?ac=day&rid=1&backurl='+encodeURIComponent(location.href);">采集当天</a> <a href="#" onClick="location.href='?ac=type&rid=1&backurl='+encodeURIComponent(location.href);">一键采集所有</a> <a href="?ac=list&rid=1">视频列表</a></td>
	</tr>
 
	<tr id="res24">
		<td><a href="?ac=list&rid=2">(2)【QVOD】<font color="#0000FF">hacow.me无弹窗、速度快、更新多</font></a></td>
		<td width="200"><a href="#" onClick="location.href='?ac=day&rid=2&backurl='+encodeURIComponent(location.href);">采集当天</a> <a href="#" onClick="location.href='?ac=type&rid=2&backurl='+encodeURIComponent(location.href);">一键采集所有</a> <a href="?ac=list&rid=2">视频列表</a></td>
	</tr>
 
	<tr id="res25">
		<td><a href="?ac=list&rid=3">(3)【QVOD】<font color="#0000FF">kuaizy.com无弹窗、速度快、更新多</font></a></td>
		<td width="200"><a href="#" onClick="location.href='?ac=day&rid=3&backurl='+encodeURIComponent(location.href);">采集当天</a> <a href="#" onClick="location.href='?ac=type&rid=3&backurl='+encodeURIComponent(location.href);">一键采集所有</a> <a href="?ac=list&rid=3">视频列表</a></td>
	</tr>
 
	<tr id="res7">
		<td><a href="?ac=list&rid=4">(4)【GVOD】<font color="#FF0000">gvodzi.com更新较为及时,有良性广告,gvodzi站长每日更新---推荐 </font></a></td>
		<td width="200"><a href="#" onClick="location.href='?ac=day&rid=4&backurl='+encodeURIComponent(location.href);">采集当天</a> <a href="#" onClick="location.href='?ac=type&rid=4&backurl='+encodeURIComponent(location.href);">一键采集所有</a> <a href="?ac=list&rid=4">视频列表</a></td>
	</tr>
 
	<tr>
		<td colspan="2"><h3>站长</h3></td>
	</tr>
 
	<tr id="res8">
		<td><a href="?ac=list&rid=5">(5)【GVOD】<font color="#0000FF">FK字幕组每日手动更新 ,数量多 </font></a></td>
		<td width="200"><a href="#" onClick="location.href='?ac=day&rid=5&backurl='+encodeURIComponent(location.href);">采集当天</a> <a href="#" onClick="location.href='?ac=type&rid=5&backurl='+encodeURIComponent(location.href);">一键采集所有</a> <a href="?ac=list&rid=5">视频列表</a></td>
	</tr>
 
	<tr id="res6">
		<td><a href="?ac=list&rid=6">(6)【GVOD】<font color="#0000FF">369ys.org原创首发最新热门</font></a></td>
		<td width="200"><a href="#" onClick="location.href='?ac=day&rid=6&backurl='+encodeURIComponent(location.href);">采集当天</a> <a href="#" onClick="location.href='?ac=type&rid=6&backurl='+encodeURIComponent(location.href);">一键采集所有</a> <a href="?ac=list&rid=6">视频列表</a></td>
	</tr>
 
</tbody>
</table>
<?php
}

function Headera() {
	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">
<!--2010-09-15 10:57-->
<title>采集平台</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[1][0]?>&nbsp;&raquo;&nbsp;采集平台';</script>
<style type="text/css">
input{height:12px;}
.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}
.gray{color:gray}
.ul li{float:left;margin:3px;width:150px}
h3{padding:0;margin:0;font-size:12px;background:none;border:none}
</style>
<script type="text/javascript">
window.RESLIB40=true;
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 bindType(){
	$bind_back=getRefer();
	$vtypename=getForm("tname","get");$curBindId=getForm("curid","get");$operType=getForm("class","get");
?>
<table class="tb">
<thead>
	<tr class="thead"><th colspan="4">&nbsp;<a href="?">采集平台</a>&nbsp;&raquo;&nbsp;绑定分类</th></tr>
	<tr><th colspan="4">
<?php
	echo "<div class='bindtype'><form action='?ac=bindsubmit&curid=".$curBindId."&class=".$operType."' method='post' id='gatherform' name='gatherform'><span>将分类 <font class='red'>".$vtypename."</font> 绑定到您的网站分类的</span><input type='hidden' value='".$bind_back."' name='bind_back' >&nbsp;&nbsp;<select name='m_type' id='m_type'><option value=''>请选择数据分类</option>";
	$typeid=getBindedLocalId($curBindId);
    makeTypeOptionSelected(0,"&nbsp;|&nbsp;&nbsp;","",$typeid);
	echo "</select>&nbsp;&nbsp;<input type='hidden' name='m_oldtype' value='".$typeid."' /><input type='submit' class='btn' value='绑  定'/>&nbsp;&nbsp;<input type='button' class='btn' value='返  回' onClick='javascript:history.back();return false;'/></form></div>";
?>
	</th></tr>
</thead>
</table>
<?php
}

function bindSubmit(){
	$curBindId=getForm("curid","get");$operType=getForm("class","get");
	$m_type=getForm("m_type","post");$bind_back=getForm("bind_back","post");$m_oldtype=getForm("m_oldtype","post");
	if (is_numeric($m_type)){
		if (!empty($m_oldtype)){
			$row = DB::fetch_first("select m_id,m_unionid from ".DB::table('type')." where m_id='$m_oldtype'");
			if(is_array($row)){
				$unionid=delBindId($curBindId,$row["m_unionid"]);
				DB::query("update ".DB::table('type')." set m_unionid='$unionid' where m_id=".$row['m_id']);
			}
		}
		$row = DB::fetch_first("select m_id,m_unionid from ".DB::table('type')." where m_id='$m_type'");
		if(is_array($row)){
			$unionid=addUnionid($curBindId,$row["m_unionid"]);
			DB::query("update ".DB::table('type')." set m_unionid='$unionid' where m_id=".$row['m_id']);
		}
		alertMsg("绑定成功",$bind_back);exit;
	}else{
		$row = DB::fetch_first("select m_id,m_unionid from ".DB::table('type')." where concat(',',m_unionid,',') like '%,".$curBindId.",%'");
		if(is_array($row)){
			$unionid=delBindId($curBindId,$row["m_unionid"]);
			DB::query("update ".DB::table('type')." set m_unionid='$unionid' where m_id=".$row['m_id']);
		}
		alertMsg("解除绑定",$bind_back);exit;
	}
}

function delBindId($bindid, $unionId) {
	if (empty($unionId)) {
		return $bindid;
	} else {
		if (strpos(" ,".$unionId.",",",".$bindid.",")) return ltrim(rtrim(str_replace(",".$bindid.",",",",",".$unionId.","),","),","); else return $unionId;
	}
}

function addUnionid($bindid, $unionId) {
	if (empty($unionId)) {
		return $bindid;
	} else {
		if (strpos(",".$unionId.",",",".$bindid.",")) return $unionId; else return $unionId.",".$bindid;
	}
}

function getBindedLibIds() {
	$libIds = "";
	$query = DB::query("select m_unionid from ".DB::table('type')." where m_type=0 AND m_unionid<>''");
	while($row = DB::fetch($query)) {
		$libIds .= $row['m_unionid'].',';
	}
	$libIds = rtrim($libIds, ',');
	return $libIds;
}

function getBindedLocalId($libId) {
	$row = DB::fetch_first("SELECT count(*) as dd FROM ".DB::table('type')." WHERE m_unionid<>''");
	if (!is_array($row)) return '';
	$query = DB::query("select m_id,m_unionid from ".DB::table('type')." where m_type=0 AND m_unionid<>''");
	while($row = DB::fetch($query)) {
		$unionArray = explode(",", $row['m_unionid']); $arrayLen2 = count($unionArray);
		for ($i = 0;$i < $arrayLen2;$i++) {
			if (trim($unionArray[$i]) == trim($libId)) return $row['m_id'];
		}
	}
	return '';
}

function gather(){
	global $res,$rid;
	$ids=getForm("ids","both");
	if (empty($ids)){ alertMsg("请选择采集数据","");last();}
	$weburl=$res[$rid]."?ac=videolist&ids=".dimplode($ids);
	intoDatabase($weburl,"select");
}

function gatherType(){
	global $res,$rid,$t,$pg;
	$weburl=$res[$rid]."?ac=videolist&rid=".$rid."&t=".$t."&pg=".$pg;
	intoDatabase($weburl,"type");
}

function gatherDay(){
	global $res,$rid,$t,$pg;
	$weburl=$res[$rid]."?ac=videolist&rid=".$rid."&t=".$t."&h=24&pg=".$pg;
	intoDatabase($weburl,"day");
}

function gatherAll(){
	global $res,$rid,$pg;
	$weburl=$res[$rid]."?ac=videolist&rid=".$rid."&pg=".$pg;
	intoDatabase($weburl,"type");
}

function Footer(){
?></div>
<div align=center></div>
<div align=center>Copyright 2010-2011 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 isSpecial($sType){
	$isSpecial=false;
	if (strpos($sType,"剧")>2){
		$isSpecial=true;
	}elseif (strpos($sType,"动漫")>0){
		$isSpecial=true;
	}elseif (strpos($sType,"动画")>0){
		$isSpecial=true;
	}elseif (strpos($sType,"综艺")>0){
		$isSpecial=true;
	}
	return $isSpecial;
}
?>