<script type="text/javascript" src="<?php echo base_url();?>resources/js/jquery.simplePagination.js"></script>
<div id="popup_kepailitan_list" class="centering" style="width:100%;margin-top: 1%;background:white;">
	<div style="margin:3px;clear:both;"></div>
	<hr class="thick-line" style="clear:both;">
	<div id="left">
		<?php
		$attributes = array('id' => 'form_search_pihak');
		echo form_open(base_url().'penyegelan_list/searchPage',$attributes);
		?>
		<?php
		$attributes = array('name' => 'keyword_pihak', 'id' => 'search-box', 'type' => 'text','size' => '50','placeholder'=>"  Ketik kata kunci  ");
		echo form_input($attributes);
		$data = array(
			'enc' => "enc"
		);
		echo form_hidden($data);
		echo "<span>  </span>";
		$attributes = array('value' => 'Search', 'class' => 'btn', 'id' => 'search-btn1', 'type' => 'submit');
		echo form_submit($attributes);
		echo form_close('');
		?>
	</div>
	<div id="left" style="margin-left:50px;">
		<?php 
		if($this->session->userdata('is_logged_in')){
			if($this->authorization->HasRuleAddPendaftaran($idalurperkara)){ ?>
			<input type="button" id='addPihak' value="Tambah" class="btn"></div>
			<?php }
		} ?>
	<div id="pages" >
    	<div id="selector" style="padding: 4px 5px 5px 0;"></div>
    </div>
	<div class="cssTable">
		<table id="tablePerkaraAll">
			<col  width="3%" />
			<col  width="15%" />
			<col  width="18%" />
			<col  width="15%" />
			<col  width="16%" />
			<col  width="15%" />
			<col  width="15%" />
			<col  width="4%" />
        	<tbody>
				<tr>
					<td onclick="sorting(7)">No</td>
					<td onclick="sorting(1)">Nomor Perkara</td>
					<td onclick="sorting(2)">Para Pihak</td>
					<td onclick="sorting(3)">Tanggal Penetapan Penyegelan</td>
					<td onclick="sorting(4)">Tanggal Pelaksanaan Penyegelan</td>
					<td onclick="sorting(5)">Jenis Barang</td>
					<td onclick="sorting(6)">Disita Dari</td>
					<td></td>
				</tr>
				<?php
				if($penyegelan!=''){
					$i=$page_active+1;
					if($penyegelan->num_rows>0){
						foreach ($penyegelan->result() as $row) {

								#$ttl .= $this->tanggalhelper->convertDate($row->tanggal_lahir);						
							echo "<tr>";
							#echo "<td style='text-align:center;'><a href='#' onClick='pilih(\"".base64_encode($this->encrypt->encode($row->id))."\")'>[Pilih]</a></td>";
							#echo "<td style='text-align:center;'><a href='#' onClick='edit(\"".base64_encode($this->encrypt->encode($row->id))."\")'>[Edit]</a></td>";
								echo "<td>".$row->nomor_urut_register."</td>";
								echo "<td>".$row->nomor_perkara."</td>";
								echo "<td style='text-overflow: ellipsis;white-space: nowrap;overflow: hidden;'>".$row->para_pihak."</td>";
								echo "<td>".$this->tanggalhelper->convertDate($row->penetapan_penyegelan)."</td>";
								echo "<td>".$this->tanggalhelper->convertDate($row->pelaksanaan_penyegelan)."</td>";
								echo "<td>".$row->jenis_barang."</td>";
								echo "<td>".$row->disita_dari."</td>";
								echo "<td style='text-align:center;'>
									<a href='#' onClick='popup_form(\"".base_url('managePenyegelan/viewDetil/'.base64_encode($this->encrypt->encode($row->perkara_id)))."\")'>[Detil]</a>
									<a href='#' onClick='edit(\"".base64_encode($this->encrypt->encode($row->perkara_id))."\")'>[Edit]</a></td>";
							echo "</tr>";
							$i++;
						}
					}
				}
				?>
			</tbody>
		</table>
	</div>
	<div id="pages_bottom" style="width:100%;padding-left:5px;padding-top:5px;">
    	<div id="selector_bottom"></div>
	</div>
	<div style="margin:bottom:5px;"></div>
</div>
<div id="popup_kepailitan" class="popup">
	<div style="margin: 0 auto;top: 50%;margin-top: 1%;margin-bottom: 25px;">
	<div style="border: 1px solid #ffffff;width: 30%;margin: 0 auto;">
	<div class="detil" style="padding: 2px;background-color: white;">
			<form id="frm_ref_penyitaan" style="background:white;margin:0;" method="post" action="<?php echo base_url().'managePenyegelan/validateInput';?>">
				<table id="tableDetilPerkara" style="font-size:14px;width:100%;">
				<col width="50%">
				<col width="50%">
					<tbody>
						<tr>
							<td colspan="2" style='text-align:center;background:white;border:0px;font-size: 20px;color: #648C03;'>TAMBAH REGISTER PENYEGELAN</td>
						</tr>
						<tr>
							<td>Nomor Urut <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='no_urut' name='no_urut' value="" class="standard-input" maxlength="5">
							</td>
						</tr>
						<tr>
							<td>Nomor Perkara <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input list="no_perkara_list" type="text" id='no_perkara' name='no_perkara' value="" class="standard-input" maxlength="200">
								<datalist id="no_perkara_list" style="height:200px;overflow:scroll;">
									<?php
									if($list_perkara!=''){
										if($list_perkara->num_rows>0){
											foreach ($list_perkara->result() as $row) {
												echo '<option data-id="'.base64_encode($this->encrypt->encode($row->perkara_id)).'" value="'.$row->nomor_perkara.'">'.$row->nomor_perkara.'</option>';
											}
										}
									}
									?>
								</datalist>
							</td>
						</tr>
						<tr id="tr_parapihak">
							<td>Para Pihak <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;" id='parapihak'></td>
						</tr>
						<tr>
							<td>Tanggal Penetapan Penyegelan <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input id="pen_segel" name="pen_segel" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td>Tanggal Pelaksanaan Penyegelan</td>
							<td style="padding:0px;padding-left:5px;">
								<input id="pel_segel" name="pel_segel" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td>Jenis Barang<font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='jenis_barang' name='jenis_barang' value="" class="standard-input" maxlength="200">
							</td>
						</tr>
						<tr>
							<td>Disita Dari <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<textarea id="disita_dari" name="disita_dari" class="standard-input" style="width: 245px; height: 70px;resize: none;"></textarea>
							</td>
						</tr>
						<tr>
							<td>Penyimpanan Barang<font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<textarea id="penyimpanan_barang" name="penyimpanan_barang" class="standard-input" style="width: 245px; height: 70px;resize: none;"></textarea>
							</td>
						</tr>
						
						<tr>
							<td>Penetapan Pengangakatan Penyegelan</td>
							<td style="padding:0px;padding-left:5px;">
								<input id="pen_pengangkatan_segel" name="pen_pengangkatan_segel" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td>Pelaksanaan Pengangakatan Penyegelan</td>
							<td style="padding:0px;padding-left:5px;">
								<input id="pel_pengangkatan_segel" name="pel_pengangkatan_segel" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
								<input type="hidden" id="curr_date" value="<?php echo $curr_date;?>">
								<input type="hidden" id="enc" name="enc" value="">
								<input type="hidden" id="refresh" value="0">
								<input type="hidden" id="enc_act" name="enc_act" value="<?php echo $enc_act;?>">
							</td>
						</tr>
						<tr>
							<td>Keterangan</td>
							<td style="padding:0px;padding-left:5px;border:0px;">
								<textarea id="keterangan" name="keterangan" class="standard-input" style="width: 245px; height: 70px;resize: none;"></textarea>
							</td>
						</tr>
						<tr>
								<td colspan="2" style="background:white;" align="center">
								<input type="button" id='back_pihak' value="Kembali" class="btn">
								<?php
								#if($this->authorization->isAuthorized('hakim_pn_edit',$AuthorizationForm)){
								?>
								<?php
								echo '<input type="submit" id="hapus" value="Hapus" class="del_btn" onclick="return false;">';
								?>
									<input type="submit" id="simpan_btn" value="Simpan" class="btn">
								<?php
								#}
								?>
							</td>
							</tr>
					</tbody>
				</table>
			</form>
		</div>
	</div>
</div>
</div>
<script type="text/javascript">
$('#close_form_2nd').closingForm2ndWin();
var act = 'add';
$('#no_perkara').change(function() {
	var np = $('#no_perkara').val();
    var val = $('#no_perkara_list option').filter(function() {
        return this.value == np;
    }).data('id');
	if(np==''){
		message_error_show('Nomor Perkara Wajib Diisikan');
		$('#no_perkara').css("background-color", "red");
		return
	}else{
		$('#no_perkara').css("background-color", "#dedbdb");
	}
	openLoadingDialog()
	$.post('<?php echo base_url()?>managePenyegelan/fetchData', {
		val:val,
		act:act
	}, function(response){
		var json = jQuery.parseJSON(response);
		closeLoading()
		if(json.st==1){
			$('#parapihak').remove();
			$("#tr_parapihak").append(json.parapihak);
			$('#enc').val(json.enc);
			$('#enc_act').val(json.enc_act);
		}else if(json.st==0){
			clearInput();
			message_error_show(json.msg);
		}
	});
});


function clearInput(){
	$('#parapihak').text('');
	$('#no_perkara').val('');
	$('#pen_segel').val('');
	$('#pel_segel').val('');
	$('#jenis_segel').val('');
	$('#jenis_barang').val('');
	$('#disita_dari').val('');
	$('#penyimpanan_barang').val('');
	$('#pen_pengangkatan_segel').val('');
	$('#pel_pengangkatan_segel').val('');
	$('#keterangan').val('');
}
$("#back_pihak").click(function() {
	$('#popup_kepailitan_list').fadeIn();
	clearInput();
	$('#popup_kepailitan').fadeOut();
    $("body").css({overflow: 'hidden'});
    if($("#refresh").val()==1){
    	window.open('<?php echo $url_requested;?>','_self')
    }
});


$('#frm_ref_penyitaan').SubmitHandling({
	refresh:'1',
	setRefresh:0,
	clicked:1,
	btnClicked:'#back_pihak',
	whenStatus:1
});

$('#hapus').ButtonClickHandling({
	refresh:'1',
	setRefresh:0,
	divRef:'#konten',
	clicked:1,
	btnClicked:'#back_pihak',
	whenStatus:1,
	actions:'<?php echo base_url()?>managePenyegelan/validateDelete',
	formName:'#frm_ref_penyitaan',
	actionName:'Menghapus Data'
});

function clearAll(){
	$('#popup_pihak :input').not('.btn').not('#curr_date').val('');
	$('#popup_pihak .hidden').hide();
	$('#kepailitan_jenis_pihak').val(1);
	$('#kepailitan_warga_negara').val(98);
}


function edit(val){
	if(val==""){
		message_show("Error <br/> Refresh Browser Anda");
		return;
	}

	openLoadingDialog()
	$.post('<?php echo base_url()?>managePenyegelan/fetchData', {
		val:val,
		act:'updt'
	}, function(response){
		var json = jQuery.parseJSON(response);
		closeLoading()
		if(json.st==1){
			$('#no_perkara').prop('readonly', true);
			//$('#no_perkara_list').prop('readonly', true);
			$('#no_perkara').css("background-color", "#26CFDD");
			$('#hapus').show();
			$('#parapihak').remove();
			$("#tr_parapihak").append(json.parapihak);
			$('#enc').val(json.enc);
			$('#enc_act').val(json.enc_act);
			$('#no_perkara').val(json.no);
			$('#no_urut').val(json.noUrut);
			$('#pen_segel').val(json.penSegel);
			$('#pel_segel').val(json.pelSegel);
			$('#jenis_barang').val(json.jeniBarang);
			$('#disita_dari').val(json.disita);
			$('#penyimpanan_barang').val(json.penyimpanan);
			$('#pen_pengangkatan_segel').val(json.penPengakatan);
			$('#pel_pengangkatan_segel').val(json.pelPengangkatan);
			$('#keterangan').val(json.catatatn);
			$('#popup_kepailitan').fadeIn();
			act = 'updt';
			$("body").css({overflow: 'hidden'});
			return
		}else if(json.st==0){
			message_show(json.msg);
		}
	});
	
}
$("#addPihak").click(function() {
	openLoadingDialog()
	$.post('<?php echo base_url()?>managePenyegelan/fetchNoUrut', {
		act:'add'
	}, function(response){
		var json = jQuery.parseJSON(response);
		closeLoading()
		if(json.st==1){
			$('#no_urut').val(json.noUrut);
		}else if(json.st==0){
			clearAll();
			message_error_show(json.msg);
			return
		}
	});

	clearAll();
	$('#no_perkara').prop('readonly', false);
	//$('#no_perkara_list').prop('readonly', false);
	$('#no_perkara').css("background-color", "white");
	$('#popup_kepailitan_list').fadeOut();
	$('#popup_kepailitan').fadeIn();
	$('#hapus').hide();
	$('#act').val('add');
	act = 'add';
    $("body").css({overflow: 'hidden'});
});

$('#form_search_pihak').submit(function(event){
	openLoadingDialog()
    $.post($(this).attr('action'),$(this).serialize(), function(json){
    	closeLoading()
    	if(json.st==1){
    		window.open('<?php echo base_url()?>penyegelan_list','_self');
    	}else{
    		message_show("Error, Tutup Browser anda kemudian login kembali");
    	}
    	event.preventDefault()
	},'json');
	event.preventDefault()
});
</script>
<script language="javascript">
$(function() {
    var totalPage = '<?php echo $total_rows; ?>';
    var page = '<?php echo $page_number;?>';
    $('#selector').pagination({
        items: totalPage,
        itemsOnPage: 50,
        displayedPages: 3,
        cssStyle: 'light-theme',
        currentPage:page,
        onPageClick: function(pageNumber){
        	openLoadingDialog()
        	$.post('<?php echo base_url()?>penyegelan_list/setPage', {
        		pageNumber:pageNumber,
        		keyword:$('#keyword_pihak').val()
			}, function(response){
				var json = jQuery.parseJSON(response);
				closeLoading()
				if(json.st==1){
					refreshPihakList()
				}else{
					message_show("Error, Tutup Browser anda kemudian login kembali");
				}
			});
            
        	}
        });
    $('#selector_bottom').pagination({
        items: totalPage,
        itemsOnPage: 50,
        displayedPages: 3,
        cssStyle: 'light-theme',
        currentPage:page,
        onPageClick: function(pageNumber){
            openLoadingDialog()
        	$.post('<?php echo base_url()?>penyegelan_list/setPage', {
        		pageNumber:pageNumber,
        		keyword:$('#keyword_pihak').val()
			}, function(response){
				var json = jQuery.parseJSON(response);
				closeLoading()
				if(json.st==1){
					refreshPihakList()
				}else{
					message_show("Error, Tutup Browser anda kemudian login kembali");
				}
			});
            
        	}
        });
    $('#pen_segel').datepicker({
            inline: true,
            showOtherMonths: true,
            dateFormat: 'dd/mm/yy',
            dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
            beforeShowDay: $.datepicker.noWeekends,
            onSelect: function(dateText, inst) {
            	var tmp = $(this).val().split("/");
				var tmp2 = $('#curr_date').val().split("/");
				if((new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T00:00:00").getTime() > new Date(tmp2[2]+"-"+tmp2[1]+"-"+tmp2[0]+"T00:00:00").getTime())){
					message = 'Tidak Dapat Memilih Melebihi Hari ini. Sekarang Tanggal '+$('#curr_date').val();
					message_show(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
        	}
      	});

    });
	
	$('#pel_segel').datepicker({
		inline: true,
		showOtherMonths: true,
		dateFormat: 'dd/mm/yy',
		dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
		beforeShowDay: $.datepicker.noWeekends
    });


	$('#pen_pengangkatan_segel').datepicker({
            inline: true,
            showOtherMonths: true,
            dateFormat: 'dd/mm/yy',
            dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
            beforeShowDay: $.datepicker.noWeekends,
      });

	$('#pel_pengangkatan_segel').datepicker({
		inline: true,
		showOtherMonths: true,
		dateFormat: 'dd/mm/yy',
		dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
		beforeShowDay: $.datepicker.noWeekends
    });

$('.datepicker').ValidateDateInput();

</script>
