<?php
//CAPTCHA Matching code
include("../connection.php");
if(isset($_POST['contact1']))
{
  if($_SESSION["code"]==$_POST["captcha"])
  {
            $Subject = $_POST['subject'];     
            //$ToEmail = 'abhayfivedesign@gmail.com';
            $ToEmail = 'info@icvassessments.com';
            $me=$_POST['name'];            
            $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["fname"]."<br>";
           

            @$MESSAGE_BODY .= "Email : ".$_POST["email"]."<br>";
            @$MESSAGE_BODY .= "Mobile : ".$_POST["phone"]."<br>";
            @$MESSAGE_BODY .= "Organisation : ".$_POST["Organisation"]."<br>";
            if(@mail($ToEmail, $Subject, $MESSAGE_BODY, $mailheader))
                {
                    echo "Successfully Mail Send!!!";
                    unset($_SESSION['code']);
                }
          else
              {
                  echo "Mail Not Send!!!";
              }
  }
  else 
      {
          echo "Enter invalid capcha try again";
      }
  }
  ?>

  <?php
//Login File Send ////////////////


if(isset($_POST['contact']))
{
   if($_SESSION["code"]==$_POST["captcha"])
  {
      extract($_POST);
      
      $recipient_email    = "abhayfivedesign@gmail.com"; //recepient
  
   
    $sender_name    = filter_var($fname, FILTER_SANITIZE_STRING); //capture sender name
    $sender_email   = filter_var($email, FILTER_SANITIZE_STRING); //capture sender email
    $phone_number   = filter_var($phone, FILTER_SANITIZE_NUMBER_INT);
    $Organisation        = filter_var($Organisation, FILTER_SANITIZE_STRING);
    $message        = filter_var($message, FILTER_SANITIZE_STRING); //capture message
    $subject = "Career ......!!";
    $attachments = $_FILES['my_files'];    
    $file_count = count($attachments['name']); //count total files attached
    $boundary = md5("sanwebe.com"); 
    
    
    
    //construct a message body to be sent to recipient 
    $message_body =  "Message from $sender_name\n";
    $message_body .=  "------------------------------\n";
    $message_body .=  "$sender_name\n";
    $message_body .=  "------------------------------\n";
    $message_body .=  "$sender_email\n";
    $message_body .=  "$phone_number\n";
    $message_body .=  "$Organisation\n";
    $message_body .=  "$message\n";

    
    if($file_count > 0){ //if attachment exists
        //header
        $headers = "MIME-Version: 1.0\r\n"; 
        $headers .= "From:".$from_email."\r\n"; 
        $headers .= "Reply-To: ".$sender_email."" . "\r\n";
        $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; 
        
        //message text
        $body = "--$boundary\r\n";
        $body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
        $body .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
        $body .= chunk_split(base64_encode($message_body)); 

        //attachments
        for ($x = 0; $x < $file_count; $x++){       
            if(!empty($attachments['name'][$x])){
                
                if($attachments['error'][$x]>0) //exit script and output error if we encounter any
                {
                    $mymsg = array( 
                    1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", 
                    2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 
                    3=>"The uploaded file was only partially uploaded", 
                    4=>"No file was uploaded", 
                    6=>"Missing a temporary folder" ); 
                    print  $mymsg[$attachments['error'][$x]]; 
                    exit;
                }
                
                //get file info
                $file_name = $attachments['name'][$x];
                $file_size = $attachments['size'][$x];
                $file_type = $attachments['type'][$x];
                
                //read file 
                $handle = fopen($attachments['tmp_name'][$x], "r");
                $content = fread($handle, $file_size);
                fclose($handle);
                $encoded_content = chunk_split(base64_encode($content)); //split into smaller chunks (RFC 2045)
                
                $body .= "--$boundary\r\n";
                $body .="Content-Type: $file_type; name=".$file_name."\r\n";
                $body .="Content-Disposition: attachment; filename=".$file_name."\r\n";
                $body .="Content-Transfer-Encoding: base64\r\n";
                $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n"; 
                $body .= $encoded_content; 
            }
        }

    }else{ //send plain email otherwise
       $headers = "From:".$from_email."\r\n".
        "Reply-To: ".$sender_email. "\n" .
        "X-Mailer: PHP/" . phpversion();
        $body = $message_body;
    }
        
    $sentMail = mail($recipient_email, $subject, $body, $headers);
    if($sentMail) //output success or failure messages
    {
        echo "Thank you for your email";   
        exit;
    }
    else
    {
        echo "Could not send mail! Please check your PHP mail configuration.";
        exit;
    }
}
}
?>
<?php

//***********************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();
  }
  if($_SESSION['code1']!=$_POST['cap_admin'])
  {
     echo "<h4 style='color:red;font-weight:bold;''>Captcha:</h4><p style='color:red;font-weight:bold;'>Invalid Captcha Try Again...</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'];
        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>";
        }
      }
    }
}
?>
