<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 = '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();});
				}
				});
				$( 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>
<?php
session_start();
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
	header('location:404.php');
}else{
$aksi="po-component/po-component/proses.php";
?>
	<div class="contentTop">
        <span class="pageTitle"><span class="icon-box"></span><?php echo $langcomponent1; ?></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 $langcomponent2; ?></a></li>
            </ul>
        </div>
    </div>
    <!-- Main content -->
    <div class="wrapper">
<?php
switch($_GET[act]){
  default:
?>
	<div class="widget">
		<div class="whead"><h6><?php echo $langcomponent1; ?></h6><div class="clear"></div></div>
			<div id="dyn" class="hiddenpars">
                <a class="tOptions" title="Options"><img src="images/icons/options" alt="" /></a>
<?php
				$tablecomponent = new PoTable('component');
				$components = $tablecomponent->findAll(id_component, DESC);
				echo "<table cellpadding='0' cellspacing='0' border='0' class='dTable' id='dynamic'>
						<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 class='tableActs' align='center'>";
									if ($_SESSION[leveluser]=='admin'){
										echo "<a href='admin.php?mod=$url' class='tablectrl_small bDefault tipS' title='$langaction3'><span class='iconb' data-icon='&#xe1db;'></span></a>
										<a href='?mod=component&act=importtable&id=$component->id_component' class='tablectrl_small bDefault tipS' title='$langaction4'><span class='iconb' data-icon='&#xe1f7;'></span></a>
										<span id='$component->id_component' class='alertdel'><a href='#delete$component->id_component' class='tablectrl_small bDefault tipS' title='$langaction2'><span class='iconb' data-icon='&#xe136;'></span></a></span>";
									}else{
										echo "<a href='admin.php?mod=$url' class='tablectrl_small bDefault tipS' title='$langaction3'><span class='iconb' data-icon='&#xe1db;'></span></a>";
									}
								echo "</td>
						</tr>";
						$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":
	if ($_SESSION[leveluser]=='admin'){
?>
		<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="component">
					<input type="hidden" name="act" value="input">
					<div class="formRow">
						<div class="grid3"><label>Component Name</label></div>
						<div class="grid9"><input class="required" type="text" id="component" name="component" required></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<div class="grid3"><label>Table Name</label></div>
						<div class="grid9"><input class="required" type="text" id="table_name" name="table_name" required></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<div class="grid3"><label>Please select component <i>(.zip)</i></label></div>
						<div class="grid9"><input style="opacity: 0;" size="24" class="fileInput" id="fileInput" name="fupload" type="file" required></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>
		<div class="widget">
			<div class="whead"><h6><span class="icon-warning"></span><?php echo $langcomponent15; ?></h6><div class="clear"></div></div>
				<div class="body">
					<ul class="liTip">
						<li><?php echo $langcomponent7; ?><br /><i><?php echo $langcomponent8; ?></i></li>
						<li><?php echo $langcomponent9; ?></li>
						<li><?php echo $langcomponent10; ?></li>
						<li><?php echo $langcomponent11; ?></li>
					</ul>
				</div>
        </div>
<?php
	}else{
?>
    <div class="wrapper" id="errorWrapperadmin">
		<span class="errorNum">404</span>
		<div class="errorContent">
			<span class="errorDesc"><span class="icon-warning"></span>Ooops! Error Somethings Wrong</span>
			<div class="fluid">
				<?php
					$url = rtrim("http://".$_SERVER['HTTP_HOST'], "/").$_SERVER['PHP_SELF'];
					$url2 = preg_replace("/\/po-admin\/(admin\.php$)/","",$url);
					$siteurl = $url2;
				?>
				<a title="Back to Previous page" class="buttonM bLightBlue grid6" onClick="history.back();">Back to previous page</a>
				<a href="<?php echo $siteurl; ?>" title="Back to the website" class="buttonM bRed grid6">Back to the website</a>
			</div>
		</div>
	</div>
<?php
	}
    break;

	case "importtable":
	if ($_SESSION[leveluser]=='admin'){
?>
		<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>Import Table</h6><div class="clear"></div></div>
					<input type="hidden" name="mod" value="component">
					<input type="hidden" name="act" value="importtable">
					<div class="formRow">
						<div class="grid3"><label>Please select sql file <i>(.sql)</i></label></div>
						<div class="grid9"><input style="opacity: 0;" size="24" class="fileInput" id="fileInput" name="fupload" type="file" required></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>
		<div class="widget">
			<div class="whead"><h6><span class="icon-warning"></span><?php echo $langcomponent15; ?></h6><div class="clear"></div></div>
				<div class="body">
					<ul class="liTip">
						<li><?php echo $langcomponent12; ?></li>
						<li><?php echo $langcomponent13; ?></li>
						<li><?php echo $langcomponent14; ?></li>
					</ul>
				</div>
        </div>
<?php
	}else{
?>
    <div class="wrapper" id="errorWrapperadmin">
		<span class="errorNum">404</span>
		<div class="errorContent">
			<span class="errorDesc"><span class="icon-warning"></span>Ooops! Error Somethings Wrong</span>
			<div class="fluid">
				<?php
					$url = rtrim("http://".$_SERVER['HTTP_HOST'], "/").$_SERVER['PHP_SELF'];
					$url2 = preg_replace("/\/po-admin\/(admin\.php$)/","",$url);
					$siteurl = $url2;
				?>
				<a title="Back to Previous page" class="buttonM bLightBlue grid6" onClick="history.back();">Back to previous page</a>
				<a href="<?php echo $siteurl; ?>" title="Back to the website" class="buttonM bRed grid6">Back to the website</a>
			</div>
		</div>
	</div>
<?php
	}
    break;  
}
?>
	</div>
<?php
}
?>