<?
include_once("req.php");
error_reporting(E_ALL ^ E_NOTICE);
array_walk($_REQUEST,"format_string");  
array_walk($_POST,"format_string");   
array_walk($_GET,"format_string");   

$showform=true;
if ($_REQUEST['dochpass']) {
	$ok=true;
	if ($_REQUEST['newpass']!=$_REQUEST['newpass2']) {$ok=false;$mess='Ошибка. Пароли не совпадают.';}
	if (trim($_REQUEST['newpass'])=='') {$ok=false;$mess='Задан пустой пароль';}
	$res=db_use('array',"select pass from users where login='".$myinfo->name."';");
	if ($res['pass']!=md5($_REQUEST['oldpass'])) {$ok=false;$mess="Ошибка. Старый пароль указан неверно.";}
	#if ($_REQUEST['newpass']!=$_REQUEST['newpass2']) {$ok=false;$mess='Ошибка. Пароли не совпадают.';}
	if ($ok) { 
		db_use('query',"update users set pass='".md5($_REQUEST['newpass'])."',passtime='".time()."' where login='".$myinfo->name."'");
		#db_use('query',"update sessions set userpass='".md5($_REQUEST['newpass'])."' where username='".$myinfo->name."'");
		db_use('query',"insert into pals_delo(id_person,id_paladin,level,align,message,type) values('".$myinfo->id_person."','".$myinfo->id_person."','".$myinfo->level."','".$myinfo->align."','Смена пароля. IP: ".$session->userip."','5')");
		$mess='Новый пароль сохранен.';
	}
}

if ($showform) {

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<link rel=stylesheet type="text/css" href="../i/main.css">
</head>
<body leftmargin=10 topmargin=0 marginwidth=0 bgcolor=e2e0e0>
<TABLE width=100% cellspacing=0 cellpadding=0>
<FORM METHOD=POST ACTION="main.php?changepsw=1" name='FORM1' id="FORM1">
<TR>
	<TD><h3>Сменить пароль персонажа "<? echo $myinfo->name; ?>"</TD>

	<TD valign=top align=right>
<INPUT TYPE=submit name=edit value="Вернуться">
	</TD>
</TR></TABLE><FONT COLOR=red><B><? echo $mess; ?></B></FONT>
<table width="95%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#B2B2B2" name="F1">
    <tr bgcolor="#D3D2D0">
      <td>Старый пароль: </td>
      <td><input name="oldpass" type=password value="<? echo $name; ?>" class="inup" size="45" maxlength="90" /></td>
    </tr>
    <tr bgcolor="#D3D2D0">
      <td>Новый пароль: </td>
      <td><input name="newpass" type=password class="inup" size="45" maxlength="90" /></td>
    </tr>
    <tr bgcolor="#D3D2D0">
      <td>Новый пароль (повтор): </td>
      <td><input name="newpass2" type=password class="inup" size="45" maxlength="90" /></td>
    </tr>
    <tr bgcolor="#D3D2D0">
      <td colspan="2" align="center"><p align="center">
          <input name="dochpass" type="submit" class="btn" value="Сохранить изменения" />
        </p>
    </tr>
  </form>
</table>
	
</body>
</html>
<? } if ($dodie) {die;} ?>