<style type="text/css">
.poto_mediator {
  width: 220px;
}
 
.poto_mediator img {
  border: 10px solid #999;
  
  border-bottom: 45px solid #fff;
  -webkit-box-shadow: 3px 3px 3px #777;
     -moz-box-shadow: 3px 3px 3px #777;
          box-shadow: 3px 3px 3px #777;
 }
 </style>
<?php
// -----------------------------------------------------------------------------


//                                 ___                                      
//                                /\  \                                     
//       ___         ___         |::\  \                ___           ___   
//      /\__\       /\__\        |:|:\  \              /\__\         /\__\  
//     /:/  /      /:/__/      __|:|\:\  \            /:/__/        /:/  /  
//    /:/__/      /::\  \     /::::|_\:\__\          /::\  \       /:/__/   
//   /::\  \      \/\:\  \__  \:\~~\  \/__/          \/\:\  \__   /::\  \   
//  /:/\:\  \      ~~\:\/\__\  \:\  \                 ~~\:\/\__\ /:/\:\  \  
//  \/__\:\  \        \::/  /   \:\  \                   \::/  / \/__\:\  \ 
//       \:\__\       /:/  /     \:\__\                  /:/  /       \:\__\
//        \/__/       \/__/       \/__/                  \/__/         \/__/

// -------------------     Mahkamah Agung Republik Indonesia --------------------- 

if($this->session->userdata('is_logged_in')){
	if($this->session->userdata('idgroup')>2 AND $this->session->userdata('idgroup')!=900){
		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 Mediator" 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="25%" />
        <col  width="25%" />
        <col  width="15%" />
        <col  width="10%" />
        <col  width="5%" />
		<tbody>
			<tr>
				<td>No</td>
				<td onclick="sorting(1)">Status Mediator</td>
				<td onclick="sorting(2)">Nama Lengkap (tanpa gelar)</td>
				<td onclick="sorting(3)">Nama Lengkap (dengan gelar)</td>
				<td onclick="sorting(4)">Profesi</td>
				<td onclick="sorting(6)">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_mediator_text.'</td>';
			    				echo '<td>'.$row->nama.'</td>';
			    				echo '<td>'.$row->nama_gelar.'</td>';
			    				echo '<td>'.$row->profesi.'</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='9' align='center'>Data Tidak diTemukan</td></tr>";
		    		}
				}else{
		    		echo "<tr><td colspan='9' 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_mediator" class="popup">
	<div style="background:white;width: 900px;margin:0px auto">
		 <form id="frm_med" style="background:white;margin:0;" method="post" action="<?php echo base_url().'mediator/validate_input';?>" enctype="multipart/form-data">
			 	<div class="detil" style="border: 1px solid #ffffff;background: white;padding:10px;float:left">
				<table id="tableDetilPerkara">
					<col width="45%">
					<col width="65%">
					<tbody>
						<tr>
							<td colspan="2" style='text-align:center;background:white;border:0px;font-size: 20px;color: #648C03;'>INFO DATA MEDIATOR</td>
						</tr>
						<tr>
							<td>Status Mediator</td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style="width:245px">
									<select style="width:245px" name="status_mediator" id="status_mediator" class="custom-dropdown__select custom-dropdown__select--white" disabled>
										<option value="1"> Mediator Umum</option>
										<option value="2"> Hakim</option>
										<option value="3"> Pegawai</option>
									</select>
								</span>
							</td>
						</tr>
						<tr>
							<td>Profesi</td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='profesi' name='profesi' class="standard-input" maxlength="20" readonly="readonly">
							</td>
						</tr>
						<tr id='hakim_field'>
							<td>Hakim</td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style="width:245px">
									<select style="width:245px" name="hakim" id="hakim" class="custom-dropdown__select custom-dropdown__select--white" disabled>
										<option class= "opt" value="-1"> Pilih Nama Hakim</option>
										<?php
										if($hakim_list!=''){
											if($hakim_list->num_rows>0){
												foreach ($hakim_list->result() as $row) {
													echo '<option value="'.$row->id.'" nip="'.$row->nip.'" nama="'.$row->nama.'" nama_gelar="'.$row->nama_gelar.'" status="'.$row->status.'">'.$row->nama.'</option>';
								    			}
									    	}
										}
										?>
									</select>
								</span>
							</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="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>Tempat Lahir</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='tempat_lahir' name='tempat_lahir' class="standard-input" maxlength="50" readonly="readonly">
							</td>
						</tr>
						<tr>
                            <td>Tanggal Lahir</td>
                            <td style="padding:0px;padding-left:5px;">
                                <input id="tgl_lahir" name="tgl_lahir" value="<?php echo (!empty($tgl_lahir) ? $this->tanggalhelper->convertToInputDate($tgl_lahir) : '');?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun" disabled>
                            </td>
                        </tr>
						<tr>
							<td>Pendidikan</td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style="width:245px">
									<select style="width:245px" name="pendidikan" id="pendidikan" class="custom-dropdown__select custom-dropdown__select--white" disabled>
										<option class= "opt" value="-1"> Pilih Pendidikan</option>
										<?php
										if($pendidikan_list!=''){
											if($pendidikan_list->num_rows>0){
												foreach ($pendidikan_list->result() as $row) {
													echo '<option value="'.$row->id.'"><b>'.$row->kode.'</b(>'.$row->nama.')</option>';
								    			}
									    	}
										}
										?>
									</select>
								</span>
							</td>
						</tr>
						<tr>
							<td>Alamat</td>
							<td style="padding:0px;padding-left:5px;">
								<textarea id="alamat" name="alamat" class="standard-input" style="resize: none;margin: 0px; width: 245px; height: 70px;" readonly="readonly"></textarea>								
							</td>
						</tr>
						<tr>
							<td>Keahlian</td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='keahlian' name='keahlian' class="standard-input" maxlength="50" readonly="readonly">
							</td>
						</tr>
						<tr>
							<td>Nomor SK Ketua</td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='nomor_sk_ketua' name='nomor_sk_ketua' class="standard-input" maxlength="50" readonly="readonly">
							</td>
						</tr>
						<tr>
                            <td>Tanggal SK Ketua</td>
                            <td style="padding:0px;padding-left:5px;">
                                <input id="tgl_sk_ketua" name="tgl_sk_ketua" value="<?php echo (!empty($tgl_sk_ketua) ? $this->tanggalhelper->convertToInputDate($tgl_sk_ketua) : '');?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun" disabled>
                            </td>
                        </tr>
						<tr>
							<td>Bersertifikat</td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style="width:80px">
									<select style="width:80px" name="bersertifikat" id="bersertifikat" 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>Nomor Sertifikasi</td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='no_sertifikasi' name='no_sertifikasi' class="standard-input" maxlength="50" readonly="readonly">
							</td>
						</tr>
						<tr>
                            <td>Tanggal Sertifikasi</td>
                            <td style="padding:0px;padding-left:5px;">
                                <input id="tgl_sertifikasi" name="tgl_sertifikasi" value="<?php echo (!empty($tgl_sertifikasi) ? $this->tanggalhelper->convertToInputDate($tgl_sertifikasi) : '');?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun" disabled>
                            </td>
                        </tr>
						<tr>
							<td>Lembaga Sertifikasi</td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='lembaga_sertifikasi' name='lembaga_sertifikasi' 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: 70px;" readonly="readonly"></textarea>
								<input type="hidden" id='idH' name="idH">								
							</td>
						</tr>
						<tr>
							<td colspan="2" style="background:white;" align="center">
							<input type="hidden" id="curr_date" name="curr_date" value="<?php echo $tgl_sekarang;?>">
							<input type="button" onClick='kembali_mediator();' id="refresh" 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>
				</div>
				<div style="margin-top:5px;padding: 5px;width:320px;float:left;height: 548px;border:1px solid #999;background: white">
					<div id="preview_foto" class="poto_mediator">
						<img class="img_mediator">
					</div>
					<div style="height: 20px;"></div>
					<p>Klik tombol dibawah ini untuk upload foto</p>
					<input id="foto_mediator" name="foto_mediator"  type="file" disabled>
					<p>Type file yang diizinkan adalah JPG, PNG dan GIF</p>
					<input id="nama_file_foto" type="text" name="nama_file_foto" hidden>
			    </div>
			</form>
		</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);
	$('#foto_mediator').prop('disabled',false);
	$('#edit_btn').prop('disabled',true);
	$('#tgl_lahir').attr('disabled',false);
	$('#tgl_sertifikasi').attr('disabled',false);
	$('#tgl_sk_ketua').attr('disabled',false);
	$('#nip').attr('readonly', true);
	if($("#status_mediator").val()==2){
		$('#nama').attr('readonly', true);
		$('#nama_gelar').attr('readonly', true);
		$('#nip_field').show();
	    $('#hakim_field').show();
	}else if($("#status_mediator").val()==3){
		$('#nama').attr('readonly', true);
		$('#nama_gelar').attr('readonly', true);
		$('#nip_field').show();
		$('#hakim_field').hide();		
	}else{
		$('#nip_field').hide();
	    $('#hakim_field').hide();
	}
}
function show_edit(enc){
	if(enc!=''){
		$.post( "<?php echo base_url()?>mediator/info",{
	        enc:enc
	    }).done(function( response ){
	    	$(".img_mediator").remove();
	    	var json = jQuery.parseJSON(response);
	        if(json.st==1){	
	        	$('#status_mediator').val(json.status_mediator);
	        	if(json.status_mediator==1){
	        		$('#nip_field').hide();
	        		$('#hakim_field').hide();
	        	}else if(json.status_mediator==3){
	        		$('#nama').attr('readonly', true);
	        		$('#nama_gelar').attr('readonly', true);
	        		$('#hakim_field').hide();
	        	}
	        	$('#idH').val(json.idH);
	        	$('#profesi').val(json.profesi);
	        	$('#nip').val(json.nip);
	        	$('#nama').val(json.nama);
	        	$('#tempat_lahir').val(json.tempat_lahir);
				$('#tgl_lahir').val(json.tgl_lahir);
				$('#pendidikan').val(json.pendidikan);
				$('#keahlian').val(json.keahlian);
				$('#alamat').val(json.alamat);
	        	$('#nama_gelar').val(json.nama_gelar);
	        	$('#nomor_sk_ketua').val(json.nomor_sk_ketua);
	        	$('#tgl_sk_ketua').val(json.tgl_sk_ketua);
	        	if (json.foto=="" || json.foto==null){
	        		var urlgambar="<?php echo base_url('resources/img/no_foto.gif');?>";
	        		$('#nama_file_foto').val("belum ada foto");
	        	}else{
	        		var urlgambar="<?php echo base_url('resources/file/foto').'/';?>"+json.foto;
        			$('#nama_file_foto').val(json.foto);
	        	}
        		$("#preview_foto").show();
        		$(".img_mediator").show();
        		$("#preview_foto").append("<img class='img_mediator' width='290px' height='350px' src="+urlgambar+">");
	        	$('#bersertifikat').val(json.bersertifikat);
	        	$('#no_sertifikasi').val(json.no_sertifikasi);
	        	$('#tgl_sertifikasi').val(json.tgl_sertifikasi);
	        	$('#lembaga_sertifikasi').val(json.lembaga_sertifikasi);
	        	$('#aktif').val(json.aktif);
	        	$('#keterangan').val(json.ket);
	        	$('#sub_title').html('INFO DATA MEDIATOR');
	        	$('#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 MEDIATOR');
		$('#idH').val(0);
		$('#edit_btn').hide();
		edit();
	}
    $('#popup_mediator').fadeIn();
    $("body").css({overflow: 'hidden'});
}

function kembali_mediator(){
	$('#popup_mediator').fadeOut();
	if($('#refresh').val()==1){
		window.open('<?php echo base_url().'mediator_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_mediator").change(function() {
	if($(this).val()==2){
		$('.opt').show();
		$('#hakim').val('-1');
		$('#nip_field').show();
		$('#hakim_field').show();
		$('#nip').attr('readonly', true);
		$('#nama').attr('readonly', true);
	    $('#nama_gelar').attr('readonly', true);
	    $('#profesi').val('Hakim');	    
	}else if($(this).val()==3){
		$('.opt').show();
		$('#nip_field').show();
		$('#nip').attr('readonly', false);
		$('#hakim_field').hide();
		$('#nama').attr('readonly', false);
	    $('#nama_gelar').attr('readonly', false);
	    $('#profesi').val('Pegawai');
	}else{
		$('#hakim_field').hide();
		$('#nip_field').hide();
		$('#profesi').val('');
		$('#nama').attr('readonly', false);
	    $('#nama_gelar').attr('readonly', false);		
	}
});
$("#hakim").change(function() {
	if($('option:selected', this).attr("status")==0){
		message_error_show_parent('Hakim Tidak Dapat Dipilih, Bukan Hakim Aktif')
		$('#nip').val('');
		$('#nama').val('');
		$('#nama_gelar').val('');
		$('#simpan_btn').prop('disabled',true);
		return
	}else{
		$('#simpan_btn').prop('disabled',false);
	}
	$('#nip').val($('option:selected', this).attr("nip"));
	$('#nama').val($('option:selected', this).attr("nama"));
	$('#nama_gelar').val($('option:selected', this).attr("nama_gelar"));

});

$('#hakim').click(function(e){
	$('.opt').hide();
});

$('#nip').ForceNumericOnly();

$('#tgl_sertifikasi').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 date = $(this).datepicker('getDate');
				
				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_parent(message);
					$(this).css("background-color", "red");
					$('#tgl_sertifikasi').val('');
				}else{
					$(this).css("background-color", "#dedbdb");
				}
			}            
      	});

		$('#tgl_lahir').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 date = $(this).datepicker('getDate');
				
				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_parent(message);
					$('#tgl_lahir').val('');
					$('#tgl_lahir').focus();
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
			}            
      	});

		$('#tgl_sk_ketua').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 date = $(this).datepicker('getDate');
				
				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_parent(message);
					$('#tgl_lahir').val('');
					$('#tgl_lahir').focus();
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
			}            
      	});
$('.datepicker').ValidateDateInput();

</script>
