<?php
require_once plugin_dir_path( __FILE__ ) .'header/header-main.php';
require_once plugin_dir_path( __FILE__ ) .'ch-auto-content-tabs.php';
require_once plugin_dir_path( __FILE__ ) .'class/afe_blog.php';

$afe_blog_main=new afeblogs();
$afe_catgories=$afe_blog_main->afe_article_category('main');

?>
<style>
    .error
    {
        padding: 18px 0px 0px 10px;
    }
</style>
<div class="content_hero_container">
<div class="container">
  <div class="row">
    <div class="col-md-12">

        <div class="tabbable-panel">
            <div class="tabbable-line">
                <h2 style="margin: 20px 0 20px;">Auto Content Search</h2>
                <ul class="nav nav-tabs ">
                    <li class="active">
                        <a href="#tab_default_1" data_id="1" data-toggle="tab"> Article Search </a>
                    </li>
                    <li>
                        <a href="#tab_default_2" data_id="2" data-toggle="tab"> Video Search </a>
                    </li>
                    <li>
                        <a href="#tab_default_3" data_id="3" data-toggle="tab"> Image Search </a>
                    </li>
                </ul>
                <div class="tab-content"><div class="tab-pane active" id="tab_default_1">
                          <!-- Multiple Item Picker -->
                    <form id="form-article">   
						<div class="form-group row">
							<label for="staticEmail" class="col-sm-2 col-form-label" style="margin-top: 1%;font-size: 16px;">Select Category:</label>
							<div class="col-sm-10">
							    <div class="jumbotron" style="padding:0;background-color:white;">
									<select class="form-control " name="selectpicker" id="selectpicker" style="background-color: #e0e0e082;padding: 10px;height:auto;color: black;">
										<option value="0">Choose one of the following category</option>
										<?php
										foreach($afe_catgories as $catgory)
										{
                                            if($catgory->category_name == 'ViralMarketing' || $catgory->category_name == 'ListBuilding')
                                                        { } else {                                            
                                            echo '<option value="'.$catgory->id.'">'.$catgory->category_name.'</option>';
                                            }
										}
										?>
									</select>
									<div id="afe_subcat_loader" style="display: flex;justify-content: center;"><img src="<?php echo plugins_url('MyContentCreatorPro-Free/includes/assets/images/loader_afe.gif'); ?>" id="afe_loader" style="display:none;"> </div>
									<div id="afe_subcat_result"></div>
								</div>
							</div>
						</div>					
                          
                        <div style="display: flex;margin: 1em;"></div>
						<div class="form-group row">
							<label for="staticEmail" class="col-sm-2 col-form-label" style="margin-top: 1.5%;font-size: 16px;">Enter Keyword:</label>
							<div class="col-sm-3">
								<input type="text" name="afe_keyword" class="afe_keyword" id="afe_keyword" placeholder="enter your keyword" value="" style="width:100%;"> 
							</div>
							<div class="col-sm-3">
								<div class="wrapper article_submit_keyword">
									<input type="button" class="button btnPush btnBlueGreen" value="Search Category" />
								</div>		
							</div>
						</div><br/>						
												
						<div id="spincontent" style="display:none">
							<div class="form-group row onoffswitch">
								<label for="staticEmail" class="col-sm-2 col-form-label" style="font-size: 17px;padding-top: 7px;">Spin Content</label>
								<div class="col-sm-10">
									<input type="checkbox" class="onoffswitch-checkbox" id="myonoffswitch" name="onoffswitch"/>
									<label class="onoffswitch-label" for="myonoffswitch">
										<span class="onoffswitch-inner"></span>
									</label>		
							   </div>
							</div><br/>
						</div>
						<div id="spinrewriter" style="display:none">
							<div class="form-group row onoffswitch_spinrewriter">
								<label for="staticEmail" class="col-sm-2 col-form-label" style="font-size: 17px;padding-top: 7px;">Spinrewriter</label>
								<div class="col-sm-10">
									<input type="checkbox" class="onoffswitch_spinrewriter-checkbox" id="myonoffswitch_spinrewriter" name="onoffswitch_spinrewriter"/>
									<label class="onoffswitch_spinrewriter-label" for="myonoffswitch_spinrewriter">
										<span class="onoffswitch_spinrewriter-inner"></span>
									</label>		
							   </div>
							</div>
						</div>						
						<div id="perfecttense" style="display:none">
							<div class="form-group row onoffswitch_perfecttense">
								<label for="staticEmail" class="col-sm-2 col-form-label" style="font-size: 17px;padding-top: 7px;">Perfect Tense</label>
								<div class="col-sm-10">
									<input type="checkbox" class="onoffswitch_perfecttense-checkbox" id="myonoffswitch_perfecttense" name="onoffswitch_perfecttense"/>
									<label class="onoffswitch_perfecttense-label" for="myonoffswitch_perfecttense">
										<span class="onoffswitch_perfecttense-inner"></span>
									</label>		
							   </div>
							</div>
						</div>						
                    </form>
                    <form id="form-article-save">
                        <div id="afe_subcat_loader" style="display: flex;justify-content: center;"><img src="<?php echo plugins_url('MyContentCreatorPro-Free/includes/assets/images/loader_afe.gif'); ?>" id="afe_search_loaders" style="display:none;"> </div>
                        <div id="afe_check_result"></div>
                        <div class="afe_search_main_div" style="display:none;">
                            <h2>Results <input type="button" name="afe_save" id="afe_save" style="background-color: #0073aa;box-shadow: none;border: none;text-shadow: none;" class="button button-primary alignright" value=" Save Results" /></h2>
                        </div>
                        <div id="afe_search_result"> 
                        </div>
                    </form>    
                    </div>
                    
                    <div class="tab-pane" id="tab_default_2">
                        <form id="form_video">
							<div class="form-group row vid-search_cls">
								<label for="staticEmail" class="col-sm-2 col-form-label" style="margin-top: 1.5%;font-size: 16px;">Video Search:</label>
								<div class="col-sm-3">
                                    <input type="text" name="afe_video_keyword" class="afe_cls_video_keyword" id="afe_id_video_keyword" placeholder="enter your keyword" value="" style="width:100%;"> 
								</div>
								<div class="col-sm-3">
									<div class="wrapper video_submit_keyword">
										<input type="button" class="button btnPushVideo btnBlueGreen" value="Search" />
									</div>		
								</div>
							</div>
							
                            <!--<div style="display:flex;" class="vid-search_cls">
                                <input type="text" name="afe_video_keyword" class="afe_cls_video_keyword" id="afe_id_video_keyword" placeholder="enter your keyword" value="" style="width:25%;"> 
                                <div class="wrapper video_submit_keyword">
                                    <input type="button" class="button btnPushVideo btnBlueGreen" value="Search" />
                                </div>
                            </div>-->
                        </form>    
                        <form id="form_video_save">
                            <div id="afe_video_subcat_loader" style="display: flex;justify-content: center;"><img src="<?php echo plugins_url('MyContentCreatorPro-Free/includes/assets/images/loader_afe.gif'); ?>" id="afe_video_search_loaders" style="display:none;"> </div>
                            <div id="afe_video_check_result"></div>                        
                            <div class="afe_video_search_main_div" style="display:none;">
                                <h2>Results <input type="button" name="afe_video_save" id="afe_video_save" style="background-color: #0073aa;box-shadow: none;border: none;text-shadow: none;" class="button button-primary alignright" value=" Save Results" /></h2>
                            </div>
                            <div id="afe_video_search_result"> 
                            </div>
                        </form>    
                    </div>

                    <div class="tab-pane" id="tab_default_3">
                        <form id="form_image" class="img-search-cls">
							<div class="form-group row">
								<label for="staticEmail" class="col-sm-2 col-form-label" style="margin-top: 1.5%;font-size: 16px;">Image Search:</label>
								<div class="col-sm-3">
                                    <input type="text" name="afe_image" class="afe_img_cls" id="afe_img_id" placeholder="enter your keyword for image" value="" style="width:100%;"> 
								</div>
								<div class="col-sm-3">
									<div class="wrapper submit_img_key">
										<input type="button" class="button btnPushImage btnBlueGreen" value="Search"/>
									</div>		
								</div>
							</div>
                            <!--<div style="display:flex;">
                                <input type="text" name="afe_image" class="afe_img_cls" id="afe_img_id" placeholder="enter your keyword for image" value="" style="width:25%;"> 
                                <div class="wrapper submit_img_key">
                                    <input type="button" class="button btnPushImage btnBlueGreen" value="Search"/>
                                </div>
                            </div>-->
                        </form>    
                        <div id="afe_img_subcat_loader" style="display: flex;justify-content: center;"><img src="<?php echo plugins_url('MyContentCreatorPro-Free/includes/assets/images/loader_afe.gif'); ?>" id="afe_img_search_loaders" style="display:none;"> </div>
                        <div id="afe_img_check_result"></div>                        
                        <div class="afe_img_search_main_div" style="display:none;">
                            <h2>Results <input type="button" name="afe_img_save" id="afe_img_save" style="background-color: #0073aa;box-shadow: none;border: none;text-shadow: none;" class="button button-primary alignright" value=" Save Results" /></h2>
                        </div>
                        <div id="afe_img_search_result"> 
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
  </div>
</div>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.11.2/js/bootstrap-select.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>						
jQuery('#spin_select_result').on('change', function() {
  jQuery('#spincontent').css('display', 'none');
  jQuery('#spinrewriter').css('display', 'none');
  jQuery('#perfecttense').css('display', 'none');
  if ( jQuery(this).val() === 'SpinContent' ) {
    jQuery('#spincontent').css('display', 'block');
  }
  if ( jQuery(this).val() === 'Spinrewriter' ) {
    jQuery('#spinrewriter').css('display', 'block');
  }
  if ( jQuery(this).val() === 'perfecttense' ) {
    jQuery('#perfecttense').css('display', 'block');
  }
});


    jQuery('#form-article,#form_image,#form_video').on('keyup keypress', function(e) {
      var keyCode = e.keyCode || e.which;
      if (keyCode === 13) { 
        e.preventDefault();
        return false;
      }
    });

     /* Multiple Item Picker */
  jQuery('.selectpicker').selectpicker({
    style: 'btn-default'
  });
  
/*
jQuery('#selectpicker').change(function () 
{
    var afe_category_id = jQuery(this).val();

    if(afe_category_id>0)
    {
        jQuery("#afe_loader").css("display","block");
        jQuery("#afe_loader").css("height","100px");
        jQuery("#afe_subcat_result").css("display","none");
        var data = {
            action: 'ch_get_subcat',
            afe_subcat_id : afe_category_id
        };
        jQuery.post(ajaxurl, data, function(response) {
            jQuery("#afe_subcat_result").html(response);
            jQuery("#afe_loader").css("display","none"); 
            jQuery("#afe_subcat_result").css("display","block");
            //requiredCheckboxes();
        });
        
    }
    else
    {
        jQuery("#afe_subcat_result").html(' '); 
        jQuery("#afe_subcat_result").hide();
    }
});

function requiredCheckboxes(){
    
    var requiredCheckboxes = jQuery('#afe_subcat_result ul li .afe_subcat_art');
    
        if(requiredCheckboxes.is(':checked')) {
            requiredCheckboxes.removeAttr('required');
        } else {
            requiredCheckboxes.attr('required', 'required');
        }
   
}
*/

jQuery(document).ready(function() {
    jQuery('.btnPush').click(function () 
    {
        var afe_array_val = jQuery("#selectpicker").val();
        var afe_keyword = jQuery("#afe_keyword").val();
        
        jQuery("#afe_search_loaders").css("display","block");
        jQuery("#afe_search_loaders").css("height","100px");
        jQuery("#afe_search_result").css("display","none");
        jQuery("#afe_check_result").css("display","none");

    
        var data_search = {
            action: 'ch_get_search_result',
            afe_ajax_array_val : afe_array_val,
            afe_ajax_keyword : afe_keyword
        };
        jQuery.post(ajaxurl, data_search, function(response) 
        {
            jQuery("#afe_search_result").html(response);
            jQuery("#afe_search_loaders").css("display","none"); 
            jQuery("#afe_search_result").css("display","block");
            jQuery(".afe_search_main_div").css("display","block");
        });
    });
});

jQuery(document).ready(function() {
    jQuery("#form-article-save").validate({
        rules: {
            'afe_check_vals[]': {required: true}
        },
        messages: {
            'afe_check_vals[]': "You must check at least 1 box"
        }
    });
    jQuery('#afe_save').click(function()
    {
        if(jQuery("#form-article-save").valid())
        {
            var afe_array_check_result = [];
            var table = jQuery("#exampless").dataTable();
            jQuery(".afe_check_val:checked", table.fnGetNodes()).each(function () 
            {
                var tuisre = jQuery(this).is(":checked");
                if (tuisre) 
                {
                    var no = jQuery(this).val();
                    afe_array_check_result.push(no);
                }
            }); 
            var afe_array_check_val = afe_array_check_result.join(",");

			var selectedSpin = jQuery('#spin_select_result').find(":selected").val();			

			if(selectedSpin == 'SpinContent')
			{
				if(jQuery("#myonoffswitch").is(":checked"))
				{
					var afe_spin_content_article = 'on';
					var afe_spin_content_rewriter = 'off';
					var afe_spin_content_perfecttense = 'off';
				} 
				else 
				{
					var afe_spin_content_article = 'off';
					var afe_spin_content_rewriter = 'off';
					var afe_spin_content_perfecttense = 'off';
				} 
			}            
			else if(selectedSpin == 'Spinrewriter')
			{
				if(jQuery("#myonoffswitch_spinrewriter").is(":checked"))
				{
					var afe_spin_content_article = 'off';
					var afe_spin_content_rewriter = 'on';
					var afe_spin_content_perfecttense = 'off';
				} 
				else 
				{
					var afe_spin_content_article = 'off';
					var afe_spin_content_rewriter = 'off';
					var afe_spin_content_perfecttense = 'off';
				} 
			}
			else if(selectedSpin == 'perfecttense')
			{
				if(jQuery("#myonoffswitch_perfecttense").is(":checked"))
				{
					var afe_spin_content_article = 'off';
					var afe_spin_content_rewriter = 'off';
					var afe_spin_content_perfecttense = 'on';
				} 
				else 
				{
					var afe_spin_content_article = 'off';
					var afe_spin_content_rewriter = 'off';
					var afe_spin_content_perfecttense = 'off';
				} 
			}	
            jQuery("#afe_check_result").css("display","none");
			
			jQuery("#afe_search_loaders").css("display","block");
			jQuery("#afe_search_loaders").css("height","100px");
            var check_data_search = {
                                action: 'ch_get_check_result',
                                afe_ajax_check_array_val : afe_array_check_val,
                                afe_ajax_spin_content_article : afe_spin_content_article,
                                afe_ajax_spin_content_rewriter : afe_spin_content_rewriter,
                                afe_ajax_spin_content_perfecttense : afe_spin_content_perfecttense
                            };
            jQuery.post(ajaxurl, check_data_search, function(check_response) 
            {
                jQuery("#afe_check_result").html(check_response);
                jQuery("#afe_check_result").css("display","block");
				jQuery("#afe_search_loaders").css("display","none");
            });
        }    
    });
});

jQuery(document).ready(function() {
    jQuery("#form_video").validate({
        rules: {
            afe_video_keyword: "required"
        },
        messages: {
            afe_video_keyword: "Please enter keyword"
        }
    });
    jQuery('.btnPushVideo').click(function ()
    {
        if(jQuery("#form_video").valid())
        {
            var afe_video_keyword = jQuery("#afe_id_video_keyword").val();
        
            jQuery("#afe_video_search_loaders").css("display","block");
            jQuery("#afe_video_search_loaders").css("height","100px");
            jQuery("#afe_video_search_result").css("display","none");
            jQuery("#afe_video_check_result").css("display","none");
        
        
            var vid_data_search = {
                action: 'ch_search_video_result',
                afe_ajax_vid_keyword : afe_video_keyword
            };
            jQuery.post(ajaxurl, vid_data_search, function(vid_response) 
            {
                jQuery("#afe_video_search_result").html(vid_response);
                jQuery("#afe_video_search_loaders").css("display","none"); 
                jQuery("#afe_video_search_result").css("display","block");
                jQuery(".afe_video_search_main_div").css("display","block");
            });
        }
    });
});

jQuery(document).ready(function() {
    jQuery("#form_video_save").validate({
        rules: {
            'afe_video_check_vals[]': {required: true}
        },
        messages: {
            'afe_video_check_vals[]': "You must check at least 1 box"
        }
    });
    jQuery('#afe_video_save').click(function()
    {
        if(jQuery("#form_video_save").valid())
        {
            var afe_video_array_check_result = [];
            var table = jQuery("#exampless").dataTable();
            jQuery(".afe_video_check_val:checked", table.fnGetNodes()).each(function () 
            {
                var tuisre = jQuery(this).is(":checked");
                if (tuisre) 
                {
                    var no = jQuery(this).val();
                    afe_video_array_check_result.push(no);
                }
            }); 
            var afe_video_array_check_val = afe_video_array_check_result.join(",");

            jQuery("#afe_video_check_result").css("display","none");
            var video_check_data_search = {
                                action: 'ch_video_check_results',
                                afe_ajax_video_check_array_val : afe_video_array_check_val
                            };
            jQuery.post(ajaxurl, video_check_data_search, function(video_check_response) 
            {
                jQuery("#afe_video_check_result").html(video_check_response);
                jQuery("#afe_video_check_result").css("display","block");
            });
        }
    });
});

jQuery(document).ready(function() {
    jQuery("#form_image").validate({
        rules: {
            afe_image: "required"
        },
        messages: {
            afe_image: "Please enter keyword"
        }
    });
    jQuery('.btnPushImage').click(function ()
    {
        if(jQuery("#form_image").valid())
        {
            var API_KEY = '20401270-0452e7ff0295b94110247f71d';
            var afe_img_key = jQuery("#afe_img_id").val();
            var img_pixa_url = "https://pixabay.com/api/?key="+API_KEY+"&q="+encodeURIComponent(afe_img_key)+"&per_page=100";
        
        
            jQuery("#afe_img_search_loaders").css("display","block");
            jQuery("#afe_img_search_loaders").css("height","100px");
            jQuery("#afe_img_search_result").css("display","none");
        
        
            var img_data_search = {
                action: 'ch_search_img_result',
                afe_ajax_img_keyword : img_pixa_url
            };
            jQuery.post(ajaxurl, img_data_search, function(img_response) 
            {
                jQuery("#afe_img_search_result").html(img_response);
                jQuery("#afe_img_search_loaders").css("display","none"); 
                jQuery("#afe_img_search_result").css("display","block");
                jQuery(".afe_img_search_main_div").css("display","block");
            });
        }
    });
});

jQuery('#afe_img_save').click(function()
{
    var afe_img_array_check_result = [];
    jQuery.each(jQuery(".img_check_cls:checked"), function(){            
        afe_img_array_check_result.push(jQuery(this).val());
    });
    var afe_img_array_check_val = afe_img_array_check_result;
    //console.log(afe_img_array_check_val);
    
    jQuery("#afe_img_check_result").css("display","none");
    var img_check_data_search = {
                        action: 'ch_img_check_results',
                        afe_ajax_img_check_array_val : afe_img_array_check_val
                    };
    jQuery.post(ajaxurl, img_check_data_search, function(img_check_response) 
    {
        jQuery("#afe_img_check_result").html(img_check_response);
        jQuery("#afe_img_check_result").css("display","block");
    });
});
</script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.0/jquery.validate.min.js"></script>