<?php

	$actions = array('submit');
	
	$action = (key_exists('action', $_GET) && in_array($_GET['action'], $actions)) ? $_GET['action'] : '';
	
	$err_message = '';
	
	if($action == 'submit')
	{
		$row = $dba->GetRow('mobile_users', $_SESSION['my_id'], 'pass');
		if(is_array($row))
		{
			$old_pass = (key_exists('old_psw', $_POST) && $_POST['old_psw']!='') ? $_POST['old_psw'] : '';
			$new_pass = (key_exists('new_psw', $_POST) && $_POST['new_psw']!='') ? $_POST['new_psw'] : '';
			$new_pass2 = (key_exists('new_psw2', $_POST) && $_POST['new_psw2']!='') ? $_POST['new_psw2'] : '';
			if($row['pass'] == md5(md5($old_pass)))
			{
				$test_pass = str_replace(' ', '', $new_pass);
				if($new_pass == $new_pass2 && $test_pass != '')
				{
					$new_pass = md5(md5($new_pass));
					$dba->ExecuteQuery("UPDATE mobile_users SET pass='$new_pass' WHERE ID=".$_SESSION['my_id']." limit 1");	
					$err_message = 'Heslo zmenené!';
				}
				else 
				{
					$err_message .= 'Nepotvrdené nové heslo!';	
				}
			}
			else 
			{
				$err_message .= 'Nesprávne pôvodné heslo!';	
			}
		}
		else 
		{
			$err_message = 'Neznáma chyba';	
		}
	}
?>
	<div id="register_form01">
	  <div id="menu01_head">:: Nastavenie - zmena hesla</div>
	  <div class="setup_div">
	  	<?php echo "<div id='form_popis03'>$err_message</div>"; ?>
		  <form name="frm" action="index.php?module=psw&action=submit" method="post" style="margin:0px;">
			  Staré heslo: <input id="form_field02" type="password" name="old_psw" size="15" maxlength="15"/><br/>
			  Nové heslo: <input id="form_field02" type="password" name="new_psw" size="15" maxlength="15"/><br/>
			  Nové heslo potvrdenie: <input id="form_field02" type="password" name="new_psw2" size="15" maxlength="15"/><br/>
			  <input id="form_button01" type="submit" name="Submit" value="OK">
		  </form>
	  </div>
	</div>