
                  
				  
				  <?php if ($_GET[act]==''){ ?>
            <div class="col-xs-12">  
              <div class="box">
                <div class="box-header">
                  <h3 class="box-title"><?php if (isset($_GET[kelas]) AND isset($_GET[tahun])){ echo "Jadwal Pelajaran"; }else{ echo "Jadwal Pelajaran Pada Tahun ".date('Y'); } ?></h3>
         
                  <!-- <a class='pull-right btn btn-primary btn-sm' href='?view=jadwalpelajaran&act=tambah'>Tambahkan Jadwal Pelajaran</a> -->
                
                  <form style='margin-right:5px; margin-top:0px' class='pull-right' action='' method='GET'>
                    <input type="hidden" name='view' value='jadwalpelajaran'>
					<?php
					 $tahun = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM tahun_ajaran where aktif='Y'"));
					 $ta = $tahun['idTahunAjaran'];
					?>
					
					<input type="hidden" class="form-control" name="tahun" value="<?php echo $ta ;?>">
                       
                    
                    <select name='kelas' style='padding:4px'>
                        <?php 
                            echo "<option value=''>- Pilih Kelas -</option>";
                            $kelas = mysqli_query($conn,"SELECT * FROM kelas_siswa");
                            while ($k = mysqli_fetch_array($kelas)){
                              if ($_GET[kelas]==$k[idKelas]){
                                echo "<option value='$k[idKelas]' selected>$k[idKelas] - $k[nmKelas]</option>";
                              }else{
                                echo "<option value='$k[idKelas]'>$k[idKelas] - $k[nmKelas]</option>";
                              }
                            }
                        ?>
                    </select>
                    <input type="submit" style='margin-top:-4px' class='btn btn-success btn-sm' value='Lihat'>
                  </form>

                </div><!-- /.box-header -->
                <div class="table-responsive">
                  <table id="example" class="table table-bordered table-striped">
                    <thead>
                      <tr>
                        <th style='width:20px'>No</th>
						            <th>Semester</th>
                        <th>Jadwal Pelajaran</th>
                        <th>Kelas</th>
                        <th>Guru</th>
                        <th>Hari</th>
					            	<th>Jam Ke</th>
                        <th>Daftar Hadir</th>
                      
                        
                      </tr>
                    </thead>
                    <tbody>
                  <?php
                    if (isset($_GET[kelas]) AND isset($_GET[tahun])){
                      $tampil = mysqli_query($conn,"SELECT a.*, e.nmKelas, b.namamatapelajaran, b.kode_pelajaran, c.nama_guru FROM rb_jadwal_pelajaran a 
                                            JOIN rb_mata_pelajaran b ON a.kode_pelajaran=b.kode_pelajaran
                                              JOIN rb_guru c ON a.nip=c.nip 
                                                  JOIN kelas_siswa e ON a.idKelas =e.idKelas 
                                                  where a.idKelas ='$_GET[kelas]' AND 
                                                    a.idTahunAjaran='$_GET[tahun]'   ORDER BY a.hari DESC");
                    
                    }
                    $no = 1;
                    while($r=mysqli_fetch_array($tampil)){
                    echo "<tr><td>$no</td>
							            	<td>$r[semester]</td>
                              <td>$r[namamatapelajaran]</td>
                              <td>$r[nmKelas]</td>
                              <td>$r[nama_guru]</td>
                              <td>$r[hari]</td>
							                 <td>$r[jam_ke]</td>";
                              if($_SESSION[level]!='kepala'){
                                  echo "<td><a class='btn btn-xs btn-warning' href='?view=absensiswa&act=tampilabsen&id=$r[idKelas]&kd=$r[kode_pelajaran]'>Buka Absensi Siswa</a></td>";
                              }
                              if($_SESSION[level]!='kepala'){
                                echo "";
                              }
                            echo "</tr>";
                      $no++;
                      }

                      if (isset($_GET[hapus])){
                        mysqli_query($conn,"DELETE FROM rb_jadwal_pelajaran where kodejdwl='$_GET[hapus]'");
                        echo "<script>document.location='?view=jadwalpelajaran';</script>";
                      }
                  ?>
                    <tbody>
                  </table>
                </div><!-- /.box-body -->
                <?php 
                    if ($_GET[kelas] == '' AND $_GET[tahun] == ''){
                        echo "<center style='padding:60px; color:red'>Silahkan Memilih Tahun akademik dan Kelas Terlebih dahulu...</center>";
                    }
                ?>
                </div>
            </div>

<?php 
}elseif($_GET[act]=='tambah'){
    if (isset($_POST[tambah])){
        mysqli_query($conn,"INSERT INTO rb_jadwal_pelajaran VALUES('','$_POST[a]','$_POST[b]','$_POST[c]','$_POST[z]','$_POST[e]','$_POST[d]','$_POST[j]','$_POST[k]')");
        echo "<script>document.location='?view=jadwalpelajaran';</script>";
    }

    echo "<div class='col-md-12'>
              <div class='box box-info'>
                <div class='box-header with-border'>
                  <h3 class='box-title'>Tambah Data Jadwal Pelajaran</h3>
                </div>
              <div class='box-body'>
              <form method='POST' class='form-horizontal' action='' enctype='multipart/form-data'>
                <div class='col-md-12'>
                  <table class='table table-condensed table-bordered'>
                  <tbody>
                    <tr><th style='width:120px' scope='row'>Tahun Akademik</th>   <td><select class='form-control' name='a'> 
                                                <option value='0' selected>- Pilih Tahun Akademik -</option>"; 
                                                $tahun = mysqli_query($conn,"SELECT * FROM tahun_ajaran where aktif='Y'");
                                                while($a = mysqli_fetch_array($tahun)){
                                                  echo "<option value='$a[idTahunAjaran]'>$a[nmTahunAjaran]</option>";
                                                }
                                                echo "</select>
                    </td></tr>
                    <tr><th scope='row'>Kelas</th>   <td><select class='form-control' name='b'> 
                                                <option value='0' selected>- Pilih Kelas -</option>"; 
                                                $kelas = mysqli_query($conn,"SELECT * FROM kelas_siswa");
                                                while($a = mysqli_fetch_array($kelas)){
                                                  echo "<option value='$a[idKelas]'>$a[nmKelas]</option>";
                                                }
                                                echo "</select>
                    </td></tr>
                  <tr><th scope='row'>Semester</th>  <td>
									<select class='form-control' name='z'>
										<option value='0'>- Pilih Semester -</option>
										<option value='Semester Ganjil'>Semester Ganjil</option>
										<option value='Semester Genap'>Semester Genap</option>
										
									</select>
								</td></tr>
                    <tr><th scope='row'>Mata Pelajaran</th>   <td><select class='form-control' name='c'> 
                                                <option value='0' selected>- Pilih Mata Pelajaran -</option>"; 
                                                $mapel = mysqli_query($conn,"SELECT * FROM rb_mata_pelajaran");
                                                while($a = mysqli_fetch_array($mapel)){
                                                  echo "<option value='$a[kode_pelajaran]'>$a[namamatapelajaran]</option>";
                                                }
                                                echo "</select>
                    </td></tr>
                    <tr><th scope='row'>Guru</th>   <td><select class='form-control' name='e'> 
                                                <option value='0' selected>- Pilih Guru -</option>"; 
                                                $guru = mysqli_query($conn,"SELECT * FROM rb_guru");
                                                while($a = mysqli_fetch_array($guru)){
                                                  echo "<option value='$a[nip]'>$a[nama_guru]</option>";
                                                }
                                                echo "</select>
                    </td></tr>
                    <tr><th scope='row'>Jam Ke</th>           <td><input type='text' class='form-control' name='d' value='$a[jam_ke]'></td></tr>
                    <tr><th scope='row'>Hari</th>  <td><select class='form-control' name='j'>
                                                <option value='0' selected>- Pilih Hari -</option>
                                                <option value='Senin'>Senin</option>
                                                <option value='Selasa'>Selasa</option>
                                                <option value='Rabu'>Rabu</option>
                                                <option value='Kamis'>Kamis</option>
                                                <option value='Jumat'>Jumat</option>
                                                <option value='Sabtu'>Sabtu</option>
                                                <option value='Minggu'>Minggu</option>
                    </td></tr>
					 
                  
                    <tr><th scope='row'>Aktif</th>                <td><input type='radio' name='k' value='Ya' checked> Ya
                                                                             <input type='radio' name='k' value='Tidak'> Tidak
                    </td></tr>
                  </tbody>
                  </table>
                </div>
              </div>
              <div class='box-footer'>
                    <button type='submit' name='tambah' class='btn btn-info'>Tambahkan</button>
                    <a href='?view=kelas'><button type='button' class='btn btn-default pull-right'>Cancel</button></a>
                    
                  </div>
              </form>
            </div>";
}elseif($_GET[act]=='edit'){
    if (isset($_POST[update])){
        mysqli_query($conn,"UPDATE rb_jadwal_pelajaran SET idTahunAjaran = '$_POST[a]',
                                                    idKelas = '$_POST[b]',
                                                    kode_pelajaran = '$_POST[c]',
													jam_ke = '$_POST[d]',
                                                    nip = '$_POST[e]',
                                                    semester='$_POST[z]',
                                                    hari = '$_POST[j]',
                                                    aktif = '$_POST[k]' where kodejdwl='$_POST[id]'");
        echo "<script>document.location='?view=jadwalpelajaran';</script>";
    }
    $e = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM rb_jadwal_pelajaran where kodejdwl='$_GET[id]'"));
    echo "<div class='col-md-12'>
              <div class='box box-info'>
                <div class='box-header with-border'>
                  <h3 class='box-title'>Edit Data Jadwal Pelajaran</h3>
                </div>
              <div class='box-body'>
              <form method='POST' class='form-horizontal' action='' enctype='multipart/form-data'>
                <div class='col-md-12'>
                  <table class='table table-condensed table-bordered'>
                  <tbody>
                  <input type='hidden' name='id' value='$_GET[id]'>
                    <tr><th style='width:120px' scope='row'>Tahun Akademik</th>   <td><select class='form-control' name='a'> 
                                                <option value='0' selected>- Pilih Tahun Akademik -</option>"; 
                                                $tahun = mysqli_query($conn,"SELECT * FROM tahun_ajaran  where aktif='Y'");
                                                while($a = mysqli_fetch_array($tahun)){
                                                  if ($e[idTahunAjaran]==$a[idTahunAjaran]){
                                                    echo "<option value='$a[idTahunAjaran]' selected>$a[nmTahunAjaran]</option>";
                                                  }else{
                                                    echo "<option value='$a[idTahunAjaran]'>$a[nmTahunAjaran]</option>";
                                                  }
                                                }
                                                echo "</select>
                    </td></tr>
                    <tr><th scope='row'>Kelas</th>   <td><select class='form-control' name='b'> 
                                                <option value='0' selected>- Pilih Kelas -</option>"; 
                                                $kelas = mysqli_query($conn,"SELECT * FROM kelas_siswa");
                                                while($a = mysqli_fetch_array($kelas)){
                                                  if ($e[idKelas]==$a[idKelas]){
                                                    echo "<option value='$a[idKelas]' selected>$a[nmKelas]</option>";
                                                  }else{
                                                   echo "<option value='$a[idKelas]'>$a[nmKelas]</option>";
                                                  }
                                                }
                                                echo "</select>
                    </td></tr>
					 <tr><th scope='row'>Semester</th>  <td>
									<select class='form-control' name='z'>
										<option value='0'>- Pilih Semester -</option>
										<option value='Semester Ganjil' >Semester Ganjil</option>
										<option value='Semester Genap'>Semester Genap</option>
										
									</select>
								</td></tr>
                    <tr><th scope='row'>Mata Pelajaran</th>   <td><select class='form-control' name='c'> 
                                                <option value='0' selected>- Pilih Mata Pelajaran -</option>"; 
                                                $mapel = mysqli_query($conn,"SELECT * FROM rb_mata_pelajaran");
                                                while($a = mysqli_fetch_array($mapel)){
                                                  if ($e[kode_pelajaran]==$a[kode_pelajaran]){
                                                    echo "<option value='$a[kode_pelajaran]' selected>$a[namamatapelajaran]</option>";
                                                  }else{
                                                    echo "<option value='$a[kode_pelajaran]'>$a[namamatapelajaran]</option>";
                                                  }
                                                }
                                                echo "</select>
                    </td></tr>
                     <tr><th scope='row'>Jadwal Paralel</th>  <td><input type='text' class='form-control' name='d' value='$e[jam_ke]'></td></tr>
                    <tr><th scope='row'>Guru</th>   <td><select class='form-control' name='e'> 
                                                <option value='0' selected>- Pilih Guru -</option>"; 
                                                $guru = mysqli_query($conn,"SELECT * FROM rb_guru");
                                                while($a = mysqli_fetch_array($guru)){
                                                  if ($e[nip]==$a[nip]){
                                                    echo "<option value='$a[nip]' selected>$a[nama_guru]</option>";
                                                  }else{
                                                    echo "<option value='$a[nip]'>$a[nama_guru]</option>";
                                                  }
                                                }
                                                echo "</select>
                    </td></tr>
                   
                    <tr><th scope='row'>Hari</th>  <td><select class='form-control' name='j'>
                                                <option value='$e[hari]' selected>$e[hari]</option>
                                                <option value='Senin'>Senin</option>
                                                <option value='Selasa'>Selasa</option>
                                                <option value='Rabu'>Rabu</option>
                                                <option value='Kamis'>Kamis</option>
                                                <option value='Jumat'>Jumat</option>
                                                <option value='Sabtu'>Sabtu</option>
                                                <option value='Minggu'>Minggu</option>
                    </td></tr>
                    <tr><th scope='row'>Aktif</th>                <td>";
                                                                  if ($e[aktif]=='Ya'){
                                                                      echo "<input type='radio' name='k' value='Ya' checked> Ya
                                                                             <input type='radio' name='k' value='Tidak'> Tidak";
                                                                  }else{
                                                                      echo "<input type='radio' name='k' value='Ya'> Ya
                                                                             <input type='radio' name='k' value='Tidak' checked> Tidak";
                                                                  }
                  echo "</td></tr>
                  </tbody>
                  </table>
                </div>
              </div>
              <div class='box-footer'>
                    <button type='submit' name='update' class='btn btn-info'>Update</button>
                    <a href='?view=kelas'><button type='button' class='btn btn-default pull-right'>Cancel</button></a>
                    
                  </div>
              </form>
            </div>";
}
?>