<?php
	if (empty($flag))
	{	
?>
<?php include("navs.html"); ?>
<TITLE>Dr. Lisa Cassileth - Beverly Hills Plastic Surgery - Send Newsletter</TITLE>

<DIV STYLE="position: absolute; top: 138px; left: 280px; z-index:4;">
<TABLE STYLE="font-family: sans-serif; font-size: 10pt;" CELLPADDING=0 CELLSPACING=0 WIDTH=500 BORDER=0>	
	<TR>
		<TD STYLE="font-family: sans-serif; font-size: 14pt;" COLSPAN=2>Newsletter Mailing
		</TD>
	</TR>
	<TR>
		<TD COLSPAN=2>
			<P>
			</P>
		</TD>
	</TR>
	<TR>
		<TD COLSPAN=2>
			<BR>
			<FORM METHOD=POST ACTION="sendnewsletter.php">
				<TABLE STYLE="font-family: sans-serif; font-size: 8pt;" CELLPADDING=0 CELLSPACING=0  BORDER=0 ALIGN=CENTER>		<TR>
						<TD>Password: </TD><TD><INPUT TYPE="password" NAME="pd" STYLE="font-family: sans-serif; font-size: 8pt;"></TD>
					</TR>
					<TR>
						<TD>Path & filename of Newsletter file: </TD><TD><INPUT TYPE="text" NAME="fname" SIZE=40 VALUE="newsletters/newsletter" STYLE="font-family: sans-serif; font-size: 8pt;"></TD>
					</TR>
					<TR>
						<TD>Email address to send to (blank for use mailing list): </TD><TD><INPUT TYPE="text" NAME="email" SIZE=40 STYLE="font-family: sans-serif; font-size: 8pt;"></TD>
					</TR>
					<TR>
						<TD>Subject line: </TD><TD><INPUT TYPE="text" NAME="subject" SIZE=60 STYLE="font-family: sans-serif; font-size: 8pt;" VALUE="Newsletter from Dr. Lisa Cassileth - Fall 2003 - Creams and Lotions"></TD>
					</TR>
					<TR>
						<TD colspan=2>
							<BR>
							<INPUT TYPE="HIDDEN" NAME="flag" VALUE="step1">
							<INPUT TYPE="submit" name="submit" value="Send It">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<INPUT TYPE="reset" VALUE="Reset">
						</TD>
					</TR>
				</TABLE>
			</FORM>
		</TD>
	</TR>
</TABLE>
<BR>
<BR>
</DIV>

<?php
	}
	else
	{
		include "MIME.class";
		include("db_functions.php");

		if ($flag=="step1")  //verify content of newsletter
		{
			if ((empty($pd)) or ($pd <> "drcnews"))
			{
				echo "Bad password.<br><br><a href='http://www.drcassileth.com/sendnewsletter.php'>Try again</a>.";
				exit;
			}
			if (empty($subject))
			{
				echo "Need a subject line.<br><br><a href='http://www.drcassileth.com/sendnewsletter.php'>Try again</a>.";
				exit;
			}
		 	$handle = fopen ($fname, "r"); //filename from form
			$email_contents = fread ($handle, filesize ($fname));
			fclose ($handle);
			
			if (empty($email))
			{
				echo "Newsletter will be bcc'd to everyone on the mailing list.<BR><BR>\n";
			}
			else
			{
				echo "Newsletter will be sent to: $email<BR><BR>\n";
			}
?>
			<FORM METHOD=POST ACTION="sendnewsletter.php">
				Are the contents of the newsletter correct?<BR>
				<INPUT TYPE="HIDDEN" NAME="flag" VALUE="step2">
				<INPUT TYPE="HIDDEN" NAME="fname" VALUE="<?php echo $fname; ?>">
				<INPUT TYPE="HIDDEN" NAME="email" VALUE="<?php echo $email; ?>">
				<INPUT TYPE="HIDDEN" NAME="subject" VALUE="<?php echo $subject; ?>">
				<INPUT TYPE="submit" NAME="submit" VALUE="YES"><BR>
			</FORM>
			<A HREF="http://www.drcassileth.com/sendnewsletter.php">No, try again.</A><BR><BR>
			
<?php
			echo $email_contents;

		}
		
		if ($flag=="step2")
		{
		 	$handle = fopen ($fname, "r"); //filename from form
			$email_contents = fread ($handle, filesize ($fname));
			fclose ($handle);
		
			if (empty($email)) //no email specified in form, use addresses from database
			{
				$email = "newsletterlist@drcassileth.com";
				$emailarray = SelectQuery ("signups", "email", "active=1");
		
				if (!is_array($emailarray))
				{
					echo "Error: $emailarray<br>\n";
					exit;
				}
				
				$bcclist = "";
				
				while (list(,$v) = each ($emailarray))
				{
					$bcclist = $bcclist.$v[0].", ";
				}
				
				$bcclist = rtrim ($bcclist, ", ");
			}
		
			$mime = new MIME_mail("newsletter@drcassileth.com", $email, $subject, "", "bcc: $bcclist\n");
			$mime->attach($email_contents, "", HTML, BASE64);
			$mime->send_mail();
			
			echo "Message sent.<br>";
			echo "File: ".$fname."<br>";
			echo "Subject: ".$subject."<br>";
			echo "to: ".$email."<br>";
			echo "bcc: ".$bcclist."<br><br><br>";		
			echo $email_contents;
		}
	}
?>
