
<?php
	require_once("config/koneksi.php");
?>
<script>
function confirmdelete(delUrl) {
   if (confirm("Anda yakin ingin menghapus?")) {
      document.location = delUrl;
   }
}
</script>

<link type="text/css" rel="stylesheet" href="development-bundle/themes/ui-lightness/ui.all.css" />
    
    <script src="development-bundle/jquery-1.8.0.min.js"></script>
    <script src="development-bundle/ui/ui.core.js"></script>
    <script src="development-bundle/ui/ui.datepicker.js"></script>
    <script src="development-bundle/ui/i18n/ui.datepicker-id.js"></script>
    <script type="text/javascript">
            $(document).ready(function(){
                $("#tgllahir").datepicker({
                    dateFormat : "mm/dd/yy",
                    changeMonth : true,
                    changeYear : true
                });
            });
        </script>
    
<style type="text/css">
input.error, textarea.error { border: 1px solid red;}
label.error {color:red;font-size:9px; padding-left:3px;}
</style>
<?php 
switch(@$_GET['act']){
  // Tampil Data
  default:
	?>
  	<h2>Data Periode</h2>
    <input type="button" name="button"  value="Tambah Data Periode" class="button" onclick="javascript:window.location='media.php?module=periode&act=forminput'"></center>
<table class="data">
<tr class="data">
	<th class="data" width="40">ID</th>
	<th class="data" width="200">Peride</th>
    <th class="data" width="30">status</th>
    <th width="80" class="data">Aksi</th>
</tr>
<?php
	if(!isset($_GET['hal'])){
		@$page = 1;
		@$hal = 1;
	} else {
		@$page = $_GET['hal'];
	}
	$jmlperhalaman = 10;  // jumlah record per halaman
	$offset = (($page * $jmlperhalaman) - $jmlperhalaman);
	
	$tampil=mysql_query("SELECT * FROM tb_periode ORDER BY periode desc LIMIT $offset, $jmlperhalaman");
    
	$no = 1;
    while ($r=mysql_fetch_array($tampil)){
    $lebar=strlen($no);
    switch($lebar){
      case 1:{
        $g="0".$no;
        break;     
      }
      case 2:{
        $g=$no;
        break;     
      }      
    } 
    
   echo "<tr class='data'>
   <td class='data'><center>$no</center></td>
    <td class='data'><center>$r[periode]</center></td>
    <td><center>";
	if($r['status']=='N'){
		echo "<a href=media.php?module=periode&act=ubahY&id=$r[id_periode] onclick=\"return confirm('Anda akan mengstatuskan Periode ini?')\" title='Tidak Aktif' class='with-tip'><center><img src='images/t.png'></center></a>";	
	}elseif($r['status']=='Y'){
		echo "<center><img src='images/y.png' title='Aktif'></center>";
	}else{
		echo "NaN";
		}
	echo "</center></td>
	<td class='data'>
   
   <a href=media.php?module=periode&act=tampil&id=$r[id_periode] title='Tampil' class='with-tip'>
   <center><img src='images/view.png'></a>
   
   <a href=media.php?module=periode&act=edit&id=$r[id_periode] title='Edit' class='with-tip'>
   <img src='images/edit.gif'></a>
   
   <a href=javascript:confirmdelete('media.php?module=periode&act=hapus&id=$r[id_periode]') 
   title='Hapus' class='with-tip'>
   <img src='images/cancel.gif'></center></a> 
	   
   </td></tr>";		
      $no++;
    }
?>
</table>
<br />
<?php
// membuat nomor halaman
	$total_record = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM tb_periode"),0);
	$total_halaman = ceil($total_record / $jmlperhalaman);
	echo "<center>Halaman :<br/>";
	$perhal=4;
	if(@$hal > 1){
		$prev = ($page - 1);
		echo "<a href=media.php?module=periode&hal=$prev> << </a> ";
	}
	if($total_halaman<=10){
	$hal1=1;
	$hal2=$total_halaman;
	}else{
	$hal1=$hal-$perhal;
	$hal2=$hal+$perhal;
	}
	if(@$hal<=5){
	$hal1=1;
	}
	if(@$hal<$total_halaman){
	$hal2=@$hal+$perhal;
	}else{
	$hal2=@$hal;
	}
	for($i = $hal1; $i <= $hal2; $i++){
		if((@$hal) == $i){
			echo "[<b>$i</b>] ";
			} else {
		if($i<=$total_halaman){
				echo "<a href=media.php?module=periode&hal=$i>$i</a> ";
		}
		}
	}
	if(@$hal < $total_halaman){
		$next = ($page + 1);
		echo "<a href=media.php?module=periode&hal=$next>>></a>";
	}
	echo "</center><br/>";
?>
</p>
  <?php
  break;
  case "ubahY":
  		mysql_query("UPDATE tb_periode SET status = 'N'");
				
		mysql_query("UPDATE tb_periode SET status = 'Y'
				WHERE id_periode = '$_GET[id]'");
			
		echo "<script>document.location='media.php?module=periode'</script>";
	break;
	
  case "forminput":
  ?>
  	<h2>Input Data Periode</h2>
    <p>
<form action="media.php?module=periode&act=simpandata" method="post" id="periode" name="periode" enctype="multipart/form-data">
<table class="data">
<tr class="data">
	<td colspan="3" align="center" class="data"><hr /></td>
 </tr>
 <tr class="data">
	<td class="data" width="200">Periode</td>
    <td class="data" width="5">:</td>
	<td class="data"><input type="text" name="periode" class="sedang"/></td>
 </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data"><hr /></td>
 </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data">
    <input type="button" name="button"  value="<< Kembali" class="button" onclick="history.go(-1)"/>
    <input type="submit" name="button"  value="Simpan" class="button" /> </td>
 </tr>
 </table>
 </form>
 </p>
 <?php
  break;
  
  case "tampil":
  	$edit = mysql_query("SELECT * FROM tb_periode WHERE id_periode='$_GET[id]'");
    $r    = mysql_fetch_array($edit);
  ?>
  <h2>Detail Data Periode</h2>
    <p>
<form action="" method="post" id="periode" name="periode" enctype="multipart/form-data">
<table class="data">
<tr>
	<td colspan="3" class="data"><hr /></td>
 </tr>
<tr class="data">
	<td width="150"class="data">ID Periode</td>
    <td width="5" class="data">:</td>
	<td class="data"><?php echo $r['id_periode'];?></td>
 </tr>
 <tr class="data">
	<td class="data">Periode</td>
    <td class="data">:</td>
	<td class="data"><?php echo $r['periode'];?></td>
 </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data"><hr /></td>
 </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data">
    <input type="button" name="button"  value="<< Kembali" class="button" onclick="history.go(-1)"/></td>
 </tr>
 </table>
 </form>
 </p>
 <?php
  break;
  
  case "edit":
  	$edit = mysql_query("SELECT * FROM tb_periode WHERE id_periode='$_GET[id]'");
    $r    = mysql_fetch_array($edit);
  ?>
  <h2>Edit Data Periode</h2>
    <p>
<form action="media.php?module=periode&act=update" method="post" id="periode" name="periode" enctype="multipart/form-data">
<table class="data">
<tr class="data">
	<td colspan="3" align="center" class="data"><hr /></td>
 </tr>
 <tr class="data">
	<td class="data" width="200">ID Periode</td>
    <td class="data" width="5">:</td>
	<td class="data"><input type="text" name="id_periode" class="pendek"
    value="<?php echo $r['id_periode'];?>" readonly /></td>
 </tr>
 <tr class="data">
	<td class="data" width="200">Periode</td>
    <td class="data" width="5">:</td>
	<td class="data"><input type="text" name="periode" class="sedang" value="<?php echo $r['periode'];?>"/></td>
 </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data"><hr /></td>
 </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data">
    <input type="button" name="button"  value="<< Kembali" class="button" onclick="history.go(-1)"/>
    <input type="submit" name="button"  value="Ubah" class="button" /> </td>
 </tr>
 </table>
 </form>
 </p>
 <?php
  break;
  
  case "simpandata":
	$query=mysql_query("insert into tb_periode(
							periode) 
						values(
							'$_POST[periode]')");
	
	 if($query){
			?><script language="javascript">alert("Data sudah tersimpan")</script><?php
			?><script language="javascript">document.location.href="media.php?module=periode"</script><?php
		}else{
			echo mysql_error();
		}
		
  break;
  
  case "update":
  	
  	$query=mysql_query("UPDATE tb_periode SET 
									periode 	= '$_POST[periode]'
			WHERE id_periode = '$_POST[id_periode]'");	
	
	if($query){
			?><script language="javascript">alert("Data sudah diubah !")</script><?php
			?><script language="javascript">document.location.href="media.php?module=periode"</script><?php
		}else{
			echo mysql_error();
		}
  break;
  
  case "hapus":
  	$query=mysql_query("DELETE FROM tb_periode WHERE id_periode='$_GET[id]'");
		if($query){
			?><script language="javascript">alert("Data sudah dihapus !")</script><?php
			?><script language="javascript">document.location.href="media.php?module=periode"</script><?php
		}else{
			echo mysql_error();
		}
  break;
}
  	?>