<?php use PMA\libraries\Template; ?>
<form class="submenu-item" action="server_privileges.php" id="<?= $formId; ?>" method="post">
    <?= PMA\libraries\URL::getHiddenInputs(); ?>
    <input type="hidden" name="username" value="<?= htmlspecialchars($userName); ?>" />
    <input type="hidden" name="hostname" value="<?= htmlspecialchars($hostName); ?>" />

    <fieldset>
        <legend data-submenu-label="<?= $subMenuLabel; ?>">
            <?= $legend; ?>
        </legend>

        <table class="data">
            <thead>
                <tr>
                    <th><?= $typeLabel; ?></th>
                    <th><?= __('Privileges'); ?></th>
                    <th><?= __('Grant'); ?></th>
                    <?php if ($type == 'database') : ?>
                        <th><?= __('Table-specific privileges'); ?></th>
                    <?php elseif ($type == 'table') : ?>
                        <th><?= __('Column-specific privileges'); ?></th>
                    <?php endif; ?>
                    <th colspan="2"><?= __('Action'); ?></th>
                </tr>
            </thead>

            <tbody>
                <?php if (count($privileges) == 0) : ?>
                    <?php $colspan = ($type == 'database' ? 7 : ($type == 'table' ? 6 : 5)); ?>
                    <tr>
                        <td colspan="<?= $colspan; ?>"><center><i><?= __('None') ?></i></center></td>
                    </tr>
                <?php else : ?>
                    <?php foreach ($privileges as $privilege) : ?>
                        <?= Template::get('privileges/privileges_summary_row')
                                ->render(
                                    array_merge(
                                        $privilege,
                                        array(
                                            'type' => $type,
                                        )
                                    )
                                ); ?>
                    <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>

        <?php if ($type == 'database') : ?>
            <?= Template::get('privileges/add_privileges_database')
                    ->render(array('databases' => $databases)); ?>
        <?php elseif ($type == 'table') : ?>
            <?= Template::get('privileges/add_privileges_table')
                    ->render(array('database' => $database, 'tables' => $tables)); ?>
        <?php else: // routine ?>
            <?= Template::get('privileges/add_privileges_routine')
                    ->render(array('database' => $database, 'routines' => $routines)); ?>
        <?php endif; ?>

    </fieldset>

    <fieldset class="tblFooters">
        <input type="submit" value="<?= __('Go'); ?>" />
    </fieldset>
</form>
