<table cellpadding="0" cellspacing="6" border="0" width="100%">
<?php
    $covered = array();
    foreach ($layout as $row_num => $row) {
        echo "<tr>\n";

        foreach ($row as $col_num => $item) {
            if (isset($covered[$row_num]) && isset($covered[$row_num][$col_num])) {
                echo "<!-- covered cell here -->\n";
            } elseif (is_a($item, 'Horde_Block')) {
                echo sprintf('<td class="summarytext" valign="top" width="%s%%" rowspan="%s" colspan="%s">', floor(100/count($row)), $item->getHeight(), $item->getWidth());

                // Remember which cells this one covers
                for ($i = 0; $i < $item->getHeight(); $i++) {
                    if (!isset($covered[$row_num + $i])) {
                        $covered[$row_num + $i] = array();
                    }
                    for ($j = 0; $j < $item->getWidth(); $j++) {
                        $covered[$row_num + $i][$col_num + $j] = true;
                    }
                }

                // Show edit version?
                if (isset($edit[$row_num]) && isset($edit[$row_num][$col_num])) {
                    echo $item->displayLayoutBlock(Horde::selfUrl(), $col_num, $row_num, $blocks, true);
                } else {
                    echo $item->displayLayoutBlock(Horde::selfUrl(), $col_num, $row_num, $blocks, false);
                }
                echo "</td>\n";
            } else {
                echo sprintf('<td class="summarytext" valign="top" width="%s%%">', floor(100/count($row)));
                echo _("Add Here:");
                ?>
                <br/>
                <form action="<?php echo Horde::selfUrl() ?>" method='post'>
                  <?php Horde::pformInput() ?>
                  <input type="hidden" name="row" value="<?php echo $row_num ?>" />
                  <input type="hidden" name="col" value="<?php echo $col_num ?>" />
                  <input type="hidden" name="action" value="save-resume" />
                  <select name="app">
                    <?php echo $blockselectoptions ?>
                  </select>
                  <input type="submit" class="button" value="<?php echo _("Add") ?>" />
                </form>
                </td>
<?php
            }
        }
        echo "</tr>\n";
    }

    echo "<tr>\n";

    reset($layout);
    for ($i = 0; $i < count(current($layout)); $i++) {
        echo '<td valign="top" class="summarytext" >';
        echo _("Add Here:") ?>
        <br/>
        <form action="<?php echo Horde::selfUrl() ?>" method='post'>
          <?php Horde::pformInput() ?>
          <input type="hidden" name="row" value="<?php echo count($layout) ?>" />
          <input type="hidden" name="col" value="<?php echo $i ?>" />
          <input type="hidden" name="action" value="save-resume" />
          <select name="app">
            <?php echo $blockselectoptions ?>
          </select>
          <input type="submit" class="button" value="<?php echo _("Add") ?>" />
        </form>
        </td>
<?php
    }
?>
  </tr>
</table>
