<?php
/**
 * The template for displaying Archive pages.
 *
 * 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 ChurchThemes
 *
 ===================================================================================================
 WARNING! DO NOT EDIT THIS FILE OR ANY TEMPLATE FILES IN THIS THEME!

 To make it easy to update your theme, you should not edit this file. Instead, you should create a
 Child Theme first. This will ensure your template changes are not lost when updating the theme.

 You can learn more about creating Child Themes here: http://codex.wordpress.org/Child_Themes

 You have been warned! :)
 ===================================================================================================
 */

$term =	$wp_query->get_queried_object();

$post_type = ( isset( $_GET['post_type'] ) ) ? $_GET['post_type'] : null;
$current_speaker = get_query_var('sermon_speaker');
$speaker_terms = get_terms('sermon_speaker');
$current_series = get_query_var('sermon_series');
$series_terms = get_terms('sermon_series');
$current_service = get_query_var('sermon_service');
$service_terms = get_terms('sermon_service');
$current_topic = get_query_var('sermon_topic');
$topic_terms = get_terms('sermon_topic');

$sermon_settings = get_option('ct_sermon_settings');
isset($sermon_settings['archive_filter_1']) ? $ct_sermon_filters_speaker = $sermon_settings['archive_filter_1'] : $ct_sermon_filters_speaker = null;
isset($sermon_settings['archive_filter_2']) ? $ct_sermon_filters_series = $sermon_settings['archive_filter_2'] : $ct_sermon_filters_series = null;
isset($sermon_settings['archive_filter_3']) ? $ct_sermon_filters_service = $sermon_settings['archive_filter_3'] : $ct_sermon_filters_service = null;
isset($sermon_settings['archive_filter_4']) ? $ct_sermon_filters_topic = $sermon_settings['archive_filter_4'] : $ct_sermon_filters_topic = null;
isset($sermon_settings['archive_filter_5']) ? $ct_sermon_filters_keyword = $sermon_settings['archive_filter_5'] : $ct_sermon_filters_keyword = null;
$ct_sermon_filters_button_text = $sermon_settings['archive_filters_button_text'];
if(empty($ct_sermon_filters_button_text)) $ct_sermon_filters_button_text = __('Search Sermons', 'churchthemes');
$ct_sermon_archive_title = $sermon_settings['archive_title'];
if(empty($ct_sermon_archive_title)) $ct_sermon_archive_title = __('Sermon Archives', 'churchthemes');
$ct_sermon_archive_slug = $sermon_settings['archive_slug'];
if(empty($ct_sermon_archive_slug)) $ct_sermon_archive_slug = 'sermons';
$ct_sermon_archive_tagline = $sermon_settings['archive_tagline'];
$ct_sermon_archive_layout = $sermon_settings['archive_layout'];

$post_settings = get_option('ct_post_settings');
$ct_post_archive_title = $post_settings['archive_title'];
if(empty($ct_post_archive_title)) $ct_post_archive_title = __('Post Archives', 'churchthemes');
$ct_post_archive_layout = $post_settings['archive_layout'];

$location_settings = get_option('ct_location_settings');
$ct_location_archive_title = $location_settings['archive_title'];
if(empty($ct_location_archive_title)) $ct_location_archive_title = __('Location Archives', 'churchthemes');
$ct_location_archive_tagline = $location_settings['archive_tagline'];
$ct_location_archive_layout = $location_settings['archive_layout'];

$person_settings = get_option('ct_person_settings');
$ct_person_archive_title = $person_settings['archive_title'];
if(empty($ct_person_archive_title)) $ct_person_archive_title = __('People Archives', 'churchthemes');
$ct_person_archive_tagline = $person_settings['archive_tagline'];
$ct_person_archive_layout = $person_settings['archive_layout'];

$search_query = get_search_query();

get_header();

?>
		<div id="ribbon" class="page">
			<div class="container_12 grid-container content">
				<div class="ribbon-wrapper">
					<div class="grid_6 grid-50 alpha">
						<h1>
<?php if(is_day()): ?>
					<?php printf( __('Daily Archives', 'churchthemes'), get_the_date()); ?>
<?php elseif(is_month()): ?>
					<?php printf( __('Monthly Archives', 'churchthemes'), get_the_date('F Y')); ?>
<?php elseif(is_year()): ?>
					<?php printf( __('Yearly Archives', 'churchthemes'), get_the_date('Y')); ?>
<?php elseif(is_post_type_archive('ct_sermon') || $post_type == 'ct_sermon' || is_tax('sermon_speaker') || is_tax('sermon_series') || is_tax('sermon_service') || is_tax('sermon_topic')): ?>
					<?php echo $ct_sermon_archive_title; ?>
<?php elseif(is_post_type_archive('ct_location') || is_tax('location_tag')): ?>
					<?php echo $ct_location_archive_title; ?>
<?php elseif(is_post_type_archive('ct_person') || is_tax('person_category') || is_tax('person_tag')): ?>
					<?php echo $ct_person_archive_title; ?>
<?php else: ?>
					<?php echo $ct_post_archive_title; ?>
<?php endif; ?>
						</h1>
					</div>
					<div class="grid_6 grid-50 omega">
						<span class="tagline">
							<?php if(is_day()): echo get_the_date(); endif; ?>
							<?php if(is_month()): echo get_the_date('F Y'); endif; ?>
							<?php if(is_year()): echo get_the_date('Y'); endif; ?>
							<?php if(is_category() || is_tag()): echo $term->name; endif; ?>
							<?php if(is_author()): echo $term->display_name; endif; ?>
							<?php if(is_post_type_archive('ct_sermon')): echo $ct_sermon_archive_tagline; endif; ?>
							<?php foreach ($speaker_terms as $term) { if($current_speaker == $term->slug) { echo $term->name; } } ?>
							<?php if($current_speaker && $current_series) { echo ' + '; } ?>
							<?php foreach ($series_terms as $term) { if($current_series == $term->slug) { echo $term->name; } } ?>
							<?php if(($current_speaker || $current_series) && $current_service) { echo ' + '; } ?>
							<?php foreach ($service_terms as $term) { if($current_service == $term->slug) { echo $term->name; } } ?>
							<?php if(($current_speaker || $current_series || $current_service) && $current_topic) { echo ' + '; } ?>
							<?php foreach ($topic_terms as $term) { if($current_topic == $term->slug) { echo $term->name; } } ?>
							<?php if(($current_speaker || $current_series || $current_service || $current_topic) && $search_query) { echo ' + '; } ?>
							<?php if($search_query && ($post_type == 'ct_sermon' || $current_speaker || $current_series || $current_service || $current_topic)): echo '&quot;'.$search_query.'&quot;'; endif; ?>
							<?php if(is_post_type_archive('ct_location')): echo $ct_location_archive_tagline; endif; ?>
							<?php if(is_post_type_archive('ct_person')): echo $ct_person_archive_tagline; endif; ?>
						</span>
					</div>
				</div>
			</div>
		</div>
		<div id="wrapper3" class="container_12 grid-container">
<?php
	if(
		((is_day() || is_month() || is_year() || is_post_type_archive('post') || is_tag() || is_category() || is_author()) && $ct_post_archive_layout == 'left') ||
		((is_post_type_archive('ct_sermon') || $post_type == 'ct_sermon' || is_tax('sermon_speaker') || is_tax('sermon_series') || is_tax('sermon_service') || is_tax('sermon_topic')) && $ct_sermon_archive_layout == 'left') ||
		((is_post_type_archive('ct_location') || is_tax('location_tag')) && $ct_location_archive_layout == 'left') ||
		((is_post_type_archive('ct_person') || is_tax('person_tag') || is_tax('person_category')) && $ct_person_archive_layout == 'left')
	):
		get_sidebar();
?>
			<div id="content" class="grid_8 grid-66 omega">
<?php
	elseif(
		((is_day() || is_month() || is_year() || is_post_type_archive('post') || is_tag() || is_category() || is_author()) && $ct_post_archive_layout == 'full') ||
		((is_post_type_archive('ct_sermon') || $post_type == 'ct_sermon' || is_tax('sermon_speaker') || is_tax('sermon_series') || is_tax('sermon_service') || is_tax('sermon_topic')) && $ct_sermon_archive_layout == 'full') ||
		((is_post_type_archive('ct_location') || is_tax('location_tag')) && $ct_location_archive_layout == 'full') ||
		((is_post_type_archive('ct_person') || is_tax('person_tag') || is_tax('person_category')) && $ct_person_archive_layout == 'full')
	):
?>
			<div id="content" class="grid_12 grid-100 alpha">
<?php
	else:
?>
			<div id="content" class="grid_8 grid-66 alpha">
<?php
	endif;
?>
<?php
if(is_day() || is_month() || is_year() || is_post_type_archive('post') || is_tag() || is_category() || is_author()):

	get_template_part('loop');

endif;

if(is_post_type_archive('ct_sermon') || $post_type == 'ct_sermon' || is_tax('sermon_speaker') || is_tax('sermon_series') || is_tax('sermon_service') || is_tax('sermon_topic')):

?>
<?php if($ct_sermon_filters_speaker || $ct_sermon_filters_series || $ct_sermon_filters_service || $ct_sermon_filters_topic || $ct_sermon_filters_keyword): ?>
				<form method="get" id="sermon-filter" action="<?php echo home_url('/'); ?><?php echo $ct_sermon_archive_slug; ?>">
					<div id="sermon_filter">
<?php if($ct_sermon_filters_speaker): ?>
						<div>
							<select name="sermon_speaker" id="sermon_speaker" style="display:none;">
								<option value=""><?php _e('Any Speaker', 'churchthemes'); ?></option>
								<?php dropdown_taxonomy_term('sermon_speaker'); ?>
							</select>
						</div>
<?php endif; ?>
<?php if($ct_sermon_filters_series): ?>
						<div>
							<select name="sermon_series" id="sermon_series" style="display:none;">
								<option value=""><?php _e('Any Series', 'churchthemes'); ?></option>
								<?php dropdown_taxonomy_term('sermon_series'); ?>
							</select>
						</div>
<?php endif; ?>
<?php if($ct_sermon_filters_service): ?>
						<div>
							<select name="sermon_service" id="sermon_service" style="display:none;">
								<option value=""><?php _e('Any Service', 'churchthemes'); ?></option>
								<?php dropdown_taxonomy_term('sermon_service'); ?>
							</select>
						</div>
<?php endif; ?>
<?php if($ct_sermon_filters_topic): ?>
						<div>
							<select name="sermon_topic" id="sermon_topic" style="display:none;">
								<option value=""><?php _e('Any Topic', 'churchthemes'); ?></option>
								<?php dropdown_taxonomy_term('sermon_topic'); ?>
							</select>
						</div>
<?php endif; ?>
<?php if($ct_sermon_filters_keyword): ?>
						<div>
							<input type="hidden" name="post_type" value="sermon" />
							<input type="text" name="s" size="20" placeholder="Search terms" value="<?php echo $s; ?>" class="sermon_keywords" />
						</div>
<?php endif; ?>
						<input type="submit" name="submit" class="button" value="<?php echo $ct_sermon_filters_button_text; ?>" />
					</div>
				</form>
<?php endif; ?>
<?php
	get_template_part('loop','ct_sermon');

endif;

if(is_post_type_archive('ct_location') || is_tax('location_tag')):

	get_template_part('loop','ct_location');

endif;

if(is_post_type_archive('ct_person') || is_tax('person_category') || is_tax('person_tag')):

	get_template_part('loop','ct_person');

endif;

?>
			</div>
<?php
	if(
		((is_day() || is_month() || is_year() || is_post_type_archive('post') || is_tag() || is_category() || is_author()) && ($ct_post_archive_layout == 'right' || empty($ct_post_archive_layout))) ||
		((is_post_type_archive('ct_sermon') || $post_type == 'ct_sermon' || is_tax('sermon_speaker') || is_tax('sermon_series') || is_tax('sermon_service') || is_tax('sermon_topic')) && ($ct_sermon_archive_layout == 'right' || empty($ct_sermon_archive_layout))) ||
		((is_post_type_archive('ct_location') || is_tax('location_tag')) && ($ct_location_archive_layout == 'right' || empty($ct_location_archive_layout))) ||
		((is_post_type_archive('ct_person') || is_tax('person_tag') || is_tax('person_category')) && ($ct_person_archive_layout == 'right' || empty($ct_person_archive_layout)))
	):
		get_sidebar();
	endif;
?>
		</div>
<?php get_footer(); ?>