<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[22]!=1)
{
  Header("Location: jump.php?id=25&jump=main.php");
  exit();
}
$phpcolor->table=$core_mysql_prefix."message";
if(isset($_GET['action']) and $_GET['action'] == "del")
{
  if(isset($_GET['id']))
    $_POST['id'][0]=$_GET['id'];
  for($i=0;$i<count($_POST['id']);$i++)
  {
    $phpcolor->where="id='".$_POST['id'][$i]."'";
    $phpcolor->delete();
  }
  Header("Location: jump.php?id=24&jump=message.php");
}
elseif(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "show")
{
  $phpcolor->table=$core_mysql_prefix."message";
  $phpcolor->field="*";
  $phpcolor->where="id='".$_GET['id']."'";
  $message = $phpcolor->exist(1);
  $tpl -> assign("message", $message);
  $tpl -> display("message_show.htm");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->field="*";
  if(isset($_GET['search']) and isset($_GET['theme']))
  {
    if($_GET['search']==1)
    {
      $phpcolor->where="theme like '%".$_GET['theme']."%'";
      $count=$phpcolor->exist(2);
      $phpcolor->where="theme like '%".$_GET['theme']."%' order by id desc limit ".($_GET['page']*20).",20";
	}
	elseif($_GET['search']==2)
	{
	  $phpcolor->where="addresser like '%".$_GET['theme']."%'";
      $count=$phpcolor->exist(2);
      $phpcolor->where="addresser like '%".$_GET['theme']."%' order by id desc limit ".($_GET['page']*20).",20";
	}
	else
	{
	  $phpcolor->where="addressee like '%".$_GET['theme']."%'";
      $count=$phpcolor->exist(2);
      $phpcolor->where="addressee like '%".$_GET['theme']."%' order by id desc limit ".($_GET['page']*20).",20";
	}
	$page=pages($count,20,$_GET['page'],'message','&theme='.$_GET['theme'].'&type=',$_GET['type'],'0');
  }
  else
  {
	$phpcolor->where="1=1";
    $count=$phpcolor->exist(2);
    $phpcolor->where="1=1 order by id desc limit ".($_GET['page']*20).",20"; 
    $page=pages($count,20,$_GET['page'],'message','','','0');
  }
  $message=$phpcolor->assignment();
  $tpl -> assign("message", $message);
  $tpl -> assign("page", $page);
  $tpl -> display("message.htm");
}
?>