<? session_start();
include 'cnn.php';
include 'estilo.css';
include 'configs/conf_extras.php';
@$login = $_SESSION['login'];
@$senha = $_SESSION['senha'];
if(!isset($_SESSION['login'])) { echo "Para acessar essa pagina é preciso estar logado!"; }
else{
$Gms = mssql_fetch_row(mssql_query("select contagm from memb_info where memb___id='".$login."'"));
if($Gms[0] <= 0) { echo "Você não faz parte da Administração"; }
else{  ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Deletar Personagem - Painel ADM</title>
</head>
<SCRIPT language=JavaScript>
var message="";
function clickIE()
{
    if (document.all)
    {
        (message);
        return false;
    }
}
function clickNS(e)
{
    if(document.layers||(document.getElementById&&!document.all))
    {
        if (e.which==2||e.which==3)
        {
            (message);
            return false;
        }
    }
}
if (document.layers)
{
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS;
}
else
{
    document.onmouseup=clickNS;
    document.oncontextmenu=clickIE;
}
document.oncontextmenu=new Function("return false")
</SCRIPT>
<body>
<table width="190" border="1" background="imagens/bg2.jpg">
  <tr>
    <th scope="col"><form name='form1' method='post' action='ir.php?pagina=deletchar&act=editar'>
      <table width="520" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="30"><img src="imagens/mu.gif" alt="" width="30" height="30"></td>
          <td width="584" background="imagens/mu_back.png">&nbsp;&nbsp;&nbsp;<strong>DELETAR CHAR</strong></td>
        </tr>
      </table>
      <br><div align="left">
      <table width="215" border="0">
        <tr>
          <td width="72">Nome: </td>
          <td width="127"><select name="nome" id="nome">
              <?
		$Chars = mssql_query("select name from character");
		for($p=0;$p<mssql_num_rows($Chars);$p++) {
		$Char=mssql_fetch_row($Chars);
		echo '<option value='.$Char[0].'>'.$Char[0].'</option>';
		}
		?>
          </select></td>
        </tr>
        <tr>
          <td height="37" colspan="2" align="center"><input name="prossegue" type="submit" class="submit" id="prossegue" value="Deletar"></td>
        </tr>
      </table></div>
      <br>
        
      </form>
      <a href="javascript:history.back(-1);"><p align="left">&lt;&lt; voltar </p>
      </a></th>
  </tr>
</table>
</body>
</html>
<? 
if ($act == 'editar') {
	$nome = $_POST['nome'];
		
		$dados_perso_q = mssql_query("SELECT * FROM Character WHERE Name='$nome'");
		$dados_perso = mssql_fetch_array($dados_perso_q);
		
		$checa_stat_login_q = mssql_query("SELECT * FROM MEMB_STAT WHERE memb___id='$dados_perso[AccountID]'");
		$checa_stat_login = mssql_fetch_array($checa_stat_login_q);
		
		if (empty($nome)) {
			echo "<script>alert('Você esqueceu o Campo Nome em Branco')</script>";
			echo "<script>window.location='ir.php?pagina=deletchar'</script>";
		} elseif (mssql_num_rows($dados_perso_q) == 0) {
			echo "<script>alert('Este Personagem não Existe')</script>";
			echo "<script>window.location='ir.php?pagina=deletchar'</script>";
		} elseif ($checa_stat_login['ConnectStat'] == 1) {
			echo "<script>alert('A Account do Personagem Está Conectada no momento.')</script>";
			echo "<script>window.location='ir.php?pagina=deletchar'</script>";
		} else {
			
			$localizar_acc_char_query = mssql_query("SELECT * FROM AccountCharacter WHERE Id='$dados_perso[AccountID]'");
			$localizar_acc_char = mssql_fetch_array($localizar_acc_char_query);
			
			if ($localizar_acc_char['GameID1'] == "$nome") { $gameid = 'GameID1'; } 
			if ($localizar_acc_char['GameID2'] == "$nome") { $gameid = 'GameID2'; } 
			if ($localizar_acc_char['GameID3'] == "$nome") { $gameid = 'GameID3'; } 
			if ($localizar_acc_char['GameID4'] == "$nome") { $gameid = 'GameID4'; } 
			if ($localizar_acc_char['GameID5'] == "$nome") { $gameid = 'GameID5'; }
			
			mssql_query("UPDATE AccountCharacter SET $gameid=NULL WHERE $gameid='$nome'");
			mssql_query("DELETE FROM Character WHERE Name='$nome'");
			mssql_query("DELETE FROM Guild WHERE G_Master='$nome'");
			$checa_gm_guild_q = mssql_query("SELECT * FROM Guild WHERE G_Master='$nome'");
			
			if (mssql_num_rows($checa_gm_guild_q) > 0) {
				$dados_guild_gm = mssql_fetch_array($checa_gm_guild_q);
				mssql_query("DELETE FROM GuildMember WHERE G_Name='$dados_guild_gm[G_Name]'");
			}
			mssql_query("DELETE FROM GuildMember WHERE Name='$nome'");
			

			echo "<script>alert('Char $nome deletado com sucesso'); 
	location='javascript:history.back()'</script>";	
		}
	}
}
}
?>