<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[12]!=1)
  jump("jump.php?id=25&jump=main.php");
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "yess")
{
  $phpcolor->table="apply_master";
  $phpcolor->field="*";
  $phpcolor->where="id='".$_GET['id']."'";
  $sqxx=$phpcolor->exist(1);
  $phpcolor->delete();
  $phpcolor->table="bar";
  $phpcolor->field="id";
  $phpcolor->where="barname='".$sqxx['barname']."'";
  $rsb=$phpcolor->exist(1);
  $phpcolor->table="user";
  $phpcolor->field="id";
  $phpcolor->where="username='".$sqxx['username']."'";
  $rsu=$phpcolor->exist(1);
  $phpcolor->table="bar_user";
  $phpcolor->field="rank=2";
  $phpcolor->where="uid = '".$rsu['id']."' and bid = '".$rsb['id']."'";
  $phpcolor->upgrade();
  $email_bzyest=str_replace("{username}",$sqxx['username'],$email_bzyest);
  $email_bzyest=str_replace("{barname}",$sqxx['barname'],$email_bzyest);
  $email_bzyesc=str_replace("{username}",$sqxx['username'],$email_bzyesc);
  $email_bzyesc=str_replace("{barname}",$sqxx['barname'],$email_bzyesc);
  if($email_mopen==1)
  {
    $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
    $phpcolor->message($email_bzyesc,$email_addresser,$sqxx['username'],$time,2);
  }
  if($email_eopen==1)
  {
    $smtp = new smtp($core_stmpserver,$core_stmpport,true,$core_stmpacc,$core_stmppwd);
    $smtp->debug =  false;
    $smtp->sendmail($sqxx['email'], $core_stmpmail, $email_bzyest, $email_bzyesc, 'HTML');
  }
  jump("jump.php?id=24&jump=apply_master.php");
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "yesc")
{
  $phpcolor->table="apply_master";
  $phpcolor->field="*";
  $phpcolor->where="id='".$_GET['id']."'";
  $sqxx=$phpcolor->exist(1);
  $phpcolor->delete();
  $phpcolor->table="bar";
  $phpcolor->field="id";
  $phpcolor->where="barname='".$sqxx['barname']."'";
  $rsb=$phpcolor->exist(1);
  $phpcolor->table="user";
  $phpcolor->field="id";
  $phpcolor->where="username='".$sqxx['username']."'";
  $rsu=$phpcolor->exist(1);
  $phpcolor->table="bar_user";
  $phpcolor->field="rank=0";
  $phpcolor->where="uid = '".$rsu['id']."' and bid = '".$rsb['id']."'";
  $phpcolor->upgrade();
  $email_cbzyest=str_replace("{username}",$sqxx['username'],$email_cbzyest);
  $email_cbzyest=str_replace("{barname}",$sqxx['barname'],$email_cbzyest);
  $email_cbzyesc=str_replace("{username}",$sqxx['username'],$email_cbzyesc);
  $email_cbzyesc=str_replace("{barname}",$sqxx['barname'],$email_cbzyesc);
  if($email_mopen==1)
  {
    $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
    $phpcolor->message($email_cbzyesc,$email_addresser,$sqxx['username'],$time,2);
  }
  if($email_eopen==1)
  {
    $smtp = new smtp($core_stmpserver,$core_stmpport,true,$core_stmpacc,$core_stmppwd);
    $smtp->debug =  false;
    $smtp->sendmail($sqxx['email'], $core_stmpmail, $email_cbzyest, $email_cbzyesc, 'HTML');
  }
  jump("jump.php?id=24&jump=apply_master.php");
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "no")
{
  $phpcolor->table="apply_master";
  $phpcolor->field="*";
  $phpcolor->where="id='".$_GET['id']."'";
  $apply=$phpcolor->exist(1);
  $phpcolor->delete();
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  if($apply['type']=="2")
  {
	$email_cbznot=str_replace("{username}",$apply['username'],$email_cbznot);
    $email_cbznot=str_replace("{barname}",$apply['barname'],$email_cbznot);
    $email_cbznoc=str_replace("{username}",$apply['username'],$email_cbznoc);
    $email_cbznoc=str_replace("{barname}",$apply['barname'],$email_cbznoc);
    if($email_mopen==1)
      $phpcolor->message($email_cbznoc,$email_addresser,$apply['username'],$time,2);
	if($email_eopen==1)
    {
      $smtp = new smtp($core_stmpserver,$core_stmpport,true,$core_stmpacc,$core_stmppwd);
      $smtp->debug =  false;
      $smtp->sendmail($apply['email'], $core_stmpmail, $email_cbznot, $email_cbznoc, 'HTML');
    }
  }
  else
  {
	$email_bznot=str_replace("{username}",$apply['username'],$email_bznot);
    $email_bznot=str_replace("{barname}",$apply['barname'],$email_bznot);
    $email_bznoc=str_replace("{username}",$apply['username'],$email_bznoc);
    $email_bznoc=str_replace("{barname}",$apply['barname'],$email_bznoc);
    if($email_mopen==1)
      $phpcolor->message($email_bznoc,$email_addresser,$apply['username'],$time,2);
	if($email_eopen==1)
    {
      $smtp = new smtp($core_stmpserver,$core_stmpport,true,$core_stmpacc,$core_stmppwd);
      $smtp->debug =  false;
      $smtp->sendmail($apply['email'], $core_stmpmail, $email_bznot, $email_bznoc, 'HTML');
    }
  }
  jump("jump.php?id=24&jump=apply_master.php");
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "show")
{
  $phpcolor->table="apply_master";
  $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="bar_user";
  $phpcolor->where="rank = '2' and bid = '".$apply['bid']."'";
  $apply['barmastery']=$phpcolor->exist(2);
  $tpl -> assign("apply", $apply);
  $tpl -> display("apply_master_show.htm");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->table="apply_master";
  $phpcolor->field="*";
  $phpcolor->where="1=1";
  $count = $phpcolor->exist(2);
  $phpcolor->where="1=1 limit ".($_GET['page']*20).",20";
  $apply = $phpcolor->assignment();
  $page=pages($count,20,$_GET['page'],'apply_master','','','0');
  $phpcolor->table="bar";
  $phpcolor->field="id";
  for ($count=0;$count<count($apply);$count++)
  {
    $phpcolor->where="barname = '".$apply[$count]['barname']."'";
    $rs=$phpcolor->exist(1);
    $apply[$count]['barid']=$rs['id'];
  }
  $tpl -> assign("apply", $apply);
  $tpl -> assign("page", $page);
  $tpl -> assign("count", $count);
  $tpl -> display("apply_master.htm");
}
?>