<?

  function goto ($url)
  {
    header ('' . 'Location: ' . $url);
  }

  function heading ($heading)
  {
    echo '<tr><td><table width="100%" border="0" bgcolor="#505090" cellpadding="3" cellspacing="1">';
    echo '<tr>';
    echo '' . '<td bgcolor="#BFBFDF"><span class="header">&nbsp;<B><FONT FACE=Tahoma>' . $heading . '</FONT></B></span></td>';
    echo '</tr><tr><td bgcolor="#EFEFF8">';
  }

  function endtable ()
  {
    echo '</td></tr></table></td></tr>';
  }

  function table ($what)
  {
    echo ($what == 'begin' ? '<table width="100%" border="0" cellpadding="0" cellspacing="3">' : '</table>');
  }

  include_once '../../config.inc.php';
  if (!include '../autorization.php')
  {
    echo 'Access denied!';
    exit ();
  }

  require_once 'data/config.php';
  $table = 'newsletter';
  echo '<html>
<head>
';
  echo '<s';
  echo 'tyle type="text/css">
<!--
body, td { font-family:Tahoma; font-size:10pt; color:#000000; }
form { font-family:Tahoma; margin-top:0px; margin-bottom:0px; }
.button_off { width:125; cursor:arrow; font:8pt Tahoma; color:#000000; border:1px solid; border-color:#000000; background:#EEEEEE; }
.button_on { width:125; cursor:pointer; font:8pt Tahoma; color:#000099; font-weight:bold; border:1px solid; ';
  echo 'border-color:#000000; background:#EEEEEE; }
.formitem { font-family:Tahoma; font-size:9pt; }
.header { font-size:9pt; font-family:Tahome; color:navy; }
.logo { font-size:10pt; font-family:Tahoma; color:#FF0000; font-weight:bold; }
-->
</style>
';
  echo '<s';
  echo 'cript language="JavaScript">
<!--
function goto(URL) {
window.location.href = URL;
}
-->
</script>
</head>
<body text="#000000" link="blue" alink="blue" vlink="blue" topmargin="5" leftmargin="0" rightmargin="0" bottommargin="0">
<table width="760" border="0" cellpadding="2" cellspacing="0">
<tr>
</td><td width="635" valign="top">
';
  if ($_POST['action'] == 'listsettings')
  {
    $file = fopen ('data/config.php', 'w');
    fputs ($file, '<?
');
    fputs ($file, '$siteurl = "' . $_POST['siteurl'] . '";' . '
');
    fputs ($file, '$adminemail = "' . $_POST['adminemail'] . '";' . '
');
    fputs ($file, '$listname = "' . $_POST['listname'] . '";' . '
');
    fputs ($file, '$unsubscribelink = "' . $_POST['unsubscribelink'] . '";' . '
');
    fputs ($file, '$welcomesubject = "' . $_POST['welcomesubject'] . '";' . '
');
    fputs ($file, '$welcomestatus = "' . $_POST['welcomestatus'] . '";' . '
');
    fputs ($file, '$goodbyesubject = "' . $_POST['goodbyesubject'] . '";' . '
');
    fputs ($file, '$goodbyestatus = "' . $_POST['goodbyestatus'] . '";');
    fputs ($file, '
?>');
    fclose ($file);
    $file = fopen ('data/welcomemsg.dat', 'w');
    fputs ($file, stripslashes ($_POST['welcomemsg']));
    fclose ($file);
    $file = fopen ('data/goodbyemsg.dat', 'w');
    fputs ($file, stripslashes ($_POST['goodbyemsg']));
    fclose ($file);
    table ('begin');
    heading ('Update Successful');
    echo '<table border="0" cellpadding="3" cellspacing="0"><td>';
    echo 'The list settings have been saved.<p>';
    echo 'Click <a href="admin.php?action=listsettings">here</a> to return.';
    echo '</td></table>';
    endtable ();
    table ('end');
  }
  else
  {
    if ($_POST['action'] == 'sendmsg')
    {
      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;
      if (!($result = mysql_query ($query)))
      {
        exit ('<b>ERROR:</b> ' . mysql_error ());
        ;
      }

      if (0 < mysql_num_rows ($result))
      {
        $subject = $_POST['subject'];
        $body = $_POST['message'];
        $mailheaders = '' . 'From: ' . $listname . ' <' . $adminemail . '>
';
        $mailheaders .= '' . 'Reply-To: ' . $adminemail;
        if ($unsubscribelink == 1)
        {
          $body .= '

---------------------------------------------------
';
          $body .= '' . 'You are receiving this e-mail because you are subscibed to "' . $listname . '".
';
          $body .= 'If you would like to be removed from the mailing list, please click the link below:
';
          $body .= '' . $siteurl . '/newsadmin/newsletter/mailer.php?action=remove&address=' . $address;
        }

        if (!($result = mysql_query ($query)))
        {
          exit ('<b>ERROR:</b> ' . mysql_error ());
          ;
        }

        while ($row = mysql_fetch_object ($result))
        {
          $address = $row->address;
          mail ($address, $subject, $body, $mailheaders);
        }

        table ('begin');
        heading ('E-mails Sent!');
        echo '<table border="0" cellpadding="3" cellspacing="0"><td>';
        echo 'The e-mail message has been sent to <b>' . mysql_num_rows ($result) . '</b> addresses.<p>';
        echo 'Click <a href="admin.php">here</a> to return.';
        echo '</td></table>';
        endtable ();
        table ('end');
      }
      else
      {
        echo '<b>ERROR:</b> You do not have any subscribers for your list.';
      }
    }
    else
    {
      if ($_POST['action'] == 'deleteaddress')
      {
        $id = $_POST['id'];
        $address = $_POST['email'];
        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 = '' . 'DELETE FROM ' . $table . ' WHERE id=' . $id;
        if (!($result = mysql_query ($query)))
        {
          exit ('<b>ERROR:</b> ' . mysql_error ());
          ;
        }

        table ('begin');
        heading ('Deletion Successful');
        echo '<table border="0" cellpadding="3" cellspacing="0"><td>';
        echo '' . 'E-mail address <b>' . $address . '</b> has been removed from the mailing list.<p>';
        echo 'Click <a href="admin.php?action=subscribers">here</a> to return.';
        echo '</td></table>';
        endtable ();
        table ('end');
      }
      else
      {
        if ($_POST['action'] == 'adduser')
        {
          $address = $_POST['address'];
          if (!eregi ('' . '^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z][-.0-9a-z]*\\.[a-z]{2,4}[.]?$', $address))
          {
            table ('begin');
            heading ('Invalid E-mail Address');
            echo '<table border="0" cellpadding="3" cellspacing="0"><td>';
            echo '' . 'The e-mail address you entered (' . $address . ') is invalid!<p><a href="javascript:self.close();">Close</a> this window';
            echo '</td></table>';
            endtable ();
            table ('end');
          }
          else
          {
            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 = '' . 'INSERT INTO ' . $table . '(address, dateadd) VALUES(\'' . $address . '\', NOW())';
            if (!($result = mysql_query ($query)))
            {
              exit ('<b>ERROR:</b> ' . mysql_error ());
              ;
            }

            table ('begin');
            heading ('Addition Successful');
            echo '<table border="0" cellpadding="3" cellspacing="0"><td>';
            echo '' . 'E-mail address <b>' . $address . '</b> has been added to the mailing list.<p>';
            echo 'Click <a href="admin.php?action=subscribers">here</a> to return.';
            echo '</td></table>';
            endtable ();
            table ('end');
          }
        }
        else
        {
          if ($_POST['action'] == 'importlist')
          {
            $addresses = explode ('
', $_POST['addresses']);
            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!');
              ;
            }

            foreach ($addresses as $address)
            {
              $query = '' . 'INSERT INTO ' . $table . '(address, dateadd) VALUES(\'' . $address . '\', NOW())';
              if (!($result = mysql_query ($query)))
              {
                exit ('<b>ERROR:</b> ' . mysql_error ());
                ;
              }
            }

            table ('begin');
            heading ('Addition Successful');
            echo '<table border="0" cellpadding="3" cellspacing="0"><td>';
            echo 'Added <b>' . count ($addresses) . '</b> addresses to the list..<p>';
            echo 'Click <a href="admin.php?action=subscribers">here</a> to return.';
            echo '</td></table>';
            endtable ();
            table ('end');
          }
          else
          {
            if ($_GET['action'] == 'config')
            {
              table ('begin');
              echo '<form action="admin.php" method="post"><input type="hidden" name="action" value="config">';
              echo '<tr><td>';
              echo '<input type="submit" value="Save Settings" class="formitem">';
              echo '</td></tr>';
              heading ('General Configuration');
              echo '	<table border="0" cellpadding="3" cellspacing="0">
	<td>Admin Password:<BR><input type="text" name="password" value="';
              echo $password;
              echo '" class="formitem"></td>
	<td>Admin E-mail:<BR><input type="text" name="adminemail" size="25" value="';
              echo $adminemail;
              echo '" class="formitem"></td>
	<td>Location of scripts (<b>don\'t</b> include a trailing /)<BR><input type="text" name="siteurl" style="width:100%" value="';
              echo $siteurl;
              echo '" class="formitem"></td>
	</table><table width="100%" border="0" cellpadding="3" cellspacing="0">
	<td width="50%">Header File:<BR><input type="text" name="header" style="width:100%" value="header.html" class="formitem"></td>
	<td width="50%">Footer File:<BR><input type="text" style="width:100%" name="footer" value="footer.html" class="formitem"></td>
	</tr>
	</table>
	';
              endtable ();
              heading ('MySQL Configuration');
              echo '	<table border="0" cellpadding="3" cellspacing="0">
	<tr>
	<td>Database:<BR><input type="text" name="db" value="';
              echo $db_name;
              echo '" class="formitem"></td>
	<td>Hostname:<BR><input type="text" name="db_host" value="';
              echo $db_hostname;
              echo '" class="formitem"></td>
	<td>Table:<BR><input type="text" value="';
              echo $table;
              echo '" class="formitem" disabled></td>
	</tr><tr>
	<td>Username:<BR><input type="text" name="db_user" value="';
              echo $db_username;
              echo '" class="formitem"></td>
	<td colspan="2">Password:<BR><input type="text" name="db_pass" value="';
              echo $db_password;
              echo '" class="formitem"></td>
	</tr>
	</table>
	';
              endtable ();
              echo '<tr><td>';
              echo '<input type="submit" value="Save Settings" class="formitem">';
              echo '</td></tr>';
              echo '</form>';
              table ('end');
            }
            else
            {
              if ($_GET['action'] == 'listsettings')
              {
                table ('begin');
                echo '<form action="admin.php" method="post"><input type="hidden" name="action" value="listsettings">';
                echo '<tr><td>';
                echo '</td></tr>';
                heading ('Mailing List Settings');
                echo '	<table border="0" cellpadding="3" cellspacing="0">
	<td>List Name:<BR><input type="text" name="listname" size="30" value="';
                echo $listname;
                echo '" class="formitem"></td>
	<td>Send E-mails As:<BR><input type="text" name="adminemail" value="';
                echo $adminemail;
                echo '" class="formitem"></td>
	<td>Site URL:<BR><input type="text" name="siteurl" value="';
                echo $siteurl;
                echo '" class="formitem" size=30></td>
	</table><table border="0" cellpadding="3" cellspacing="0">
	<td>Provide subscribers with a link to unsubscribe in outgoing e-mails? ';
                echo '<s';
                echo 'elect name="unsubscribelink" class="formitem">';
                echo ($unsubscribelink == 1 ? '<option value"0">No</option><option value="1" selected>Yes</option>' : '<option value"0" selected>No</option><option value="1">Yes</option>');
                echo '</select></td>
	</table>
	';
                endtable ();
                $file = file ('data/welcomemsg.dat');
                $lines = count ($file);
                heading ('Welcome E-mail');
                echo '	<table width="100%" border="0" cellpadding="3" cellspacing="0"><td>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<td>Subject: <input type="text" name="welcomesubject" size="30" value="';
                echo $welcomesubject;
                echo '" class="formitem"></td>
	<td align="right">Status: ';
                echo '<s';
                echo 'elect name="welcomestatus" class="formitem">';
                echo ($welcomestatus == '1' ? '<option value="1" selected>Enabled</option><option value="0">Disabled</option>' : '<option value="1">Enabled</option><option value="0" selected>Disabled</option>');
                echo '</select></td>
	</table><BR>
	Message:<BR><textarea name="welcomemsg" class="formitem" rows="9" style="width:100%">';
                for ($i = 0; $i < $lines; ++$i)
                {
                  echo $file[$i];
                }

                echo '</textarea>
	</td></table>
	';
                endtable ();
                $file = file ('data/goodbyemsg.dat');
                $lines = count ($file);
                heading ('Goodbye E-mail');
                echo '	<table width="100%" border="0" cellpadding="3" cellspacing="0"><td>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<td>Subject: <input type="text" name="goodbyesubject" size="30" value="';
                echo $goodbyesubject;
                echo '" class="formitem"></td>
	<td align="right">Status: ';
                echo '<s';
                echo 'elect name="goodbyestatus" class="formitem">';
                echo ($goodbyestatus == '1' ? '<option value="1" selected>Enabled</option><option value="0">Disabled</option>' : '<option value="1">Enabled</option><option value="0" selected>Disabled</option>');
                echo '</select></td>
	</table><BR>
	Message:<BR><textarea name="goodbyemsg" class="formitem" rows="9" style="width:100%">';
                for ($i = 0; $i < $lines; ++$i)
                {
                  echo $file[$i];
                }

                echo '</textarea>
	</td></table>
	';
                endtable ();
                echo '<tr><td>';
                echo '<input type="submit" value="Save Settings" class="formitem">';
                echo '</td></tr>';
                echo '</form>';
                table ('end');
              }
              else
              {
                if ($_GET['action'] == 'subscribers_add')
                {
                  table ('begin');
                  heading ('Subscribers - Subscribe a new address');
                  echo '	<table width="100%" border="0" cellpadding="3" cellspacing="0"><td>
	To subscribe a new e-mail address, just enter it below:<p>
	<form action="admin.php" method="post">
	<input type="hidden" name="action" value="adduser">
	E-mail Address: <input type="text" name="address" size="25" class="formitem"> <input type="submit" value="Subscribe Address!" class="formitem">
	</form>
	</td></table>
	';
                  endtable ();
                  table ('end');
                }
                else
                {
                  if ($_GET['action'] == 'subscribers_import')
                  {
                    table ('begin');
                    heading ('Subscribers - Import a list');
                    echo '	<table width="100%" border="0" cellpadding="3" cellspacing="0"><td>
	To import a list of addresses to the mailing list, just paste the addresses into the box below.<p>
	<font color="#FF0000"><b>NOTE:</b> Make sure you only have on address per line. An sample list may be:<BR>
	user1@domain.com<BR>user2@domain.com<BR>user3@domain.com</font><p>
	<b>REMEMBER! ONE ADDRESS PER LINE!</b>
	<form action="admin.php';
                    echo '" method="POST">
	<input type="hidden" name="action" value="importlist">
	<textarea name="addresses" style="width:100%" cols="75" rows="10" class="formitem"></textarea><BR>
	<input type="submit" value="Import List!" class="formitem">
	</form>
	</td></table>
	';
                    endtable ();
                    table ('end');
                  }
                  else
                  {
                    if ($_GET['action'] == 'subscribers_export')
                    {
                      table ('begin');
                      heading ('Subscribers - Export list of subscribers');
                      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 id, address FROM ' . $table . ' ORDER BY dateadd ASC';
                      if (!($result = mysql_query ($query)))
                      {
                        exit ('<b>ERROR:</b> ' . mysql_error ());
                        ;
                      }

                      echo '	<table width="100%" border="0" cellpadding="3" cellspacing="0"><td>
	Below is a list of each address subscribed to the mailing list, each address on a new line. If you want to save this list, simply select everything in the text box below and paste it into a text file.<p>';
                      echo '<textarea cols="55" rows="15" style="width:100%;">';
                      echo 'List as of: ' . date ('M. j, Y') . ' (' . date ('g:ia') . ')
';
                      echo ('' . 'List name: ' . $listname . '
');
                      echo 'Total subscribers: ' . mysql_num_rows ($result);
                      echo '

';
                      while ($row = mysql_fetch_object ($result))
                      {
                        echo $row->address;
                        echo '
';
                      }

                      echo '</textarea>';
                      echo '	</td></table>
	';
                      endtable ();
                      table ('end');
                    }
                    else
                    {
                      if ($_GET['action'] == 'subscribers_deleteall')
                      {
                        table ('begin');
                        heading ('Deletion successful');
                        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 = '' . 'DELETE FROM ' . $table;
                        if (!($result = mysql_query ($query)))
                        {
                          exit ('<b>ERROR:</b> ' . mysql_error ());
                          ;
                        }

                        echo '	<table width="100%" border="0" cellpadding="3" cellspacing="0"><td>
	All users have been removed from the mailing list. Your list now contains <b>0</b> subscribers.<p>
	Click <a href="admin.php?action=subscribers">here</a> to return.
	</td></table>
	';
                        endtable ();
                        table ('end');
                      }
                      else
                      {
                        if ($_GET['action'] == 'subscribers')
                        {
                          table ('begin');
                          heading ('Subscribers');
                          echo '	<center><form action="admin.php" method="GET">
	<input type="hidden" name="action" value="subscribers">
	Sort By: ';
                          echo '<s';
                          echo 'elect name="sortby" class="formitem">
	';
                          echo ($_GET['sortby'] == 'dateadd' ? '<option value="address">E-mail Address</option><option value="dateadd" selected>Date Subscribed</option>' : '<option value="address" selected>E-mail Address</option><option value="dateadd">Date Subscribed</option>');
                          echo '	</select>
	Order: ';
                          echo '<s';
                          echo 'elect name="order" class="formitem">
	';
                          echo ($_GET['order'] == 'desc' ? '<option value="asc">Ascending</option><option value="desc" selected>Descending</option>' : '<option value="asc" selected>Ascending</option><option value="desc">Descending</option>');
                          echo '	</select>
	<input type="submit" value="Refresh" class="formitem">
	</form><p>
	';
                          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!');
                            ;
                          }

                          $orderby = ($_GET['sortby'] == '' ? 'address' : $_GET['sortby']);
                          $order = ($_GET['order'] == '' ? 'ASC' : $_GET['order']);
                          $query = '' . 'SELECT id, address, DATE_FORMAT(dateadd, \'%b. %e, %Y at %l:%i%p\') as subscribed FROM ' . $table . ' ORDER BY ' . $orderby . ' ' . $order;
                          if (!($result = mysql_query ($query)))
                          {
                            exit ('<b>ERROR:</b> ' . mysql_error ());
                            ;
                          }

                          echo '<table border="0" bgcolor="#000000" cellpadding="2" cellspacing="1" align="center">';
                          echo '<tr>';
                          echo '<td bgcolor="#DDDDDD" align="center"><b>E-mail Address</b></td>';
                          echo '<td bgcolor="#DDDDDD" align="center"><b>Date Subscribed</b></td>';
                          echo '<td bgcolor="#DDDDDD" align="center"><b>Options:</b></td>';
                          echo '</tr>';
                          if (mysql_num_rows ($result) == 0)
                          {
                            echo '<tr><td colspan="3" bgcolor="#EEEEEE" align="center">No one is subscribed yet.</td></tr>';
                          }
                          else
                          {
                            while ($row = mysql_fetch_object ($result))
                            {
                              echo '<tr bgcolor="';
                              if ($i++ % 2)
                              {
                                echo '#BFBFDF';
                              }
                              else
                              {
                                echo '#DCDCED';
                              }

                              echo '">';
                              echo '' . '<td>' . $row->address . '</td>';
                              echo '<td>' . str_replace (array ('AM', 'PM'), array ('am', 'pm'), $row->subscribed) . '</td>';
                              echo '' . '<td><form action="admin.php" method="post" onSubmit="javascript:return confirm(\'Are you sure you want to remove this address from the mailing list?\');"><input type="hidden" name="action" value="deleteaddress"><input type="hidden" name="id" value="' . $row->id . '"><input type="hidden" name="email" value="' . $row->address . '"><input type="submit" value="Delete" class="formitem"></form></td>';
                              echo '</tr>';
                            }
                          }

                          echo '</table><p>';
                          endtable ();
                          heading ('Options');
                          echo '<table width="100%" border="0" cellpadding="3" cellspacing="0"><td>';
                          echo '<b>Options:</b><BR>';
                          echo '<ul style="MARGIN-TOP:0px; MARGIN-BOTTOM:0px;">';
                          echo '<li><a href="admin.php?action=subscribers_add">Add an address</a></li>';
                          echo '<li><a href="admin.php?action=subscribers_import">Import addresses</a></li>';
                          echo '<li><a href="admin.php?action=subscribers_export">Export current list</a></li>';
                          echo '<li><a href="admin.php?action=subscribers_deleteall" onClick="javascript:return confirm(\'Are you sure you want to delete ALL subscribers?\\n\\nTHIS ACTION CANNOT BE UNDONE!\')">Delete ALL subscribers</a></li>';
                          echo '</ul>';
                          echo '</td></table>';
                          endtable ();
                          table ('end');
                        }
                        else
                        {
                          if ($_GET['action'] == 'sendemail')
                          {
                            table ('begin');
                            heading ('Message Composition');
                            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;
                            if (!($result = mysql_query ($query)))
                            {
                              exit ('<b>ERROR:</b> ' . mysql_error ());
                              ;
                            }

                            $subscribers = mysql_num_rows ($result);
                            echo '	<form action="admin.php" method="POST">
	<input type="hidden" name="action" value="sendmsg">
	<table width="100%" border="0" cellpadding="0" cellspacing="2">
	<tr>
	<td>Subject:<BR><input type="text" name="subject" size="65" class="formitem"></td>
	<td align="right">From: <b>';
                            echo $listname;
                            echo '</b><BR>
	Reply to: <b>';
                            echo $adminemail;
                            echo '</b></td>
	</tr><tr>
	<td colspan="2"><BR>Message:<BR><textarea name="message" rows="25" class="formitem" style="width:100%;"></textarea></td>
	</tr><tr>
	<td colspan="2" align="right">Send an e-mail to <b>';
                            echo $subscribers;
                            echo '</b> users: <input type="submit" value="Send it!" class="formitem"></td>
	</tr>
	</table>
	</form>
	';
                            endtable ();
                            table ('end');
                          }
                          else
                          {
                            if ($_GET['action'] == 'logout')
                            {
                              session_destroy ();
                              table ('begin');
                              heading ('Logged out');
                              echo '<table border="0" cellpadding="3" cellspacing="0"><td>';
                              echo 'You\'ve been logged out <b>successfully</b>!<p>Click <a href="admin.php">here</a> to log in again.';
                              echo '</td></table>';
                              endtable ();
                              table ('end');
                            }
                            else
                            {
                              table ('begin');
                              heading ('Mailing List Statistics');
                              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 id FROM ' . $table;
                              if (!($result = mysql_query ($query)))
                              {
                                exit ('<b>ERROR:</b> ' . mysql_error ());
                                ;
                              }

                              $subscribed = mysql_num_rows ($result);
                              echo '<table width="100%" border="0" cellpadding="0" cellspacing="2"><td>';
                              echo '' . 'There are a total of <b>' . $subscribed . '</b> addresses subscribed to <b>' . $listname . '</b>.<p>';
                              echo 'The latest <b>5</b> subscribers are:<ul>';
                              $query = '' . 'SELECT id, address FROM ' . $table . ' ORDER BY id DESC LIMIT 5';
                              if (!($result = mysql_query ($query)))
                              {
                                exit ('<b>ERROR:</b> ' . mysql_error ());
                                ;
                              }

                              if (0 < mysql_num_rows ($result))
                              {
                                while ($row = mysql_fetch_object ($result))
                                {
                                  echo '' . '<li>' . $row->address . '</li>';
                                }
                              }
                              else
                              {
                                echo '* No addresses are subscribed yet.';
                              }

                              echo '</ul><a href="admin.php?action=subscribers">View all subscribers</a>';
                              echo '</td></table>';
                              endtable ();
                              table ('end');
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

  echo '</td>
</tr>
</table>
';
  if ($connection)
  {
    mysql_close ($connection);
  }

?>
