<?php
	include "php_class/class_mysql.php";
	include "php_class/class_agenda.php";
	$dataAgenda = new dataAgenda;
?>
<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>
<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 beranda = $(this).attr('beranda');
		$('#kodekunci').val(kode);
		$('#beranda').val(beranda);
   		$("#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-surat-keluar/'+ kode +'';
	});
	
	$('#nonaktif').click(function(){
		var kode = $('#kodekunci').val();
		var beranda = $('#beranda').val();
		if (confirm("Anda yakin menghapus data dengan kode " + kode+"?")){
			window.location=''+base+'query-delete-surat-keluar/'+ kode +'/'+ beranda;	
		}
	});
	
	$('#newdata').click(function(){
		window.location=''+base+'add-dosen';
	});

  });
   
</script>
<section class="content-header">
  <h1>
    Data Agenda Surat
  </h1>
  <ol class="breadcrumb">
    <li><a href="<?php echo $base?>index"><i class="fa fa-dashboard"></i> Home</a></li>
    <li class="active">Data Agenda Surat Keluar</li>
  </ol>
</section>
<section class="content">
  <div class="row">
    <div class="col-xs-12">
                    <?php 
						$beranda = $_POST['beranda'];
						if($beranda == ''){
							$beranda = $xcode;
						}
						if($tglAwal == ''){
							$tglAwal = date('Y-m-d');	
						}
						if($tglAkhir == ''){
							$tglAkhir = date('Y-m-d');	
						}
						
						if($beranda == 1){
							$ctk = 'DEKANAT';	
						}elseif($beranda == 2){
							$ctk = 'MANAJEMEN';
						}elseif($beranda == 3){
							$ctk = 'AKUNTANSI';	
						}elseif($beranda == 4){
							$ctk = 'IESP';	
						}elseif($beranda == 5){
							$ctk = 'REGULER B';
						}else{
							$ctk = 'DEKANAT';
							$beranda = 1;	
						}
					?>
      <div class="box">
        <div class="box-header">
          <h3 class="box-title">Surat Keluar</h3>
          <a style="float:right"  href="<?php echo $base?>add-surat-keluar/<?php echo $beranda?>" class="btn btn-primary">
            <i class="glyphicon glyphicon-plus-sign"></i>
            Tambah Data
          </a>
        </div><!-- /.box-header -->
        <div class="box-body">
        	<div class="row">
            	<div class="col-md-3">
                	<div class="form-group">
                        <form action="data-surat-masuk" method="post">
                            <label for="Operator" class="control-label">Beranda</label>
                            <select name="beranda" class="form-control">
                                <option value="<?php echo $beranda?>"><?php echo $ctk?></option>
                                <option value="1">DEKANAT</option>
                                <option value="2">MANAJEMEN</option>
                                <option value="3">AKUNTANSI</option>
                                <option value="4">IESP</option>
                                <option value="5">REGULER B</option>
                            </select>
                	</div>
            	</div>
                <div class="col-md-3">
                     <div class="form-group">
                        <label class="control-label">Tanggal Awal</label>
                        <div class="input-group date form_date" data-date="" data-date-format="yyyy-mm-dd" data-link-field="tgl">
                            <input required="required" class="form-control" type="text" placeholder="tanggal awal" readonly id="tgl" value="<?php echo $tglAwal?>">
                            <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="tgl" name="tglAwal" value="<?php echo $tglAwal?>" />
                            <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>
                <div class="col-md-3">
                     <div class="form-group">
                        <label class="control-label">Tanggal akhir</label>
                        <div class="input-group date form_date" data-date="" data-date-format="yyyy-mm-dd" data-link-field="tgl2">
                            <input required="required" class="form-control" type="text" placeholder="tanggal akhir" readonly id="tgl2" value="<?php echo $tglAkhir?>">
                            <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="tgl2" name="tglAkhir" value="<?php echo $tglAkhir?>" />
                            <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>
                <div class="col-md-3">
                     <div class="form-group">
                        <button type="submit" class="btn btn-default" style="margin-top:25px;"><i class='glyphicon glyphicon-search'></i> Cari</button>
                     </div>
                </div>
	                </form>
        	</div>        
        <div class="table-responsive" style="margin-top:30px;">
          <table id="example1" class="table table-bordered table-striped table-hover">
             <thead>
                <tr>
                    <th>No</th>
                    <th>Tanggal Surat</th>
                    <th>Asal Surat</th>
                    <th>No Surat</th>
                    <th>Prihal</th>
                    <th>Tujuan/Kepada</th>
                    <th>Disposisi</th>
                    <th>Dokumen</th>
                </tr>
            </thead>
            <tbody>
            <?php
				
            	$JumlahData = $dataAgenda->get_data_agenda('',$a,'jumlah', $beranda, 2, $tglAwal, $tglAkhir);
				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 "<td></td>";
					echo "</tr>";	
				}else{
					for ($a=1;$a<=$JumlahData;$a++){
						$id = $dataAgenda->get_data_agenda('id',$a,'', $beranda, 2, $tglAwal, $tglAkhir);
						$tgl = $dataAgenda->get_data_agenda('tgl', $a, '', $beranda, 2, $tglAwal, $tglAkhir);
						$nosurat = $dataAgenda->get_data_agenda('nosurat',$a,'', $beranda, 2, $tglAwal, $tglAkhir);
						$asal = $dataAgenda->get_data_agenda('asal',$a,'', $beranda, 2, $tglAwal, $tglAkhir);
						$tujuan = $dataAgenda->get_data_agenda('tujuan',$a,'', $beranda, 2, $tglAwal, $tglAkhir);
						$prihal = $dataAgenda->get_data_agenda('prihal', $a, '', $beranda, 2, $tglAwal, $tglAkhir);
						$disposisi = $dataAgenda->get_data_agenda('disposisi',$a,'', $beranda, 2, $tglAwal, $tglAkhir);
						$dokumen = $dataAgenda->get_data_agenda('dokumen',$a,'', $beranda, 2, $tglAwal, $tglAkhir);
						
						echo "<tr id='".$id."' beranda = '".$beranda."' class='odd gradeX'>";
						echo "<td id='".$id."' beranda = '".$beranda."' class='context'>".$a."</td>";
						echo "<td id='".$id."' beranda = '".$beranda."' class='context'>".$tgl."</td>";
						echo "<td id='".$id."' beranda = '".$beranda."' class='context'>".$asal."</td>";
						echo "<td id='".$id."' beranda = '".$beranda."' class='context'>".$nosurat."</td>";
						echo "<td id='".$id."' beranda = '".$beranda."' class='context'>".$prihal."</td>";
						echo "<td id='".$id."' beranda = '".$beranda."' class='context'>".$tujuan."</td>";
						echo "<td id='".$id."' beranda = '".$beranda."' class='context'>".$disposisi."</td>";
						echo "<td><a href='".$base."dokumen/".$dokumen."' target='_blank'>Download</a></td>";
						echo "</tr>";
					}
				}
			?>
        	</tbody>
          </table>
          </div>
             <form action="<?php echo $base?>tabel-agenda-surat.php" method="post" style="float:right; margin-right:10px;" target="_blank">
                <input type="hidden" name="beranda" value="<?php echo $beranda?>" />
                <input type="hidden" name="status" value="2" />
                <input type="hidden" name="tglAwal" value="<?php echo $tglAwal?>" />
                <input type="hidden" name="tglAkhir" value="<?php echo $tglAkhir?>">
            	<button type="submit" class="btn btn-success" id="OK" style="margin-top:20px;"> <i class="glyphicon glyphicon-print"></i> Export Data</button>
             </form>
              <form action="<?php echo $base?>laporan-agenda-surat.php" method="post" style="float:right; margin-right:10px;" target="_blank">
                <input type="hidden" name="beranda" value="<?php echo $beranda?>" />
                <input type="hidden" name="status" value="1" />
                <input type="hidden" name="tglAwal" value="<?php echo $tglAwal?>" />
                <input type="hidden" name="tglAkhir" value="<?php echo $tglAkhir?>">
            	<button type="submit" class="btn btn-default" id="OK" style="margin-top:20px;"> <i class="glyphicon glyphicon-print"></i> Cetak Data</button>
             </form>

          <a style="float:right; margin-top:20px; margin-right:10px;"  href="<?php echo $base?>laporan-form-kosong.php" class="btn btn-default" target="_blank">
            <i class="glyphicon glyphicon-print"></i>
            Form Kosong
          </a>
          <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="beranda">
                        <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>
                        </div>
                     </div>
                </div>
            </div>
          </div>
          
          
        </div><!-- /.box-body -->
      </div><!-- /.box -->
    </div><!-- /.col -->
  </div><!-- /.row -->
  
</section>
 
