<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[11]!=1)
{
  Header("Location: jump.php?id=25&jump=main.php");
  exit();
}
if(isset($_GET['action']) and isset($_GET['id']) and isset($_GET['cid']) and isset($_GET['bn']) and $_GET['action'] == "yes")
{
  $phpcolor->table=$core_mysql_prefix."bar";
  $phpcolor->field="barclass='".$_GET['cid']."'";
  $phpcolor->where="barname = '".$_GET['bn']."'";
  $phpcolor->upgrade();
  $phpcolor->table=$core_mysql_prefix."apply_sort";
  $phpcolor->field="username";
  $phpcolor->where="id='".$_GET['id']."'";
  $user=$phpcolor->exist(1);
  $phpcolor->delete();
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60);
  $email_flyest=str_replace("{username}",$user['username'],$email_flyest);
  $email_flyest=str_replace("{barname}",$_GET['bn'],$email_flyest);
  $email_flyesc=str_replace("{username}",$user['username'],$email_flyesc);
  $email_flyesc=str_replace("{barname}",$_GET['bn'],$email_flyesc);
  $phpcolor->table=$core_mysql_prefix."message";
  $phpcolor->field="theme, content, addresser, addressee, sent, type";
  $phpcolor->where="'".$email_flyest."', '".$email_flyesc."', '".$email_addresser."', '".$user['username']."', '".$time."', '2'";
  $phpcolor->write();
  Header("Location: jump.php?id=24&jump=apply_sort.php");
}
elseif(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "no")
{
  $phpcolor->table=$core_mysql_prefix."apply_sort";
  $phpcolor->field="username";
  $phpcolor->where="id='".$_GET['id']."'";
  $user=$phpcolor->exist(1);
  $phpcolor->delete();
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60);
  $email_flnot=str_replace("{username}",$user['username'],$email_flnot);
  $email_flnot=str_replace("{barname}",$_GET['bn'],$email_flnot);
  $email_flnoc=str_replace("{username}",$user['username'],$email_flnoc);
  $email_flnoc=str_replace("{barname}",$_GET['bn'],$email_flnoc);
  $phpcolor->table=$core_mysql_prefix."message";
  $phpcolor->field="theme, content, addresser, addressee, sent, type";
  $phpcolor->where="'".$email_flnot."', '".$email_flnoc."', '".$email_addresser."', '".$user['username']."', '".$time."', '2'";
  $phpcolor->write();
  Header("Location: jump.php?id=24&jump=apply_sort.php");
}
elseif(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "show")
{
  $phpcolor->table=$core_mysql_prefix."apply_sort";
  $phpcolor->field="*";
  $phpcolor->where="id='".$_GET['id']."'";
  $apply = $phpcolor->exist(1);
  $phpcolor->table=$core_mysql_prefix."bar";
  $phpcolor->field="id";
  $phpcolor->where="barname = '".$apply['barname']."'";
  $rs=$phpcolor->exist(1);
  $apply['barid']=$rs['id'];
  $phpcolor->table=$core_mysql_prefix."class";
  $phpcolor->field="classname";
  $phpcolor->where="id = '".$apply['sort']."'";
  $rs=$phpcolor->exist(1);
  $apply['classname']=$rs['classname'];
  $tpl -> assign("apply", $apply);
  $tpl -> display("apply_sort_show.htm");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->table=$core_mysql_prefix."apply_sort";
  $phpcolor->field="*";
  $phpcolor->where="1=1";
  $count = $phpcolor->exist(2);
  $phpcolor->where="1=1 limit ".($_GET['page']*20).",20";
  $apply = $phpcolor->assignment();
  for($count=0;$count<count($apply);$count++)
  {
    $phpcolor->table=$core_mysql_prefix."class";
    $phpcolor->field="classname";
    $phpcolor->where="id='".$apply[$count]['sort']."'";
    $sort[] = $phpcolor->exist(1);
    $phpcolor->table=$core_mysql_prefix."bar";
    $phpcolor->field="id";
    $phpcolor->where="barname='".$apply[$count]['barname']."'";
    $rs=$phpcolor->exist(1);
    $apply[$count]['barid'] = $rs['id'];
  }
  $page=pages($count,20,$_GET['page'],'apply_sort','','','0');
  $tpl -> assign("apply", $apply);
  $tpl -> assign("sort", $sort);
  $tpl -> assign("page", $page);
  $tpl -> display("apply_sort.htm");
}
?>