<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-dosen/'+ kode +'';
	});
	
	$('#nonaktif').click(function(){
		var kode = $('#kodekunci').val();
		if (confirm("Anda yakin me-nonaktifkan data dengan kode " + kode+"?")){
			window.location=''+base+'query-delete-dosen/'+ kode +'';	
		}
	});
	
	$('#newdata').click(function(){
		window.location=''+base+'add-dosen';
	});

  });
   
</script>
<script type="text/javascript">
    var detik = <?php echo date('s'); ?>;
    var menit = <?php echo date('i'); ?>;
    var jam   = <?php echo date('H'); ?>;
    
    function clock()
    {
        if (detik!=0 && detik%60==0) {
            menit++;
            detik=0;
        }
        second = detik;
        
        if (menit!=0 && menit%60==0) {
            jam++;
            menit=0;
        }
        minute = menit;
        
        if (jam!=0 && jam%24==0) {
            jam=0;
        }
        hour = jam;
        
        if (detik<10){
            second='0'+detik;
        }
        if (menit<10){
            minute='0'+menit;
        }
        
        if (jam<10){
            hour='0'+jam;
        }
        waktu = hour+':'+minute+':'+second;
        
        document.getElementById("clock").innerHTML = waktu;
        detik++;
    }

    setInterval(clock,1000);
</script>
<aside class="right-side">                
                <section class="content-header">
                    <h1>
                        Data Nahkoda 
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="home"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li><a href="#">Kelola Data</a></li>
                        <li class="active">Data Nahkoda</li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                                <div class="box-header">
                                    <a data-toggle="modal" href="#modalInsert" class="btn btn-primary" style="color:#FFF; margin-left:10px;"><i class="fa fa-plus"></i> Tambah Data</a>
                                </div><!-- /.box-header -->
        <div class="table-responsive">
          <table id="example1" class="table table-bordered table-striped table-hover">
             <thead>
                <tr>
                    <th>No</th>
                    <th>Nama Nahkoda</th>
                    <th>Alamat</th>
                    <th>No Telepon</th>
                    <th colspan="2"><div align="center">Aksi</div></th>
                </tr>
            </thead>
            <tbody>
			<?php  
				    include("config/connection.php");
              		$sql ="select * from tb_nahkoda where Status ='1'";
					$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
					mysql_close($test);
					
					while($row = mysql_fetch_object($hasil)){
						$id = $row->Id_Nahkoda;
						$nama = $row->Nahkoda;
						$alamat = $row->Alamat;
						$telp = $row->No_Telp;
						
			?>
            		<tr>
                    	<td><?php echo $id ?></td>
                        <td><?php echo $nama ?></td>
                        <td><?php echo $alamat ?></td>
                        <td><?php echo $telp ?></td>
                        <td><div align="center"><a data-toggle="modal" data-id='<?php echo $id?>' href="#modalEdit" class="open-Edit btn btn-xs btn-primary"><i class="fa fa-wrench"></i></a></div></td>
                        <td><div align="center"><a data-toggle="modal" data-id='<?php echo $id?>' href="#modalDelete" class="open-Delete btn btn-xs btn-primary"><i class="fa fa-times"></i></a></div></td>
                    </tr>
            <?php		
					}
			?>         
        	</tbody>
          </table>
          </div>
        </div><!-- /.box-body -->
      </div><!-- /.box -->
    </div><!-- /.col -->
  </div><!-- /.row -->
  
                            <div class="modal fade" id="modalInsert" tabindex="-1" role="dialog">
                                <div class="modal-dialog modal-lg">
                                    <div class="modal-content">
                                    <form class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="data-nahkoda-proses">
                                    	<input type="hidden" name="act" value="1">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                            <h4 class="modal-title" id="myModalLabel">Tambah Data Nahkoda</h4>
                                        </div>
                                        <div class="modal-body" style="padding-left:50px; padding-right:50px;">
                                            <div class="form-group">
                                                <label for="Operator" class="control-label">Nama Dosen</label>
                                                <input type="text" name="nama" required="required" class="form-control" >
                                             </div>
                                            <div class="form-group">
                                                <label for="Operator" class="control-label">Alamat</label>
                                                <input type="text" name="alamat" class="form-control" >
                                             </div>
                                            <div class="form-group">
                                                <label for="Operator" class="control-label">Telepon</label>
                                                <input type="text" name="telepon"  class="form-control"  >
                                             </div>
                                        </div> 
                                        <div class="modal-footer">
                                            <div class="form-group">  
                                                <label class="col-sm-2" for="aksi"></label>      
                                                    <div class="col-sm-10">
                                                        <button type="submit" class="btn btn-success"><i class='glyphicon glyphicon-save'></i> Simpan</button>
                                                    </div>
                                            </div>
                                        </div>
                                    </form>
                                    </div>
                                    <!-- /.modal-content -->
                                </div>
                                <!-- /.modal-dialog -->
                            </div>


                            <div class="modal fade" id="modalEdit" tabindex="-1" role="dialog">
                                <div class="modal-dialog modal-lg">
                                    <div class="modal-content">
                                    <form class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="data-nahkoda-proses">
                                       <input type="hidden" name="act" value="2">
                                       <input type="hidden" name="id" id="id">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                            <h4 class="modal-title" id="myModalLabel">Ubah Data Nahkoda</h4>
                                        </div>
                                        <div class="modal-body" style="padding-left:50px; padding-right:50px;">
                                            <div class="form-group">
                                                <label for="Operator" class="control-label">Nama Nahkoda</label>
                                                <input type="text" name="nama" required="required" class="form-control" id="nama">
                                             </div>
                                            <div class="form-group">
                                                <label for="Operator" class="control-label">Alamat</label>
                                                <input type="text" name="alamat" class="form-control" id="alamat">
                                             </div>
                                            <div class="form-group">
                                                <label for="Operator" class="control-label">Telepon</label>
                                                <input type="text" name="telepon"  class="form-control" id="telp">
                                             </div>
                                        </div> 
                                        <div class="modal-footer">
                                            <div class="form-group">  
                                                <label class="col-sm-2" for="aksi"></label>      
                                                    <div class="col-sm-10">
                                                        <button type="submit" class="btn btn-success"><i class='glyphicon glyphicon-save'></i> Simpan</button>
                                                    </div>
                                            </div>
                                        </div>
                                    </form>
                                    </div>
                                    <!-- /.modal-content -->
                                </div>
                                <!-- /.modal-dialog -->
                            </div>
                            <div class="modal fade" id="modalDelete" tabindex="-1" role="dialog">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                            <h4 class="modal-title" id="myModalLabel">Non Aktif Data Nahkoda</h4>
                                        </div>
                                        <div class="modal-body">
                                            <form class="form-horizontal" role="form" name="form_kepala_delete" method="POST" enctype="multipart/form-data" id="form_kepala_delete" action="data-nahkoda-proses">
                                                <input type="hidden" id="idd" name="id">
                                                <input type="hidden" name="act" value="3">
                                            <p>Apakah Anda Yakin Akan Menghapus data ini?</p>
                                        </div>
                                        <div class="modal-footer"> 
                                            <button type="button" class="btn btn-warning" data-dismiss="modal">Tidak</button>
                                            <button type="submit" class="editflag btn btn-success" >Yakin</button>    
                                        </div>
                                            </form>
                                    </div>
                                    <!-- /.modal-content -->
                                </div>
                                <!-- /.modal-dialog -->
                            </div>
    <script>
        $(document).on("click", ".open-Edit", function () {
            var Id = $(this).data('id');
            //event.preventDefault();
            $.ajax({
                type: "get",
                url: "data-nahkoda-proses.php?actget=1",
                data: "id="+Id,
                success: function(data){
                    var jdata = jQuery.parseJSON(data);
                    $('#id').val(jdata.Id_Nahkoda);
					$('#nama').val(jdata.Nahkoda);
                    $('#alamat').val(jdata.Alamat);
                    $('#telp').val(jdata.No_Telp);
                    $("#modalEdit").modal('show');
                },
                error: function(){
                    alert("failure");
                }
            });
        });
        $(document).on("click", ".open-Delete", function () {
            var Id = $(this).data('id');
            //event.preventDefault();
            $('#idd').val(Id);
            $('#modalDelete').modal('show');
        });

    </script>
