<?
if(empty($_SESSION['backend']['user_id'])) exit;

$user=$X->DB->fast(' SELECT * FROM _admin_users WHERE id="'.(int)$_SESSION['backend']['user_id'].'" ');

$old_pass=md5('d:'.$_POST['old_password'].'<>'.$_POST['old_password'].':h');
if($old_pass!=$user['password'] || strlen($_POST['old_password'])<3) $REQ[]=array('text', 1000, 'old_password', 'Stare hasło jest błędne!');
if(strlen($_POST['new_password'])<3) $REQ[]=array('text', 1000, 'new_password');
if(strlen($_POST['new_password2'])<3) $REQ[]=array('text', 1000, 'new_password2');
if($_POST['new_password']!=$_POST['new_password2']) $REQ[]=array('text', 1000, 'new_password2','<b>Nowe hasło</b> i <b>potwierdzenie</b> nie są takie same');


function callback() {
	header('Content-type: text/javascript; charset=utf-8');
	global $X;

	$login=$X->DB->fast(' SELECT login FROM _admin_users WHERE id="'.(int)$_SESSION['backend']['user_id'].'" ');

	$pass=md5('d:'.$_POST['new_password'].'<>'.$_POST['new_password'].':h');
	$checksum=md5('dh::'.$_POST['new_password'].'@'.$X->STR->outt($login).'<<'.(int)$_SESSION['backend']['user_id']);

	$X->DB->q(' UPDATE _admin_users SET password="'.$pass.'", auth_checksum="'.$checksum.'" WHERE id="'.(int)$_SESSION['backend']['user_id'].'" ');

	die('
		$(\'#old_password\').blur().val("");
		$(\'#new_password\').blur().val("");
		$(\'#new_password2\').blur().val("");
		notif(\'ok\', \'Hasło zostało zmienione!\', 2000);
	');
}
?>