<?php
@set_time_limit(0);
@ob_implicit_flush();
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%原创、未引入任何网上代码,对一切抄袭行为、坚决严肃追究法律责任
'*******************************************************************************************/
viewHead("数据库相关操作"."-" .$menuList[4][0]);
$action = getForm("action", "get");$table=getForm("table","both");
$sql = getForm("sql","post");
switch ($action) {
	case "sql" : executeSql();break;
	case "result" : executeSql();executeResult();break;
	case "japan" : killJapan();break;
	case "kill" : killJapanSubmit();break;
	case "batch" : batchReplace();break;
	case "batchsubmit" : batchReplaceSubmit();break;
	case "randomset" : randomset();break;
	case "dorandomset" : dorandomset();break;
	case "downpic" : downPic();break;
	case "checkpic" : checkPica();break;
	case "sumitcheck" : sumitCheckPic();break;
	case "delvideoform":delvideoform();break;
	case "delByFrom":delByFrom();break;
	case "repairplaydata":repairplaydata();break;
	case "existpic":existpic();break;
	case "repeat":repeat();break;
}
viewFoot();

function repeat(){
	global $menuList;
?>
<div class="container" id="cpcontainer">
<form  method="post" action="?action=result">
<table class="tb">
    <tr class="thead"><td>同名数据检测</td></tr>
    <tr><td>检测长度：<input type="text" name="rlen" id="rlen" size="5" value="2" maxlength="1" onkeyup="this.value=this.value.replace(/\D/g,'')"> <input type="button" class="btn" onclick="location.href='admin_video.php?repeat=ok&order=m_name&rlen='+$('rlen').value;" value="查询"></td></tr>
	</table>
</form></div>
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?php echo $menuList[4][0];?>&nbsp;&raquo;&nbsp;SQL高级助手';</script>
<?php
}

function existpic() {
	global $action,$table;
	$x = ifthen($table=="news","news","data");$y = getForm("offset","both");
	if (!is_numeric($y)) $y = 0; else $y = intval($y);
	if ($x == "news"){
		$sqlStr = "SELECT m_id,m_title AS m_name,m_pic FROM ".DB::table('news')." WHERE m_pic LIKE 'pic/%'";
	}else{
		$sqlStr = "SELECT m_id,m_name,m_pic FROM ".DB::table('data')." WHERE m_pic LIKE 'pic/%'";
	}
	$numPerPage = 100;
	$allRecordset = db::getCount($sqlStr);
    $TotalPage = ceil($allRecordset / $numPerPage);
	$y = max(intval($y), 1);
	if ($y <= $TotalPage) { 
        $limitstart = $numPerPage * ($y - 1);
	    if ($allRecordset > 0) {
			echo "<div class='container' id='cpcontainer'>正在更新,当前是第<font color='red'>".$y."</font>页,共<font color='red'>".$TotalPage."</font>页,共<font color='red'>".$allRecordset."</font>部数据<hr style='border:1px solid #DEEFFA'/>";
			$query = DB::query("$sqlStr LIMIT $limitstart,$numPerPage");
            while($row = DB::fetch($query)) {
				if (isExistFile("../".$row["m_pic"])){
				    echo "清空 <font color='red'>id:".$row["m_id"]." ".$row["m_name"]."</font><br/>";
					DB::update($x, array('m_pic' => ''),array('m_id' => $row['m_id']));
			    }else{
				    echo "跳过 <font color='blue'>id:".$row["m_id"]." ".$row["m_name"]."</font><br/>";
			    }
            }
        }
		echo "<br>暂停1秒后继续检验<script language=\"javascript\">setTimeout(function (){location.href='?action=".$action."&table=".$x."&offset=".($y+1)."';},1000);</script>";
    } else {
	    alertMsg("恭喜，已经搞定","admin_datarelate.php?action=checkpic");
    }
}

function executeSql() {
	global $sql,$menuList;
?><div class="container" id="cpcontainer">
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?php echo $menuList[4][0];?>&nbsp;&raquo;&nbsp;SQL高级助手';</script>
<form  method="post" action="?action=result">
<table class="tb">
    <tr class="thead"><td>SQL高级助手</td></tr>
    <tr><td><input  type="text" name="sql" size="90" value="<?php echo $sql;?>"> <input type="submit" class="btn"  value="执行SQL语句">  <input type="reset" value="清除" class="btn"></td></tr>
	<tr><td>
    1: 列出所有数据  select * from m_data<br/>
	2: 删除所有数据  delete  from m_data<br/>
	3: 列出某一栏目数据  select  *  from m_data where m_type =(select m_id from m_type where m_name = '频道1') <br/>
	4: 删除某一栏目数据  delete  from m_data where m_type =(select m_id from m_type where m_name = '频道1') <br/>
	5: 列出某一专题的数据  select  *  from m_data where m_type =(select m_id from m_topic where m_name = '男人必看十部')<br/>
	6: 删除 某一专题的数据  delete   from m_data where m_type =(select m_id from m_topic where m_name = '男人必看十部')<br/><br/>
    <a href="http://bbs.tfdj.com/" target="_blank">提示：更多sql语句应用教程</a>
	</td></tr>
	</table>
</form></div>
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?php echo $menuList[4][0];?>&nbsp;&raquo;&nbsp;SQL高级助手';</script>
<?php
}

function executeResult() {
	global $sql;
	$n=0;
	$back = getRefer();
	$sql = trim(stripslashes($sql));
	if (eregi("drop(.*)table",$sql) || eregi("drop(.*)database",$sql)) {
		echo "<span style='font-size:10pt'>删除'数据表'或'数据库'的语句不允许在这里执行。</span>";
		exit();
	}
	if (empty($sql)) alertMsg("",$back);
	if (eregi("^select ",$sql)) {
		$isselect = "true";
	} else {
		$isselect = "false";
	}
    if (DB::query($sql)) {
	    $num=DB::affected_rows();
?>
<table class="tb">
	<?php
	if ($isselect == "true")
	{
		$results = DB::query($sql);
		$rows = DB::fetch($results);
	?>
    <tr> 
		<?php foreach($rows as $k=>$v){?>
        <td nowrap class=forumrow>&nbsp;<?php echo $k?></td>
		<?php 
		}
		?>
    </tr>
		<?php
		$l = 0;
		$query = DB::query($sql);
	    while ($rows = DB::fetch($query)) {
		$l++;
		 if ($l > 100) {
			break;
		 }
		 ?>
    <tr> 
		<?php 
		
		foreach ($rows as $k => $v) {
			?>
        <td nowrap class=forumrow>&nbsp;<?php echo $v?></td>
        <?php }
		
		?>
	</tr>
	<?php
		}
	} else {
	?>
    <tr> <td>执行结果</td></tr>
	<tr> <td> <?php echo $num?>条记录受影响</td></tr>
		<?php
	}
		?>
</table>
<?php	
	} else {
	?>
<table class="tb">
    <tr> <td> 错误号</td><td> 错误信息</td></tr>
    <tr> <td> <?php echo db::errno()?> </td><td> <?php echo db::error()?> </td></tr>
</table>
	<?php
	}
}

function batchReplaceSubmit() {
	$m_field = getForm("m_field","post");$m_str1 = getForm("m_str1","post");$m_str2 = getForm("m_str2","post");
	$sql = "SELECT m_id,".$m_field." FROM ".DB::table('data')." WHERE ".$m_field." LIKE '%".$m_str1."%'";
	echo "<table class='tb'><tr class='thead' align='left'><td>已处理数据</td></tr><tr><td>结果</td></tr>";
	$query = DB::query($sql);
	while ($row = DB::fetch($query)) {
		DB::update('data', array($m_field => str_replace($m_str1,$m_str2,$row[$m_field])),array('m_id' => $row['m_id']));
		echo "<tr><td>ID为".$row['m_id']."的数据替换成功</td></tr>";
	}
	echo "</table>";
}

function batchReplace() {
	global $menuList;
?>
<div class="container" id="cpcontainer">
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?php echo $menuList[4][0];?>&nbsp;&raquo;&nbsp;数据批量替换';</script>
<form action="?action=batchsubmit" method="post">
<table class="tb">
<tr class="thead"><td colspan="15"  align="left" >数据批量替换</td></tr>
<tr><td>将字段：<select name="m_field" style="width:150px"><?php echoFieldOptions();?></select>中的字符：<input type="text" size="25" name="m_str1" /> 替换成：<input type="text" size="25" name="m_str2" /> <input class="btn" type="submit" value="确认替换" /><br><br><font color=#FF0000>注意，程序遇到待替换的字符就会立即替换且不可恢复，请小心处理。</font>
</td></tr></table>
</form>
</div>
<?php
}

function echoFieldOptions() {
	$fieldOptionArray[0][0]="视频名称" ; $fieldOptionArray[0][1]="m_name";
	$fieldOptionArray[1][0]="视频图片" ; $fieldOptionArray[1][1]="m_pic";
	$fieldOptionArray[2][0]="视频主演" ; $fieldOptionArray[2][1]="m_actor";
	$fieldOptionArray[3][0]="视频简介" ; $fieldOptionArray[3][1]="m_des";
	$fieldOptionArray[4][0]="视频添加时间" ; $fieldOptionArray[4][1]="m_addtime";
	$fieldOptionArray[5][0]="视频标题颜色" ; $fieldOptionArray[5][1]="m_color";
	$fieldOptionArray[6][0]="视频发行年份" ; $fieldOptionArray[6][1]="m_publishyear";
	$fieldOptionArray[7][0]="视频发行地区" ; $fieldOptionArray[7][1]="m_publisharea";
	$fieldOptionArray[8][0]="视频分类ID" ; $fieldOptionArray[8][1]="m_type";
	$fieldOptionArray[9][0]="视频推荐" ; $fieldOptionArray[9][1]="m_commend";
	$fieldOptionArray[10][0]="视频点击量" ; $fieldOptionArray[10][1]="m_hit";
	$fieldOptionArray[11][0]="播放地址" ; $fieldOptionArray[11][1]="m_playdata";
	$fieldOptionArray[12][0]="下载地址" ; $fieldOptionArray[12][1]="m_downdata";
	$fieldOptionArray[13][0]="视频备注" ; $fieldOptionArray[13][1]="m_note";
	$fieldOptionArray[14][0]="关键字" ; $fieldOptionArray[14][1]="m_keyword";
	$fieldOptionArray[15][0]="视频导演" ; $fieldOptionArray[15][1]="m_director";
	$fieldOptionArray[16][0]="视频语言" ; $fieldOptionArray[16][1]="m_lang";
	$arrayLen=count($fieldOptionArray);
	for ($i = 0;$i < $arrayLen;$i++) {
		echo "<option value=\"".$fieldOptionArray[$i][1]."\">[".$fieldOptionArray[$i][0]."]</option>";
	}
}

function checkPica() {
	global $menuList;
?>
<div class="container" id="cpcontainer"> 
<table class="tb">
<tr class="thead"><td colspan="15"  align="left" >无效数据图片清除工具</td></tr>
<tr><td><input type="button" class="btn" value="查询无图片的数据" onClick="location.href='admin_video.php?action=nullpic';">&nbsp;&nbsp;<input type="button" class="btn" value="清空数据图片不存在地址" onClick="location.href='?action=existpic';" style="width:140px">&nbsp;&nbsp;<input type="button" class="btn" value="删除多余数据图片" onClick="if(confirm('注意：使用此功能前,务必确认数据图片文件夹是/pic/<?=sitePic?>/')){location.href='?action=sumitcheck';}else{return false}"></td></tr>
<tr><td><input type="button" class="btn" value="查询无图片的新闻" onClick="location.href='admin_news.php?action=nullpic';">&nbsp;&nbsp;<input type="button" class="btn" value="清空新闻图片不存在地址" onClick="location.href='?action=existpic&table=news';" style="width:140px">&nbsp;&nbsp;<input type="button" class="btn" value="删除多余新闻图片" onClick="if(confirm('注意：使用此功能前,务必确认数据图片文件夹是/pic/newspic/')){location.href='?action=sumitcheck&table=news';}else{return false}"></td></tr>
<tr><td>说明：对比数据库中图片名称，删除多余图片文件，节省服务器空间！<br />注意：使用此功能前,务必确认数据图片文件夹是/pic/<?=sitePic?>/</td></tr>
</table></div>
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?=$menuList[4][0]?>&nbsp;&raquo;&nbsp;无效图片清除工具';</script>	
<?php	
}

function sumitCheckPic() {
	global $table;
	$x = ifthen($table=="news","newspic",sitePic);
?>
<div align="center">
<?php
echo("<div style=' width:100%; background: #F9FBFD; border-top:4px solid #DEEFFA; border-bottom:1px solid #DEEFFA;color:#008EBD; font-size:12px; height:30px; line-height:30px;font-weight:bold; margin:0 auto;'>&nbsp;正在移除无效图片链接</font></div>");
	viewFileAndFolder("pic/".$x);
	die("<br/><font style=font-size:13px;>&nbsp;恭喜你！所有无效图片删除完毕．．．</font><br/>");
?>
</div>
<?php
}

function viewFileAndFolder($folder) {
	global $table;
	$x = ifthen($table=="news","newspic",sitePic);
	$d="../".$folder;
	if (is_dir($d)){
	  	$dh = opendir($d);
 		 while (false !== ( $file = readdir ($dh))) {
   			if ($file != "." && $file!="..") { 
      			$fullpath = $d."/".$file;
				$folderl = "pic/".$x."/".$file;
      			if (!is_dir($fullpath)) {       		 	
					$row = DB::fetch_first("SELECT m_pic FROM ".DB::table('data')." WHERE m_pic='$folderl' LIMIT 1");
					if (!is_array($row)) {
						@unlink($fullpath);
						echo "<font style=font-size:12px;><font color=red>".$file."</font>无效图片已经删除...</font><br/>";
					}
					
     			} 
			}
   		}
   	closedir($dh);
   }
}

function randomset() {
	global $menuList;
?>
<div class="container" id="cpcontainer">
<form  method="get" action="?">
<input type="hidden" name="action" value="dorandomset" />
<table class="tb">
    <tr class="thead"><td colspan="2">随机设置数据点击量</td></tr>
	<!--tr><td width="12%">数据始止ID：</td><td width="88%"><input type="text" name="iStart" value="不限" /> 到 <input type="text" name="iEnd" value="不限" /></td></tr>
	<tr><td width="12%">星级数：</td><td width="88%"><input type="checkbox" class="checkbox" name="bComm" id="bComm" value="1" onclick="$('bComm').checked=false" disabled/><label for="bComm">随机加上</label>&nbsp;&nbsp;<input type="checkbox" class="checkbox" name="bComm" id="bComm2" value="2" onclick="$('bComm').checked=false" /><label for="bComm2">随机重设</label>&nbsp;&nbsp;<span>0 到 <input type="text" name="maxComm" value="5" maxlength="1" readOnly></span>&nbsp;&nbsp;<input type="submit" class="btn"  value="执行"></td></tr-->
	<tr><td width="12%">点击量区间：<!--/td><td width="88%"--><div style="display:none"><input type="checkbox" class="checkbox" name="bHit" id="bHit" value="1" onclick="$('bHit2').checked=false"/><label for="bHit">随机加上</label>&nbsp;&nbsp;<input type="checkbox" class="checkbox" name="bHit" id="bHit2" value="2" onclick="$('bHit').checked=false" checked/><label for="bHit2">随机重设</label>&nbsp;&nbsp;</div><span>0 到 <input type="text" name="maxHit" value="1000" maxlength="4">&nbsp;&nbsp;<select name="Days" id="Days">
       <option value="">全部</option>
        <?php for ($i = 1;$i < 7;$i++) {
echo "<option value=\"$i\">$i</option>\n";
}?>

		</select>日内内容</span>&nbsp;&nbsp;<input type="submit" class="btn"  value="执行"></td></tr>
	<!--tr><td width="12%">顶次数：</td><td width="88%"><input type="checkbox" class="checkbox" name="bDigg" id="bDigg" value="1" onclick="$('bDigg2').checked=false"/><label for="bDigg">随机加上</label>&nbsp;&nbsp;<input type="checkbox" class="checkbox" name="bDigg" id="bDigg2" value="2" onclick="$('bDigg').checked=false" /><label for="bDigg2">随机重设</label>&nbsp;&nbsp;<span>0 到 <input type="text" name="maxDigg" value="200" maxlength="3"></span>&nbsp;&nbsp;<input type="submit" class="btn"  value="执行"></td></tr>
	<tr><td width="12%">踩次数：</td><td width="88%"><input type="checkbox" class="checkbox" name="bTread" id="bTread" value="1" onclick="$('bTread2').checked=false"/><label for="bTread">随机加上</label>&nbsp;&nbsp;<input type="checkbox" class="checkbox" name="bTread" id="bTread2" value="2" onclick="$('bTread').checked=false" /><label for="bTread2">随机重设</label>&nbsp;&nbsp;<span>0 到 <input type="text" name="maxTread" value="200" maxlength="3"></span>&nbsp;&nbsp;<input type="submit" class="btn"  value="执行"></td></tr>
	<tr><td colspan="2">随机加上 说明： 新点击量 = 点击量 + 随机数<br />随机重设 说明： 新点击量 = 随机数<br />点击量清零技巧：勾上 随机重设，把最大值设为 0</td></tr>
    <tr><td colspan="2"><input type="submit" class="btn"  value="执行"></td></tr-->
</table>
</form>
</div>
<?php
}

function doRandomset() {
	global $action;
	$maxHit = getForm("maxHit","get");$bHit = getForm("bHit","get");$page = getForm("page","get");$days = Str2Num(getForm("Days"));
	$page=ifthen(empty($page),1,$page);
	if (empty($maxHit)){ exit("<font color='red'>你输入的不能为空!</font><br>");}
	if (is_numeric($maxHit)){ $maxHit=$maxHit; } else { exit("<font color='red'>你输入的不是数字!</font><br>");}
	$number = 100;
	$ntime = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y'));
	$limitday = $ntime - ($days * 24 * 3600);
    $whereStr =' WHERE 1=1';
	if (!empty($days)){ $whereStr .= " AND m_addtime>".$limitday;}
	$sqlStr = "SELECT m_id,m_name,m_hit FROM ".DB::table('data')." $whereStr ORDER BY m_id DESC";
	$allRecordset = DB::getCount($sqlStr);
    $tpagecount = ceil($allRecordset / $number);
	if ($page <= $tpagecount) { 
	    if ($allRecordset > 0) {
			echo "<div class='container' id='cpcontainer'>正在更新,当前是第<font color='red'>".$page."</font>页,共<font color='red'>".$tpagecount."</font>页,共<font color='red'>".$allRecordset."</font>部数据<hr style='border:1px solid #DEEFFA'/>";
			$page = max(intval($page), 1);
            $offset = $number*($page-1);
			$query = DB::query("$sqlStr LIMIT $offset, $number");
	        while ($row = DB::fetch($query)) {
				$iHit=$row['m_hit'];
				if ($bHit == 2) {
					$iHit=mt_rand(0,$maxHit);
					DB::update('data', array('m_hit' => $iHit),array('m_id' => $row['m_id']));
				} else if ($bHit == 1) {
					$iHit=mt_rand(0,$maxHit);
					DB::update('data', array('m_hit' => $iHit),array('m_id' => $row['m_id']));
                }			    
				echo "成功更新 ID:".$row['m_id']."	<font color=red>".$row['m_name']."</font> 点击量:".$iHit."<br>";
            }
        }
		echo "<br>暂停3秒后继续更新</div><script language='javascript'>setTimeout(function (){location.href='?action=".$action."&page=".($page+1)."&bHit=".$bHit."&maxHit=".$maxHit."&Days=".$days."';},3000);</script>";
	} else {
		alertMsg("操作完成","?action=randomset");
    }
}
	
function downPic() {
	global $table;
	session_start();
	$downType = getForm("downtype","get");
	$sitePic = ifthen($table == "news","newspic",sitePic)."/".date('Y')."-".date('m');
	$isDownOk = false;$pagesize=30;
	$page=getForm("page","get");
	if ($table=="news"){
		$sql="SELECT m_id,m_title as m_name,m_pic FROM ".DB::table('news')." WHERE LEFT(m_pic,7) = 'http://' ORDER BY m_addtime DESC";
    }else{
		$sql="SELECT m_id,m_name,m_pic FROM ".DB::table('data')." WHERE LEFT(m_pic,7) = 'http://' ORDER BY m_addtime DESC";
    }
	$allRecordset = db::getCount($sql);
	$page=ifthen(empty($page),1,$page);
	$totalpage = ceil($allRecordset/$pagesize);
	if ($page == 1) $_SESSION["m_pic_page"] = $totalpage;
	if ($allRecordset == 0 || $page > $totalpage) {
		alertMsg("恭喜，所有图片已经成功下载到本地!",ifthen($table=="news","admin_news.php","admin_video.php"));exit();
	}
	echo "<font color=red>共".$_SESSION["m_pic_page"]."页,正在开始下载第".$page."页数据的的图片</font><br>";
    $query = DB::query("$sql LIMIT 0,$pagesize");
	while ($row = DB::fetch($query)) {
		$ps = explode("/",$row['m_pic']);
		$filename = $ps[count($ps)-1];
		if (strpos(" ".$filename,"?") > 0){$filenamet=explode('?',$filename);$filename=$filenamet[0];}
		$filePath = "pic/".$sitePic."/".$filename;
		if (!file_exists($filePath)) {
			$isDownOk = downSinglePic($row['m_pic'],$row['m_id'],$row['m_name'],$filePath,"down");
		} else {
			echo "数据<font color=red>".$row['m_name']."</font>的图片已经存在 <a target=_blank href=".$filePath.">预览图片</a><br>";
			$isDownOk=true;
		}
		if ($isDownOk) {
			updatePicUrl($row['m_id'],replaceStr($filePath,"../",""));
			if (watermark == 1) writeFontWaterPrint($filePath);
		} else {
			updatePicUrl($row['m_id'],"");
		}
	}
	echo "<br>暂停5秒后继续下载<script language='javascript'>setTimeout('gatherNextPagePic();',5000);function gatherNextPagePic(){location.href='?action=downpic&downtype=".$downType."&table=".$table."&page=".($page+1)."';}</script>";
}
	
function updatePicUrl($id,$pic) {
	global $table;
	DB::update(ifthen($table=="news","news","data"), array('m_pic' => $pic),array('m_id' => $id));
}

function delvideoform() {
	global $menuList;
?>
<div class="container" id="cpcontainer">
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?php echo $menuList[4][0];?>&nbsp;&raquo;&nbsp;删除指定来源';</script>

<table class="tb">
<tr class="thead"><td colspan="15"  align="left" >删除指定来源</td></tr>
<form method="post" id="delsubmit" action="?">

<tr><td>
选择来源：<select  name="from" id="from">
<option value="">请选择删除的来源</option>
<?php echo makePlayerSelect("");?>
</select></td></tr>
<tr><td>处理每页数据间隔时间：<input type="text" name="wtime" size="5" value="5" />秒&nbsp;(默认5)</td></tr>
<tr><td>按特征删除：<input type="text" name="domain" class="txt" value="" /> 提示：留空为不限制，可以输入网址、域名、包含的字符特征</td></tr>
<tr><td><input type="button" value="确认删除"  class="btn" onclick="var delsubmit=document.getElementById('delsubmit'),from=document.getElementById('from'),fromvalue=from.options[from.selectedIndex].value;if(fromvalue!=''){delsubmit.action='?action=delByFrom';delsubmit.submit();}else{alert('请选择删除的来源!')}"/> </td></tr>
<tr><td> <br />注意：为了防止意外、请操作前务必先备份数据库 </td></tr>
</table>
<?php
}

function delByFrom() {
	global $menuList;
	$domain = getForm("domain");$from = getForm("from");$page = getForm("page","get");$wtime = getForm("wtime");
	$wtime = empty($wtime) ? 5 : intval($wtime);$id = getReferedId($from);$number = 30;
	$page = empty($page) ? 1 : intval($page);
	$sqlStr = "SELECT m_id,m_name,m_playdata FROM ".DB::table('data')." WHERE m_playdata LIKE '%".ifthen(!empty($domain),$domain."%","")."$".$id."%'";
	$allRecordset = db::getCount($sqlStr);
	if (empty($totalpage)) $totalpage = ceil($allRecordset/$number);
	if (!empty($domain)) $str="(".$domain.").+"; else $str="";
	$regstr=$from.'.+'.$str.'\$'.$id;
	if ($allRecordset==0 || $page>$totalpage) {
		alertMsg("恭喜，已经搞定","admin_datarelate.php?action=delvideoform");exit();
	} else {
		if ($page == 1) dsetcookie("delfrompcount", $totalpage, 365);
		if ($page<1) $page=1;
		if ($page > $totalpage) $page = $totalpage;
		echo "<style>body{font-size: 12px;}</style>正在准备删除<font color='red' >".$from."</font>来源,共<font color='red' >".getcookie("delfrompcount")."</font>页，当前<font color='red' >".($page."")."</font>页，每页<font color='red' >".$number."</font>个<br/>";
		$page = max(intval($page), 1);$offset = $number*($page-1);
		$query = DB::query("$sqlStr LIMIT $offset, $number");
	    while ($row = DB::fetch($query)) {
			$playdata = $row['m_playdata'];
			$playdata = str_replace('$$$$$$','$$$',str_replace('$$$$$$','$$$',ltrim(rtrim(ltrim(rtrim(preg_replace(buildregx($regstr,'is'),'',$playdata),'#'),'$'),'$$$'),'$$$')));
			DB::update('data', array('m_playdata' => $playdata),array('m_id' => $row['m_id']));
			echo "数据ID<font color='red' >".$row['m_name']."</font>的<font color='red' >".$from."</font>来源删除成功<br/>";
		}
		echo "<br>暂停".$wtime."秒后继续<script language=\"javascript\">setTimeout(\"transNextPage();\",".$wtime."*1000);function transNextPage(){location.href='?action=delByFrom&page=".($page+1)."&wtime=".$wtime."&from=".$from."&domain=".$domain."';}</script>";
	}
}
?>
