
<form action="?page=<?php echo $this -> sections -> links; ?>&method=mass" method="post" onsubmit="if (!confirm('<?php echo esc_js(__('Are you sure you want to apply this action to the selected links?', 'wp-mailinglist')); ?>')) { return false; }">
    <?php wp_nonce_field($this -> sections -> links . '_mass'); ?>
    <div class="tablenav">
        <div class="alignleft actions">
            <a href="?page=<?php echo $this -> sections -> clicks; ?>" class="button"><i class="fa-solid fa-arrow-pointer"></i> <?php _e('Clicks', 'wp-mailinglist'); ?></a>
        </div>
        <div class="alignleft actions">
            <select name="action">
                <option value=""><?php _e('- Bulk Actions -', 'wp-mailinglist'); ?></option>
                <option value="delete"><?php _e('Delete', 'wp-mailinglist'); ?></option>
                <option value="reset"><?php _e('Reset', 'wp-mailinglist'); ?></option>
            </select>
            <button value="1" type="submit" name="apply" class="button">
                <?php _e('Apply', 'wp-mailinglist'); ?>
            </button>
        </div>
        <?php $this -> render('pagination', array('paginate' => $paginate), true, 'admin'); ?>
    </div>
    <?php

    $orderby = (empty($_GET['orderby'])) ? 'modified' : esc_html($_GET['orderby']);
    $order = (empty($_GET['order'])) ? 'desc' : strtolower(esc_html($_GET['order']));
    $otherorder = ($order == "desc") ? 'asc' : 'desc';

    $colspan = 4;

    ?>
    <table class="widefat">
        <thead>
        <tr>
            <td class="check-column"><input type="checkbox" name="checkall" value="1" id="checkall" /></td>
            <th class="column-link <?php echo ($orderby == "link") ? 'sorted ' . $order : 'sortable desc'; ?>">
                <a href="<?php echo $Html -> retainquery('orderby=link&order=' . (($orderby == "link") ? $otherorder : "asc")); ?>">
                    <span><?php _e('Link', 'wp-mailinglist'); ?></span>
                    <span class="sorting-indicator"></span>
                </a>
            </th>
            <th><?php _e('Clicks', 'wp-mailinglist'); ?></th>
            <th class="column-modified <?php echo ($orderby == "modified") ? 'sorted ' . $order : 'sortable desc'; ?>">
                <a href="<?php echo $Html -> retainquery('orderby=modified&order=' . (($orderby == "modified") ? $otherorder : "asc")); ?>">
                    <span><?php _e('Date', 'wp-mailinglist'); ?></span>
                    <span class="sorting-indicator"></span>
                </a>
            </th>
        </tr>
        </thead>
        <tfoot>
        <tr>
            <td class="check-column"><input type="checkbox" name="checkall" value="1" id="checkall" /></td>
            <th class="column-link <?php echo ($orderby == "link") ? 'sorted ' . $order : 'sortable desc'; ?>">
                <a href="<?php echo $Html -> retainquery('orderby=link&order=' . (($orderby == "link") ? $otherorder : "asc")); ?>">
                    <span><?php _e('Link', 'wp-mailinglist'); ?></span>
                    <span class="sorting-indicator"></span>
                </a>
            </th>
            <th><?php _e('Clicks', 'wp-mailinglist'); ?></th>
            <th class="column-modified <?php echo ($orderby == "modified") ? 'sorted ' . $order : 'sortable desc'; ?>">
                <a href="<?php echo $Html -> retainquery('orderby=modified&order=' . (($orderby == "modified") ? $otherorder : "asc")); ?>">
                    <span><?php _e('Date', 'wp-mailinglist'); ?></span>
                    <span class="sorting-indicator"></span>
                </a>
            </th>
        </tr>
        </tfoot>
        <tbody>
        <?php if (empty($links)) : ?>
            <tr class="no-items">
                <td class="colspanchange" colspan="<?php echo esc_html($colspan); ?>"><?php _e('No links were found', 'wp-mailinglist'); ?></td>
            </tr>
        <?php else : ?>
            <?php $class = false; ?>
            <?php foreach ($links as $link) : ?>
                <tr class="<?php $class = (empty($class)) ? 'alternate' : false; ?>">
                    <th class="check-column"><input type="checkbox" name="links[]" value="<?php echo $link -> id; ?>" id="links_<?php echo $link -> id; ?>" /></th>
                    <td>
                        <a href="" class="row-title"><?php echo $Html -> link($link -> link, $link -> link, array('target' => "_blank")); ?></a>
                        <div class="row-actions">
                            <span class="delete"><?php echo ( $Html -> link(__('Delete', 'wp-mailinglist'), wp_nonce_url('?page=' . $this -> sections -> links . '&amp;method=delete&amp;id=' . $link -> id,   $this -> sections -> links . '_delete'), array('onclick' => "if (!confirm('" . __('Are you sure you want to delete this link?', 'wp-mailinglist') . "')) { return false; }", 'class' => "delete"))); ?> |</span>
                            <span class="view"><?php echo $Html -> link(__('Open Link', 'wp-mailinglist'), $link -> link, array('target' => "_blank")); ?></span>
                        </div>
                    </td>
                    <td>
                        <?php echo $Html -> link($this -> Click() -> count(array('link_id' => $link -> id)), '?page=' . $this -> sections -> clicks . '&amp;link_id=' . $link -> id); ?>
                    </td>
                    <td>
                        <abbr title="<?php echo $link -> modified; ?>"><?php echo $Html -> gen_date("Y-m-d", strtotime($link -> modified)); ?></abbr>
                    </td>
                </tr>
            <?php endforeach; ?>
        <?php endif; ?>
        </tbody>
    </table>
    <div class="tablenav">
        <div class="alignleft">
            <?php if (empty($_GET['showall'])) : ?>
                <select class="widefat" style="width:auto;" name="perpage" onchange="change_perpage(this.value);">
                    <option value=""><?php _e('- Per Page -', 'wp-mailinglist'); ?></option>
                    <?php $p = 5; ?>
                    <?php while ($p < 100) : ?>
                        <option <?php echo (isset($_COOKIE[$this -> pre . 'linksperpage']) && !empty(esc_html($_COOKIE[$this -> pre . 'linksperpage'])) && esc_html($_COOKIE[$this -> pre . 'linksperpage']) == $p) ? 'selected="selected"' : ''; ?> value="<?php echo $p; ?>"><?php echo $p; ?> <?php _e('per page', 'wp-mailinglist'); ?></option>
                        <?php $p += 5; ?>
                    <?php endwhile; ?>
                    <?php if (isset($_COOKIE[$this -> pre . 'linksperpage'])) : ?>
                        <option selected="selected" value="<?php echo esc_html($_COOKIE[$this -> pre . 'linksperpage']); ?>"><?php echo esc_html($_COOKIE[$this -> pre . 'linksperpage']); ?></option>
                    <?php endif; ?>
                </select>
            <?php endif; ?>

            <script type="text/javascript">
                function change_perpage(perpage) {
                    if (perpage != "") {
                        document.cookie = "<?php echo $this -> pre; ?>linksperpage=" + perpage + "; expires=<?php echo $Html -> gen_date($this -> get_option('cookieformat'), strtotime("+30 days")); ?> UTC; path=/";
                        window.location = "<?php echo preg_replace("/\&?" . $this -> pre . "page\=(.*)?/si", "", $_SERVER['REQUEST_URI']); ?>";
                    }
                }
            </script>
        </div>
        <?php $this -> render('pagination', array('paginate' => $paginate), true, 'admin'); ?>
    </div>
</form>