function process_session($session_slug)
{
    global $TRACE_ENABLED;
    $pod = new Pod('event_session', $session_slug);
    $session_youtube_video = $pod->get_field('media_items.youtube_uri');
    $session_media_item_title = $pod->get_field('media_items.name');
    $subsessions = $pod->get_field('sessions.slug');
    if ($subsessions and count($subsessions) == 1) {
        $subsessions = array(0 => $subsessions);
    }
    if ($session_youtube_video and $session_media_item_title) {
        echo "{$session_youtube_video}|{$session_media_item_title}\n";
    }
    if ($subsessions) {
        foreach ($subsessions as $session) {
            process_session($session);
        }
    }
}
function process_session($session_slug)
{
    global $TRACE_PODS_EVENT_PROGRAMME;
    $ALLOWED_TAGS_IN_BLURBS = '<strong><em>';
    $pod = new Pod('event_session', $session_slug);
    $session_id = $pod->get_field('slug');
    $session_title = $pod->get_field('name');
    $session_subtitle = $pod->get_field('session_subtitle');
    $show_times = $pod->get_field('show_times');
    $session_start = new DateTime($pod->get_field('start'));
    $session_start = $session_start->format('H:i');
    $session_end = new DateTime($pod->get_field('end'));
    $session_end = $pod->get_field('end') == '0000-00-00 00:00:00' ? null : $session_end->format('H:i');
    if ($pod->get_field('show_times')) {
        $session_times = is_null($session_end) ? "{$session_start}&#160;&#160;&#160;" : "{$session_start} &#8212; {$session_end}&#160;&#160;&#160;";
    }
    $hide_title = $pod->get_field('hide_title');
    $session_type = $pod->get_field('session_type.slug');
    if ($session_type != 'session') {
        $session_type = "session {$session_type}";
    }
    $session_speakers = $pod->get_field('speakers');
    $session_speakers_blurb = strip_tags($pod->get_field('speakers_blurb'), $ALLOWED_TAGS_IN_BLURBS);
    $session_chairs = $pod->get_field('chairs');
    $session_chairs_blurb = strip_tags($pod->get_field('chairs_blurb'), $ALLOWED_TAGS_IN_BLURBS);
    $session_respondents = $pod->get_field('respondents');
    $session_respondents_blurb = strip_tags($pod->get_field('respondents_blurb'), $ALLOWED_TAGS_IN_BLURBS);
    $session_youtube_video = $pod->get_field('media_items.youtube_uri');
    $session_slides = $pod->get_field('media_items.slides_uri');
    $subsessions = $pod->get_field('sessions.slug');
    if ($subsessions and count($subsessions) == 1) {
        $subsessions = array(0 => $subsessions);
    }
    if ($TRACE_PODS_EVENT_PROGRAMME) {
        error_log($TRACE_PREFIX . 'session count: ' . count($subsessions));
    }
    if ($TRACE_PODS_EVENT_PROGRAMME) {
        error_log($TRACE_PREFIX . 'sessions: ' . var_export($subsessions, true));
    }
    echo "<div id='{$session_id}' class='{$session_type}'>";
    if ($session_title and !$hide_title) {
        echo '<h2>' . $session_times . $session_title . '</h2>';
    }
    if ($session_subtitle and !$hide_title) {
        echo "<h3>{$session_subtitle}</h3>";
    }
    if ($session_chairs) {
        $caption = count($session_chairs) > 1 ? "Chairs" : "Chair";
        echo "<dl class='session-chairs'><dt>{$caption}: </dt><dd>{$session_chairs_blurb}</dd></dl>";
    }
    if ($session_speakers) {
        echo "<div>{$session_speakers_blurb}</div>";
    }
    if ($session_youtube_video or $session_slides) {
        echo '<ul class="mediaitems">';
        if ($session_youtube_video) {
            echo "<li class='link video'><a href='http://youtube.com/watch?v={$session_youtube_video}'>Watch video</a></li>";
        }
        if ($session_slides) {
            echo "<li class='link slides'><a href='http://downloads0.cloud.lsecities.net/{$session_slides}'>Browse slides</a></li>";
        }
        echo '</ul>';
    }
    if ($subsessions) {
        foreach ($subsessions as $session) {
            process_session($session);
        }
    }
    echo "</div>";
}