<?
session_start();
include 'cnn.php';
$login = $_SESSION['login'];
$senha = $_SESSION['senha'];
if(!(isset($_SESSION['login']) OR isset($_SESSION['senha']))) { 
echo "<h1></h1>";
}
else{
$vip=mssql_fetch_row(mssql_query("select vip from memb_info where memb___id='".$login."'"));
?>
<form name="form1" method="post" action="">
<h1>Adicionar um F.A.Q (Ajuda Online)</h1>
<div class="quadros">
<label>Pergunta:</label>
<input name="pergunta" class="submit" type="text" id="pergunta" /> 
<label>Char:</label>
<select name="char" id="char">
<?
		$Chars = mssql_query("select name from character where accountid='".$login."'");
		for($p=0;$p<mssql_num_rows($Chars);$p++) {
		$Char=mssql_fetch_row($Chars);
		echo '<option value='.$Char[0].'>'.$Char[0].'</option>';
		}
?>
</select>
<label>Categoria:</label>
                 <select name="categoria" id="categoria">
                    <option value="Bugs">Bugs</option>
                    <option value="Bloqueios">Bloqueios</option>
                    <option value="Compras">Compras</option>
                    <option value="Roubos">Roubos</option>
                    <option value="MuOnline">MuOnline</option>
                    <option value="Guilds">Guilds</option>
    </select>

<label>Resposta:</label>
<input name="conteudo" class="submit" type="text" id="conteudo" /> 
<br><br>
<input name="prossegue" type="submit" class="submit" id="prossegue" value="Adicionar">
</div>
</form>
<? 
if($_POST['prossegue']) {
$char = $_POST['char'];
$pergunta = $_POST['pergunta'];
$conteudo = $_POST['conteudo'];
$categoria = $_POST['categoria'];

$VerificaStatus = mssql_fetch_row(mssql_query("select connectstat from memb_stat where memb___id='".$login."'"));
$VerificaChar = mssql_num_rows(mssql_query("select name from character where name='".$char."' and accountid='".$login."'"));
$VerificaTitulo = mssql_num_rows(mssql_query("select titulo from faq where titulo='".$pergunta."'"));
if($VerificaStatus[0] >= 1) {
echo "<script>alert('Saia da conta.'); 
location='javascript:history.back()'</script>";
}
if($VerificaChar <= 0) { 
echo "<script>alert('Char inválido.'); 
location='javascript:history.back()'</script>"; 
}
if($VerificaTitulo >= 1) { 
echo "<script>alert('O titulo já está em uso, por favor, escolha outro!'); 
location='javascript:history.back()'</script>"; 
}
elseif($pergunta == NULL) { 
echo "<script>alert('Pergunta inválida.'); 
location='javascript:history.back()'</script>"; 
}
elseif($conteudo == NULL) { 
echo "<script>alert('Resposta inválida.'); 
location='javascript:history.back()'</script>"; 
}
else {
mssql_query("INSERT INTO faq (titulo,conteudo,faq,por) values ('$pergunta','$conteudo','$categoria','$char')");
echo "<script>alert('Faq adicionado na categoria $categoria.'); 
	location='javascript:history.back()'</script>";	
} } }
?>