<?php
	require_once( explode( "wp-content" , __FILE__ )[0] . "wp-load.php" );	
	
	$dir_id=0; if(isset($_REQUEST['dir_id'])){$dir_id=sanitize_text_field($_REQUEST['dir_id']);}
	$id=$dir_id;	
	$jobbank_apply=get_option('jobbank_apply_opt');	
	if($jobbank_apply==""){$jobbank_apply='visitor';}	
	
	$div_class='';
	if(get_post_meta($id,'external_form_url',true)!=''){
		if($jobbank_apply=='visitor'){
			$div_class='col-md-4';
		}elseif($jobbank_apply=='only_user'){
			$div_class='col-md-6';
		}else{
			$div_class='col-md-12';
		}
	}else{
		if($jobbank_apply=='visitor'){
			$div_class='col-md-6';
		}elseif($jobbank_apply=='only_user'){
			$div_class='col-md-12';
		}else{
			$div_class='col-md-12';
		}
	
	}
?>
<div class="bootstrap-wrapper popup0margin "id="popup-contact" >		
	<div class="container" >
		<div class="row" >		
			<div class="col-md-12">
				<div class="modal-header">
					<div class="modal-title"><?php esc_html_e('Job Application','jobbank'); ?></div>							
						<button type="button" onclick="jobbank_contact_close();" class="close btn btn-border " data-dismiss="modal" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
				</div>
				<div class="modal-body"> 
					<div class="row vertical-divider">
						<?php
						if($jobbank_apply=='visitor'){
						?>
						<div class="<?php echo esc_html($div_class); ?> ">
							<?php
							include( ep_jobbank_template. 'listing/apply-form.php');						
							?>
						</div>
						<?php
						}
						?>
						<?php
						if($jobbank_apply=='only_user' OR $jobbank_apply=='visitor'){
						?>
						<div class="<?php echo esc_html($div_class); ?> ">
						<div class="modal-title"><?php esc_html_e('Apply From Your Account ','jobbank'); ?></div>
						<hr/>
						<?php
						 if(is_user_logged_in()){
						
							$job_apply='no';
							$userID = get_current_user_id();
							$job_apply_all = get_user_meta($userID,'job_apply_all',true);
							$job_apply_all = explode(",", $job_apply_all);
							if (in_array($id, $job_apply_all)) {
								$job_apply='yes';
							}										
							if($job_apply=='yes'){ ?>
								<div class="col-md-12 alert alert-info alert-dismissable"><h4><?php  esc_html_e( 'Applied Already', 'jobbank' ); ?></h4></div>
								
							<?php	
							}	
							?>
						<form action="#" id="apply-pop2" name="apply-pop2"   method="POST" >
							<div class="form-group ">
								<label for="message" ><?php  esc_html_e( 'Cover Letter', 'jobbank' ); ?></label>
								 <input type="hidden" name="dir_id" id="dir_id" value="<?php echo esc_attr($id);?>">
								<textarea  class="col-md-12  form-control-textarea" name="cover-content2" id="cover-content2"  cols="20" rows="3"></textarea>
							 </div>
							 <div class="form-group ">									
							  <button type="button" class="btn btn-big  ml-2"  onclick="jobbank_job_apply_user();" ><?php  esc_html_e( 'Submit', 'jobbank' ); ?></button>									 
							  </div>
						</form>
						 <div  id="message_popupjob_apply_user"></div> 
						<?php
						}else{
							$login_page=get_option('epjbjobbank_login_page'); 
							?>
								<h5 ><a href="<?php echo get_permalink( $login_page);?>"><?php esc_html_e('Please Login & Apply','jobbank'); ?></a></h5>
							<?php
							
							}
							?>
						</div>
						
						<?php
						}
						?>
						<?php
						if(get_post_meta($id,'external_form_url',true)!=''){
						?>	
						<div class="<?php echo esc_html($div_class); ?> ">							
							<a  target="_blank" class="btn btn-big  ml-2 mt-4" href="<?php echo esc_url(get_post_meta($id,'external_form_url',true)); ?>"> <?php esc_html_e('Submit on External Form','jobbank'); ?> </a>
						</div>								
							<?php
							}
							?>
					</div>					
				</div>	
				</div>	
		</div>	
	</div>	
</div>	
