<script type="text/javascript">
$(document).ready(function () {
    $('.addtoform').click(function(){
		var name = $(this).attr("id");
		$('#customDialog').dialog("close");
		$('#picture').val(name);
    });
});
</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>
<?php
session_start();
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
	header('location:404.php');
}else{
$aksi="po-component/po-pages/proses.php";
?>
	<div class="contentTop">
        <span class="pageTitle"><span class="icon-documents"></span><?php echo $langpages1; ?></span>
    </div>
    <!-- Breadcrumbs line -->
    <div class="breadLine">
        <div class="bc">
            <ul id="breadcrumbs" class="breadcrumbs">
                <li><a href="admin.php?mod=home"><?php echo $langmenu1; ?></a></li>
                <li class="current"><a><?php echo $langpages2; ?></a></li>
            </ul>
        </div>
    </div>
    <!-- Main content -->
    <div class="wrapper">
<?php
switch($_GET[act]){
  default:
?>
<script type="text/javascript">
$(document).ready( function() {
var oTable = $('.dTable').dataTable();
    $('#alertdel').dialog({
		autoOpen: false,
		width: 400,
		modal: true,
		buttons: {
			"<?php echo $langdelete3; ?>": function() {
				var id = $('#delid').val();
				var mod = 'pages';
				var act =  'delete';
				var dataString = 'id='+ id + '&mod='+ mod + '&act='+ act;
				$.ajax({
					type: "POST",
					url: "po-component/po-pages/proses.php",
					data: dataString,
					cache: false,
					success: function(){
						$('#del'+id).slideUp('slow', function() {$(this).remove();});
				}
				});
				$( this ).dialog( "close" );
			},
			"<?php echo $langdelete4; ?>": function() {
				$( this ).dialog( "close" );
			}
		}
	});
    oTable.$('.alertdel').click(function () {
		var id = $(this).attr("id");
        $('#alertdel').dialog('open');
		$('#delid').val(id);
        return false;
    });
});
</script>
	<div class="widget">
		<div class="whead"><span class="titleIcon check"><input type="checkbox" id="titleCheck" name="titleCheck" /></span><h6><?php echo $langpages1; ?></h6><div class="clear"></div></div>
			<div id="dyn" class="hiddenpars">
                <a class="tOptions" title="Options"><img src="images/icons/options" alt="" /></a>
				<form method="post" action="<?php echo $aksi; ?>">
					<input type="hidden" name="mod" value="pages">
					<input type="hidden" name="act" value="multidelete">
					<input type="hidden" value="0" name="totaldata" id="totaldata">
<?php
				$tablepages = new PoTable('pages');
				$pages = $tablepages->findAll(id_pages, DESC);
				$str = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
				$strlink = preg_replace("/\/po-admin\/(admin\.php$)/","",$str);
				echo "<table cellpadding='0' cellspacing='0' border='0' class='dTable checkAll check' id='dynamic'>
						<thead><tr>
							<th><img src='images/elements/other/tableArrows.png' /></th>
							<th>No</th>
							<th>Id</th>
							<th>$langpages3 | Link</th>
							<th>$langpages5</th>
							<th>$langpages6</th>
						</tr></thead><tbody>";
						$no=1;
						foreach($pages as $page){
						echo "<tr class='gradeA' id='del$page->id_pages'>
							<td><input type='checkbox' id='titleCheckdel'></td>
							<input type='hidden' class='deldata' name='item[$no][deldata]' value='$page->id_pages' disabled>
							<td>$no</td>
							<td>$page->id_pages</td>
							<td>
								$page->title
								<br /><i><a href='$strlink/pages-$page->id_pages-$page->seotitle.html' target='_blank'>$strlink/pages-$page->id_pages-$page->seotitle.html</a></i>
							</td>
							<td>$page->active</td>
							<td class='tableActs' align='center'>
								<a href='?mod=pages&act=edit&id=$page->id_pages' class='tablectrl_small bDefault tipS' title='$langaction1'><span class='iconb' data-icon='&#xe1db;'></span></a>
								<span id='$page->id_pages' class='alertdel'><a href='#delete$page->id_pages' class='tablectrl_small bDefault tipS' title='$langaction2'><span class='iconb' data-icon='&#xe136;'></span></a></span>
							</td>
						</tr>";
						$no++;
						}
					echo "</tbody>
					<tfoot>
						<tr><td colspan='6'><div class='itemActions'><input class='buttonS bRed' type='submit' value='Delete Selected Item' onClick=\"return confirm('$langdelete2')\"></div></td></tr>
					</tfoot>
				</table>";
?>
				</form>
			</div>
		<div class="clear"></div>
	</div>
	<div id="alertdel" title="<?php echo $langdelete1; ?>" style="display:none;">
		<p><input type='hidden' id='delid' name='delid'><span class='icon-warning'></span> <?php echo $langdelete2; ?></p>
	</div>
<?php
    break;

	case "addnew":
?>
		<form id="usualValidate" class="main" method="post" action="<?php echo $aksi; ?>" enctype="multipart/form-data" autocomplete="off">
            <fieldset>
				<div class="widget fluid">
				<div class="whead"><h6>Add New</h6><div class="clear"></div></div>
					<input type="hidden" name="mod" value="pages">
					<input type="hidden" name="act" value="input">
					<div class="formRow">
						<div class="grid3"><label>Title</label></div>
						<div class="grid9"><input class="required" type="text" id="title" name="title" required></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<div class="widget">
							<ul class="tabs">
								<li><a href="#tabb1">Content</a></li>
							</ul>
							<div class="tab_container">
							<?php if ($activeeditor=="redactor"){ ?>
								<div id="tabb1" class="tab_content"><textarea id="redactor_content" name="content"></textarea></div>
							<?php }elseif ($activeeditor=="tinymce"){ ?>
								<div id="tabb1" class="tab_content"><textarea id="popojitiny" name="content" style="width:100%; height:500px; border:1px solid #d0d0d0;"></textarea></div>
							<?php }elseif ($activeeditor=="newtinymce"){ ?>
								<div id="tabb1" class="tab_content"><textarea id="wysiwyg" name="content" style="height:500px;"></textarea></div>
							<?php }else{ ?>
								<div id="tabb1" class="tab_content"><textarea id="redactor_content" name="content"></textarea></div>
							<?php } ?>
							</div>
							<div class="clear"></div>
						</div>
					</div>
					<div class="formRow">
						<div class="grid3"><label>Image</label></div>
						<div class="grid9"><div class="btn-group" data-toggle="buttons-radio">
							<button type="button" id="btn_uploadfpc" class="buttonS bGreen">Image From PC</button>
							<a class="buttonS bRed" id="btn_uploadfweb">Images From Web</a>
						</div></div>
						<div class="clear"></div>
					</div>
					<div class="formRow" id="uploadfpc" style="display:none;">
						<div class="grid3"><label>Select Image</label></div>
						<div class="grid9"><input style="opacity: 0;" size="24" class="fileInput" id="fileInput" name="fupload" type="file"><br /><br /><i>Please upload image type must be jpg</i></div>
						<div class="clear"></div>
					</div>
					<div class="formRow" id="uploadfweb" style="display:none;">
						<div class="grid3"><label>Select Image</label></div>
						<div class="grid9"><input type="text" id="picture" name="picture"></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<input class="buttonM bBlue" type="submit" value="Submit">
						<input class="buttonM bRed formSubmit" type="button" value="Cancel" onclick=self.history.back()><div class="clear"></div>
					</div>
				</div>
            </fieldset>
		</form>
<?php
	break;

	case "edit":
	$valid = $val->validasi($_GET['id'],'sql');
	$table = new PoTable('pages');
	$currentPages = $table->findBy(id_pages, $valid);
	$currentPages = $currentPages->current();

	if ($currentPages == '0'){
?>
		<div class="wrapper" id="errorWrapperadmin">
			<span class="errorNum">404</span>
			<div class="errorContent">
				<span class="errorDesc"><span class="icon-warning"></span>Sorry! Your Request Data Not Found. Please Try Again Submit Your Data</span>
			</div>
		</div>
<?php
	}else{
	$dutf=html_entity_decode($currentPages->content);
?>
		<form id="usualValidate" class="main" method="post" action="<?php echo $aksi; ?>" enctype="multipart/form-data" autocomplete="off">
            <fieldset>
				<div class="widget fluid">
				<div class="whead"><h6>Edit Pages</h6><div class="clear"></div></div>
					<input type='hidden' name='mod' value='pages'>
					<input type='hidden' name='act' value='update'>
					<input type='hidden' name='id' value='<?php echo $currentPages->id_pages; ?>'>
					<div class="formRow">
						<div class="grid3"><label>Title</label></div>
						<div class="grid9"><input class="required" type="text" id="title" name="title" value='<?php echo $currentPages->title; ?>' required></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<div class="widget">
							<ul class="tabs">
								<li><a href="#tabb1">Content</a></li>
							</ul>
							<div class="tab_container">
							<?php if ($activeeditor=="redactor"){ ?>
								<div id="tabb1" class="tab_content"><textarea id="redactor_content" name="content"><?php echo $dutf; ?></textarea></div>
							<?php }elseif ($activeeditor=="tinymce"){ ?>
								<div id="tabb1" class="tab_content"><textarea id="popojitiny" name="content" style="width:100%; height:500px; border:1px solid #d0d0d0;"><?php echo $dutf; ?></textarea></div>
							<?php }elseif ($activeeditor=="newtinymce"){ ?>
								<div id="tabb1" class="tab_content"><textarea id="wysiwyg" name="content" style="height:500px;"><?php echo $dutf; ?></textarea></div>
							<?php }else{ ?>
								<div id="tabb1" class="tab_content"><textarea id="redactor_content" name="content"><?php echo $dutf; ?></textarea></div>
							<?php } ?>
							</div>
							<div class="clear"></div>
						</div>
					</div>
					<div class="formRow">
						<?php if ($currentPages->picture==''){ ?>
							<div class="grid3"><label>Image Selected</label></div>
							<div class="grid9">
								<a class="lightbox" 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>
								<p><i>Please upload image type must be jpg and if the image is not replaced, do not choose any option below.</i></p>
							</div>
							<div class="clear"></div>
						<?php }else{ ?>
							<div class="grid3"><label>Image Selected</label></div>
							<div class="grid9">
								<a class="lightbox" href="../po-content/po-upload/<?php echo $currentPages->picture; ?>">Existing Image Preview</a>
								<p><i>Please upload image type must be jpg and if the image is not replaced, do not choose any option below.</i></p>
							</div>
							<div class="clear"></div>
						<?php } ?>
					</div>
					<div class="formRow">
						<div class="grid3"><label>Change Image</label></div>
						<div class="grid9"><div class="btn-group" data-toggle="buttons-radio">
							<button type="button" id="btn_uploadfpc" class="buttonS bGreen">Image From PC</button>
							<a class="buttonS bRed" id="btn_uploadfweb">Images From Web</a>
						</div></div>
						<div class="clear"></div>
					</div>
					<div class="formRow" id="uploadfpc" style="display:none;">
						<div class="grid3"><label>Select Image</label></div>
						<div class="grid9"><input style="opacity: 0;" size="24" class="fileInput" id="fileInput" name="fupload" type="file"><br /><br /><i>Please upload image type must be jpg</i></div>
						<div class="clear"></div>
					</div>
					<div class="formRow" id="uploadfweb" style="display:none;">
						<div class="grid3"><label>Select Image</label></div>
						<div class="grid9"><input type="text" id="picture" name="picture"></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<?php if ($currentPages->active=="N"){ ?>
							<div class="grid3"><label>Active</label></div>
							<div class="grid9">
								<div id="uniform-radio1" class="radio"><input style="opacity: 0;" type="radio" id="active1" name="active" value="Y"></div><label for="active1" class="mr20">Y</label>
								<div id="uniform-radio2" class="radio"><input style="opacity: 0;" type="radio" id="active2" name="active" value="N" checked="checked"></div><label for="active2" class="mr20">N</label>
							</div>
							<div class="clear"></div>
						<?php }else{ ?>
							<div class="grid3"><label>Active</label></div>
							<div class="grid9">
								<div id="uniform-radio1" class="radio"><input style="opacity: 0;" type="radio" id="active1" name="active" value="Y" checked="checked"></div><label for="active1" class="mr20">Y</label>
								<div id="uniform-radio2" class="radio"><input style="opacity: 0;" type="radio" id="active2" name="active" value="N"></div><label for="active2" class="mr20">N</label>
							</div>
							<div class="clear"></div>
						<?php } ?>
					</div>
					<div class="formRow">
						<input class="buttonM bBlue" type="submit" value="Submit">
						<input class="buttonM bRed formSubmit" type="button" value="Cancel" onclick=self.history.back()><div class="clear"></div>
					</div>
				</div>
            </fieldset>
		</form>
<?php
	}
    break;
}
?>
		<!-- Dialog content -->
		<div id="customDialog" class="customDialog" title="Images From Web">
			<div id="paging_container">
				<table class="tDefault" cellpadding="0" cellspacing="0" width="100%">
					<thead><tr>
						<td>Image</td>
						<td>Image Name</td>
						<td>Action</td>
					</tr></thead><tbody class="contentmed">
					<?php
						$tablemedia = new PoTable("media");
						$medias = $tablemedia->findAll(id_media, DESC);
						foreach($medias as $media){
							$pecah = explode("/", $media->file_type);
							$fileType = $pecah[0];
							$cari = "$media->file_name";
							$tanda = "popoji";
							if ($fileType=="image"){
					?>
								<tr>
									<td><a href="../po-content/po-upload/<?php echo $media->file_name; ?>" title="" class="lightbox"><img src="../po-content/po-upload/medium-<?php echo $media->file_name; ?>" width="60" height="60" class="img-polaroid" /></a></td>
									<td><?php echo $media->file_name; ?></td>
									<td>
										<?php if ($yangdicari = strstr($cari, $tanda)){ ?>
											<a id="<?php echo $media->file_name; ?>" class="addtoform"><span class="label label-info"><i class="icon-picture icon-white"></i>Add to Form</span></a>
										<?php }else{ ?>
											<span class="label label-inverse"><i class="icon-picture icon-white"></i>Can't Add</span>
										<?php } ?>
									</td>
								</tr>
					<?php
							}else{}
						}
					?>
					</tbody></table>
				<div class="page_navigation"></div>
			</div>
		</div>
	</div>
<?php
}
?>