<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[4]!=1)
{
  Header("Location: jump.php?id=25&jump=main.php");
  exit();
}
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);
  Header("Location: jump.php?id=24&jump=cache.php");
}
elseif(isset($_GET['action']) && $_GET['action']=="user")
{
  $phpcolor->table=$core_mysql_prefix."user";
  $phpcolor->field="username";
  $phpcolor->where="1=1";
  $user=$phpcolor->assignment();
  for ($count=0;$count<count($user);$count++)
  {
    $phpcolor->table=$core_mysql_prefix."topic";
	$phpcolor->field="*";
	$phpcolor->where="author = '".$user[$count]['username']."'";
	$topic=$phpcolor->exist(2);
	$phpcolor->table=$core_mysql_prefix."repost";
	$repost=$phpcolor->exist(2);
	$phpcolor->table=$core_mysql_prefix."user";
    $phpcolor->field="topic='".$topic."',reply='".$repost."'";
    $phpcolor->where="username='".$user[$count]['username']."'";
	$phpcolor->upgrade();
  }
  Header("Location: jump.php?id=24&jump=cache.php");
}
elseif(isset($_GET['action']) && $_GET['action']=="uploaddela")
{
  if(!isset($_GET['page']))
    $_GET['page']=="0";
  $phpcolor->table=$core_mysql_prefix."upload";
  $phpcolor->field="*";
  $phpcolor->where="1 = 1";
  $file=$phpcolor->assignment();
  for ($count=0;$count<count($file);$count++)
  {
    $cz="0";
    $phpcolor->table=$core_mysql_prefix."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=$core_mysql_prefix."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=$core_mysql_prefix."upload";
      $phpcolor->where="id = '".$file[$count]['id']."'";
      $phpcolor->delete();
	}
  }
  Header("Location: jump.php?id=24&jump=cache.php");
}
elseif(isset($_GET['action']) && $_GET['action']=="uploaddelb")
{
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60);
  $time=strtotime($time)-86400;
  $time=date("Y-m-d H:i:s", $time);
  $phpcolor->table=$core_mysql_prefix."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();
  Header("Location: jump.php?id=24&jump=cache.php");
}
else
  $tpl -> display("cache.htm");
?>