<?php
	include "php_class/class_mysql.php";
	include "php_class/class_mahasiswa.php";
	$DataMahasiswa = new DataMahasiswa;
?>
<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');
		$('#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+'edit-mahasiswa/'+ kode +'';
	});
	
	$('#nonaktif').click(function(){
		var kode = $('#kodekunci').val();
		if (confirm("Anda yakin me-nonaktifkan data dengan kode " + kode+"?")){
			window.location=''+base+'query-nonaktif-mahasiswa/'+ kode +'';	
		}
	});
	
	$('#newdata').click(function(){
		window.location=''+base+'add-mahasiswa';
	});

  });
   
</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>
    <li class="active">Data Mahasiswa</li>
  </ol>
</section>
<section class="content">
  <div class="row">
    <div class="col-xs-12">
     
      <div class="box">
        <div class="box-header">
                <div class="col-sm-5" >
                     <div class="form-group">
                     <?php 
					 
                        $idAngkatan = $_POST['idAngkatan'];
                     ?>
                          <form action="<?php echo $base?>data-mahasiswa" method="post" name="cmb1" style="margin-bottom:35px;">
                            <label for="Operator" class="control-label">Angkatan</label>
                            <select class="form-control" name="idAngkatan" onChange="cmb1.submit();">
                                <?php
                                    if ($idAngkatan == "") {
                                        $idAngkatan = date('y');
                                        }
                                        echo "<option value='".$idAngkatan."'>20".$idAngkatan."</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>
              <div class="col-sm-7" >
                     <div class="form-group">
                      </div>
				</div>

          <a style="float:right"  href="<?php echo $base?>add-mahasiswa" class="btn btn-primary">
            <i class="glyphicon glyphicon-plus-sign"></i>
            Tambah Data
          </a>
          <a style="float:right; margin-right:20px;"  href="<?php echo $base?>upload-data-mahasiswa" class="btn btn-primary">
            <i class="glyphicon glyphicon-plus-sign"></i>
            Import Data
          </a>
        </div><!-- /.box-header -->
        <div class="box-body">
        <div class="table-responsive">
          <table id="example1" class="table table-bordered table-striped table-hover">
             <thead>
                <tr>
                    <th>NPM</th>
                    <th>Nama</th>
                    <th>Jurusan</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
            <?php
		            	$JumlahData = $DataMahasiswa->get_all_by_angkatan('',$a,'jumlah', $idAngkatan);
						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++){
								$id = $DataMahasiswa->get_all_by_angkatan('id',$a,'', $idAngkatan);
								$KodeMahasiswa = $DataMahasiswa->get_all_by_angkatan('NPM',$a,'', $idAngkatan);
								$Nama = $DataMahasiswa->get_all_by_angkatan('Nama',$a,'', $idAngkatan);
								$Jurusan = $DataMahasiswa->get_all_by_angkatan('Jurusan',$a,'', $idAngkatan);
								$isAktif = $DataMahasiswa->get_all_by_angkatan('isAktif',$a,'', $idAngkatan);
								$kdJurusan =  substr($KodeMahasiswa, 2, 2);
								
								if ($kdJurusan == "31"){
									$Jurusan = "IESP";	
								}elseif ($kdJurusan == "32"){
									$Jurusan = "MANAJEMEN";
								} elseif ($kdJurusan == "33"){
									$Jurusan = "AKUNTANSI";	
								}
								
								
								if ($isAktif=='1'){
									$Status = 'Aktif';
								}else{
									$Status ='Non Aktif';
								}
								echo "<tr id='".$id."' class='odd gradeX context'>";
								echo "<td>".$KodeMahasiswa."</td>";
								echo "<td>".$Nama."</td>";
								echo "<td>".$Jurusan."</td>";
								echo "<td>".$Status."</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">
                        <div align="center">
                        <p><button type="button" class="btn btn-default" id="editdata">Edit Data</button></p>
                        <p><button type="button" class="btn btn-default" id="nonaktif">Non Aktif</button></p>
                        <p><button type="button" class="btn btn-primary" id="newdata"><i class='glyphicon glyphicon-plus-sign'></i> Tambah Data</button></p>
                        </div>
                        
                     </div>
                </div>
            </div>
          </div>
          
          
        </div><!-- /.box-body -->
      </div><!-- /.box -->
    </div><!-- /.col -->
  </div><!-- /.row -->
  
</section>
 
