<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[4]!=1)
  jump("jump.php?id=25&jump=main.php");
if(isset($_GET['action']) && $_GET['action']=="cache")
{
  is_dir("template_c");
  $handle = openDir("template_c");
  while(($file_name = readdir($handle))!==false)
  {
    if($file_name!="." && $file_name!="..")
	{
      $file_path = "template_c/".$file_name;
      unlink($file_path);
    }
  }
  closedir($handle);
  is_dir("../template_c");
  $handle = openDir("../template_c");
  while(($file_name = readdir($handle))!==false)
  {
    if($file_name!="." && $file_name!="..")
	{
      $file_path = "../template_c/".$file_name;
      unlink($file_path);
    }
  }
  closedir($handle);
  jump("jump.php?id=24&jump=cache.php");
}
elseif(isset($_GET['action']) && $_GET['action']=="uploaddela")
{
  if(!isset($_GET['page']))
    $_GET['page']=="0";
  $phpcolor->table="upload";
  $phpcolor->field="*";
  $phpcolor->where="qltype = 0 limit 100";
  $file=$phpcolor->assignment();
  $phpcolor->field="qltype = 1";
  $phpcolor->upgrade();
  for ($count=0;$count<count($file);$count++)
  {
    $cz="0";
    $phpcolor->table="topic";
	$phpcolor->field="*";
	$phpcolor->where="file = '".$file[$count]['id']."'";
	$cz=$phpcolor->exist(2);
	if($cz=="0")
	{
	  $phpcolor->where="file like '".$file[$count]['id']."|%'";
	  $cz=$phpcolor->exist(2);
	  if($cz=="0")
	  {
	    $phpcolor->where="file like '%|".$file[$count]['id']."'";
	    $cz=$phpcolor->exist(2);
		if($cz=="0")
	    {
	      $phpcolor->where="file like '%|".$file[$count]['id']."|%'";
	      $cz=$phpcolor->exist(2);
		  if($cz=="0")
	      {
	        $phpcolor->table="repost";
	        $phpcolor->where="file = '".$file[$count]['id']."'";
			$cz=$phpcolor->exist(2);
			if($cz=="0")
	        {
	          $phpcolor->where="file like '".$file[$count]['id']."|%'";
			  $cz=$phpcolor->exist(2);
			  if($cz=="0")
	          {
	            $phpcolor->where="file like '%|".$file[$count]['id']."'";
			    $cz=$phpcolor->exist(2);
				if($cz=="0")
	            {
	              $phpcolor->where="file like '%|".$file[$count]['id']."|%'";
			      $cz=$phpcolor->exist(2);
	            }
	          }
	        }
	      }
	    }
	  }
	}
	if($cz=="0")
	{
	  unlink('../upload/'.$file[$count]['filename']);
	  $phpcolor->table="upload";
      $phpcolor->where="id = '".$file[$count]['id']."'";
      $phpcolor->delete();
	}
  }
  if(count($file)!=0)
    jump("jump.php?page=".($_GET['page']+1)."&id=26&jump=cache.php?action=uploaddela=and=page=".($_GET['page']+1));
  $phpcolor->table="upload";
  $phpcolor->field="qltype = 0";
  $phpcolor->where="1 = 1";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=cache.php");
}
if(isset($_GET['action']) && $_GET['action']=="uploaddelb")
{
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $time=strtotime($time)-86400;
  $time=date("Y-m-d H:i:s", $time);
  $phpcolor->table="upload";
  $phpcolor->field="*";
  $phpcolor->where="type='0' and uptime<'".$time."'";
  $upload=$phpcolor->assignment();
  for ($count=0;$count<count($upload);$count++)
  {
    unlink('../upload/'.$upload[$count]['filename']);
  }
  $phpcolor->delete();
  jump("jump.php?id=24&jump=cache.php");
}
$tpl -> display("cache.htm");
?>