
<?php
  if(empty($_POST))
  {
    $Pos = $_GET['pos'];
    $Users = file($PswdFile);
    $Login = trim($Users[$Pos]);
    if(strpos($Login, ' (%%%voted%%%)') !== false)
    {
      $Login = str_replace(' (%%%voted%%%)', '', $Login);
      $Voted = 'checked';
    }
    else $Voted = '';
  }
  elseif(!empty($_POST))
  {
    include('_form_addnewvipuser_correct.inc');
    $VoteStatus = $_POST['votestatus'];
    $Pos = $_POST['pos'];
    //рассылка логина и пароля копия аналогичного кода из модуля changepasswords_adduser.inc
    if($SendPassword == 'on')
    {
      if(file_exists($LetterFile))
      {
        $Letter = file($LetterFile);
	      $MessSubject = trim($Letter[0]);
	      $EmailFrom = trim($Letter[1]);
	      $MessText = base64_decode(trim($Letter[2]));
      } else
        $Errors[] = "{$Err_lapfe_NoEmailSettings[0]} <a href='index.php?page=ch_passwords_emailset&pswdfile={$PswdFile}&questlength={$QuestLength}'>{$Err_lapfe_NoEmailSettings[1]}</a>";
      if(empty($Errors))
      {
      	if(!@mail($Email, $MessSubject, $MessText, $EmailFrom))
	        $Errors[] = "{$Err_lapfe_CantSend} {$Email}";
      }
    }
    if(empty($Errors))
    {
      if($VoteStatus =='on')
        $Login = $Login." (%%%voted%%%)";
      $Users = file($PswdFile);
      $Users[$Pos] = $Login."\n";
      $Users[($Pos+1)] = md5($Password)."\n";
      SaveStringInFile($PswdFile, implode('', $Users), 'w');
      Refresh("ch_passwords&pswdfile={$PswdFile}&questlength={$QuestLength}");
    }
  }
  print "<h4><i>{$Heading_lapfe_EditUser}</i></h4>";
  print "<h5><i>{$Question}</i></h5>";
  print "<form action='' method=post>";
    ShowErrors($Errors, '100%');
    include('_form_addnewvipuser.inc');
  print "<input type=hidden name=pos value={$Pos}>";
  print "</form>";
?>