<?php
	include "php_class/class_mysql.php";
	include "php_class/class_absen.php";
	$dataabsen = new dataabsen;
	$dataabsen2 = new dataabsen;
	$dataabsen3 = new dataabsen;
	$dataabsen4 = new dataabsen;
	include "php_class/class_jadwal.php";
	$DataJadwal = new dataJadwal;
?>
<link href="<?php echo $base?>plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $base?>plugins/iCheck/all.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $base?>plugins/timepicker/bootstrap-timepicker.min.css" rel="stylesheet"/>
<script src="<?php echo $base?>plugins/input-mask/jquery.inputmask.js" type="text/javascript"></script>
<script src="<?php echo $base?>plugins/input-mask/jquery.inputmask.date.extensions.js" type="text/javascript"></script>
<script src="<?php echo $base?>plugins/input-mask/jquery.inputmask.extensions.js" type="text/javascript"></script>
<script src="<?php echo $base?>plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<script src="<?php echo $base?>plugins/timepicker/bootstrap-timepicker.min.js" type="text/javascript"></script>
<script src="<?php echo $base?>plugins/iCheck/icheck.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="<?php echo $base?>plugins/autocomplete/shieldui-all.css" />
<link href="<?php echo $base?>bootstrap/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="<?php echo $base?>bootstrap/js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
<script type="text/javascript" src="<?php echo $base?>bootstrap/js/locales/bootstrap-datetimepicker.id.js" charset="UTF-8"></script>
<script type="text/javascript" src="<?php echo $base?>plugins/autocomplete/shieldui-all.min.js"></script>

<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();
		$("#setting").click(function(){
			$("#myModal").modal('show');
		});
	$('.context').click(function(e){
		var kode = $(this).attr('id');
		$('#kodekunci').val(kode);
   		$("#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+'query-absen-dosen-hadir/'+ kode;
	});
	
	$('#nonaktif').click(function(){
		var kode = $('#kodekunci').val();
		window.location=''+base+'query-absen-dosen-tidak-hadir/'+ kode;
	});
	
	$('#newdata').click(function(){
		var kode = $('#kodekunci').val();
		window.location=''+base+'add-detil-jadwal/'+ kode +'';
	});

  });
   
</script>
<section class="content-header">
  <h1>
    Kehadiran Dosen
  </h1>
  <ol class="breadcrumb">
    <li><a href="<?php echo $base?>index"><i class="fa fa-dashboard"></i> Home</a></li>
    <li class="active">Data Kehadiran Dosen</li>
  </ol>
</section>
<section class="content">
  <div class="row">
    <div class="col-xs-12">
     
      <div class="box">
        <div class="box-body">
					<div class="row">
                        <div class="col-sm-7" >
							<?php 
							$tanggal = $_POST['tanggal'];
							$tanggal = substr($tanggal, 0, 10);
							if($tanggal == ''){
								$tanggal = $_SESSION['tanggalabsen'];
							}else{
								$_SESSION['tanggalabsen'] = $tanggal;	
							}
							if($tanggal == ''){
								$tanggal = date('Y-m-d');
								$_SESSION['tanggalabsen'] = $tanggal;
							}
							$day = date('D', strtotime($tanggal));
							$dayList = array(
								'Sun' => 'Minggu',
								'Mon' => 'Senin',
								'Tue' => 'Selasa',
								'Wed' => 'Rabu',
								'Thu' => 'Kamis',
								'Fri' => 'Jumat',
								'Sat' => 'Sabtu'
							);
							
							$hari = $dayList[$day];
							
							$tahun = $_POST['tahun'];
							$semester = $_POST['semester'];
							$jurusan = $_POST['jurusan'];
							$program = $_POST['program'];
							
								if ($tahun == '' ){
									$tahun = '2016/2017';
								}
								if ($semester == '' ){
									$semester = 'GENAP';
								}					
								if ($jurusan == '' ){
									$jurusan = '';
								}					
								if ($program == '' ){
									$program = 'SEMUA';
								}					

									echo "<H3 style='margin-bottom:15px;'>Hari : ".$hari."</h3>";
									echo "<H5 style='margin-bottom:15px;'>Tanggal : ".$tanggal."</h5>";
									echo "<H5 style='margin-bottom:15px;'>Tahun Akademik : ".$tahun."</h5>";
									echo "<H5 style='margin-bottom:15px;'>Semester Akademik : ".$semester."</h5>";
									echo "<H5 style='margin-bottom:15px;'>Program : ".$program."</h5>";
								
								
								$Jumlah = $dataabsen2->get_jumlah('',$a,'jumlah', $tanggal);
								
								if($Jumlah < 1){
									$dataabsen3->add_jadwal($hari, $tahun, $semester);
									$dataabsen4->add_jadwal_tambahan($tanggal);
								}	
							?>
                        </div>
                        <div class="col-sm-5">
            <button type="submit" class="btn btn-success" id="setting" style="margin-top:20px; float:right"> <i class="glyphicon glyphicon glyphicon glyphicon-edit" style="padding-right:4px;"></i>Setting</button>
                        </div>
                	</div>        
			</div>
        <div class="box-body">
        <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>Hari</th>
                    <th>Waktu</th>
                    <th>Kehadiran</th>
                </tr>
            </thead>
            <tbody>
            <?php
            	$JumlahData = $dataabsen->get_data_jadwal_filter('',$a,'jumlah', $semester, $tahun, $jurusan, $program, $tanggal);
				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 = $dataabsen->get_data_jadwal_filter('id',$a,'', $semester, $tahun, $jurusan, $program, $tanggal);
						$dosen = $dataabsen->get_data_jadwal_filter('dosen', $a, '', $semester, $tahun, $jurusan, $program, $tanggal);
						$matakuliah = $dataabsen->get_data_jadwal_filter('matakuliah',$a,'', $semester, $tahun, $jurusan, $program, $tanggal);
						$kelas = $dataabsen->get_data_jadwal_filter('kelas',$a,'', $semester, $tahun, $jurusan, $program, $tanggal);
						$hari = $dataabsen->get_data_jadwal_filter('hari',$a,'', $semester, $tahun, $jurusan, $program, $tanggal);
						$waktu = $dataabsen->get_data_jadwal_filter('waktu',$a,'', $semester, $tahun, $jurusan, $program, $tanggal);
						$hadir = $dataabsen->get_data_jadwal_filter('hadir',$a,'', $semester, $tahun, $jurusan, $program, $tanggal);
						
						echo "<tr id='".$id."' class='odd gradeX'>";
						echo "<td id='".$id."' class='context'>".$a."</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'>".$hari."</td>";
						echo "<td id='".$id."' class='context'>".$waktu."</td>";
						if($hadir == '1'){
							$hadir = 'HADIR';
							echo "<td id='".$id."' class='context' style='color:#F66; text-transform:uppercase'><strong>".$hadir."</strong></td>";
						}else{
							$hadir = 'TIDAK';
							echo "<td id='".$id."' class='context' style='color:#060; text-transform:uppercase'><strong>".$hadir."</strong></td>";
						}
						echo "</tr>";
					}
				}
			?>
        	</tbody>
          </table>
          </div>
         </div>
        <div class="box-body">
					<div class="row">
                        <div class="col-sm-7" >
                        </div>
                        <div class="col-sm-5">
                          <form action="<?php echo $base?>tabel-jadwal.php" method="post" name="cmb" style="float:right; " id="cmb" target="_blank">
                                    <input type="hidden" name="semester" value="<?php echo $semester?>" />
                                    <input type="hidden" name="tahun" value="<?php echo $tahun?>" />
                                    <input type="hidden" name="jurusan" value="<?php echo $jurusan?>" />
                                    <input type="hidden" name="program" value="<?php echo $program?>" />
                                <button type="submit" class="btn btn-primary" id="OK" style="margin-top:20px;"> <i class="glyphicon glyphicon-print"></i> Export Excel</button>
                         </form>   
                        </div>
                	</div>        
			</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">
                        <div align="center">
                        <p><button type="button" class="btn btn-success" id="editdata">Hadir</button></p>
                        <p><button type="button" class="btn btn-warning" id="nonaktif">Tidak Hadir</button></p>
                        </div>
                        
                     </div>
                </div>
            </div>
          </div>
          
          
        </div><!-- /.box-body -->
      </div><!-- /.box -->
    </div><!-- /.col -->
  </div><!-- /.row -->
  
</section>
 
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog modal-lg">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Setting</h4>
      </div>
      <div class="modal-body">
          <form action="<?php echo $base?>data-absen-dosen" method="post" name="cmb" style="margin-bottom:35px;" id="cmb">
            <div class="form-group">
                <label class="control-label">Tahun Akademik</label>
                <select class="form-control" name="tahun">
                <?php 
                    if ($tahun != "") {
                        echo "<option value='".$tahun."'>".$tahun."</option>";
                    }
					    $DataJadwal2 = new dataJadwal; 
						$JumlahData = $DataJadwal2->get_all_tahun('',$a,'jumlah');	
                            for ($a=1;$a<=$JumlahData;$a++){
                            $tahun = $DataJadwal2->get_all_tahun('tahun',$a,'');
                       		echo "<option value=".$tahun.">".$tahun."</option>";
                        }
                ?>
                </select>
			</div>
            <div class="form-group">
                <label class="control-label">Semester</label>
                <select class="form-control" name="semester">
                <?php 
                    if ($semester != "") {
                        echo "<option value='".$semester."'>".$semester."</option>";
                    }
                ?>
                	<option value="GENAP">GENAP</option>
                    <option value="GANJIL">GANJIL</option>
                </select>
			</div>
                 <div class="form-group">
                    <label class="control-label">Tanggal</label>
                    <div class="input-group date form_date" data-date="" data-date-format="yyyy-mm-dd" data-link-field="tglProposal2">
                        <input required="required" class="form-control" type="text" value="" placeholder="tanggal" readonly id="tglProposal">
                        <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                        <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                        <input type="hidden" id="tglProposal2" name="tanggal" value="" />
                        <script type="text/javascript">
                            $('.form_date').datetimepicker({
                                language:  'id',
                                weekStart: 1,
                                todayBtn:  1,
                                autoclose: 1,
                                todayHighlight: 1,
                                startView: 2,
                                minView: 2,
                                forceParse: 0
                            });
                        </script>  
                    </div>
                 </div>
            <div class="form-group">
                <label class="control-label">Program</label>
                <select class="form-control" name="program">
                <?php 
                    if ($program != "") {
                        echo "<option value='".$program."'>".$program."</option>";
                    }
                ?>
                	<option value="SEMUA">SEMUA</option>
                    <option value="REGULER">REGULER</option>
                    <option value="R. SORE">R. SORE</option>
                </select>
			</div>
                <button type="submit" class="btn btn-primary" id="OK" style="margin-top:20px;"> <i class="glyphicon glyphicon glyphicon-ok-circle"></i> OK</button>
         </form>   
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" id="closemodal" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
