<?php
defined('ABSPATH') or die('No script kiddies please!!');
$std_metabox_details = get_post_meta($post->ID, '_std_metabox_details', true);
wp_nonce_field('std_metabox_nonce', 'std_metabox_nonce_field');
?>
<div class="std-field-wrap">
    <label><?php esc_html_e('Enable', 'subscribe-to-download'); ?></label>
    <div class="std-field">
        <input type="checkbox" name="std_metabox_details[enable_popup]" <?php echo (!empty($std_metabox_details['enable_popup'])) ? 'checked="checked"' : ''; ?> value="1" />
    </div>
</div>
<div class="std-field-wrap">
    <label><?php esc_html_e('Disable for already subscribed users', 'subscribe-to-download'); ?></label>
    <div class="std-field">
        <input type="checkbox" name="std_metabox_details[disabled_already_subscriber]" <?php echo (!empty($std_metabox_details['disabled_already_subscriber'])) ? 'checked="checked"' : ''; ?> value="1" />
    </div>
</div>
<div class="std-field-wrap">
    <label><?php esc_html_e('Disable when closed', 'subscribe-to-download'); ?></label>
    <div class="std-field">
        <input type="checkbox" name="std_metabox_details[disable_when_closed]" <?php echo (!empty($std_metabox_details['disable_when_closed'])) ? 'checked="checked"' : ''; ?> value="1" />
        <p class="description"><?php esc_html_e('Please enable this option if you want don\'t want to show the popup after it is closed', 'subscribe-to-download'); ?></p>
    </div>
</div>
<div class="std-field-wrap std-elem-block">
    <label><?php esc_html_e('Delay', 'subscribe-to-download'); ?></label>
    <div class="">
        <input type="number" name="std_metabox_details[delay]" min="0" value="<?php echo (!empty($std_metabox_details['delay'])) ? intval($std_metabox_details['delay']) : ''; ?>" />
        <p class="description"><?php esc_html_e('Please enter the delay time for popup display in seconds. Please leave empty or enter 0 to display with the page load.', 'subscribe-to-download'); ?></p>
    </div>
</div>
<div class="std-field-wrap std-elem-block">
    <label><?php esc_html_e('Subscription Form', 'subscribe-to-download') ?></label>
    <div class="">
        <select name="std_metabox_details[form_alias]">
            <option value=""><?php esc_html_e("Choose Form", 'subscribe-to-download'); ?></option>
            <?php
            $selected_form_alias = (!empty($std_metabox_details['form_alias'])) ? $std_metabox_details['form_alias'] : '';
            global $wpdb;
            $form_table = STD_FORM_TABLE;
            $forms = $wpdb->get_results("select * from $form_table order by form_title asc");
            if (!empty($forms)) {
                foreach ($forms as $form) {
            ?>
                    <option value="<?php echo esc_attr($form->form_alias); ?>" <?php selected($selected_form_alias, $form->form_alias); ?>><?php echo esc_attr($form->form_title); ?></option>
            <?php
                }
            }
            ?>
        </select>
    </div>
</div>