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

$recentcommentsCount = FUNNELVOODOO_DEFAULT_COUNT_RECENTCOMMENTS;
?>


<div class="row">
	<div class="cell">
		<h3>Manage Recent Comments</h3> <hr />
	</div>
</div>


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

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


				<?php
				for ($a = 1; $a <= $recentcommentsCount; $a++) {
					$recentcommentsOptions = get_option($funnelVoodooDatabase->tableRecentComments .'_'. $a);
					if (!is_array($recentcommentsOptions)) {
						$recentcommentsOptions = $funnelVoodooDatabase->tableRecentCommentsDefaults;
					}
					?>


					<div id="tab-recentcomments-<?php echo $a; ?>">
						<div class="row">
							<div class="cell">
								<h3>Recent Comments <?php echo $a; ?></h3> <hr />
							</div>
						</div>


						<form name="recentcommentsForm" id="recentcommentsForm" method="POST" action="">
							<div class="row cells2">
								<div class="cell">
									<label for="<?php echo $a; ?>-recentcomments-enable" class="input-control checkbox adjust-top">
										<input type="checkbox" name="<?php echo $a; ?>-recentcomments-enable" id="<?php echo $a; ?>-recentcomments-enable" rel="<?php echo $a; ?>" <?php checked($recentcommentsOptions['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="<?php echo $a; ?>-recentcomments-title">Title</label>
										<input type="text" name="<?php echo $a; ?>-recentcomments-title" id="<?php echo $a; ?>-recentcomments-title" rel="<?php echo $a; ?>" placeholder="Enter title" value="<?php echo $recentcommentsOptions['title']; ?>" />
									</div>
								</div>

								<div class="cell">
									<label for="<?php echo $a; ?>-recentcomments-title-hide" class="input-control checkbox adjust-top">
										<input type="checkbox" name="<?php echo $a; ?>-recentcomments-title-hide" id="<?php echo $a; ?>-recentcomments-title-hide" rel="<?php echo $a; ?>" <?php checked($recentcommentsOptions['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="<?php echo $a; ?>-recentcomments-homepage" class="input-control checkbox adjust-top">
										<input type="checkbox" name="<?php echo $a; ?>-recentcomments-homepage" id="<?php echo $a; ?>-recentcomments-homepage" rel="<?php echo $a; ?>" <?php checked($recentcommentsOptions['sidebar']['homepage'], FUNNELVOODOO_YES); ?> />
										<span class="check"></span>
										<span class="caption">Homepage</span>
									</label>
								</div>
							</div>
							<div class="row cells2">
								<div class="cell">
									<label for="<?php echo $a; ?>-recentcomments-pages" class="input-control checkbox adjust-top">
										<input type="checkbox" name="<?php echo $a; ?>-recentcomments-pages" id="<?php echo $a; ?>-recentcomments-pages" rel="<?php echo $a; ?>" <?php checked($recentcommentsOptions['sidebar']['pages'], FUNNELVOODOO_YES); ?> />
										<span class="check"></span>
										<span class="caption">Pages</span>
									</label>

									<div id="holder-<?php echo $a; ?>-recentcomments-pagesid" class="row cells2" style="margin-top:5px;">
										<div class="cell">
											<div class="input-control textbox full-size">
												<label for="">Display</label>
												<input type="text" name="<?php echo $a; ?>-recentcomments-pagesid" id="<?php echo $a; ?>-recentcomments-pagesid" placeholder="Enter PagesID. Comma separated." value="<?php echo $recentcommentsOptions['sidebar']['pagesid']; ?>" />
											</div>
										</div>

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

									<div id="holder-<?php echo $a; ?>-recentcomments-postsid" class="row cells2" style="margin-top:5px;">
										<div class="cell">
											<div class="input-control textbox full-size">
												<label for="">Display</label>
												<input type="text" name="<?php echo $a; ?>-recentcomments-postsid" id="<?php echo $a; ?>-recentcomments-postsid" placeholder="Enter PostsID. Comma separated." value="<?php echo $recentcommentsOptions['sidebar']['postsid']; ?>" />
											</div>
										</div>

										<div class="cell">
											<div class="input-control textbox full-size">
												<label for="">Hide</label>
												<input type="text" name="<?php echo $a; ?>-recentcomments-nopostsid" id="<?php echo $a; ?>-recentcomments-nopostsid" placeholder="Enter PostsID. Comma separated." value="<?php echo $recentcommentsOptions['sidebar']['nopostsid']; ?>" />
											</div>
										</div>
									</div>
								</div>
							</div> <br />
							<!-- // widgets -->


							<!-- contents -->
							<div class="row">
								<div class="cell">
									<label for="<?php echo $a; ?>-recentcomments-contents">Contents</label>
									<?php
									wp_editor(str_replace('\\', '', $recentcommentsOptions['contents']), $a .'-recentcomments-contents', array(
										'textarea_name'	=> $a. '-recentcomments-contents',
										'textarea_rows'	=> 5,
										'wpautop'		=> true,
										'media_buttons'	=> true
									));
									?>
								</div>
							</div> <br />
							<!-- // contents -->


							<!-- how many -->
							<div class="row cells2">
								<div class="cell">
									<div class="input-control select full-size">
										<label for="<?php echo $a; ?>-recentcomments-how-many">How Many To Display</label>
										<select name="<?php echo $a; ?>-recentcomments-how-many" id="<?php echo $a; ?>-recentcomments-how-many" style="height:38px;">
											<?php
												for ($rc = 0; $rc <= 20; $rc++) {
													echo '<option value="'. $rc .'" '. selected($rc, $recentcommentsOptions['how_many']) .'>'. $rc .'</option>';
												}
												?>
										</select>
									</div>
								</div>
							</div> <br />
							<!-- // how many -->


							<!-- submit -->
							<div class="row cells2">
								<div class="cell">
									<input type="submit" name="cmdSubmitRecentComments" id="cmdSubmitRecentComments" rel="<?php echo $a; ?>" class="button button-primary" value="Submit Changes for Recent Comments <?php echo $a; ?>" />
									<span id="dialog-<?php echo $a; ?>-recentcomments" style="margin-left:10px;"></span>
								</div>
							</div>
							<!-- // submit -->

						</form>
					</div>


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

	<?php
}
?>


<script type="text/javascript">
	var recentcommentsJs = jQuery.noConflict();
	recentcommentsJs(function($) {
		//* submit
		$('input[id*=cmdSubmitRecentComments]').click(function() {
			var $this					= $(this),
				$id						= $this.attr('rel'),

				$enable					= $('#'+ $id +'-recentcomments-enable'),
				$title					= $('#'+ $id +'-recentcomments-title'),
				$titleHide				= $('#'+ $id +'-recentcomments-title-hide'),

				$homepage				= $('#'+ $id +'-recentcomments-homepage'),
				$pages					= $('#'+ $id +'-recentcomments-pages'),
				$pagesid				= $('#'+ $id +'-recentcomments-pagesid'),
				$nopagesid				= $('#'+ $id +'-recentcomments-nopagesid'),
				$posts					= $('#'+ $id +'-recentcomments-posts'),
				$postsid				= $('#'+ $id +'-recentcomments-postsid'),
				$nopostsid				= $('#'+ $id +'-recentcomments-nopostsid'),

				$contents				= tinymceGetContent($id +'-recentcomments-contents'),
				
				$howMany                = $('#'+ $id +'-recentcomments-how-many'),

				$dialog					= $('#dialog-'+ $id +'-recentcomments'),

				$data					= {
					action					: 'sp-update-recentcomments',
					id						: $id,

					enable					: $enable.is(':checked'),
					title					: $title.val(),
					titleHide				: $titleHide.is(':checked'),

					homepage				: $homepage.is(':checked'),
					pages					: $pages.is(':checked'),
					pagesid					: $pagesid.val(),
					nopagesid				: $nopagesid.val(),
					posts					: $posts.is(':checked'),
					postsid					: $postsid.val(),
					nopostsid				: $nopostsid.val(),

					contents				: $contents,
					
					howMany                 : $howMany.val()
				};

			$dialog.empty().append('<span class="icon mif-spinner2 mif-ani-spin"></span> Submitting data... Please wait!');
			$.post('<?php echo admin_url('admin-ajax.php'); ?>', $data, function(res) {
				if (res == 'error') {
					$dialog.empty().append('<span class="icon mif-cross fg-red"></span> Data cannot be processed. Please try again!');
				}
				else {
					$dialog.empty().append('<span class="icon mif-checkmark fg-green"></span> Data has been successfully submitted.');
				}
			});
			return false;
		});


		//* posts
		$('input[id*=-recentcomments-posts]').each(function() {
			var $this 	= $(this),
				$id		= $this.attr('rel'),
				$holder	= $('#holder-'+ $id +'-recentcomments-postsid');

			if ($this.attr('type') == 'checkbox') {
				if ($this.is(':checked')) {
					$holder.slideDown();
				}
				else {
					$holder.slideUp();
				}
			}
			return true;
		}).click(function() {
			var $this 	= $(this),
				$id		= $this.attr('rel'),
				$holder	= $('#holder-'+ $id +'-recentcomments-postsid');

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


		//* pages
		$('input[id*=-recentcomments-pages]').each(function() {
			var $this 	= $(this),
				$id		= $this.attr('rel'),
				$holder	= $('#holder-'+ $id +'-recentcomments-pagesid');

			if ($this.attr('type') == 'checkbox') {
				if ($this.is(':checked')) {
					$holder.slideDown();
				}
				else {
					$holder.slideUp();
				}
			}
			return true;
		}).click(function() {
			var $this 	= $(this),
				$id		= $this.attr('rel'),
				$holder	= $('#holder-'+ $id +'-recentcomments-pagesid');

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