<?
include 'cnn.php';
@$login = $_SESSION['login'];
@$senha = $_SESSION['senha'];
if(!isset($_SESSION['login'])) { echo "<strong>Para acessar essa pagina  preciso esta logado!</strong>"; }
else{
$vip=mssql_fetch_row(mssql_query("select vip from memb_info where memb___id='".$login."'"));
?>
<h1>Distribuir Pontos</h1>
<form name="form1" onMouseMove="Null();" method="post" action="">
<div class="qdestaques">
<label>Personagem:</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>For&ccedil;a:</label>
<input name="str" class="submit" type="text" id="str" value="0" maxlength="5">
<label>Agilidade:</label>
<input name="agi" class="submit" type="text" id="agi" value="0" maxlength="5">
<label>Vida:</label>
<input name="vit" class="submit" type="text" id="vit" value="0" maxlength="5">
<label>Energia:</label>
<input name="eng" class="submit" type="text" id="eng" value="0" maxlength="5">
<br />
<br />
<input name="prossegue" type="submit" class="submit" id="prossegue" value="Distribuir">
<br />
<br />
<div class="qdestaques2">
<?
$tmp = mssql_query ( "select name, leveluppoint, strength, dexterity, vitality, energy from character where accountid = '" . $login . "'" );
while ( $tmp2 = mssql_fetch_row ( $tmp ) )
{
    print  $tmp2 [ 0 ] . " <br /><label>- Pontos: " . $tmp2 [ 1 ] . "</label> <label>- Fora: " . $tmp2[2] . "</label> <label>- Agilidade: " . $tmp2[3] . "</label> <label>- Vida: " . $tmp2[4] . "</label> <label>- Energia: " . $tmp2[5] . "</label>";
}
?>
</div>
</div>
</form>
<? 
if($_POST['prossegue']) {
$char = $_POST['char'];
$str = $_POST['str'];
$agi = $_POST['agi'];
$vit = $_POST['vit'];
$enr = $_POST['enr'];
$VerificaChar = mssql_num_rows(mssql_query("select name from character where name='".$char."' and accountid='".$login."'"));
if($VerificaChar <= 0) {
echo "<script>alert('Char incorreto'); 
location='javascript:history.back()'</script>"; 
}
else{
    $Query = mssql_query("select leveluppoint from character where name='".$char."'");
    $Result = mssql_fetch_row($Query);
    $Limite = "$str"+"$agi"+"$vit"+"$enr";
    if($Limite > $Result[0]){
    die("<script>alert('Você ultrapassou a quantidade de pontos que você tem');
    location='javascript:history.back()'</script>");
    }
    $tirar = "$str"+"$agi"+"$vit"+"$enr";
    if($str == "") { $str = 0; }
    if($agi == "") { $agi = 0; }
    if($enr == "") { $enr = 0; }
    if($vit == "") { $vit = 0; }
    else{ mssql_query("update character set Strength=Strength+$str, 
        Dexterity=Dexterity+$agi, 
        Vitality=Vitality+$vit,  
        leveluppoint=leveluppoint-$tirar, 
        Energy=Energy+$enr where name='".$char."' 
        and accountid='".$login."'");
    echo "<script>alert('$char, $tirar pontos adicionados!'); 
    location='javascript:history.back()'</script>";
} 
    } }
} 

?>