<?



  include '../../config.inc.php';
  require_once 'data/config.php';
  $table = 'newsletter';
  if ($_GET['submitted'])
  {
    $address = $_GET['address'];
    $action = $_GET['action'];
    if (!eregi ('' . '^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z][-.0-9a-z]*\\.[a-z]{2,4}[.]?$', $address))
    {
      echo '' . '<b>ERROR:</b> The e-mail address you entered (' . $address . ') is invalid!<p><a href="javascript:self.close();">Close</a> this window';
    }
    else
    {
      if ($action == 'add')
      {
        $query = '' . 'INSERT INTO ' . $table . ' (address, dateadd) VALUES(\'' . $address . '\', NOW())';
        if (!($result = mysql_query ($query)))
        {
          exit ('<b>ERROR:</b> ' . mysql_error ());
          ;
        }

        if ($welcomestatus == 1)
        {
          $mailheaders = '' . 'From: ' . $listname . ' <' . $adminemail . '>
';
          $mailheaders .= '' . 'Reply-To: ' . $adminemail;
          $file = file ('data/welcomemsg.dat');
          $lines = count ($file);
          $body = '';
          for ($i = 0; $i < $lines; ++$i)
          {
            $body .= $file[$i];
          }

          mail ($address, $welcomesubject, $body, $mailheaders);
        }

        echo 'You have been subscribed to the mailing list <b>successfully</b>!';
      }
      else
      {
        if ($action == 'remove')
        {
          $query = '' . 'SELECT address FROM ' . $table . ' where address=\'' . $address . '\'';
          if (!($result = mysql_query ($query)))
          {
            exit ('<b>ERROR:</b> ' . mysql_error ());
            ;
          }

          if (0 < mysql_num_rows ($result))
          {
            $query = '' . 'DELETE FROM ' . $table . ' where address=\'' . $address . '\'';
            if (!($result = mysql_query ($query)))
            {
              exit ('<b>ERROR:</b> ' . mysql_error ());
              ;
            }

            if ($goodbyestatus == 1)
            {
              $mailheaders = '' . 'From: ' . $listname . ' <' . $adminemail . '>
';
              $mailheaders .= '' . 'Reply-To: ' . $adminemail;
              $file = file ('data/goodbyemsg.dat');
              $lines = count ($file);
              $body = '';
              for ($i = 0; $i < $lines; ++$i)
              {
                $body .= $file[$i];
              }

              mail ($address, $goodbyesubject, $body, $mailheaders);
            }

            echo '' . '<i>' . $address . '</i> has been removed from the mailing list <b>successfully</b>!<br><br><a href="javascript:self.close();">Close</a> this window';
          }
          else
          {
            echo '' . '<b>ERROR:</b> <i>' . $address . '</i> is not currently subscribed to the mailing list.<br><br><a href="javascript:self.close();">Close</a> this window';
          }
        }
      }
    }
  }
  else
  {
    if (($_GET['action'] == 'remove' AND $_GET['address'] != ''))
    {
      $address = $_GET['address'];
      if (!($connection = mysql_connect ($db_hostname, $db_username, $db_password)))
      {
        exit ('<b>ERROR:</b> Unable to connect!');
        ;
      }

      if (!(mysql_select_db ($db_name)))
      {
        exit ('<b>ERROR:</b> Unable to select database!');
        ;
      }

      $query = '' . 'SELECT address FROM ' . $table . ' where address=\'' . $address . '\'';
      if (!($result = mysql_query ($query)))
      {
        exit ('<b>ERROR:</b> ' . mysql_error ());
        ;
      }

      if (0 < mysql_num_rows ($result))
      {
        $query = '' . 'DELETE FROM ' . $table . ' where address=\'' . $address . '\'';
        if (!($result = mysql_query ($query)))
        {
          exit ('<b>ERROR:</b> ' . mysql_error ());
          ;
        }

        if ($goodbyestatus == 1)
        {
          $mailheaders = '' . 'From: ' . $listname . ' <' . $adminemail . '>
';
          $mailheaders .= '' . 'Reply-To: ' . $adminemail;
          $file = file ('data/goodbyemsg.dat');
          $lines = count ($file);
          $body = '';
          for ($i = 0; $i < $lines; ++$i)
          {
            $body .= $file[$i];
          }

          mail ($address, $goodbyesubject, $body, $mailheaders);
        }

        echo '' . '<i>' . $address . '</i> has been removed from the mailing list <b>successfully</b>!<br><br><a href="javascript:self.close();">Close</a> this window';
      }
      else
      {
        echo '' . '<b>ERROR:</b> <i>' . $address . '</i> is not currently subscribed to the mailing list.<br><br><a href="javascript:self.close();">Close</a> this window';
      }
    }
    else
    {
      echo '<center><b>ERROR:</b> You have accessed this page from an invalid location.</center>';
    }
  }

?>
