<?php
/*
Template Name: Conference-Papers-Archive
*/
global $post;
// Get list of people-to-authors
$people = thinkplace::getPeopleAuthors();

$metadata		= get_post_custom($post->ID);
$extraBodyClass	= get_the_title($post->post_parent);
$people				= thinkplace::getPeopleList();
$ancestorPostId	= $post->ID;
$selectedPaperId	= (isset($_REQUEST['paper_id']))	? $_REQUEST['paper_id']	: 0;
if (! empty($post->ancestors)){
	$ancestorPostId	= $post->ancestors[ count($post->ancestors) -1];
}
get_header();
?>
		<div id="content" role="main">
  			<?php
                  $breadcrumb = '<span class="active">'.get_the_title().'</span>';
                  foreach ($post->ancestors as $bc_ancestor_id){
                      $breadcrumb	= '<a href="'.htmlentities(get_page_link( $bc_ancestor_id )).'">'.get_the_title($bc_ancestor_id).'</a> &gt; '.$breadcrumb;
                  }
                  $breadcrumb	= '<a href="'.home_url( '/' ).'">Home</a> &gt; '.$breadcrumb;
                  echo '<div class="breadcrumbs">'.$breadcrumb.'</div>';
              ?>
  			<?php edit_post_link( __( 'Edit', 'thinkplace' ), '<span class="edit-link">', '</span>' ); ?>
		  
<?php
// If a person has been selected...
if (! empty($selectedPaperId)){
	$args	= array(
				'numberposts'	=> 1,
				'post_type' 	=> 'papers',
				'p'				=> $selectedPaperId
				);
	$papersQuery = new WP_Query($args);			
?>
    <?php if ( $papersQuery->have_posts() ) while ( $papersQuery->have_posts() ) : $papersQuery->the_post(); ?>
  				  <div class="general-content">
                    <?php $paperMetadata	= get_post_custom(get_the_ID()); ?>
            <h2>
              <?php the_title();?>
            </h2>
            <?php $paperMetadata	= get_post_custom(get_the_ID()); ?>
            <p>
              <?php
              $presenter = $people[$paperMetadata[thinkplace::$prefix.'presenter'][0]];
              if(isset($presenter)) echo '<a href="'.get_bloginfo('url').'/about/the-team/?person_id='.$paperMetadata[thinkplace::$prefix.'presenter'][0].'">'.$presenter->post_title . '</a>,'; ?>
              <?php if(isset($paperMetadata[thinkplace::$prefix.'display_date'][0])) echo $paperMetadata[thinkplace::$prefix.'display_date'][0] . ','; ?>
              <?php if(isset($paperMetadata[thinkplace::$prefix.'conference'][0])) echo $paperMetadata[thinkplace::$prefix.'conference'][0] . ','; ?>
              <?php if(isset($paperMetadata[thinkplace::$prefix.'organisation'][0])) echo $paperMetadata[thinkplace::$prefix.'organisation'][0] . ','; ?>
              <?php if(isset($paperMetadata[thinkplace::$prefix.'location'][0])) echo $paperMetadata[thinkplace::$prefix.'location'][0]; ?>
            </p>
			          <?php the_content(); ?>
          <?php endwhile; ?>
<?php } else { ?>
		  
            <div id="archive">
                <h1>Papers and Presentations</h1>
                <?php if (have_posts()) : ?>
                    <?php $args	= array(
                      'numberposts'	=> 1,
                      'post_type' 	=> 'papers',
                      // 'p'        => $selectedPersonId
                    );
                    $papersQuery = new WP_Query($args);
                    ?>
                    <?php while ($papersQuery->have_posts()) : $papersQuery->the_post(); ?>
                      <?php $paperMetadata	= get_post_custom(get_the_ID()); ?>
                        <div>
                            <h2><a href="<?php echo get_bloginfo('url') . '/ideas/papers-and-presentations/?paper_id='.get_the_ID(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                            <p>
                              <?php
                              $presenter = $people[$paperMetadata[thinkplace::$prefix.'presenter'][0]];
                              if(isset($presenter)) echo '<a href="'.get_bloginfo('url').'/about/the-team/?person_id='.$paperMetadata[thinkplace::$prefix.'presenter'][0].'">'.$presenter->post_title . '</a>,'; ?>
                              <?php if(isset($paperMetadata[thinkplace::$prefix.'display_date'][0])) echo $paperMetadata[thinkplace::$prefix.'display_date'][0] . ','; ?>
                              <?php if(isset($paperMetadata[thinkplace::$prefix.'conference'][0])) echo $paperMetadata[thinkplace::$prefix.'conference'][0] . ','; ?>
                              <?php if(isset($paperMetadata[thinkplace::$prefix.'organisation'][0])) echo $paperMetadata[thinkplace::$prefix.'organisation'][0] . ','; ?>
                              <?php if(isset($paperMetadata[thinkplace::$prefix.'location'][0])) echo $paperMetadata[thinkplace::$prefix.'location'][0]; ?>
                            </p>
                        </div>
                    <?php endwhile; ?>    
                  <?php endif; ?>
              <?php } ?>
        	</div>
		</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>