<?php

$info = '';
$html->PrgStart();
if($player->Check())
{
  if(array_key_exists('zmenit', $_POST) and ($_POST['zmenit'] == 1))
  {
    $account = $_POST['acc1'];
    $heslo1 = $_POST['heslo1'];
  	$heslo2 = $_POST['heslo2'];
	  $heslo3 = $_POST['heslo3'];
   
    if(empty($account) OR empty($heslo1) OR empty($heslo2) OR empty($heslo3)) $info = '<font color=red><strong>Nevyplnil jste všechna políčka!</strong></font>';
    else   
    {
      $db->select_db($Config['Mangos']['DatabaseRealmd']);
      $DbResult = $db->query('SELECT id FROM account WHERE username="'.$account.'" and sha_pass_hash=SHA1(CONCAT(UPPER("'.$account.'"),":",UPPER("'.$heslo1.'")))');
	    if($DbResult->num_rows > 0)
      {
	      if($heslo2 == $heslo3)
        {
	        $pass_update = $db->query('update account set sha_pass_hash=SHA1(CONCAT(UPPER("'.$account.'"), ":", UPPER("'.$heslo2.'"))) where username="'.$account.'"');
	        if($pass_update) $info = '<font color="green"><strong>Heslo bylo vpořádku změněno!</strong></font>';
	        else $info = '<font color="red"><strong>Heslo se nepodařilo změnit!</strong></font>';
	      } else $info = '<font color="red"><b>Hesla se neshodují!</b></font>';	
	    } else $info = '<font color="red"><b>Zadali jste neexistujici účet nebo špatné heslo!</b></font>';	    
    }
  }

  echo('&nbsp;<a href="?page=acc">&lt;- Zpět do správy účtu</a><br />

<b>'.$info.'</b>
<form method="post" action="?page=chpass">
<center><h3>Změna typu účtu</h3></center>

<table align="center">
  <input type="hidden" name="acc1" value="'.$_SESSION['UserName'].'" />
  <tr>
    <td>
      Momentální Heslo: </td>
    <td>
     <input type="password" name="heslo1" class="textinput" /></td>
  </tr>
   <tr>
    <td>
      Nové Heslo : </td>
    <td>
     <input type="password" name="heslo2" class="textinput" /></td>
  </tr>
   <tr>
    <td>
      Nové Heslo podruhé : </td>
    <td>
     <input type="password" name="heslo3" class="textinput" /></td>
  </tr>
  <tr>
    <td colspan="2" align="right">
	<input type="hidden" name="zmenit" value="1" />
      <input type="submit" value="Změnit" name="change"></td>
  </tr>
</table>
</form>');
}
else $player->LoginForm();
$html->PrgStop();

?>
