
<?php
  $FileName = $_GET['pswdfile'];
  $PswdFile = "../txt/{$FileName}";
  //получаем длину вопроса
  $QuestLength = $_GET['questlength'];
  //выбираем вопрос
  $Question = GetQuestion($PswdFile, $QuestLength, 'pswd');
  //определяет новый пароль/изменить пароль
  $PswdStatus = $_POST['pswdstatus'];
  $Password = $_POST['password'];
  $PasswordConf = $_POST['passwordconf'];
  if(!empty($_POST['save']))
  {

    if($Password == '')
      $Errors[] = $Err_opfa_NoPassword;
    if($PasswordConf == '')
      $Errors[] = $Err_opfa_NoPassConf;
    if(strcmp($Password, $PasswordConf) != 0)
      $Errors[] = $Err_opfa_PassConf;
    if(empty($Errors))
    {
      $Md5Password = md5($Password);
      SaveStringInFile($PswdFile, $Md5Password, 'w');
      refresh($PageTmp);
    }
  } //if(!empty($_POST['save']))
  if($PswdStatus == '')
  {
    if(!file_exists($PswdFile))
    {
      $PswdStatus = $Heading_NewPass;
    }
    else {
	    $PswArr = file($PswdFile);
	    if(count($PswArr) != 1)
	      $PswdStatus = $Heading_NewPass;
	    else $PswdStatus = $Heading_ChangePass;
	  }
  } //if($PswdStatus == '')
  print "<h4>{$PswdStatus}</h4>";
  print "<h5>{$Question}</h5>";
  print "<form action='' method=post>";
  if($ShowTips == 'yes')
      ShowTips($Page);
  ShowErrors($Errors, '90%', 'MiniField');
  print "<fieldset align=center class=MiniField>";
   print "<table class=General align=center border=0 cellspacing=0 cellpadding=0 width=90%>";
     print "<tr>";
       print "<td width=90>{$Cpt_opfa_Passwd}</td>";
       print "<td><input name=password type=password size=35 maxlength=35 value={$Password}></td>";
       print "<td><a class=Mustred href=index.php?page=changepassword_emailset&pswdfile={$FileName}&questlength={$QuestLength}>{$Cpt_opfa_SendPass1}</a></td>";
     print "</tr>";
     print "<tr>";
       print "<td>{$Cpt_opfa_ConfPass}</td>";
       print "<td><input name=passwordconf type=password size=35 maxlength=35 value={$PasswordConf}></td>";
       print "<td>&nbsp;</td>";
     print "</tr>";
     print "</table>";
     print "<table class=General align=center border=0 cellspacing=0 cellpadding=0 width=90%>";
       print "<tr align=center>";
         print "<td><input class=ButtonSettings type=button value={$Cpt_Back} onClick = 'history.back()'>";
         print "&nbsp;<input class=ButtonSettings type=submit value={$Cpt_Save} name = save>";
         print "&nbsp;<input class=ButtonSettings type=reset value={$Cpt_Reset}></td>";
       print "</tr>";
     print "</table>";
     print "<input type=hidden name=pswdstatus value='{$PswdStatus}'>";
   print "</table>";
  print "</fieldset>";

  print "</form>";
?>