<?php
if($this->session->userdata('is_logged_in')){
	if($this->session->userdata('idgroup')>2 AND $this->session->userdata('idgroup')!=900 AND $this->session->userdata('idgroup')!=901){
		redirect('login');
	}
}else{
	redirect('login');
}
?>
<hr class="thick-line" style="clear:both;">
<div id="left">
	<?php
	echo form_open(base_url().$page_url.'/search');
	$attributes = array('name' => 'search', 'id' => 'search-box', 'type' => 'text','size' => '50','placeholder'=>"  Ketik kata kunci  ");
	echo form_input($attributes);
	echo "<span>  </span>";
	$attributes = array('value' => 'Search', 'id' => 'search-btn1','class' => 'btn', 'type' => 'submit');
	echo form_submit($attributes);
	echo form_close('');
	?>
</div>
<div id="left" style="margin-left:50px;">
	<input type="submit" value="Tambah Hakim" class="btn" onclick="show_edit('')">
</div>
<div id="pages">
    <div id="selector"></div>
</div>
<div class="cssTable">
	<table id="tablePerkaraAll">
		<col  width="3%" />
        <col  width="15%" />
        <col  width="15%" />
        <col  width="25%" />
        <col  width="25%" />
        <col  width="10%" />
        <col  width="5%" />
		<tbody>
			<tr>
				<td>No</td>
				<td onclick="sorting(1)">Status Hakim</td>
				<td onclick="sorting(2)">NIP</td>
				<td onclick="sorting(3)">Nama Lengkap (tanpa gelar)</td>
				<td onclick="sorting(4)">Nama Lengkap (dengan gelar)</td>
				<td onclick="sorting(5)">Aktif</td>
				<td>Link</td>
			</tr>
			<?php
				if($users_list!=''){
					if($users_list->num_rows>0){
						if($page_active<1){
							$con = 1;
						}else{
							$con = $page_active+1;
						}
						$modelClass =& get_instance();
						
						# set history URL REQUESTED, this will be used to back on previous page.
						# 
						$this->nativesession->set_flash_session('history', current_url());
		    			foreach ($users_list->result() as $row) {
		    				echo "<tr>";
			    				echo '<td>'.$con.'</td>';
			    				echo '<td>'.$row->status_hakim_text.'</td>';
			    				echo '<td>'.$row->nip.'</td>';
			    				echo '<td>'.$row->nama.'</td>';
			    				echo '<td>'.$row->nama_gelar.'</td>';
			    				echo '<td>'.$row->aktif_text.'</td>';
			    				echo '<td style="cursor:pointer;" align="center" onclick="show_edit(\''.base64_encode($modelClass->encrypt->encode($row->id)).'\')">[<a href="#">edit</a>]</td>';
		    				echo "</tr>";
		    				$con++;
		    			}
			    	}else{
		    			echo "<tr><td colspan='7' align='center'>Data Tidak diTemukan</td></tr>";
		    		}
				}else{
		    		echo "<tr><td colspan='7' align='center'>Data Tidak diTemukan</td></tr>";
		    	}
			?>
		</tbody>
	</table>
</div>
<div id="pages_bottom" style="width:100%;padding-left:5px;padding-top:5px;">
    <div id="selector_bottom"></div>
</div>
<div id="popup_hakim" class="popup">
	<div class="centering" style="width:570px;margin-top: 5%;z-index:-100">
		<div id='edit_hakim_ma' style="border: 1px solid #ffffff;">
			<div class="detil" style="padding: 2px;background-color: white;">
			<form id="frm_hakim_ma" style="background:white;margin:0;" method="post" action="<?php echo base_url().'hakim_ma/validate_input';?>">
				<table id="tableDetilPerkara">
					<col width="40%">
					<col width="60%">
					<tbody>
						<tr>
							<td colspan="2" style='text-align:center;background:#fff;color:#5fb85c;border:2px solid #fff;margin-bottom:10px;font-size: 20px;'>INFO DATA HAKIM</td>
						</tr>
						<tr>
							<td>Status Hakim</td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style="width:130px">
									<select style="width:130px" name="status_hakim" id="status_hakim" class="custom-dropdown__select custom-dropdown__select--white" disabled>
										<option value="1"> Hakim Tetap</option>
										<option value="2"> Hakim Adhock</option>
									</select>
								</span>
							</td>
						</tr>
						<tr>
							<td>Kode Hakim</td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='kode_hakim' name='kode_hakim' class="standard-input" maxlength="20" readonly="readonly">
							</td>
						</tr>
						<tr id="nip_field">
							<td>NIP<font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='nip' name='nip' class="standard-input" maxlength="18" readonly="readonly">
								<input type="hidden" id='nip_lama' name='nip_lama' class="standard-input" maxlength="18" readonly="readonly">
								<input type="button" id="validate_btn" onClick='val_to_ma();' value="validate" class="btn_small">
							</td>
						</tr>
						<tr>
							<td>Nama Lengkap (tanpa gelar)<font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='nama' name='nama' class="standard-input" maxlength="50" readonly="readonly">
							</td>
						</tr>
						<tr>
							<td>Nama Lengkap dengan Gelar<font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='nama_gelar' name='nama_gelar' class="standard-input" maxlength="50" readonly="readonly">
							</td>
						</tr>
						<tr>
							<td>Aktif</td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style="width:80px">
									<select style="width:80px" name="aktif" id="aktif" class="custom-dropdown__select custom-dropdown__select--white" disabled>
										<option value="1"> Ya</option>
										<option value="0"> Tidak</option>
									</select>
								</span>
							</td>
						</tr>
						<tr>
							<td>Keterangan</td>
							<td style="padding:0px;padding-left:5px;">
								<textarea id="keterangan" name="keterangan" class="standard-input" style="resize: none;margin: 0px; width: 245px; height: 100px;" readonly="readonly"></textarea>
								<input type="hidden" id='idH' name="idH">
							</td>
						</tr>
						<tr>
							<td colspan="2" style="background:white;" align="center">

							<input type="button" onClick='kembali_hakim_ma();' id="back" value="Kembali" class="btn">
							<?php
							if($this->session->userdata('idgroup')<2 OR $this->session->userdata('idgroup')==900){
							?>
								<input type="button" id="edit_btn" onClick='edit();' value="Edit" class="btn">
								<input type="submit" id="simpan_btn" value="Simpan" class="btn" disabled>
							<?php
							}
							?>
						</td>
						</tr>
					</tbody>
				</table>
			</form>
		</div>
	</div>
</div>
<?php
$url = base_url().$page_url.'/sort/';
$keyword = (!empty($keyword))?'/'.$keyword : '';
?>
<script type="text/javascript">
	function sorting(col){
		window.open('<?php echo $url;?>'+col+'/<?php echo $enc; ?><?php echo $keyword; ?>','_self')
	}
	<?php $enc = (!empty($enc)) ? "/".$enc : $enc;?>
	function searchDetilShow(){
		window.open('<?php echo base_url();?>search','_self')
	}

function val_to_ma(){
	message_error_show_parent('Tarik Auto Dari SIKEP SIMARI, Sedang Dalam Tahap Ujicoba.')
}
function edit(){
	$(':input').prop('readonly', false);
	$(':input').attr('readonly', false);
	$('.custom-dropdown__select').prop('disabled',false);
	$('.custom-dropdown__select').attr('disabled',false);
	$('#simpan_btn').prop('disabled',false);
	$('#edit_btn').prop('disabled',true);
}
function show_edit(enc){
	if(enc!=''){
		$.post( "<?php echo base_url()?>hakim_ma/info",{
	        enc:enc
	    }).done(function( response ){
	    	var json = jQuery.parseJSON(response);
	        if(json.st==1){
	        	$('#status_hakim').val(json.status_hakim);
	        	if(json.status_hakim==2){
	        		$('#nip_field').hide();
	        	}
	        	$('#idH').val(json.idH);
	        	$('#kode_hakim').val(json.kode);
	        	$('#nip').val(json.nip);
	        	$('#nip_lama').val(json.nip);
	        	$('#nama').val(json.nama);
	        	$('#nama_gelar').val(json.nama_gelar);
	        	$('#aktif').val(json.aktif);
	        	$('#keterangan').val(json.ket);
	        	$('#sub_title').html('INFO DATA HAKIM');
	        	$('#edit_btn').prop('disabled',false);
	        	$('#edit_btn').attr('disabled',false);
	        	$('.custom-dropdown__select').attr('disabled',true);
	        	$(':input').not('.btn').not('.btn_small').attr('readonly', true);
	        }else{
	        	message_error_show_parent('Error, Please refresh your browser and clear the cache')
	        }
	    },'json');
	}else{
		$('#sub_title').html('TAMBAH HAKIM');
		$('#idH').val(0);
		$('#edit_btn').hide();
		edit();
	}
    $('#popup_hakim').fadeIn();
    $("body").css({overflow: 'hidden'});
}

function kembali_hakim_ma(){
	$('#popup_hakim').fadeOut();
	window.open('<?php echo base_url().'hakim_ma_list';?>','_self');
	$(':input').not('.btn').not('.btn_small').val('');
	$('.hidden').hide();
	$('#edit_btn').show();
	$('#nip_field').show();
	$('#simpan_btn').prop('disabled',true);
	$("body").css({ overflow: 'inherit' })
}

$("#status_hakim").change(function() {
	if($(this).val()==1){
		$('#nip_field').show();
	}else{
		$('#nip_field').hide();
	}
});

$('#nip').on('keyup', function (event) {
    var newValue = this.value.replace(/[^0-9\P\/]/gi, '');
    if (this.value != newValue) {
        this.value = newValue;
    }
});
$('#frm_hakim_ma').SubmitHandling({
   	refresh:'1',
    setRefresh:1,
    divRef:'#frm_hakim_ma',
    clicked:1,
    btnClicked:'#back',
    whenStatus:1,
});
</script>
