<html>
<head>
<title>LAP MHS</title>
</head>
<body>
<?
	include "connect.php";
	session_start();

//cek apakah user sudah login


//cek level user
if($_SESSION['Level']=="baak" || $_SESSION['Level']=="admin" || $_SESSION['Level']=="kmhs"){

	$seleksi = "";

if (isset($_POST['ctingkat']))
{
   $tingkat = $_POST['tingkat'];
   if (empty($seleksi))
   {
		$seleksi .= "tingkat LIKE '$tingkat'";
   }
}

if (isset($_POST['ckelas']))
{
   $kelas = $_POST['kelas'];
   if (empty($seleksi))
   {
		$seleksi .= "kelas LIKE '%$kelas%'";
   }
   else
   {
        $seleksi .= " AND kelas LIKE '%$kelas%'";
   }
}

if (isset($_POST['cstatus']))
{
   $status = $_POST['status'];
   if (empty($seleksi))
   {
		$seleksi .= "status LIKE '$status'";
   }
   else
   {
        $seleksi .= " AND status LIKE '$status'";
   }
}

if (isset($_POST['cangkatan']))
{
   $angkatan = $_POST['angkatan'];
   if (empty($seleksi))
   {
		$seleksi .= "angkatan LIKE '$angkatan'";
   }
   else
   {
        $seleksi .= " AND angkatan LIKE '$angkatan'";
   }
}

?>
<h3><center> UPDATE TINGKAT, KELAS, SEMESTER, STATUS (MHS) </h3>
<form method=post action=cnaik.php>
<table border="1" align="center">
<tr>
<th> No</th>
<th> Nim</th>
<th> Nama</th>
<th> Tingkat</th>
<th> Kelas</th>
<th> Semester</th>
<th> Angkatan</th>
<th> Status</th>
</tr>
<?php
	$hasil=mysqli_query($koneksi,"select * from mhs where $seleksi");
	$total= mysqli_num_rows($hasil);
	
 $no=1;
 if ($total){
		while ($row=mysqli_fetch_array($hasil))
		{
?>
<tr>
<td> <input name="id[<? echo $no; ?>]" type="text" value="<? echo $no; ?>" /></td>
<td><input name="nim[<? echo $no; ?>]" type="text" value="<? echo $row[0]; ?>" /></td>
<td width="300"><a href="viewmhs.php?idv=<? echo $row[0]; ?> " style="text-decoration:none"><? echo $row[1]; ?></td>
<td>
<select name ="tingkat[<? echo $no; ?>]">
	<option selected><? echo $row[2]; ?></option>
	<option>1</option>
	<option>2</option>
    <option>3</option>
	<option>-</option>
  </select>
<td>
<select name ="kelas[<? echo $no; ?>]">
	<option selected><? echo $row[3]; ?></option>
	<option>A</option>
	<option>B</option>
    <option>C</option>
	<option>-</option>
  </select>
<td>
<select name ="semester[<? echo $no; ?>]">
	<option selected><? echo $row[4]; ?></option>
	<option>1</option>
	<option>2</option>
    <option>3</option>
	<option>4</option>
	<option>5</option>
	<option>6</option>
	<option>-</option>
  </select>
<td><? echo $row[14]; ?></td>
<td>
<select name ="status[<? echo $no; ?>]">
	<option selected><? echo $row[15]; ?></option>
	<option>AKTIF</option>
	<option>UNREG</option>
	<option>CUTI</option>
    <option>DO</option>
	<option>ALUMNI</option>
  </select>
<?php
$no++;
}
}
?>
<tr>
<td>
<input type="submit" value="Update" >
<input type="reset" value="Cancel" ></td>
</tr>
</table>
</form>
<?php
} else {
    die("Anda bukan admin");
}
?>
</body>
</html>