<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[12]!=1)
{
  Header("Location: jump.php?id=25&jump=main.php");
  exit();
}
$phpcolor->table=$core_mysql_prefix."bar";
$phpcolor->field="barmaster";
$phpcolor->where="barname = '".$_GET['bn']."'";
if(isset($_GET['action']) and isset($_GET['id']) and isset($_GET['un']) and isset($_GET['bn']) and $_GET['action'] == "yess")
{
  $bar = $phpcolor->exist(1);
  if($bar['barmaster']!="")
    $bar['barmaster'].="|".$_GET['un'];
  else
    $bar['barmaster']=$_GET['un'];
  $phpcolor->field="barmaster='".$bar['barmaster']."'";
  $phpcolor->upgrade();
  $phpcolor->table=$core_mysql_prefix."apply_master";
  $phpcolor->field="*";
  $phpcolor->where="id='".$_GET['id']."'";
  $sqxx=$phpcolor->exist(1);
  $phpcolor->delete();
  $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*60*60);
    $phpcolor->table=$core_mysql_prefix."message";
    $phpcolor->field="theme, content, addresser, addressee, sent, type";
    $phpcolor->where="'".$email_bzyest."', '".$email_bzyesc."', '".$email_addresser."', '".$sqxx['username']."', '".$time."', '2'";
    $phpcolor->write();
  }
  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');
  }
  Header("Location: jump.php?id=24&jump=apply_master.php");
}
elseif(isset($_GET['action']) and isset($_GET['id']) and isset($_GET['un']) and isset($_GET['bn']) and $_GET['action'] == "yesc")
{
  $bar = $phpcolor->exist(1);
  $bar['barmaster']=replacemandf($bar['barmaster'],$_GET['un']);
  $phpcolor->field="barmaster='".$bar['barmaster']."'";
  $phpcolor->upgrade();
  $phpcolor->table=$core_mysql_prefix."apply_master";
  $phpcolor->field="*";
  $phpcolor->where="id='".$_GET['id']."'";
  $sqxx=$phpcolor->exist(1);
  $phpcolor->delete();
  $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*60*60);
    $phpcolor->table=$core_mysql_prefix."message";
    $phpcolor->field="theme, content, addresser, addressee, sent, type";
    $phpcolor->where="'".$email_cbzyest."', '".$email_cbzyesc."', '".$email_addresser."', '".$sqxx['username']."', '".$time."', '2'";
    $phpcolor->write();
  }
  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');
  }
  Header("Location: jump.php?id=24&jump=apply_master.php");
}
elseif(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "no")
{
  $phpcolor->table=$core_mysql_prefix."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*60*60);
  $phpcolor->table=$core_mysql_prefix."message";
  $phpcolor->field="theme, content, addresser, addressee, sent, type";
  if($apply['type']=="2")
  {
    if($email_mopen==1)
    {
      $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);
      $phpcolor->where="'".$email_cbznot."', '".$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
  {
    if($email_mopen==1)
    {
      $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);
      $phpcolor->where="'".$email_bznot."', '".$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');
    }
  }
  $phpcolor->write();
  Header("Location: jump.php?id=24&jump=apply_master.php");
}
elseif(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "show")
{
  $phpcolor->table=$core_mysql_prefix."apply_master";
  $phpcolor->field="*";
  $phpcolor->where="id='".$_GET['id']."'";
  $apply = $phpcolor->exist(1);
  $phpcolor->table=$core_mysql_prefix."bar";
  $phpcolor->field="id,barmaster";
  $phpcolor->where="barname = '".$apply['barname']."'";
  $rs=$phpcolor->exist(1);
  $apply['barid']=$rs['id'];
  $apply['barmastery']="0";
  if($rs['barmaster']!="")
    $apply['barmastery']="1";
  $tpl -> assign("apply", $apply);
  $tpl -> display("apply_master_show.htm");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->table=$core_mysql_prefix."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=$core_mysql_prefix."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");
}
?>