<?php
/**
 * Displays Custom Fields Options Page
 * 
 * This file is a template for wp-admin / Classifieds / Options / Custom Fields panel. 
 * 
 * It is being loaded by wpadverts_custom_fields_page_options function.
 * 
 * @see wpadverts_custom_fields_page_options()
 * @since 1.0.0
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;

?>
<div class="wrap">

    <h2 class="">
        <?php _e("Custom Fields", "wpadverts-custom-fields") ?>
    </h2>

    <h2 class="nav-tab-wrapper">
        <a href="<?php echo esc_attr( remove_query_arg( array( 'adaction' ) ) ) ?>" class="nav-tab nav-tab-active"><?php _e("Form Schemes", "wpadverts-custom-fields") ?></a>
        <a href="<?php echo esc_attr( add_query_arg( array('cfpanel' => 'data-sources') ) ) ?>" class="nav-tab "><?php _e("Data Sources", "wpadverts-custom-fields") ?></a>
    </h2>
    
    <h2 class="">
        <a class="add-new-h2" href="<?php echo esc_attr( add_query_arg('add', 'new') ) ?>"><?php _e("+ New Form Scheme", "wpadverts-custom-fields") ?></a> </h1>
    </h2>
    
    <?php adverts_admin_flash() ?>

    <table cellspacing="0" class="widefat post fixed">
        <?php foreach(array("thead", "tfoot") as $tx): ?>
        <<?php echo $tx; ?>>
            <tr>
                <th style="" class="" scope="col"><?php _e("Form", "wpadverts-custom-fields") ?></th>
                <th style="" class="" scope="col"><?php _e("Type (Is Default)", "wpadverts-custom-fields") ?></th>
                <th style="" class="" scope="col"><?php _e("Name", "wpadverts-custom-fields") ?></th>

            </tr>
        </<?php echo $tx; ?>>
        <?php endforeach; ?>

        <tbody>
            <?php $i = 0; ?>
            <?php foreach( array_keys( wpadverts_custom_fields_form_types() ) as $post_status ): ?>
            <?php $loop = new WP_Query( array_merge( $loop_args, array( "post_status" => $post_status ) ) ) ?>
            <?php if( $loop->found_posts == 0 ) continue; ?>
            <?php foreach($loop->posts as $j => $item): ?>
            <tr valign="top" class="<?php if($i%2==0): ?>alternate <?php endif; ?>  author-self status-publish iedit">
                <td class="">
                    <strong>
                        <a href="<?php esc_attr_e(add_query_arg('edit', $item->ID)) ?>" class=""><?php echo esc_html( $item->post_title ) ?></a>
                    </strong>
                    <div class="row-actions" style="">
                        <span class="edit"><a href="<?php esc_attr_e(add_query_arg('edit', $item->ID)) ?>"><?php _e("Edit Form", "wpadverts-custom-fields") ?></a> | </span>
                        <span class=""><a href="<?php esc_attr_e( add_query_arg( array( "delete" => $item->ID,"noheader" => 1 ) ) ) ?>" title="<?php _e("Delete") ?>" class="adverts-delete"><?php _e("Delete") ?></a> | </span>
                    </div>
                </td>
                <td class="">
                    <?php $icon_c = '<span class="dashicons dashicons-megaphone"></span>'; ?>
                    <?php $icon_a = '<span class="dashicons dashicons-arrow-right-alt"></span>'; ?>
                    <?php if($item->post_status == 'wpad-form-add'): ?>
                    <?php echo sprintf( __( "%s Classifieds %s Create", 'wpadverts-custom-fields' ), $icon_c, $icon_a ) ?>
                    <?php elseif($item->post_status == 'wpad-form-search'): ?>
                    <?php echo sprintf( __( "%s Classifieds %s Search", 'wpadverts-custom-fields' ), $icon_c, $icon_a ) ?>
                    <?php elseif($item->post_status == 'wpad-form-contact'): ?>
                    <?php echo sprintf( __( "%s Classifieds %s Contact", 'wpadverts-custom-fields' ), $icon_c, $icon_a ) ?>
                    <?php else: ?>
                    <?php echo apply_filters( 'wpadverts_cf_form_type_label', '—', $item ); ?>
                    <?php endif; ?>
                    
                    <?php if($item->menu_order > 0): ?>
                    <span class="dashicons dashicons-yes"></span>
                    <?php else: ?>
                    
                    <?php endif; ?>
                    
                </td>
                <td class="">
                    <code><?php echo esc_html( $item->post_name ) ?></code>
                </td>

            </tr>
            <?php $i++; ?>
            <?php endforeach; ?>
            <?php endforeach; ?>
        </tbody>
    </table>

</div>
