<?php defined('ABSPATH') or die('No script kiddies please!'); ?>
<?php
if (isset($_GET['action'], $_GET['id'])) {
    include(WPFM_PRO_FILE_ROOT_DIR . 'inc/backend/menu-actions/edit-menu.php');
} else {
    ?>
    <div class="wpfm-wrapper wpfm-clear">
        <div class="wpfm-head">     
            <?php include(WPFM_PRO_FILE_ROOT_DIR . 'inc/backend/includes/wpfm-header.php'); ?> 
        </div> 
        <?php
        $options = get_option(WPFM_SETTINGS);
        if (isset($_SESSION['wpfmp_message'])) {
            ?>
            <div class="wpfm-message notice notice-success is-dismissible">
                <p><?php
                    echo $_SESSION['wpfmp_message'];
                    unset($_SESSION['wpfmp_message']);
                    ?>
                </p>
            </div>
        <?php } ?>  
        <div class="wpfm-inner-wrapper" id="poststuff">
            <div id="post-body-full" class="metabox-holder columns-2">
                <div id="post-body-content">
                    <div class="postbox">
                        <div class="wpfm-backend-wrapper clearfix" id="col-container">
                            <div class="inside" id="wpfm-menu-setting-wrapper">
                                <div class="wpfm-header-title">
                                    <div class="wpfm-menu-header-left">
                                        <?php _e('Navigation Menu', 'wp-floating-menu-pro'); ?>
                                    </div>
                                    <div class="wpfm-menu-header-right">
                                        <a href="<?php echo admin_url() . 'admin.php?page=wpfmp-add-menu' ?>" class="wpfm-add-new-menu">
                                            <?php _e('Add New Menu', 'wp-floating-menu-pro'); ?></a>
                                    </div>
                                </div>
                                <?php
                                global $wpdb;
                                $table_name = $wpdb->prefix . "wp_floating_menu_details";
                                $menu_lists = $wpdb->get_results("SELECT * FROM $table_name ORDER BY ID DESC");
                                ?>
                                <table class="wp-list-table widefat fixed posts apct-table">
                                    <thead>
                                        <tr>
                                            <th scope="col" id="name" class="manage-column column-shortcode">
                                                <?php _e('Menu Title', 'wp-floating-menu-pro'); ?>
                                            </th>
                                            <th scope="col" id="menu-bar-position" class="manage-column column-shortcode">
                                                <?php _e('Menu Position', 'wp-floating-menu-pro'); ?>
                                            </th>
                                            <th scope="col" id="menu-status" class="manage-column column-shortcode">
                                                <?php _e('Template', 'wp-floating-menu-pro'); ?>
                                            </th>
                                            <th scope="col" id="menu-status" class="manage-column column-shortcode">
                                                <?php _e('Custom Template', 'wp-floating-menu-pro'); ?>
                                            </th>  
                                        </tr>
                                    </thead>
                                    <tfoot>
                                        <tr>
                                            <th scope="col" id="name" class="manage-column column-shortcode">
                                                <?php _e('Menu Title', 'wp-floating-menu-pro'); ?>
                                            </th>
                                            <th scope="col" id="menu-bar-position" class="manage-column column-shortcode">
                                                <?php _e('Menu Position', 'wp-floating-menu-pro'); ?>
                                            </th>
                                            <th scope="col" id="menu-status" class="manage-column column-shortcode">
                                                <?php _e('Template', 'wp-floating-menu-pro'); ?>
                                            </th>
                                            <th scope="col" id="menu-status" class="manage-column column-shortcode">
                                                <?php _e('Custom Template', 'wp-floating-menu-pro'); ?>
                                            </th>  
                                        </tr>
                                    </tfoot>
                                    <?php
                                    $counter = 1;
                                    if (count($menu_lists) > 0) {
                                        foreach ($menu_lists as $row) {
                                            $menu_settings = unserialize($row->menu_display_setting_details);
                                            $wpfm_duplicate_nonce = wp_create_nonce('wpfm-duplicate-menu-settings-nonce');
                                            $wpfm_delete_nonce = wp_create_nonce('wpfm-remove-menu-settings-nonce');
                                            ?>
                                            <tbody id="the-list">
                                                <tr class="<?php if ($counter % 2 != 0) { ?>alternate<?php } ?>">
                                                    <td class="title column-title has-row-actions"> 
                                                        <a href="<?php echo admin_url('admin.php?page=wpfmp-admin&action=wpfmp-edit-menu&id=' . $row->id); ?>" class="wpfm-menu-action-button"><?php echo esc_attr($row->menu_name); ?></a>   
                                                        <div id="wpfm-menu-action" class="row-actions" >
                                                            <span class="wpfm-menu-edit-entry">
                                                                <a href="<?php echo admin_url('admin.php?page=wpfmp-admin&action=wpfmp-edit-menu&id=' . $row->id); ?>" class="wpfm-menu-action-button"><?php _e('Edit', 'wp-floating-menu-pro'); ?> |</a>
                                                                <input type="hidden" name="current_post_id" value="<?php echo $row->id; ?>" /> 
                                                            </span>
                                                            <span class="wpfm-menu-preview-entry">
                                                                <a href="<?php echo site_url('?wpfmp_preview=true&menu_id=' . $row->id); ?>"  target="_blank"><?php _e('Preview', 'wp-floating-menu-pro') ?> |</a>
                                                            </span>
                                                            <span class="wpfm-menu-duplicate-entry">
                                                                <a class="wpfm-btn-wrap" href="<?php echo admin_url() . 'admin-post.php?action=wpfm_menu_duplicate_options&_wpnonce=' . $wpfm_duplicate_nonce . '&id=' . $row->id ?>" onclick="return confirm('<?php _e('Duplicate This Menu?', 'wp-floating-menu-pro'); ?>')"><?php _e('Duplicate', 'wp-floating-menu-pro'); ?> |</a>
                                                            </span>
                                                            <span class="wpfm-menu-delete-entry">
                                                                <a class="wpfm-btn-wrap" href="<?php echo admin_url() . 'admin-post.php?action=wpfm_menu_delete_options&_wpnonce=' . $wpfm_delete_nonce . '&id=' . $row->id ?>" onclick="return confirm('<?php _e('Delete This Menu? There is no undo.', 'wp-floating-menu-pro'); ?>')"><?php _e('Delete', 'wp-floating-menu-pro'); ?></a>
                                                            </span>

                                                        </div>
                                                    </td>
                                                    <td class="title column-title">
                                                        <?php
                                                        if (isset($menu_settings['menu_design']['template_number']) && ($menu_settings['menu_design']['template_number'] == 'template-11' || $menu_settings['menu_design']['template_number'] == 'template-12' || $menu_settings['menu_design']['template_number'] == 'template-13')) {
                                                            if (isset($menu_settings['menu_design']['cmenu_placement']) && $menu_settings['menu_design']['cmenu_placement'] == 'top-left') {
                                                                echo __('Top Left', 'wp-floating-menu-pro');
                                                            } else if (isset($menu_settings['menu_design']['cmenu_placement']) && $menu_settings['menu_design']['cmenu_placement'] == 'left') {
                                                                echo __('Middle Left', 'wp-floating-menu-pro');
                                                            } else if (isset($menu_settings['menu_design']['cmenu_placement']) && $menu_settings['menu_design']['cmenu_placement'] == 'bottom-left') {
                                                                echo __('Bottom Left', 'wp-floating-menu-pro');
                                                            } else if (isset($menu_settings['menu_design']['cmenu_placement']) && $menu_settings['menu_design']['cmenu_placement'] == 'top-right') {
                                                                echo __('Top Right', 'wp-floating-menu-pro');
                                                            } else if (isset($menu_settings['menu_design']['cmenu_placement']) && $menu_settings['menu_design']['cmenu_placement'] == 'right') {
                                                                echo __('Middle Right', 'wp-floating-menu-pro');
                                                            } else if (isset($menu_settings['menu_design']['cmenu_placement']) && $menu_settings['menu_design']['cmenu_placement'] == 'bottom-right') {
                                                                echo __('Bottom Right', 'wp-floating-menu-pro');
                                                            } else if (isset($menu_settings['menu_design']['cmenu_placement']) && $menu_settings['menu_design']['cmenu_placement'] == 'bottom-center') {
                                                                echo __('Bottom Center', 'wp-floating-menu-pro');
                                                            }
                                                        } else {
                                                            if (isset($menu_settings['menu_design']['menu_placement']) && $menu_settings['menu_design']['menu_placement'] == 'top-left') {
                                                                echo __('Top Left', 'wp-floating-menu-pro');
                                                            } else if (isset($menu_settings['menu_design']['menu_placement']) && $menu_settings['menu_design']['menu_placement'] == 'left') {
                                                                echo __('Middle Left', 'wp-floating-menu-pro');
                                                            } else if (isset($menu_settings['menu_design']['menu_placement']) && $menu_settings['menu_design']['menu_placement'] == 'bottom-left') {
                                                                echo __('Bottom Left', 'wp-floating-menu-pro');
                                                            } else if (isset($menu_settings['menu_design']['menu_placement']) && $menu_settings['menu_design']['menu_placement'] == 'top-right') {
                                                                echo __('Top Right', 'wp-floating-menu-pro');
                                                            } else if (isset($menu_settings['menu_design']['menu_placement']) && $menu_settings['menu_design']['menu_placement'] == 'right') {
                                                                echo __('Middle Right', 'wp-floating-menu-pro');
                                                            } else if (isset($menu_settings['menu_design']['menu_placement']) && $menu_settings['menu_design']['menu_placement'] == 'bottom-right') {
                                                                echo __('Bottom Right', 'wp-floating-menu-pro');
                                                            }
                                                        }
                                                        ?>
                                                    </td>
                                                    <td class="title column-title">
                                                        <?php
                                                        if (isset($menu_settings['menu_design']['menu_template_style']) && $menu_settings['menu_design']['menu_template_style'] == 'buildin') {
                                                            $title_id = explode("-", esc_attr($menu_settings['menu_design']['template_number']));
                                                            echo __('Template', 'wp-floating-menu-pro') .' '. $title_id[1];
                                                        } else if (isset($menu_settings['menu_design']['menu_template_style']) && $menu_settings['menu_design']['menu_template_style'] == 'custom-template') {
                                                            echo __('Custom Template', 'wp-floating-menu-pro');
                                                        }
                                                        ?>
                                                    </td>
                                                    <td>
                                                        <?php
                                                        if (isset($menu_settings['menu_design']['menu_template_style']) && $menu_settings['menu_design']['menu_template_style'] == 'custom-template') {
                                                            if (isset($menu_settings['menu_design']['custom_template_type']) && !empty($menu_settings['menu_design']['custom_template_type'])) {
                                                                global $wpdb;
                                                                $table_name = $wpdb->prefix . "wp_floating_menu_custom_templates";
                                                                $template_detail = $wpdb->get_results("SELECT * FROM $table_name WHERE id=" . esc_attr($menu_settings['menu_design']['custom_template_type']));
                                                                foreach ($template_detail as $row) {
                                                                    $custom_template_name = esc_attr($row->template_name);
                                                                    $template_design_settings = unserialize($row->template_details);
                                                                    $custom_defined_template_name = isset($template_design_settings['custom_template']['menu_layout']) ? esc_attr($template_design_settings['custom_template']['menu_layout']) : '';
                                                                    $title_id = explode("-", $custom_defined_template_name);

                                                                    echo $custom_template_name . ' ( ' . __('Template', 'wp-floating-menu-pro') . ' ' . $title_id[1] . ' )';
                                                                }
                                                            } else {
                                                                echo __('Unnamed Template', 'wp-floating-menu-pro');
                                                            }
                                                        } else {
                                                            echo '<span class="wpfm-dash-default">-</span>';
                                                        }
                                                        ?>
                                                    </td>
                                                </tr>
                                            </tbody>
                                            <?php
                                            $counter++;
                                        }
                                    } else {
                                        ?> 
                                        <tbody id="the-list">
                                            <tr class="alternate">
                                                <td class="title column-title has-row-actions" ></td> 
                                                <td class="title column-title has-row-actions" >
                                                    <strong style="text-align:center"><?php _e('No Menu To Display. Try Adding New Menu', 'wp-floating-menu-pro'); ?></strong>
                                                </td>
                                                <td class="title column-title has-row-actions" ></td> 
                                            </tr>
                                        </tbody>
                                    <?php } ?>
                                </table>
                            </div><!-- .inside #wpfm-menu-setting-wrapper-->
                        </div><!--  .wpfm backend wrapper --> 
                    </div><!-- .postbox -->
                </div> <!-- #post-body-content -->
                <div id="postbox-container-1" class="postbox-container" style="display:none;">
                    <?php //include(WPFM_PRO_FILE_ROOT_DIR. 'inc/backend/includes/wpfm-sidebar.php');     ?>
                </div> <!-- #postbox-container-1 .postbox-container -->
            </div><!-- .metabox-holder columns-2 #post-body -->
        </div><!-- .poststuff -->
    </div>
    <?php
} 