<?php

/*

'**************************************************************************************************

' 软件名称: 黑色幻想舞曲管理系统CMS2.0

' 版本编号: hshxsdj 2.0

' 官方网站: http://www.hshxs.com

' 官方论坛：http://bbs.hshxs.com

' 版权所有: 黑色幻想开发团队    噬己翼(QQ:532917920)

' 郑重声明:

'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；

'    2、黑色幻想网络事业部保留此软件的法律追究权利

'**************************************************************************************************

*/


include "../../include/conn.php";

include "../../include/function.php";

include "../admin_version.php";

include "../admin_loginstate.php";

?>

<?php

$playadd=playadd(2);

$action=SafeRequest("action","get");

switch($action){

	case 'hitrand':

		HitRand();

		break;

	case 'hitranda':

		HitRandA();

		break;

	case 'replacement':

		ReplaceMent();

		break;

	case 'delsource':

		DelSource();

		break;

	case 'downpic':

		PicDown();

		break;

	}

	

function PicDown(){

	global $db;

	$sqlv="Select count(*) as vp from s_video where Lower(Left(S_Pic,7))='http://'  order by S_ID desc";

	$sqla="Select count(*) as ap from s_article where Lower(Left(S_Pic,7))='http://'  order by S_ID desc";

	

	$rowv=$db->getRow($sqlv);	

	$rowa=$db->getRow($sqla);	

	echo "<div style=' width:100%; background: #F9FBFD; border-top:1px solid #DEEFFA; border-bottom:0px solid #DEEFFA;color:#008EBD; font-size:12px; height:30px; line-height:30px;font-weight:bold; margin:0 auto;'>&nbsp;舞曲共有<font color=red>".$rowv['vp']."</font>张远程图片&nbsp;[<a href=\"../admin_downpic.php?sid=1\"><font color=\"#FF0000\">保存到本地</font></a>]</div><div style=' width:100%; background: #F9FBFD; border-top:0px 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 color=red>".$rowa['ap']."</font>张远程图片&nbsp;[<a href=\"../admin_downpic.php?sid=2\"><font color=\"#FF0000\">保存到本地</font></a>]</div>";

	die();

	}

	

function DelSource(){

	global $db;

	global $playadd;

	$S_Source=SafeRequest("source","auto");

	$Page=SafeRequest("pages","auto");

	$SleepTime=SafeRequest("sleeptime","auto");

	if(!IsNum($SleepTime)) $SleepTime=3;

	if(!IsNum($Page)) $Page=1;

	$JsTime=intval($SleepTime)*1000;

	$sql="select S_ID,S_Source,S_Name,S_VData,S_AddPath from s_video where S_Source Like '%".$S_Source."%' Order by S_ID desc";

	//die($sql);

	$Arr=getpagerow($sql,20);//sql,每页显示条数

	$result=$db->query($Arr[2]);

	

	if($result){

		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;正在移除".$S_Source."的数据第<font style='color:red; font-size:12px; font-style:italic'>".$Page."</font>页，剩<font style='color:red; font-size:12px; font-style:italic'>".$Arr[3]."</font>页</div>");



		while($row=$db->fetch_array($result)){

		  $SArr=$row['S_Source'];

		  $DArr=$row['S_VData']; 

			$db->query("delete from s_video where S_ID=".$row['S_ID']." ");	

			$sql1="delete from s_dt where S_Djid='".$row['S_ID']."'";

			$db->query($sql1);

			$sql2="delete from s_usersc where S_Djid='".$row['S_ID']."'";

			$db->query($sql2);

			$sql3="delete from s_down where S_Djid='".$row['S_ID']."'";

			$db->query($sql3);

			 echo "<font style=font-size:10pt;>&nbsp;&nbsp;<font color=red >".$row['S_Name']."</font>中播放源为<font color=red>".playaddshow($playadd,$S_Source)."</font>的数据已经移除！</font><br/>";	  

			  

			}

		}

	  $Page=$Page+1;

	  if($Page>$Arr[3]){

		 die("<script>alert('该组播放地址已全部删除完毕！');window.location='admin_bulk.php';</script>");

		  }

	  else{

		  die("<br><font color=red style=font-size:10pt;>&nbsp;暂停".$SleepTime."秒后继续删除播放器组．．．</font><br><script>setTimeout('updatenext();',".$JsTime.");function updatenext(){location.href='?action=delsource&source=".$S_Source."&sleeptime=".$SleepTime."&pages=".$Page."';}</script>");

		  }

  

	}



function ReplaceMent(){

	global $db;

	$S_Table=SafeRequest("S_Table","post");

	$S_Rescord=SafeRequest("S_Rescord","post");

	$Old_Str=SafeRequest("Old_Str","post");

	$New_Str=SafeRequest("New_Str","post");

	if($S_Table=="S_Video"){

		$table="s_video";

		$sql="select ".$S_Rescord.",S_ID from s_video  where ".$S_Rescord." like '%".$Old_Str."%'";

		}

	else{

		$table="s_article";

		$sql="select ".$S_Rescord." ,S_ID from s_article where ".$S_Rescord." like '%".$Old_Str."%'";

		}

	$result=$db->query($sql);

	if($result){

			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;正在处理数据...</div>");		  

		

		while($row=$db->fetch_array($result)){

			$row[$S_Rescord]=ReplaceStr($row[$S_Rescord],$Old_Str,$New_Str);

			$sql3="update ".$table." set ".$S_Rescord."='".$row[$S_Rescord]."' where S_ID=".$row['S_ID']."";

			$db->query($sql3);

			echo "&nbsp;<font color=red style=font-size:12px;>".$row[$S_Rescord]."OK!</font><br/>";

			}

		}

	die("<br/>&nbsp;<font color=red style=font-size:12px;>字符已全部替换完成．．．</font>");	

	}



function HitRand(){

	global $db;

	$shits=SafeRequest("start_hits","post");

	$ehits=SafeRequest("end_hits","post");

	$classid=SafeRequest("ClassIDs","post");

	$hitsfl=SafeRequest("hitsfl","post");

	$sday=SafeRequest("sday","auto");

	$count=SafeRequest("count","auto");

	if(!IsNum($count)) $count=30;	

	if($classid==""){

		$classid=SafeRequest("classid","get");

		}

	if($hitsfl==""){

		$hitsfl=SafeRequest("hitsfl","get");

		}

	if($hitsfl==""){

		$hitsfl="0";

		}

	$page=SafeRequest("pages","get");

	if(!IsNum($page)) $page=1;

	if(!IsNum($shits)) $shits=1;

	if(!IsNum($ehits)) $ehits=1000;

	if($page!=1){

		$shits=SafeRequest("start_hits","get");

		$ehits=SafeRequest("end_hits","get");

		$classid=SafeRequest("classid","get");

	}

	

	if($classid==0){

		if(IsNul($sday)){

			$sql="select * from s_video where DATEDIFF(DATE(S_AddTime),'".date('Y-m-d')."')>=-$sday order by S_ID desc";

			}

		else{

			$sql="select * from s_video order by S_ID desc";

			}	

		

		}

	else{

		if(IsNul($sday)){

			$sql="select * from s_video where S_ClassID=".$classid." and DATEDIFF(DATE(S_AddTime),'".date('Y-m-d')."')>=-$sday order by S_ID desc";

			}

		else{

			$sql="select * from s_video where S_ClassID=".$classid." order by S_ID desc";

			}	

		

		}

	

	$Arr=getpagerow($sql,$count);//sql,每页显示条数

	$result=$db->query($Arr[2]);

	  if($result){

			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 style='color:red; font-size:15px; font-style:italic'>".$page."</font>页，共<font style='color:red; font-size:15px; font-style:italic'>".$Arr[3]."</font>页</div>");		  

		 while ($row = $db ->fetch_array($result)){

			$S_Hits=mt_rand($shits,$ehits);

                    if($hitsfl=="0"){

                        $Hname="年度";

			$sql2="update s_video set S_Hits=".$S_Hits." where S_ID=".$row['S_ID']."";

                    }elseif($hitsfl=="1"){

                        $Hname="每日";

			$sql2="update s_video set S_Rhits=".$S_Hits." where S_ID=".$row['S_ID']."";

                    }elseif($hitsfl=="2"){

                        $Hname="每周";

			$sql2="update s_video set S_Zhits=".$S_Hits." where S_ID=".$row['S_ID']."";

                    }elseif($hitsfl=="3"){

                        $Hname="每月";

			$sql2="update s_video set S_Yhits=".$S_Hits." where S_ID=".$row['S_ID']."";

                    }elseif($hitsfl=="4"){

                        $Hname="收藏";

			$sql2="update s_video set S_FavHits=".$S_Hits." where S_ID=".$row['S_ID']."";

                    }elseif($hitsfl=="5"){

                        $Hname="下载";

			$sql2="update s_video set S_DownHits=".$S_Hits." where S_ID=".$row['S_ID']."";

                    }elseif($hitsfl=="6"){

                        $Hname="被顶";

			$sql2="update s_video set S_Apex=".$S_Hits." where S_ID=".$row['S_ID']."";

                    }elseif($hitsfl=="7"){

                        $Hname="被踩";

			$sql2="update s_video set S_Tread=".$S_Hits." where S_ID=".$row['S_ID']."";

                    }

			$db->query($sql2);

			echo "&nbsp;<font style=font-size:12px;><a href=".LinkUrl("s_video",$row['S_ClassID'],1,$row['S_ID'])." target=_blank><font color=red>".$row['S_Name']."</font></a>的".$Hname."人气变为了<font color=red>".$S_Hits."</font></font><br/>";

			}

	if($page>=$Arr[3]){

		die("<br/>&nbsp;<font style=font-size:10pt;>所有的随机舞曲人气完毕．．．．</font>");

		}

	else{	

		die("<br/>&nbsp;<font style=font-size:10pt;>暂停".S_StopTime."秒后继续随机舞曲人气 ．．．．</font><script language='javascript'>setTimeout('ReadGo();',".(S_StopTime*1000).");function ReadGo(){location.href='?action=hitrand&pages=".($page+1)."&classid=".$classid."&start_hits=".$shits."&end_hits=".$ehits."&sday=".$sday."&count=".$count."';}</script>");

	}

		}

	}

	

function HitRandA(){

	global $db;

	$shits=SafeRequest("start_hits","post");

	$ehits=SafeRequest("end_hits","post");

	$classid=SafeRequest("ClassIDs","post");

	$sday=SafeRequest("sday","auto");

	$count=SafeRequest("count","auto");

	if(!IsNum($count)) $count=30;

	if($classid==""){

		$classid=SafeRequest("classid","get");

		}

	$page=SafeRequest("pages","get");

	if(!IsNum($page)) $page=1;

	if(!IsNum($shits)) $shits=1;

	if(!IsNum($ehits)) $ehits=1000;

	if($page!=1){

		$shits=SafeRequest("start_hits","get");

		$ehits=SafeRequest("end_hits","get");

		$classid=SafeRequest("classid","get");

	}

	if($classid==0){

		if(IsNul($sday)){

			$sql="select * from s_article where DATEDIFF(DATE(S_AddTime),'".date('Y-m-d')."')>=-$sday order by S_ID desc";

			}

		else{

			$sql="select * from s_article order by S_ID desc";

			}	

		}

	else{

		if(IsNul($sday)){

			$sql="select * from s_article where S_ClassID=".$classid." and DATEDIFF(DATE(S_AddTime),'".date('Y-m-d')."')>=-$sday order by S_ID desc";

			}

		else{

			$sql="select * from s_article where S_ClassID=".$classid." order by S_ID desc";

			}			

		}	

	$Arr=getpagerow($sql,$count);//sql,每页显示条数

	$result=$db->query($Arr[2]);

	  if($result){

			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 style='color:red; font-size:15px; font-style:italic'>".$page."</font>页，共<font style='color:red; font-size:15px; font-style:italic'>".$Arr[3]."</font>页</div>");		  

		 while ($row = $db ->fetch_array($result)){

			$S_Hits=mt_rand($shits,$ehits);

			$sql2="update s_article set S_Hits=".$S_Hits." where S_ID=".$row['S_ID']."";

			$db->query($sql2);

			echo "&nbsp;<font style=font-size:10pt;><a href=".LinkUrl("s_article",$row['S_ClassID'],2,$row['S_ID'])." target=_blank><font color=red>".$row['S_Name']."</font></a>的人气变为了<font color=red>".$S_Hits."</font></font><br/>";

			}

	if($page>=$Arr[3]){

		die("<br/>&nbsp;<font style=font-size:10pt;>所有的随机文章人气完毕．．．．</font>");

		}

	else{	

		die("<br/>&nbsp;<font style=font-size:10pt;>暂停".S_StopTime."秒后继续随机舞曲人气 ．．．．</font><script language='javascript'>setTimeout('ReadGo();',".(S_StopTime*1000).");function ReadGo(){location.href='?action=hitranda&pages=".($page+1)."&classid=".$classid."&start_hits=".$shits."&end_hits=".$ehits."&sday=".$sday."&count=".$count."';}</script>");

	}

		}

	}

?>

<!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>

<link  href="../images/style.css" rel="stylesheet" type="text/css" />

<link type="text/css" href="../images/alerts.css" rel="stylesheet" media="screen">

<title>数据批量操作</title>

<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>

<script language="javascript" type="text/javascript" src="../js/jquery.js"></script>

<script language="javascript" src="../js/alerts.js"></script>



<script language="javascript">

$(document).ready(function(){

	$("#S_Table").change(function(){

		var strv="<select name='S_Rescord' id='S_Record'><option value='S_Name'>舞曲名称(S_Name)</option><option value='S_Color'>标题颜色(S_Color)</option><option value='S_Keywords'>舞曲关键字(S_Keywords)</option><option value='S_ConTent'>舞曲介绍(S_ConTent)</option><option value='S_Source'>播放器来源(S_Source)</option><option value='S_VData'>舞曲地址(S_VData)</option><option value='S_Remark'>下载地址(S_Remark)</option><option value='S_Language'>舞曲语言(S_Language)</option><option value='S_Area'>舞曲地区(S_Area)</option><option value='S_Pic'>舞曲图片(S_Pic)</option></select>";

		var stra="<select name='S_Rescord' id='S_Record'><option value='S_Name'>文章标题(S_Name)</option><option value='S_Color'>标题颜色(S_Color)</option><option value='S_Keywords'>文章关键字(S_Keywords)</option><option value='S_ConTent'>文章内容(S_ConTent)</option><option value='S_Remark'>新闻概述(S_Remark)</option><option value='S_Author'>文章作者(S_Author)</option><option value='S_Source'>文章来源(S_Source)</option></select>";

		var table=$("#S_Table").val();

		if(table=="S_Video"){

			$("#select_r").html(strv);

			}

		if(table=="S_Article"){

			$("#select_r").html(stra);

			}	

	})

	

	$("#btn_rep").click(function(){

		var table=$("#S_Table").val();

		var old=$("#Old_Str").val();

		var news=$("#New_Str").val();

		if(table==""){

			jAlert("请t先选择数据表！","操作提示");

			return false;

			}

		if(old==""){

			jAlert("请填写要替换的字符！","操作提示");

			return false;

			}

		if(news==""){

			jAlert("请填写替换的字符！","操作提示");

			return false;

			}

	 jConfirm('您确定要执行替换操作吗?', '操作提示', function(r) {

		if(r==true){

			form1.submit();

			}

		})

			

	})

	

	$("#remjp").click(function(){

		jConfirm('您确定要执行修复数据吗?</b>', '操作提示', function(r) {

		if(r==true){

			window.location='?action=removalo';

			}

				});					   

	})

	

	$("#btn_dsource").click(function(){

		var source=$("#source").val();

		if (source==""){

			jAlert("请选择您要删除的播放源！","操作提示");

			}

		else{

			form2.submit();

			}	

	})	

					   

 })



</script>

</head>



<body>

<?php SystemPer(10);?>

<div class="r_main">

	<div class="r_content">

		<div class="r_content_1">

		<form name="form2" action="?action=delsource" method="post">

		<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">

        	<tr>

            	<td class="td_title">&nbsp;删除指定来源数据</td>

            </tr>

            <tr>

            	<td class="td_border" height="30">&nbsp;选择播放来源：

            	  <select name="source" id="source"><option value="">选择要删除的来源</option><?php echo playselect($playadd,"");?></select></td>

            </tr>

             <tr>

           	   <td class="td_border" height="30">&nbsp;每页处理时间：

           	     <input type="text" size="4" value="3" name="sleeptime">

       	       &nbsp;秒&nbsp; <input type="button" id="btn_dsource" value="执行操作" class="rb1"></td>

            </tr>

             

             <tr>

            	<td class="td_border" height="30">&nbsp;<font color='red'>注意：操作前请备份数据库，以免因意外造成不可逆转的损失！</font>				</td>

            </tr>            

         </table>   

</form>





        <form name="form3" action="?action=hitrand" method="post">

		<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">

        	<tr>

            	<td class="td_title">&nbsp;舞曲人气随机工具</td>

            </tr>

            <tr>

           	  <td class="td_border" height="30">&nbsp;随机人气范围：<input type="text" size="4" name="start_hits" value="1">至<input type="text" size="4" name="end_hits" value="1000">

           	    &nbsp; 舞曲分类：

                <select name="ClassIDs">

                  <option value="0">所有内容</option>

                  <?php

         //舞曲分类

		$sqlclass="select * from s_class where S_SystemID=1 ";

		$results=$db->query($sqlclass);

		if($results){

			$classstr="";

			while ($row3=$db->fetch_array($results)){

				$classstr.="<option value=".$row3['S_ID'].">".$row3['S_Name']."</option>";

				}

			}

									?>

                  <?php echo $classstr?>

                </select>

                &nbsp;指定天数:

                <select name="sday">

                	<option value="">不限</option>

                    <?php

                    	for($i=1;$i<16;$i++){

							echo "<option value=\"".$i."\">".$i."天内</option>\r\n";

							}

					?>

                </select>

                &nbsp;人气分类:

                <select name="hitsfl">

                	<option value="0">年度人气</option>

                	<option value="1">每日人气</option>

                	<option value="2">每周人气</option>

                	<option value="3">每月人气</option>

                	<option value="4">收藏人气</option>

                	<option value="5">下载人气</option>

                	<option value="6">被顶人气</option>

                	<option value="7">被踩人气</option>

                </select>

                &nbsp; 每页<input name="count" type="text" size="4" value="30">条

                &nbsp; <input name="submit" type="submit" class="rb1" value="开始随机设置人气" /></td>

            </tr>

        </table> 

        </form>           



		<form name="form3" action="?action=hitranda" method="post">

		<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">

        	<tr>

            	<td class="td_title">&nbsp;文章人气随机工具</td>

            </tr>

            <tr>

           	  <td class="td_border" height="30">&nbsp;随机人气范围：<input type="text" size="4" name="start_hits" value="1">至<input type="text" size="4" name="end_hits" value="1000">

           	    &nbsp; 文章分类：

                <select name="ClassIDs">

                  <option value="0">所有内容</option>

                  <?php

         //舞曲分类

		$sqlclassa="select * from s_class where S_SystemID=2 ";

		$resultsa=$db->query($sqlclassa);

		if($resultsa){

			$classstra="";

			while ($row3a=$db->fetch_array($resultsa)){

				$classstra.="<option value=".$row3a['S_ID'].">".$row3a['S_Name']."</option>";

				}

			}

									?>

                  <?php echo $classstra?>

                </select>                &nbsp;指定天数:

                <select name="sday">

                	<option value="">不限</option>

                    <?php

                    	for($i=1;$i<16;$i++){

							echo "<option value=\"".$i."\">".$i."天内</option>\r\n";

							}

					?>

                </select>

                &nbsp; 每页<input name="count" type="text" size="4" value="30">条

                &nbsp; <input name="submit" type="submit" class="rb1" value="开始随机设置人气" /></td>

            </tr>

        </table> 

        </form>

        

        <form name="form1" action="?action=replacement" method="post">

		<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">

        	<tr>

            	<td class="td_title">&nbsp;数据批量替换</td>

            </tr>

            <tr>

            	<td class="td_border">&nbsp;将

                <select name="S_Table" id="S_Table" >

                	<option value="">选择表</option>

                	<option value="S_Video">舞曲表</option>

                    <option value="S_Article">文章表</option>

                </select>

                <span id="select_r">



                </span>字段中的字符&nbsp;<input type="text" id="Old_Str" name="Old_Str">&nbsp;替换成&nbsp;<input type="text" name="New_Str" id="New_Str">&nbsp;<input type="button" value="确定替换" class="rb1" id="btn_rep"></td>

            </tr>

             <tr>

            	<td class="td_border" height="30">&nbsp;<font color='red'>注意：操作前请先备份数据库!</font>

</td>

            </tr>

             <tr>

            	<td class="td_border" height="30">&nbsp;<font color='red'>程序遇到待替换的字符就会立即替换且不可恢复，请小心处理。</font>

</td>

            </tr>            

        </table> 

        </form> 

   

     		</div>

        </div>

     </div>       

<?php include "../admin_bottom.php"; ?>

</body>

</html>