<?php
require_once plugin_dir_path( __FILE__ ) .'header/header-main.php';
require_once plugin_dir_path( __FILE__ ) .'ch-auto-content-tabs.php';
?>
<div class="content_hero_container">
<div class="container">
  <div class="row">
	<?php
	$pro_lic_key = get_option('mycpfree_licence_key');
	if($pro_lic_key != "MyContentCreatorFree-1234")
	{ ?>		
		<div class="col-md-12" id="pro_message" style="padding: 15px;font-size: 17px;color: brown;">
			<div class="wpch-upgrade-notice" style="border: 2px solid;padding: 15px;line-height:25px;"> <span style="font-weight:700;"> Note :- </span> The Following Options are available in <a href="<?php echo admin_url('admin.php?page=mywpch_unlock_pro'); ?>" title="Upgrade to Elite">Elite Version</a> only. Upgrade to <a href="<?php echo admin_url('admin.php?page=mywpch_unlock_pro'); ?>" title="Upgrade to Elite">Elite Version</a>  for more features and for supporting us. Thanks.</div>
		</div>  	
		<div class="col-md-12" id="campaign_detail_box" style="pointer-events:none;opacity: 0.2;">
			<div class="afe_campaign_list_main_div" style="line-height: 25px;">
				<h2 style="margin: 20px 0 20px;">Campaign Details <a href="<?php echo admin_url('admin.php?page=my-campaign'); ?>"><input type="button" name="afe_campaign_list" id="afe_campaign_list" class="button button-primary alignright" style="background-color: #0073aa;box-shadow: none;border: none;text-shadow: none;" value=" Add New Campaign" /></a></h2>
			</div>
			<div>
				<?php
				global $wpdb;
				if(isset($_POST['id_campaign_list_del']))
				{
					$campaign_list_post_del = $wpdb->base_prefix.'ch_camapign';
					$campaign_list_post_del1 = $wpdb->base_prefix.'ch_campaign_post';

					$afe_list_campaign_saved_del = $wpdb->get_results("SELECT * FROM ".$wpdb->base_prefix."ch_campaign_post WHERE campaign_id='".$_POST['id_campaign_list_del']."'");
					if(!empty($afe_list_campaign_saved_del))
					{
						foreach($afe_list_campaign_saved_del as $afe_list_campaign_saved_del1)
						{
							$post_camp_id = $afe_list_campaign_saved_del1->post_id;
							wp_delete_post($post_camp_id,true);
						}
					}

					$campaign_list_del1 = $wpdb->delete($campaign_list_post_del1, array( 'campaign_id' => $_POST['id_campaign_list_del'] ) );
					$campaign_list_del = $wpdb->delete($campaign_list_post_del, array( 'id' => $_POST['id_campaign_list_del'] ) );
					if($campaign_list_del || $campaign_list_del1)
					{?>
					<div class="wrap">
						<div class="updated"><p>Successfully Deleted!</p></div>
					</div>
					<?php }
				}

				$afe_detail_campaign_saved_result1 = $wpdb->get_results("SELECT * FROM ".$wpdb->base_prefix."ch_camapign ORDER BY id DESC");
				?>
				<table id="example" class="table table-striped widefat" style="width:100%;">
				  <thead>
					<tr>
					  <th style="text-align: inherit;font-weight: 700;"></th>
					  <th style="text-align: inherit;font-weight: 700;">ID</th>
					  <th style="text-align: inherit;font-weight: 700;">Campaign Name</th>
					  <th style="text-align: inherit;font-weight: 700;">Action<h>
					</tr>
				  </thead>
				  <tbody>
					<?php
					foreach($afe_detail_campaign_saved_result1 as $afe_detail_campaign_saved_result)
					{
						$afe_list_campaign_count = $wpdb->get_results("SELECT * FROM ".$wpdb->base_prefix."ch_campaign_post WHERE campaign_id='".$afe_detail_campaign_saved_result->id."'");
					?>
					<tr>
						<td></td>
						<td><?php echo $afe_detail_campaign_saved_result->id; ?></td>
						<td><p style="color: firebrick;"><?php echo $afe_detail_campaign_saved_result->c_title; ?></p></td>
						<td>
							<?php if(count($afe_list_campaign_count) == 0) {?>
								<input type="submit" class="btn class_edit btn-success" value="Completed">
							<?php } else {?>
								<input type="submit" class="btn class_edit btn-warning" value="Processing">
							<?php } $s = $afe_detail_campaign_saved_result->id;?>
							<form method="post" action="admin.php?page=my-auto-campaign-edit&id=<?php echo $s; ?>" style="margin-bottom: 5px;display: inline-block;"><input type="hidden" name="id_campaign_list_edit" value="<?php echo $afe_detail_campaign_saved_result->id; ?>" /><input type="submit" style="background-color:#0073aa;border:none;color:white;" class="btn" value="Edit"></form>
							<form method="post" action="" style="margin-bottom: 5px;display: inline-block;"><input type="hidden" name="id_campaign_list_del" value="<?php echo $afe_detail_campaign_saved_result->id; ?>" /><input type="submit" class="btn class_edit btn-danger" value="Delete"></form>
						</td>
					</tr>
					<?php
					}
					?>
				  </tbody>
				</table>
			</div>

		</div>
	<?php }
	else
	{ ?>
		<div class="col-md-12" id="campaign_detail_box">
			<div class="afe_campaign_list_main_div">
				<h2 style="margin: 20px 0 20px;">Campaign Details <a href="<?php echo admin_url('admin.php?page=my-campaign'); ?>"><input type="button" name="afe_campaign_list" id="afe_campaign_list" class="button button-primary alignright" style="background-color: #0073aa;box-shadow: none;border: none;text-shadow: none;" value=" Add New Campaign" /></a></h2>
			</div>
			<div>
				<?php
				global $wpdb;
				if(isset($_POST['id_campaign_list_del']))
				{
					$campaign_list_post_del = $wpdb->base_prefix.'ch_camapign';
					$campaign_list_post_del1 = $wpdb->base_prefix.'ch_campaign_post';

					$afe_list_campaign_saved_del = $wpdb->get_results("SELECT * FROM ".$wpdb->base_prefix."ch_campaign_post WHERE campaign_id='".$_POST['id_campaign_list_del']."'");
					if(!empty($afe_list_campaign_saved_del))
					{
						foreach($afe_list_campaign_saved_del as $afe_list_campaign_saved_del1)
						{
							$post_camp_id = $afe_list_campaign_saved_del1->post_id;
							wp_delete_post($post_camp_id,true);
						}
					}

					$campaign_list_del1 = $wpdb->delete($campaign_list_post_del1, array( 'campaign_id' => $_POST['id_campaign_list_del'] ) );
					$campaign_list_del = $wpdb->delete($campaign_list_post_del, array( 'id' => $_POST['id_campaign_list_del'] ) );
					if($campaign_list_del || $campaign_list_del1)
					{?>
					<div class="wrap">
						<div class="updated"><p>Successfully Deleted!</p></div>
					</div>
					<?php }
				}

				$afe_detail_campaign_saved_result1 = $wpdb->get_results("SELECT * FROM ".$wpdb->base_prefix."ch_camapign ORDER BY id DESC");
				?>
				<table id="example" class="table table-striped widefat" style="width:100%;">
				  <thead>
					<tr>
					  <th style="text-align: inherit;font-weight: 700;"></th>
					  <th style="text-align: inherit;font-weight: 700;">ID</th>
					  <th style="text-align: inherit;font-weight: 700;">Campaign Name</th>
					  <th style="text-align: inherit;font-weight: 700;">Action<h>
					</tr>
				  </thead>
				  <tbody>
					<?php
					foreach($afe_detail_campaign_saved_result1 as $afe_detail_campaign_saved_result)
					{
						$afe_list_campaign_count = $wpdb->get_results("SELECT * FROM ".$wpdb->base_prefix."ch_campaign_post WHERE campaign_id='".$afe_detail_campaign_saved_result->id."'");
					?>
					<tr>
						<td></td>
						<td><?php echo $afe_detail_campaign_saved_result->id; ?></td>
						<td><p style="color: firebrick;"><?php echo $afe_detail_campaign_saved_result->c_title; ?></p></td>
						<td>
							<?php if(count($afe_list_campaign_count) == 0) {?>
								<input type="submit" class="btn class_edit btn-success" value="Completed">
							<?php } else {?>
								<input type="submit" class="btn class_edit btn-warning" value="Processing">
							<?php } $s = $afe_detail_campaign_saved_result->id;?>
							<form method="post" action="admin.php?page=my-auto-campaign-edit&id=<?php echo $s; ?>" style="margin-bottom: 5px;display: inline-block;"><input type="hidden" name="id_campaign_list_edit" value="<?php echo $afe_detail_campaign_saved_result->id; ?>" /><input type="submit" style="background-color:#0073aa;border:none;color:white;" class="btn" value="Edit"></form>
							<form method="post" action="" style="margin-bottom: 5px;display: inline-block;"><input type="hidden" name="id_campaign_list_del" value="<?php echo $afe_detail_campaign_saved_result->id; ?>" /><input type="submit" class="btn class_edit btn-danger" value="Delete"></form>
						</td>
					</tr>
					<?php
					}
					?>
				  </tbody>
				</table>
			</div>

		</div>
	<?php	
	}
	?>
  </div>
</div>
</div>
<script>
jQuery(function() {
    setTimeout(function() {
          jQuery('.updated').fadeOut('slow');
        }, 5000); // <-- time in milliseconds
});

jQuery(document).ready(function() 
{
  var table = jQuery('#example').DataTable({ 
        select: false,
        "columnDefs": [{
            className: "Name", 
            "targets":[0],
            "visible": false,
            "searchable":false
        }]
    });//End of create main table
});
</script>