<?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');
?>

<div class="content_hero_container">
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <h2>Auto Blog Campaign</h2>
            <br/>
            <form action="" id="form1" method="post">
                <div>
                    <label for="campaign_title" style="font-size: 17px;">Title</label>
                    <input type="text" name="afe_auto_campaign_title" class="afe_class_campaign_title" id="afe_id_campaign_title" placeholder="enter title name" value=""> 
                </div>
                <br/><br/>
                <div>
                    <div style="display:flex;">
                        <label for="campaign_schedule" style="font-size: 17px;margin-right:10px;">Schedule</label> 
                        <!--<p>(You are limited to 20 max posts per campaign) </p> -->
                    </div>    
                    <p></p>
                    <div>
                        <p>Every <input type="text" name="afe_campaign_timer" id="afe_campaign_hours" value="" style="height:40px;border-radius:10px;">
                         <select name="afe_campaign_increment" id="afe_campaign_increments" style="width:25%;height:40px;border-radius:10px;margin-top:-5px;">
    						<option value="hours" selected="selected">Hour(s)</option>
                            <option value="days">Day(s)</option>		
                         </select>
                        </p>
                    </div>
                </div>
                <br/><br/>
                <div>
                    <label for="campaign_image_keyword" style="font-size: 17px;">Choose Image Keyword</label> 
                    <input type="text" name="afe_img_keyword" class="afe_cls_img_keyword" id="afe_id_img_keyword" placeholder="enter your keyword" value=""> 
                </div>
                <br/><br/>
                <div>
                    <label for="campaign_video_keyword" style="font-size: 17px;">Choose Video Keyword</label> 
                    <input type="text" name="afe_video_keyword" class="afe_cls_video_keyword" id="afe_id_video_keyword" placeholder="enter your keyword" value=""> 
                </div><br/><br/>    				
				<div>
					
				</div><br/>						
				<div id="spincontent" style="display:none">
					<br/>
					<label for="campaign_spinner" style="font-size: 17px;padding-top: 7px;margin-bottom:15px;">Spin Content</label>
					<input type="checkbox" class="onoffswitch-checkbox" id="myonoffswitch" name="onoffswitch"/>
					<label class="onoffswitch-label" for="myonoffswitch">
						<span class="onoffswitch-inner"></span>
					</label>							
				</div>
				<div id="spinrewriter" style="display:none">
					<br/>
					<label for="campaign_spinner" style="font-size: 17px;padding-top: 7px;margin-bottom:15px;">Spinrewriter</label>
					<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><br/>		
				</div>						
				<div id="perfecttense" style="display:none">
					<br/>
					<label for="campaign_spinner" style="font-size: 17px;padding-top: 7px;margin-bottom:15px;">Perfect Tense</label>
					<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>						
                <br/><br/>
                <div>
                    <div style="display:flex;">
                        <label for="campaign_schedule" style="font-size: 17px;">Select Category</label> 
                    </div>   
                    <p></p>
                    <div class="jumbotron" style="padding:0;background-color:white;">
                        <select class="form-control" name="selectpicker" id="selectpicker" style="background-color:#fff;padding: 10px;height:auto;color: black;max-width:100%;">
                            <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 style="display: flex;margin: 1em;"></div>
                    <div style="display:flex;">
                        <input type="text" name="afe_c_keyword" class="afe_c_keyword" id="afe_c_keyword" placeholder="enter your keyword" value="" style="width:25%;"> 
                        <div class="wrapper autoblog_submit_keyword">
                            <input type="button" class="button btnPush btnnPush btnBlueGreen" value="Search Category" />
                        </div>
                    </div>
                    <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_campaign_check_result"></div>
            </div>        
            </form>
            <form id="form-save">
                    <div class="afe_search_main_div" style="display:none;margin-top:2em;">
                        <h2>Results <input type="button" name="afe_campaign_save" id="afe_campaign_save" style="border-color: #0073aa;background-color: #0073aa;box-shadow: none;font-size: 17px;text-shadow: none;" class="button button-primary alignright" value="Save Campaign" /></h2>
                    </div>
                    <div id="afe_search_result"> </div>
            </form>
        </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');
  }
});

     /* 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");
		});
		
	}
	else
	{
		jQuery("#afe_subcat_result").html(' ');	
		jQuery("#afe_subcat_result").hide();
	}
});
*/

jQuery(document).ready(function() {
    jQuery("#form1").validate({
        rules: {
            afe_auto_campaign_title: "required",
            afe_campaign_timer: "required",
            afe_campaign_increment: {
                    selectchecks: true
                }            
        },
        messages: {
            afe_auto_campaign_title: "Please specify title name",
            afe_campaign_timer: "Please enter the numeric value"
        }
    });
    jQuery('.btnnPush').click(function () 
    {
        if(jQuery("#form1").valid())
        {
            var afe_c_array_val = jQuery("#selectpicker").val();                
            var afe_c_keyword = jQuery("#afe_c_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 c_data_search = {
        		action: 'ch_campaign_search_result',
        		afe_ajax_cmp_array_val : afe_c_array_val,
        		afe_ajax_cmp_keyword : afe_c_keyword
        	};
        	jQuery.post(ajaxurl, c_data_search, function(cmp_response) 
        	{
        		jQuery("#afe_search_result").html(cmp_response);
        		jQuery("#afe_search_loaders").css("display","none"); 
        		jQuery("#afe_search_result").css("display","block");
        		jQuery(".afe_search_main_div").css("display","block");
        	});
        }    
    });
        jQuery.validator.addMethod('selectcheck', function (value) {
            return (value != '0');
        }, "Please Choose atleast one option");    
        jQuery.validator.addMethod('selectchecks', function (values) {
            return (values != '0');
        }, "Please Choose atleast one option");    
});

jQuery(document).ready(function() {
    jQuery("#form-save").validate({
        rules: {
            'afe_cmp_check_vals[]': {required: true}
        },
        messages: {
            'afe_cmp_check_vals[]': "You must check at least 1 box"
        }
    });
    jQuery('#afe_campaign_save').click(function()
    {
        if(jQuery("#form-save").valid())
        {
            var afe_array_check_result1 = [];
            var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
        
            jQuery.each(jQuery(".afe_cmp_check_val:checked"), function(){            
                afe_array_check_result1.push(jQuery(this).val());
            });
            var afe_array_check_val1 = afe_array_check_result1.join(",");
            var afe_campaign_keyword = jQuery('.afe_c_keyword').val(); 
            var afe_campaign_title = jQuery('.afe_class_campaign_title').val(); 
            var afe_img_keyword = jQuery("#afe_id_img_keyword").val();
            var afe_vid_keyword = jQuery("#afe_id_video_keyword").val();
            //var afe_vid_keyword = '';
            
            //var afe_spin_content_check = document.getElementById("myonoffswitch");
            //if (afe_spin_content_check.checked) 
				
			var selectedSpin = jQuery('#spin_select_result').find(":selected").val();			
			if(selectedSpin == 'SpinContent')
			{			
				if(jQuery("#myonoffswitch").is(":checked"))
				{
					var afe_spin_content = 'on';
					var afe_spin_content_rewriter = 'off';
					var afe_spin_content_perfecttense = 'off';
				} 
				else 
				{
					var afe_spin_content = 'off';
					var afe_spin_content_rewriter = 'off';
					var afe_spin_content_perfecttense = 'off';
				} 
			}	
			if(selectedSpin == 'Spinrewriter')
			{			
				if(jQuery("#myonoffswitch_spinrewriter").is(":checked"))
				{
					var afe_spin_content = 'off';
					var afe_spin_content_rewriter = 'on';
					var afe_spin_content_perfecttense = 'off';
				} 
				else 
				{
					var afe_spin_content = 'off';
					var afe_spin_content_rewriter = 'off';
					var afe_spin_content_perfecttense = 'off';
				} 
			}
			if(selectedSpin == 'perfecttense')
			{			
				if(jQuery("#myonoffswitch_perfecttense").is(":checked"))
				{
					var afe_spin_content = 'off';
					var afe_spin_content_rewriter = 'off';
					var afe_spin_content_perfecttense = 'on';
				} 
				else 
				{
					var afe_spin_content = 'off';
					var afe_spin_content_rewriter = 'off';
					var afe_spin_content_perfecttense = 'off';
				} 
			}	
            var c_hour = [];
            var c_days = [];
            var campaign_time = jQuery("#afe_campaign_increments").val();
            if(campaign_time == 'hours')
            {
              c_hour.push(jQuery('#afe_campaign_hours').val());
            }
            else if(campaign_time == 'days')
            {
              c_days.push(jQuery('#afe_campaign_hours').val());
            }
        
            
			jQuery("#afe_search_loaders").css("display","block");
			jQuery("#afe_search_loaders").css("height","100px");
            jQuery("#afe_campaign_check_result").css("display","none");
        	var check_campaign_search = {
                    			action: 'ch_get_check_campaign_result',
                    			afe_ajax_campaign_check_array_val : afe_array_check_val1,
                    			afe_ajax_campaign_title : afe_campaign_title,
                    			afe_ajax_campaign_key : afe_campaign_keyword,
                    			afe_ajax_campaign_hour : c_hour,
                    			afe_ajax_campaign_days : c_days, 
                    			afe_ajax_campaign_img_key : afe_img_keyword, 
                    			afe_ajax_campaign_vid_key : afe_vid_keyword, 
                    			afe_ajax_afe_spin_content : afe_spin_content, 
                                afe_ajax_spin_content_rewriter : afe_spin_content_rewriter,
                                afe_ajax_spin_content_perfecttense : afe_spin_content_perfecttense
                    		};
            jQuery.post(ajaxurl, check_campaign_search, function(campaign_response) 
            {
                jQuery("#afe_campaign_check_result").html(campaign_response);
        		jQuery("#afe_campaign_check_result").css("display","block");
				jQuery("#afe_search_loaders").css("display","none");
            });
        }
    });
});
</script>

<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.0/jquery.validate.min.js"></script>