<?php
if($this->session->userdata('is_logged_in')){
	if($this->session->userdata('idgroup')>2){
		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 Ruang Sidang" 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="7%" />
        <col  width="30%" />
        <col  width="45%" />
        <col  width="10%" />
        <col  width="5%" />
		<tbody>
			<tr>
				<td>No</td>
				<td onclick="sorting(1)">Kode</td>
				<td onclick="sorting(2)">Nama Ruangan</td>
				<td>Keterangan</td>
				<td onclick="sorting(4)">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->kode.'</td>';
			    				echo '<td>'.$row->nama.'</td>';
			    				echo '<td>'.$row->keterangan.'</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='6' align='center'>Data Tidak diTemukan</td></tr>";
		    		}
				}else{
		    		echo "<tr><td colspan='6' 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_ruang_sidang" class="popup">
	<div class="centering" style="width:500px;margin-top: 5%;z-index:-100">
		<div id='edit_ruang_sidang' style="border: 1px solid #ffffff;">
			<div class="detil" style="padding: 2px;background-color: white;">
				<form id="frm_ruang_sidang" style="background:white;margin:0;" method="post" action="<?php echo base_url().'ruang_sidang/validate_input';?>">
				<table id="tableDetilPerkara">
					<col width="45%">
					<col width="55%">
					<tbody>
						<tr>
							<td colspan="2" style='text-align:center;background:#fff;color:#5fb85c;border:2px solid #fff;margin-bottom:10px;font-size: 20px;'>REFERENSI RUANG SIDANG</td>
						</tr>
						<tr>
							<td>Kode Ruangan<font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='kode_ruangan' name='kode_ruangan' class="standard-input" maxlength="20" readonly="readonly">
							</td>
						</tr>
						<tr>
							<td>Nama Ruangan<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>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: 300px; 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_ruang_sidang();' 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>
			</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 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()?>ruang_sidang/info",{
	        enc:enc
	    }).done(function( response ){
	    	var json = jQuery.parseJSON(response);
	        if(json.st==1){
	        	$('#idH').val(json.idH);
	        	$('#nama').val(json.nama);
	        	$('#keterangan').val(json.ket);
	        	$('#kode_ruangan').val(json.kode);
	        	$('#aktif').val(json.aktif);
	        	$('#sub_title').html('INFO DATA RUANG SIDANG');
	        	$('#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 RUANG SIDANG');
		$('#idH').val(0);
		$('#edit_btn').hide();
		edit();
	}
    $('#popup_ruang_sidang').fadeIn();
    $("body").css({overflow: 'hidden'});
}

function kembali_ruang_sidang(){
	$('#popup_ruang_sidang').fadeOut();
	if($('#refresh').val()==1){
		window.open('<?php echo base_url().'ruangan_sidang_list';?>','_self');
	}
	$(':input').not('.btn').not('.btn_small').val('');
	$('.hidden').hide();
	$('#edit_btn').show();
	$('#simpan_btn').prop('disabled',true);
	$("body").css({ overflow: 'inherit' })
}


$('#frm_ruang_sidang').SubmitHandling({
   	refresh:'1',
    setRefresh:1,
    divRef:'#frm_ruang_sidang',
    clicked:1,
    btnClicked:'#refresh',
    whenStatus:1,
});
</script>
