<?
session_start();
?>
<style>
* { margin: 0; padding: 0; }
body {
	background: #CCCCCC;
	color: #333; 
	text-align: center;
}
.quadros {
  margin: 5px 0;
  padding: 10px;
  text-align: left;
  display: block;
  overflow: auto;  
  /* white-space: pre; */
  background: #FAFAFA;
  border: 3px solid #EFEFEF;  
}
.qdestaques {
  margin: 5px 0;
  padding: 10px;
  text-align: left;
  display: block;
  overflow: auto;  
  /* white-space: pre; */
  background: #FAFAFA;
  border: 3px solid #FF3737;  
}
input {
	padding:2px;
	border:1px solid #CFCFCF;
	font: Verdana, sans-serif;
	color:#777;
}
</style>
<?
if(isset($_POST[ip])) {
	$_SESSION[conection] = true;
	$_SESSION[host] = $_POST[ip];
	$_SESSION[user] = $_POST[usuario];
	$_SESSION[pwd] = $_POST[senha];
	$_SESSION[database] = $_POST[bancodedados];
	$_SESSION[nitens] = $_POST[itens];
}
if($_SESSION[conection] == true) {
    if(mssql_select_db($_SESSION[database], mssql_connect($_SESSION[host],$_SESSION[user],$_SESSION[pwd])) == false) session_destroy();
} else {
    echo "<form action='$_SERVER[PHP_SELF]' method='POST'>
   		   <table class='quadros' width='600'>
		    <tr>
			 <td colspan='2' align='center'>Conex&atilde;o com o Banco de dados</td>
			</tr>
		    <tr>
			 <td align=right>IP Host: </td>
			 <td><input name='ip' value='127.0.0.1' size='40'/></td>
			</tr>
		    <tr>
			 <td align=right>Banco de Dados: </td>
			 <td><input name='bancodedados' value='MuOnline' size='40'/></td>
			</tr>
		    <tr>
			 <td align=right>Usu&aacute;rio: </td>
			 <td><input name='usuario' value='sa' size='40'/></td>
			</tr>
		    <tr>
			 <td align=right>Senha: </td>
			 <td><input name='senha' type='password' size='40'/></td>
			</tr>
		    <tr>
			 <td align=right>Itens: </td>
			 <td><input name='itens' type='radio' value='1200'/> 1200 (Para versões menores que Season 2)<br /><input name='itens' type='radio' checked value='1920'/> 1920 (Para versões maiores que Season 2 ou a propria Season 2)</td>
			</tr>
		    <tr>
			 <td align='center' colspan='2'><input type='submit' value='Conectar ao banco de dados'/></td>
			</tr>
		    </table>
		 </form>";
}
if($_SESSION[conection] == true) {

function executarquery($arquivo) {
	$open = fopen($arquivo, "r");
	$conteudo = fread($open, filesize($arquivo));
	
	if(mssql_query($conteudo) == true) { return "Criado com Sucesso."; } else { return "Erro."; }

}

function droparchave() {

$dropachave = "if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PK_MEMB_INFO]') and OBJECTPROPERTY(id, N'IsPrimaryKey') = 1)
ALTER TABLE [dbo].[MEMB_INFO] DROP CONSTRAINT [PK_MEMB_INFO]";
	
	if(mssql_query($dropachave) == true) { return "Criado com Sucesso."; } else { return "Erro."; }

}

function criar_procedure_muda_bau() {
$apagarmuda_bau = "if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Mudar_Bau]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Mudar_Bau]";

$apagou = mssql_query($apagarmuda_bau);

$criarprocedure_muda_bau = "CREATE PROCEDURE Mudar_Bau
@login VARCHAR(20)
AS
BEGIN
UPDATE warehouse
SET Items = (SELECT Itens2 FROM warehouse WHERE AccountID = @login),
Itens2 = (SELECT Items FROM warehouse WHERE AccountID = @login)
WHERE AccountID = @login
END";
	
	if(mssql_query($criarprocedure_muda_bau) == true) { return "Criado com Sucesso."; } else { return "Erro."; }
}

function verificartabela($nome) {
	if(@mssql_query("SELECT * FROM ".$nome."") == true) { return "J&aacute; Criada."; } else { return executarquery("etc/".$nome.".sql"); }
}
function verificarcoluna($table,$nome,$tipo,$null,$default) {
	if(@mssql_query("SELECT ".$nome." FROM ".$table."") == true) { return "J&aacute; Criada."; } else { 
	  if($null == 1) $null = "NULL";
	  if(mssql_query("ALTER TABLE $table ADD $nome $tipo $null $default")) { return "Criada com sucesso!"; } else { return "Erro."; }
	}
	
}

if($_GET[etapa] == 1 || isset($_GET[etapa]) == false) {

echo "<table class='quadros' width='500'>
	   <tr>
	    <td align='center' colspan='2'>Criar Tabelas</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Faq: </td>
	    <td>".verificartabela("faq")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Site_Aviso: </td>
	    <td>".verificartabela("site_aviso")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Site_Confirman: </td>
	    <td>".verificartabela("site_confirman")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Site_confirmav: </td>
	    <td>".verificartabela("site_confirmav")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Site_contato: </td>
	    <td>".verificartabela("site_contato")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Site_ticket: </td>
	    <td>".verificartabela("site_ticket")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Site_ticket_res: </td>
	    <td>".verificartabela("site_ticket_res")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Noticias: </td>
	    <td>".verificartabela("noticias")."</td>
	   </tr>
	    <td align='center' colspan=2><input type='button' value='Proxima Etapa' onclick=\"location='".$_SERVER[PHP_SELF]."?etapa=2'\"/></td>
	   </tr>
	  </table>";
} elseif($_GET[etapa] == 2) {
echo "<table class='quadros' width='500'>
	   <tr>
	    <td align='center' colspan='2'>Criar Colunas</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::Resets: </td>
	    <td>".verificarcoluna('Character','Resets','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	   <td align='right'>Character::Resem: </td>
	   <td>".verificarcoluna('Character','Resem','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::diasdesbloc: </td>
	    <td>".verificarcoluna('Character','diasdesbloc','varchar(50)','','')."</td>
	   </tr>
	   <tr> 
	   <td align='right'>Character::blocpor: </td>
	    <td>".verificarcoluna('Character','blocpor','varchar(50)','','')."</td>
	   </tr>
	   </tr>
	    <td align='right'>Character::databloc: </td>
	    <td>".verificarcoluna('Character','databloc','varchar(50)','','')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::motivobloc: </td>
	    <td>".verificarcoluna('Character','motivobloc','varchar(50)','','')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::Reputacao: </td>
	    <td>".verificarcoluna('Character','Reputacao','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::Resetao: </td>
	    <td>".verificarcoluna('Character','resetao','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::semanaldif: </td>
	    <td>".verificarcoluna('Character','semanaldif','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::rankmes: </td>
	    <td>".verificarcoluna('Character','rankmes','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::ourotop: </td>
	    <td>".verificarcoluna('Character','ourotop','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::pratatop: </td>
	    <td>".verificarcoluna('Character','pratatop','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::bronzetop: </td>
	    <td>".verificarcoluna('Character','bronzetop','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::ouroduelo: </td>
	    <td>".verificarcoluna('Character','ouroduelo','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::prataduelo: </td>
	    <td>".verificarcoluna('Character','prataduelo','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::bronzeduelo: </td>
	    <td>".verificarcoluna('Character','bronzeduelo','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::ouroevento: </td>
	    <td>".verificarcoluna('Character','ouroevento','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::prataevento: </td>
	    <td>".verificarcoluna('Character','prataevento','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::bronzeevento: </td>
	    <td>".verificarcoluna('Character','bronzeevento','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::foto: </td>
	    <td>".verificarcoluna('Character','foto','nvarchar','','DEFAULT sem_imagem.gif')."</td>
	   </tr>
	   <tr>
	    <td align='right'>Character::MRresets: </td>
	    <td>".verificarcoluna('Character','MRresets','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	   <td align='right'>MEMB_INFO::painelgm: </td>
	    <td>".verificarcoluna('MEMB_INFO','painelgm','nvarchar(50)','','')."</td>
	   </tr>
	   <tr>
	   <td align='right'>MEMB_INFO::Sexo: </td>
	    <td>".verificarcoluna('MEMB_INFO','autoriza','nvarchar(50)','','')."</td>
	   </tr>
	   <tr>
	    <td align='right'>MEMB_INFO::Idade: </td>
	    <td>".verificarcoluna('MEMB_INFO','Vip','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	    <td align='right'>MEMB_INFO::Numero: </td>
	    <td>".verificarcoluna('MEMB_INFO','Numero','varchar(50)','','')."</td>
	   </tr>
	   <tr>
	   <td align='right'>MEMB_INFO::Creditos: </td>
	    <td>".verificarcoluna('MEMB_INFO','Creditos','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	   <td align='right'>MEMB_INFO::Frase: </td>
	    <td>".verificarcoluna('MEMB_INFO','Frase','varchar(50)','','')."</td>
	   </tr>
	   <tr>
	   <td align='right'>MEMB_INFO::gold: </td>
	    <td>".verificarcoluna('MEMB_INFO','gold','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	   <td align='right'>MEMB_INFO::diasdesbloc: </td>
	    <td>".verificarcoluna('MEMB_INFO','diasdesbloc','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	   <td align='right'>MEMB_INFO::blocpor: </td>
	    <td>".verificarcoluna('MEMB_INFO','blocpor','int','','DEFAULT 0')."</td>
	   </tr>
              <tr>
	   <td align='right'>MEMB_INFO::blocpor: </td>
	    <td>".verificarcoluna('Character','foto','nvarchar','','DEFAULT sem_imagem.gif')."</td>
	   </tr>
	   <td align='right'>MEMB_INFO::databloc: </td>
	    <td>".verificarcoluna('MEMB_INFO','databloc','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	   <td align='right'>MEMB_INFO::motivobloc: </td>
	    <td>".verificarcoluna('MEMB_INFO','motivobloc','int','','DEFAULT 0')."</td>
	   </tr>
	   <tr>
	   <td align='right'>Guild::G_Banner: </td>
	    <td>".verificarcoluna('Guild','G_Banner','nvarchar(75)','','DEFAULT guild_sem_banner.gif')."</td>
	   </tr>
	   <tr>

	    <td align='center' colspan=2><input type='button' value='Proxima Etapa' onclick=\"location='".$_SERVER[PHP_SELF]."?etapa=3'\"/></td>
	   </tr>
	  </table>";
} elseif($_GET[etapa] == 3) {
echo "<table class='quadros' width='500'>
	   <tr>
	    <td align='center' colspan='2'>Criar Procedures</td>
	   </tr>
	   <tr>
	   <td align='right'>Chave_MEMB_INFO: </td>
	    <td>".droparchave()."</td>
	   </tr>
	   <tr>
	   <td align='right'>Muda_Bau: </td>
	    <td>".criar_procedure_muda_bau()."</td> 
	   </tr>
	   <tr>
	    <td align='center' colspan=2><input type='button' value='Proxima Etapa' onclick=\"location='".$_SERVER[PHP_SELF]."?etapa=4'\"/></td>
	   </tr>
	  </table>";
} elseif($_GET[etapa] == 4) {
echo "<table class='quadros' width='500'>
	   <tr>
	    <td align='center' colspan='2'>Criar Tabelas</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Faq: </td>
	    <td>".verificartabela("faq")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Site_Aviso: </td>
	    <td>".verificartabela("site_aviso")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Site_Confirman: </td>
	    <td>".verificartabela("site_confirman")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Site_confirmav: </td>
	    <td>".verificartabela("site_confirmav")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Site_contato: </td>
	    <td>".verificartabela("site_contato")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Site_ticket: </td>
	    <td>".verificartabela("site_ticket")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Site_ticket_res: </td>
	    <td>".verificartabela("site_ticket_res")."</td>
	   </tr>
	   <tr>
	    <td align='right'>Tabela: Noticias: </td>
	    <td>".verificartabela("noticias")."</td>
	   </tr>
	    <td align='center' colspan=2><input type='button' value='Proxima Etapa' onclick=\"location='".$_SERVER[PHP_SELF]."?etapa=5'\"/></td>
	   </tr>
	  </table>";
} elseif($_GET[etapa] == 5) {
echo "<table class='quadros' width='500'>
	   <tr>
	    <td align='center' colspan='2'>Finalizando Instala&ccedil;&atilde;o: </td>
	   </tr>
	   <tr>
	    <td align='right'>Apagando Sessions: </td>
	    <td>"; if(session_destroy() == true) echo "OK"; else echo "Erro"; echo "</td>
	   </tr>
	   <tr>
	    <td align='right'>Fechando Conex&atilde;o com o SQL: </td>
	    <td>"; if(mssql_close() == true) echo "OK"; else echo "Erro"; echo "</td>
	   </tr>
	   <tr>
	    <td align='center' colspan='2'><br/><b>A instala&ccedil;&atilde;o do site foi concluida com sucesso!<br/>Apague essa pasta para sua seguran&ccedil;a!<br>Obrigado!</b>
<br>By: RaidFight ~ ZoneGames.com.br</b></td>
	   </tr>
	  </table>";
}

}
?>
