<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 = 'banner';
				var act =  'delete';
				var dataString = 'id='+ id + '&mod='+ mod + '&act='+ act;
				$.ajax({
					type: "POST",
					url: "po-component/po-banner/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>

<script type="text/javascript">
$(document).ready( function() {
var oTable = $('.dTable').dataTable();
    // Dialog Link
    oTable.$('.tbledit').click(function () {
		var idisi = $(this).attr('id');
        $('#editdata'+idisi).dialog('open');
        return false;
    });
});
</script>

<script type="text/javascript">
$(document).ready( function() {
    $('.editdata').dialog({
        autoOpen: false,
        width: 400,
		modal: true
    });
});
</script>
<?php
//Author  	= 'Jenuar Dwi Putra Dalapang';
//Contact 	= 'mailto:djenuar@gmail.com';

session_start();
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
	header('location:404.php');
}else{
$aksi="po-component/po-banner/proses.php";
?>
	<div class="contentTop">
        <span class="pageTitle"><span class="icos-money"></span>Banner Management</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>Input, edit, view and delete banner management</a></li>
            </ul>
        </div>
    </div>
    <!-- Main content -->
    <div class="wrapper">
<?php
switch($_GET[act]){
  default:
?>
	<div class="widget">
		<div class="whead"><h6>Banner Management</h6><div class="clear"></div></div>
            <ul class="tToolbar">
                <li><a href="?mod=banner&act=addnew" title=""><span class="icos-add"></span>Add New</a></li>
            </ul>
			<div id="dyn" class="hiddenpars">
                <a class="tOptions" title="Options"><img src="images/icons/options" alt="" /></a>
<?php
				$tablebanner = new PoTable('banner');
				$banners = $tablebanner->findAll(id_banner, DESC);
				echo "<table cellpadding='0' cellspacing='0' border='0' class='dTable' id='dynamic'>
						<thead><tr>
							<th>No</th>
							<th>Title</th>
							<th>Url</th>
							<th>Preview</th>
							<th>Date</th>
							<th>Size</th>
							<th>Action</th>
						</tr></thead><tbody>";
						$no=1;
						foreach($banners as $banner){
						$urlcar = addhttp($banner->url);
						echo "<tr class='gradeA' id='del$banner->id_banner'>
							<td>$no</td>
							<td>$banner->title</td>
							<td><a href='$urlcar' target='_blank'>$urlcar</a></td>
							<td><div id='gallery'><i class='icon-picture'></i> <a class='lightbox' rel='group' href='../po-content/po-upload/banner/$banner->picture'>Image</a></div></td>
							<td>$banner->date</td>
							<td>$banner->size</td>
							<td class='tableActs' align='center' style='width:50px'>
								<span id='$banner->id_banner' class='tbledit'><a href='#editdata$banner->id_banner' class='tablectrl_small bDefault tipS' title='$langaction1'><span class='iconb' data-icon='&#xe1db;'></span></a></span>
								<span id='$banner->id_banner' class='alertdel'><a href='#delete$banner->id_banner' class='tablectrl_small bDefault tipS' title='$langaction2'><span class='iconb' data-icon='&#xe136;'></span></a></span>
							</td>
						</tr>";
						?>
                        <div id="editdata<?php echo $banner->id_banner; ?>" class="editdata" title="Edit Video">
                            <form id="formedit" method="post" action="<?php echo $aksi; ?>" autocomplete="off">
								<input type="hidden" name="mod" value="banner">
								<input type="hidden" name="act" value="update">
								<input type="hidden" name="id" value='<?php echo $banner->id_banner; ?>'>
								<label>Title</label><input class="required" type="text" id="title" name="title" value="<?php echo $banner->title; ?>" style="width:97%;" required>
								<div class="divider"><span></span></div>
								<label>Url</label><input class="required" type="text" id="url" name="url" value="<?php echo $banner->url; ?>" style="width:97%;" required>
								<div class="divider"><span></span></div>
								<span class="floatR" style="margin-top:5px; margin-bottom:5px;"><input class="buttonM bBlue" type="submit" value="Submit"></span>
                            </form>
                        </div>
						<?php
						$no++;
						}
					echo "</tbody></table>";
?>
			</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='banner'>
					<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="grid3"><label>Url</label></div>
						<div class="grid9"><input class="required" type="text" id="url" name="url" required></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<div class="grid3"><label>Size</label></div>
						<div class="grid9 noSearch">
							<select data-placeholder="Choose a Size" class="select" name="size" style="width:280px;">
								<option value="180" selected>180</option>
								<option value="480">480</option>
							</select>
						</div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<div class="grid3"><label>Image</label></div>
						<div class="grid9">
							<input style="opacity: 0;" size="24" class="fileInput" id="fileInput" name="fupload" type="file" required>
							<p><i>Please upload image type must be jpg</i></p>
						</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;
}
?>
	</div>
<?php
}
?>