<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[5]!=1 && isset($_GET['action']) && $_GET['action'] == "foreground")
{
  Header("Location: jump.php?id=25&jump=main.php");
  exit();
}
if($ppurview[6]!=1 && isset($_GET['action']) && $_GET['action'] == "back")
{
  Header("Location: jump.php?id=25&jump=main.php");
  exit();
}
$phpcolor->table=$core_mysql_prefix."log";
if(isset($_GET['action']) and $_GET['action'] == "cleared" and isset($_GET['type']))
{
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60-24*60*60*7);
  $phpcolor->where="type = '".$_GET['type']."' && operatetime < '".$time."'";
  $phpcolor->delete(); 
  if($_GET['type']==2)
    Header("Location: log.php?action=foreground");
  else
    Header("Location: log.php?action=back");
}
elseif(isset($_GET['action']) and $_GET['action'] == "del" and isset($_GET['type']))
{
  $phpcolor->where="id = '".$_GET['id']."'";
  $phpcolor->delete(); 
  if($_GET['type']==2)
    Header("Location: log.php?action=foreground");
  else
    Header("Location: log.php?action=back");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  if(isset($_GET['action']) and $_GET['action'] == "back")
  {
    $phpcolor->field="*";
    $phpcolor->where="type = '1'";
    $count = $phpcolor->exist(2);
    $phpcolor->where=" type = '1' order by operatetime desc limit ".($_GET['page']*20).",20";
    $page=pages($count,20,$_GET['page'],'log','&action=','back','0');
  }
  else
  {
    $phpcolor->field="*";
    $phpcolor->where="type = '2'";
    $count = $phpcolor->exist(2);
    $phpcolor->where=" type = '2' order by operatetime desc limit ".($_GET['page']*20).",20";
    $page=pages($count,20,$_GET['page'],'log','&action=','foreground','0');
  }
  $log=$phpcolor->assignment();
  $tpl -> assign("log", $log);
  $tpl -> assign("page", $page);
  if(isset($_GET['action']) and $_GET['action'] == "back")
    $tpl -> display("log_back.htm");
  else
    $tpl -> display("log_foreground.htm");
}
?>