<?php
// echo "here";
// exit;
include_once("include/main.inc.php");
date_default_timezone_set('Asia/Kolkata');
$enq_date = date('Y-m-d H:i:s');

$referer = $_SERVER['HTTP_REFERER'];
$ip=$_SERVER['REMOTE_ADDR'];

if (isset($_POST['career_submit']))
    {

        $name = !empty($_POST['name'])?$_POST['name']:'';
        $email = !empty($_POST['email'])?$_POST['email']:'';
        $mobile = !empty($_POST['mobile'])?$_POST['mobile']:'';
        $location = !empty($_POST['location'])?$_POST['location']:'';
        $zipcode = !empty($_POST['zipcode'])?$_POST['zipcode']:'';
        $qualifications = !empty($_POST['qualifications'])?$_POST['qualifications']:'NA';
        $experience = !empty($_POST['experience'])?$_POST['experience']:'NA';
        $jobtitle = !empty($_POST['jobtitle'])?$_POST['jobtitle']:'';
        $salary = !empty($_POST['salary'])?$_POST['salary']:'NA';
        $message = !empty($_POST['message'])?$_POST['message']:'NA';
      // $code = (!empty($_POST['code']))?$_POST['code']:'';
      // $countryNames = (!empty($_POST['countryName']))?$_POST['countryName']:'';
      // $countryName1= explode('(',$countryNames);
      // $countryName=$countryName1[0];
      // $code =$code!=''?$code:'91';
      // $countryName= $countryName!=''?$countryName:'India';
      // $mobileNumbers= '+'.$code.' - '.$mobile;
      $image = !empty($_FILES["files"]["name"])?$_FILES["files"]["name"]:'';
 if($_FILES['files']['name']!="") {

  $target_file = "uploaded-files/resume/".basename($_FILES["files"]["name"]);
 move_uploaded_file($_FILES["files"]["tmp_name"], $target_file);
}
    
      if(strpos($message,'#')!==false || strpos($message,'%')!==false || strpos($message,'@')!==false || strpos($message,'&')!==false || strpos($message,'~')!==false || strpos($message,'https')!==false || strpos($message,'http')!==false || strpos($message,'www')!==false || strpos($message,'?')!==false  || strpos($name,'#')!==false || strpos($name,'%')!==false || strpos($name,'@')!==false || strpos($name,'&')!==false || strpos($name,'~')!==false || strpos($name,'https')!==false || strpos($name,'http')!==false || strpos($name,'www')!==false || strpos($name,'?')!==false){
          $resp = [
              'message_response' => 'URL(s) and special characters are not allowed',
              'status' => false
          ];
          echo json_encode($resp);
          exit;
      } else {   
        if($name != '' && $email != '' && $mobile != ''  && $location != ''){
             if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
                 $secret = secret_key;
      $data = array( 'secret' => $secret, 'response' => $_POST['g-recaptcha-response'] ); $verify = curl_init(); curl_setopt($verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify"); curl_setopt($verify, CURLOPT_POST, true); curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($verify, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($verify); //var_dump($response);
      $response = json_decode($response);
      if (!$response->success) {
          $resp = [
              'message_response' => 'Robot verification failed, please try again.',
              'status' => false
          ];
          echo json_encode($resp);
          exit;
      }	
      if($response->success) {
          $sql_ens="insert into tbl_careerEnquiry set en_name='$name', en_email='$email', en_mobile='$mobile', en_comment='$message', en_zip='$zipcode', en_jobTitle='$jobtitle', en_doc_name='$image', en_url='$referer', en_country='$location', en_qualification='$qualifications',en_experience='$experience',en_salary='$salary', en_ip='$ip', en_date='$enq_date'";
         
          $qry=mysqli_query($GLOBALS['dbconn'], $sql_ens);
          
          $subject = utf8_encode('Webpulseindia.com - Career Enquiry From '. site_url);
          // $htmlContent = "
          // Customer Details:
          // Url: ".$referer."
          // Name: ".$name."    
          // Email: ".$email."
          // Mobile: ".$mobileNumber."
          // Location:".$location."
          // Message: ".$message."
          // ";
            $htmlContent =  '<table border="0" width="100%">
      <tbody>
<tr>
  <td colspan="2">
    <strong>Dear Admin</strong></td>
</tr>
<tr>
  <td colspan="2">
    Enquiry Received with following info :</td>
</tr>
<tr>
  <td colspan="2">
    &nbsp;</td>
</tr>
<tr>
  <td width="26%">
    <strong>Post URL : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $referer . '</span></td>
</tr>
<tr>
  <td width="26%">
    <strong>Name : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $name . '</span></td>
</tr>
<tr>
  <td width="26%">
    <strong>Email Id : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $email . '</span></td>
</tr>
<tr>
  <td width="26%">
    <strong>Contact No : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $mobile . '</span></td>
</tr>
<tr>
  <td>
    <strong>Location : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $location . '</span></td>
</tr>

<tr>
  <td>
    <strong>Zip Code : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $zipcode . '</span></td>
</tr>

<tr>
  <td>
    <strong>Qualifications : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $qualifications . '</span></td>
</tr>
<tr>
  <td>
    <strong>Experience : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $experience . '</span></td>
</tr>

<tr>
  <td>
    <strong>Job Title : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $jobtitle . '</span></td>
</tr>

<tr>
  <td>
    <strong>Salary Expectation : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $salary . '</span></td>
</tr>
<tr>
  <td>
    <strong>Message : </strong></td>
  <td>
    <span style="margin-top: 15px;">' . $message . '</span></td>
</tr>
<tr>
  <td>
    <strong>Resume : </strong></td>
  <td>
    <span style="margin-top: 15px;"><a href="' . site_url . '/uploaded-files/resume/'.$image.'">View Resume</a></span></td>
</tr>


</tbody>
      </table>';
          $to = 'hr@ajmerafashion.com';
          $to2 = $admin_res['cc'];
          $to3 = 'webpulseindia@gmail.com'; 
        // $to= 'cs1@webpulseindia.com';
        //   $to3 = 'developer1.wpsrnc@gmail.com'; 
          // $headers = 'From: '.'Webpulseindia.com'.' enquiry@webpulseindia.com' . "\r\n" .
          // 'Reply-To:  '.$name.'<'.$email.'>' . "\r\n" .
          // 'X-Mailer: PHP/' . phpversion();
          // @mail($to,$subject,$htmlContent,$headers);
          // @mail($to2,$subject,$htmlContent,$headers);
          // @mail($to3,$subject,$htmlContent,$headers);
        if($to!='')
       {
       smtp_mailer($to, $email, $name, $subject, $htmlContent);
       }
       if($to2!='')
       {
       smtp_mailer($to2, $email, $name, $subject, $htmlContent);
       }
       smtp_mailer($to3, $email, $name, $subject, $htmlContent);
          $resp = [
              'message_response' => 'Thank you for your enquiry. Our team will contact you soon.',
              'status' => true
          ];
          echo json_encode($resp);
          exit;
      }	
  }
  else {
      $resp = [
          'message_response' => 'Please check the recaptcha box!',
          'status' => false
      ];
      echo json_encode($resp);
      exit;
 }
}
else {
  $resp = [
      'message_response' => 'All the fields are Mandatory!',
      'status' => false
  ];
  echo json_encode($resp);
  exit;
}
}

}
?>