<?php
	include "php_class/class_mysql.php";
	include "php_class/class_ujianakhir.php";
	$Dataujian = new dataujian;
	$DataUjian2 = new dataUjian;
?>
<link href="<?php echo $base?>plugins/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<script src="<?php echo $base?>plugins/datatables/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="<?php echo $base?>plugins/datatables/dataTables.bootstrap.min.js" type="text/javascript"></script>
<script type="text/javascript">
  $(document).ready(function(){
	var base = <?php echo json_encode($base);?>;
	
	$("#example1").dataTable();
	
	$('.context').click(function(e){
		var kode = $(this).attr('id');
		var tahun = $(this).attr('tahun');
		var sm = $(this).attr('sm');
		var hari = $(this).attr('hari');
		var program = $(this).attr('program');
		
		$('#kodekunci').val(kode);
		$('#tahun').val(tahun);
		$('#sm').val(sm);
		$('#hari').val(hari);
		$('#program').val(program);
		
   		$("#menuklik").modal('show');
	});
	
	/*$('.context').bind('contextmenu', function(e){
		e.preventDefault();
    	var kode = $(this).attr('id');
		$('#kodekunci').val(kode);
   		$("#menuklik").modal('show');
	});*/
	
	$('#editdata').click(function(){
		var kode = $('#kodekunci').val();
		window.location=''+base+'edit-jadwal-uas/'+ kode +'';
	});
	$('#cetak').click(function(){
		var kode = $('#kodekunci').val();
		window.location=''+base+'laporan-kehadiran-uas.php?id='+ kode +'';
	});
	$('#hadir').click(function(){
		var kode = $('#kodekunci').val();
		window.location=''+base+'edit-hadir-uas/'+ kode +'';
	});
	
	$('#nonaktif').click(function(){
		var kode = $('#kodekunci').val();
		if (confirm("Anda yakin me-nonaktifkan data dengan kode " + kode+"?")){
			window.location=''+base+'query-delete-uas/'+ kode +'';	
		}
	});
	
	$('#newdata').click(function(){
		var kode = $('#kodekunci').val();
		window.location=''+base+'add-detil-jadwal/'+ kode +'';
	});

  });
   
</script>
<section class="content-header">
  <h1>
    Data UAS
  </h1>
  <ol class="breadcrumb">
    <li><a href="<?php echo $base?>index"><i class="fa fa-dashboard"></i> Home</a></li>
    <li class="active">Data UAS</li>
  </ol>
</section>
<section class="content">
  <div class="row">
    <div class="col-xs-12">
     <?php
			$hari = $_POST['hari'];
			$semester = $_POST['semester'];
			$program = $_POST['program'];
			if($program == ''){
				$program = 'REGULER';	
			}
			if($hari == ''){
				$hari = 'SEMUA HARI';	
			}
			if($semester == ''){
				$semester = 'GENAP';	
			}
			$tahun = $_POST['tahun'];
			if ($tahun == ""){
				$bulansmst = date('m');
				$bulansmst = substr($bulansmst, 1, 1); 
				if ($bulansmst > 8 and $bulansmst < 13){
						$dp = date('y');
						$bk = $dp - 1;
						$tahun = '20'.$bk.'/20'.$dp;	
				}else if ($bulansmst <= 3){
						$dp = date('y');
						$bk = $dp - 1;
						$tahun = '20'.$bk.'/20'.$dp;	
				}else{
						$dp = date('y');
						$bk = $dp + 1;
						$tahun = '20'.$dp.'/20'.$bk;	
				}
			}
	 ?>
      <div class="box">
        <div class="box-header">
          <h3 class="box-title">Data UAS</h3>
          <a style="float:right"  href="<?php echo $base?>laporan-daftar-uang-koreksi-uas.php?tahun=<?php echo $tahun?>&semester=<?php echo $semester?>&program=<?php echo $program?>" class="btn btn-success" target="_blank">
            <i class="glyphicon glyphicon-print"></i>
            Laporan Uang Koreksi
          </a>
          <a style="float:right; margin-right:10px;"  href="<?php echo $base?>upload-data-jadwal-uas" class="btn btn-primary">
            <i class="glyphicon glyphicon-import"></i>
            Import Jadwal
          </a>
          <a style="float:right; margin-right:10px;"  href="<?php echo $base?>add-jadwal-uas" class="btn btn-primary">
            <i class="glyphicon glyphicon-plus-sign"></i>
            Tambah Data
          </a>
        </div><!-- /.box-header -->
        <div class="box-body">
        <form action="data-uas" method="post" name="frm">
            <select class="form-control" name="program" style="margin-bottom:30px;width:50%" onchange="frm.submit()">
                <option value="<?php echo $program?>"><?php echo $program?></option>
                <option value="SEMUA">SEMUA</option>
                <option value="REGULER">REGULER</option>
                <option value="R. SORE EKSEKUTIF">R. SORE EKSEKUTIF</option>
            </select>
            <select class="form-control" name="hari" style="margin-bottom:30px;width:50%" onchange="frm.submit()">
                <option value="<?php echo $hari?>"><?php echo $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>
            </select>
            <select class="form-control" name="semester" style="margin-bottom:30px;width:50%" onchange="frm.submit()">
                <option value="<?php echo $semester?>" selected="selected"><?php echo $semester?></option>
                <option value="GENAP">GENAP</option>
                <option value="GANJIL">GANJIL</option>
            </select>
            <select class="form-control" name="tahun" style="margin-bottom:30px;width:50%" onchange="frm.submit()">
                <option value="<?php echo $tahun?>" selected="selected"><?php echo $tahun?></option>
            <?php 
            	$JumlahData1 = $DataUjian2->get_tahun('',$a,'jumlah');
					for ($a=1;$a<=$JumlahData1;$a++){
						$tahun2 = $DataUjian2->get_tahun('tahun', $a, '');
			?>    
                <option value="<?php echo $tahun2?>"><?php echo $tahun2?></option>
			<?php } ?>
            </select>
		</form>
        <div class="table-responsive">
          <table id="example1" class="table table-bordered table-striped table-hover">
             <thead>
                <tr>
                    <th>No</th>
                    <th>Nama Dosen</th>
                    <th>Mata Kuliah</th>
                    <th>Kelas</th>
                    <th>Ruang</th>
                    <th>Hari</th>
                    <th>Hadir</th>
                </tr>
            </thead>
            <tbody>
            <?php
            	$JumlahData = $Dataujian->get_data_uas('',$a,'jumlah', $hari, $semester, $tahun, $program);
				if ($JumlahData<=0){
					echo "<tr class='odd gradeX'>";
					echo "<td>No Data</td>";
					echo "<td></td>";
					echo "<td></td>";
					echo "<td></td>";
					echo "<td></td>";
					echo "<td></td>";
					echo "<td></td>";
					echo "</tr>";	
				}else{
					for ($a=1;$a<=$JumlahData;$a++){
						$id = $Dataujian->get_data_uas('id',$a,'', $hari, $semester, $tahun, $program);
						$dosen = $Dataujian->get_data_uas('dosen', $a, '', $hari, $semester, $tahun, $program);
						$matakuliah = $Dataujian->get_data_uas('matakuliah',$a,'', $hari, $semester, $tahun, $program);
						$jurusan = $Dataujian->get_data_uas('jurusan',$a,'', $hari, $semester, $tahun, $program);
						$kelas = $Dataujian->get_data_uas('kelas',$a,'', $hari, $semester, $tahun, $program);
						$hari = $Dataujian->get_data_uas('hari',$a,'', $hari, $semester, $tahun, $program);
						$hadir = $Dataujian->get_data_uas('hadir',$a,'', $hari, $semester, $tahun, $program);
						$ruang = $Dataujian->get_data_uas('ruang',$a,'', $hari, $semester, $tahun, $program);

						echo "<tr id='".$id."' tahun = '".$tahun."' sm = '".$semester."' hari = '".$hari."' program = '".$program."' class='odd gradeX'>";
						echo "<td id='".$id."' class='context'>".$id."</td>";
						echo "<td id='".$id."' class='context'>".$dosen."</td>";
						echo "<td id='".$id."' class='context'>".$matakuliah."</td>";
						echo "<td id='".$id."' class='context'>".$kelas."</td>";
						echo "<td id='".$id."' class='context'>".$ruang."</td>";
						echo "<td id='".$id."' class='context'>".$hari."</td>";
						echo "<td id='".$id."' class='context'>".$hadir."</td>";
						echo "</tr>";
					}
				}
			?>
        	</tbody>
          </table>
          </div>
          <div id="menuklik" class="modal fade" role="dialog">
          	<div class="modal-dialog modal-sm">
                <div class="modal-content">
                	<div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h5 class="modal-title">Aksi</h5>
                    </div>
                  	<div class="modal-body">
                        <input type="hidden" value="" id="kodekunci">
                        <input type="hidden" value="" id="sm">
                        <input type="hidden" value="" id="hari">
                        <input type="hidden" value="" id="program">
                        <div align="center">
                        <input type="text" id="tahun">
                        <p><button type="button" class="btn btn-default" id="editdata"><i class="glyphicon glyphicon-pencil"></i> Edit Data</button></p>
                        <p><button type="button" class="btn btn-default" id="nonaktif"><i class="glyphicon glyphicon-cancel"></i> Hapus</button></p>
                        <p><button type="button" class="btn btn-success" id="cetak"><i class="glyphicon glyphicon-print"></i> Cetak</button></p>
                        <p><button type="button" class="btn btn-warning" id="hadir"><i class="glyphicon glyphicon-list"></i> Kehadiran</button></p>
                        </div>
                        
                     </div>
                </div>
            </div>
          </div>
          
          
        </div><!-- /.box-body -->
      </div><!-- /.box -->
    </div><!-- /.col -->
  </div><!-- /.row -->
  
</section>
 
