<div>
	<h4>Tahapan Perolehan</h4>

	<!-- <div class="tab">
		<button class="tablinks" onclick="openCity(event, 'London')" id="defaultOpen">Survey/Koordinasi Awal</button>
		<button class="tablinks" onclick="openCity(event, 'Paris')">KKPR</button>
		<button class="tablinks" onclick="openCity(event, 'Tokyo')">Pertimbangan Teknis</button>
	</div> -->

    <!-- Add Progres -->
    <div id="addProgres" class="modal fade" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <center><h4 class="modal-title"> Tambah Progres</h4></center>
                </div>

                <div class="modal-body">
                    <form action="<?= base_url('perolehan/progres_act');?>" method="post" enctype="multipart/form-data">		
                        <div class="form-group" style="width:100%">
                            <label style="width: 100%;"> Progres</label>		
                            <input type="hidden" name="perolehan_id" value="<?=$perolehan->perolehan_id?>">
                            <select class="form-control" name="nama" required style="width: 100%;">
                                <option value="">--Pilih Progres--</option>
                                    <?php 
                                        $pr = $this->db->query("select * from master_progres_status")->result();
                                        foreach ($pr as $d) {
                                    ?>
                                        <option value="<?php echo $d->progres_status_desc ?>"><?php echo $d->progres_status_desc ?></option>
                                    <?php
                                        }
                                    ?>													
                            </select>
                        </div>

                        <div class="form-group" style="width:100%">
                            <label style="width: 100%;"> Tanggal</label>		
                            <input type="date" name="tgl_progres" required class="form-control" style="width:100%">
                        </div>

                        <div class="form-group" style="width:100%">
                            <label style="width: 100%;"> Keterangan</label>		
                            <textarea name="ket_progres" class="form-control" cols="84" rows="5" required></textarea>
                        </div>
                                                                                
                        <br>
                        <div style="height:20px;"></div>
                        <input type="submit" value="Simpan" class="btn btn-primary">
                    </form>
                </div>											
            </div>
        </div>
    </div>

    <div class="tab">
        <?php
            $tahapans = $this->db->query('SELECT * FROM master_perolehan_status ORDER BY tahapan;')->result();

            foreach($tahapans as $tahapan){
        ?>
            <button class="tablinks" onclick="openCity(event, '<?= $tahapan->perolehan_status_id;?>')" <?php if($tahapan->tahapan == 1){echo 'id="defaultOpen"';} ?>><?= $tahapan->perolehan_status_nama;?></button>
        <?php
            }
        ?>
    </div>
    
    <?php
        foreach($tahapans as $tahapan){
    ?>
        <div id="<?= $tahapan->perolehan_status_id;?>" class="tabcontent">
            <center>
                <h4><?= $tahapan->perolehan_status_nama;?></h4>
            </center>

            <?php 
                if(isset($_GET['alert'])){
                    if($_GET['alert'] == "sukses"){
                        echo "<div class='alert alert-success'>Password telah diubah!</div>";
                    }else if($_GET['alert'] == "gagal"){
                        echo "<div class='alert alert-danger'>Maaf, password lama yang anda masukkan salah!</div>";
                    }
                }

                foreach($progres as $p){
                
                if($p->perolehan_status_id == $tahapan->perolehan_status_id){
            ?>
                <div class="table-responsive">
                    <table class="table" style="border : 2px solid #3c8dbc;">
                        <thead>
                            <tr>
                                <td>
                                    <strong><?=$p->perolehan_kegiatan_desc;?></strong>
                                </td>
                                <td width="15%">
                                    <h4 class="pull-right">
                                        <button type="button" class="btn btn-success btn-sm" title="Edit" data-toggle="modal" data-target="#editProgres<?php echo $p->progres_id ?>"><i class="fa fa-pencil"></i> </button>
                                        <button type="button" class="btn btn-danger btn-sm" title="Hapus" data-toggle="modal" data-target="#hapusData<?php echo $p->progres_id ?>"><i class="fa fa-trash"></i> </button>
                                    </h4>
                                </td>
                            </tr>
                            <tr>
                                <?php
                                    

                                    if (!empty($p->tgl_akhir)) {
                                        $tglAkhir = date("d-m-Y", strtotime($p->tgl_akhir));
                                    }else {
                                        $tglAkhir = "Sekarang";
                                    }

                                    $tglAwal = date("d-m-Y", strtotime($p->tgl_awal));
                                ?>
                                <td colspan=2>
                                    <p><?= $tglAwal.' s/d '.$tglAkhir?></p>
                                </td>
                            </tr>
                            <tr>
                                <td colspan=2>
                                    <u>Keterangan :</u>
                                    <p><?= $p->progres_ket;?></p>
                                </td>
                            </tr>
                        </thead>
                    </table>
                </div>
                <br>

                <!-- Edit Progres -->
                <div id="editProgres<?=$p->progres_id?>" class="modal fade" role="dialog">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal">&times;</button>
                                <center><h4 class="modal-title"> Edit Progres</h4></center>
                            </div>

                            <div class="modal-body">
                                <form action="<?= base_url('perolehan/progres_update');?>" method="post" enctype="multipart/form-data">		

                                    <div class="form-group" style="width:100%; margin-bottom:10px;">
                                        <label style="width: 100%;">Tahapan Perolehan</label>		
                                        <select class="form-control" id="status_perolehan_progres<?=$p->progres_id;?>" onchange="changeKegiatanProgres(<?=$p->progres_id;?>)" name="status" required style="width: 100%;">
                                            <option value="">--Pilih Tahapan Perolehan--</option>
                                            <?php 
                                                $statuse = $this->db->query("select * from master_perolehan_status")->result();
                                                foreach ($statuse as $stpe) {
                                            ?>
                                            <option value="<?php echo $stpe->perolehan_status_id;?>" <?php if($stpe->perolehan_status_id == $p->perolehan_status_id){echo "selected";} ?>><?php echo $stpe->perolehan_status_nama; ?></option>
                                            <?php
                                                }
                                            ?>													
                                        </select>
                                    </div>

                                    <div class="form-group" style="width:100%; margin-bottom:10px;">
                                        <label style="width: 100%;">Kegiatan</label>	
                                        <input type="hidden" name="id" value="<?=$p->progres_id?>">
                                        <input type="hidden" name="perolehan_id" value="<?=$p->perolehan_id?>">	
                                        <select class="form-control" id="kegiatan_perolehan_progres<?=$p->progres_id;?>" name="kegiatan" required style="width: 100%;">
                                            <option value="">--Pilih Kegiatan--</option>
                                            <?php 
                                                $kegiatane = $this->db->query("select * from master_perolehan_kegiatan where perolehan_status_id = '$p->perolehan_status_id'")->result();
                                                foreach ($kegiatane as $kge) {
                                            ?>
                                            <option value="<?php echo $kge->perolehan_kegiatan_id;?>" <?php if($kge->perolehan_kegiatan_id == $p->perolehan_kegiatan_id){echo "selected";} ?>><?php echo $kge->perolehan_kegiatan_desc; ?></option>
                                            <?php
                                                }
                                            ?>		
                                        </select>
                                    </div>

                                    <div class="form-group" style="width:100%; margin-bottom:20px;">
                                        <?php
                                            $tglAwalE = date("Y-m-d", strtotime($p->tgl_awal));
                                            $tglAkhirE = date("Y-m-d", strtotime($p->tgl_akhir));
                                        ?>
                                        <div class="col-sm-6">
                                            <label style="width: 100%;"> Tanggal Mulai</label>		
                                            <input type="date" name="tgl_awal" value="<?=$tglAwalE?>" required class="form-control" style="width:100%">
                                        </div>

                                        <div class="col-sm-6">
                                            <label style="width: 100%;"> Tanggal Selesai</label>		
                                            <input type="date" name="tgl_akhir" value="<?=$tglAkhirE?>" required class="form-control" style="width:100%">
                                        </div>
                                    </div>

                                    <div class="form-group" style="width:100%">
                                        <label style="width: 100%;"> Keterangan</label>		
                                        <textarea name="ket_progres" class="form-control" cols="84" rows="5" required><?=$p->progres_ket?></textarea>
                                    </div>
                                                                                    
                                    <br>
                                    <div style="height:20px;"></div>
                                    <input type="submit" value="Simpan" class="btn btn-primary">
                                </form>
                            </div>											
                        </div>
                    </div>
                </div>

                <!-- Hapus progres -->
                <div id="hapusData<?=$p->progres_id?>" class="modal fade" role="dialog">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                                <h5 class="modal-title" id="exampleModalLabel">Peringatan!</h5>
                            </div>
                            <div class="modal-body">
                                <p>Yakin ingin menghapus data ini ?</p>
                            </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
                            <a href="<?php echo base_url().'Perolehan/progres_hapus/'.$p->progres_id; ?>" class="btn btn-primary">Hapus</a>
                        </div>
                    </div>
                </div>
            </div>

            <?php
                }
                }
            ?>

	    </div>
    <?php
        }
    ?>

</div>