<?php

/**
 * Contao Repository :: Template to display a single extension
 * @copyright  Peter Koch 2008-2010
 * @author     Peter Koch, IBK Software AG
 * @license    See accompaning file LICENSE.txt
 */

$rep = &$this->rep;
$theme = &$rep->theme;
$text = &$GLOBALS['TL_LANG']['tl_repository'];
$type_options = &$GLOBALS['TL_LANG']['tl_repository_type_options'];
$category_options = &$GLOBALS['TL_LANG']['tl_repository_category_options'];
$ext = &$rep->extensions[0];
$langs = property_exists($ext, 'languages') && count($ext->languages)>0;

?>

<div id="tl_buttons">
  <a href="contao/main.php?do=repository_catalog" class="header_back" title="<?= $text['goback'] ?>" accesskey="b" onclick="Backend.getScrollOffset()"><?= $text['goback'] ?></a>
</div>

<div class="mod_repository mod_repository_view">
  <form action="<?= $rep->f_link ?>" id="repository_editform" method="post">
    <div class="extension_container">
      <input type="hidden" name="repository_action" value="<?= $rep->f_action ?>">
      <input type="hidden" name="REQUEST_TOKEN" value="<?= REQUEST_TOKEN ?>">
      <table class="extension">
        <tr class="title">
          <th colspan="4"><span class="title">[<?= $ext->name ?>] <?= $ext->title ?></span> <span class="actions"><?php if (property_exists($ext, 'packageLink')): ?> <a href="<?= $ext->packageLink ?>" title="<?= $text['downloadpackage'] ?>"> <?= $rep->theme->createImage('download16',$text['downloadpackage'],'title="'.$text['downloadpackage'].'"') ?></a><?php endif; ?></span></th>
        </tr>
        <tr class="description">
          <td colspan="4">
            <?php if (property_exists($ext, 'thumbnail')): ?>
              <figure class="image_container">
                <a href="<?= $ext->picture->url ?>" title="<?= $text['showpicture'] ?>" onclick="Backend.openModalImage({'width':<?= $ext->picture->width ?>,'title':'<?= str_replace("'", "\\'", $ext->title) ?>','url':'<?= $ext->picture->url ?>'});return false"><img src="<?= $ext->thumbnail->url ?>" alt="<?= $text['thumbnail'] ?>" width="<?= $ext->thumbnail->width ?>" height="<?= $ext->thumbnail->height ?>" class="thumbnail"></a>
              </figure>
            <?php endif; ?>
            <?php if ($ext->teaser!=''): ?>
              <h2><?= $ext->teaser ?></h2>
            <?php endif; ?>
            <?= str_replace('<br />', '<br>', StringUtil::restoreBasicEntities($ext->description)) ?>
          </td>
        </tr>
        <tr class="spacer"><td colspan="4" class="spacer">&nbsp;</td></tr>
        <tr>
          <th class="viewcol1"><?= $text['version'][0] ?></th>
          <td class="viewcol2 status-<?= $ext->version % 10 ?>"><?= Repository::formatVersion($ext->version) ?></td>
          <th class="viewcol3"><?= $text['type'][0] ?></th>
          <td class="type-<?= $ext->type ?>"><?= $type_options[$ext->type] ?></td>
        </tr>
        <tr>
          <th><?= $text['releasedate'][0] ?></th>
          <td><?= Date::parse(Config::get('dateFormat'), $ext->releasedate) ?></td>
          <th>&nbsp;</th>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <th><?= $text['license'][0] ?></th>
          <td><?= $ext->license ?></td>
          <th><?= $text['category'][0] ?></th>
          <td><?= $category_options[$ext->category] ?></td>
        </tr>
        <tr class="spacer"><td colspan="4" class="spacer">&nbsp;</td></tr>
        <tr>
          <th><?= $text['copyright'][0] ?></th>
          <td colspan="3"><?= $ext->copyright ?></td>
        </tr>
        <tr>
          <th><?= $text['author'] ?></th>
          <td colspan="3"><?= property_exists($ext,'authorname') ? $ext->authorname.' ('.$ext->author.')' : $ext->author ?><?php if (property_exists($ext,'authorsite')): ?> <a href="<?=  $ext->authorsite ?>"><?=  $ext->authorsite ?></a><?php endif; ?></td>
        </tr>
        <?php if ($ext->translator != $ext->author): ?>
          <tr>
            <th><?= sprintf($text['langtrans'], $GLOBALS['TL_LANG']['LNG'][$ext->language]) ?></th>
            <td colspan="3"><?= property_exists($ext,'translatorname') ? $ext->translatorname.' ('.$ext->translator.')' : $ext->translator ?><?php if (property_exists($ext,'translatorsite')): ?> <a href="<?=  $ext->translatorsite ?>"><?=  $ext->translatorsite ?></a><?php endif; ?></td>
          </tr>
        <?php endif; ?>
        <tr class="spacer"><td colspan="4" class="spacer">&nbsp;</td></tr>
        <tr>
          <th colspan="3"><?= sprintf($text['releasenotesfor'], Repository::formatVersion($ext->version)) ?></th>
          <th><?= $text['versions'] ?></th>
        </tr>
        <tr>
          <td colspan="3"<?php if ($langs) echo ' rowspan="3"'; ?> class="releasenotes"><?= str_replace('<br>', '<br>', $ext->releasenotes) ?></td>
          <td><?php if (property_exists($ext, 'allversions')) foreach ($ext->allversions as $ver) if ($ver->version != $ext->version): ?><a href="<?= $ver->viewLink ?>"><?= Repository::formatVersion($ver->version) ?></a><br><?php endif; ?></td>
        </tr>
        <?php if ($langs): ?>
          <tr>
            <th style="height:20px"><?= $text['otherlanguages'] ?></th>
          </tr>
          <tr>
            <td><?php foreach ($ext->languages as $lng) if ($lng->language != $ext->language): ?><a href="<?= $lng->link ?>"><?= $GLOBALS['TL_LANG']['LNG'][$lng->language] ?></a><br><?php endif; ?></td>
          </tr>
        <?php endif; ?>
        <tr class="spacer"><td colspan="4" class="spacer">&nbsp;</td></tr>
        <?php if (property_exists($ext, 'votes')): ?>
          <tr>
            <th><?= $text['relfunctionality'] ?></th>
            <td class="nowrap"><?php if (property_exists($ext, 'rel_votes')): ?><div class="ratebarframe"><div class="ratebar" style="width:<?= $ext->rel_functionality*10.0 ?>%"></div></div> <div class="ratebartext"><?= sprintf('%.2f', $ext->rel_functionality) ?></div><?php endif; ?></td>
            <th><?= $text['totfunctionality'] ?></th>
            <td class="nowrap"><div class="ratebarframe"><div class="ratebar" style="width:<?= $ext->functionality*10.0 ?>%"></div></div> <div class="ratebartext"><?= sprintf('%.2f', $ext->functionality) ?></div></td>
          </tr>
          <tr>
            <th><?= $text['relusability'] ?></th>
            <td class="nowrap"><?php if (property_exists($ext, 'rel_votes')): ?><div class="ratebarframe"><div class="ratebar" style="width:<?= $ext->rel_usability*10.0 ?>%"></div></div> <div class="ratebartext"><?= sprintf('%.2f', $ext->rel_usability) ?></div><?php endif; ?></td>
            <th><?= $text['totusability'] ?></th>
            <td class="nowrap"><div class="ratebarframe"><div class="ratebar" style="width:<?= $ext->usability*10.0 ?>%"></div></div> <div class="ratebartext"><?= sprintf('%.2f', $ext->usability) ?></div></td>
          </tr>
          <tr>
            <th><?= $text['relquality'] ?></th>
            <td class="nowrap"><?php if (property_exists($ext, 'rel_votes')): ?><div class="ratebarframe"><div class="ratebar" style="width:<?= $ext->rel_quality*10.0 ?>%"></div></div> <div class="ratebartext"><?= sprintf('%.2f', $ext->rel_quality) ?></div><?php endif; ?></td>
            <th><?= $text['totquality'] ?></th>
            <td class="nowrap"><div class="ratebarframe"><div class="ratebar" style="width:<?= $ext->quality*10.0 ?>%"></div></div> <div class="ratebartext"><?= sprintf('%.2f', $ext->quality) ?></div></td>
          </tr>
          <tr>
            <th><?= $text['relrating'] ?></th>
            <td class="nowrap"><?php if (property_exists($ext, 'rel_votes')): ?><div class="ratebarframe"><div class="ratebar" style="width:<?= $ext->rel_rating*10.0 ?>%"></div></div> <div class="ratebartext"><?= sprintf($text['ratingfmt'], $ext->rel_rating, $ext->rel_votes) ?></div><?php endif; ?></td>
            <th><?= $text['totrating'] ?></th>
            <td class="nowrap"><div class="ratebarframe"><div class="ratebar" style="width:<?= $ext->rating*10.0 ?>%"></div></div> <div class="ratebartext"><?= sprintf($text['ratingfmt'], $ext->rating, $ext->votes) ?></div></td>
          </tr>
          <tr class="spacer"><td colspan="4" class="spacer">&nbsp;</td></tr>
        <?php endif; ?>
        <?php if (property_exists($ext, 'downloads')): ?>
          <tr>
            <th><?= $text['reldownloads'] ?></th>
            <td><?= $ext->rel_downloads ?></td>
            <th><?= $text['totdownloads'] ?></th>
            <td><?= $ext->downloads ?></td>
          </tr>
        <?php endif; ?>
        <?php if (property_exists($ext, 'installs')): ?>
          <tr>
            <th><?= $text['relinstalls'] ?></th>
            <td><?= $ext->rel_installs ?></td>
            <th><?= $text['totinstalls'] ?></th>
            <td><?= $ext->installs ?></td>
          </tr>
        <?php endif; ?>
        <?php if (property_exists($ext, 'updates')): ?>
          <tr>
            <th><?= $text['relupdates'] ?></th>
            <td><?= $ext->rel_updates ?></td>
            <th><?= $text['totupdates'] ?></th>
            <td><?= $ext->updates ?></td>
          </tr>
        <?php endif; ?>
        <tr class="spacer"><td colspan="4" class="spacer">&nbsp;</td></tr>
        <tr>
          <th colspan="2"><?= $text['dependencies'] ?></th>
          <th colspan="2"><?= $text['dependents'] ?></th>
        </tr>
        <tr>
          <td colspan="2" class="nopadding">
            <table class="nested">
              <tr>
                <th><?= $text['name'][0] ?></th>
                <th><?= $text['versionfrom'] ?></th>
                <th><?= $text['versionto'] ?></th>
              </tr>
              <tr>
                <td>Contao</td>
                <td><?= Repository::formatCoreVersion($ext->coreminversion) ?></td>
                <td><?= Repository::formatCoreVersion($ext->coremaxversion) ?></td>
              </tr>
              <?php if (property_exists($ext, 'dependencies')): ?>
                <?php foreach ($ext->dependencies as $dep): ?>
                  <tr>
                    <td><a href="<?= $dep->viewLink ?>"><?= $dep->extension ?></a></td>
                    <td><?= Repository::formatVersion($dep->minversion) ?></td>
                    <td><?= Repository::formatVersion($dep->maxversion) ?></td>
                  </tr>
                <?php endforeach; ?>
              <?php endif; ?>
            </table>
          </td>
          <td colspan="2" class="nopadding">
            <table class="nested">
              <tr>
                <th><?= $text['name'][0] ?></th>
                <th><?= $text['versionfrom'] ?></th>
                <th><?= $text['versionto'] ?></th>
              </tr>
              <?php if (property_exists($ext, 'dependents')): ?>
                <?php foreach ($ext->dependents as $dep): ?>
                  <tr>
                    <td><a href="<?= $dep->viewLink ?>"><?= $dep->extension ?></a></td>
                    <td><?= Repository::formatVersion($dep->minversion) ?></td>
                    <td><?= Repository::formatVersion($dep->maxversion) ?></td>
                  </tr>
                <?php endforeach; ?>
              <?php endif; ?>
            </table>
          </td>
        </tr>
      </table>
    </div>
    <div class="mod_repository_submit tl_formbody_submit">
      <div class="tl_submit_container">
        <input type="submit" name="repository_installbutton" class="tl_submit" value="<?= $text['install'] ?>">
        <?php if (property_exists($ext, 'manual')): ?>
          <input type="submit" name="repository_manualbutton" class="tl_submit" value="<?= $text['manual'] ?>" onclick="window.open('<?= ampersand($ext->manual) ?>');return false">
        <?php endif; ?>
        <?php if (property_exists($ext, 'forum')): ?>
          <input type="submit" name="repository_forumbutton" class="tl_submit" value="<?= $text['forum'] ?>" onclick="window.open('<?= ampersand($ext->forum) ?>');return false">
        <?php endif; ?>
        <?php if (property_exists($ext, 'shop')): ?>
          <input type="submit" name="repository_shopbutton" class="tl_submit" value="<?= $text[$ext->type=='free' ? 'donate' : 'shop'] ?>" onclick="window.open('<?= ampersand($ext->shop) ?>');return false">
        <?php endif; ?>
      </div>
    </div>
  </form>
</div>
