<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[11]!=1)
  jump("jump.php?id=25&jump=main.php");
if(isset($_GET['action']) and isset($_GET['id']) and isset($_GET['cid']) and isset($_GET['bn']) and $_GET['action'] == "yes")
{
  $phpcolor->table="bar";
  $phpcolor->field="barclass='".$_GET['cid']."'";
  $phpcolor->where="barname = '".$_GET['bn']."'";
  $phpcolor->upgrade();
  $phpcolor->table="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*3600);
  $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->message($email_flyesc,$email_addresser,$user['username'],$time,2);
  jump("jump.php?id=24&jump=apply_sort.php");
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "no")
{
  $phpcolor->table="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*3600);
  $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->message($email_flnoc,$email_addresser,$user['username'],$time,2);
  jump("jump.php?id=24&jump=apply_sort.php");
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "show")
{
  $phpcolor->table="apply_sort";
  $phpcolor->field="*";
  $phpcolor->where="id='".$_GET['id']."'";
  $apply = $phpcolor->exist(1);
  $phpcolor->table="bar";
  $phpcolor->field="id";
  $phpcolor->where="barname = '".$apply['barname']."'";
  $rs=$phpcolor->exist(1);
  $apply['barid']=$rs['id'];
  $phpcolor->table="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="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="class";
    $phpcolor->field="classname";
    $phpcolor->where="id='".$apply[$count]['sort']."'";
    $sort[] = $phpcolor->exist(1);
    $phpcolor->table="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");
}
?>