<?php
/**
 * Show the current lineup for a specific channel
 *
 * @url         $URL: http://svn.mythtv.org/svn/branches/release-0-21-fixes/mythplugins/mythweb/modules/tv/tmpl/default/channel.php $
 * @date        $Date: 2008/10/16 05:36:27 $
 * @version     $Revision: 1.1 $
 * @author      $Author: grog $
 * @license     GPL
 *
 * @package     MythWeb
 * @subpackage  TV
 *
/**/

// Set the desired page title
    $page_title = 'MythWeb - '.t('Channel Detail');

// Custom headers
    $headers[] = '<link rel="stylesheet" type="text/css" href="'.skin_url.'/tv_channel.css">';

// Print the page header
    require 'modules/_shared/tmpl/'.tmpl.'/header.php';

// Print out some header info about this channel and time
?>

<div id="list_head" class="clearfix">
    <form method="get" id="program_listing" action="<?php echo root ?>tv/channel">
    <div id="x_current_time">
<?php   if ($_SESSION["show_channel_icons"] && !empty($this_channel->icon)) { ?>
        <img src="<?php echo $this_channel->icon ?>" height="30" width="30">
<?php   } ?>
        Channel <?php echo $this_channel->channum ?>:  <?php echo $this_channel->callsign ?> on <?php echo strftime('%B %e, %Y', $_SESSION['list_time']) ?>
    </div>
    <table id="x-jumpto" class="commandbox commands" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td class="x-jumpto"><?php echo t('Jump To') ?>:</td>
        <td class="x-hour"><?php channel_select('onchange="$(\'program_listing\').submit()"', $this_channel->chanid) ?></td>
        <td class="x-day"><a href="<?php echo root ?>tv/channel/<?php echo $this_channel->chanid, '/', $_SESSION['list_time'] - (24 * 60 * 60) ?>"
                ><img src="<?php echo skin_url ?>img/left.gif" alt="<?php echo t('leftl'); ?>"></a>
            <?php date_select('onchange="$(\'program_listing\').submit()"') ?>
            <a href="<?php echo root ?>tv/channel/<?php echo $this_channel->chanid, '/', $_SESSION['list_time'] + (24 * 60 * 60) ?>"
                    ><img src="<?php echo skin_url ?>img/right.gif" alt="<?php echo t('right'); ?>"></a>
            </td>
    </tr>
    </table>
    </form>
</div>

<?php

// Only show the programs if there are some to display
    if (is_array($this_channel->programs)) {
?><table width="100%" border="0" cellpadding="4" cellspacing="2" class="list small">
<tr class="menu">
    <td><?php echo t('Time')        ?></td>
    <td><?php echo t('Show')        ?></td>
    <td><?php echo t('Episode')     ?></td>
    <td><?php echo t('Description') ?></td>
    <td><?php echo t('Length')      ?></td>
</tr>

<?php
        $row = 0;
        $lastend = 0;                           /* last end time */
        foreach ($this_channel->programs as $show) {

        // Print some additional information for movies
        $additional = '';
        if ($show->category_type == 'movie'
                || $show->category_type == 'Film') {
            if ($show->airdate > 0)
                    $additional = sprintf('%4d', $show->airdate);
            if (strlen($show->rating) > 0) {
                if ($additional)
                    $additional .= ", ";
                $additional .= "<i>$show->rating</i>";
            }
            if (strlen($show->starstring) > 0) {
                if ($additional)
                    $additional .= ", ";
                $additional .= $show->starstring;
            }
            if ($additional)
                $additional = ' (' . $additional . ')';
        }

        $starttime = strftime($_SESSION['time_format'], $show->starttime);
        $endtime = strftime($_SESSION['time_format'], $lastend);
        /* Do we have a gap? */
        $gap = $show->starttime - $lastend;
        if (($gap > 0) && ($lastend != 0))
        {
          $gapmins = $gap / 60;
          print <<< EOS
            <tr><td colspan="5"><font color="red">Missing programme data from $endtime to $starttime ($gapmins minutes)</font></td></tr>
EOS;
        }
        /* Print the content */
        $endtime = strftime($_SESSION['time_format'], $show->endtime);
        $root = root;
        $length = nice_length ($show->length);
        print <<< EOS
  <tr class="$show->css_class">
    <td class="nowrap" align="center">
          <a href="/${root}tv/list?time=$show->starttime">$starttime &ndash; $endtime</a>
    </td>
    <td class="$show->css_class">
EOS;
        if ($show->hdtv)
               echo '<span class="hdtv_icon">HD</span>';
        print <<< EOS

      <a href="$root/tv/detail/$show->chanid/$show->starttime">$show->title$additional</a>
    </td>
    <td>$show->subtitle</td>
    <td>$show->description</td>
    <td class="nowrap" align="right">$length</td>
  </tr>

EOS;
        $lastend = $show->endtime;
        $row++;
        }
?>

</table>
<?php
    }

// Print the page footer
    require 'modules/_shared/tmpl/'.tmpl.'/footer.php';
