
<?php
  if(count($_POST) == 0)
  {
    $PswdFile = $_GET['pswdfile'];
    $Pos = $_GET['pos'];
    $QuestLength = $_GET['questlength'];
    $EmailAddrFile = "../txt/".str_replace("pswd", "onepassd_emailaddr", $PswdFile);
    $EmailAddrArr = file($EmailAddrFile);
    $Email = $EmailAddrArr[$Pos];
    if(strpos($Email, ' (%%sended%%)') === false)
      $Checked = ''; else $Checked = 'checked';
    $Email = str_replace(' (%%sended%%)', '', $Email);
    $Question = GetQuestion("../txt/".$PswdFile, $QuestLength, 'pswd');
  }
  elseif(count($_POST) > 0)
  {
    //Переменные для передачи методом ГЕТ
    $Question = $_POST['question'];
    $PswdFile = $_POST['pswdfile'];
    $QuestLength = $_POST['questlength'];
    //Переменные, используемые данным модулем
    $Pos = $_POST['pos'];
    $Email = $_POST['email'];
    //Проверяем ввод пользователя на корректность
    if(!preg_match("/[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,3}/i", $Email))
      $Errors[] = $Err_opfa_IncorrEmail;
    //отмечаем: послано/не послано
    if(empty($Errors))
    {
      $Sended = $_POST['sended'];
	    if($Sended == '')
	      $Email = str_replace(' (%%sended%%)', '', $Email);
	    else {
	      if(strpos($Sended, ' (%%sended%%)') === false)
	        $Email = $Email.' (%%sended%%)';
	    }
	    //Записываем изменения в файл
	    $EmailAddrFile = "../txt/".str_replace("pswd", "onepassd_emailaddr", $PswdFile);
	    $EmailAddrArr = file($EmailAddrFile);
	    $EmailAddrArr[$Pos] = $Email."\n";
	    SaveStringInFile($EmailAddrFile, implode('', $EmailAddrArr), 'w');
	    Refresh("changepassword_emailset&pswdfile={$PswdFile}&questlength={$QuestLength}");
    }
  }
  print "<form action='' method=post>";
  print "<h4>{$Heading_EmailList}</h4>";
  print "<h5>{$Question}</h5>";
  ShowErrors($Errors, '90%', 'VeryMiniField').'<br>';
  print "<fieldset class=VeryMiniField align=center>";
  print "<table class=General align=center border=0 cellspacing=0 cellpadding=0 width=90%>";
    print "<tr>";
      print "<td>{$Cpt_opfa_Email}</td>";
      print "<td><input name=email type=text size=35 maxlength=60 value={$Email}></td>";
    print "</tr>";
    print "<tr>";
      print "<td>{$Cpt_opfa_Sended2}</td>";
      print "<td><input name=sended type=checkbox name=sended {$Checked}></td>";
    print "</tr>";
  print "</table>";
  print "<table class=General align=center border=0 cellspacing=0 cellpadding=0 width=90%>";
    print "<tr><td align=center><input class=Button type=Submit name=Change value='{$Button_Change}'></td></tr>";
  print "</table>";
  print "</fieldset>";
  print "<input type=hidden name=question value='{$Question}'>";
  print "<input type=hidden name=pswdfile value='{$PswdFile}'>";
  print "<input type=hidden name=questlength value='{$QuestLength}'>";
  print "<input type=hidden name=pos value='{$Pos}'>";
  print "</form>";

?>