<?php
include_once "library/inc.sesadmin.php";
include_once "library/inc.library.php";

# UNTUK PAGING (PEMBAGIAN HALAMAN)
$row = 20;
$hal = isset($_GET['hal']) ? $_GET['hal'] : 0;
$pageSql = "SELECT * FROM siswa";
$pageQry = mysql_query($pageSql, $koneksidb) or die ("error paging: ".mysql_error());
$jml	 = mysql_num_rows($pageQry);
$max	 = ceil($jml/$row);
?>
<table width="100%" border="0" cellpadding="2" cellspacing="1" class="table-border">
  <tr>
    <td colspan="2" align="center"><h1><b>DATA SISWA </b></h1></td>
  </tr>
  <tr>
    <td colspan="2"><a href="?page=Tambah-Siswa" target="_self"><img src="images/btn_add_data2.png" height="25" border="0" /></a></td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">
	<table class="table-list" width="100%"  border="1" cellspacing="1" cellpadding="2">
      <tr>
        <th width="30" align="center"bgcolor="#CCCCCC"><b>No</b></th>
        <th width="80"bgcolor="#CCCCCC"><b>NIS</b></th>
        <th width="200"bgcolor="#CCCCCC"><b>NAMA SISWA </b></th>
        <th width="100"bgcolor="#CCCCCC"><b>TEMPAT LAHIR</b></th>
		<th width="100"bgcolor="#CCCCCC"><b>TANGGAL LAHIR</b></th>
		<th width="400"bgcolor="#CCCCCC"><b>ALAMAT</b></th>
		<th width="200"bgcolor="#CCCCCC"><b>KELAS</b></th>
		<th width="80"bgcolor="#CCCCCC"><b>TAHUN PELAJARAN</b></th>
        <td width="50" align="center" bgcolor="#CCCCCC"><b>Edit</b></td>
        <td width="50" align="center" bgcolor="#CCCCCC"><b>Delete</b></td>
      </tr>
      <?php
	$userSql = "SELECT  siswa.nis, siswa.nama_siswa, siswa.tempat_lahir, siswa.tanggal_lahir, siswa.alamat, kelas.namakelas, kelas.tp 
	FROM siswa, kelas, kelas_siswa WHERE siswa.nis=kelas_siswa.nis AND kelas.kdkelas=kelas_siswa.kdkelas ORDER BY nis ASC ";
	$userQry = mysql_query($userSql, $koneksidb)  or die ("Query user salah : ".mysql_error());
	$nomor  = 0; 
	while ($userRow = mysql_fetch_array($userQry)) {
	$nomor++;
	$Kode = $userRow['nis'];
	?>
      <tr>
        <td align="center"><b><?php echo $nomor; ?></b></td>
        <td><?php echo $userRow['nis']; ?></td>
        <td><?php echo $userRow['nama_siswa']; ?></td>
        <td><?php echo $userRow['tempat_lahir']; ?></td>
		<td><?php echo $userRow['tanggal_lahir']; ?></td>
		<td><?php echo $userRow['alamat']; ?></td>
		<td><?php echo $userRow['namakelas']; ?></td>
		<td><?php echo $userRow['tp']; ?></td>
        <td align="center"><a href="?page=Edit-Siswa&amp;Kode=<?php echo $Kode; ?>" target="_self" alt="Edit Data"><img src="images/btn_edit.png" width="20" height="20" border="0" /></a></td>
        <td align="center"><a href="?page=Delete-Siswa&amp;Kode=<?php echo $Kode; ?>" target="_self" alt="Delete Data" onclick="return confirm('ANDA YAKIN INGIN MENGHAPUS DATA PENTING INI ... ?')"><img src="images/btn_delete.png" width="20" height="20"  border="0"  alt="Delete Data" /></a></td>
      </tr>
      <?php } ?>
    </table></td>
  </tr>
  <tr>
    <td><b>Jumlah Data :</b> <?php echo $jml; ?> </td>
    <td align="right"><b>Halaman ke :</b>      
	<?php
	for ($h = 1; $h <= $max; $h++) {
		$list[$h] = $row * $h - $row;
		echo " <a href='?page=Data-Siswa&hal=$list[$h]'>$h</a> ";
	}
	?>
	</td>
  </tr>
</table>
