<?
include(dirname(__FILE__)."/global.php");




include("../../include/pinyin.php");


?>

<link href="css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
	text-decoration: none;
	color: #000000;
}
a:visited {
	text-decoration: none;
	color: #000000;
}
a:hover {
	text-decoration: underline;
	color: #FF0000;
}
a:active {
	text-decoration: none;
	color: #000000;
}
-->
</style>

<?

		$mid = 51;
		
$job = $_GET['job'];	
	
if( $job == 'star_search' ){

	$set_aid = $_GET['max_aid'] ? $_GET['max_aid'] : $_GET['set_aid'];//要操作的 aid ，第一次为最大 aid
	
	//取得当前操作的title
	$query  = "SELECT * FROM `w6_module_content_".$mid."` WHERE `aid` = '$set_aid'";
	$result =mysql_query( $query ) or die("Could not connect: " . mysql_error());
	$title  =  stripslashes(mysql_result($result,"0","title"));//这里有时会跳出不影响程序执行
	
	//查找 与当前 title 标题相同 的记录
	$query  = "SELECT * FROM `w6_module_content_".$mid."` WHERE `title` = '$title'";
	$result =mysql_query( $query ) or die("Could not connect: " . mysql_error());
	$num = mysql_num_rows($result);
	
	
	//如果num大于1说明有相同记录
	if( $num > 2 ){//一般为1 即不能有两个相同的
	
		echo '<form action="" method="get" name="form1" target="_blank" id="form1">';
		while($rs=mysql_fetch_array($result)){
			echo '
			<input type="checkbox" name="delAidDb[]" value="'.$rs['aid'].'" style="border:0px;" checked />
			<font color="#990000" >aid：'.$rs['aid'].'</font>：
			<img src="../../images/newrank/'.$rs['jbtb'].'" alt="'.$rs['jbtb_sm'].'" border="0" />
			'.$rs['cp_jj'].'
			：<a href="../../show.php?aid='.$rs['aid'].'" target="_blank">'.$rs['title'].'</a>
			<a href="article_modify.php?aid='.$rs['aid'].'&fid='.$rs['fid'].'&mid='.$rs['module_id'].'" target="_blank"><font color="#0000FF">点击修改</font></a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="article_list.php?job=del&aid='.$rs['aid'].'&fid='.$rs['fid'].'&mid='.$rs['module_id'].'" target="_blank"><font color="#FF0000">点击删除</font></a>
			<br /><br />
			
			';
		}
		echo '<input name="job" type="hidden" id="job" value="deldb" /><input type="submit" name="Submit" value=" 批量删除文章 "></FORM>';
		
	}else{//如果num为1说明没有相同记录，跳入下一条记录
		
		$set_aid--;//操作 aid 减 1
		echo "跳入下一条记录 aid = $set_aid <br> <meta http-equiv=\"refresh\" content=\"0;URL=?job=star_search&set_aid=$set_aid\">";
	}


}elseif( $job == 'deldb' ){

	$delAidDb = $_GET['delAidDb'];
	foreach($delAidDb AS $rs){
		//echo $rs.'<br />';
		$query  = "SELECT `aid`,`fid`,`module_id` FROM `w6_module_content_".$mid."` WHERE `aid` = '$rs'";
		$result =mysql_query( $query ) or die("Could not connect: " . mysql_error());
		$aid = $rs;
		$fid  =  stripslashes(mysql_result($result,"0","fid"));
		$mid  =  stripslashes(mysql_result($result,"0","module_id"));
		//echo $aid.','.$fid.','.$mid.'<br>';
		
		$query="DELETE FROM `w6_module_content_index` WHERE `id`='$aid' ";
		$result=mysql_query($query) or die( mysql_error() );

		$query="DELETE FROM `w6_module_content_$mid` WHERE `aid`='$aid' ";
		$result=mysql_query($query) or die( mysql_error() );
		if ($result)
		{
			echo "文章 ( $aid ) 删除成功！<br />";
		}
		else
		{
			echo '<font color="#FF0000">文章 ( $aid ) 删除失败！</font>';
		}


	}

	


}else{
	
		//取最大 aid
		$query   =  "SELECT max( aid ) FROM w6_module_content_$mid";
		$result  =  mysql_query($query);
		$max_aid =  mysql_result($result,"0","max( aid )");
		
		//得到文章总数
		$query  = "SELECT * FROM `w6_module_content_".$mid."`";
		$result =mysql_query( $query ) or die("Could not connect: " . mysql_error());
		$total = mysql_num_rows($result);
		
		echo '
		<div align="center"><br /><br /><br />本操作一共要从<font color="#FF0000"> '.$total .' </font>篇文章中查找相同的文章！
		<br /><br /><br />
		<a href="search_same.php?job=star_search&max_aid='.$max_aid.'" class="a_bt">&nbsp;&nbsp; 继续操作请点击这里 &nbsp;&nbsp;</a> 
		</div>
		';
}