<?php
/**
 * Filename: optins.part.php
 * Created by: BlogProfitNetwork.Com <marcus@blogprofitnetwork.com> (https://BlogProfitNetwork.Com)
 * Copyright 2017 - BlogProfitNetwork.Com <marcus@blogprofitnetwork.com> (https://BlogProfitNetwork.Com)
 *
 * Skype: blogprofitnetwork
 * Email: marcus@blogprofitnetwork.com
 * GTalk: marcus@blogprofitnetwork.com
 */
defined('_IN_MAIN_MODULE') or die ('ACCESS DENIED');

global $funnelVoodooDatabase,
	   $funnelVoodooHelpers;

$count = FUNNELVOODOO_DEFAULT_COUNT_OPTINS;
?>



<div class="row">
	<div class="cell">
		<h3>Manage Opt-Ins</h3> <hr />
	</div>
</div>



<?php
if (0 != $count) {
	?>

	<div class="row">
		<div class="cell">
			<div class="ui-tabs-sub">
				<ul>
					<?php for ($tab = 1; $tab <= $count; $tab++) {
						echo '<li><a href="#tab-optin-'. $tab .'">#'. $tab .'</a></li>';
					} ?>
				</ul>


				<?php
				for ($o = 1; $o <= $count; $o++) {
					$options = get_option($funnelVoodooDatabase->tableOptins .'_'. $o);
					if (!is_array($options)) {
						$options = $funnelVoodooDatabase->tableOptinsDefaults;
					}
					?>


					<div id="tab-optin-<?php echo $o; ?>">
						<div class="row">
							<div class="cell">
								<h3>Optin <?php echo $o; ?></h3> <hr />
							</div>
						</div>


						<form>
							<div class="row cells2">
								<div class="cell">
									<label for="optin-<?php echo $o; ?>-enable" class="input-control checkbox adjust-top">
										<input type="checkbox" name="optin-<?php echo $o; ?>-enable" id="optin-<?php echo $o; ?>-enable" rel="<?php echo $o; ?>" <?php checked($options['enable'], FUNNELVOODOO_YES); ?> />
										<span class="check"></span>
										<span class="caption">Enable</span>
									</label>
								</div>
							</div> <br />


							<div class="row cells2">
								<div class="cell">
									<div class="input-control text full-size">
										<label for="optin-<?php echo $o; ?>-title">Title</label>
										<input type="text" name="optin-<?php echo $o; ?>-title" id="optin-<?php echo $o; ?>-title" rel="<?php echo $o; ?>" placeholder="Enter title" value="<?php echo $options['title']; ?>" />
									</div>
								</div>

								<div class="cell">
									<label for="optin-<?php echo $o; ?>-title-hide" class="input-control checkbox adjust-top">
										<input type="checkbox" name="optin-<?php echo $o; ?>-title-hide" id="optin-<?php echo $o; ?>-title-hide" rel="<?php echo $o; ?>" <?php checked($options['title_hide'], FUNNELVOODOO_YES); ?> />
										<span class="check"></span>
										<span class="caption">Hide Title</span>
									</label>
								</div>
							</div> <br />


							<!-- widgets -->
							<div class="row cells2">
								<div class="cell">
									<label for="optin-<?php echo $o; ?>-homepage" class="input-control checkbox adjust-top">
										<input type="checkbox" name="optin-<?php echo $o; ?>-homepage" id="optin-<?php echo $o; ?>-homepage" rel="<?php echo $o; ?>" <?php checked($options['homepage'], FUNNELVOODOO_YES); ?> />
										<span class="check"></span>
										<span class="caption">Homepage</span>
									</label>
								</div>
							</div>
							<div class="row cells2">
								<div class="cell">
									<label for="optin-<?php echo $o; ?>-pages" class="input-control checkbox adjust-top">
										<input type="checkbox" name="optin-<?php echo $o; ?>-pages" id="optin-<?php echo $o; ?>-pages" rel="<?php echo $o; ?>" <?php checked($options['pages'], FUNNELVOODOO_YES); ?> />
										<span class="check"></span>
										<span class="caption">Pages</span>
									</label>

									<div id="holder-optin-<?php echo $o; ?>-pagesid" class="input-control textbox full-size">
										<input type="text" name="optin-<?php echo $o; ?>-pagesid" id="optin-<?php echo $o; ?>-pagesid" placeholder="Enter PagesID. Comma separated." value="<?php echo $options['pagesid']; ?>" />
									</div>
								</div>
							</div>
							<div class="row cells2">
								<div class="cell">
									<label for="optin-<?php echo $o; ?>-posts" class="input-control checkbox adjust-top">
										<input type="checkbox" name="optin-<?php echo $o; ?>-posts" id="optin-<?php echo $o; ?>-posts" rel="<?php echo $o; ?>" <?php checked($options['posts'], FUNNELVOODOO_YES);?> />
										<span class="check"></span>
										<span class="caption">Posts</span>
									</label>

									<div id="holder-optin-<?php echo $o; ?>-postsid" class="input-control textbox full-size">
										<input type="text" name="optin-<?php echo $o; ?>-postsid" id="optin-<?php echo $o; ?>-postsid" placeholder="Enter PostsID. Comma separated." value="<?php echo $options['postsid']; ?>" />
									</div>
								</div>
							</div> <br />
							<!-- // widgets -->


							<!-- contents -->
							<div class="row">
								<div class="cell" style="display:none;">
<!--									<label for="optin---><?php //echo $o; ?><!---contents">Contents</label>-->
									<?php
//									wp_editor($options['contents'], 'optin-'. $o .'-contents', array(
//										'textarea_name'	=> 'optin-'. $o. '-contents',
//										'textarea_rows'	=> 5,
//										'wpautop'		=> true,
//										'media_buttons'	=> true
//									));
//									_WP_Editors::editor_js();
									?>
								</div>
							</div>
							<!-- // contents -->


							<!-- popup -->
							<div class="row cells2">
								<div id="editor-container-<?php echo $o; ?>"></div>
							</div>
							<!-- // popup -->
						</form>
					</div>


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

	<?php
}

?>




<script type="text/javascript">
	var optinsFooterJs = jQuery.noConflict();
	optinsFooterJs(function($) {
		//* auto request for wp_editor() via ajax
		<?php
		for ($editor = 1; $editor <= $count; $editor++) {
			?>

			var editorid 	= 'optin-<?php echo $editor; ?>-contents';
			var data		= {
				action		: 'sp-load-wp-editor',
				editorid	: editorid
			};

			$.post('<?php echo admin_url('admin-ajax.php'); ?>', data, function(response, status) {
				if (status == 'success') {
					var container = $('#editor-container-<?php echo $editor; ?>');
					container.append(response);
					
					$.post('<?php echo admin_url('admin-ajax.php'); ?>', {
						action : 'sp-load-wp-editor-files'
					}, function(response, status) {
						console.log(status);
					});
				}
			});

			<?php
		}
		?>


		//* sub tabs
		$('.ui-tabs-sub').tabs();


		//* posts
		$('input[id*=-posts]').each(function() {
			var $this = $(this);

			if ($this.attr('type') == 'checkbox') {
				$id		= $this.attr('rel');
				$holder	= $('#holder-optin-'+ $id +'-postsid');

				if ($this.is(':checked')) {
					$holder.slideDown();
				}
				else {
					$holder.slideUp();
				}
			}
			return true;
		}).click(function() {
			var $this = $(this);

			if ($this.attr('type') == 'checkbox') {
				$id		= $this.attr('rel');
				$holder	= $('#holder-optin-'+ $id +'-postsid');

				if ($this.is(':checked')) {
					$holder.slideDown();
				}
				else {
					$holder.slideUp();
				}
			}
			return true;
		});


		//* pages
		$('input[id*=-pages]').each(function() {
			var $this = $(this);

			if ($this.attr('type') == 'checkbox') {
				$id		= $this.attr('rel');
				$holder	= $('#holder-optin-'+ $id +'-pagesid');

				if ($this.is(':checked')) {
					$holder.slideDown();
				}
				else {
					$holder.slideUp();
				}
			}
			return true;
		}).click(function() {
			var $this = $(this);

			if ($this.attr('type') == 'checkbox') {
				$id		= $this.attr('rel');
				$holder	= $('#holder-optin-'+ $id +'-pagesid');

				if ($this.is(':checked')) {
					$holder.slideDown();
				}
				else {
					$holder.slideUp();
				}
			}
			return true;
		});
	});
</script>