Location: PHPKode > projects > PHP Multiple Newsletters > admin/index.php
<?php
/***************************************************************************
File Name 	: index.php
Domain		: http://www.triangle-solutions.com/
----------------------------------------------------------------------------
Author		: Ian Warner
Copyright	: (C) 2001 Triangle Solutions Ltd
Email		: hide@address.com
URL		: http://www.triangle-solutions.com/
Description	: Displays the admin for the PHPMultiple Newsletters.
Date Created	: Tuesday 24 February 2004 15:32:07
File Version	: 2.7
\\||************************************************************************/


#############################################################################################
#########################     CURRENT CASEID'S ON THIS PAGE    ##############################
#############################################################################################

	// home - Literally shows the front page of the newsletter - and processes the join.
	// archive - Shows an archive of the past sent newsletters without the template.
	// unregister - Allows the user to unsubscribe from there registered newsletters.
	// verify - Makes the users verify there email address - set in config to TRUE or FALSE


#############################################################################################
#################     INCLUDE THE CONFIG, FUNCTIONS, AND HEADER FILE    #####################
#############################################################################################

	include ('../config.php');
	include ('../class/functions.php');
	include ('header.php');
?>
	<TABLE Width=<?= $maintablewidth ?> Cellspacing=0 Cellpadding=0 Border=0 Align=<?= $maintablealign ?>>
	<FORM Action=<?= $_SERVER['PHP_SELF'] ?>?caseid=list Method=POST>
	  <TR>
		<TD><A HREF=<?= $_SERVER['PHP_SELF'] ?>><IMG SRC=../images/mulitple_newsletter_logo.gif Width=83 Height=61 title='PHP Multiple Newsletters' alt='PHP Multiple Newsletters' Vspace=1 Border=0></TD>
		<TD Align=Right Valign=Bottom>
		<INPUT Name=keywords Size=40 onFocus=javascript:this.value='' Value='Search Email Addresses'>
		<INPUT Type=Submit Value=Go>
		</TD>
	  </TR>
	</FORM>
	</TABLE>

<?php
#############################################################################################
#################     AUTH LOGIN AND LOGOUT SYSTEM REQUIRES SESSIONS    #####################
#############################################################################################

	IF (isset($_GET['action']) && $_GET['action'] == 'Logout')
		{
		$_SESSION = array();
		unset($_COOKIE[session_name()]);
		session_destroy();
		}

	IF (isset($_POST['form']))
		{
		IF (($_POST['username'] == $admin_username) && ($_POST['password'] == $admin_password))
			{
			$_SESSION['username'] = $_POST['username'];
			$_SESSION['password'] = $_POST['password'];
			}
			ELSE
				{
				$_SESSION = array();
?>
				<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=1 Bordercolor=#000000 Align=<?= $maintablealign ?>>
				  <TR Bgcolor=<?= $background ?>>
					<TD><P>Access Denied</TD>
				  </TR>
				</TABLE>

				<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=1 Bordercolor=#000000 Align=<?= $maintablealign ?>>
				  <TR>
					<TD><BR><P>
					Your Username or Password is incorrect, or you are not a
					registered user on this site. Please Try logging in again.<P Align=Center>
					<INPUT Type=button Value=Back onClick=history.back()><BR><BR>
					</TD>
				  </TR>
				</TABLE>
<?php
				include('footer.php');
				Exit();
				}
		}

	// IF NOT LOGGED IN SHOW THE USERNAME AND PASSWORD ENTRY AREAS

	IF ((!isset($_SESSION['username']) OR $_SESSION['username'] != $admin_username) OR (!isset($_SESSION['password']) OR $_SESSION['password'] != $admin_password))
		{
?>
		<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=1 Bordercolor=#000000 Align=<?= $maintablealign ?>>
		  <TR Bgcolor=<?= $background ?>>
			<TD><P><A HREF=<?= $_SERVER['PHP_SELF'] ?> OnMouseOver="window.status='Login Required';return true;" OnMouseOut="window.status=' ';return true;">Login Required</A></TD>
		  </TR>
		</TABLE>

		<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=0 Class=boxborder Align=<?= $maintablealign ?>>
		<FORM Action=<?= $_SERVER['PHP_SELF'] ?> Method=POST>
		  <TR>
			<TD><BR><P Align=Center>
			Username: <INPUT Name=username Size=20>
			Password: <INPUT Type=password Name=password Size=20>
			<INPUT Type=Submit Name=form Value='Log in'><BR><BR>
			</TD>
		  </TR>
		</FORM>
		</TABLE>
<?php
		include('footer.php');
		Exit();
		}


#############################################################################################
##########     MAKE SURE THE RIGHT CASEID IS ENTERED OR DEFAULT TO HOME ID    ###############
#############################################################################################

	IF (!isset($_GET['caseid']) || $_GET['caseid'] == '' || $_GET['caseid'] != 'home' && $_GET['caseid'] != 'add' && $_GET['caseid'] != 'save' && $_GET['caseid'] != 'document'  && $_GET['caseid'] != 'send'  && $_GET['caseid'] != 'list' && $_GET['caseid'] != 'upload' && $_GET['caseid'] != 'archive' && $_GET['caseid'] != 'delete' && $_GET['caseid'] != 'trackit')
		$_GET['caseid'] = 'home';
?>
	<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=1 Bordercolor=#000000 Align=<?= $maintablealign ?>>
	<FORM Action=<?= $_SERVER['PHP_SELF'] ?>?caseid=list Method=POST>
	  <TR Bgcolor=<?= $backout ?>>
		<TD OnMouseOver="this.style.background='<?= $backover ?>';window.status='Newsletter Admin';return true;" OnMouseOut="this.style.background='<?= $backout ?>';window.status=' ';return true;" Align=Center><A HREF=<?= $_SERVER['PHP_SELF'] ?> Style=Width:100%;Color:#000000>Newsletter Admin</TD>
		<TD OnMouseOver="this.style.background='<?= $backover ?>';window.status='Add Newsletter';return true;" OnMouseOut="this.style.background='<?= $backout ?>';window.status=' ';return true;" Align=Center><A HREF=<?= $_SERVER['PHP_SELF'] ?>?caseid=add Style=Width:100%;Color:#000000>Add Newsletter</TD>
		<TD OnMouseOver="this.style.background='<?= $backover ?>';window.status='Archive';return true;" OnMouseOut="this.style.background='<?= $backout ?>';window.status=' ';return true;" Align=Center><A HREF=<?= $_SERVER['PHP_SELF'] ?>?caseid=archive Style=Width:100%;Color:#000000>Archive</TD>
		<TD OnMouseOver="this.style.background='<?= $backover ?>';window.status='Logout';return true;" OnMouseOut="this.style.background='<?= $backout ?>';window.status=' ';return true;" Align=Center><A HREF=<?= $_SERVER['PHP_SELF'] ?>?caseid=home&action=Logout Style=Width:100%;Color:#000000>Logout</TD>
	  </TR>
	</FORM>
	</TABLE>

	<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=1 Bordercolor=#000000 Align=<?= $maintablealign ?>>
	  <TR Bgcolor=<?= $background ?>>
		<TD Width=15%><P>&nbsp;<A HREF=<?= $_SERVER['PHP_SELF'] ?>?caseid=document&docid=Install>Install</TD>
		<TD Width=15%><P>&nbsp;<A HREF=<?= $_SERVER['PHP_SELF'] ?>?caseid=document&docid=ReadMe>ReadMe</TD>
		<TD Width=15%><P>&nbsp;<A HREF=<?= $_SERVER['PHP_SELF'] ?>?caseid=document&docid=ChangeLog>ChangeLog</TD>
		<TD Width=15%><P>&nbsp;<A HREF=<?= $_SERVER['PHP_SELF'] ?>?caseid=document&docid=Todo>Todo</TD>
		<TD Width=15%><P>&nbsp;<A HREF=<?= $_SERVER['PHP_SELF'] ?>?caseid=document&docid=Licence>Licence</TD>
		<TD Width=15%><P>&nbsp;<A HREF=<?= $_SERVER['PHP_SELF'] ?>?caseid=document&docid=Version>Version</TD>
		</TD>
	  </TR>
	</TABLE>

<?php
#############################################################################################
#######################     URL SWITCH FOR THE EMAIL MESSAGE    #############################
#############################################################################################

	SWITCH ($_GET['caseid'])
		{


#############################################################################################
####################     THE DEFAULT LISTING FOR THE ADMIN AREA    ##########################
#############################################################################################

		CASE 'home':

			$query = "	SELECT newsletter_id, newsletter_title, newsletter_description, Count(members_id) AS total
					FROM news_newsletter a
					LEFT JOIN news_member b
					ON a.newsletter_id = b.members_newsid
					GROUP BY a.newsletter_id
					ORDER BY a.newsletter_id ASC";

			$result = @mysql_query($query);

			IF (@mysql_num_rows($result) > 0)
				{
?>
				<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=1 Bordercolor=#000000 Align=<?= $maintablealign ?>>
				  <TR BgColor=#AACCEE>
					<TD><P><B>Name</TD>
					<TD><P><B>Description</TD>
					<TD><P><B>Members</TD>
					<TD><P><B>Send</TD>
					<TD><P><B>Delete</TD>
					<TD><P><B>Edit</TD>
					<TD><P><B>List</TD>
					<TD><P><B>Upload</TD>
				  </TR>
<?php
				WHILE ($row = @mysql_fetch_array($result))
					{
					extract($row);
?>
					<TR Align=Center>
						<TD><P><?= stripslashes($newsletter_title) ?></TD>
						<TD><P><?= stripslashes($newsletter_description) ?></TD>
						<TD><P><?= $total ?></TD>
						<TD><BUTTON onClick=location='<?= $_SERVER['PHP_SELF'] ?>?caseid=send&newsid=<?= $newsletter_id ?>'>Send</BUTTON></TD>
						<TD><A HREF=<?= $_SERVER['PHP_SELF'] ?>?caseid=delete&newsid=<?= $newsletter_id ?> onclick="return deletemember()">Delete</A>
						<TD><BUTTON onClick=location='<?= $_SERVER['PHP_SELF'] ?>?caseid=add&newsid=<?= $newsletter_id ?>'>Edit</BUTTON></TD>
						<TD><BUTTON onClick=location='<?= $_SERVER['PHP_SELF'] ?>?caseid=list&newsid=<?= $newsletter_id ?>'>List</BUTTON></TD>
						<TD><BUTTON onClick=location='<?= $_SERVER['PHP_SELF'] ?>?caseid=upload&newsid=<?= $newsletter_id ?>'>Upload</BUTTON></TD>
					</TR>
<?php
					}
?>
				</TABLE>
<?php
				}
				ELSE
					PageTitle('The first thing you need to do is Add A Newsletter - <A HREF='.$_SERVER['PHP_SELF'].'?caseid=add>ADD');

		BREAK;


#############################################################################################
##############################     SEND THE NEWSLETTER    ###################################
#############################################################################################

		CASE 'send':

	// IF THE ELEMENTS ARE FILLED OUT ON THE POST SCREEN THEN CONTINUE

			IF (isset($_POST['sendnews']))
				{
				IF ($_POST['newslettertextplain'] != '' && $_POST['newslettertexthtml'] != '' && $_POST['subject'] != '')
					{


	// ADD INFORMATION INTO MAIL ARCHIVE SYSTEM

					$query = "	INSERT INTO news_archive (archive_id, archive_newsid, archive_subject, archive_body, archive_timestamp, archive_status)
							VALUES ('', '".$_POST['newsid']."', '".$_POST['subject']."', '".$_POST['newslettertexthtml']."', '".mktime()."', '1')";

					$result = @mysql_query($query);

					$archive_id = mysql_insert_id();


	// QUERY TO GET THE MEMBERS SUBSCRIBED TO THE NEWSLETTER

					$query = "	SELECT members_id, members_name, members_email, members_mailpref, members_ip, FROM_UNIXTIME(members_timestamp, '%d-%m-%Y') AS date, newsletter_title, newsletter_description, newsletter_htmlemail, newsletter_plainemail
							FROM news_member a, news_newsletter b
							WHERE a.members_newsid = '".$_POST['newsid']."'
							AND b.newsletter_id = a.members_newsid
							AND members_status = '1'";

					$result = @mysql_query($query);

	// IF NO MEMBERS ARE REGISTERED OR MAYBE NOT STATUS 1

					IF (mysql_num_rows($result) > '0')
						{

	// SEND THE EMAIL VIA SOCKETS

						include ('../class/class.phpmailer.php');
						$mail = new phpmailer();
						$mail -> SMTPKeepAlive = 'true';
						$mail->IsSMTP();
						$mail->Host = $sockethost;

						IF ($smtpauth == 'TRUE')
							{
							$mail -> SMTPAuth = 'true';
							$mail -> Username = $smtpauthuser;
							$mail -> Password = $smtpauthpass;
							}

						$mail->From = $socketfrom;
						$mail->FromName = $socketfromname;
						$mail->AddReplyTo($socketfrom, $socketfromname);
						$mail -> Subject = $_POST['subject'];

						WHILE ($row = @mysql_fetch_array($result))
							{
							extract($row);

							$final_tip = $trackingurl.'caseid=trackit&archive_id='.$archive_id.'&members_email='.$members_email.'&newsid='.$_GET['newsid'];

							IF ($members_mailpref == 'html')
								{
								$body = (ereg_replace('MEMBERNAMEHERE', stripslashes($members_name), stripslashes($newsletter_htmlemail)));
								$body = (ereg_replace('NEWSLETTERBODY', nl2br(stripslashes($_POST['newslettertexthtml'])), stripslashes($body)));

								$mail -> IsHTML(true);
								}
								ELSE
									{
									$body = (ereg_replace('MEMBERNAMEHERE', stripslashes($members_name), stripslashes($newsletter_plainemail)));
									$body = (ereg_replace('NEWSLETTERBODY', stripslashes($_POST['newslettertextplain']), stripslashes($body)));

									$mail -> IsHTML(false);
									}

							$body = (ereg_replace('NEWSLETTERTITLEHERE', stripslashes($newsletter_title), stripslashes($body)));
							$body = (ereg_replace('NEWSLETTERDESCRIPTIONHERE', stripslashes($newsletter_description), stripslashes($body)));
							$body = (ereg_replace('MEMBEREMAILHERE', stripslashes($members_email), stripslashes($body)));
							$body = (ereg_replace('MEMBERIP', stripslashes($members_ip), stripslashes($body)));
							$body = (ereg_replace('MEMBERDATE', stripslashes($date), stripslashes($body)));
							$body = (ereg_replace('SITENAMEHERE', stripslashes($sitename), stripslashes($body)));
							$body = (ereg_replace('SITEURLHERE', stripslashes($siteurl), stripslashes($body)));
							$body = (ereg_replace('TRACKINGURL', nl2br(stripslashes($final_tip)), stripslashes($body)));

							$mail -> Body = $body;
							$mail -> AddAddress($members_email, $members_name);

							IF(!$mail->Send())
								$msg = 'ERROR: Mail not sent to '.$members_email.' at '.date('Y-m-d H:i:s').' <A HREF='.$_SERVER['PHP_SELF'].'?caseid=list&sub=delete&newsid='.$_POST['newsid'].'&memberid='.$members_id.' onclick="return deletemember()">Delete Member</A>';
								ELSE
									$msg = 'Mail sent to '.$members_email.' at '.date('Y-m-d H:i:s');
?>
							<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=0 Class=boxborder Align=<?= $maintablealign ?>>
							  <TR BgColor=#AACCEE>
								<TD><P><?= $msg ?></TD>
							  </TR>
							</TABLE>
<?php
							$mail -> ClearAddresses();

							$mail -> SmtpClose();
							}
						}
						ELSE
							PageTitle('No Members Or Members Status 0');
					}
					ELSE
						{
						PageTitle('Fill in all fields please');
						$pagetitle = TRUE;
						}
				}
				ELSE
					$pagetitle = TRUE;

	// SHOW THE FORM TO FILL IN THE DETAILS TO SEND THE MESSAGE

			IF (isset($pagetitle))
				{
				PageTitle('Send Newsletter - All Fields Are Required');
?>
				<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=0 Class=boxborder Align=<?= $maintablealign ?>>
				<FORM Action=<?= $_SERVER['PHP_SELF'] ?>?caseid=send&newsid=<?= $_GET['newsid'] ?> Method=POST>
				  <TR>
					<TD><P>Subject</TD>
					<TD><INPUT Name=subject size=68></TD>
				  </TR>
				  <TR>
					<TD Valign=Top><P>HTML Newsletter Body</TD>
					<TD><TEXTAREA Name=newslettertexthtml Cols=70 Rows=10></TEXTAREA></TD>
				  </TR>
				  <TR>
					<TD Valign=Top><P>PLAIN Newsletter Body</TD>
					<TD><TEXTAREA Name=newslettertextplain Cols=70 Rows=10></TEXTAREA></TD>
				  </TR>
				  <TR>
					<TD Colspan=2 Align=Center>
					<INPUT Type=Hidden Name=newsid
<?php
				IF (isset($_GET['newsid']))
					echo 'Value="'.$_GET['newsid'].'"';
?>
					>
					<INPUT Type=submit Name=sendnews Value="Send Newsletter">
					</TD>
				  </TR>
				</FORM>
				</TABLE>
<?php
				}
		BREAK;


#############################################################################################
#############################     DELETE THE NEWSLETTER    ##################################
#############################################################################################

		CASE 'delete':

			$query = "	DELETE
					FROM news_newsletter
					WHERE newsletter_id = '".$_GET['newsid']."'";

			$result = @mysql_query($query);
?>
			<META http-equiv=Refresh content='0;URL=<?= $_SERVER['PHP_SELF'] ?>'>
<?php
		BREAK;


#############################################################################################
###############################     ADD A NEWSLETTER    #####################################
#############################################################################################

		CASE 'add':

			IF (isset($_GET['sub']))
				{
				IF ($_GET['sub'] == 'Add')
					{
					$query = "	INSERT INTO news_newsletter (newsletter_id, newsletter_title, newsletter_description, newsletter_htmlemail, newsletter_plainemail, newsletter_redirect_url, newsletter_welcome, newsletter_unsubscribe, newsletter_status)
							VALUES ('', '".$_POST['title']."', '".$_POST['desc']."', '".$_POST['htmlemail']."', '".$_POST['plainemail']."', '".$_POST['redirect_url']."', '".$_POST['welcomeemail']."', '".$_POST['unsubscribeemail']."', '1')";

					PageTitle('Your Newsletter has been added');

					$result = @mysql_query($query);

					$_GET['newsid'] = mysql_insert_id();
					}

				ELSEIF ($_GET['sub'] == 'Edit')
					{
					$query = "	UPDATE news_newsletter
							SET
							newsletter_title = '".addslashes($_POST['title'])."',
							newsletter_description = '".addslashes($_POST['desc'])."',
							newsletter_htmlemail = '".addslashes($_POST['htmlemail'])."',
							newsletter_plainemail = '".addslashes($_POST['plainemail'])."',
							newsletter_redirect_url = '".addslashes($_POST['redirect_url'])."',
							newsletter_welcome = '".addslashes($_POST['welcomeemail'])."',
							newsletter_unsubscribe = '".addslashes($_POST['unsubscribeemail'])."'
							WHERE newsletter_id = '".addslashes($_POST['newsid'])."'";

					PageTitle('Your Newsletter has been edited.');

					$result = @mysql_query($query);
					}
				}

			IF (isset($_GET['newsid']) == '')
				{
				PageTitle('Add Newsletter - All fields are Required');
				$addon = '&sub=Add';
				}
				ELSE
					{
					PageTitle('Edit Newsletter');

					$query = "	SELECT newsletter_title, newsletter_description, newsletter_htmlemail, newsletter_plainemail, newsletter_redirect_url, newsletter_welcome, newsletter_unsubscribe
							FROM news_newsletter
							WHERE newsletter_id = '".$_GET['newsid']."'";

					$result = @mysql_query($query);
					$row = @mysql_fetch_array($result);

					extract($row);

					$addon = '&sub=Edit&newsid='.$_GET['newsid'];
					}
?>
			<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=1 Bordercolor=#000000 Align=<?= $maintablealign ?>>
			<FORM Action=<?= $_SERVER['PHP_SELF'] ?>?caseid=add<?= $addon ?> Method=POST>
			  <TR>
				<TD Bgcolor=#AABBDD><P><B>Title:</TD>
				<TD><INPUT Name=title Size=50
<?php
			IF (isset($newsletter_title))
				echo 'Value="'.stripslashes($newsletter_title).'"';
?>
				></TD>
			  </TR>
			  <TR>
				<TD Bgcolor=#AABBDD><P><B>Description:</TD>
				<TD><INPUT Name=desc Size=50
<?php
			IF (isset($newsletter_description))
				echo 'Value="'.stripslashes($newsletter_description).'"';
?>
				></TD>
			  </TR>
			  <TR>
				<TD Bgcolor=#AABBDD><P><B>Redirect URL:</TD>
				<TD><INPUT Name=redirect_url Size=50
<?php
			IF (isset($newsletter_redirect_url))
				echo 'Value="'.stripslashes($newsletter_redirect_url).'"';
?>
				></TD>
			  </TR>
			  <TR>
				<TD Bgcolor=#AABBDD Valign=Top><P><B>HTML Email Template:
<?php
			IF (isset($_GET['newsid']) != '')
				echo '<BR><A HREF=javascript:popwindow(\'email.php?newsid='.$_GET['newsid'].'&emailid=html\',\'top=15,left=15,width=500,height=500\')>View HTML Email</A>';
?>
				</TD>
				<TD><TEXTAREA Cols=115 Rows=10 Name=htmlemail>
<?php
			IF (isset($newsletter_htmlemail))
					echo stripslashes($newsletter_htmlemail).'</TEXTAREA>';
				ELSE
					echo '</TEXTAREA>';
?>
				</TD>
			  </TR>
			  <TR>
				<TD Bgcolor=#AABBDD Valign=Top><P><B>Plain Email Template:
<?php
			IF (isset($_GET['newsid']) != '')
				echo '<BR><A HREF=javascript:popwindow(\'email.php?newsid='.$_GET['newsid'].'&emailid=plain\',\'top=15,left=15,width=500,height=500\')>View Plain Email</A>';
?>
				</TD>
				<TD><TEXTAREA Cols=115 Rows=10 Name=plainemail>
<?php
			IF (isset($newsletter_plainemail))
				echo stripslashes($newsletter_plainemail).'</TEXTAREA>';
				ELSE
					echo '</TEXTAREA>';
?>
				</TD>
			  </TR>
			  <TR>
				<TD Bgcolor=#AABBDD Valign=Top><P><B>Welcome Email:</TD>
				<TD><TEXTAREA Cols=115 Rows=10 Name=welcomeemail>
<?php
			IF (isset($newsletter_welcome))
				echo stripslashes($newsletter_welcome).'</TEXTAREA>';
				ELSE
					echo '</TEXTAREA>';
?>
				</TD>
			  </TR>
			  <TR>
				<TD Bgcolor=#AABBDD Valign=Top><P><B>Unsubscribe Email:</TD>
				<TD><TEXTAREA Cols=115 Rows=10 Name=unsubscribeemail>
<?php
			IF (isset($newsletter_unsubscribe))
				echo stripslashes($newsletter_unsubscribe).'</TEXTAREA>';
				ELSE
					echo '</TEXTAREA>';
?>

				</TD>
			  </TR>
			  <TR>
				<TD Align=Center Colspan=2>
				<INPUT Type=Hidden Name=newsid
<?php
			IF (isset($_GET['newsid']))
				echo 'Value="'.$_GET['newsid'].'"';
?>
				>
			       	<INPUT Type=submit Name=Submit Value="Save Newsletter">
				</TD>
			  </TR>
			</FORM>
			</TABLE>
<?php
		BREAK;


#############################################################################################
######################     LIST THE MEMBERS OF EACH NEWSLETTER    ###########################
#############################################################################################

		CASE 'list':

			IF (isset($_GET['sub']) && isset($_GET['memberid']))
				{
				$query = "	DELETE
						FROM news_member
						WHERE members_id = '".$_GET['memberid']."'";

				$result = @mysql_query($query);

				PageTitle('Newsletter Member '.$_GET['memberid'].' Deleted');
				}

			$query = "	SELECT members_id, members_name, members_email, members_mailpref
					FROM news_member";

			IF (!isset($_POST['keywords']))
				$query .= "	WHERE members_newsid = '".$_GET['newsid']."'";
				ELSE
					$query .= "	WHERE members_email LIKE '%".$_POST['keywords']."%'";

			$query .= "	ORDER BY members_id ASC";

			$result = mysql_query($query);
?>
			<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=1 Bordercolor=#000000 Align=<?= $maintablealign ?>>
			  <TR BgColor=#AACCEE>
				<TD><P><B>ID</TD>
				<TD><P><B>Name</TD>
				<TD><P><B>Email</TD>
				<TD><P><B>Mail Pref</TD>
				<TD><P><B>Delete</TD>
			  </TR>
<?php
			WHILE ($row = mysql_fetch_array($result))
				{
				extract($row);
?>
				<TR>
					<TD><P><?= $members_id ?></TD>
					<TD><P><?= stripslashes($members_name) ?></TD>
					<TD><P><A HREF=mailto:<?= $members_email ?>><?= $members_email ?></TD>
					<TD><P><?= $members_mailpref ?></TD>
					<TD><P><A HREF=<?= $_SERVER['PHP_SELF'] ?>?caseid=list&sub=delete&memberid=<?= $members_id ?>
<?php
				IF (!isset($_POST['keywords']))
					echo '&newsid='.$_GET['newsid'];
?>
					onclick="return deletemember()">Delete</A></TD>
				</TR>
<?php
				}
?>
			</TABLE>
<?php
		BREAK;

#############################################################################################
###############     FUNCTION TO UPLOAD EMAILS ADDRESSES TO NEWSLETTER    ####################
#############################################################################################

		CASE 'upload':

			IF (isset($_GET['form']) == 'new')
				{
				IF ($_POST['emails'] != '')
					{
					$emailarray = explode("\r\n", $_POST['emails']);

					$numrows = count($emailarray);

					FOR ($i = 0; $i < $numrows; $i++)
						{
						$emailarray1 = explode(',', $emailarray[$i]);

						IF (!isset($emailarray1[0]))
							PageTitle('Missing Name - '.$i);
						ELSEIF (!ereg('^.+@.+\\..+$', $emailarray1[1]))
							PageTitle('Missing Email - '.$i);
							ELSE
								{
								$query = "	INSERT INTO news_member (members_id, members_name, members_email, members_newsid, members_mailpref, members_ip, members_timestamp, members_status)
										VALUES ('', '".trim($emailarray1[0])."', '".trim($emailarray1[1])."', '".$_GET['newsid']."', '".$_POST['mailpref']."', 'Upload', '".mktime()."', '1')";

								$result = @mysql_query($query);

								PageTitle('Emails Uploaded - '.$i);
								}
						}
					}
					ELSE
						PageTitle('Form is blank');
				}

			PageTitle('Upload Email Addresses - Newsletter '.$_GET['newsid']);
?>
			<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=1 Bordercolor=#000000 Align=<?= $maintablealign ?>>
			  <TR>
				<TD><BLOCKQUOTE><OL><LI>
				Upload name and email addresses by placing them in the textarea below,
				make sure each name/email address is on a seperate line within the textarea. The
				name and email must be seperated by a comma e.g. Fred Bloggs, hide@address.com
				Please select the default mail preference for all the imported email addresses.
				If there is no name then please put in anything you want i.e. Subscriber, Member etc.
				<BR><BR></TD>
			  </TR>
			</TABLE>

			<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=0 Class=boxborder Align=<?= $maintablealign ?>>
			<FORM Action=<?= $_SERVER['PHP_SELF'] ?>?caseid=upload&newsid=<?= $_GET['newsid'] ?>&form=new Method=POST>
			  <TR>
				<TD><BR><BLOCKQUOTE><P>HTML: <INPUT CHECKED Type=Radio Name=mailpref Value=html>
				&nbsp;&nbsp;&nbsp; Plain: <INPUT Type=Radio Name=mailpref Value=plain></TD>
			  </TR>
			  <TR>
				<TD><BLOCKQUOTE><P><TEXTAREA Cols=50 Rows=20 Name=emails></TEXTAREA></TD>
			  </TR>
			  <TR>
				<TD><BLOCKQUOTE><P><INPUT Type=submit Value=submit><BR><BR></TD>
			  </TR>
			</FORM>
			</TABLE>
<?php
		BREAK;


#############################################################################################
###############################     READ THE DOCUMENTS    ###################################
#############################################################################################

		CASE 'document':
?>
			<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=1 Bordercolor=#000000 Align=<?= $maintablealign ?>>
			  <TR>
				<TD><IFRAME SRC=../documents/<?= $_GET['docid'] ?>.txt FrameBorder=0 FrameSpacing=0 WIDTH=100% HEIGHT=450 NAME=inframe></IFRAME></TD>
			  </TR>
			</TABLE>
<?php
		BREAK;


#############################################################################################
#####################     CHECK THE ARCHIVED NEWSLETTER MESSAGES    #########################
#############################################################################################

		CASE 'archive':

			IF (isset($_GET['archiveid']))
				{
				$query = "	DELETE
						FROM news_archive
						WHERE archive_id = '".$_GET['archiveid']."'";

				$result = @mysql_query($query);

				PageTitle('Archive '.$_GET['archiveid'].' Deleted');

				$query = "	DELETE
						FROM news_tracking
						WHERE tracking_send = '".$_GET['archiveid']."'";

				$result = @mysql_query($query);

				PageTitle('Tracking Hits Deleted');
				}

			PageTitle('Archive');

			$query = "	SELECT archive_id, archive_subject, archive_body, FROM_UNIXTIME(archive_timestamp, '%d/%m/%Y') AS timestamp
					FROM news_archive";

			IF (isset($_GET['newsid']))
				$query .= "	WHERE archive_id = '".$_GET['newsid']."'
						LIMIT 0,1";
				ELSE
					$query .= "	ORDER BY archive_timestamp DESC";

			$result = @mysql_query($query);
?>
			<TABLE Width=<?= $maintablewidth ?> Cellspacing=1 Cellpadding=1 Border=1 Bordercolor=#000000 Align=<?= $maintablealign ?>>
<?php

			IF (@mysql_num_rows($result) > 0)
				{
				IF (isset($_GET['newsid']))
					{
					$row = @mysql_fetch_array($result);
					extract($row);
?>
					<TR>
						<TD Width=100><P><B>VOLUME:</TD>
						<TD><P><?= $archive_id ?></TD>
					  </TR>
					  <TR>
						<TD><P><B>DATE:</TD>
						<TD><P><?= $timestamp ?></TD>
					  </TR>
					  <TR>
						<TD><P><B>SUBJECT:</TD>
						<TD><P><?= stripslashes($archive_subject) ?></TD>
					  </TR>
					  <TR>
						<TD Valign=Top><P><B>BODY:</TD>
						<TD><P><?= stripslashes(nl2br($archive_body)) ?></TD>
					  </TR>
<?php
	######## TRACKING INFORMATION HERE ##########

					$query = "	SELECT tracking_email
							FROM news_tracking
							WHERE tracking_send = '".$_GET['newsid']."'";

					$result = @mysql_query($query);
					$total_clicks = @mysql_num_rows($result);
?>
					<TR>
						<TD Valign=Top><P><B>Total Clicks:</TD>
						<TD><P><?= $total_clicks ?><BR>
<?php
					WHILE ($row = @mysql_fetch_array($result))
						{
						extract($row);
?>
						<A HREF=index.php?caseid=list&keywords=<?= $tracking_email ?>><?= $tracking_email ?></A><BR>
<?php
						}
?>
						</TD>
					</TR>
					<TR>
						<TD Colspan=2 Align=Center><BR><P><INPUT Type=Button Value=Back onClick=history.back()><BR><BR></TD>
					</TR>
<?php
					}
					ELSE
						{
?>
						<TR Bgcolor=#AACCEE>
							<TD><P><B>VOLUME</TD>
							<TD><P><B>DATE</TD>
							<TD><P><B>SUBJECT</TD>
							<TD><P><B>SELECT</TD>
							<TD><P><B>DELETE</TD>
						</TR>
<?php
						WHILE ($row = @mysql_fetch_array($result))
							{
							extract($row);
?>
							<TR BGcolor=<?= UseColor() ?> Valign=Top>
								<TD><P><?= $archive_id ?></TD>
								<TD><P><?= $timestamp ?></TD>
								<TD><P><?= stripslashes($archive_subject) ?></TD>
								<TD><P><BUTTON onClick=location='<?= $_SERVER['PHP_SELF'] ?>?caseid=archive&newsid=<?= $archive_id ?>'>Select</BUTTON></TD>
								<TD><A HREF=<?= $_SERVER['PHP_SELF'] ?>?caseid=archive&archiveid=<?= $archive_id ?> onclick="return deletemember()">Delete</A>
								</TD>
							</TR>
<?php
							}
						}
				}
				ELSE
					{
?>
					<TR>
						<TD><P>Currently there has been no newsletters sent.</TD>
					</TR>
<?php
					}
?>
			</TABLE>
<?php
		BREAK;
	}


#############################################################################################
###########################     ADD THE FOOTER INFORMATION    ###############################
#############################################################################################

	include('footer.php');
?>
Return current item: PHP Multiple Newsletters