<script type="text/javascript" src="<?php echo base_url();?>resources/js/jquery.simplePagination.js"></script>
<div id="popup_rehabilitasi_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_rehabilitasi_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"></div>
			<?php }
		} ?>
	<div id="pages" >
    	<div id="selector" style="padding: 4px 5px 5px 0;"></div>
    </div>
	<div class="cssTable">
		<table id="tablePerkaraAll">
			<col  width="4%" />
			<col  width="13%" />
			<col  width="13%" />
			<col  width="13%" />
			<col  width="12%" />
			<col  width="13%" />
			<col  width="13%" />
			<col  width="13%" />
			<col  width="6%" />
        	<tbody>
				<tr>
					<td onclick="sorting(7)">No Urut</td>
					<td onclick="sorting(1)">Tanggal Permohonan Rehabilitasi </td>
					<td onclick="sorting(2)">Tanggal Putusan dimohonkan Rehabilitasi</td>
					<td onclick="sorting(3)">Nomor Putusan dimohonkan Rehabilitasi</td>
					<td onclick="sorting(4)">Para Pihak</td>
					<td onclick="sorting(5)">Tanggal Pengumuman dalam Berita </td>
					<td onclick="sorting(6)">Tanggal Dimuat Surat Kabar</td>
					<td onclick="sorting(6)">Tanggal Putusan Rehabilitasi</td>
					<td></td>
				</tr>
				<?php
				if($rehabilitasi!=''){
					$i=$page_active+1;
					if($rehabilitasi->num_rows>0){
						foreach ($rehabilitasi->result() as $row) {					
							echo "<tr>";
								echo "<td>".$row->nomor_urut_register."</td>";
								echo "<td>".$this->tanggalhelper->convertDate($row->tanggal_permohonan)."</td>";
								echo "<td>".$this->tanggalhelper->convertDate($row->tanggal_putusan_mohon)."</td>";
								echo "<td>".$row->nomor_putusan_mohon."</td>";
								echo "<td style='text-overflow: ellipsis;white-space: nowrap;overflow: hidden;'>".$row->para_pihak."</td>";
								echo "<td>".$this->tanggalhelper->convertDate($row->tanggal_berita_putusan)."</td>";
								echo "<td>".$this->tanggalhelper->convertDate($row->tanggal_surat_kabar)."</td>";
								echo "<td>".$this->tanggalhelper->convertDate($row->tanggal_putusan)."</td>";
								echo "<td style='text-align:center;'>
										<a href='#' onClick='popup_form(\"".base_url('manageRehabilitasi/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_rehab" class="popup">
	<div style="margin: 0 auto;top: 50%;margin-top: 1%;margin-bottom: 25px;">
		<div class="detil" style="background-color:white;border-color: white;font-size:14px;margin-top:25px;width: 90%;margin: 0 auto;">
			<div id="sub_title" style="padding:10px;color:#5FB85C;text-align:center;">TAMBAH REGISTER REHABILITASI</div>
			<form id="frm_ref_rehab" style="background:white;margin:0;" method="post" action="<?php echo base_url().'manageRehabilitasi/validateInput';?>">
				<table id="tableDetilPerkara" style="font-size:14px;width:100%;">
				<col width="23%">
				<col width="77%">
					<tbody>
						<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="10" style="width: 50px;">
							</td>
						</tr>
						<tr>
							<td>Nomor Putusan dimohonkan Rehabilitasi<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 Putusan Yang dimohonkan Rehabilitas<font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input id="tgl_putusan" name="tgl_putusan" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun" readonly="readonly">
							</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 Permohonan Rehabilitasi <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input id="tgl_permohonan" name="tgl_permohonan" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td valign="top" style="vertical-align:top">Alasan Permohonan Rehabilitasi <font color="red">*</font></td>
							<td style="background:white;" id="alasan_text">
								<?php echo $this->ckeditor->editor("alasan",'');?>
							</td>
						</tr>
						<tr>
							<td>Tanggal Pengumuman Rehabilitasi dalam Berita Negara RI</td>
							<td style="padding:0px;padding-left:5px;">
								<input id="tgl_berita_ri" name="tgl_berita_ri" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td>Tanggal Dimuat dalam Surat Kabar</td>
							<td style="padding:0px;padding-left:5px;">
								<input id="tgl_surat_berita" name="tgl_surat_berita" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td>Nama Surat Kabar</td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='nama_surat_kabar' name='nama_surat_kabar' value="" class="standard-input" maxlength="200">
							</td>
						</tr>
						<tr>
							<td>Tanggal Perlawanan</td>
							<td style="padding:0px;padding-left:5px;">
								<input id="tgl_perlawanan" name="tgl_perlawanan" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td>Tanggal Putusan Rehabilitasi <font color="red" id="wajib">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input id="tgl_putusan_rehab" name="tgl_putusan_rehab" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr>
							<td valign="top" style="vertical-align:top">Amar Putusan <font color="red" id="wajib_amar">*</font></td>
							<td style="background:white;" id="amar_put_text">
								<?php echo $this->ckeditor->editor("amar_put",'');?>
							</td>
						</tr>
						<tr>
							<td>E-Doc Amar Putusan</td>
							<td style="padding:0px;padding-left:5px;border:0px;">
								<input type="text" id='edoc_amar' name='edoc_amar' value="" class="standard-input" maxlength="200">
							</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: 850px; height: 70px;resize: none;"></textarea>
								<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 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>
<script type="text/javascript">

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()?>manageRehabilitasi/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);
			$('#tgl_putusan').val(json.tglPutusanPerkara);
		}else if(json.st==0){
			clearInput();
			message_error_show(json.msg);
		}
	});
});


function clearInput(){
	$('#parapihak').text('');
	$('#no_perkara').val('');
	$('#tgl_perlawanan').val('');
	$('#tgl_permohonan').val('');
	$('#tgl_putusan').val('');
	$('#nama_surat_kabar').val('');
	$('#tgl_putusan_rehab').val('');
	$('#tgl_surat_berita').val('');
	$('#edoc_amar').val('');
	$('#tgl_berita_ri').val('');
	$('#keterangan').val('');
	CKEDITOR.instances['alasan'].setData('');
	CKEDITOR.instances['amar_put'].setData('');
}
$("#back_pihak").click(function() {
	$('#popup_rehabilitasi_list').fadeIn();
	clearInput();
	$('#popup_rehab').fadeOut();
    $("body").css({overflow: 'hidden'});
    if($("#refresh").val()==1){
    	window.open('<?php echo $url_requested;?>','_self')
    }
});


$('#frm_ref_rehab').SubmitHandling({
	refresh:'1',
	setRefresh:1,
	divRef:'#konten',
	clicked:1,
	btnClicked:'#back_pihak',
	whenStatus:1,
	isCKEdit:1,
	tdID:'alasan_text',
	textID:'alasan',
});

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


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

	openLoadingDialog()
	$.post('<?php echo base_url()?>manageRehabilitasi/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);
			$('#tgl_permohonan').val(json.tglPermohonan);
			$('#tgl_putusan').val(json.tglPutusMohon);
			
			$('#tgl_berita_ri').val(json.tglBerita);
			$('#tgl_surat_berita').val(json.tglSuratKabar);
			$('#nama_surat_kabar').val(json.suratKabar);
			$('#tgl_perlawanan').val(json.tglPerlawanan);
			$('#tgl_putusan_rehab').val(json.tglPutusanRehab);
			CKEDITOR.instances['alasan'].setData(json.alasan);
			CKEDITOR.instances['amar_put'].setData(json.amarPutusan);
			$('#edoc_amar').val(json.edocAmar);
			$('#keterangan').val(json.ket);
			$('#wajib').show();
			$('#wajib_amar').show();
			$('#popup_rehab').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()?>manageRehabilitasi/fetchNoUrut', {
		act:'add'
	}, function(response){
		var json = jQuery.parseJSON(response);
		closeLoading()
		if(json.st==1){
			$('#wajib').hide();
			$('#wajib_amar').hide();
			$('#no_urut').val(json.noUrut);
		}else if(json.st==0){
			clearInput();
			message_error_show(json.msg);
			return
		}
	});

	clearInput();
	$('#no_perkara').prop('readonly', false);
	//$('#no_perkara_list').prop('readonly', false);
	$('#no_perkara').css("background-color", "white");
	$('#popup_rehabilitasi_list').fadeOut();
	$('#popup_rehab').fadeIn();
	$('#hapus').hide();
	$('#act').val('add');
	act = 'add';
    $("body").css({overflow: 'hidden'});
});
</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_rehabilitasi_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_rehabilitasi_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_permohonan').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");
				}
        	}
      	});
	$('#tgl_berita_ri').datepicker({
            inline: true,
            showOtherMonths: true,
            dateFormat: 'dd/mm/yy',
            dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
            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");
				}
        	}
      	});
	$('#tgl_surat_berita').datepicker({
            inline: true,
            showOtherMonths: true,
            dateFormat: 'dd/mm/yy',
            dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
            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");
				}
        	}
      	});
	$('#tgl_perlawanan').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");
				}
        	}
      	});
	$('#tgl_putusan_rehab').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");
				}
        	}
      	});
	
});
$('.datepicker').ValidateDateInput();

</script>
