<?php
	//清理测试数据及图片 -tt- , 清理 log feedback stastic 
	require_once('_approot.php');	

	$opertb=new mytb();
	//$cleartable="ls_products,ls_news,ls_message,ls_article,ls_singlepages,ls_download,ls_video";
	$gentable="workshop,certificate,quality,packing,revolvingpics,rd,brand,management,history"; //通用图片处理
	$cleartable="ls_products,ls_news,ls_message,ls_article,ls_singlepages,ls_download,ls_video,ls_internal,ls_links,ls_functioncates,ls_pro_feedback"; // 
	$TRUNCATEtable="ls_writefiles,ls_keywords,ls_select_id"; //本地删除
	

	$Actionarr=explode(",",$cleartable);

	
	for($j=0;$j<count($Actionarr); $j++)
	{
	
	$Action=trim($Actionarr[$j]);
	//var_dump($Actionarr,$Action);
//	if(strpos($gentable ,$Action)!==false)$_GET['gen']=$Action; else $_GET['gen']="";
	
	switch ($Action){
		
		
		case "ls_products":	//删除产品
				$clear_sql="select * from ls_products where productName like '%-tt-%' or  cateName  like '%-tt-%' or  subcateName like '%-tt-%' or    midcateName like '%-tt-%' or  productTitle  like '%-tt-%' ";
				$clear_query=$opendb->query($clear_sql);
				$clear_num=mysqli_num_rows($clear_query);
				for($i=0;$i<$clear_num; $i++){	
					$cate_myrows=mysqli_fetch_assoc($clear_query);		
					$id=$cate_myrows['ID'];
					if ($id!=""){
						//获取文件目录
						
						$products_sql="select * from ls_products where ID=".$id." ";
						$products_query=$opendb->query($products_sql);
						$products_rows=mysqli_fetch_assoc($products_query);
						 
						$thisProductsFloder=trim(getproductfolder($products_rows['productID']));
						if($thisProductsFloder=="") continue;
						$Bigpicsrc1="../".$thisProductsFloder ;
						deldir($Bigpicsrc1);
						$del_sql="delete from ls_products where ID=".$id;
						$del_query=$opendb->query($del_sql);
					}
			  }
			  echo "ls_products $clear_num 已清空 <br/>";

		  break;	
		  
		 case "ls_functioncates"://删除新闻、博客、常见问题分类
				$clear_sql="select * from ls_functioncates where cateName like '%-tt-%' or  functionName like '%-tt-%' "; 
				$clear_query=$opendb->query($clear_sql);
				$clear_num=mysqli_num_rows($clear_query);
				for($i=0;$i<$clear_num; $i++){	
					$cate_myrows=mysqli_fetch_assoc($clear_query);		
					$id=$cate_myrows['ID'];	
					{
						 $del_sql="delete from ls_functioncates where ID=".$id."";
						//echo $del_sql."<br>";
						$del_query=$opendb->query($del_sql);
					}
				}
 
	
		 echo "ls_functioncates 新闻、博客、常见问题分类 $clear_num 已清空 <br/>";
		 break;

		 
		 case "ls_news": //删除新闻、常见问题、博客
				$clear_sql="select * from ls_news where newsTitle like '%-tt-%' ";
				$clear_query=$opendb->query($clear_sql);
				$clear_num=mysqli_num_rows($clear_query);
				for($i=0;$i<$clear_num; $i++){	
					$cate_myrows=mysqli_fetch_assoc($clear_query);		
					$id=$cate_myrows['ID'];	
					{
						 $del_sql="delete from ls_news where ID=".$id."";
						//echo $del_sql."<br>";
						$del_query=$opendb->query($del_sql);
					}
				}
 
				  echo "ls_news 已清空 $clear_num 条  <br/>";
				
				break;	
				
 			 case "ls_article": //删除文章
				$clear_sql="select * from ls_article where articleTitle like '%-tt-%' ";
				$clear_query=$opendb->query($clear_sql);
				$clear_num=mysqli_num_rows($clear_query);
				for($i=0;$i<$clear_num; $i++){	
					$cate_myrows=mysqli_fetch_assoc($clear_query);		
					$id=$cate_myrows['ID'];	
						{
						 		$del_sql="delete from ls_article where ID=".$id."";
				   			//echo $del_sql."<br>";
				   			$del_query=$opendb->query($del_sql);
				   		}
				   	 
				   	}
				  echo " ls_article 已清空 $clear_num 条  <br/>";
		   			
				 	break;	
			 	
			 case "ls_singlepages": //删除文章
			 
				$clear_sql="select * from ls_singlepages where pageTitle like '%-tt-%' ";
				$clear_query=$opendb->query($clear_sql);
				$clear_num=mysqli_num_rows($clear_query);
				for($i=0;$i<$clear_num; $i++){	
					$cate_myrows=mysqli_fetch_assoc($clear_query);		
					$id=$cate_myrows['ID'];	
					{
						 		$del_sql="delete from ls_singlepages where ID=".$id."";
				   			//echo $del_sql."<br>";
				   				$del_query=$opendb->query($del_sql);
				   			}
				   	  		 
				   	}
					  echo " ls_singlepages 已清空 $clear_num 条  <br/>";
	   			
				 	break;	
			
			
		 case "ls_download"://删除下载
		 	 $opertb->table="ls_download";
				$clear_sql="select * from ls_download where downloadTitle like '%-tt-%' ";
				$clear_query=$opendb->query($clear_sql);
				$clear_num=mysqli_num_rows($clear_query);
				for($i=0;$i<$clear_num; $i++){	
					$cate_myrows=mysqli_fetch_assoc($clear_query);		
					$id=$cate_myrows['ID'];	
						{
							 

							$opertb->id=$id;
							$ls_msg=$opertb->delwfile($downloadFolders,"","downloadName");
						
						}
				}
				 echo " ls_download 已清空 $clear_num 条, 上传文件已删除  <br/>";
				
				break;	
				
		 
				
		case "ls_video"://删除视频 videoName
		
		 	 $opertb->table="ls_video";
				$clear_sql="select * from ls_video where videoName like '%-tt-%' ";
				$clear_query=$opendb->query($clear_sql);
				$clear_num=mysqli_num_rows($clear_query);
				for($i=0;$i<$clear_num; $i++){	
					$cate_myrows=mysqli_fetch_assoc($clear_query);		
					$id=$cate_myrows['ID'];	
						{
							 

							$opertb->id=$id;
							$ls_msg=$opertb->delwfile($downloadFolders,"","videoFile");
						
						}
				}
				 echo " ls_video 已清空 $clear_num 条, 上传视频已删除  <br/>";
				
				break;	
				

			
		case "ls_pro_feedback"://删除反馈 requirement
			
			 
				$clear_sql="select * from ls_pro_feedback where requirement like '%-tt-%' ";
				$clear_query=$opendb->query($clear_sql);
				$clear_num=mysqli_num_rows($clear_query);
				for($i=0;$i<$clear_num; $i++){	
					$cate_myrows=mysqli_fetch_assoc($clear_query);		
					$id=$cate_myrows['ID'];	
					{
						 		$del_sql="delete from ls_pro_feedback where ID=".$id."";
				   			//echo $del_sql."<br>";
				   				$del_query=$opendb->query($del_sql);
				   			}
				   	  		 
				   	}
			  echo " ls_pro_feedback 已清空 $clear_num 条  <br/>";
	   			
			break;	
			 

		case "ls_internal"://删除老的常见问题
				$clear_sql="select * from ls_internal where title like '%-tt-%' ";
				$clear_query=$opendb->query($clear_sql);
				$clear_num=mysqli_num_rows($clear_query);
				for($i=0;$i<$clear_num; $i++){	
					$cate_myrows=mysqli_fetch_assoc($clear_query);		
					$id=$cate_myrows['ID'];	
					{
						 		$del_sql="delete from ls_pro_feedback where ID=".$id."";
				   			//echo $del_sql."<br>";
				   				$del_query=$opendb->query($del_sql);
				   			}
				   	  		 
				   	}
			  echo " ls_internal 已清空 $clear_num 条  <br/>";		 
		 	break;
			
 
			
		case "ls_motif"://主题图片
				
				$clear_sql="select * from ls_motif  where motifText like '%-tt-%'  ";
				$clear_query=$opendb->query($clear_sql);
				$clear_num=mysqli_num_rows($clear_query);
				for($i=0;$i<$clear_num; $i++){	
					$cate_myrows=mysqli_fetch_assoc($clear_query);		
					$id=$cate_myrows['ID'];	
						{
						$select_sql="select * from ls_motif where ID=".$id."";
						$select_query=$opendb->query($select_sql);
						$select_myrows=mysqli_fetch_assoc($select_query);
						//获取文件目录
						$Bigpicsrc="../".$MotifFolders."/".$BigFoldersProducts."/".$select_myrows['motifPic'];
							//$Smallpicsrc="../".$MotifShopFolders."/".$SmallFoldersProducts."/".$select_myrows['workshopPic'];
							//删除文件
						if(file_exists($Bigpicsrc))		unlink($Bigpicsrc);
							//unlink($Smallpicsrc);
						$del_sql="delete from ls_motif where ID=".$id."";
							//echo $del_sql;
						$del_query=$opendb->query($del_sql);
						
					}
				}
				echo "ls_motif 已清空 $clear_num 条 <br/>";
				
				break;

		case "ls_links"://友情链接
				
				$clear_sql="select * from ls_links  where linkTitle like '%-tt-%'  ";
				$clear_query=$opendb->query($clear_sql);
				$clear_num=mysqli_num_rows($clear_query);
				for($i=0;$i<$clear_num; $i++){	
					$cate_myrows=mysqli_fetch_assoc($clear_query);		
					$id=$cate_myrows['ID'];	
						{
						$select_sql="select * from ls_links where ID=".$id."";
						$select_query=$opendb->query($select_sql);
						$select_myrows=mysqli_fetch_assoc($select_query);
						$del_sql="delete from ls_links where ID=".$id."";
							//echo $del_sql;
						$del_query=$opendb->query($del_sql);
						
					}
				}
				echo "ls_links 已清空 $clear_num 条 <br/>";
				
				break;
		}

	} // end for
	
	
	$Actionarr=explode(",",$gentable);

	
	for($j=0;$j<count($Actionarr); $j++)
	{
	
		$Action=trim($Actionarr[$j]);
		$_GET['gen']=$Action;
		require('generalpicrequire.php');  //通用图片文件开关语句
		//echo $generalTable."- table";
		if(mysqli_num_rows($opendb->query("SHOW TABLES LIKE '".$generalTable."' "))==1)  // 表是否存在
		{
				$opertb->table=$generalTable;
				$clear_sql="select * from  ".$generalTable."  where $generalpicsTitle like '%-tt-%'  ";
				$clear_query=$opendb->query($clear_sql);
				$clear_num=mysqli_num_rows($clear_query);
				for($i=0;$i<$clear_num; $i++){	
					$cate_myrows=mysqli_fetch_assoc($clear_query);		
					$id=$cate_myrows['ID'];	
					$opertb->id=$id;
					 
					$ls_msg=$opertb->delwfile($folder1,$folder2,$generalpicsPic);
				}
				echo  $generalTable." 已清空 $clear_num 条 <br/>";
		}
			
	}
	if(strpos($_SERVER["SERVER_ADDR"],"192.168.2")!==false||strpos($_SERVER["SERVER_ADDR"],"::1")!==false){ //网上不删除

		$Actionarr=explode(",",$TRUNCATEtable);
		for($j=0;$j<count($Actionarr); $j++)
		{
		
			$Action=trim($Actionarr[$j]);
			//echo $Action."- table";
			if(mysqli_num_rows($opendb->query("SHOW TABLES LIKE '".$Action."' "))==1)  // 表是否存在
			{
					 
					$clear_sql="DELETE FROM ".$Action." WHERE 1   ";
					$clear_query=$opendb->query($clear_sql);
					 
					echo $Action." 已清空 $clear_num 条 <br/>";
			}
				
		}
	}
	
	$clear_sql="TRUNCATE TABLE `ls_statistics` ";
	$clear_query=$opendb->query($clear_sql);

	$clear_sql="TRUNCATE TABLE `ls_pro_feedback` ";
	$clear_query=$opendb->query($clear_sql);

	$clear_sql="TRUNCATE TABLE `ls_log` ";
	$clear_query=$opendb->query($clear_sql);


	 $mid=midfolder($_SERVER['PHP_SELF']);
	 xdel("../../flllbak",  "../../".$mid);
	
	echo  "<br/>相关文件已删除。 <br/>";
	?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link href="css/style2.css" rel="stylesheet"  type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
