<div class="centering" style="width:100%;margin-top: 1%;">
<hr class="thick-line" style="clear:both;">
<?php 
if(!empty($nomor_perkara))
{
?><table id='infoPerkara' style="width:100%;margin-left: 5px;margin-bottom:-15px;margin-top:-15px;">
	<tr>
	<td colspan='2'><a style="color:#259FD3;text-decoration: none;" href="<?php echo $previous; ?>" class="btn btn-default btn-sm"><i class="fa fa-reply-all"></i> Kembali</a></td>
	</tr>
</table>
<hr class="thick-line" style="clear:both;">
    <div id='pihak_penahanan_detil' >
            <table id='infoPerkara' style="width:100%;margin-left: 5px;">
            		<col width="15%">
                    <col width="85%">
            		<tr>
            			<td id="first-child">Nomor Perkara </td>
            			<td>
            				<?php echo $nomor_perkara; ?>
            			</td>	
            		</tr>
            		<tr>
            			<td id="first-child">Nama</td>
            			<td>
            				<?php echo $pihak_detail['nama']; ?>
            			</td>	
            		</tr>      
                    <?php if ($this->session->userdata('jenis_pengadilan')=='2'){ ?>
                    <tr>
                        <td id="first-child">NRP</td>
                        <td>
                            <?php echo $pihak_detail['nrp']; ?>
                        </td>   
                    </tr>
                    <tr>
                        <td id="first-child">Pangkat</td>
                        <td>
                            <?php echo $pihak_detail['pangkat']; ?>
                        </td>   
                    </tr>
                    <tr>
                        <td id="first-child">Jabatan</td>
                        <td>
                            <?php echo $pihak_detail['jabatan']; ?>
                        </td>   
                    </tr>
                    <tr>
                        <td id="first-child">Kesatuan</td>
                        <td>
                            <?php echo $pihak_detail['kesatuan']; ?>
                        </td>   
                    </tr>
                    <?php
                    }
                    ?>          
            		<tr>
            			<td id="first-child">Tempat Lahir</td>
            			<td>
            				<?php echo $pihak_detail['tempat_lahir']; ?>
            			</td>	
            		</tr>
            		<tr>
            			<td id="first-child">Tanggal Lahir</td>
            			<td>
            				<?php echo $pihak_detail['tanggal_lahir']; ?>
            			</td>	
            		</tr>
            		<tr>
            			<td id="first-child">Umur</td>
            			<td>
            				<?php echo $pihak_detail['umur']; ?>
            			</td>	
            		</tr>
            		<tr>
            			<td id="first-child">Jenis Kelamin</td>
            			<td>
            				<?php if ($pihak_detail['jenis_kelamin']=='L'){echo 'Laki-laki';}else{echo 'Perempuan';}; ?>
            			</td>	
            		</tr>
            		<tr>
            			<td id="first-child">Warga Negara</td>
            			<td>
            				<?php echo $pihak_detail['warga_negara']; ?>
            			</td>	
            		</tr>
            		<tr>
            			<td id="first-child">Alamat</td>
            			<td>
            				<?php echo $pihak_detail['alamat']; ?>
            			</td>	
            		</tr>
            		<tr>
            			<td id="first-child">Agama</td>
            			<td>
            				<?php echo $pihak_detail['agama']; ?>
            			</td>	
            		</tr>
            		<tr>
            			<td id="first-child">Pekerjaan</td>
            			<td>
            				<?php echo $pihak_detail['pekerjaan']; ?>
            			</td>	
            		</tr>
            		<tr>
            			<td id="first-child">Dakwaan</td>
            			<td>
            				<?php echo ($dakwaan[0]->dakwaan); ?>
            			</td>	
            		</tr>
                </table>
                <!--<div style='padding:10px;'></div>-->
				<hr class="thick-line" style="clear:both;">
                <div id="pageTitle" style="width:100%;text-align:center;margin-top:-18px"><strong>DATA PENAHANAN</strong></div>
            	<div class="cssTable">
	            	<table>
	            		<col width="3%">
                    	<col width="11%">
                    	<col width="24%">
                    	<col width="10%">
                    	<col width="8%">                    	
                    	<col width="8%">
                    	<col width="8%">
                    	<col width="18%">
                        <?php if ($add){
                                echo '<col width="5%">';
                            };
                        ?>
                    	
	            		<tr>
	            			<td>No</td>
	            			<td>Status Penahanan</td>
	            			<td>Oleh</td>
	            			<td>Jenis Tahanan</td>	            			
	            			<td>Mulai</td>
	            			<td>Sampai</td>
	            			<td>Jumlah<br>(Hari)</td>
							<td>Cetak Dokumen</td>
                            <?php if ($this->authorization->HasRuleEditPenahanan($id_perkara)){
                                    echo '<td>Edit</td>';
                                }
                            ?>
	            		</tr>
	            		<?php
                            $i=0;
                            $tgl_mulai_sebelumnya='';
                            $list=$detail_penahanan;
                            foreach ($detail_penahanan as $row) {
                                $x=$i;
                                if(++$i === count($list)) {
                                    $list[$x]->fix_lama_penahanan = $row->lama_penahanan;
                                }else{
                                    $selisih=$this->tanggalhelper->getSelisihHari($row->mulai,$list[$i]->mulai);     
                                    if ($selisih ==($row->lama_penahanan+1)){
                                        $selisih = $row->lama_penahanan;
                                    }
                                    $list[$x]->fix_lama_penahanan = $selisih;
                                    //echo $list[$i]->mulai.' - '.$row->mulai.' = '.$this->tanggalhelper->getSelisihHari($row->mulai,$list[$i]->mulai).' *** ';
                                }
                            }
	            			$i=1;
	            			foreach ($list as $row) {
                                $enctahan=base64_encode($this->encrypt->encode($row->id));
                                $encpihak=base64_encode($this->encrypt->encode($row->pihak_id));
								if (empty($row->nomor_surat)){
									$nomor_surat="-";
									$atur="center";
								}else{
									$nomor_surat=$row->nomor_surat;
									$atur="left";
								}
								if ($row->status_penahanan_id==5 OR $row->status_penahanan_id==3 OR $row->status_penahanan_id==2){
									$jumlahari="-";
								}
								else{
									$jumlahari=$row->fix_lama_penahanan."&nbsp;dari&nbsp;".$row->lama_penahanan;
								}
	            				echo "<tr>";
	            				echo "<td align='center'>".$i."<input type='hidden' value='".base64_encode($this->encrypt->encode($row->id))."'/></td>";
	            				echo "<td>".$row->status_penahanan."</td>";
								echo "<td>".$row->ditahan_oleh;
                                    if($row->status_penahanan_id==1 AND (!empty($row->nomor_surat) OR (!empty($row->tanggal_surat) AND $row->tanggal_surat!="0000-00-00") )){
                                            echo "<br><br><font color='#259FD3'>Nomor Surat Penahanan</font><br>".$nomor_surat;
                                            echo "<br><font color='#259FD3'>Tanggal Surat</font><br>".$this->tanggalhelper->convertDate($row->tanggal_surat);
                                    }
                                echo "</td>";
	            				echo "<td>".$row->jenis_tahanan."</td>";	            				
	            				echo "<td align='center'>".$this->tanggalhelper->convertDate($row->mulai)."</td>";
	            				echo "<td align='center'>".$this->tanggalhelper->convertDate($row->sampai)."</td>";
	            				echo "<td align='center'>".$jumlahari."</td>";
	            				?>
                                    <td >
                                    <?php                                                                               
									if ((($row->jenis_penahanan_id==3)||($row->jenis_penahanan_id==5)||($row->jenis_penahanan_id==7)||($row->jenis_penahanan_id==8)||($row->jenis_penahanan_id==9)||($row->jenis_penahanan_id==22)||($row->jenis_penahanan_id==23)||($row->jenis_penahanan_id==24)||($row->jenis_penahanan_id==31)) ){
									?>
                                        <span class="custom-dropdown custom-dropdown--emerald">
                                            <select onchange="pilih_cetak(this,'<?php echo $enctahan; ?>')" style="width:210px;height: 29px;z-index:99999;" class="custom-dropdown__select custom-dropdown__select--white">
												<option value='1'>Pilih Dokumen Penahanan</option>
										<?php 
                                        if (($row->jenis_penahanan_id == 7)&&($row->status_penahanan_id==1)){
                                            if($alur_perkara_id==111 OR $alur_perkara_id==112 OR $alur_perkara_id==113 OR $alur_perkara_id==115){ 
                                                // echo '<option value="cetak">Penetapan Penahanan Hakim PN</option>';
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_penahanan_hakim_pn/".$enc."/".$enctahan."/".$encpihak."/1").'">Penetapan Penahanan Hakim PN</option>';
                                            }elseif($alur_perkara_id==116){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_penahanan_hakim_pn/".$enc."/".$enctahan."/".$encpihak."/2").'">Penetapan Penahanan Hakim PN</option>';
                                            }elseif($alur_perkara_id==117){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_penahanan_hakim_pn/".$enc."/".$enctahan."/".$encpihak."/3").'">Penetapan Penahanan Hakim PN</option>';
                                            }elseif($alur_perkara_id==118){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_penahanan_hakim_pn/".$enc."/".$enctahan."/".$encpihak."/4").'">Penetapan Penahanan Hakim PN</option>';
                                            }
										} 
                                        if($alur_perkara_id!=118){
    										if (($row->jenis_penahanan_id >= 7)&&($row->status_penahanan_id==3)){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_pembantaran_penahanan/".$enc."/".$enctahan."/".$encpihak).'">Penetapan Pembantaran Penahanan</option>';
    										} 										
    										if (($row->jenis_penahanan_id >= 7)&&($row->status_penahanan_id==4)){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_penangguhan/".$enc."/".$enctahan."/".$encpihak."/1").'">Penetapan Penangguhan Penahanan Dengan Jaminan Orang</option>';
    										}
    										if (($row->jenis_penahanan_id >= 7)&&($row->status_penahanan_id==4)){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_penangguhan/".$enc."/".$enctahan."/".$encpihak."/2").'">Penetapan Penangguhan Penahanan Dengan Jaminan Uang</option>';
    										}
    										if (($row->jenis_penahanan_id >= 7)&&($row->status_penahanan_id==4)){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_penangguhan/".$enc."/".$enctahan."/".$encpihak."/3").'">Penetapan Penangguhan Penahanan Tanpa Jaminan</option>';
    										}
    										if (($row->jenis_penahanan_id==3)){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_penolakan_perpanjangan_tahanan/".$enc."/".$enctahan."/".$encpihak."/1").'">Penetapan Penolakan Perpanjangan Tahanan Penyidik Pasal 29</option>';
    										}
    										if (($row->jenis_penahanan_id==5)){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_penolakan_perpanjangan_tahanan/".$enc."/".$enctahan."/".$encpihak."/2").'">Penetapan Penolakan Perpanjangan Tahanan Penuntut Pasal 29</option>';
    										}
    										if (($row->jenis_penahanan_id == 7)&&($row->status_penahanan_id==1)){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_pengalihan_penahanan_permohonan/".$enc."/".$enctahan."/".$encpihak."/1").'">Penetapan Pengalihan Penahanan Dengan Permohonan</option>';
    										} 
    										if (($row->jenis_penahanan_id == 7)&&($row->status_penahanan_id==1)){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_pengalihan_penahanan_permohonan/".$enc."/".$enctahan."/".$encpihak."/2").'">Penetapan Pengalihan Penahanan Tanpa Permohonan</option>';
    										} 
    										if ($row->jenis_penahanan_id==8){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_perpanjangan_penahanan/".$enc."/".$enctahan."/".$encpihak."/1").'">Penetapan Perpanjangan Penahanan Oleh KPN</option>';
    										} 
    										if ($row->jenis_penahanan_id==3){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_perpanjangan_penahanan/".$enc."/".$enctahan."/".$encpihak."/2").'">Penetapan Perpanjangan Penahanan Penyidik Oleh KPN Pasal 29 ayat 1</option>';
    										} 
    										if ($row->jenis_penahanan_id==3){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_perpanjangan_penahanan/".$enc."/".$enctahan."/".$encpihak."/3").'">Penetapan Perpanjangan Penahanan Penyidik Oleh KPN Pasal 29 ayat 2</option>';
    										} 
    										if ($row->jenis_penahanan_id==5){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_perpanjangan_penahanan/".$enc."/".$enctahan."/".$encpihak."/4").'">Penetapan Perpanjangan Penahanan Penuntut Umum Oleh KPN Pasal 25</option>';
    										} 
    										if ($row->jenis_penahanan_id==5){ 
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_perpanjangan_penahanan/".$enc."/".$enctahan."/".$encpihak."/5").'">Penetapan Perpanjangan Penahanan Penuntut Umum Oleh KPN Pasal 29 ayat 1</option>';
    										} 
    										if ($row->jenis_penahanan_id==5){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_perpanjangan_penahanan/".$enc."/".$enctahan."/".$encpihak."/6").'">Penetapan Perpanjangan Penahanan Penuntut Umum Oleh KPN Pasal 29 ayat 2</option>';
    										} 
    										if ($row->jenis_penahanan_id==9){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_perpanjangan_penahanan/".$enc."/".$enctahan."/".$encpihak."/7").'">Penetapan Perpanjangan Penahanan Hakim Oleh KPT Pasal 29 ayat 1</option>';
    										} 
    										if ($row->jenis_penahanan_id==9){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_perpanjangan_penahanan/".$enc."/".$enctahan."/".$encpihak."/8").'">Penetapan Perpanjangan Penahanan Hakim Oleh KPT Pasal 29 ayat 2</option>';
    										} 
                                            if (($row->jenis_penahanan_id==22) || ($row->jenis_penahanan_id==23) || ($row->jenis_penahanan_id==24)|| ($row->jenis_penahanan_id==31)){
                                                        if($row->status_penahanan_id=='5'){
                                                            echo '<option value="1202004">Pembebasan Tahanan</option>';  
                                                        }else{
                                                            echo '<option value="120221">Penetapan Penahanan</option>';
                                                            echo '<option value="120222">Penetapan Perpanjangan Penahanan</option>';
                                                        }                                                    
                                            } 
    										if ((($row->jenis_penahanan_id==7)||($row->jenis_penahanan_id==8)||($row->jenis_penahanan_id==9))&&($row->status_penahanan_id==1)){
                                                echo '<option value="'.base_url("c_template_penetapan/popup_penetapan_ijin_meninggalkan_atau_keluar_tahanan/".$enc."/".$enctahan."/".$encpihak."/8").'">Penetapan Izin Meninggalkan Atau Keluar Tahanan</option>';
    										} 
                                        }
                                        echo '</select>';
                                        echo '</span>';									
									 }else{
										 echo "Template Tidak Tersedia";
									 }
									
									?>
                                    </td>
                                <?php
                                if ($this->authorization->HasRuleEditPenahanan($id_perkara)){
	            				?>
	            					<td align='center'>
	            						[<a href="#" onClick="popup_form('<?php echo base_url('add_penahanan_detail/'.$perkara_id.'/'.base64_encode($this->encrypt->encode($pihak_id)).'/'.base64_encode($this->encrypt->encode($row->id)));?>')">Edit</a>]
	            				       <?php
                                        if($row->status_penahanan_id=='3'){
                                            echo '<br>[<a href="#" onClick="popup_form(\''.base_url('addPenahanan_c/add_data_template_dibantar/'.$perkara_id.'/'.base64_encode($this->encrypt->encode($pihak_id)).'/'.base64_encode($this->encrypt->encode($row->id))).'\')">Data Dibantar</a>]';
                                        }                                        
                                        if($row->status_penahanan_id=='4'){
                                            echo '<br>[<a href="#" onClick="popup_form(\''.base_url('addPenahanan_c/add_data_template_ditangguhkan/'.$perkara_id.'/'.base64_encode($this->encrypt->encode($pihak_id)).'/'.base64_encode($this->encrypt->encode($row->id))).'\')">Data Ditangguhkan</a>]';
                                        }?>
                                </td>
                                <?php 
                                }
	            				echo "</tr>";
	            				$i++;
	            			};
	            		?>
	            	</table>
                    <?php if (!$dari_dataumum){?>
    	            	<input type="hidden" id="refresh_dest" value="<?php echo $history;?>">
    	            	<input type="hidden" id="refresh" class='detil_penahanan_refresh' value="0">
                    <?php
						}
                    
                        if ($this->authorization->HasRuleAddPenahanan($id_perkara)){?>
                            [<a style="color:#259FD3;text-decoration: none;" href="#" onClick="popup_form('<?php echo base_url('add_penahanan_detail/'.$perkara_id.'/'.base64_encode($this->encrypt->encode($pihak_id)).'/add');?>')">Tambah</a>]</br>
                    <?php
                        };
                    ?>
	            	
            	</div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
<?php if (!empty($detail_penahanan)){ ?>
	function cetakpenetapanpenahananhakimpn(var1){
	    window.open('<?php echo base_url("c_template_penetapan/cetak_penetapan_penahanan_hakim_pn/".$enc);?>/'+var1+'/<?php echo $encpihak;?>','_self');
	}
    function cetakPenetapanPenahananMil(var1){
        window.open('<?php echo base_url("c_template_pen_mil/popup_penetapan_penahanan_hakim_mil/".$enc);?>/'+var1+'/<?php echo $encpihak."/1";?>','_self');
    }
    function cetakPerpanjanganPenahananMil(var1){
        window.open('<?php echo base_url("c_template_pen_mil/popup_penetapan_penahanan_hakim_mil/".$enc);?>/'+var1+'/<?php echo $encpihak."/2";?>','_self');
    }

    function cetakPembebasaTahananMil(var1){
        window.open('<?php echo base_url("c_template_pen_mil/popup_penetapan_penahanan_hakim_mil/".$enc);?>/'+var1+'/<?php echo $encpihak."/3";?>','_self');
    }


    function pilih_cetak(ele,enctahan){
        if (ele.value=='cetak'){
            cetakpenetapanpenahananhakimpn(enctahan);
        }else if (ele.value=='120221'){
            cetakPenetapanPenahananMil(enctahan);
        }else if (ele.value=='120222'){
            cetakPerpanjanganPenahananMil(enctahan);
        }else if (ele.value=='1202004'){
            cetakPembebasaTahananMil(enctahan);
        }

        else if (ele.value!=1) {
            popup_form(ele.value);
            $(ele).val('1');
        }
    }
    $("#refresh").change(function(){
		if($(this).val()==1){
			var urlRefresh = $('#refresh_dest').val();
			window.open(urlRefresh,'_self')
		}
	});
<?php } ?>
</script>
<?php
}
?>
<script type="text/javascript">
<?php if(empty($nomor_perkara)){?>
	window.open("<?php echo base_url('default');?>","_self");
<?php } ?>
</script>