<?php
defined('ABSPATH') or die('No script kiddies please!!');
?>
<div class="wrap std-wrap">
    <div class="std-header std-clearfix">
        <h1 class="std-floatLeft">
            <img src="<?php echo STD_URL . 'images/logo.png' ?>" class="std-plugin-logo" />
            <span class="std-sub-header"><?php esc_html_e('Subscription Forms', 'subscribe-to-download'); ?></span>
        </h1>
        <div class="std-add-wrap">
            <a href="<?php echo admin_url('admin.php?page=add-subscription-form'); ?>"><input type="button" class="std-button-white" value="<?php esc_html_e('Add New Form', 'subscribe-to-download'); ?>"></a>
        </div>
    </div>
    <div class="std-form-wrap">

        <table class="wp-list-table widefat fixed std-form-lists-table">
            <thead>
                <tr>
                    <th><?php esc_html_e('Form Title', 'subscribe-to-download'); ?></th>
                    <th><?php esc_html_e('Alias', 'subscribe-to-download'); ?></th>
                    <th><?php esc_html_e('Shortcode', 'subscribe-to-download'); ?></th>
                    <th><?php esc_html_e('Status', 'subscribe-to-download'); ?></th>
                    <th><?php esc_html_e('Action', 'subscribe-to-download'); ?></th>
                </tr>
            </thead>
            <tbody>
                <?php
                global $wpdb;
                $form_table = STD_FORM_TABLE;
                $form_rows = $wpdb->get_results("select * from $form_table order by form_title asc");
                if (!empty($form_rows)) {
                    foreach ($form_rows as $form_row) {
                        ?>
                        <tr>
                            <td>
                                <a href="<?php echo admin_url('admin.php?page=subscribe-to-download&form_id=' . $form_row->form_id . '&action=edit_form'); ?>" title="<?php esc_html_e('Edit Form', 'subscribe-to-download'); ?>"><?php echo esc_attr($form_row->form_title); ?></a>
                            </td>
                            <td><?php echo esc_attr($form_row->form_alias); ?></td>
                            <td>
                                <span class="std-shortcode-preview">[std alias="<?php echo esc_attr($form_row->form_alias); ?>"]</span>
                                <span class="std-clipboard-copy"><i class="fas fa-clipboard-list"></i></span>
                            </td>
                            <td><?php echo (!empty($form_row->form_status)) ? esc_html__('Active', 'subscribe-to-download') : esc_html__('Inactive', 'subscribe-to-download'); ?></td>
                            <td>
                                <a class="std-edit" href="<?php echo admin_url('admin.php?page=subscribe-to-download&form_id=' . $form_row->form_id . '&action=edit_form'); ?>" title="<?php esc_html_e('Edit Form', 'subscribe-to-download'); ?>"><?php esc_html_e('Edit', 'subscribe-to-download'); ?></a>
                                <a class="std-copy std-form-copy" href="javascript:void(0);" data-form-id="<?php echo intval($form_row->form_id); ?>" title="<?php esc_html_e('Copy Form', 'subscribe-to-download'); ?>"><?php esc_html_e('Copy', 'subscribe-to-download'); ?></a>
                                <a class="std-preview" href="<?php echo home_url() . '?std_preview=true&form_alias=' . esc_attr($form_row->form_alias) . '&_wpnonce=' . wp_create_nonce('std_form_preview_nonce'); ?>" target="_blank" title="<?php esc_html_e('Preview', 'subscribe-to-download'); ?>"><?php esc_html_e('Preview', 'subscribe-to-download'); ?></a>
                                <a class="std-delete std-form-delete" href="javascript:void(0)" data-form-id="<?php echo intval($form_row->form_id); ?>" title="<?php esc_html_e('Delete Form', 'subscribe-to-download'); ?>"><?php esc_html_e('Delete', 'subscribe-to-download'); ?></a>
                            </td>
                        </tr>
                        <?php
                    }
                } else {
                    ?>
                    <tr>
                        <td colspan="5"><?php esc_html_e('No forms added yet.', 'subscribe-to-download'); ?></td>
                    </tr>
                    <?php
                }
                ?>
            </tbody>
            <tfoot>
                <tr>
                    <th><?php esc_html_e('Form Title', 'subscribe-to-download'); ?></th>
                    <th><?php esc_html_e('Alias', 'subscribe-to-download'); ?></th>
                    <th><?php esc_html_e('Shortcode', 'subscribe-to-download'); ?></th>
                    <th><?php esc_html_e('Status', 'subscribe-to-download'); ?></th>
                    <th><?php esc_html_e('Action', 'subscribe-to-download'); ?></th>
                </tr>
            </tfoot>
        </table>
    </div>
</div>
<div class="std-form-message"></div>
