
<?php

  if(count($_POST) > 0)
  {
    include('_form_addnewvipuser_correct.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))
      {
        $MessText = str_replace('%%Login%%', $Login, $MessText);
        $MessText = str_replace('%%Password%%', $Password, $MessText);
        if(!@mail($Email, $MessSubject, $MessText, $EmailFrom))
	        $Errors[] = "{$Err_lapfe_CantSend} {$Email}";
	      else $Message = "{$Cpt_lapfe_LetterIsSended} {$Email}";
      }
    }
    if(empty($Errors))
    {
      $Str  = $Login."\n";
      $Str .= md5($Password)."\n";
      $State = SaveStringInFile($PswdFile, $Str, 'a');
      if(empty($State))
      {
        $Message = "{$Cpt_lapfe_UserIsAdded[0]} <b>{$Login}</b> {$Cpt_lapfe_UserIsAdded[1]}";
        $Login = '';
      }
      //Refresh("ch_passwords_adduser&pswdfile={$PswdFile}&Mess=1&questlength={$QuestLength}");
    }
  }
  print "<h4><i>{$Heading_lapfe_AddUser}</i></h4>";
  print "<h5><i>{$Question}</i></h5>";
  print "<form action='' method=post>";
    if($ShowTips == 'yes')
      ShowTips($Page);
    ShowMessage($Message, '100%');
    ShowErrors($Errors, '100%');
    include('_form_addnewvipuser.inc');
  print "</form>";
?>