<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>IEEE Student Chater | Contact UAA IEEE Members</title>
<link rel="stylesheet" href="includes/style.css" type="text/css" /></head>
<body> 
</body>
</html>
<?php
/*
This file allows user to send e-mail to three administrators. User can choose who to send or send three of them, or any combination of two receipients. 
*/
include("header.htm");
echo "<div class=\"left\">";
include("includes/left.htm");
echo "</div>";
echo "<div class=\"body\">";
/*
This file will send e-mail to the officer selected
*/
if(isset($_POST['sendemail']))
{
	$name = $_POST['name'];
	$email = $_POST['emailadd'];
	$address = $_POST['address'];
	$message = $_POST['body'];
	$emailToOfficers = $_POST['emailToOfficers']; 
	$emailToAdvisor = $_POST['emailToAdvisor'];
	$emailToDesigner = $_POST['emailToDesigner'];
	/*
		Validating user's inputs. 
	*/
	function validate()
	{
		$errors = array();
		if($_POST['name'] == "")
		{
			$errors[] = "Blank name not allowed";
		}
		if($_POST['emailadd'] == "")
		{
			$errors[] = "Blank email not allowed";
		}
		if($_POST['address'] == "")
		{
			$errors[] = "Blank address not allowed";
		}
		if($_POST['body'] == "")
		{
			$errors[] = "Blank body not allowed";
		}
		if(empty($errors))
		{
			/*
			 If no errors are found call the function sendEmail()
			 */
			$email = $_POST['emailadd'];
			sendEmail(); 
			echo "<br> New post submitted successfully";
		} else 
		{
			foreach ($errors as $error) 
				{
					echo "<br>- ". $error;
				}
		}
	}
	/*
	This subroutine allows user to check who to send e-mail to. 
	*/
	function sendEmail()
	{
		//Array from check box
		$emailToOfficers = $_POST['emailToOfficers']; 
		$emailToAdvisor = $_POST['emailToAdvisor'];
		$emailToDesigner = $_POST['emailToDesigner'];
		
		/* 
		Contents of an e-amil 
		*/
		$name = $_POST['name'];
		$email = $_POST['emailadd'];
		$address = $_POST['address'];
		$body = $_POST['body'];
		$message = "Sender's summary: -------->  Name: $name --------->  Email Address: $email ---------->   Address: $address ----------->  Message: $body ";
		$OffEmail = 'james.marshall@ieee.org';
		$AdEmail = 'afjm@uaa.alaska.edu';
		$DeEmail = 'sunilpanthi@aim.com';
		$subject = 'Email from UAA IEEE web user';
			if(isset($emailToOfficers) && isset($emailToAdvisor) && isset($emailToDesigner))
			{
				$sendmailOfficers = mail($OffEmail, $subject, $message, 'This email is for the officers', $address);
				if($sendmailOfficers == FALSE)
				{
					echo " Your email can not be delivered to the Officers<br> We apologize for the inconvenience";
				}
				$sendmailAdvisor = mail($AdEmail, $subject, $message, 'This email is for the advisor', $address);
				if($sendmailAdvisor == FALSE)
				{
					echo " Your email can not be delivered to the Advisor<br> We apologize for the inconvenience";
				}
				$sendmailDesigner = mail($DeEmail, $subject, $message, 'This email is for the designer', $address);
				if($sendmailDesigner == FALSE)
				{
					echo " Your email can not be delivered to the designer<br> We apologize for the inconvenience";
				}
			} 
			else if(isset($emailToOfficers) && isset($emailToAdvisor))
			{
				$sendmailOfficers = mail($OffEmail, $subject, $message, 'This email is for the officers', $address);
				if($sendmailOfficers == FALSE)
				{
					echo " Your email can not be delivered to the Officers<br> We apologize for the inconvenience";
				}
				$sendmailAdvisor = mail($AdEmail, $subject, $message, 'This email is for the advisor', $address);
				if($sendmailAdvisor == FALSE)
				{
					echo " Your email can not be delivered to the Advisor<br> We apologize for the inconvenience";
				}
			} 
			else if(isset($emailToOfficers) && isset($emailToDesigner))
			{
				$sendmailOfficers = mail($OffEmail, $subject, $message, 'This email is for the officers', $address);
				if($sendmailOfficers == FALSE)
				{
					echo " Your email can not be delivered to the Officers<br> We apologize for the inconvenience";
				}
				$sendmailDesigner = mail($DeEmail, $subject, $message, 'This email is for the designer', $address);
				if($sendmailDesigner == FALSE)
				{
					echo " Your email can not be delivered to the designer<br> We apologize for the inconvenience";
				}
			}
			else if(isset($emailToAdvisor) && isset($emailToDesigner))
			{
				$sendmailAdvisor = mail($AdEmail, $subject, $message, 'This email is for the advisor', $address);
				if($sendmailAdvisor == FALSE)
				{
					echo " Your email can not be delivered to the Advisor<br> We apologize for the inconvenience";
				}
				$sendmailDesigner = mail($DeEmail, $subject, $message, 'This email is for the designer', $address);
				if($sendmailDesigner == FALSE)
				{
					echo " Your email can not be delivered to the designer<br> We apologize for the inconvenience";
				}
			} else
			{
				$sendmailDesigner = mail($DeEmail, $subject, $message, 'This email is for the designer', $address);
				if($sendmailDesigner == FALSE)
				{
					echo " Your email can not be delivered to the designer<br> We apologize for the inconvenience";
				}
			}
		
	}
	validate(); 
} 
else
{
	echo "<h4>Send us e-mail using this form. </h4> ";
	echo "<form name=form1 method=post action=$PHP_SELF>";
  echo "
  <p>&nbsp;Your Name: 
    <input type=text name=name>
*</p>";
echo "<p>Your E-mail: 
<input type=text name=emailadd>*
	</p>";
  echo "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Address: 
    <input type=text name=address> 
  *</p>";
  echo "<p>Message:</p>
  <p>
    <textarea name=body cols=35 rows=10></textarea> 
  </p>";
  echo" <p><b>Send email to:</b><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Chair 
    <input type=checkbox name=emailToOfficers value=checkbox><br>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Advisor 
<input type=checkbox name=emailToAdvisor value=checkbox><br>"; 
echo "Web Designer 
<input type=checkbox name=emailToDesigner value=checkbox>
</p>";
  echo "<p>
    <input type=submit name=sendemail value=Send>";
    echo "<input type=reset name=Reset value=Reset>
  </p>";
echo "</form>";
}
echo "</div>";
include("bottom.htm");
?>
