<?php



function jobtheme_contributes($columns) {
		$columns['jb1'] = "Job Theme Role";			 
		return $columns;
}		
function jobtheme_contributes_columns( $value, $column_name, $user_id ) {  
 
	if ( 'jb1' != $column_name ){ return $value; }
 			
	if($column_name == "jb1"){
		
		$usertype = get_user_meta($user_id, 'account_type', true);
		if($usertype == 1){
			return "Employee";
		}else{
			return "Job Seeker";
		}
	}	 
}	
 
class core_jobs extends white_label_themes {

function __construct(){




		if(is_admin()){		 

 			// HOOK INTO THE EDIT PAGE AND ADD-ON STORE FIELDS
	 		//add_action('hook_admin_1_pagesetup', array($this, '_hook_admin_1_pagesetup'  ) ); 
	 
			add_action('hook_fieldlist_0', array($this, '_extra_fields' ) );
			
			// ADD IN NEW ADMIN AREA COLUMN
			add_filter('manage_users_columns', 'jobtheme_contributes');
			add_action('manage_users_custom_column', 'jobtheme_contributes_columns', 10, 3 );		 
			
		}
		

		
 
		add_action('wp', array($this, 'jobs_savefunctions' ) );	
		
		add_action('register_form' ,  array($this, 'register_hiddenfields' ) ); 
		add_action('hook_account_mydetails_after' ,  array($this, 'register_hiddenfields' ) ); 		
		
		// ADD IN CV UPLOAD TOOL
		add_action('hook_account_after',array($this, '_upload_cv')); 
		add_action('hook_account_pagelist', array($this, '_hook_account_pagelist' ) );  	
			
		add_action('hook_email_list', array($this, 'add_new_emails' ) ); 		
		 
		add_action('hook_single_before', array($this, 'jb_winner' ));
		add_action('hook_add_fieldlist',  array($this, '_hook_customfields' ) );
		
		// COUPON ACTIVATED SHORTCODES
		add_shortcode( 'PROFORM', array($this,'shortcode_proform') );
		add_shortcode( 'JOBTYPE', array($this,'wlt_jobtype_label') );
		add_shortcode( 'PRICETYPE', array($this,'wlt_pricetype_label') );
	 
		add_shortcode( 'JOBSTATUS', array($this,'wlt_jobstatus') );
		
		add_shortcode( 'JOBFORM', array($this,'wlt_jobform') );
		
		// HOOK PRICE FOR TEXT
		add_action('hook_price', array($this, '_new_price'), 2 );
		
	 	// HOOK ALL CUSTOM QUERIES TO REMOVE FINISHED JOBS FROM DISPLAY
	 	add_action('hook_custom_queries',  array($this, '_hook_custom_query' ) );
		add_action('hook_wlt_core_search', array($this, '_core_search_extras' ) );
 
		// REGISTER RESUME TYPE
		register_post_type( 'wlt_resume', 
			array(
			'hierarchical' => true,	
			  'labels' => array('name' => 'Resume'),
			  'public' => true,
			  'query_var' => true,
			  'show_ui' => true,
			  'menu_icon' 	=> get_template_directory_uri()."/framework/admin/img/icons/35.png",
			  'exclude_from_search' => true,
			  'rewrite' => array('slug' => 'resume'),
			  'supports' 			=> array ( 'title', 'editor','author', 'post-formats', 'comments','excerpt', 'thumbnail', 'custom-fields', 'publicize', 'wpcom-markdown' ),
			  //'taxonomies' => array('category'),    
	 
		) );
		
	}


 
	
		//1. HOOK INTO THE ADMIN MENU TO CREATE A NEW TAB
	function _hook_admin_1_pagesetup(){  global $wpdb, $CORE; $core_admin_values = get_option("core_admin_values");  ?>
	
	<div class="accordion-group">
    <div class="accordion-heading" style="background:#fff;">
        <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#pagesetup_according" href="#extra1">
         <h4 style="margin:0xp;font-weight:bold;">
         <img src="<?php echo get_template_directory_uri(); ?>/framework/admin/img/icons/set.png">
         Job Board Settings <span style="font-size:12px;">(view/hide)</span></h4> 
        </a>
    </div>
    
    <div id="extra1" class="accordion-body collapse">
    <div class="accordion-inner">
    <div class="innerwrap content">
     
   no settings
   
	</div></div></div></div>
     
     <?php 
     }
	 
	function _hook_account_pagelist($c){ global $userdata;
	
	$usertype = get_user_meta($userdata->ID, 'account_type', true);
	/*
	0 = job seeker
	1 = business owner
	*/
	if($usertype == 0){
	
		unset($c[1]);
		unset($c[2]);
		
		$c[] = array(
		"l" => "#top",
		"oc" => "jQuery('#MyAccountBlock').hide();jQuery('#MyCVBlock').show();",
		"i" => "fa fa-file-text ",
		"t" => "My Resume (CV)",
		"d" => "Here you can upload &amp; manage your profile resume.",
		"e" => "",
		);
		
	} 
	
	return $c;
	}
 
	
	// EXTRA FIELD ON REGISTRATION PAGE FOR CHOOSING ACCOUNT TYPE
	function register_hiddenfields(){ global $userdata;
	
	$current = 0;
	if($userdata->ID){
	
		$current = get_user_meta($userdata->ID, 'account_type', true);
	}
	
	ob_start();
	
	?> 
    
    <ul style="line-height:40px;">
    
    	<li>As a <b>job seeker</b> you can manage your resume, upload a CV and apply for jobs.</li>
    
    	<li>As a <b>recruiter</b> you can create and manage your jobs, view and contact job seekers.</li>
  
    </ul>
    
    <div class="registertype">
    
        <div class="well">
        
            <div class="col-md-6">
            <a href="javascript:void(0);"  class="l1 <?php if($current == "0"){ echo "selected"; } ?>" 
            onclick="jQuery('#jb_field_accounttype').val(0);jQuery(this).addClass('selected');jQuery('.l2').removeClass('selected');">
            <div class="thumbnail text-center"> <i class="fa fa-user"></i> <div> I am a <span> Job Seeker </span> </div> </div>
            </a>
            </div>
            
            <div class="col-md-6">
            <a href="javascript:void(0);" class="l2 <?php if($current == "1"){ echo "selected"; } ?>" 
            onclick="jQuery('#jb_field_accounttype').val(1); jQuery(this).addClass('selected');jQuery('.l1').removeClass('selected');">
            <div class="thumbnail text-center"> <i class="fa fa-briefcase"></i> <div> I am a <span> Recruiter </span> </div> </div>
            </a>
            </div>
            
            <div class="clearfix"></div>
        
        </div>
    
    </div>
    
	<input type='hidden' id='jb_field_accounttype' name='custom[account_type]' value='0'>
    
	<?php
	echo ob_get_clean(); 
	
	} 
	 
	
	
	function wlt_jobform(){ global $CORE, $userdata;
	
	ob_start();
	?>
    
<div class="wlt_shortcode_jobform">


<?php if($userdata->ID){ ?>

<form method="post" action="" enctype="multipart/form-data" onsubmit="return CheckFormData();">
<input type="hidden" name="jb_action" value="jobform"> 

<?php } ?>
 

<div class="row form-group">
    <div class="col-md-6">
    <label>First Name</label>
    <input type="text"  class="form-control jbf1" name="jobform[fname]" />
    </div>
    
    <div class="col-md-6">
    <label>Last Name</label>
    <input type="text"  class="form-control jbf2" name="jobform[lname]" />
    </div>
</div>

 
<div class="form-group">
<label>Email address</label>
<input type="text"  class="form-control jbf3" name="jobform[email]" />
</div>

<div class="form-group">
<label>Covering Message</label>
<textarea style="width:100%; height:100px;" class="form-control jbf4" name="jobform[msg]" ></textarea>
</div>

<hr style="  border-top: 1px solid #D5D5D5;  border-bottom: 1px solid #fff;" />

<div class="form-group">
<label>Upload your CV</label>
<input type="file" name="mycsv" />

<p style="font-size:12px;" class="label label-info">.PDF Files Only.</p>
</div>
<hr style="border-top: 1px solid #D5D5D5;  border-bottom: 1px solid #fff;" />


<div class="text-center"><button class="btn btn-success btn-lg" <?php if(!$userdata->ID){ ?>onclick="alert('Please login to submit this application.');"<?php } ?>>Submit Application</button></div>

<?php if($userdata->ID){ ?>
</form>
<?php } ?>
</div>
<script language="javascript" type="text/javascript">
function CheckFormData(){ 
					 
			if(jQuery('.jbf1').val() == '')
			{
				alert('<?php echo $CORE->_e(array('validate','0')); ?>'); 
				return false;
			}
 		
			
			return true;
} 
</script>    
            
<?php 
return ob_get_clean();
}
	
 
	function _upload_cv(){  global $CORE, $userdata;
	
	// CHECK FOR EXISTING CSV
	$myresumeid = get_user_meta($userdata->ID,'myresumeid',true);
	
	// GET RESUME DATA
	if($myresumeid != ""){
		$resume0 = get_post_meta($myresumeid, 'resume0', true); 
		$resume1 = get_post_meta($myresumeid, 'resume1', true); 
		$resume2 = get_post_meta($myresumeid, 'resume2', true); 
		$resume3 = get_post_meta($myresumeid, 'resume3', true); 
		$resume4 = get_post_meta($myresumeid, 'resume4', true); 	
		$mycv = get_post_meta($myresumeid, 'cv', true); 
	}
	
	?>
    
    <div class="panel panel-default" id="MyCVBlock" style="display:none;">
    
    <div class="panel-heading">MY CV</div>
		 
	<div class="panel-body"> 
    
    <h1><?php echo $CORE->_e(array('author','28')); ?></h1> 
    
    <hr />
    
<form method="post" action="" enctype="multipart/form-data" onsubmit="return CheckFormData();">
<input type="hidden" name="jb_action" value="saveresume"> 
<?php 

if($resume1 !="" ){ $resume1 = stripslashes($resume1); }
?>

 
<div class="form-group">
<label>Opening Text <span style="font-weight:normal;color:#999;" >(short description)</span> </label>
<input name="resume0" type="text" class="form-control" value="<?php if(isset($resume0)){ echo $resume0; } ?>" maxlength="200" />
</div>

<hr />

<div class="form-group">
<label>My Skills <span style="font-weight:normal;color:#999;" >(separate each skill with a comma. e.g skill1, skill2, skill3)</span> </label>
<input name="resume1" type="text" class="form-control" value="<?php if(isset($resume1)){ echo $resume1; } ?>" />
</div>

<div class="form-group">
<label>My Education</label>
<textarea name="resume2" class="form-control"  style="width:100%; height:150px;"><?php if(isset($resume2)){ echo $resume2; } ?></textarea>
</div>


<div class="form-group">
<label>My Work Experience</label>
<textarea name="resume3" class="form-control"  style="width:100%; height:150px;"><?php if(isset($resume3)){ echo $resume3; } ?></textarea>
</div>
 
<div class="form-group">
<label>My Interests</label>
<textarea name="resume4" class="form-control"  style="width:100%; height:150px;"><?php if(isset($resume4)){ echo $resume4; } ?></textarea>
</div>   
    
<div class="form-group">
<label>My CV</label>
<div class="clearfix"></div>
<input name="mycsv" type="file" class="form-control"  />  <span class="label label-info">(.PDF Files Only)</span>  
</div>      

 <?php
	
	if(isset($mycv) && is_array($mycv)){ ?>
	 <img src="<?php echo get_template_directory_uri(); ?>/framework/img/icons/pdf_small.png" alt="pdf file" /><a href="<?php echo $mycv['url']; ?>" target="_blank"><?php echo $mycv['name']; ?></a>
     - <a href="<?php echo $GLOBALS['CORE_THEME']['links']['myaccount']; ?>?del=cvfile"><i class="gicon-trash"></i> <?php echo $CORE->_e(array('button','3')); ?></a>
	<?php	
	}
	?>

<hr />


<button class="btn btn-success btn-lg" type="submit">Save Resume</button>    
    
    
</form>    
    
    
        		 
	<button class="btn btn-default pull-right" type="button" onclick="jQuery('#MyAccountBlock').show();jQuery('#MyCVBlock').hide();"><?php echo $CORE->_e(array('button','7')); ?></button>
		
    <div class="clearfix"></div>
     
    </div>
    
   
</div>
    <?php
	
	}
	
	// HOOK PRICE TAG
	function _new_price($c){ global $CORE;
	
		if($c == 0 || $c == ""){
		return $CORE->_e(array('author','16'));
		}
		return $c;
	}
	
	// ADD IN CUSTOM QUERY TO PREVENT THE DISPLAY OF FINISHED JOBS
	function _core_search_extras(){ 
		
		// CUSTOM TAX QUERY FOR LOCATIONS USING COUNTRY NAME	 
		if(isset($_GET['jobtype1']) && strlen($_GET['jobtype1']) > 2 ){ 				 
					$GLOBALS['custom'][] = array(							
							'key' => 'jobtype',
							'value' => strip_tags($_GET['jobtype1']),
							'compare'=> '='						
					);					
		}
		
	}
	
	function _hook_custom_query($c){
	  
		$args = array(
			'post_type' => THEME_TAXONOMY."_type",
			
			'meta_query' => array(
			   'relation' => 'OR',
				array(
				 'key' => 'is_completed',
				 'compare' => 'NOT EXISTS', // works!
				 'value' => '' // This is ignored, but is necessary...
				),
				array(
				 'key' => 'is_completed',
				 'value' => 'yes',
				'compare' => '!='
				)
			)
		); 
	
	// MERGE VALUES
	if(!isset($GLOBALS['flag-home'])){
	$c = array_merge($c,$args);
	}
 
	return $c;
	}
	
	// SHORTCODE FOR JOB STATUS
	function wlt_jobstatus( $atts, $content = null ) {
	
		global $userdata, $CORE, $post, $shortcode_tags; $STRING = "";  $default_options = 'text';
		
		extract( shortcode_atts( array('text' => $default_options  ), $atts ) );		
		
		$is_accepted = get_post_meta($post->ID, 'has_accepted_bid', true);
		if($is_accepted != ""){ return " <span class='label label-success'>".$CORE->_e(array('listvalues','6'))."</span>"; }
		
	}

 
	
	function wlt_pricetype_label( $atts, $content = null ) {
	
		global $userdata, $CORE, $post, $shortcode_tags; $STRING = "";  $default_options = 'text';
		
		extract( shortcode_atts( array('text' => $default_options  ), $atts ) );
			
		$tt = get_post_meta($post->ID,'pricetype', true);
		if($tt != ""){
		$label = "";
			switch($tt){
				case "2": { $label = $CORE->_e(array('author','12')); } break;
				case "3": { $label = $CORE->_e(array('author','13')); } break;
				case "4": { $label = $CORE->_e(array('author','14')); } break;
				default: { $label = $CORE->_e(array('author','11')); }
			}
		return $label;
		}
	}
			
	function wlt_jobtype_label( $atts, $content = null ) {
	
		global $userdata, $CORE, $post, $shortcode_tags; $STRING = "";  $default_options = 'text';
		
		extract( shortcode_atts( array('text' => $default_options, 'strip' => false  ), $atts ) );
			
		$tt = get_post_meta($post->ID,'jobtype', true);
		if($tt != ""){
			if($strip){
				return $CORE->_e(array('author',$tt));
			}else{
				return "<span class='label label-".$tt."'>".$CORE->_e(array('author',$tt))."</span>";
			}		
		}
	}
	
	function _hook_customfields($c){ global $CORE;
	
		$o = 50;
	 
		
		$c[$o]['title'] 	= $CORE->_e(array('author','3'));
		$c[$o]['name'] 		= "jobtype";
		$c[$o]['type'] 		= "select";
		$c[$o]['class'] 	= "form-control";
		$c[$o]['listvalues'] 	= array("fulltime" => $CORE->_e(array('author','fulltime')), "parttime" => $CORE->_e(array('author','parttime')),  "contract" => $CORE->_e(array('author','contract')), "internship" => $CORE->_e(array('author','internship')), "temporary" => $CORE->_e(array('author','temporary')));
		$c[$o]['help'] 		= "";
		$o++;
		
		$c[$o]['title'] 	= $CORE->_e(array('author','4'));
		$c[$o]['name'] 		= "pricetype";
		$c[$o]['type'] 		= "select";
		$c[$o]['class'] 	= "form-control";
		$c[$o]['listvalues'] 	= array("" => "", "1" =>  $CORE->_e(array('author','11')), "2" => $CORE->_e(array('author','12')),  "3" => $CORE->_e(array('author','13')), "4" => $CORE->_e(array('author','14')));
		$c[$o]['help'] 		= "<script>jQuery('#form_budgettype').change(function(e) { jQuery('#form-row-rapper-budget').show();    }); jQuery(document).ready(function(){ jQuery('#form-row-rapper-budget').hide(); }); </script>";
		$o++;
		
		$c[$o]['title'] 	= $CORE->_e(array('author','5'));
		$c[$o]['name'] 		= "price";
		$c[$o]['type'] 		= "price";
		$c[$o]['class'] 	= "form-control";
		$c[$o]['help'] 		= $CORE->_e(array('author','17'));
		$o++;
 		
		$c[$o]['title'] 	= "";
		$c[$o]['name'] 		= "bidcount";
		$c[$o]['type'] 		= "hidden";
		$c[$o]['values'] 	= "0";
		$c[$o]['class'] 	= "form-control";
		$o++;	
		
		return $c;
	}
 
	// HOOK INTO THE EDIT LISTING PAGE
	function _extra_fields($c){	global $CORE;
	
		$list1 = array ( 			
		"tab7" => array("tab" => true, "title" => "Job Data"),	
		
		"jobtype" => array("label" => "Job Type", "desc" => "", "values" => array("fulltime" => "Full-time", "parttime" => "Part-time",  "contract" => "Contract", "internship" => "Internship", "temporary" => "Temporary") ), 	
		
			"price" => array("label" => "Budget", "desc" => $CORE->_e(array('author','17'))  ),
			"pricetype" => array("label" => "Budget Type", "desc" => "", "values" => array("" => "", "1" => "Hourly Rate", "2" => "Budget",  "3" => "Fixed Salary (monthly)", "4" => "Fixed Salary (yearly)") ), 	
									
		); 	 
		
	return array_merge($c,$list1);
	}
	
	// SAVE JOB FUNCTIONALITY
	function jobs_savefunctions(){ global $post, $wpdb, $userdata, $CORE; 

	// DELETE CV FILE
	if(isset($_GET['del']) && $_GET['del'] == "cvfile"){
	
		$myresumeid = get_user_meta($userdata->ID,'myresumeid',true);
		if($myresumeid != ""){
			$mycv = get_post_meta($myresumeid,'cv',true);
			if(is_array($mycv) && !empty($mycv)){
				unset($mycv['file']);
				update_post_meta($myresumeid,'cv', '');
				$GLOBALS['error_message'] = $CORE->_e(array('author','27'));
			}		
		}
	}
	if( isset($_POST['jb_action']) ){
		switch($_POST['jb_action']){
		
			case "saveresume": {
			
				
				// CREATE A NEW RESUME PROFILE OR CHECK FOR AN EXISTING ID
				$myresumeid = get_user_meta($userdata->ID,'myresumeid',true);
				
				// CHECK EXISTS
				$check = get_post($myresumeid);
				if(!isset($check->post_title)){ $myresumeid = ""; }
				if($myresumeid == ""){
					$my_post = array();
					$my_post['post_title'] 		= "Resume User ".$userdata->ID;
					$my_post['post_content'] 	= "";
					$my_post['post_excerpt'] 	= "";
					$my_post['post_status'] 	= "publish";
					$my_post['post_type'] 		= "wlt_resume";
					$my_post['post_author'] 	= $userdata->ID;
					$myresumeid					= wp_insert_post( $my_post );
					update_user_meta($userdata->ID,'myresumeid', $myresumeid);
				}
				
				// UPDATE USER RESUME
				update_post_meta($myresumeid, 'resume0', strip_tags($_POST['resume0']));
				update_post_meta($myresumeid, 'resume1', strip_tags($_POST['resume1']));
				update_post_meta($myresumeid, 'resume2', strip_tags($_POST['resume2']));
				update_post_meta($myresumeid, 'resume3', strip_tags($_POST['resume3']));
				update_post_meta($myresumeid, 'resume4', strip_tags($_POST['resume4']));
				
				// UPDATE POST TITLE
				$title = get_the_author_meta( 'first_name', $userdata->ID)." ".get_the_author_meta( 'last_name', $userdata->ID);
				if($title == ""){ $title = "User Resume ".$userdata->ID; }
				$my_post = array();
				$my_post['ID'] 					= $myresumeid;
				$my_post['post_title']			= $title;
				wp_update_post( $my_post  );
				
				
				// NOW SAVE THE CV TO THE RESUME
				if($_FILES['mycsv']['type'] == "application/pdf"){
				
					// CHECK FOR EXISTING CSV
					$mycv = get_user_meta($userdata->ID,'mycv',true);
					if(is_array($mycv)){ 				
						// DELETE OLD CV FILE
						unset($mycv['file']);
					}
					// LOAD IN WORDPRESS FILE UPLOAOD CLASSES
					$dir_path = str_replace("wp-content","",WP_CONTENT_DIR);
					if(!function_exists('get_file_description')){
					require $dir_path . "/wp-load.php";
					require $dir_path . "/wp-admin/includes/file.php";
					require $dir_path . "/wp-admin/includes/media.php";	
					}
				
					// create an array of the $_FILES for each file
					$file_array = array(
						'name' 		=> $userdata->ID."_".$_FILES['mycsv']['name'],
						'type'		=> $_FILES['mycsv']['type'],
						'tmp_name'	=> $_FILES['mycsv']['tmp_name'],
						'error'		=> $_FILES['mycsv']['error'],
						'size'		=> $_FILES['mycsv']['size'],
					);
					
					// upload the file to the server
					$uploaded_file = wp_handle_upload( $file_array, array( 'test_form' => FALSE ) );
					$uploaded_file['name'] = $file_array['name'];
					
					// CHECK FOR ERRORS
					if(!isset($uploaded_file['error']) ){		
						//save cv to user account
						update_post_meta($myresumeid,'cv', $uploaded_file);
					}else{
					
					echo $uploaded_file['error'];
					}// end if			
					
				}// end if 
			
		 	$GLOBALS['error_message'] = "Resume Updated Successfully";	
				
			
			} break;
		
			case "jobform": {
			
			 	
				if(strlen($_POST['jobform']['email']) > 5){ 
				
				// BUILT EMAILS TRING			
				$STRING =  "<p>Name: ".esc_attr($_POST['jobform']['fname'])." ".esc_attr($_POST['jobform']['fname'])."</p>";
				$STRING .= "<p>Email: ".esc_attr($_POST['jobform']['email'])."</p>";
				$STRING .= "<p>Covering Message:<br> ".esc_attr($_POST['jobform']['msg'])."</p>";
				$STRING .= "<p>Ref:<br> ".get_permalink($_POST['jobform']['postid'])." (".$_POST['jobform']['postid'].")</p>";
				
				// UPLOAD CS ATTACHMENT
			 
				
				// NOW SAVE THE CV TO THE RESUME
				if($_FILES['mycsv']['type'] == "application/pdf"){
				
					// CHECK FOR EXISTING CSV
					$mycv = get_user_meta($userdata->ID,'mycv',true);
					if(is_array($mycv)){ 				
						// DELETE OLD CV FILE
						unset($mycv['file']);
					}
					// LOAD IN WORDPRESS FILE UPLOAOD CLASSES
					$dir_path = str_replace("wp-content","",WP_CONTENT_DIR);
					if(!function_exists('get_file_description')){
					require $dir_path . "/wp-load.php";
					require $dir_path . "/wp-admin/includes/file.php";
					require $dir_path . "/wp-admin/includes/media.php";	
					}
				
					// create an array of the $_FILES for each file
					$file_array = array(
						'name' 		=> $userdata->ID."_".$_FILES['mycsv']['name'],
						'type'		=> $_FILES['mycsv']['type'],
						'tmp_name'	=> $_FILES['mycsv']['tmp_name'],
						'error'		=> $_FILES['mycsv']['error'],
						'size'		=> $_FILES['mycsv']['size'],
					);
					
					// upload the file to the server
					$uploaded_file = wp_handle_upload( $file_array, array( 'test_form' => FALSE ) );
					$uploaded_file['name'] = $file_array['name'];
					 
					
					// CHECK FOR ERRORS
					if(!isset($uploaded_file['error']) ){		
						//save cv to user account
						update_post_meta($myresumeid,'cv', $uploaded_file);
						
						$STRING .= "Resume Link: ".$uploaded_file['url'];
					} 	
					
				}// end if
				
			 
				// SEND EMAIL					 	 					 
				$CORE->SENDEMAIL($post->post_author, "custom", "New Job Application", $STRING);
				
				$GLOBALS['error_message'] = "Job Application Sent Successfully";
				
				}else{
				
				$GLOBALS['error_message'] = "Please complete all the fields.";	
				
				}
			
			} break;
		
			 
	 
		}
	}
}



 


 


function jb_winner(){ global $post, $CORE, $userdata;
	// CHECK IF WE ARE THE BID WINNER
	if(!$userdata->ID){ return; }
	
	$winnerID = get_post_meta($post->ID,'bidwinner',true);
	// SHOW MESSAGE TO THE WINNER
	if($winnerID == $userdata->ID){
	$user_info = get_userdata($post->post_author);
	?>
    
    <div class="well">
    <h3><?php echo $CORE->_e(array('job','5')); ?></h3>
    <p><?php echo $CORE->_e(array('job','6')); ?></p>
    <hr />
    <p>
    <?php if($GLOBALS['CORE_THEME']['message_system'] == '1'){ ?>
    <a class="btn btn-warning" href="<?php echo $GLOBALS['CORE_THEME']['links']['myaccount']; ?>?tab=msg&show=1&u=<?php echo $user_info->user_login; ?>">Contact <?php echo $user_info->display_name; ?></a> <?php echo $CORE->_e(array('job','10')); ?> 
    <?php } ?>
    email: <a href="mailto:<?php echo $user_info->user_email; ?>"><?php echo $user_info->user_email; ?></a></p>
    </div>
	<?php
	}elseif(is_numeric($winnerID) && $winnerID != "" && $post->post_author == $userdata->ID){ 
	$pp = get_userdata( $winnerID );
	?>
    
    <div class="well">
    <h3><?php echo $CORE->_e(array('job','7')); ?></h3>
    <p><?php echo $CORE->_e(array('job','8')); ?> </p>
    <hr />
    <p>
     <?php if($GLOBALS['CORE_THEME']['message_system'] == '1'){ ?>
    <a class="btn btn-warning" href="<?php echo $GLOBALS['CORE_THEME']['links']['myaccount']; ?>?tab=msg&show=1&u=<?php echo $pp->user_login; ?>"><?php echo $CORE->_e(array('job','9')); ?></a> <?php echo $CORE->_e(array('job','10')); ?> 
    <?php } ?>
    email: <a href="mailto:<?php echo $pp->user_email; ?>"><?php echo $pp->user_email; ?></a></p>
    </div>	
	<?php }
	
	// end if
}






function add_new_emails(){ global $wpdb; $wlt_emails = get_option("wlt_emails"); $core_admin_values = get_option("core_admin_values");

  ?>
<hr />
<table class="table table-bordered table-striped">
            <thead>
              <tr>
                <th>Job Board Emails</th>
                <th></th>
              </tr>
            </thead>
            <tbody>
            
            <tr><td>
<span class="label label-inverse">New Proposal - sent to user</span>
<br> <a style="font-size:11px;" href="javascript:void(0);" onclick="alert('username = (username) \n link to post (link) ');return false;">[view  shortcodes]</a>
</td>
<td>
<select data-placeholder="Choose a an email..." class="chzn-select" name="admin_values[emails][jb_newproposal]">
   
    
	<?php 
	if(is_array($wlt_emails)){ 
		foreach($wlt_emails as $key=>$field){ 
			if(isset($core_admin_values['emails']) && $core_admin_values['emails']['jb_newproposal'] == $key){	$sel = " selected=selected ";	}else{ $sel = ""; }
			echo "<option value='".$key."' ".$sel.">".stripslashes($field['subject'])."</option>"; 
		} 
	} 
	?> 
    
     <option value="" <?php if($core_admin_values['emails']['jb_newproposal'] == ""){ echo " selected=selected "; } ?>>--- do not send --- </option>
</select> 
</td></tr> 

   
            <tr><td>
<span class="label label-inverse">New Proposal - sent to admin</span>
<br> <a style="font-size:11px;" href="javascript:void(0);" onclick="alert('username = (username) \n link to post (link) ');return false;">[view  shortcodes]</a>
</td>
<td>
<select data-placeholder="Choose a an email..." class="chzn-select" name="admin_values[emails][jb_newproposal_admin]">
   
    
	<?php 
	if(is_array($wlt_emails)){ 
		foreach($wlt_emails as $key=>$field){ 
			if(isset($core_admin_values['emails']) && $core_admin_values['emails']['jb_newproposal_admin'] == $key){	$sel = " selected=selected ";	}else{ $sel = ""; }
			echo "<option value='".$key."' ".$sel.">".stripslashes($field['subject'])."</option>"; 
		} 
	} 
	?> 
    
     <option value="" <?php if($core_admin_values['emails']['jb_newproposal_admin'] == ""){ echo " selected=selected "; } ?>>--- do not send --- </option>
</select> 
</td></tr> 


<!------------ END FIELD -------------->  
  </tbody> </table>
<?php }



 
}

?>