<?php
include "koneksi.php";
include "fungsi_indotgl.php";
include "library.php";
$time_start = microtime(true); // waktu awal execusi program
if (isset($simpan)) //jika klik tombol simpan
{
$tgl_lahir="$thn-$bln-$tgl";
if ($gen=="L") $gen = "L"; else $gen = "P";
if (empty($nim))
{
print "Nim Tidak Boleh Kosong";
}
else
{
$sql="select * from tbmhs where nim = '$nim'";
$cekdata=mysql_query($sql);
$jlh=mysql_num_rows($cekdata);
if ($jlh <1)
{
$sql2="insert into tbmhs(NIM,NAMA,TMP_LAHIR,TGL_LAHIR,GENDER,TELP)
values('$nim','$nama','$ttl','$tgl_lahir','$gen','$tlp')";
$simpan=mysql_query($sql2) or die ("Kesalahan Proses Query pada $sql2");
}
else
{
echo"Data sudah ada";
}
}
header ("location:mhs.php");//refresh page
}
elseif ($_REQUEST=='edit')
{ //edit file
$dtmhs=all_data("tbmhs","nim=$kode");
$nim=$dtmhs[0];
$nama=$dtmhs[1];
$ttl=$dtmhs[2];
$tgllahir=$dtmhs[3];
$pecah=explode("-",$tgllahir); $thn=$pecah[0]; $bln=$pecah[1]; $tgl=$pecah[2];
$gen=$dtmhs[4];
$tlp=$dtmhs[5];
}
elseif (isset($nim)) //jika ditekan enter pada field nim
{ //searching
$dtmhs=all_data("tbmhs","nim=$nim");
$nim=$dtmhs[0];
$nama=$dtmhs[1];
$ttl=$dtmhs[2];
$tgllahir=$dtmhs[3];
$pecah=explode("-",$tgllahir); $thn=$pecah[0]; $bln=$pecah[1]; $tgl=$pecah[2];
$gen=$dtmhs[4];
$tlp=$dtmhs[5];
}
else if ($_REQUEST=='hapus') { //hapus file
$hps=mysql_query("Delete from tbmhs where nim='$kode'");
header ("location:mhs.php");//refresh page
}
// bagian script untuk menghapus data
//if ($_GET == "del")
elseif (isset($_POST)) //proses hapus data
{
// membaca nilai n dari hidden value
$n = $_POST;
for ($i=0; $i<=$n-1; $i++)
{
if (isset($_POST))
{
$kode = $_POST;
$query = "DELETE FROM tbmhs WHERE nim = '$kode'";
mysql_query($query);
}
}
header ("location:mhs.php");//refresh page
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" media="screen" href="style.css" />
<script src="cekAll.js"></script>
</head>
<body>
<?php
echo"<p align=left>Hari ini : $hari_ini, ";
echo tgl_indo(date("Y m d"));
echo " | ";
echo date("H:i:s");
echo " WIB</p>";
?>
<form action="" method="post" name="form1">
<table width="510" border="0" bgcolor="#FAFAFA">
<tr>
<td class="td" colspan="3" align="center"><label>Entry Data Mahasiswa</label></td>
</tr>
<tr>
<td class="td" width="150"><label>NIM</label></td>
<td><input name="nim" type="text" id="nim" onchange="this.form.submit()" value="<?php if (isset($_POST)) echo $_POST; else echo $nim ?>" /></td>
<td width="274"> </td>
</tr>
<tr>
<td class="td"><label>NAMA</label></td>
<td colspan="2"><input type="text" name="nama" id="nama" value="<?PHP echo $nama; ?>" /></td>
</tr>
<tr>
<td class="td"><label>TEMPAT TGL LAHIR</label></td>
<td><input type="text" name="ttl" id="ttl" value="<?php echo $ttl; ?>" /></td>
<td><?php
echo "<select name=tgl>"; //begin:combo tanggal
if (($_REQUEST=='edit') || (isset($nim))) //jika ststus edit
{
for ($i=1; $i<=31; $i++) // tampilkan tanggal sampai 31
{
if ($tgl==$i)
echo "<option value='$i' selected>$tgl</option>";
else
echo "<option value=$i>$i</option>";
}
}
else
{
//for ($i=1; $i<=$tanggal; $i++) // tampilkan tanggal hanya sampai tanggal sekarang
for ($i=1; $i<=31; $i++) // tampilkan tanggal sampai 31
{
if ($tgl_skrg==$i)
echo "<option value=$i selected>$tgl_skrg</option>";
else
echo "<option value=$i>$i</option>";
}
}
echo "</select>"; //end:tanggal
echo " <select name=bln>"; //begin: combo bulan
if (($_REQUEST=='edit')|| (isset($nim)))
{
for ($i=1; $i<=12; $i++) //tampilkan tanggal sampai 12
{
if ($bln==$i) {
$j=substr($bln, 1); //Menghasilkan bagian dari string
echo "<option value=$i selected>$nama_bln[$j]</option>"; }
else
echo "<option value=$i>$nama_bln[$i]</option>";
}
}
else
{
//for ($i=1; $i<=$bulan; $i++) //tampilkan bulan hanya sampai bulan sekarang
for ($i=1; $i<=12; $i++) //tampilkan tanggal sampai 12
{
if ($bln_sekarang==$i)
echo "<option value=$i selected>$nama_bln[$i]</option>";
else
echo "<option value=$i>$nama_bln[$i]</option>";
}
}
echo "</select>"; //end:combo bulan
echo " <select name=thn>"; //begin combo tahun
if (($_REQUEST=='edit')|| (isset($nim)))
{
for ($i=1970;$i<=2020;$i++) //tampilkan tahun sampai 2020
{
if ($thn==$i) {
echo "<option value=$i selected>$thn</option>"; }
else
echo "<option value=$i>$i</option>";
}
}
else
{
//for ($i=$tahun-5;$i<=$tahun;$i++) //tampilkan tahun hanya dari 6 tahun lalu sampai sekarang
for ($i=1970;$i<=2020;$i++) //tampilkan tahun sampai 2020
{
if ($thn_sekarang==$i)
echo "<option value=$i selected>$thn_sekarang</option>";
else
echo "<option value=$i>$i</option>";
}
}
echo "</select>"; //end:combo tahun
?></td>
</tr>
<tr>
<td class="td"><label>GENDER</label></td>
<td colspan="2">
<input type="radio" name="gen" id="gen" value="L" checked="checked" /> Laki-laki
<input type="radio" name="gen" id="gen" value="P" /> Perempuan</td>
</tr>
<tr>
<td class="td"><label>TLP/HP</label></td>
<td><input type="text" name="tlp" id="tlp" value="<?php echo $tlp; ?>" /></td>
<td> </td>
<tr>
<td> </td>
<td><input type="submit" name="simpan" id="simpan" value="Simpan" /></td>
<td> </td>
</tr>
</table>
</form>
<p></p>
<?php
$sql3="select * from tbmhs";
$hasil=mysql_query($sql3);
$total=mysql_num_rows($hasil);
echo"<h3>Daftar Mahasiswa</h3>";
echo "<form name='myform' method='post' action=''>
<table width='800' border='0' cellspacing='2' cellpadding='2' bgcolor='#FFFFFF'>
<tr bgcolor='#FAFAFA'>
<td align=center background=images/tab_bg.png><input type='checkbox' name='pilih' onclick='pilihan()' /></td>
<td class=td align=center><label>#</label></td>
<td class=td><label>NIM</label></td>
<td class=td><label>NAMA</label></td>
<td class=td><label>TEMPAT, TANGGAL LAHIR</label></td>
<td class=td align=center><label>GENDER</label></td>
<td class=td><label>TLP/HP</label></td>
<td class=td align=center width=130><label>Aksi</label></td>
</tr>";
if ($total <=0)
{
echo"<tr><td class=td colspan=8><label class=warning>Daftar Kosong</label></td></tr>";
}
else
{
$no=0;
$i=0;
while ($data=mysql_fetch_array($hasil))
{
$no++;
$atur = $no%2;
if ($atur <> 0)
{
$warna = '#FFFFFF';
}
else
{
$warna = '#FAFAFA';
}
echo"<tr bgcolor=$warna>
<td align=center><input type='checkbox' name='nim".$i."' value='".$data[0]."' /></td>
<td>$no</td>
<td>$data[0]</td>
<td>$data[1]</td>";
//begin: fungsi explode memecahkan string tanggal lahir
$pecah1=explode("-",$data[3]);
$tgl1=$pecah1[2];
$bln1=$pecah1[1];
$thn1=$pecah1[0];
//end: fungsi explode memecahkan string tanggal lahir
$k=substr($bln1, 1); //Menghasilkan bagian dari string
echo"<td>$data[2], $tgl1 $nama_bln[$k] $thn1</td>";
$jk=$data[4];
if ($jk=="L") $jk="Laki-laki"; else $jk="Perempuan";
echo"<td>$jk</td>
<td>$data[5]</td>
<td align=center>
<a href='?status=hapus&kode=$data[0]' title='hapus' onclick=\"return confirm('Apakah Anda Benar-benar akan menghapus $data[0]?')\"><img src='images/b_deltbl.png'>Hapus</a> |
<a href='?status=edit&kode=$data[0]' title='Edit')\"><img src='images/b_edit.png'>Edit</a></td>
</tr>";
$i++;
}
echo"<tr>
<td class=button colspan=6>
<input type='hidden' name='n' value='".$i."' />
<img src='images/arrow_ltr.png'>
<input type='submit' value='Hapus' name='hapus' class='button' onclick=\"return confirm('Apakah Anda Benar-benar akan menghapus?')\">
<input type='reset' value='Batal' name='reset' class='button'>
</td>
<td colspan=2 class=td align=right><label>Ditemukan $total Record</label></td>
</tr>";
}
echo"</table>
<p></p>";
$time_end = microtime(true); // waktu akhir proses
$time = $time_end - $time_start;
$waktu = number_format($time, 4, ',', '.');
echo $format_number;
echo "Waktu proses $waktu Detik\n ";
echo"</form>";
?>
</body>
</html>