
<?php
  //Инициализируем переменные
  $PswdFile = $_GET['pswdfile'];
  $QuestLength=$_GET['questlength'];
  $Question = getquestion($PswdFile, $QuestLength);
   //выбираем из файла массив с логинами, паролями и адресами
  $fp = fopen($File_Tmp, 'r');
  $Serialized = fread($fp, 8000);
  fclose($fp);
  $Generated = unserialize($Serialized);
  if(empty($_GET['conf']))
  {
    print "<br><br>";
    print "<div align=center>";
      print "{$Conf_gen_Send}<br><br>";
      print "<a href=index.php?page=ch_passwords_gener_sendpswd&conf=1&pswdfile={$PswdFile}&questlength=$QuestLength>{$Cpt_Yes}</a>&nbsp;&nbsp;&nbsp;";
      print "<a href=index.php?page=ch_passwords_gener_sendpswd&conf=2&pswdfile={$PswdFile}&questlength=$QuestLength>{$Cpt_No}</a>";
    print "</div><br>";
    print "<table cellspacing=0 cellpadding=0 border=0 align=center>";
    for($i = 0; $i < count($Generated); $i = $i + 3)
    {
      print "<tr><td><b>".$Generated[$i]."</b></td></tr>";
      print "<tr><td>".$Generated[($i+1)]."</td></tr>";
      print "<tr><td>".$Generated[($i+2)]."</td></tr>";

    }
    print "</table>";
  }

  //рассылка паролей
  if($_GET['conf'] == 1)
  {
    //выбираем тему письма, адрес отправителя, текст письма
    $Letter = file($LetterFile);
    $MessSubject = trim($Letter[0]);
    $EmailFrom = trim($Letter[1]);
    $MessText = trim(base64_decode($Letter[2]));
    for($i = 0; $i < count($Generated); $i = $i + 3)
    {
      $Login = trim($Generated[$i]);
	    $Email = trim($Generated[($i+1)]);
	    $Password = trim($Generated[($i+2)]);
      if($Email != 'no')
      {
        $Sended[] = $Login;
        $Sended[] = $Password;
        $Sended[] = $Email;
        $MessText = str_replace('%%Login%%', $Login, $MessText);
	      $MessText = str_replace('%%Password%%', $Password, $MessText);
        if(@mail($Email, $MessSubject, $MessText, $EmailFrom))
          $Sended[] = $Cpt_gen_Sended;
        else
          $Sended[] = "<span class=mustred>{$Cpt_gen_NotSended}</span>";
      } else
      {
        $NoSended[] = $Login;
        $NoSended[] = $Password;
      }
    } //for($i = 0; $i < count($Generated); $i = $i + 3)
//Отправка писем-приглашений: статус
    print "<h5>{$Heading_gen_SendState}</h5>";
    print "<table align=center cellspacing=0 cellpadding=0 class=OrdTable border=1>";
    print "<tr>";
      print "<td align=center><b>{$TH_gen_Login}</b></td>";
      print "<td align=center><b>{$TH_gen_Password}</b></td>";
      print "<td align=center><b>{$TH_gen_Email}</b></td>";
      print "<td align=center><b>{$TH_gen_State}</b></td>";
    print "</tr>";
    for($i = 0; $i < count($Sended); $i = $i + 4)
    {
      print "<tr>";
        print "<td>{$Sended[$i]}</td>";
	      print "<td>{$Sended[($i+1)]}</td>";
	      print "<td>{$Sended[($i+2)]}</td>";
	      print "<td>{$Sended[($i+3)]}</td>";
      print "</tr>";
    }
    print "</table>";
//Отправка писем-приглашений: статус
    print "<h5>{$Heading_gen_NoEmail}</h5>";
    print "<table align=center cellspacing=0 cellpadding=0 class=OrdTable border=1>";
    print "<tr>";
      print "<td align=center><b>{$TH_gen_Login}</b></td>";
      print "<td align=center><b>{$TH_gen_Password}</b></td>";
    print "</tr>";
    for($i = 0; $i < count($NoSended); $i = $i + 2)
    {
      print "<tr>";
        print "<td>{$NoSended[$i]}</td>";
	      print "<td>{$NoSended[($i+1)]}</td>";
      print "</tr>";
    }
    print "</table>";
    SaveStringInFile($File_Tmp, '', 'w');
  } //if($_GET['conf'] == 1)

  //не рассылать пароли
  if($_GET['conf'] == 2)
  {
    SaveStringInFile($File_Tmp, '', 'w');
    Refresh("ch_passwords&pswdfile={$PswdFile}&questlength={$QuestLength}");
  }
?>