<?php
/**
* The template for displaying Archive pages.
*
* THIS IS THE ONE THAT SHOWS FOR JOBS AND OPPORTUNITIES
*
* Used to display archive-type pages if nothing more specific matches a query.
* For example, puts together date-based pages if no date.php file exists.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Starkers
* @since Starkers 3.0
*/
?>
<?php
function buildTaxonomyTermOrSQL($checkBoxName, $tM) {
if (is_array($_POST[$checkBoxName])) {
foreach ($_POST[$checkBoxName] as $interest) {
$terms .= " " . $tM . ".slug = '" . $interest . "' OR ";
}
} else {
$terms = "";
}
return $terms;
}
function taxTerm($checkBoxName,$alias){
$tM = 'wp_z4azbl_terms';
$string = " $alias.term_id IN (SELECT term_id FROM wp_z4azbl_terms WHERE ";
if(is_array($_POST[$checkBoxName])){
foreach($_POST[$checkBoxName] as $slug){
$string .= "slug = " . "'" . $slug . "' OR ";
}
$string = substr($string, 0, -3);
}
$string .= ") AND ";
$empty = " $alias.term_id IN (SELECT term_id FROM wp_z4azbl_terms WHERE ) AND ";
if($string == $empty){
$string = "";
}
return $string;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_POST["searchingJobs"])) {
//Build job search query
$termsName = $wpdb->terms;
///////////////
// All Terms
///////////////
$terms = "(" . buildTaxonomyTermOrSQL("interest", $termsName) . buildTaxonomyTermOrSQL("job-type", $termsName) . buildTaxonomyTermOrSQL("experience", $termsName);
if (substr($terms, -3) == "OR ") {
$terms = substr($terms, 0, -3);
}
$terms .= ") AND";
$interests = taxTerm("interest",'wp1');
$type = taxTerm("job-type",'wp2');
$experience = taxTerm("experience",'wp3');
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
$qry = "SELECT * FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT JOIN $wpdb->terms ON($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id)
LEFT JOIN $wpdb->terms wp1 ON(wp1.term_id = $wpdb->term_taxonomy.term_id)
LEFT JOIN $wpdb->terms wp2 ON(wp2.term_id = $wpdb->term_taxonomy.term_id)
LEFT JOIN $wpdb->terms wp3 ON(wp3.term_id = $wpdb->term_taxonomy.term_id)";
if (($_POST["job_latitude"] != "") && ($_POST["radius"] != "X") ) {
//add location joins
$qry .= "LEFT JOIN $wpdb->postmeta AS latitude ON(
$wpdb->posts.ID = latitude.post_id
AND latitude.meta_key = 'latitude'
)";
$qry .= "LEFT JOIN $wpdb->postmeta AS longitude ON(
$wpdb->posts.ID = longitude.post_id
AND longitude.meta_key = 'longitude'
)";
$qry .= "LEFT JOIN $wpdb->postmeta AS location ON(
$wpdb->posts.ID = location.post_id
AND location.meta_key = 'location'
)";
}
//$qry .= " WHERE " . $terms;
if ($terms != "() AND") {
$qry .= " WHERE $terms $wpdb->term_taxonomy.taxonomy = 'jobtype' AND";
} else {
$qry .= " WHERE $wpdb->term_taxonomy.taxonomy = 'jobtype' AND ";
}
// $combined = "";
// $combined .= $interests . $type . $experience;
// $combined = substr($combined, 0, -4);
// $combined .= " AND";
// if($combined != " AND"){
// $qry .= " WHERE $combined $wpdb->term_taxonomy.taxonomy = 'jobtype' AND ";
// } else{
// $qry .= " WHERE $wpdb->term_taxonomy.taxonomy = 'jobtype' AND ";
// }
// if($interests == "" && $type == "" && $experience == ""){
// $qry .= " WHERE $wpdb->term_taxonomy.taxonomy = 'jobtype' AND ";
// } else {
// $qry .= " WHERE $interests $type $experience $wpdb->term_taxonomy.taxonomy = 'jobtype' AND ";
// }
$qry .= "
$wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'jobs'
";
//Now check for location fields
if (($_POST["job_latitude"] != "") && ($_POST["radius"] != "X") ) {
$radius = $_POST["radius"];
$qry .= " AND ( 3959 * acos( cos( radians(" . $_POST["job_latitude"] . ") ) * cos( radians( latitude.meta_value ) ) * cos( radians( longitude.meta_value ) - radians(" . $_POST["job_longitude"] . ") ) + sin( radians(" . $_POST["job_latitude"] . ") ) * sin( radians( latitude.meta_value ) ) ) ) < " . $_POST["radius"];
$qry .= " OR location.meta_value = 'Virtual Office'";
}
$qry .= " GROUP BY $wpdb->posts.ID ORDER BY $wpdb->posts.post_date DESC";
//echo $qry;
$jobResults = $wpdb->get_results($qry);
?>
<?php foreach ($jobResults as $post): ?>
<?php setup_postdata($post); ?>
<div class="post_entry">
<?php //echo $interests . $type . $experience; ?>
<h4 class="post-title"><a class="title-anchor" href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( '%s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h4>
<?php
$location = get_post_meta($post->ID, 'location', TRUE);
$organization = get_post_meta($post->ID, 'organization', TRUE);
$url = get_post_meta($post->ID, 'url', TRUE);
$matches = substr($url, 0, 7);
if ($matches=='http://')
{
$url = substr($url, 7);
}
else
{
$matches = substr($url, 0, 8);
if ($matches=='https://')
$url = substr($url, 8);
}
?>
<p class="post_meta_date">Posted: <?php echo get_the_date(); ?></p>
<div class="post-meta">
<?php if($organization != ''){ ?><p class="post_meta_organization"><?php echo $organization; ?></p><?php } ?>
<?php if($location != ''){ ?><p class="post_meta_location"><?php echo $location; ?></p><?php } ?>
<!-- <?php if($url != ''){ ?><p class="post_meta_url">Website: <a href="http://<?php echo $url; ?>" target="_blank">Click Here</a></p><?php } ?> -->
<p class="post_meta_url"><?php $sideterms = wp_get_post_terms($post->ID,'jobtype');
$showterms = array();
foreach($sideterms as $term){
if(($term->slug) == 'full-time' || ($term->slug) == 'internship' || ($term->slug) == 'part-time' || ($term->slug) == 'temporarycontract'){
$showterms[] = $term->name;
}
}
echo implode(', ', $showterms);
?></p>
</div>
<div class="hidden tags<?php $terms = wp_get_post_terms($post->ID,'jobtype'); foreach($terms as $term){echo ' ' . $term->slug;} ?><?php $terms = wp_get_post_terms($post->ID,'opportunitytype'); foreach($terms as $term){echo ' ' . $term->slug;} ?>"></div>
<?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
<p class="post_excerpt"><?php the_excerpt(); ?><p class="post_categories"><?php
$terms = wp_get_post_terms($post->ID,'jobtype');
$names = array();
foreach($terms as $term){
if(($term->slug) == 'full-time' || ($term->slug) == 'internship' || ($term->slug) == 'part-time' || ($term->slug) == 'temporarycontract'){
}else{ $names[] = $term->name; }
}
echo implode(', ', $names);
?><?php $terms = wp_get_post_terms($post->ID,'opportunitytype'); foreach($terms as $term){echo ', ' . $term->name;} ?>.</p></p>
<?php else : ?>
<div class="category_read_more"><?php the_content( __( 'Read More', 'twentyten' ) ); ?></div>
<?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'twentyten' ), 'after' => '' ) ); ?>
<?php endif; ?>
<?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>
<?php comments_template( '', true ); ?>
</div>
<?php endforeach; ?>
<?php
} else {
get_header(); ?>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('#') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
</script>
<script type="text/javascript">
var geocoder;
function initialize() {
geocoder = new google.maps.Geocoder();
}
initialize();
$(document).ready(function() {
searchJobs();
});
function initialize() {
geocoder = new google.maps.Geocoder();
}
function codeAddress() {
var address = document.getElementById("zip").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
$("#lat")[0].value = results[0].geometry.location.lat();
$("#lng")[0].value = results[0].geometry.location.lng();
loadJobs();
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function searchJobs() {
//set url query
var interests = new Array();
$("input[name='interest[]']").each(function(){
if($(this).prop('checked')){
interests.push($(this).val());
}
});
var types = new Array();
$("input[name='job-type[]']").each(function(){
if($(this).prop('checked')){
types.push($(this).val());
}
});
var experience = new Array();
$("input[name='experience[]']").each(function(){
if($(this).prop('checked')){
experience.push($(this).val());
}
});
var interestsstring = '', typestring = '', experiencestring = '';
if(interests.join("+") != ''){
interestsstring = "interests=" + interests.join("+");
}
if(types.join("+") != ''){
if(interestsstring == ''){
typestring = "type=" + types.join("+");
}else{
typestring = "&type=" + types.join("+");
}
}
if(experience.join("+") != ''){
if(interestsstring == '' && typestring == ''){
experiencestring = "experience=" + experience.join("+");
}else{
experiencestring = "&experience=" + experience.join("+");
}
}
var querystring = interestsstring + typestring + experiencestring;
window.location.hash = querystring;
//slide up the div
$("#jobListings").slideUp('fast', function() {
//geocoding
if ($("#zip")[0].value != "" && $("#zip")[0].value != "City, State, Zip, or Address") {
codeAddress();
} else {
$(".loader").slideDown('fast');
loadJobs();
}
});
return false;
}
function loadJobs() {
dataString = $("#category_fieldset_jobs").serialize();
$.post(window.location, $("#category_fieldset_jobs").serialize(), function(data) {
$("#jobListings").html(data);
$(".loader").slideUp();
$("#jobListings").slideDown();
document.getElementById('zip').value == 'City, State, Zip, or Address';
$("#lat")[0].value = "";
$("#lng")[0].value = "";
wrapEntries();
});
}
function wrapEntries() {
$('.post_entry').each(function(){
var anchor;
anchor = $(this).find('.title-anchor').attr('href');
$(this).wrap('<a href=\"' + anchor + '\"></a>');
});
}
</script>
<div id="page" class="job">
<div id="category_filter">
<form id="category_fieldset_jobs" method="POST" action="" onsubmit="return searchJobs()">
<div id="filter_left" class="category_filter_content">
<h2>Interests</h2>
<input class="filterbox" type="checkbox" name="interest[]" value="academia" />Academia<br />
<input class="filterbox" type="checkbox" name="interest[]" value="adminassistant" />Admin/Assistant<br />
<input class="filterbox" type="checkbox" name="interest[]" value="communicationsmarketing" />Communications/Marketing<br />
<input class="filterbox" type="checkbox" name="interest[]" value="development" />Development<br />
<input class="filterbox" type="checkbox" name="interest[]" value="filmvideo-production" />Film/Video Production<br />
<input class="filterbox" type="checkbox" name="interest[]" value="journalism" />Journalism<br />
<input class="filterbox" type="checkbox" name="interest[]" value="law" />Law<br/>
<input class="filterbox" type="checkbox" name="interest[]" value="adminmanagement" />Management<br />
<input class="filterbox" type="checkbox" name="interest[]" value="policy" />Policy<br />
<input class="filterbox" type="checkbox" name="interest[]" value="web-developmentit" />Web Development/IT<br />
<input class="filterbox" type="checkbox" name="interest[]" value="other" />Other
</div>
<div id="filter_middle" class="category_filter_content">
<h2>Location</h2>
Within <select name="radius">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="X">Unlimited</option>
</select> miles of<br/>
<input type="text" id="zip" name="zip" onfocus="if(this.value == 'City, State, Zip, or Address') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'City, State, Zip, or Address'; }" value="City, State, Zip, or Address" />
<h2>Job Type</h2>
<input class="filterbox" type="checkbox" name="job-type[]" value="full-time" />Full-Time<br />
<input class="filterbox" type="checkbox" name="job-type[]" value="part-time" />Part-Time<br />
<input class="filterbox" type="checkbox" name="job-type[]" value="temporarycontract" />Temporary/Contract<br/>
<input class="filterbox" type="checkbox" name="job-type[]" value="internship" />Internship<br/>
</div>
<div id="filter_right" class="category_filter_content">
<h2>Experience</h2>
<input class="filterbox" type="checkbox" name="experience[]" value="early-career" />Early-Career<br />
<input class="filterbox" type="checkbox" name="experience[]" value="mid-career" />Mid-Career<br />
<input class="filterbox" type="checkbox" name="experience[] " value="advanced" />Late-Career<br/>
<input id="filter_submit" type="button" value="FIND" onclick="searchJobs()" />
</div>
<div class="clear"></div>
<input type="hidden" name="searchingJobs" value="Y" />
<input type="hidden" id="lat" name="job_latitude" value="" />
<input type="hidden" id="lng" name="job_longitude" value="" />
</form>
</div>
<h1 class="category_head"><img src="<?php bloginfo('template_url') ?>/images/job_icon_small.png" class="header_icon_small" /><p><?php echo post_type_archive_title(); ?></p><a href="<?php bloginfo('url'); ?>/submit-job" class="posting">Post a Job</a></h1>
<div class="loader"></div>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '' . $category_description . '';
/* Run the loop for the category page to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-category.php and that will be used instead.
*/
if (get_post_type() == 'jobs') {
?>
<div id="jobListings">
</div>
<?php
} else {
get_template_part( 'loop', 'category' );
}
?>
<?php get_sidebar(); ?>
</div>
<script type="text/javascript">
var querystring = getUrlVars();
if(querystring['interests'] != undefined){ var interests = querystring['interests'].split('+'); }
if(querystring['type'] != undefined){ var type = querystring['type'].split('+'); }
if(querystring['experience'] != undefined){ var experience = querystring['experience'].split('+'); }
if(interests != undefined){
$("input[name='interest[]']").each(function(){
for (var i = 0; i < interests.length; i++){
if(interests[i] == $(this).val()){
$(this).prop('checked',true);
}
}
});
}
if(type != undefined){
$("input[name='job-type[]']").each(function(){
for (var i = 0; i < type.length; i++){
if(type[i] == $(this).val()){
$(this).prop('checked',true);
}
}
});
}
if(experience != undefined){
$("input[name='experience[]']").each(function(){
for (var i = 0; i < experience.length; i++){
if(experience[i] == $(this).val()){
$(this).prop('checked',true);
}
}
});
}
</script>
<?php
get_footer();
}
?>