<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[20]!=1)
  jump("jump.php?id=25&jump=main.php");
$phpcolor->table="attest";
$phpcolor->where="id = '".$_GET['id']."'";
if(isset($_GET['action']) and $_GET['action'] == "del" and isset($_GET['id']))
{
  $phpcolor->field="*";
  $phpcolor->delete();
  jump("jump.php?id=24&jump=attest.php");
}
if(isset($_GET['action']) and $_GET['action'] == "yes" and isset($_GET['id']))
{
  $phpcolor->field="type='1'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=attest.php");
}
if(isset($_GET['action']) and $_GET['action'] == "no" and isset($_GET['id']))
{
  $phpcolor->field="type='3'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=attest.php");
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "edit")
{
  $phpcolor->field="*";
  $attest = $phpcolor->exist(1);
  $attest['info'] = str_replace("<br />","",$attest['info']);
  $phpcolor->table="user";
  $phpcolor->field="username";
  $phpcolor->where="id = '".$attest['uid']."'";
  $rs=$phpcolor->exist(1);
  $attest['username']=$rs['username'];
  $tpl -> assign("attest", $attest);
  $tpl -> display("attest_edit.htm");
}
elseif(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "editdo")
{
  if($_POST['attest']=="" or strlen($_POST['attest'])>200 or $_POST['info']=="" or strlen($_POST['info'])>20000)
    jump("jump.php?id=8&jump=attest.php?action=edit=and=id=".$_GET['id']);
  $_POST['attest']=bn_replace($_POST['attest']);
  $phpcolor->field="attest='".$_POST['attest']."', info='".$_POST['info']."'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=attest.php");
}
elseif(isset($_GET['action']) and $_GET['action'] == "add")
  $tpl -> display("attest_add.htm");
elseif(isset($_GET['action']) and $_GET['action'] == "adddo")
{
  if($_POST['attest']=="" or $_POST['info']=="")
    jump("jump.php?id=2&jump=attest.php");
  if(strlen($_POST['attest'])>200 or strlen($_POST['info'])>20000)
    jump("jump.php?id=8&jump=attest.php");
  $phpcolor->table="user";
  $phpcolor->field="id";
  $phpcolor->where="username = '".$_POST['username']."'";
  if(!$rs=$phpcolor->exist(1))
    jump("jump.php?id=1&jump=attest.php");
  $phpcolor->table="attest";
  $phpcolor->field="*";
  $phpcolor->where="uid = '".$rs['id']."'";
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60);
  if($phpcolor->exist(2))
    jump("jump.php?id=4&jump=attest.php");
  $_POST['attest']=bn_replace($_POST['attest']);
  $phpcolor->field="uid, attest, info, time, type";
  $phpcolor->where="'".$rs['id']."','".$_POST['attest']."','".$_POST['info']."','".$time."','1'";
  $phpcolor->write();
  jump("attest.php");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->field="*";
  if(isset($_GET['theme']))
  {
	$phpcolor->table="user";
	$phpcolor->field="id";
    $phpcolor->where="username = '".$_GET['theme']."'";
    $rs=$phpcolor->exist(1);
	$phpcolor->table="attest";
    $phpcolor->where="uid = '".$rs['id']."'";
    $count = $phpcolor->exist(2);
    $phpcolor->where="uid = '".$rs['id']." order by time desc' limit ".($_GET['page']*20).",20";
	$phpcolor->field="*";
    $page=pages($count,20,$_GET['page'],'attest','&theme=',$_GET['theme'],'0');
  }
  else
  {
    if(isset($_GET['type']) and $_GET['type']=="yes")
    {
	  $phpcolor->where="type = '1'";
      $count = $phpcolor->exist(2);
	  $phpcolor->where="type = '1' order by time desc limit ".($_GET['page']*20).",20";
	  $page=pages($count,20,$_GET['page'],'attest','&type=','yes','0');
	}
    elseif(isset($_GET['type']) and $_GET['type']=="dsh")
    {
      $phpcolor->where="type = '0'";
      $count = $phpcolor->exist(2);
      $phpcolor->where="type = '0' order by time desc limit ".($_GET['page']*20).",20";
	  $page=pages($count,20,$_GET['page'],'attest','&type=','dsh','0');
	}
    elseif(isset($_GET['type']) and $_GET['type']=="no")
    {
      $phpcolor->where="type = '2' or type = '3'";
      $count = $phpcolor->exist(2);
      $phpcolor->where="type = '2' or type = '3' order by time desc limit ".($_GET['page']*20).",20";
	  $page=pages($count,20,$_GET['page'],'attest','&type=','no','0');
	}
	else
	{
	  $phpcolor->where="1=1";
      $count = $phpcolor->exist(2);
      $phpcolor->where="1=1 order by time desc limit ".($_GET['page']*20).",20";
	  $page=pages($count,20,$_GET['page'],'attest','','','0');
	}
  }
  $attest=$phpcolor->assignment();
  $phpcolor->table="user";
  for($count=0;$count<count($attest);$count++)
  {
    $phpcolor->field="username";
    $phpcolor->where="id = '".$attest[$count]['uid']."'";
    $rs=$phpcolor->exist(1);
    $attest[$count]['username']=$rs['username'];
  }
  $tpl -> assign("attest", $attest);
  $tpl -> assign("page", $page);
  $tpl -> display("attest.htm");
}
?>