<?php
//CAPTCHA Matching code
include("../connection.php");


$ToEmail = 'abhayfivedesign@gmail.com';  // To Send Mail Id 
                  
//subscribe Form
if(isset($_POST['subscribe_form']))
{       
        //Check
        $email= $_POST["email"]; 
        $sql_check = "SELECT * FROM `tbl_news_letter` WHERE `news_letter_email`='$email' && `status` ='1'";
        $runNew = mysqli_query($link,$sql_check);
        if(mysqli_num_rows($runNew)==0)
        {

                  $Subject = "Newsletter.....!!!";
                  $mailheader = 'From : '.$_POST['email'].'\r\n'; 
                  $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
                  $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
                  @$MESSAGE_BODY .= "Newsletter Id: ".$_POST["email"]."<br>";
                  @$MESSAGE_BODY .= "Email : ".$_POST["email"]."<br>";
                  
                  if(@mail($ToEmail, $Subject, $MESSAGE_BODY, $mailheader))
                  {
                    
                    $insert = "INSERT INTO `tbl_news_letter`(`news_letter_email`, `status`) VALUES ('$email','1')";
                    if(mysqli_query($link,$insert))
                     {
                      echo "Successfully Newsletter Send!!!";
                     }
                  }
                  else
                  {
                    
                    $insert = "INSERT INTO `tbl_news_letter`(`news_letter_email`, `status`) VALUES ('$email','0')";
                    if(mysqli_query($link,$insert))
                     {
                      echo "Mail Not Send!!!";
                     }
                    
                  } 
            } 
        else
        {
          echo "You are Already Subscribed to Our Newsletter";  
        }
        
  
}

//Book My Seat Form
if(isset($_POST['book_My_Seat_form']))
{

        $Subject = "Admissions Enquiry ......!!!";     
        $mailheader = 'From : '.$_POST['email'].'\r\n'; 
        $mailheader .= "Reply-To: ".$_POST["email"]."\r\n";  
        $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
        
        @$MESSAGE_BODY .= "Name : ".$_POST["name"]."<br>";
        @$MESSAGE_BODY .= "DOB : ".$_POST["dob"]."<br>";
        @$MESSAGE_BODY .= "phone : ".$_POST["phone"]."<br>";
        @$MESSAGE_BODY .= "Ten Percentage : ".$_POST["ten_percentage"]."<br>";
        @$MESSAGE_BODY .= "Twelve Percentage : ".$_POST["twelve_percentage"]."<br>";
        @$MESSAGE_BODY .= "Graduation Percentage : ".$_POST["graduation_percentage"]."<br>";
        @$MESSAGE_BODY .= "Email : ".$_POST["email"]."<br>";
       
        
        if(@mail($ToEmail, $Subject, $MESSAGE_BODY, $mailheader))
        {
          echo "Successfully Mail Send!!!";
        }
        else
        {
          echo "Mail Not Send!!!";
        }
  
}

//Contact Form
if(isset($_POST['contact_form']))
{
        $Subject = $_POST['enq_con'];       
        $mailheader = 'From : '.$_POST['email'].'\r\n'; 
        $mailheader .= "Reply-To: ".$_POST["email"]."\r\n";  
        $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
        @$MESSAGE_BODY .= "Name : ".$_POST["name"]."<br>";
        @$MESSAGE_BODY .= "Company : ".$_POST["company"]."<br>";
         @$MESSAGE_BODY .= "Email : ".$_POST["email"]."<br>";
        @$MESSAGE_BODY .= "Phone : ".$_POST["phone"]."<br>";
        @$MESSAGE_BODY .= "Msg Subject: ".$_POST["msg_subject"]."<br>";       
        @$MESSAGE_BODY .= "Message : ".$_POST["message"]."<br>";
        
        if(@mail($ToEmail, $Subject, $MESSAGE_BODY, $mailheader))
        {
          echo "Successfully Mail Send!!!";
        }
        else
        {
          echo "Mail Not Send!!!";
        }
  
}



//***********************Admin Panel Captcha*****************

if(isset($_POST['cap_admin_click']))
{
  $patterUser = "/^[a-zA-Z0-9.\-_@]{5,30}$/";
  $patterPass = "/^[a-zA-Z$#@_.0-9&]{3,15}$/";
  if(empty($_POST['uname']))
  {
    echo "<h4 style='color:red;text-transform:inherit;'>Enter a value in the username field...</h4>";
    exit();
  }
  if(!preg_match($patterUser, $_POST['uname']))
  {
      echo "<p>
     <h4 style='color:#000;font-weight: bold;''>User Name:</h4>
     Enter only $,_,-,@,a-z,0-9 only At least  between 5 character to 30 Character!!!
      </p><h4 style='color:red;'>Invalid Your Username </h4>";
      exit();
  }
  if(empty($_POST['pass']))
  {
    echo "<h4 style='color:red;text-transform:inherit;'>Enter a value in the Password field...</h4>";
    exit();
  }
  if(!preg_match($patterPass, $_POST['pass']))
  {
      echo "
       <h4 style='color:red;font-weight: bold;''>Password:</h4><p>Valid up to character ,numeric value and special Character like @,#,$,& password... </p>
      <p>";
      exit();
  }
  
  else
  {
      $admin_email_id=$_POST['uname'];
      $admin_pass= sha1(md5($_POST['pass']));
      $sqllog="SELECT * FROM tbl_admin where admin_login='$admin_email_id' and admin_pass='$admin_pass'";
      $datalog=mysqli_query($link,$sqllog);
      $reslt=mysqli_fetch_array($datalog);
      if($admin_pass==$reslt['admin_pass'])
      {
        $_SESSION['user_id']=$reslt['admin_login'];
        $_SESSION['user_name']=$reslt['admin_name'];
        echo "ldsdlgfsdo";
      }
      else
      {
        $admin_data = mysqli_query($link,"SELECT * FROM tbl_admin WHERE id=1");
        $admin_arr = mysqli_fetch_assoc($admin_data);
        if(!($admin_pass==$admin_arr['admin_pass']))
        {
         echo  "<h4 style='color:red;text-transform: inherit;'>Invalid Your Password Input Correct Password...<h4>";
        }
        if(!($admin_email_id==$admin_arr['admin_login']))
        {
          echo  "<h4 style='color:red;text-transform: inherit;'>Invalid Your Username  Input Correct username...<h4>";
        }
      }
    }
}
?>
