<script language="javascript">
$(document).ready( function() {
	$("#btnalertdel").click(function(){
		var id = $('#delid').val();
		var mod = 'library';
		var act =  'delete';
		var dataString = 'id='+ id + '&mod='+ mod + '&act='+ act;
		$.ajax({
			type: "POST",
			url: "po-component/po-library/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-library/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-pictures'></span>
		</div>
		<h1>$langlibrary1<small><span class='text-info'>$langlibrary2</span></small></h1>
	</div>
	<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>";
				$tablemedia = new PoTable('media');
				$medias = $tablemedia->findAll(id_media, DESC);
				echo "<div class='data-fluid'>
					<table cellspacing='0' border='0' class='table table-hover' id='tableboot'>
						<thead><tr>
							<th>No</th>
							<th>$langlibrary3</th>
							<th>$langlibrary4</th>
							<th>$langlibrary5</th>
							<th>$langlibrary6</th>
							<th>$langlibrary7</th>
						</tr></thead><tbody>"; 
						$no=1;
						foreach($medias as $media){
							$pecah = explode(".", $media->file_name);
							$fileName = $pecah[0];
							$pecah2 = explode("/", $media->file_type);
							$fileType = $pecah2[0];
							echo "<tr class='gradeA' id='del$media->id_media'>
								<td>$no</td>
								<td>$fileName</td>
								<td>";
									if ($fileType=='image'){
										echo "<div id='gallery'><i class='icon-picture'></i> <a class='fb' rel='group' href='../po-content/po-upload/$media->file_name'>$langlibrary8</a></div>";
									}else{
										echo "<i class='icon-file'></i> $langlibrary9";
									}
								echo "</td>
								<td>$media->file_size Byte</td>
								<td>$media->date</td>
								<td>
								<a href='#delete$media->id_media' class='alertdel' id='$media->id_media'><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='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'>$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-picture'></i> Add New</legend>
				<form method='post' action='$aksi' enctype='multipart/form-data' autocomplete='off'>
					<input type='hidden' name='mod' value='library'>
					<input type='hidden' name='act' value='input'>
					<fieldset>
						<label>Please select file</label>
						<div class='row-form'>
						<div class='span4'>
                            <div class='input-append file'>
                                <input style='width: 284px;' name='fupload' type='file' required>
								<input style='width: 297px;' type='text'>
								<span class='btn'>Browse</span>
							</div>
                        </div>
						</div><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>
			</div>
		</div>
	</div>
	<div style='width:100%; height:500px;'>&nbsp;</div>";
	break;
}
}
?>