<?php
include "manager/conn.php";
include "database_tables.php";
include "db_functions.php";

//--------------------------------------------------------------------
        $mendatry_check_array=array('fname','email');				
        $unset_array=array('submit');
		$validate_check_array=array(												
										'uniqueValidEmail'=>array(
										  	    array('name'=>'email',
												'tablename'=>'subscribedusers',
												'tablefield'=>'email',
												'updateidmatch'=>'id',	
												'error1'=>'Please enter your valid Email address.',
												'error'=>'The email address you have entered is already in our Newsletter Subscription .'))	
												
							                );	
//------------------------------------------------------------------------											
$insert=0;
$fname="";
$email="";

  if(count($_POST)){
	
	$post_data=$_POST;	
	$proceed_flag=0;
	$edit_id=0;	
	$errormsg='';	
	extract($post_data);
	list($proceed_flag,$errormsg)=mendatry_check_field($mendatry_check_array,$validate_check_array,$post_data,$edit_id);
	    if($proceed_flag < 1)
		{			 
	    $email=$post_data['email'];	
		$name=$post_data['fname'];
		$sql = "SELECT * FROM admin";
	    $result = mysql_query($sql); 
	    $row = mysql_fetch_object($result);
	    $sendemailid = $row->sendemailid;
		$headers="";
        $mail_to =$email ;
        $mail_subject= "Welcome to Heron's walk:: Subscription Confirmation";
        $mail_body = "Thank you for susbscribing to our Newsletter.";
		$mail_body = $mail_body ."\nYou have susbscribed using following: \n";
        $mail_body = $mail_body ."\nName: ".$name."\n";
		$mail_body = $mail_body ."Email ID: ".$email."\n";
		$headers = $headers . "From: ".$sendemailid;
		
		mail($mail_to,$mail_subject,$mail_body,$headers,"");
		$qid ="INSERT INTO subscribedusers(email,name,groupid)VALUES('".$email."','".$name."','')";
		               $updateresult = mysql_query($qid);
		               echo mysql_error();		
	                   $insert=1;
		 
		}
		else {
	           $haderr="yes";
	           $errormsg = $errormsg;
			   extract($post_data);
	           }
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Heron's Walk : Contact Us</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<script type="text/javascript" src="js.js"></script>
</head>
<body>
<div id="main">
<div id="top">
<img src="images/index_08.png" width="850" height="17" alt=""/>
</div>
<div id="wrapper">
<table width="100%" border="0" cellpadding="0" cellspacing="0">

  <tr>
    <td width="250" id="left">
<?php include "left_menu.php";?>
       </td>
     <td width="530" id="right">
     <!--flash area -->  
   
	<?php include "header.php";?>
  <!--flash area --> 
  <div id="text">
  <p>&nbsp; </p>
  <h5>Join Our Newsletter</h5>
 <?php if($insert==0){?> 
<p class="errFont"><?php 
		                               if(isset($errormsg))
		  	                           {
									   echo $errormsg;
		   	                           }						 
			?> </p>
           
<p>
<form action="" method="post" name="contact" id="contact" class="form-1">

<div>
  <label><span class="errFont">*</span>Your Full Name</label>
   <input name="fname" type="text"  value="<?php echo $fname;?>" maxlength="40" /></div>

<div>
  <label><span class="errFont">*</span>Email Address</label>
   <input name="email" type="text" value="<?php echo $email;?>" maxlength="40" /></div>
<div><label>&nbsp;</label> <input name="submit" type="submit" value="Submit" /></div>
</form></p>
 <?php }?> 
 
  <?php if($insert==1){?> 
  <p align="center">Thank you for susbscribing to our Newsletter.</p>
    <?php }?> 
  </div>
     </td>
  </tr>
</table>
<?php include "footer.php";?>
<div id="bot">
<img src="images/index_09.png" width="850" height="18" alt=""/>
</div>
</div>
</body>
</html>