<?php

/*if(isset($_POST[BBWP_SEO]) && is_array($_POST[BBWP_SEO]) && count($_POST[BBWP_SEO]) >= 1){
    $this->save_form_data($_POST[BBWP_SEO]);
  }*/
if ($this->get_option('reset_bbseo') && $this->get_option('reset_bbseo') == 'yes') {
    $this->set_option('reset_bbseo', 'No');
    $this->update_db(true);
}
?>
<div class="wrap bytebunch_seo_container"><div id="icon-tools" class="icon32"></div>
<?php 
BBWPUpdateErrorMessage();
?>
<form method="post" action="options.php">
  <!-- <form method="post" action=""> -->
      <?php 
settings_fields(BBWP_SEO);
//db($this);
?>
      <h2> Titles & Metas - BBWP SEO </h2>
      <ul class="tabbed_menu">
         <li><a href="#bytebunch_seo_tab1">Home Page</a></li>
         <li><a href="#bytebunch_seo_tab2">Post Types</a></li>
         <li><a href="#bytebunch_seo_tab3">Taxonomies</a></li>
         <li><a href="#bytebunch_seo_tab4">Archives</a></li>
         <li><a href="#bytebunch_seo_tab5">Special Pages</a></li>
         <li><a href="#bytebunch_seo_tab6">Other</a></li>
      </ul>
      <div class="clearboth" style="border-top:1px solid #ccc;"></div>
      <div class="setting_pages_content_wrapper">
 public function user_created_menu_pages()
 {
     if ($this->user_created_pages && is_array($this->user_created_pages) && count($this->user_created_pages) >= 1) {
         echo '<div class="wrap bytebunch_admin_page_container"><div id="icon-tools" class="icon32"></div>';
         echo '<form method="post" action="">';
         $current_page = false;
         foreach ($this->user_created_pages as $page) {
             if (isset($_GET['page']) && $_GET['page'] === $page['page_slug'] && $current_page == false) {
                 $current_page = $page;
                 echo '<h2>' . $page['page_title'] . '</h2>';
             }
         }
         if (count($this->user_created_metaboxes) >= 1 && $current_page) {
             foreach ($this->user_created_metaboxes as $key => $value) {
                 if (isset($value["metabox_pages"]) && $value["metabox_pages"] === $current_page['page_slug']) {
                     $BBWPFieldTypes = new BBWPFieldTypes($this->prefix($key));
                     $BBWPFieldTypes->SaveOptions();
                     BBWPUpdateErrorMessage();
                     echo '<h3>' . $value['metabox_title'] . '</h3>';
                     $BBWPFieldTypes->DisplayOptions();
                 }
             }
         }
         submit_button();
         echo '</form>';
         echo '</div>';
     }
 }
    public function add_submenu_page()
    {
        echo '<div class="wrap bytebunch_admin_page_container"><div id="icon-tools" class="icon32"></div>';
        $metaboxes_select_list = false;
        $user_created_metaboxes = SerializeStringToArray(get_option($this->prefix('user_created_metaboxes')));
        $user_created_pages = SerializeStringToArray(get_option($this->prefix('user_created_pages')));
        $current_selected_metabox = $this->get_bbcf_option("selected_metabox");
        if (isset($user_created_metaboxes) && is_array($user_created_metaboxes) && count($user_created_metaboxes) >= 1) {
            $metaboxes_select_list = '<select class="submit_on_change" name="' . $this->prefix("current_selected_metabox") . '">';
            foreach ($user_created_metaboxes as $key => $value) {
                if ($current_selected_metabox == $key) {
                    $metaboxes_select_list .= '<option value="' . $key . '" selected="selected">' . $value['metabox_title'] . '</option>';
                } else {
                    $metaboxes_select_list .= '<option value="' . $key . '">' . $value['metabox_title'] . '</option>';
                    if (!$current_selected_metabox) {
                        $current_selected_metabox = $key;
                        $this->set_bbcf_option("selected_metabox", $key);
                    }
                }
            }
            $metaboxes_select_list .= '</select>';
        }
        echo '<h2> BBWP Custom Fields </h2>';
        if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['meta_key']) && $_GET['meta_key']) {
            $BBWPFieldTypes = new BBWPFieldTypes($this->prefix($current_selected_metabox));
            BBWPUpdateErrorMessage();
            echo '<form method="post" action="">';
            $BBWPFieldTypes->AddNewFields($_GET['meta_key']);
            echo '</form>';
            return;
        } elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['metabox_id']) && $_GET['metabox_id']) {
            BBWPUpdateErrorMessage();
            $this->CreateMetaboxForm($user_created_metaboxes, $_GET['metabox_id']);
            return;
        } elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['page_slug']) && $_GET['page_slug']) {
            BBWPUpdateErrorMessage();
            $this->CreatePageForm($user_created_pages, $_GET['page_slug']);
            return;
        }
        BBWPUpdateErrorMessage();
        ?>
    <h2 class="nav-tab-wrapper bbwp_nav_wrapper">
      <?php 
        if ($metaboxes_select_list) {
            echo '<a href="#add-new-fields" class="nav-tab nav-tab-active">Edit or Add Fields</a>';
        }
        ?>
      <a href="#add-new-metabox" class="nav-tab">Meta Boxes</a>
      <a href="#add-new-option-page" class="nav-tab">Option Pages</a>
    </h2>

    <div class="bbwp_tab_nav_content" id="add-new-metabox" style="display:none;">
      <?php 
        $this->CreateMetaboxForm($user_created_metaboxes);
        if ($metaboxes_select_list) {
            echo '<form method="post" action=""><h3>Existing Meta Boxes</h3>';
            $tableColumns = array("metabox_id" => "Meta Box ID", "metabox_title" => "Meta Box Title");
            $BBWPListTable = new BBWPListTable();
            $BBWPListTable->get_columns($tableColumns);
            $BBWPListTable->bulk_actions = array("delete" => "Delete Selected");
            $BBWPListTable->get_sortable_columns(array("metabox_id" => "metabox_id"));
            $BBWPListTable->actions = array('metabox_id' => array('delete', 'edit'));
            $BBWPListTable->prepare_items($user_created_metaboxes);
            $BBWPListTable->display();
            echo '<input type="hidden" name="sort_fields" value="' . $this->prefix('user_created_metaboxes') . '" />';
            submit_button('Save Changes', 'primary alignright');
            echo '</form>';
        }
        ?>
    </div><!-- add-new-metabox -->
    <div class="bbwp_tab_nav_content" id="add-new-option-page" style="display:none;">
      <?php 
        $this->CreatePageForm($user_created_pages);
        if ($user_created_pages && is_array($user_created_pages) && count($user_created_pages) >= 1) {
            echo '<form method="post" action=""><h3>Existing Option pages</h3>';
            $tableColumns = array("page_slug" => "Page Slug", "page_title" => "Page Title");
            $BBWPListTable = new BBWPListTable();
            $BBWPListTable->get_columns($tableColumns);
            $BBWPListTable->bulk_actions = array("delete" => "Delete Selected");
            $BBWPListTable->get_sortable_columns(array("page_slug" => "page_slug"));
            $BBWPListTable->actions = array('page_slug' => array('delete', 'edit'));
            $BBWPListTable->prepare_items($user_created_pages);
            $BBWPListTable->display();
            echo '<input type="hidden" name="sort_fields" value="' . $this->prefix('user_created_pages') . '" />';
            submit_button('Save Changes', 'primary alignright');
            echo '</form>';
        }
        ?>
    </div>
    <div class="bbwp_tab_nav_content" id="add-new-fields">
      <?php 
        if ($metaboxes_select_list) {
            echo '<form method="post" action="">
        <table class="form-table"><tr><th>Selected Meta Box :</th><td>' . $metaboxes_select_list . '</td></tr>';
            echo '</table></form>';
            echo '<form method="post" action="">';
            $BBWPFieldTypes = new BBWPFieldTypes($this->prefix($current_selected_metabox));
            $BBWPFieldTypes->AddNewFields();
            echo '</form>';
            $existing_values = SerializeStringToArray(get_option($this->prefix($current_selected_metabox)));
            if (isset($existing_values) && is_array($existing_values) && count($existing_values) >= 1) {
                echo '<form method="post" action="">';
                $tableColumns = array("meta_key" => "Meta Key", "field_title" => "Field Title", 'field_type' => 'Field Type');
                $BBWPListTable = new BBWPListTable();
                $BBWPListTable->get_columns($tableColumns);
                $BBWPListTable->bulk_actions = array("delete" => "Delete Selected");
                $BBWPListTable->get_sortable_columns(array("meta_key" => "meta_key"));
                $BBWPListTable->actions = array('meta_key' => array('delete', 'edit'));
                $BBWPListTable->prepare_items($existing_values);
                $BBWPListTable->display();
                echo '<input type="hidden" name="sort_fields" value="' . $this->prefix($current_selected_metabox) . '" />';
                submit_button('Save Changes', 'primary alignright');
                echo '</form>';
            }
        }
        ?>
    </div>


    <?php 
        echo '</div><!-- main wrap div end here -->';
    }