  <h1><?php print _("Upgrade Other Modules") ?></h1>

  <script type="text/javascript">
    // <![CDATA[
    function checkAll(newValue) {
	for (var i = 0; i < document.forms[0].length; i++) {
	    var element = document.forms[0].elements[i];
	    if (element.type == 'checkbox' &&
		element.name.substr(0,6) == 'module' && !element.disabled) {
		element.checked = newValue;
	    }
	}
    }
    // ]]>
  </script>

  <p>
    <?php print _("The following modules can be automatically upgraded for you.  If you choose not to upgrade them now, you may experience problems with your Gallery.   You can always upgrade or deactivate them on the Site Administration page, or return to this page later so any decision you make here is not permanent.") ?>
  </p>

  <?php if (!empty($templateData['missingCode'])): ?>
    <h2 class="error"> <?php print _('Missing Code') ?> </h2>
    <div class="stack_trace">
      <?php print _('The code for some plugins that were previously active can no longer be found. You must restore code for these plugins before this upgrade can continue. Code for the plugins must be the same version or newer than what was installed before.') ?>
      <div class="go">
	<?php foreach ($templateData['missingCode'] as $pluginType => $list) {
		$pluginType = ($pluginType == 'module') ? _('Module') : _('Theme');
		foreach ($list as $pluginId) {
		  print "$pluginType: $pluginId<br/>\n";
		}
	      } ?>
      </div>
    </div>
  <?php elseif (!empty($templateData['groupedModules'])): ?>
    <form method="post" action="<?php generateUrl('index.php?step=' . $stepNumber) ?>">
      <table class="modules">
	<tr style="background-color: #ccc">
	  <th>
	    &nbsp;
	  </th>
	  <th>
	    <?php print _("Name") ?>
	  </th>
	  <th>
	    <?php print _("Current") ?>
	  </th>
	  <th>
	    <?php print _("New") ?>
	  </th>
	  <th>
	    <?php print _("Description") ?>
	  </th>
	</tr>
	<?php $upgradableCount = 0;
	  foreach ($templateData['groupedModules'] as $group => $modules): ?>
	  <tr style="background-color: #fff">
	    <td colspan="4"><h3><?php print $templateData['groupLabel'][$group] ?></h3></td>
	  </tr>
	  <?php $counter = 0; ?>
	  <?php foreach ($modules as $id => $module): ?>
	  <?php $isUpgradeable = $templateData['moduleIsUpgradeable'][$id]; ?>
	  <tr<?php if ($counter % 2 == 0) print ' style="background-color: #eee"' ?>>
	    <td>
	      <input type="checkbox" id="plugin_<?php print $id ?>" 
                name="<?php print ($templateData['groupType'][$group] . '[' . $id . ']')?>"
		<?php if ($isUpgradeable): ?>
		  checked="checked"
		<?php $upgradableCount++; else: ?>
		  disabled="disabled"
		<?php endif; ?>
	      />
	    </td>
	    <td>
	      <?php if (!$isUpgradeable): ?> <span class="disabled"> <?php endif; ?>
	      <label for="plugin_<?php print $id ?>">
		<?php print $module->getName() ?>
	      </label>
	      <?php if (!$isUpgradeable): ?> </span> <?php endif; ?>
	    </td>
	    <td>
	      <?php if (!$isUpgradeable): ?> <span class="disabled"> <?php endif; ?>
	      <?php print $templateData['currentVersion'][$id]; ?>
	      <?php if (!$isUpgradeable): ?> </span> <?php endif; ?>
	    </td>
	    <td>
	      <?php if (!$isUpgradeable): ?> <span class="disabled"> <?php endif; ?>
	      <?php print $module->getVersion() ?>
	      <?php if (!$isUpgradeable): ?> </span> <?php endif; ?>
	    </td>
	    <td>
	      <?php if (!$isUpgradeable): ?> <span class="disabled"> <?php endif; ?>
	      <?php print $module->getDescription() ?>
	      <?php if (!$isUpgradeable): ?> </span> <?php endif; ?>
	    </td>
	  </tr>
	  <?php $counter++; ?>
	  <?php endforeach; ?>
	<?php endforeach; ?>
	<?php if ($templateData['anyUpgradeable']): ?>
	<tr style="background-color: #ccc">
	  <td>
	    <input type="checkbox" onclick="checkAll(this.checked);" checked="checked"/>
	  </td>
	  <td colspan="4">
	    <?php print _("(un)check all") ?>
	    <input type="hidden" name="step" value="<?php print $currentStep->getStepNumber() ?>"/>
	    <input type="hidden" name="upgrade" value="<?php print $upgradableCount ?>"/>
	  </td>
	</tr>
	<?php endif; ?>
      </table>
    </form>

    <?php if (!empty($templateData['errors'])): ?>
    <?php foreach ($templateData['errors'] as $error): ?>
    <h3 class="error">
      <?php print $error; ?>
    </h3>
    <?php endforeach; ?>
    <?php endif; ?>

    <?php if (!empty($templateData['stackTrace'])): ?>
    <h2>
      <?php print _("Stack Trace:") ?>
    </h2>
    <div class="stack_trace">
      <?php print $templateData['stackTrace']; ?>
    </div>
    <?php endif; ?>

    <?php if (!empty($templateData['debug'])): ?>
    <h2>
      <?php print _("Debug Output:") ?>
    </h2>
    <div class="debug">
      <pre>
      <?php print $templateData['debug']; ?>
      </pre>
    </div>
    <?php endif; ?>

    <?php if ($templateData['anyUpgradeable']): ?>    
    <div class="go">
      <?php $nextStep = $stepNumber + 1 ?>
	  <div class="btn btn-continue"><span><span><span><span>
	<a href="<?php generateUrl('index.php?step=' . $nextStep) ?>"><?php printf(_('Skip Upgrade and Continue to Step %d&raquo;'), $nextStep); ?></a>
	  </span></span></span></span></div>
	  <div class="btn btn-continue"><span><span><span><span>
	<a href="javascript:document.forms[0].submit();"><?php print _('Upgrade Selected Modules') ?></a>
	  </span></span></span></span></div>
    </div>
    <?php endif; ?>
  <?php endif; ?>
