<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[22]!=1)
  jump("jump.php?id=25&jump=main.php");
$phpcolor->table="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();
  }
  jump("jump.php?id=24&jump=message.php");
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "show")
{
  $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['so']) and isset($_GET['theme']))
  {
    if($_GET['so']==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['so']==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();
  for ($count=0;$count<count($message);$count++)
  { 
    $message[$count]['content']=$phpcolor->mysubstr($message[$count]['content'],0,50);
  }
  $tpl -> assign("message", $message);
  $tpl -> assign("page", $page);
  $tpl -> display("message.htm");
}
?>