<?php

/**
 * Contao Repository :: Template to display a list of extensions
 * @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'];
$order_options = &$GLOBALS['TL_LANG']['tl_repository_order_options'];
$state_options = &$GLOBALS['TL_LANG']['tl_repository_state_options'];

?>

<div class="mod_repository">
  <form action="<?= $rep->f_link ?>" id="repository_editform" method="post">
    <div class="tl_formbody">
      <input type="hidden" name="repository_action" value="<?= $rep->f_action ?>">
      <input type="hidden" name="REQUEST_TOKEN" value="<?= REQUEST_TOKEN ?>">
      <div class="tl_panel">
        <div class="tl_filter tl_subpanel">
          <strong><?= $GLOBALS['TL_LANG']['MSC']['filter'] ?>:</strong>

          <select name="repository_tag" id="repository_tag" class="tl_select<?php if ($rep->f_tag!='') echo ' active'; ?>">
            <option value=""><?= $text['tag'] ?></option>
            <option value="">---</option>
            <?php foreach ($rep->tags as $tag): ?>
              <option value="<?= $tag->item ?>"<?php if ($rep->f_tag==$tag->item) echo ' selected="selected"'; ?>><?= $tag->item ?></option>
            <?php endforeach; ?>
          </select>

          <select name="repository_type" id="repository_type" class="tl_select<?php if ($rep->f_type!='') echo ' active'; ?>">
            <option value=""><?= $text['type'][0] ?></option>
            <option value="">---</option>
            <?php foreach (array_keys($type_options) as $tpe): ?>
              <?php if ($tpe!='private'): ?>
                <option value="<?= $tpe ?>"<?php if ($rep->f_type==$tpe) echo ' selected="selected"'; ?>><?= $type_options[$tpe] ?></option>
              <?php endif; ?>
            <?php endforeach; ?>
          </select>

          <select name="repository_category" id="repository_category" class="tl_select<?php if ($rep->f_category!='') echo ' active'; ?>">
            <option value=""><?= $text['category'][0] ?></option>
            <option value="">---</option>
            <?php foreach (array_keys($category_options) as $cat): ?>
              <?php if ($cat != 'core'): ?>
                <option value="<?= $cat ?>"<?php if ($rep->f_category==$cat): ?> selected="selected"<?php endif; ?>><?= $category_options[$cat] ?></option>
              <?php endif; ?>
            <?php endforeach; ?>
          </select>

          <select name="repository_state" id="repository_state" class="tl_select<?php if ($rep->f_state!='') echo ' active'; ?>">
            <option value=""><?= $text['state'] ?></option>
            <option value="">---</option>
            <?php foreach (array_keys($state_options) as $sta): ?>
              <option value="<?= $sta ?>"<?php if ($rep->f_state==$sta) echo ' selected="selected"'; ?>><?= $state_options[$sta] ?></option>
            <?php endforeach; ?>
          </select>

          <select name="repository_author" id="repository_author" class="tl_select<?php if ($rep->f_author!='') echo ' active'; ?>">
            <option value=""><?= $text['author'] ?></option>
            <option value="">---</option>
            <?php foreach ($rep->authors as $aut): ?>
              <option value="<?= $aut->item ?>"<?php if ($rep->f_author==$aut->item) echo ' selected="selected"'; ?>><?= $aut->item ?></option>
            <?php endforeach; ?>
          </select>

        </div>
        <div class="clear"></div>
      </div>
      <div class="tl_panel">

        <div class="tl_submit_panel tl_subpanel">
          <input type="image" name="filter" id="filter" src="<?= TL_FILES_URL ?>system/themes/<?= Backend::getTheme() ?>/images/reload.gif" class="tl_img_submit" title="<?= $text['apply'] ?>" alt="<?= $text['apply'] ?>">
        </div>

        <div class="tl_limit tl_subpanel">
          <strong><?= $GLOBALS['TL_LANG']['MSC']['showOnly'] ?>:</strong>
          <select name="repository_page" id="repository_page" class="tl_select<?php if ($rep->f_page!=-1) echo ' active'; ?>" onchange="this.form.submit()">
            <option value="0"><?= $GLOBALS['TL_LANG']['MSC']['filterRecords'] ?></option>
            <?php for ($page=0, $count=count($rep->pages); $page<$count; $page++): ?>
              <option value="<?= $page ?>"<?php if ($rep->f_page==$page) echo ' selected="selected"'; ?>><?= $rep->pages[$page] ?></option>
            <?php endfor; ?>
            <option value="-1"<?php if ($rep->f_page<0) echo ' selected="selected"'; ?>><?= $GLOBALS['TL_LANG']['MSC']['filterAll'] ?></option>
          </select>
        </div>

        <div class="tl_search tl_subpanel">
          <strong><?= $GLOBALS['TL_LANG']['MSC']['search'] ?>:</strong>
          <input type="text" name="repository_find" id="repository_find" value="<?= specialchars($rep->f_find) ?>" class="tl_text fulltextsearch<?php if ($rep->f_find!='') echo ' active'; ?>"/>
        </div>

        <div class="tl_sorting tl_subpanel">
          <strong><?= $GLOBALS['TL_LANG']['MSC']['sortBy'] ?>:</strong>
          <select name="repository_order" id="repository_order" class="tl_select">
          <?php foreach (array_keys($order_options) as $oby): ?>
            <option value="<?= $oby ?>"<?php if ($rep->f_order==$oby) echo ' selected="selected"'; ?>><?= sprintf($text['byorder'], $order_options[$oby]) ?></option>
          <?php endforeach; ?>
          </select>
        </div>

        <div class="clear"></div>
      </div>
    </div>
  </form>

  <div class="extension_container">
    <?php if (count($rep->extensions) < 1): ?>
      <p><?= $text['noextensionsfound'] ?></p>
      <?php if (!Config::get('repository_unsafe_catalog')): ?>
        <p class="tl_info"><?= $GLOBALS['TL_LANG']['tl_repository']['showIncompatible'] ?></p>
      <?php endif; ?>
    <?php else: ?>
      <?php foreach ($rep->extensions as $ext): ?>
        <table class="extension">
          <tr class="title">
            <th colspan="4"><span class="leftblock">[<a href="<?= $ext->viewLink ?>" title="<?= $text['showdetails'] ?>"><?= $ext->name ?></a>] <?= $ext->title ?></span> <span class="rightblock"><?= $theme->createListButton('info', $ext->viewLink, $text['showdetails']) ?> <?= $theme->createListButton('install16', $ext->installLink, $text['install']) ?></span></th>
          </tr>
          <?php if ($ext->teaser!=''): ?>
            <tr class="description">
              <td colspan="4"><?= $ext->teaser ?></td>
            </tr>
          <?php endif; ?>
          <tr class="info">
            <th class="listcol1"><?= $text['version'][0] ?></th>
            <td class="listcol2 status-<?= $ext->version % 10 ?>"><?= Repository::formatVersion($ext->version) ?></td>
            <th class="listcol3"><?= $text['type'][0] ?></th>
            <td class="type-<?= $ext->type ?>"><?= $type_options[$ext->type] ?></td>
          </tr>
          <tr class="info">
            <th><?= $text['releasedate'][0] ?></th>
            <td><?= Date::parse(Config::get('dateFormat'), $ext->releasedate) ?></td>
            <th><?= $text['approvedForLabel'] ?></th>
            <td><?php printf($text['approvedForText'], Repository::formatCoreVersion($ext->coreminversion), Repository::formatCoreVersion($ext->coremaxversion)); ?></td>
          </tr>
          <tr class="info">
            <th><?= $text['author'] ?></th>
            <td><?= $ext->author ?></td>
            <th><?= $text['license'][0] ?></th>
            <td><?= $ext->license ?></td>
          </tr>
          <tr class="info">
            <th><?= $text['totrating'] ?></th>
            <td class="nowrap"><div class="ratebarframe<?= ($ext->votes < 1) ? ' empty' : '' ?>"><div class="ratebar" style="width:<?= number_format($ext->rating*10.0,12,'.',',') ?>%"></div></div> <div class="ratebartext"><?= sprintf($text['ratingfmt'], $ext->rating, $ext->votes) ?></div></td>
            <th><?= $text['popularity'][0] ?></th>
            <td class="nowrap"><?= sprintf($text['popularity'][1], (int)$ext->downloads, (int)$ext->installs) ?></td>
          </tr>
        </table>
      <?php endforeach; ?>
    <?php endif; ?>
  </div>
</div>

<?php if ($rep->pageOffset): ?>
  <script>
    function repositoryGetScrollOffset() {
      var top = this.pageYOffset || document.documentElement.scrollTop;
      document.cookie = "REPOSITORY_PAGE_OFFSET=" + top + "; path=/";
    }
    onload = self.scrollTo(0, <?= $rep->pageOffset ?>);
  </script>
<?php endif; ?>
