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

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

<script language="javascript">
$(document).ready( function() {
	$("#btnalertdel").click(function(){
		var id = $('#delid').val();
		var mod = 'component';
		var act =  'delete';
		var dataString = 'id='+ id + '&mod='+ mod + '&act='+ act;
		$.ajax({
			type: "POST",
			url: "po-component/po-component/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-component/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-box'></span>
		</div>
		<h1>$langcomponent1<small><span class='text-info'>$langcomponent2</span></small></h1>
	</div>
	<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>";
				$tablecomponent = new PoTable('component');
				$components = $tablecomponent->findAll(id_component, DESC);
				echo "<div class='data-fluid'>
					<table cellspacing='0' border='0' class='table table-hover' id='tableboot'>
						<thead><tr>
							<th>No</th>
							<th>$langcomponent3</th>
							<th>$langcomponent4</th>
							<th>$langcomponent5</th>
							<th>$langcomponent6</th>
						</tr></thead><tbody>"; 
						$no=1;
						foreach($components as $component){
						$pecahurl = explode("-", $component->component);
						$url = $pecahurl[1];
							echo "<tr class='gradeA' id='del$component->id_component'>
								<td>$no</td>
								<td style='width:40%;'>$component->component</td>
								<td>$component->date</td>
								<td>$component->table_name</td>
								<td>";
									if ($_SESSION[leveluser]=='admin'){
										echo "<a href='admin.php?mod=$url'><span class='label label-warning'><i class='icon-arrow-right icon-white'></i> $langaction3</span></a>
										<a href='?mod=component&act=importtable&id=$component->id_component'><span class='label label-info'><i class='icon-upload icon-white'></i> $langaction4</span></a>
										<a href='#delete$component->id_component' class='alertdel' id='$component->id_component'><span class='label label-important'><i class='icon-remove icon-white'></i>$langaction2</span></a>";
									}else{
										echo "<a href='admin.php?mod=$url'><span class='label label-warning'><i class='icon-arrow-right icon-white'></i> $langaction3</span></a>";
									}
								echo "</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":
	if ($_SESSION[leveluser]=='admin'){
	echo "<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>
				<legend><i class='ico-box'></i> Add New</legend>
				<form method='post' action='$aksi' enctype='multipart/form-data' autocomplete='off'>
					<input type='hidden' name='mod' value='component'>
					<input type='hidden' name='act' value='input'>
					<fieldset>
						<label>Component Name</label><input class='input-xxlarge' type='text' id='component' name='component' required>
						<label>Table Name</label><input class='input-xxlarge' type='text' id='table_name' name='table_name' required>
						<label>Please select component <i>(.zip)</i></label>
						<div class='row-form' style='margin-left:-15px;'>
						<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><br />
				<div class='page-error'>
					<div class='alert alert-error'>
						<strong>Warning!</strong> Best check yourself, you're not looking too good.
					</div>
				</div>
				<p>&nbsp;</p>
				<h4>$langcomponent15</h4>
				<blockquote>
					<p>1. $langcomponent7</p>
					<small>$langcomponent8</small>
				</blockquote>
				<blockquote>
					<p>2. $langcomponent9</p>
				</blockquote>
				<blockquote>
					<p>3. $langcomponent10</p>
				</blockquote>
				<blockquote>
					<p>4. $langcomponent11</p>
				</blockquote>
			</div>
		</div>
	</div>
	<div style='width:100%; height:500px;'>&nbsp;</div>";
	}else{
		echo "<div class='page-header'></div>
		<div class='row-fluid'>
			<div class='span12'>
				<div class='errorContainerpage'>
					<h1>404</h1>
					<h2>$langcomponent1</h2>
					<button class='btn btn-large btn-primary' onClick='document.location.href=\"admin.php?mod=home\";'>$langpagenotfound2</button> <button class='btn btn-large' onClick='history.back();'>$langpagenotfound3</button>
				</div>
			</div>
		</div>";
	}
	break;

	case "importtable":
	if ($_SESSION[leveluser]=='admin'){
	echo "<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>
				<legend><i class='ico-box'></i> Import Table</legend>
				<form method='post' action='$aksi' enctype='multipart/form-data' autocomplete='off'>
					<input type='hidden' name='mod' value='component'>
					<input type='hidden' name='act' value='importtable'>
					<fieldset>
						<label>Please select sql file <i>(.sql)</i></label>
						<div class='row-form' style='margin-left:-15px;'>
						<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><br />
				<p>&nbsp;</p>
				<h4>$langcomponent15</h4>
				<blockquote>
					<p>1. $langcomponent12</p>
				</blockquote>
				<blockquote>
					<p>2. $langcomponent13</p>
				</blockquote>
				<blockquote>
					<p>3. $langcomponent14</p>
				</blockquote>
			</div>
		</div>
	</div>
	<div style='width:100%; height:500px;'>&nbsp;</div>";
	}else{
		echo "<div class='page-header'></div>
		<div class='row-fluid'>
			<div class='span12'>
				<div class='errorContainerpage'>
					<h1>404</h1>
					<h2>$langcomponent1</h2>
					<button class='btn btn-large btn-primary' onClick='document.location.href=\"admin.php?mod=home\";'>$langpagenotfound2</button> <button class='btn btn-large' onClick='history.back();'>$langpagenotfound3</button>
				</div>
			</div>
		</div>";
	}
	break;
}
}
?>