<script type="text/javascript">
$(function(){
	$('#redactor_content').redactor();
	$('#redactor_content2').redactor();
});
</script>

<script type="text/javascript">
$(function(){
    $('#pagestab a').click(function (e) {
		e.preventDefault();
		$(this).tab('show');
    })
});
</script>

<script type="text/javascript">
function valpost(form){
	if (form.title_id.value == ""){
		$(".page-error").show();
		form.title_id.focus();
		return (false);
	}
	if (form.title_en.value == ""){
		$(".page-error").show();
		form.title_en.focus();
		return (false);
	}
	return (true);
}
</script>

<script type="text/javascript">
$(document).ready(function () {
	$("#title_id").keyup(function() {
		$(".page-error").fadeOut('slow');
	});
	$("#title_en").keyup(function() {
		$(".page-error").fadeOut('slow');
	});
});
</script>

<script type="text/javascript">
$(document).ready(function () {
	$('#picture').keypress(function(e){
		e.preventDefault();    
	});
    $('#btn_uploadfpc').click(function(){
		$('#uploadfpc').show();
		$('#uploadfweb').hide();
		$('#picture').val('');
    });
    $('#btn_uploadfweb').click(function(){
		$('#uploadfpc').hide();
		$('#uploadfweb').show();
		$('#picture').val('');
    });
});
</script>

<script type="text/javascript">
	$(document).ready(function(){
		$('#paging_container').pajinate({
			items_per_page : 5,
			num_page_links_to_display : 5
					
		});
	});
</script>

<script type="text/javascript">
$(document).ready(function(){
	$('a[data-toggle="modal"]').click(function(e) {
		e.preventDefault();
		target = ($ @).attr('data-target')
		url = ($ @).attr('href')
		($ target).load(url)
	});
});
</script>

<script type="text/javascript">
$(document).ready(function () {
    $('.addtoform').click(function(){
		var name = $(this).attr("id");
		$('#addimage').modal('hide');
		$('#picture').val(name);
    });
});
</script>

<script language="javascript">
$(document).ready( function() {
	$("#btnalertdel").click(function(){
		var id = $('#delid').val();
		var mod = 'post';
		var act =  'delete';
		var dataString = 'id='+ id + '&mod='+ mod + '&act='+ act;
		$.ajax({
			type: "POST",
			url: "po-component/po-post/proses.php",
			data: dataString,
			cache: false,
			success: function(){
				$('#del'+id).slideUp('slow', function() {$(this).remove();});
				$('#alertdel').modal('hide');
			}
		});
		return false;
	});
});
</script>

<?php
session_start();
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
	header('location:404.php');
}else{

$aksi="po-component/po-post/proses.php";
switch($_GET[act]){
	default:
?>
<script language="javascript">
$(document).ready( function() {
var oTable = $('#tableboot').dataTable();
	oTable.$(".alertdel").click(function(){
		var id = $(this).attr("id");
		$('#alertdel').modal('show');
		$('#delid').val(id);
	});
});
</script>
<?php
	echo "<div class='page-header'>
		<div class='icon'>
			<span class='ico-pen-2'></span>
		</div>
		<h1>$langpost1<small><span class='text-info'>$langpost2</span></small></h1>
	</div>
	<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>";
				$tablepost = new PoTable('post');
				$posts = $tablepost->findAll(id_post, DESC);
				echo "<div class='data-fluid'>
					<table cellspacing='0' border='0' class='table table-hover' id='tableboot'>
						<thead><tr>
							<th>No</th>
							<th>$langpost3</th>
							<th>$langpost4 <i>($langpost5)</i></th>
							<th>$langpost6</th>
							<th>$langpost7</th>
						</tr></thead><tbody>";
						$no=1;
						foreach($posts as $post){
						$valid = $post->id_category;
						$tablecat = new PoTable('category');
						$currentCat = $tablecat->findBy(id_category, $valid);
						$currentCat = $currentCat->current();
						echo "<tr class='gradeA' id='del$post->id_post'>
							<td>$no</td>
							<td>$currentCat->title_id</td>
							<td>
								$post->title_id <i>($post->title_en)</i><br />
								<form method='post' action='$aksi'>
									<input type='hidden' name='mod' value='post'>
									<input type='hidden' name='act' value='subscribe'>
									<input type='hidden' name='idsub' value='$post->id_post'>
									<input type='hidden' name='titlesub' value='$post->title_id'>
									<input type='hidden' name='seotitlesub' value='$post->seotitle_id'>
									<button class='btn btn-info' type='submit'><i class='ico-rss icon-white'></i>Subscribe</button>
								</form>
							</td>
							<td>$post->active</td>
							<td>
								<a href='?mod=post&act=edit&id=$post->id_post'><span class='label label-info'><i class='icon-file icon-white'></i> $langaction1</span></a>
								<a href='#delete$post->id_post' class='alertdel' id='$post->id_post'><span class='label label-important'><i class='icon-remove icon-white'></i> $langaction2</span></a>
							</td>
						</tr>";
						$no++;
						}
					echo "</tbody></table>
				</div>
			</div>
			<div style='width:100%; height:500px;'>&nbsp;</div>
		</div>
	</div>

	<div id='alertdel' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel3' aria-hidden='true' style='width:570px;'>
		<div class='modal-header'>
			<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
			<h3 id='myModalLabel3'>$langdelete1</h3>
		</div>
		<div class='modal-body'>
			<input type='hidden' id='delid' name='delid'>
			<span class='ico-warning'></span> $langdelete2
		</div>
		<div class='modal-footer'>
			<button id='btnalertdel' class='btn btn-danger'>$langdelete3</button>
			<button class='btn' data-dismiss='modal' aria-hidden='true'>$langdelete4</button>
		</div>
	</div>";
    break;

	case "addnew":
	echo "<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>
				<legend><i class='icon-pencil'></i> Add New</legend>
				<form method='post' action='$aksi' enctype='multipart/form-data' autocomplete='off' onSubmit='return valpost(this)'>
					<input type='hidden' name='mod' value='post'>
					<input type='hidden' name='act' value='input'>
					<fieldset>
						<label>Category</label>
						<select class='select' name='id_category' style='width:280px;'>";
							$tablecats = new PoTable('category');
							$cats = $tablecats->findAll(id_category, ASC);
							foreach($cats as $cat){
								echo "<option value='$cat->id_category'>$cat->title_id</option>";
							}
						echo "</select>
						<label>Title Id</label><input class='input-xxlarge' type='text' id='title_id' name='title_id' required>
						<label>Title En</label><input class='input-xxlarge' type='text' id='title_en' name='title_en' required>
						<br />&nbsp;
						<ul class='nav nav-tabs' id='pagestab'>
							<li class='active'><a href='#content_pid'>Content Id</a></li>
							<li><a href='#content_pen'>Content En</a></li>
						</ul>
						<div class='tab-content'>
							<div class='tab-pane active' id='content_pid'><textarea id='redactor_content' name='content_id'></textarea></div>
							<div class='tab-pane' id='content_pen'><textarea id='redactor_content2' name='content_en'></textarea></div>
						</div><br />
						<label>Tags</label>
						<select  multiple='multiple' class='select' name='tag[]' style='width:280px;'>";
							$tabletag = new PoTable('tag');
							$tags = $tabletag->findAll(id_tag, DESC);
							foreach($tags as $tag){
								echo "<option value='$tag->tag_seo'>$tag->tag_title</option>";
							}
						echo "</select>
						<p>&nbsp;</p>
						<label>Image *</label>
						<div class='btn-group' data-toggle='buttons-radio'>
							<button type='button' id='btn_uploadfpc' class='btn'>Image From PC</button>
							<a class='btn' id='btn_uploadfweb' data-toggle='modal' href='po-component/po-post/media.php' data-target='#addimage'>Image From Web</a>
						</div><br />
						<div id='uploadfpc' style='display:none;'>
							<p>&nbsp;</p>
							<div class='fileupload fileupload-new' data-provides='fileupload'>
								<div class='fileupload-new thumbnail' style='width: 200px; height: 150px;'>
									<img src='data:image/gif;base64,R0lGODdhyACWAOMAAO/v76qqqubm5t3d3bu7u7KystXV1cPDw8zMzAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAyACWAAAE/hDISau9OOvNu/9gKI5kaZ5oqq5s675wLM90bd94ru987//AoHBILBqPyKRyyWw6n9CodEqtWq/YrHbL7Xq/4LB4TC6bz+i0es1uu9/wuHxOr9vv+Lx+z+/7/4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3TAMFBQO4LAUBAQW+K8DCxCoGu73IzSUCwQECAwQBBAIVCMAFCBrRxwDQwQLKvOHV1xbUwQfYEwIHwO3BBBTawu2BA9HGwcMT1b7Vw/Dt3z563xAIrHCQnzsAAf0F6ybhwDdwgAx8OxDQgASN/sKUBWNmwQDIfwBAThRoMYDHCRYJGAhI8eRMf+4OFrgZgCKgaB4PHqg4EoBQbxgBROtlrJu4ofYm0JMQkJk/mOMkTA10Vas1CcakJrXQ1eu/sF4HWhB3NphYlNsmxOWKsWtZtASTdsVb1mhEu3UDX3RLFyVguITzolQKji/GhgXNvhU7OICgsoflJr7Qd2/isgEPGGAruTTjnSZTXw7c1rJpznobf2Y9GYBjxIsJYQbXstfRDJ1luz6t2TDvosSJSpMw4GXG3TtT+hPpEoPJ6R89B7AaUrnolgWwnUQQEKVOAy199mlonPDfr3m/GeUHFjBhAf0SUh28+P12QOIIgDbcPdwgJV+Arf0jnwTwsHOQT/Hs1BcABObjDAcTXhiCOGppKAJI6nnIwQGiKZSViB2YqB+KHtxjjXMsxijjjDTWaOONOOao44489ujjj0AGKeSQRBZp5JFIJqnkkkw26eSTUEYp5ZRUVmnllVhmqeWWXHbp5ZdghinmmGSW6UsEADs=' />
								</div>
								<div class='fileupload-preview fileupload-exists thumbnail' style='max-width: 200px; max-height: 150px; line-height: 20px;'></div>
							<div>
							<span class='btn btn-file'>
								<span class='fileupload-new'>Select image</span>
								<span class='fileupload-exists'>Change</span>
								<input type='file' name='fupload' />
							</span>
							<a href='#' class='btn fileupload-exists' data-dismiss='fileupload'>Remove</a>
						</div>
						</div></div>
						<div id='uploadfweb' style='display:none;'>
							<p>&nbsp;</p>
							<label>Image</label><input class='input-xxlarge' type='text' id='picture' name='picture'>
						</div><br />&nbsp;
						<span class='label label-important'>*) Please upload image type must be jpg.</span>
						<br /><br />
						<input class='btn btn-large' type='submit' value='Submit'>
						<input class='btn btn-large btn-inverse' type='button' value='Cancel' onclick=self.history.back()>
					</fieldset>
				</form><br />
				<div class='page-error'>
					<div class='alert alert-error'>
					<strong><i class='icon-file icon-white'></i> Warning!</strong> Best check yourself, you're not looking too good.
				</div>
			</div>
		</div>
	</div>
	<div style='width:100%; height:750px;'>&nbsp;</div>
	
	<div id='addimage' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true' style='width:570px;'>
		<div class='modal-header'>
			<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
			<h3 id='myModalLabel'>Add Image From Web</h3>
		</div>
		<div class='modal-body'>
		</div>
		<div class='modal-footer'>
			<button class='btn' data-dismiss='modal' aria-hidden='true'>Cancel</button>
		</div>
	</div>";
	break;

	case "edit":
	$valid = $val->validasi($_GET['id'],'sql');
	$table = new PoTable('post');
	$currentPosts = $table->findBy(id_post, $valid);
	$currentPosts = $currentPosts->current();
	$dutf=html_entity_decode($currentPosts->content_id);
	$dutf2=html_entity_decode($currentPosts->content_en);
	echo "<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>
				<legend><i class='icon-pencil'></i> Edit Post</legend>
				<form method='post' action='$aksi' enctype='multipart/form-data' autocomplete='off' onSubmit='return valpag(this)'>
					<input type='hidden' name='mod' value='post'>
					<input type='hidden' name='act' value='update'>
					<input type='hidden' name='id' value='$currentPosts->id_post'>
					<fieldset>
						<label>Category</label>
						<select class='select' name='id_category' style='width:280px;'>";
							$tableselcats = new PoTable('category');
							$selcats = $tableselcats->findBy(id_category, $currentPosts->id_category);
							$selcats = $selcats->current();
								echo "<option value='$selcats->id_category'>$selcats->title_id</option>";
							$tablecats = new PoTable('category');
							$cats = $tablecats->findNotAll(id_category, $currentPosts->id_category);
							foreach($cats as $cat){
								echo "<option value='$cat->id_category'>$cat->title_id</option>";
							}
						echo "</select>
						<label>Title Id</label><input class='input-xxlarge' type='text' id='title_id' name='title_id' value='$currentPosts->title_id' required>
						<label>Title En</label><input class='input-xxlarge' type='text' id='title_en' name='title_en' value='$currentPosts->title_en' required>
						<br />&nbsp;
						<ul class='nav nav-tabs' id='pagestab'>
							<li class='active'><a href='#content_pid'>Content Id</a></li>
							<li><a href='#content_pen'>Content En</a></li>
						</ul>
						<div class='tab-content'>
							<div class='tab-pane active' id='content_pid'><textarea id='redactor_content' name='content_id'>$dutf</textarea></div>
							<div class='tab-pane' id='content_pen'><textarea id='redactor_content2' name='content_en'>$dutf2</textarea></div>
						</div><br />";
						if ($currentPosts->picture==''){
							echo "<label><a class='fb' href='data:image/gif;base64,R0lGODdhyACWAOMAAO/v76qqqubm5t3d3bu7u7KystXV1cPDw8zMzAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAyACWAAAE/hDISau9OOvNu/9gKI5kaZ5oqq5s675wLM90bd94ru987//AoHBILBqPyKRyyWw6n9CodEqtWq/YrHbL7Xq/4LB4TC6bz+i0es1uu9/wuHxOr9vv+Lx+z+/7/4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3TAMFBQO4LAUBAQW+K8DCxCoGu73IzSUCwQECAwQBBAIVCMAFCBrRxwDQwQLKvOHV1xbUwQfYEwIHwO3BBBTawu2BA9HGwcMT1b7Vw/Dt3z563xAIrHCQnzsAAf0F6ybhwDdwgAx8OxDQgASN/sKUBWNmwQDIfwBAThRoMYDHCRYJGAhI8eRMf+4OFrgZgCKgaB4PHqg4EoBQbxgBROtlrJu4ofYm0JMQkJk/mOMkTA10Vas1CcakJrXQ1eu/sF4HWhB3NphYlNsmxOWKsWtZtASTdsVb1mhEu3UDX3RLFyVguITzolQKji/GhgXNvhU7OICgsoflJr7Qd2/isgEPGGAruTTjnSZTXw7c1rJpznobf2Y9GYBjxIsJYQbXstfRDJ1luz6t2TDvosSJSpMw4GXG3TtT+hPpEoPJ6R89B7AaUrnolgWwnUQQEKVOAy199mlonPDfr3m/GeUHFjBhAf0SUh28+P12QOIIgDbcPdwgJV+Arf0jnwTwsHOQT/Hs1BcABObjDAcTXhiCOGppKAJI6nnIwQGiKZSViB2YqB+KHtxjjXMsxijjjDTWaOONOOao44489ujjj0AGKeSQRBZp5JFIJqnkkkw26eSTUEYp5ZRUVmnllVhmqeWWXHbp5ZdghinmmGSW6UsEADs='>Existing Image Preview</a></label><br />";
						}else{
							echo "<label><a class='fb' href='../po-content/po-upload/$currentPosts->picture'>Existing Image Preview</a></label><br />";
						}
						echo "<div class='span5'>
						<label>Image *</label>
						<div class='btn-group' data-toggle='buttons-radio'>
							<button type='button' id='btn_uploadfpc' class='btn'>Image From PC</button>
							<a class='btn' id='btn_uploadfweb' data-toggle='modal' href='po-component/po-post/media.php' data-target='#addimage'>Image From Web</a>
						</div>
						<div id='uploadfpc' style='display:none;'>
							<p>&nbsp;</p>
							<div class='fileupload fileupload-new' data-provides='fileupload'>
								<div class='fileupload-new thumbnail' style='width: 200px; height: 150px;'>
									<img src='data:image/gif;base64,R0lGODdhyACWAOMAAO/v76qqqubm5t3d3bu7u7KystXV1cPDw8zMzAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAyACWAAAE/hDISau9OOvNu/9gKI5kaZ5oqq5s675wLM90bd94ru987//AoHBILBqPyKRyyWw6n9CodEqtWq/YrHbL7Xq/4LB4TC6bz+i0es1uu9/wuHxOr9vv+Lx+z+/7/4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3TAMFBQO4LAUBAQW+K8DCxCoGu73IzSUCwQECAwQBBAIVCMAFCBrRxwDQwQLKvOHV1xbUwQfYEwIHwO3BBBTawu2BA9HGwcMT1b7Vw/Dt3z563xAIrHCQnzsAAf0F6ybhwDdwgAx8OxDQgASN/sKUBWNmwQDIfwBAThRoMYDHCRYJGAhI8eRMf+4OFrgZgCKgaB4PHqg4EoBQbxgBROtlrJu4ofYm0JMQkJk/mOMkTA10Vas1CcakJrXQ1eu/sF4HWhB3NphYlNsmxOWKsWtZtASTdsVb1mhEu3UDX3RLFyVguITzolQKji/GhgXNvhU7OICgsoflJr7Qd2/isgEPGGAruTTjnSZTXw7c1rJpznobf2Y9GYBjxIsJYQbXstfRDJ1luz6t2TDvosSJSpMw4GXG3TtT+hPpEoPJ6R89B7AaUrnolgWwnUQQEKVOAy199mlonPDfr3m/GeUHFjBhAf0SUh28+P12QOIIgDbcPdwgJV+Arf0jnwTwsHOQT/Hs1BcABObjDAcTXhiCOGppKAJI6nnIwQGiKZSViB2YqB+KHtxjjXMsxijjjDTWaOONOOao44489ujjj0AGKeSQRBZp5JFIJqnkkkw26eSTUEYp5ZRUVmnllVhmqeWWXHbp5ZdghinmmGSW6UsEADs=' />
								</div>
								<div class='fileupload-preview fileupload-exists thumbnail' style='max-width: 200px; max-height: 150px; line-height: 20px;'></div>
							<div>
							<span class='btn btn-file'>
								<span class='fileupload-new'>Select image</span>
								<span class='fileupload-exists'>Change</span>
								<input type='file' name='fupload' />
							</span>
							<a href='#' class='btn fileupload-exists' data-dismiss='fileupload'>Remove</a>
						</div>
						</div></div>
						<div id='uploadfweb' style='display:none;'>
							<p>&nbsp;</p>
							<label>Image</label><input class='input-xxlarge' type='text' id='picture' name='picture'>
						</div>
						</div>
						<div class='span5'>
						<label>Tags</label>";
						function GetCheckboxes($tagging){
							$tabletag = new PoTable('tag');
							$tags = $tabletag->findAll(id_tag, DESC);
							$_arrNilai = explode(',', $tagging);
							$str = '';
							foreach($tags as $tag){
								$_ck = (array_search($tag->tag_seo, $_arrNilai) === false)? '' : 'selected=selected';
								$str .= "<option value='$tag->tag_seo' $_ck>$tag->tag_title</option>";
							}
							return $str;
						}
						$d = GetCheckboxes($currentPosts->tag);
						echo "<select  multiple='multiple' class='select' name='tag[]' style='width:100%;'>$d</select>
						<p>&nbsp;</p>";
						if ($currentPosts->active=='N'){
							echo "<label>Active</label>
							<label class='radio inline'><input type='radio' name='active' value='Y'>Y</label>
							<label class='radio inline'><input type='radio' name='active' value='N' checked>N</label><br /><br />";
						}else{
							echo "<label>Active</label>
							<label class='radio inline'><input type='radio' name='active' value='Y' checked>Y</label>
							<label class='radio inline'><input type='radio' name='active' value='N'>N</label><br /><br />";
						}
						echo "<input class='btn btn-large' type='submit' value='Submit'>
						<input class='btn btn-large btn-inverse' type='button' value='Cancel' onclick=self.history.back()>
						</div>
					</fieldset>
				</form>
				<p>&nbsp;</p>
				<p>&nbsp;</p>
				<div class='pages-error'>
					<div class='alert alert-error'>
					<strong><i class='icon-pencil icon-white'></i> Warning!</strong> Please upload image type must be jpg and if the image is not replaced, do not choose any option below.
				</div>
				<p>&nbsp;</p>
				<div class='page-error'>
					<div class='alert alert-error'>
					<strong><i class='icon-pencil icon-white'></i> Warning!</strong> Best check yourself, you're not looking too good.
				</div>
			</div>
		</div>
	</div>
	<div style='width:100%; height:1100px;'>&nbsp;</div>
	
	<div id='addimage' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel2' aria-hidden='true' style='width:570px;'>
		<div class='modal-header'>
			<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
			<h3 id='myModalLabel2'>Add Image From Web</h3>
		</div>
		<div class='modal-body'>
		</div>
		<div class='modal-footer'>
			<button class='btn' data-dismiss='modal' aria-hidden='true'>Cancel</button>
		</div>
	</div>";
	break;
}
}
?>