<script type="text/javascript" src="<?php echo base_url();?>resources/js/jquery.simplePagination.js"></script>
<div id="popup_actio_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().'perkara_actio_pauliana_list/search',$attributes);
		?>
		<?php
		$attributes = array('name' => 'search', '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">
		<?php } 
	} ?>
	</div>
	<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="12%" />
			<col  width="18%" />
			<col  width="13%" />
			<col  width="12%" />
			<col  width="18%" />
			<col  width="12%" />
			<col  width="9%" />
			<col  width="4%" />
        	<tbody>
				<tr>
					<td>No</td>
					<td onclick="sorting(1)">Tanggal Pendaftaran Actio Pauliana</td>
					<td onclick="sorting(2)">Pemohon Actio Pauliana</td>
					<td onclick="sorting(3)">Nomor Perkara Kepailitan</td>
					<td onclick="sorting(4)">Tanggal Pendaftaran Kepailitan</td>
					<td onclick="sorting(5)">Susunan Majelis Hakim</td>
					<td onclick="sorting(6)">Panitera Pengganti</td>
					<td onclick="sorting(7)">Tanggal Putusan</td>
					<td></td>
				</tr>
				<?php
				if($actio!=''){
					$i=$page_active+1;
					if($actio->num_rows>0){
						foreach ($actio->result() as $row) {
							$pemohon = $row->nama;
							$pemohon .= '<br> Alamat: '.$row->alamat;
							$pemohon .= '<br> Pekerjaan: '.$row->pekerjaan;
							echo "<tr>";
								echo "<td>".$i."</td>";
								echo "<td>".$this->tanggalhelper->convertDate($row->tanggal_pendaftaran_actio)."</td>";
								echo "<td style='text-overflow: ellipsis;white-space: nowrap;overflow: hidden;'>".$pemohon."</td>";
								echo "<td>".$row->nomor_perkara."</td>";
								echo "<td>".$this->tanggalhelper->convertDate($row->tanggal_pendaftaran)."</td>";
								echo "<td style='text-overflow: ellipsis;white-space: nowrap;overflow: hidden;'>".$row->majelis_hakim_text."</td>";
								echo "<td style='text-overflow: ellipsis;white-space: nowrap;overflow: hidden;'>".$row->panitera_pengganti_text."</td>";
								echo "<td>".$this->tanggalhelper->convertDate($row->tanggal_putusan)."</td>";
								echo "<td style='text-align:center;'>
									<a href='#' onClick='popup_form(\"".base_url('manageActioPauliana/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_actio" class="popup">
	<div style="margin: 0 auto;top: 50%;margin-top: 5%;margin-bottom: 25px;">
		<div class="detil" style="background-color:white;border-color: white;font-size:14px;margin-top:25px;width: 35%;margin: 0 auto;">
			<div id="sub_title" style="padding:10px;color:#5FB85C;text-align:center;">TAMBAH REGISTER ACTIO PAULIANA</div>
			<form id="frm_ref_actio" style="background:white;margin:0;" method="post" action="<?php echo base_url().'manageActioPauliana/validateInput';?>">
				<table id="tableDetilPerkara" style="font-size:14px;width:100%;">
				<col width="40%">
				<col width="60%">
					<tbody>
						<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>
							<td>Tanggal Pendaftaran Kepailitan</td>
							<td style="padding:0px;padding-left:5px;" id="td_pendaftaran"></td>
						</tr>
						<tr>
							<td>Tanggal Putusan</td>
							<td style="padding:0px;padding-left:5px;" id="td_putusan"></td>
						</tr>
						<tr>
							<td>Tanggal Minutasi</td>
							<td style="padding:0px;padding-left:5px;" id="td_minut"></td>
						</tr>
						<tr>
							<td>Tanggal Pendaftaran Actio Pauliana <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input id="tgl_pendaftaran_actio" name="tgl_pendaftaran_actio" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td>Nama Pemohon <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='fullname' name='fullname' value="" class="standard-input" maxlength="255" style="width:150px;" readonly="readonly">
								<input type="button" onClick="popup_form2nd('<?php echo base_url('pihak_list');?>')" value="Cari" style="padding: 7px 0;color:white;background: #7f8c8d;border: 0 none;  -webkit-border-radius: 0 0 0 0;width: 90px;">
							</td>
						</tr>
						<tr>
							<td>Alamat Pemohon<font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<textarea id="alamat" name="alamat" class="standard-input" style="width: 245px; height: 70px;resize: none;" readonly="readonly"></textarea>
							</td>
						</tr>
						<tr>
							<td>Pekerjaan<font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='pekerjaan' name='pekerjaan' value="" class="standard-input" maxlength="200" readonly="readonly">
								
							</td>
						</tr>
						<tr>
							<td>Keterangan</td>
							<td style="padding:0px;padding-left:5px;border:0px;">
								<input type="hidden" id="curr_date" value="<?php echo $curr_date;?>">
								<input type="hidden" id="enc" name="enc" value="">
								<input type="hidden" id="enc_pihak" name="enc_pihak" value="">
								<input type="hidden" id="refresh" value="0">
								<input type="hidden" id="enc_act" name="enc_act" value="<?php echo $enc_act;?>">
								<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_actio' 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>
<script type="text/javascript">
function refreshPihakList(){
	$("#popup_form_2nd").remove();
	popup_form2nd('<?php echo base_url("pihak_list");?>')
	$("#refresh").remove();
}
$('#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()?>manageActioPauliana/fetchData', {
		val:val,
		act:act
	}, function(response){
		var json = jQuery.parseJSON(response);
		closeLoading()
		if(json.st==1){
			$('#enc').val(json.enc);
			$('#enc_act').val(json.enc_act);
			$('#td_putusan').text(json.tglPutusan);
			$('#td_pendaftaran').text(json.tglPendaftaran);
			$('#td_minut').text(json.tglMinutasi);
		}else if(json.st==0){
			clearInput();
			message_error_show(json.msg);
		}
	});
});


function clearInput(){
	$('#no_perkara').val('');
	$('#td_putusan').text('');
	$('#td_pendaftaran').text('');
	$('#td_minut').text('');
	$('#tgl_pendaftaran_actio').val('');
	$('#keterangan').val('');
	$('#alamat').val('');
	$('#pekerjaan').val('');
	$('#fullname').val('');
}

$("#back_actio").click(function() {
	$('#popup_actio_list').fadeIn();
	clearInput();
	$('#popup_actio').fadeOut();
    $("body").css({overflow: 'hidden'});
    if($("#refresh").val()==1){
    	window.open('<?php echo $url_requested;?>','_self')
    }
});


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

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

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

	openLoadingDialog()
	$.post('<?php echo base_url()?>manageActioPauliana/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();
			$('#enc').val(json.enc);
			$('#enc_act').val(json.enc_act);
			$('#enc_pihak').val(json.enc_pihak);
			$('#no_perkara').val(json.noPerkara);
			$('#td_putusan').text(json.tglPutusan);
			$('#td_pendaftaran').text(json.tglPendaftaran);
			$('#td_minut').text(json.tglMinutasi);
			$('#tgl_pendaftaran_actio').val(json.tglPenActio);
			$('#keterangan').val(json.catatatn);
			$('#alamat').val(json.alamat);
			$('#pekerjaan').val(json.pekerjaan);
			$('#fullname').val(json.nama);
			
			$('#popup_actio').fadeIn();
			act = 'updt';
			$("body").css({overflow: 'hidden'});
			return
		}else if(json.st==0){
			message_show(json.msg);
		}
	});
	
}
$("#addPihak").click(function() {
	openLoadingDialog()
	clearInput()
	$('#no_perkara').prop('readonly', false);
	//$('#no_perkara_list').prop('readonly', false);
	$('#no_perkara').css("background-color", "white");
	$('#popup_actio_list').fadeOut();
	$('#popup_actio').fadeIn();
	$('#hapus').hide();
	$('#act').val('add');
	act = 'add';
    $("body").css({overflow: 'hidden'});
    closeLoading()
});
</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()?>perkara_actio_pauliana_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()?>perkara_actio_pauliana_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");
				}
			});
            
        	}
        });
    $('#tgl_pendaftaran_actio').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_error_show(message);
				$(this).css("background-color", "red");
			}else{
				$(this).css("background-color", "#dedbdb");
			}
        }
    });
});

$('.datepicker').ValidateDateInput();
</script>
