<?php echo $this->error($this); ?>
<div class="usvn_info">
  <h1><?php echo $this->path ?></h1>
  <br />
  <table width="100%">
    <tr>
      <th align="left"><?php echo T_("Language:")." ".(empty($this->language) ? T_('text') : $this->language) ?></th>
      <th align="right">
        <form method="POST" action="<?php echo $this->url(array('action' => 'browser', 'project' => $this->project->name), 'project') ?>" style="display: inline;">
          <input type="hidden" name="back" value="<?php echo '/'.dirname($this->path).'/' ?>">
          <input type="submit" value="<?php echo T_('Browser') ?>" />
        </form>
        /
        <a href="<?php echo USVN_SVNUtils::getSubversionUrl($this->project->name, "/".$this->path) ?>"><?php echo T_('Original') ?></a>
      </th>
    </tr>
    <tr>
      <form name="revisions" method="POST" action="<?php echo $this->url(array('project' => $this->project->name, 'action' => 'show'), 'project')."/".str_replace('%2F', '/', urlencode($this->path)).'?rev='.$this->revision ?>">
      <td align="center" style="padding-top: 5px;">
        <input type="hidden" name="post" value="1" />
          <?php if ($this->prev_revision > 0) { ?>
            <input type="submit" onclick="document.revisions.action=document.revisions.action.split('?',1)+'?rev=<?php echo $this->prev_revision ?>';" value="<?php echo T_('Previous') ?>" />
          <?php } else { ?>
            <input type="submit" value="<?php echo T_('Previous') ?>" disabled />
          <?php } ?>
          <?php echo T_('Revision: ') ?>
          <select onChange="document.revisions.action=document.revisions.action.split('?',1)+'?rev='+this.value;document.revisions.submit();">
            <?php foreach ($this->select_revisions as $rev) { echo '<option value="'.$rev.'"'.($rev == $this->revision ? ' selected' : '').'>'.$rev.'</option>'; } ?>
          </select>
          <?php if ($this->next_revision > 0) { ?>
            <input type="submit" onclick="document.revisions.action=document.revisions.action.split('?',1)+'?rev=<?php echo $this->next_revision ?>';" value="<?php echo T_('Next') ?>" />
          <?php } else { ?>
            <input type="submit" value="<?php echo T_('Next') ?>" disabled />
          <?php } ?>
          <br />
          <a href="<?php echo $this->url(array('project' => $this->project->name, 'action' => 'commit', 'commit' => $this->revision), 'commit') ?>"><?php echo T_('View the full commit.') ?></a>
      </td>
      <td align="left">
        <label><input onChange="document.revisions.submit();" type="checkbox" name="color" style="vertical-align: middle;" <?php echo ($this->color_view ? 'checked' : '') ?> /> <?php echo T_('Color view') ?></label><br />
        <label><input onChange="document.revisions.submit();" type="checkbox" name="diff" style="vertical-align: middle;" <?php echo ($this->diff_view ? 'checked' : '') ?> /> <?php echo T_('Diff view') ?></label>
        <input type="hidden" name="drev" value="<?php echo $this->diff_revision ?>" id="drev" />
        <select onChange="document.getElementById('drev').value=this.value;document.revisions.submit();" <?php echo ($this->diff_view ? '' : 'disabled') ?>>
          <?php foreach ($this->select_revisions as $rev) {
              if ($rev > $this->revision) { continue; }
              if ($rev == $this->revision) {
                echo '<option value=""'.($this->diff_revision ? ' selected' : '').'>'.T_('Prev').'</option>';
                continue;
              }
              echo '<option value="'.$rev.'"'.($rev == $this->diff_revision ? ' selected' : '').'>'.$rev.'</option>';
            }
            $diff_rev = ($this->diff_revision ? $this->diff_revision : $this->prev_revision);
          ?>
        </select>
      </td>
      </form>
    </tr>
  </table>
  <p align="right">
  </p>
</div>
<?php
  if (!$this->diff_view) {
    echo $this->highlighted_source;
  }
  else {
    ?><div <?php echo $this->diff_div ?>><table border="0" cellspacing="1px" cellpadding="0" width="100%" style="padding: 2px;"><tr><?php if ($diff_rev > 0) { ?><th style="background-color: #EEEEEE;" width="30px;">r<?php echo $diff_rev ?></th><?php } ?><th style="background-color: #EEEEEE;" width="30px;">r<?php echo $this->revision ?></th><th style="background-color: #EEEEEE;">&nbsp;</th></tr>
    <?php
      $source = explode("\n", $this->highlighted_source);
      $r1_line = 1;
      $r2_line = 1;
      foreach ($source as $nb => $line) {
        if ($diff_rev > 0) {
          echo '<tr><td align="right" style="background-color: #EEEEEE;">';
          if (!isset($this->diff_lines[$nb]) || $this->diff_lines[$nb] == '-') {
            echo $r1_line++;
          } else {
            echo '&nbsp;';
          }
          echo '</td>';
        }
        echo '<td align="right" style="background-color: #EEEEEE;">';
        if (!isset($this->diff_lines[$nb]) || $this->diff_lines[$nb] == '+') {
          echo $r2_line++;
        } else {
          echo '&nbsp;';
        }
        echo '</td>';
        if (isset($this->diff_lines[$nb])) {
          echo '<td style="background-color: '.($this->diff_lines[$nb] == '+' ? '#DDFFDD' : '#FFDDDD').';">';
        } else {
          echo '<td>';
        }
        if (preg_match('#^<li [^>]*>(.*)</li>$#', $line, $tmp)) {
          $line = $tmp[1];
        }
        echo $line, '</td></tr>', "\n";
      }
    ?></table></div><?php
  }
?>