<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
include_once("../../lib/cs_label.php");
include_once("../loginstate.php");
SystemPer('5_5');
$ac=CS_Request("ac");
if(empty($ac)) $ac=1;
@set_time_limit(0);
echo("<link href=\"../res/css/admin_style.css\" rel=\"stylesheet\" /><div class=\"h_a\">&nbsp;正在移除无效图片链接</div>");

if($ac==1){
	checkimg('dance',"dance","歌曲");
	die("<br/><font style=font-size:13px;>&nbsp;&nbsp;&nbsp;无效<font color=red>歌曲图片</font>删除完毕!暂停3秒后检测无效文章图片．．．</font><br/><script language='javascript'>setTimeout('ReadGo();',".(3000).");function ReadGo(){location.href='?ac=2';}</script></br>");
}elseif($ac==2){
	checkimg('news',"news","文章");
	die("<br/><font style=font-size:13px;>&nbsp;&nbsp;&nbsp;无效<font color=red>文章图片</font>删除完毕!暂停3秒后检测无效专集图片．．．</font><br/><script language='javascript'>setTimeout('ReadGo();',".(3000).");function ReadGo(){location.href='?ac=3';}</script></br>");
}elseif($ac==3){
	checkimg('topic',"topic","专集");
	die("<br/><font style=font-size:13px;>&nbsp;&nbsp;&nbsp;无效<font color=red>专集图片</font>删除完毕!暂停3秒后检测无效会员头像图片．．．</font><br/><script language='javascript'>setTimeout('ReadGo();',".(3000).");function ReadGo(){location.href='?ac=4';}</script></br>");
}elseif($ac==4){
	checkimg('logo',"logo","会员头像");
	die("<br/><font style=font-size:13px;>&nbsp;&nbsp;&nbsp;无效<font color=red>会员头像图片</font>删除完毕!暂停3秒后检测相册图片．．．</font><br/><script language='javascript'>setTimeout('ReadGo();',".(3000).");function ReadGo(){location.href='?ac=5';}</script></br>");
}elseif($ac==5){
	checkimg('pic',"pic","相册");
	die("<br/><font style=font-size:13px;>&nbsp;&nbsp;&nbsp;无效<font color=red>相册图片</font>删除完毕!暂停3秒后检测会员主页背景图片．．．</font><br/><script language='javascript'>setTimeout('ReadGo();',".(3000).");function ReadGo(){location.href='?ac=6';}</script></br>");
}elseif($ac==6){
	checkimg('bg',"bg","会员主页背景");
	die("<br/><font style=font-size:13px;>&nbsp;&nbsp;&nbsp;无效<font color=red>会员主页背景图片</font>删除完毕!暂停3秒后检测会员主页标题图片．．．</font><br/><script language='javascript'>setTimeout('ReadGo();',".(3000).");function ReadGo(){location.href='?ac=7';}</script></br>");
}elseif($ac==7){
	checkimg('top',"top","会员主页标题");
	die("<br/><font style=font-size:15px;>&nbsp;&nbsp;&nbsp;无效<font color=red>会员主页标题图片</font>删除完毕,&nbsp;<font color=#0000ff>恭喜你！所有无效图片删除完毕．．．</font></font><br/>");
}



function checkimg($folder,$table,$title){
global $db;
   if($table=="logo"){  //会员头像
	$d="../../annex/".$folder."/big";
	$d2="../../annex/".$folder."/small";
	if (is_dir($d)) {
	  	$dh=opendir($d);//打开目录
  		//列出目录中的所有文件并去掉 . 和 ..
 		 while (false !== ( $file = readdir ($dh))) {
   			if($file!="." && $file!="..") { 
      			   $fullpath=$d."/".$file;
      			   $fullpath2=$d2."/".$file;
      			   if(!is_dir($fullpath)) {  
                                        $sql="select CS_Logo from ".Getdbname('user')." where CS_Logo='".$file."'";
					$CS_ID=$db->getOne($sql);
					if(!$CS_ID){
					        @unlink($fullpath);//删除无效图片
                                                @unlink($fullpath2);
						echo "&nbsp;<font style=font-size:12px;><font color=red>".$file."</font>".$title."无效图片已经删除...</font></br>";
					}
      			   }		
     			} 
		}
   		closedir($dh);
   	}
   }else{
	$d="../../annex/".$folder;
	if (is_dir($d)) {
	  	$dh=opendir($d);//打开目录
  		//列出目录中的所有文件并去掉 . 和 ..
 		 while (false !== ( $file = readdir ($dh))) {
   			if($file!="." && $file!="..") { 
      			   $fullpath=$d."/".$file;
      			   if(!is_dir($fullpath)) { 
                               if($table=="pic"){  //相册
				    $CS_XID=$db->getOne("select CS_Pic from ".Getdbname('pic')." where CS_Pic='$file'");
				    $CS_PID=$db->getOne("select CS_Url from ".Getdbname('photo')." where CS_Url='$file'"); 
				    if(!$CS_XID && !$CS_PID){
					@unlink($fullpath);//删除无效图片
					echo "&nbsp;<font style=font-size:12px;><font color=red>".$file."</font>".$title."无效图片已经删除...</font></br>";
				    } 
                               }else{
                                    if($table=="bg"){
				    	$sql="select CS_Bgpic from ".Getdbname('user')." where CS_Bgpic='$file'";
                                    }elseif($table=="top"){
					$sql="select CS_Toppic from ".Getdbname('user')." where CS_Toppic='$file'";
                                    }else{	
					$sql="select CS_Pic from ".Getdbname($table)." where CS_Pic='$file'";
                                    }
					$CS_ID=$db->getOne($sql);
					if(!$CS_ID){
					        @unlink($fullpath);//删除无效图片
						echo "&nbsp;<font style=font-size:12px;><font color=red>".$file."</font>".$title."无效图片已经删除...</font></br>";
					}
                               }
      			   }		
     			} 
		}
   	}
   		closedir($dh);
   }
}
?>
