<?php
	include "php_class/class_mysql.php";
	include "php_class/class_template.php";
	include "php_class/class_mahasiswa.php";
	include "php_class/class_grup.php";
	include "php_class/class_transaksi.php";
	
	$DataTransaksi = new DataTransaksi;
	$datagrup = new DataGrup;
	$DataMahasiswa = new DataMahasiswa;
	$DataTemplate = new DataTemplate;

	$id = $xcode;
?>
<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>
	$(document).ready(function(){
	var base = <?php echo json_encode($base);?>;
		$("#setting").click(function(){
			$("#myModal").modal('show');
		});

		$("#Nama").click(function(){
			$("#myModal").modal('show');
		});
		$("#batal").click(function(){
			$('#form1').hide();
			$('#NPM').val() = '';
		});
		$("#AddTrans").click(function(){
			$("#myModal2").modal('show');
		});
		$('.delete').click(function(){
			var kode = $(this).attr('ids');
			if (confirm("Anda yakin menghapus transaksi ini?")){
				window.location=''+base+'query-delete-temp/'+ kode +'';	
			}
		});
		$('#NPM').keyup(function(e){
	  		if(e.keyCode == 13){
				var npm = $('#NPM').val();
				var action = '3';
				var program = $('#program').val();
				var tahun = $('#tahun').val();
				var semester = $('#semester').val();
				var idgrup = $('#idgrup').val();
				if (npm==''){
					$('.peringatan').html('<div id="warning"><div class="alert alert-warning" role="alert">NPM Masih Kosong!</div></div>')			
				}else{
					$.ajax({
						type:"POST",
						data: "index=" + npm + "&program=" + program + "&tahun=" + tahun + "&semester=" + semester + "&grup=" + idgrup ,
						url:"<?php echo $base?>cek-npm.php",     
						success: function(data){
							var tampung = data;
							if(tampung!=404){
								$('#form1').show();
								var pecah=tampung.split(":");
								$('#Nama2').val(pecah[0]);
								$('#jurusan').val(pecah[1]);
								$('#alamat').val(pecah[2]);
								$('#kodeMhs').val(pecah[3]);
								$('#nn').val(pecah[4]);
								$('#Nama3').val(pecah[0]);
								status = pecah[5];
								statuskelas = pecah[6];
								
								if (statuskelas == "tidak") {
									$('.peringatan').html('<div id="warning"><div class="alert alert-warning" role="alert">Kelas dengan NPM yang diinput tidak sesuai!</div></div>')
								$('#simpan').hide();
								} else if (status == "ada") {
									$('.peringatan').html('<div id="warning"><div class="alert alert-warning" role="alert">Mahasiswa ini sudah melakukan pembayaran untuk transaksi ini!</div></div>')
								$('#simpan').hide();

								}else {
								$('.peringatan').html('<div id="warning"><div role="alert"></div></div>')
								$('#simpan').show();
								$('#simpan').focus();	
									}
							}else{
								$('.peringatan').html('<div id="warning"><div class="alert alert-warning" role="alert">Mahasiswa dengan NPM ini tidak ditemukan!</div></div>')
								$('#NPM').focus();	
								}
						}
					});
				}
			} 
		});

	});
</script>
<section class="content-header">
  <h1>
   Data Mahasiswa
  </h1>
  <ol class="breadcrumb">
    <li><a href="<?php echo $base?>"><i class="fa fa-dashboard"></i> Home</a></li>
  </ol>
</section>
<section class="content">
 	<div class="row">
    	<div class="row">
        	<div class="col-md-12">
            </div>
        </div>
    	<div class="col-md-12">
        	 <div class="box box-info">
                <div class="box-body">
					<div class="row">
                        <div class="col-sm-7" >
							<?php 
							$angkatan = $_POST['angkatan'];
							$jurusan = $_POST['jurusan'];
							$tahun = date("y");
							$cetakjurusan = $jurusan;
							$klas = $_POST['klas'];;
							
								if ($klas == ""){
									$cetakklas = 'Semua';	
								} else if ($klas == "121"){
									$cetakklas = 'Reguler';	
								} else if ($klas == '122'){
									$cetakklas = 'R. Sore - Eksekutif';	
								}
								
								if ($jurusan == "" ){
									$cetakjurusan = 'Semua';
									}					
								
								if ($angkatan == ""){
									$angkatan = $tahun;
									}								

									$cetakangkatan = "20".$angkatan;

									echo "<H3 style='margin-bottom:15px;'>Jurusan : ".$cetakjurusan."</h3>";
									echo "<H5 style='margin-bottom:15px;'>Angkatan : ".$cetakangkatan."</h5>";
									echo "<H5 style='margin-bottom:15px;'>Klas : ".$cetakklas."</h5>";

							?>
                        </div>
                        <div class="col-sm-5">
            <button type="submit" class="btn btn-primary" 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 class="table-responsive" style="margin-top:30px;">
                          <table  class="table table-striped">
                             <thead>
                                <tr>
                                    <th>NO</th>
                                    <th>Nama Mahasiswa</th>
                                    <th>NPM</th>
                                    <th>Jurusan</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php
								$total = 0;
								$jumlahtotal = 0;
								$b = 0;
								$JumlahData = $DataMahasiswa->get_all_by_jurusan_angkatan('',$a,'jumlah', $jurusan, $angkatan, $klas);
                                if ($JumlahData<=0){
                                    echo "<tr class='odd gradeX'>";
                                    echo "<td>No Data</td>";
                                    echo "<td></td>";
                                    echo "<td></td>";
									echo "<td></td>";
                                    echo "</tr>";	
                                }else{
                                    
									for ($a=1;$a<=$JumlahData;$a++){
										$Nama = $DataMahasiswa->get_all_by_jurusan_angkatan('Nama',$a,'', $jurusan, $angkatan, $klas);
										$NPM = $DataMahasiswa->get_all_by_jurusan_angkatan('NPM',$a,'', $jurusan, $angkatan, $klas);
										$Jurusan = $DataMahasiswa->get_all_by_jurusan_angkatan('Jurusan',$a,'', $jurusan, $angkatan, $klas);

										$b	= $b + 1;
                                        echo "<tr id='".$NPM."' class='odd gradeX context'>";
                                        echo "<td>".$b."</td>";
                                        echo "<td>".$Nama."</td>";
                                        echo "<td>".$NPM."</td>";
										echo "<td>".$Jurusan."</td>";
                                        echo "</tr>";
                                    }
                                }
                            ?>
                            </tbody>
                          </table>
          			</div>
                    <div class="col-sm-7" >
                            <?php
                                date_default_timezone_set('UTC');
                            ?>
                            <h4>Jumlah Mahasiswa : <?php echo $b?></h4>

                    </div>
                    <div class="col-sm-5">
                                  <form action="<?php echo $base?>tabel-mahasiswa.php" method="post" name="cmb" style="float:right" id="cmb" target="_blank">
                                            <input type="hidden" name="angkatan" value="<?php echo $angkatan?>" />
                                            <input type="hidden" name="tglawal" value="<?php echo $tglawal?>" />
                                            <input type="hidden" name="tglakhir" value="<?php echo $tglakhir?>" />
                                        	<input type="hidden" name="kegiatan" value="<?php echo $kegiatan?>">
                                            <input type="hidden" name="jurusan" value="<?php echo $jurusan?>">
                                        	<input type="hidden" name="operator" value="<?php echo $idOperator?>">
                                        <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>
    </div>
</section>

    	
<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(){
	$("#example1").dataTable();
	
  });
</script>

<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-mahasiswa-total" method="post" name="cmb" style="margin-bottom:35px;" id="cmb">
            <div class="form-group">
                <label class="control-label">Angkatan</label>
                <select class="form-control" name="angkatan">
                <?php 
                    if ($angkatan != "") {
                        echo "<option value='".$angkatan."'>".$cetakangkatan."</option>";
                    }
                ?>
                            <?php 
                                $JumlahData = $DataMahasiswa->get_angkatan('',$a,'jumlah');	
                                    for ($a=1;$a<=$JumlahData;$a++){
                                    $angkatan = $DataMahasiswa->get_angkatan('angkatan',$a,'');
                                echo "<option value=".$angkatan.">20".$angkatan."</option>";
                                }
                            			echo "<option value=''>Semua Angkatan</option>";  
                            ?>

                </select>
			</div>

            <div class="form-group">
                <label class="control-label">Jurusan</label>
                <select class="form-control" name="jurusan">
                <?php 
                    if ($jurusan != "") {
                        echo "<option value='".$jurusan."'>".$cetakjurusan."</option>";
                    }
                        echo "<option value=''>Semua</option>";	
                ?>
                    <option value="IESP">IESP</option>
                    <option value="AKUNTANSI">AKUNTANSI</option>
                    <option value="MANAJEMEN">MANAJEMEN</option>

                </select>
			</div>

            <div class="form-group">
                <label class="control-label">KLAS</label>
                <select class="form-control" name="klas">
                <?php 
                    if ($klas != "") {
                        echo "<option value='".$klas."'>".$cetakklas."</option>";
                    }
                        echo "<option value=''>Semua</option>";	
                ?>
                    <option value="">Semua</option>
                    <option value="121">Reguler</option>
                    <option value="122">R. Sore - Eksekutif</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>
<script>
	$(document).ready(function(){
		$('.pilih').click(function(){
			var kode = $(this).attr('ids');
			var pecah = kode.split("-");	
				kodeMhs = pecah[0];
				npm = pecah[1];
				nama = pecah[2];
				jurusan = pecah[3];
				alamat = pecah[4];
				
			$('#kodeMhs').val(kodeMhs);
			$('#NPM').val(npm);
			$('#nn').val(npm);
			$('#Nama').val(nama);
			$('#alamat').val(alamat);
			$('#jurusan').val(jurusan);
			$('#myModal').modal('hide')
			$('#Nama').focus();
		});
	});
