<?php	
	global $woie_data, $woie_versions_type, $woie_pro, $woie_url, $woie_premium_link, $wpdb, $woie_filter_meta_keys;

			
    $woie_options = get_option('woie_options', array());
	
	
	
	
	$post_types = get_post_types();
	ksort($post_types);

	//pree($woie_options);
?>



<div class="wrap woie-wrapper">
<h2><?php echo $woie_data['Name'].' ('.$woie_data['Version'].($woie_pro?') Pro':')').' - '.__('Settings', 'woo-ie'); ?></h2>
<?php if(!$woie_pro): ?>
            <a style="float:right; position:relative; top:-40px; display:none;" href="<?php echo esc_url($woie_premium_link); ?>" target="_blank"><?php _e('Go Premium', 'woo-ie'); ?></a>
<?php endif; ?>

    <h2 class="nav-tab-wrapper">
        <a class="nav-tab"><?php _e("Dashboard",'woo-ie'); ?></a>
        <a class="nav-tab"><?php _e("Export",'woo-ie'); ?></a>
        <a class="nav-tab"><?php _e("Import",'woo-ie'); ?></a>
        <a class="nav-tab"><?php _e("Developers",'woo-ie'); ?></a>
        <a class="nav-tab"><?php _e("Filters",'woo-ie'); ?> (<?php _e("Orders List Page",'woo-ie'); ?>)</a>
        
        <a class="nav-tab" data-tab="help" data-type="free"><i class="far fa-question-circle" style="color:#FB7A47"></i>&nbsp;<?php _e("Help", 'woo-ie'); ?></a>
        
    </h2>

	<div class="nav-tab-content woie_in_action settings_section mt-2">


        <!-- Main Section -->

        <div class="woie_folders">

            <div class="row">

                <div class="col-12 text-center text-dark">
                    
                </div>


            </div>

        </div>

        <!--        Sidebar section-->
        <div class="woie_log">
            <div class="row">

                <div class="col-12 text-center">
                    <?php _e('Enable/Disable (Post Types)', 'woo-ie'); ?>
                </div>


            </div>



            <hr class="bg-warning"/>

            <div class="row nopadding woie-options">
                <?php if(!$woie_pro): ?>
                    <a class="btn btn-warning btn-sm mx-auto" href="<?php echo esc_url($woie_premium_link); ?>" target="_blank" title="<?php echo __('Click here for Premium Version', 'woo-ie'); ?>"><?php echo __('Go Premium', 'woo-ie'); ?></a>
                <?php endif; ?>


                <div class="alert alert-secondary fade in alert-dismissible d-none mx-auto mt-4" style="width: 90%">
                    <button type="button" class="close" data-dismiss="alert" aria-label="<?php echo __('Close', 'woo-ie'); ?>">
                        <span aria-hidden="true" style="font-size:20px">×</span>
                    </button>    <strong><?php echo __('Success!', 'woo-ie'); ?></strong> <?php echo __('Options are updated successfully.', 'woo-ie'); ?>
                </div>

                <ul class="col col-md-12 mt-4">
<?php if(!empty($post_types)): foreach($post_types as $post_type): ?>                	
                    <li <?php echo array_key_exists($post_type, $woie_options)?'class="selected"':''; ?>>
                        <label for="woie_options_<?php echo $post_type; ?>">
                            <input <?php echo checked(array_key_exists($post_type, $woie_options)); ?> type="checkbox" name="woie_options[<?php echo $post_type; ?>]" value="<?php echo $post_type; ?>" id="woie_options_<?php echo $post_type; ?>"  />
                            <?php echo $post_type; ?> <small></small>
                            
                            <i class="fas fa-check"></i>
                        </label>
                    </li>
<?php endforeach; endif; ?>                    


                    <li class="premium-features"></li>



                    <li>
                        <label for="woie_options_product_ids">
                            <input type="checkbox" name="woie_options[product_ids]" value="product_ids" id="woie_options_product_ids" <?php echo array_key_exists('product_ids', $woie_options) ? 'checked' : '' ?> />
                            <?php echo __("Product ID's", 'woo-ie'); ?>
                        </label>

                    </li>

                    <li>
                        <label for="woie_options_item_title">
                            <input type="checkbox" name="woie_options[item_title]" value="item_title" id="woie_options_item_title" <?php echo array_key_exists('item_title', $woie_options) ? 'checked' : '' ?> />
                            <?php echo __('Item Title', 'woo-ie'); ?>
                        </label>

                    </li>

                    <li>
                        <label for="woie_options_item_slug">
                            <input type="checkbox" name="woie_options[item_slug]" value="item_slug" id="woie_options_item_slug" <?php echo array_key_exists('item_slug', $woie_options) ? 'checked' : '' ?> />
                            <?php echo __(' Item Slug', 'woo-ie'); ?>
                        </label>

                    </li>
 

                        </ul>

                    </li>
  
                </ul>



             

                <ul class="col col-md-12 mt-4">
                    <li class="promotions"></li>
                    <li style="text-align:center;">
                        <a href="https://wordpress.org/plugins/gulri-slider" target="_blank" title="<?php echo __('Image Slider', 'woo-ie'); ?>"><img src="<?php echo $woie_url; ?>img/gslider.gif" /></a>
                    </li>
                </ul>
            </div>

        </div>


    </div>

    <div class="nav-tab-content hide export_section">

        <?php
		
			
			
			//pree($_woie_settings_obj);

            $allowed_post_types = (empty($woie_options)?array('product', 'shop_order'):array_keys($woie_options));
            $allowed_post_types = array_combine($allowed_post_types, $allowed_post_types);


            

            $post_types = array_intersect_key($post_types, $allowed_post_types);
            $post_statuses = get_post_statuses();
            $order_status = wc_get_order_statuses();
            $page_status = get_page_statuses();

            $all_statuses = array_merge($post_statuses, $page_status, $order_status);

			$_woie_settings_obj = get_option('_woie_settings_obj', array());
			$_woie_settings_obj = (is_array($_woie_settings_obj)?$_woie_settings_obj:array());

			//pree($_woie_settings_obj);

        ?>

        <div class="row mt-3 mb-4">
            <div class="col-md-12">
                <div class="h5"><?php _e("Export Options",'woo-ie'); ?></div>
            </div>
        </div>


        <div class="row mt-3">
            <div class="col-md-12">
                <div class="alert alert-success export_alert hide  mb-4"><?php _e("Data exported successfully. ",'woo-ie'); ?> <a href="" target="_blank"><?php _e("Click here",'woo-ie'); ?></a> <?php _e("to view file.",'woo-ie'); ?></div>
            </div>
        </div>



        <div class="row mb-3">
            <div class="col-md-3">
                <label for="woie_export_post_type"><?php _e("Post Types:",'woo-ie'); ?></label>
            </div>
            <div class="col-md-4">

                <select name="woie_export[post_type][]" data-name="post_type" class="woie_export_settings" id="woie_export_post_type" multiple>

                    <?php

                        foreach ($post_types as $type_key => $type_value){
                            $type_selected = $type_key == 'product' ? 'selected' : '';
                            echo "<option $type_selected>$type_key</option>";
                        }

                    ?>

                </select>
                
            </div>
        </div>

        <div class="row mb-3">
            <div class="col-md-3">
                <label for="woie_export_post_status"><?php _e("Post Status:",'woo-ie'); ?></label>
            </div>
            <div class="col-md-4">

                <select name="woie_export[post_status][]" data-name="post_status" class="woie_export_settings" id="woie_export_post_status" multiple>

                    <?php

                        foreach ($all_statuses as $status_key => $status_value){
                            $selected = $status_key == 'publish' ? 'selected' : '';
                            echo "<option value='$status_key' $selected>$status_value</option>";
                        }

                    ?>

                    <?php



                    ?>

                </select>

            </div>
        </div>

        <div class="row mb-3">
            <div class="col-md-3">
                <label for="woie_export_post_status"><?php _e("Post/Product/Order ID's (Optional):",'woo-ie'); ?></label>
            </div>
            <div class="col-md-4">



                <div>
                    <input class="woie_export_settings" type="radio" name="woie_export[export_number]" data-name="export_number" id="woie_export_number_all" value="all" checked>
                    <label class="form-check-label" for="woie_export_number_all">
                        <?php _e("Export Everything",'woo-ie'); ?>
                    </label>
                </div>


                <?php

                    $woie_settings_array = array(

                        'product_ids' => '',
                        'item_title' => '',
                        'item_slug' => '',

                    );

                    $woie_options_intersect = array_intersect_key($woie_settings_array, $woie_options);

                    if(array_key_exists('product_ids', $woie_options) || empty($woie_options_intersect)):

                ?>


                <div>
                    <input class="woie_export_settings" type="radio" name="woie_export[export_number]" data-name="export_number" id="woie_export_number_include" value="include" <?php echo !$woie_pro ? 'disabled' : ''  ?> >
                    <label class="form-check-label " for="woie_export_number_include">
                        <?php _e("Selective Items to Export",'woo-ie'); ?>
                        <small class="text-danger float-right">
                            &nbsp;<?php echo !$woie_pro ? '(Premium)' : ''  ?>
                        </small>
                    </label>
                </div>


                <div class="my-3 woie_include_ids_select_wrapper <?php echo !$woie_pro ? '' : 'hide'  ?>" <?php echo !$woie_pro ? 'disabled' : ''  ?>>


                    <select name="woie_export[include][]" class="woie_export_settings woie_include_ids_select" data-name="ids" id="woie_export_include_ids" multiple>

                    </select>

                </div>


                <?php


                    endif;


                ?>



            </div>
        </div>

        <?php



        if(array_key_exists('item_title', $woie_options)):

        ?>

        <div class="row  mb-3">
            <div class="col-md-3">
                <label class="form-check-label" for="woie_export_post_title">
                    <?php _e("Item Title:",'woo-ie'); ?>
                </label>
            </div>
            <div class="col-md-4">
                <input type="text" name="woie_export[title]" data-name="post_title" class="<?php echo !$woie_pro ? 'w-75' : 'w-100'  ?> woie_export_settings" id="woie_export_post_title" placeholder="Beanie With Logo" <?php echo !$woie_pro ? 'disabled' : ''  ?>>
                <small class="text-danger float-right">
                            <?php echo !$woie_pro ? '(Premium)' : ''  ?>
                </small>
            </div>
        </div>


        <?php


        endif;


        ?>


        <?php

        if(array_key_exists('item_slug', $woie_options)):

        ?>

        <div class="row  mb-3">
            <div class="col-md-3">
                <label class="form-check-label" for="woie_export_post_name">
                    <?php _e("Item Slug:",'woo-ie'); ?>
                </label>
            </div>
            <div class="col-md-4">
                <input type="text" name="woie_export[name]" data-name="post_name" class="<?php echo !$woie_pro ? 'w-75' : 'w-100'  ?> woie_export_settings" id="woie_export_post_name" placeholder="beanie-with-logo" <?php echo !$woie_pro ? 'disabled' : ''  ?>>
                <small class="text-danger float-right">
                            <?php echo !$woie_pro ? '(Premium)' : ''  ?>
                </small>
            </div>
        </div>


        <?php


        endif;


        ?>


        <div class="row mb-3">
            <div class="col-md-3">
                <label for="woie_export_post_status"><?php _e("Export Type:",'woo-ie'); ?></label>
            </div>
            <div class="col-md-4">

				
			<?php
			
				$export_file_types = array('string'=>__("String",'woo-ie'), 'file'=>__("Text File",'woo-ie'), 'csv'=>__("CSV File",'woo-ie'));
				
				if(!empty($export_file_types)){
			?>
            		<ul>
            <?php					
					foreach($export_file_types as $export_file_type=>$export_file_type_title){
						
						
			?>           
            		<li>     
						<label class="form-check-label" for="woie_export_type_<?php echo $export_file_type; ?>">
							<input class="woie_export_settings" type="radio" name="woie_export[export_type]" data-name="export_type" id="woie_export_type_<?php echo $export_file_type; ?>" value="<?php echo $export_file_type; ?>" <?php checked(isset($_woie_settings_obj['type']) && $_woie_settings_obj['type']==$export_file_type); ?> />
							<?php echo $export_file_type_title; ?>
						</label>
					</li>                        
			<?php
					}
			?>
            		</ul>
            <?php
				}
			?>
              

            </div>
        </div>
        
        <?php
			if(isset($_woie_settings_obj['args']) && isset($_woie_settings_obj['args']['post_type']) && in_array('shop_order', $_woie_settings_obj['args']['post_type'])){
			
		?>
        <div class="row mb-3">
            <div class="col-md-3">
                <label for="woie_export_btn_display"><?php _e("Export Button Display On:",'woo-ie'); ?></label>
            </div>
            <div class="col-md-4">

				
			<?php
			
				$export_btn_display = array('orders_list'=>__("Orders List Page",'woo-ie'), 'edit_order'=>__("Edit Order Page",'woo-ie'),);
				
				if(!empty($export_btn_display)){
			?>
            		<ul>
            <?php					
					foreach($export_btn_display as $export_btn_type=>$export_btn_caption){
						
						
			?>     
            		<li>           
						<label class="form-check-label" for="woie_export_type_<?php echo $export_btn_type; ?>">
							<input class="woie_export_settings" type="checkbox" name="woie_export[export_btn_display][]" data-name="export_btn_display" id="woie_export_type_<?php echo $export_btn_type; ?>" value="<?php echo $export_btn_type; ?>" <?php checked(isset($_woie_settings_obj['args']['export_btn_display']) && in_array($export_btn_type, $_woie_settings_obj['args']['export_btn_display'])); ?> />
							<?php echo $export_btn_caption; ?>
						</label>
					</li>
			<?php
					}
			?>
            		</ul>
            <?php						
				}
			?>
              

            </div>
        </div>



		<div class="row mb-3">
            <div class="col-md-3">
                <label for="woie_export_btn_display"><?php _e("Export Order Data:",'woo-ie'); ?></label>
            </div>
            <div class="col-md-4">

				
			<?php
			
				$defaults = array(
					'numberposts'      => 1,
					'category'         => 0,
					'orderby'          => 'date',
					'order'            => 'DESC',
					'include'          => array(),
					'exclude'          => array(),
					'meta_key'         => '',
					'meta_value'       => '',
					'post_type'        => 'shop_order',
					'post_status'        => 'any',
					'suppress_filters' => true,
				);
				
				$default_results = get_posts($defaults);
				
				$order_file_columns = array();
				
				if(!empty($default_results)){
					$default_object = current($default_results);
					$default_id = $default_object->ID;
					if(is_numeric($default_id)){
						$default_order = wc_get_order($default_id);
						if(is_object($default_order)){
							
							foreach($default_order->get_data() as $default_order_key=>$default_order_val){
								$order_file_columns[] = $default_order_key;
							}
							
							foreach($default_order as $default_order_key=>$default_order_val){
								$order_file_columns[] = $default_order_key;
							}
							
						}
						//pree($order_file_columns);
					}
				}
				
				$order_file_columns = array_unique($order_file_columns);
				
				$order_file_columns = apply_filters('woie_export_order_data_columns', $order_file_columns);
				
				//pree($_woie_settings_obj);
				if(!empty($order_file_columns)){
					//sort($order_file_columns);
					//pree($_woie_settings_obj['args']['export_order_field_label']);
			?>
            		<ul>
            <?php					
					foreach($order_file_columns as $column_index=>$order_file_column){ //pree($column_index);
						
						$column_label_index = array_search($order_file_column, $_woie_settings_obj['args']['export_order_field']);
						//pree($column_label_index.' - '.$order_file_column);
						//pree($_woie_settings_obj['args']['export_order_field_label'][$column_label_index]);
			?>     
            		<li>           
						<label class="form-check-label" for="woie_export_order_field_<?php echo $order_file_column; ?>">
                        
                        	<span style="display:inline-block; width:260px;">
							<input class="woie_export_settings" type="checkbox" name="woie_export[export_order_field][<?php echo $column_index; ?>]" data-name="export_order_field" id="woie_export_order_field_<?php echo $order_file_column; ?>" value="<?php echo $order_file_column; ?>" <?php checked(isset($_woie_settings_obj['args']['export_order_field']) && is_array($_woie_settings_obj['args']['export_order_field']) && in_array($order_file_column, $_woie_settings_obj['args']['export_order_field'])); ?> />
							<?php echo $order_file_column; ?>
                            </span>
                            
                            <input class="woie_export_settings" title="<?php _e('You can change the column titles for the export file columns','woo-ie'); ?>" placeholder="<?php _e('Column Title','woo-ie'); ?>" type="text" name="woie_export[export_order_field_label][<?php echo $column_index; ?>]" data-name="export_order_field_label" id="woie_export_order_field_label_<?php echo $order_file_column; ?>" data-field="<?php echo $order_file_column; ?>" value="<?php echo (isset($_woie_settings_obj['args']['export_order_field_label'][$column_label_index])?$_woie_settings_obj['args']['export_order_field_label'][$column_label_index]:''); ?>" />
                            
						</label>
					</li>
			<?php
					}
			?>
            		</ul>
            <?php						
				}
			?>
              

            </div>
        </div>
        
		<?php
			}
		?>			

        <div class="row mb-3 woie_export_exported_string_row hide">
            <div class="col-md-3">
                <label for="woie_export_exported_string"><?php _e("Exported String:",'woo-ie'); ?></label>
            </div>
            <div class="col-md-8">

                <textarea class="form-control" id="woie_export_exported_string" rows="8"></textarea>


            </div>
        </div>

        <div class="row mt-3">
            <div class="col-md-3"></div>

            <div class="col-md-4">
                <button class="btn btn-success woie_export_btn w-50"><?php _e("Save & Proceed",'woo-ie'); ?></button>
            </div>
        </div>


    </div>

    <div class="nav-tab-content hide import_section">

        <div class="row mt-3 mb-4">
            <div class="col-md-12">
                <div class="h5"><?php _e("Import Options",'woo-ie'); ?></div>
            </div>
        </div>

        <div class="row mt-3">
            <div class="col-md-12">
                <div class="alert alert-success import_alert hide mb-4"></div>
            </div>
        </div>


        <div class="row mb-3">
            <div class="col-md-3">
                <label for="woie_import_post_type"><?php _e("Import Type:",'woo-ie'); ?></label>
            </div>
            <div class="col-md-4">


                
                <label class="form-check-label" for="woie_import_type_string">
                	<input class="woie_import_settings" type="radio" name="woie_import[import_type]" id="woie_import_type_string" value="string" checked="checked" />
                    <?php _e("String",'woo-ie'); ?>
                </label>

                
                <label class="form-check-label" for="woie_import_type_file">
                	<input class="woie_import_settings" type="radio" name="woie_import[import_type]" id="woie_import_type_file" value="file" >
                    <?php _e("File",'woo-ie'); ?>
                </label>


            </div>
        </div>

        <form action="" method="post" enctype="multipart/form-data" id="woie_import_form">

        <div class="row mb-3 woie_import_settings_file_wrapper hide">

            <div class="col-md-3">
                <label for="woie_export_post_type"><?php _e("File to Import:",'woo-ie'); ?></label>
            </div>
            <div class="col-md-4">

                <input type="file" class="woie_import_settings_file" name="woie_import_file_txt">
                <input type="hidden" class="woie_import_settings" name="action" value="woie_import_posts_data_file">
                <?php echo  wp_nonce_field('woie_import_file_action', 'woie_import_nonce') ;?>

            </div>





                <div class="col-md-5"></div>
                <div class="col-md-3"></div>

                <div class="col-md-9 mt-3">
                    <div class="progress woie_import_progress hide">
                        <div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
                            25%
                        </div>
                    </div>
                </div>




        </div>



        <div class="row mb-3 woie_import_exported_string_row">
            <div class="col-md-3">
                <label for="woie_export_exported_string"><?php _e("String to Import:",'woo-ie'); ?></label>
            </div>
            <div class="col-md-8">

                <textarea class="form-control" id="woie_import_exported_string" rows="8"></textarea>


            </div>
        </div>

        <div class="row mt-5">
            <div class="col-md-3"></div>
            <div class="col-md-4">
                <button type="submit" class="btn btn-danger woie_import_btn w-25"><?php _e("Import",'woo-ie'); ?></button>
            </div>
        </div>

        </form>


    </div>
    <?php 
		$theme_name = get_option('stylesheet');
		
		
		$custom_meta_keys_query = 'SELECT DISTINCT(meta_key) FROM '.$wpdb->postmeta.' ORDER BY meta_key';
		
		$custom_meta_keys = $wpdb->get_results($custom_meta_keys_query);
		
	?>
    
    
    
    
    <div class="nav-tab-content container-fluid hide" data-content="developers">

        <div class="row mt-3">
            
            <div class="col-md-12">
                <div class="h5"><?php _e("Filter Hooks",'woo-ie'); ?></div>
                
                <ul class="position-relative">
                    <li>add_filter( 'woie_export_order_data', '<?php echo $theme_name; ?>_export_order_data_callback', 10, 4 );</li>
                    <li>add_filter( 'woie_export_order_data_columns', '<?php echo $theme_name; ?>_export_order_data_columns_callback', 8, 1 );</li>
                </ul> 
            </div>
        
            
        	               
        </div>

    </div>
    
    <div class="nav-tab-content container-fluid hide" data-content="filters">
    
    	<form action="" method="post" enctype="multipart/form-data" id="woie_filters_form">
		
		<?php echo  wp_nonce_field('woie_filters_action', 'woie_filters_nonce') ;?>

        <div class="row mt-3">
            
            <div class="col-md-12">
                <div class="h5"><?php _e("Select order meta keys to work as filters and count the orders inside",'woo-ie'); ?>:</div>
                
                <ul class="position-relative" style="height: 400px; overflow-y: auto;">
<?php
		if(!empty($custom_meta_keys)){
			//pree($woie_filter_meta_keys);
			foreach($custom_meta_keys as $custom_meta_key_obj){
				$custom_meta_key = $custom_meta_key_obj->meta_key;

?>
<li><label id="<?php echo $custom_meta_key; ?>"><input <?php checked(in_array($custom_meta_key, $woie_filter_meta_keys)); ?> type="checkbox" value="<?php echo $custom_meta_key; ?>" name="filter_meta_keys[]" /> <?php echo $custom_meta_key; ?></label></li>
<?php
			}
		}
?>
                </ul> 
                
            </div>          
        </div>
        
        <div class="row mt-5">
            <div class="col-md-4">
                <button type="submit" class="btn btn-danger woie_filters_save_btn w-25"><?php _e("Save Changes",'woo-ie'); ?></button>
            </div>
        </div>
        
        </form>

    </div>
    
    <div class="nav-tab-content container-fluid hide" data-content="help">

        <div class="row mt-3">
        
        	<ul class="position-relative">
            	<li><a class="btn btn-sm btn-info" href="https://wordpress.org/support/plugin/export-import-for-woocommerce/" target="_blank"><?php _e('Open a Ticket on Support Forums', 'woo-ie'); ?> &nbsp;<i class="fas fa-tag"></i></a></li>
                <li><a class="btn btn-sm btn-warning" href="http://demo.androidbubble.com/contact/" target="_blank"><?php _e('Contact Developer', 'woo-ie'); ?> &nbsp;<i class="fas fa-headset"></i></a></li>
                <li><a class="btn btn-sm btn-secondary" href="<?php echo $woie_premium_link; ?>/?help" target="_blank"><?php _e('Need Urgent Help?', 'woo-ie'); ?> &nbsp;<i class="fas fa-phone"></i></i></a></li>
                <li style="display:none"><iframe width="560" height="315" src="https://www.youtube.com/embed/HAMuzSm0Jd0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></li>
			</ul>                
        </div>

    </div>

    

    <div class="modal wpie_load_modal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="ajax_load_modalLabel" >
        <div class="modal-dialog" role="document" style="max-width: 50px;">
            <div class="modal-content" style="margin-top: 45vh; width: max-content">

                <img src="<?php echo  $woie_url ?>img/loader.gif" style="width: 50px; height: 50px"/>

            </div>
        </div>
    </div>

</div>


<script type="text/javascript" language="javascript">

    jQuery(document).ready(function($){


        <?php if(isset($_GET['t'])): ?>



        $('.nav-tab-wrapper .nav-tab:nth-child(<?php echo esc_attr($_GET['t'])+1; ?>)').click();

        <?php endif; ?>

    });

</script>
<style type="text/css">
.php-error #adminmenuback, .php-error #adminmenuwrap {
    margin-top: 0;
}
</style>