File: /var/www/panigaletech.com/wp-content/themes/panigale/template-parts/submit_resume.php
<?php
/**
* Template Name: Submit Resume
*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
get_header();
ini_set('max_execution_time', 900000);
set_time_limit(0);
$msg = '';
if($_POST)
{
$msg = '';
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone_no = $_POST['phone_no'];
global $wpdb;
$client_secret = 'MpZixnLHV6sAFGZUA8M0QwJw';
$client_id = 'edf1089c-c6a7-43a1-a6ed-7f85c0cd7fe2';
$table_name = "bullhorn_token";
$token_details = $wpdb->get_results( "SELECT * FROM $table_name ORDER BY i_id DESC LIMIT 1" );
/**** Get Access Token From Refresh Token start ****/
$refresh_token = $token_details[0]->s_refresh_token;
$token_url = 'https://auth.bullhornstaffing.com/oauth/token?grant_type=refresh_token&refresh_token='.$refresh_token.'&client_id='.$client_id.'&client_secret='.$client_secret.'';
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch,CURLOPT_URL, $token_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POST, '1');
//execute post
$token_result = curl_exec($ch);
//close connection
curl_close($ch);
$token_result_arr = json_decode($token_result);
$access_token = $token_result_arr->access_token;
$new_refresh_token = $token_result_arr->refresh_token;
//print_r($token_result_arr);exit;
$table = 'bullhorn_token';
$data = array('s_access_token' => $access_token, 's_refresh_token' => $new_refresh_token,'dt_created_date'=>date('Y-m-d H:i:s'));
$wpdb->insert($table,$data);
unset($ch);
/**** Get Access Token From Refresh Token end ****/
/**** Create BHRestToken start ****/
$bhrest_token_url = 'https://rest.bullhornstaffing.com/rest-services/login?version=*&access_token='.$access_token.'';
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch,CURLOPT_URL, $bhrest_token_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//execute post
$bhrest_token_result = curl_exec($ch);
//close connection
curl_close($ch);
$bhrest_token_result_arr = json_decode($bhrest_token_result);
$bhrest_token = $bhrest_token_result_arr->BhRestToken;
$rest_url = $bhrest_token_result_arr->restUrl;
unset($ch);
/**** Create BHRestToken end ****/
/**** Check Candidate exist or not start ****/
$candidate_search_url = urlencode('firstName:"'.$first_name.'" AND lastName:"'.$last_name.'"AND email:"'.$email.'"');
$candidate_exist_api_url = $rest_url.'search/Candidate?count=3&query='.$candidate_search_url.'&fields=id&BhRestToken='.$bhrest_token.'';
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch,CURLOPT_URL, $candidate_exist_api_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//execute post
$candidate_exist_result = curl_exec($ch);
//close connection
curl_close($ch);
$candidate_exist_result_arr = json_decode($candidate_exist_result);
unset($ch);
$total_result = $candidate_exist_result_arr->total;
if($total_result == 0)
{
/*$candidate_insert_api_url = $rest_url.'entity/Candidate?BhRestToken='.$bhrest_token.'';
$data = array(
'firstName' => $first_name,
'lastName' => $last_name,
'email' => $email,
'phone' => $phone_no
);
$ch = curl_init();
$headers = array('Content-Type: application/json');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch,CURLOPT_URL, $job_api_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POST, '1');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//execute post
$candidate_result = curl_exec($ch);
//close connection
curl_close($ch);*/
$candidate_resume_parse_api_url = $rest_url.'resume/parseToCandidate?format=DOC&BhRestToken='.$bhrest_token.'';
if (function_exists('curl_file_create')) { // php 5.5+
$cFile = curl_file_create($_FILES['resume_file']['tmp_name']);
$cFile->postname = $_FILES['resume_file']['name'];
$cFile->mime = $_FILES['resume_file']['type'];
} else { //
$cFile = '@' . realpath($_FILES['resume_file']['tmp_name']).';filename=' . $_FILES['resume_file']['name'].';type=' . $_FILES['resume_file']['type'];
}
$data = array(
'resume' => $cFile
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch,CURLOPT_URL, $candidate_resume_parse_api_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POST, '1');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//execute post
$resume_parse_result = curl_exec($ch);
//close connection
curl_close($ch);
$resume_parse_result_arr = json_decode($resume_parse_result);
unset($ch);
//echo '<pre>';print_r($resume_parse_result_arr);exit;
$candidate_personal_details = $resume_parse_result_arr->candidate;
$candidate_education_details = $resume_parse_result_arr->candidateEducation;
$candidate_workhistory_details = $resume_parse_result_arr->candidateWorkHistory;
//echo '<pre>';print_r($candidate_personal_details);
$address = $candidate_personal_details->address;
$firstName = $candidate_personal_details->firstName;
$lastName = $candidate_personal_details->lastName;
$email = $candidate_personal_details->email;
$mobile = $candidate_personal_details->mobile;
$candidate_details_arr = array('address'=>$address,'firstName'=>$firstName,'lastName'=>$lastName,'email'=>$email,'mobile'=>$mobile,'phone'=>$phone_no);
$candidate_details = json_encode($candidate_details_arr);
if($firstName != '')
{
$candidate_insert_api_url = $rest_url.'entity/Candidate?BhRestToken='.$bhrest_token.'';
$ch = curl_init();
$headers = array('Content-Type: application/json');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch,CURLOPT_URL, $candidate_insert_api_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $candidate_details);
//execute post
$candidate_insert_result = curl_exec($ch);
//echo '<pre>';print_r(curl_getinfo($ch));
//close connection
curl_close($ch);
$candidate_insert_result_arr = json_decode($candidate_insert_result);
unset($ch);
//echo '<pre>';print_r($candidate_insert_result_arr);exit;
$candidateId = $candidate_insert_result_arr->changedEntityId;
if(!empty($candidate_education_details))
{
foreach($candidate_education_details as $candidate_education_details_val)
{
$startDate = $candidate_education_details_val->startDate;
$endDate = $candidate_education_details_val->endDate;
$graduationDate = $candidate_education_details_val->graduationDate;
$school = $candidate_education_details_val->school;
$degree = $candidate_education_details_val->degree;
$major = $candidate_education_details_val->major;
$education_details_arr = array('candidate'=>json_encode(array('id'=>$candidateId)),'startDate'=>$startDate,'endDate'=>$endDate,'graduationDate'=>$graduationDate,'school'=>$school,'degree'=>$degree,'major'=>$major);
$education_details = json_encode($education_details_arr);
$candidate_education_insert_api_url = $rest_url.'entity/CandidateEducation?BhRestToken='.$bhrest_token.'';
$ch = curl_init();
$headers = array('Content-Type: application/json');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch,CURLOPT_URL, $candidate_education_insert_api_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $education_details);
//execute post
$candidate_education_insert_result = curl_exec($ch);
//close connection
curl_close($ch);
$candidate_education_insert_result_arr = json_decode($candidate_education_insert_result);
unset($ch);
unset($education_details_arr);
}
}
if(!empty($candidate_workhistory_details))
{
foreach($candidate_workhistory_details as $candidate_workhistory_details_val)
{
$startDate = $candidate_workhistory_details_val->startDate;
$endDate = $candidate_workhistory_details_val->endDate;
$companyName = $candidate_workhistory_details_val->companyName;
$title = $candidate_workhistory_details_val->title;
$comments = $candidate_workhistory_details_val->comments;
$workhistory_details_arr = array('candidate'=>json_encode(array('id'=>$candidateId)),'startDate'=>$startDate,'endDate'=>$endDate,'companyName'=>$companyName,'title'=>$title,'comments'=>$comments);
$workhistory_details = json_encode($workhistory_details_arr);
$candidate_workhistory_insert_api_url = $rest_url.'entity/CandidateWorkHistory?BhRestToken='.$bhrest_token.'';
$ch = curl_init();
$headers = array('Content-Type: application/json');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_URL, $candidate_workhistory_insert_api_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $workhistory_details);
//execute post
$candidate_work_historyinsert_result = curl_exec($ch);
//close connection
curl_close($ch);
$candidate_work_historyinsert_result_arr = json_decode($candidate_work_historyinsert_result);
unset($ch);
unset($workhistory_details_arr);
}
}
$candidate_resume_upload_api_url = $rest_url.'file/Candidate/'.$candidateId.'/raw?BhRestToken='.$bhrest_token.'&externalID=Portfolio&fileType=SAMPLE';
if (function_exists('curl_file_create')) { // php 5.5+
$cFile = curl_file_create($_FILES['resume_file']['tmp_name']);
$cFile->postname = $_FILES['resume_file']['name'];
$cFile->mime = $_FILES['resume_file']['type'];
} else { //
$cFile = '@' . realpath($_FILES['resume_file']['tmp_name']).';filename=' . $_FILES['resume_file']['name'].';type=' . $_FILES['resume_file']['type'];
}
$data = array(
'resume' => $cFile
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_URL, $candidate_resume_upload_api_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//execute post
$candidate_resume_upload_result = curl_exec($ch);
//close connection
curl_close($ch);
$candidate_resume_upload_result_arr = json_decode($candidate_resume_upload_result);
unset($ch);
//print_r($candidate_resume_upload_result_arr);exit;
$candidate_resume_upload_result_arr = (array)$candidate_resume_upload_result_arr;
if(!empty($candidate_resume_upload_result_arr))
{
$msg = 'Resume submitted successfully';
}
else
{
$msg = 'Resume submit failed';
}
}
else
{
$msg = 'Candidate resume persing failed';
}
}
else
{
$msg = 'Candidate exist';
}
}
?>
<section class="inner-section mb-3">
<div class="container-fluid">
<div class="row">
<div class="col-lg-6 col-md-8 col-sm-12 offset-lg-3 offset-md-2 text-center mb-5">
<h2 class="heading02 font-weight-7 mb-2 wow fadeInUp" data-wow-duration="2s">Submit Your Resume</h2>
<p class=" wow fadeInUp" data-wow-duration="2s">We spend our day discovering top talent. With access to millions of resumes, our teams screen more than 10K candidates weekly.Below is a snapshot of our talent showcase. Let us know how we can help you identify your next hire.</p>
</div>
<div class="col-lg-4 offset-lg-4">
<div class="row submit_resume">
<?php if($msg != ''){?>
<div class="alert alert-success fade in alert-dismissible" style="margin-top:18px;">
<a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
<strong>Success!</strong> <?php echo $msg;?>
</div>
<?php }?>
<form name="frm_submit_resume" id="frm_submit_resume" action="" method="POST" enctype="multipart/form-data">
<div class="row">
<div class="col-md-12">
<div class="form-group wow fadeInUp" data-wow-duration="2s">
<label>First Name</label>
<input type="text" class="form-control" name="first_name" id="first_name">
<span class="error-message"></span>
</div>
</div>
<div class="col-md-12">
<div class="form-group wow fadeInUp" data-wow-duration="2s">
<label>Last Name</label>
<input type="text" class="form-control" name="last_name" id="last_name">
<span class="error-message"></span>
</div>
</div>
<div class="col-md-12">
<div class="form-group wow fadeInUp" data-wow-duration="2s">
<label>Email</label>
<input type="email" class="form-control" name="email" id="email">
<span class="error-message"></span>
</div>
</div>
<div class="col-md-12">
<div class="form-group wow fadeInUp" data-wow-duration="2s">
<label>Phone</label>
<input type="tel" class="form-control" name="phone_no" id="phone_no">
<span class="error-message"></span>
</div>
</div>
<div class="col-md-12">
<div class="form-group wow fadeInUp" data-wow-duration="2s">
<label>Resume</label>
<input type="file" class="form-control" name="resume_file" id="resume_file"/>
</div>
</div>
<div class="col-md-12 wow fadeInUp" data-wow-duration="2s">
<button type="button" id="btnSubmt" class="btn btn-blue">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<?php
get_footer();
?>
<script type="text/javascript">
var markAsError = function(selector,msg,animate){
/*if(focus_element == '')
focus_element = selector;*/
/*if(animate != 'no')
$('html, body').animate({scrollTop : 0},800);*/
//$(selector).next('.text-danger').html('<i class="fa fa-times-circle-o"></i> '+msg);
/*$(selector).next('.text-danger').html(msg);
$(selector).parents('.form-panel').addClass("error");*/
$('html, body').animate({scrollTop : 0},800);
$(selector).next('.error-message').html(msg);
$(selector).parents('.form-panel').addClass("error");
$(selector).on('focus',function(){
removeAsError($(this));
});
}
// Hide error
var removeAsError = function(selector){
/*$(selector).next('.text-danger').html('');
$(selector).parents('.form-group').removeClass("has-error");*/
$(selector).next('.error-message').html('');
$(selector).parents('.form-panel').removeClass("error");
}
$(document).ready(function() {
$("#btnSubmt").click(function() {
var b_valid = true;
var s_err = '';
var email_pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i;
$("#div_err").hide("slow");
if ($("#first_name").val() == '') {
markAsError($("#first_name"), 'First Name is required!');
b_valid = false;
}
if ($("#last_name").val() == '') {
markAsError($("#last_name"), 'Last Name is required!');
b_valid = false;
}
if ($("#email").val() == '') {
markAsError($("#email"), 'Email is required!');
b_valid = false;
}
else if (email_pattern.test($.trim($("#email").val())) == false) {
markAsError($("#email"), 'Please provide a valid email');
b_valid = false;
}
if ($("#phone_no").val() == '') {
markAsError($("#phone_no"), 'Phone no is required!');
b_valid = false;
}
if (!b_valid) {
$("#div_err").html('<div id="err_msg" class="error_massage">' + s_err + '</div>').show(
"slow");
}
else
{
$("#frm_submit_resume").submit();
}
return b_valid;
});
});
</script>