<?php

/**
 * Contao Repository :: Template to install an 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'];
$state_options = &$GLOBALS['TL_LANG']['tl_repository_state_options'];
$statext = &$GLOBALS['TL_LANG']['tl_repository_statext'];
$tabindex = 1;

?>

<div id="tl_buttons">
  <a href="<?= $rep->homeLink ?>" class="header_back" title="<?= $text['goback'] ?>" accesskey="b" onclick="Backend.getScrollOffset()"><?= $text['goback'] ?></a>
</div>

<h2 class="sub_headline"><?= $text['installextension'] ?></h2>

<div class="mod_repository">
  <form action="<?= $rep->f_link ?>" id="repository_editform" method="post" >
    <div class="tl_formbody_edit">
      <input type="hidden" name="repository_action" value="<?= $rep->f_action ?>">
      <input type="hidden" name="repository_stage" value="<?= $rep->f_stage ?>">
      <input type="hidden" name="REQUEST_TOKEN" value="<?= REQUEST_TOKEN ?>">
      <div class="tl_tbox">
        <?php if ($rep->f_stage>=$rep->inst_extension): ?>
          <?php $nm = ($rep->f_stage==$rep->inst_extension) ? 'repository_extension' : 'repository_extension_dis'; ?>
          <div>
            <h3><label for="<?= $nm ?>"><?= $text['extension'][0] ?></label></h3>
            <input type="text" tabindex="<?= $tabindex++ ?>" maxlength="32" name="<?= $nm ?>" id="<?= $nm ?>" value="<?= $rep->f_extension ?>" class="tl_text"<?php if ($rep->f_stage>$rep->inst_extension): ?> disabled<?php else: ?> autofocus<?php endif; ?>>
            <?php if (property_exists($rep, 'f_extension_msg')): ?>
              <p class="tl_error"><?= $text[$rep->f_extension_msg] ?></p>
            <?php else: ?>
              <p class="tl_help tl_tip"><?= $text['extension'][1] ?></p>
            <?php endif; ?>
            <?php if ($rep->f_stage>$rep->inst_extension): ?>
              <input type="hidden" name="repository_extension" value="<?= $rep->f_extension ?>">
            <?php endif; ?>
          </div>
        <?php endif; ?>
        <?php if ($rep->f_stage>=$rep->inst_version): ?>
          <?php $nm = ($rep->f_stage==$rep->inst_version) ? 'repository_version' : 'repository_version_dis'; ?>
          <div>
            <h3><label for="<?= $nm ?>"><?= $text['selversion'][0] ?></label></h3>
            <select name="<?= $nm ?>" id="<?= $nm ?>" class="tl_select" tabindex="<?= $tabindex++ ?>"<?php if ($rep->f_stage>$rep->inst_version) echo ' disabled="disabled"'; ?>>
              <?php foreach ($rep->f_allversions as $ver) echo '    <option value="'.$ver.'" '.($ver==$rep->f_version ? ' selected="selected"' : '').'>'.Repository::formatVersion($ver).'</option>'."\n"; ?>
            </select>
            <p class="tl_help tl_tip"><?= $text['selversion'][1] ?></p>
            <?php if ($rep->f_stage>$rep->inst_version): ?>
              <input type="hidden" name="repository_version" value="<?= $rep->f_version ?>">
            <?php endif; ?>
          </div>
        <?php endif; ?>
        <?php if ($rep->f_enterkey && $rep->f_stage>=$rep->inst_lickey): ?>
          <?php $nm = ($rep->f_stage==$rep->inst_lickey) ? 'repository_lickey' : 'repository_lickey_dis'; ?>
          <div>
            <h3><label for="<?= $nm ?>"><?= $text['lickey'][0] ?></label></h3>
            <input type="text" tabindex="<?= $tabindex++ ?>" maxlength="255" name="<?= $nm ?>" id="<?= $nm ?>" value="<?= $rep->f_lickey ?>" class="tl_text"<?php if ($rep->f_stage>$rep->inst_lickey) echo ' disabled="disabled"'; ?>>
            <?php if ($rep->f_stage>$rep->inst_lickey): ?>
              <input type="hidden" name="repository_lickey" value="<?= $rep->f_lickey ?>">
            <?php endif; ?>
            <?php if (property_exists($rep, 'f_lickey_msg')): ?>
              <div class="tl_error"><?= $text[$rep->f_lickey_msg] ?></div>
            <?php else: ?>
              <p class="tl_help tl_tip"><?= $text['lickey'][1] ?></p>
            <?php endif; ?>
          </div>
        <?php endif; ?>
        <?php if ($rep->f_stage>=$rep->inst_actions): ?>
          <?php if ($rep->f_changelog): ?>
            <div class="mod_repository_view">
              <h3><label><?php printf($text['releasenotesfor'], $rep->f_extension); ?></label></h3>
              <div class="releasenotes"><?= $rep->f_changelog ?></div>
            </div>
          <?php endif; ?>
          <div>
            <h3><label><?= $text['actionsummary'] ?></label></h3>
            <table class="installs">
              <tr class="title">
                <th class="col_extension"><?= $text['extension'][0] ?></th>
                <th class="col_version"><?= $text['version'][0] ?></th>
                <th class="col_build"><?= $text['build'] ?></th>
                <th class="col_action"><?= $text['action'] ?></th>
                <th class="col_status"><?= $text['status'] ?></th>
              </tr>
              <?php foreach ($rep->actions as $act): ?>
                <tr class="datarow">
                  <td class="col_extension"><?= $act->extension ?></td>
                  <td class="col_version"><?= Repository::formatVersion($act->version) ?></td>
                  <td class="col_build"><?= $act->build ?></td>
                  <td class="col_action">
                    <div class="tl_checkbox_container">
                      <input type="checkbox" name="repository_enable[]" id="repository_enable_<?= $act->extension ?>"  tabindex="<?= $tabindex++ ?>" class="tl_checkbox" value="<?= $act->extension ?>"<?php if ($act->enabled): ?> checked="checked"<?php endif; ?><?php if ($act->locked): ?> disabled="disabled"<?php endif; ?>> <label for="repository_enable_<?= $act->extension ?>"><?= $text[$act->action] ?></label>
                    </div>
                  </td>
                  <td class="col_status"><?php foreach ($act->status as $sta) echo '<div class="color_'.$sta->color.'">'.sprintf($statext[$sta->text], $sta->par1, $sta->par2).'</div>'; ?></td>
                </tr>
              <?php endforeach; ?>
            </table>
          </div>
        <?php endif; ?>
      </div>
      <?php if ($rep->f_stage>=$rep->inst_showlog): ?>
        <div class="installlog">
          <?= $rep->log ?>
        </div>
      <?php endif; ?>
    </div>
    <div class="mod_repository_submit tl_formbody_submit">
      <div class="tl_submit_container">
        <?php if (property_exists($rep, 'f_submit')): ?>
          <input type="submit" name="repository_submitbutton" class="tl_submit" value="<?= $text[$rep->f_submit] ?>">
        <?php endif; ?>
        <input type="submit" name="repository_cancelbutton" class="tl_submit" value="<?= $text['cancel'] ?>">
      </div>
    </div>
  </form>
</div>
