<?php
$actionName = "UserManage";
if($this->session->userdata('is_logged_in')){
	$AuthorizationForm = $this->nativesession->get('getAuthorizationAction');
	if($this->authorization->isAuthorized($actionName,$AuthorizationForm)==FALSE){
		redirect('login');
	}
}else{
	redirect('login');
}

$previous = $this->nativesession->get_flash_session('history');
$username = "";
$password = "";
$password_repeat = "";
$fullname = "";
$email = "";
$alter_email = "";
$block = "0";
$expired_date = "";
$tupoksi ='';
$hakim_id = "";
$jurusita_id = "";
$panitera_id = "";
$action = "add";
$action_name = "Tambah";
$readonly = "";
if($user_info!=''){
	if($user_info->num_rows>0){
		foreach ($user_info->result() as $row) {
			$username = $row->username;
			$fullname = $row->fullname;;
			$block = $row->block;
			$email = $row->email;
			$alter_email = $row->alternative_email;
			$hakim_id = $row->hakim_id;
			$jurusita_id = $row->jurusita_id;
			$panitera_id = $row->panitera_id;
			$tupoksi = $row->group_id;
			$action = "updt";
			$action_name = "Update";
			$readonly = "readonly='readonly'";
		}
	}
}

if($tupoksi==30 OR $tupoksi == 500 OR $tupoksi==410 OR $tupoksi==420 OR $tupoksi==430 OR $tupoksi==440 OR $tupoksi==450 OR $tupoksi==460 OR $tupoksi==470 OR $tupoksi==480 OR $tupoksi==1000 OR $tupoksi==1010 OR $tupoksi==1020 OR $tupoksi==1030){
	$show = 'rw_panitera';
}elseif($tupoksi==10 OR $tupoksi == 20){
	$show = 'rw_hakim';
}elseif($tupoksi==600){
	$show = 'rw_jurusita';
}else{
	$show = "abc";
}
?>
<hr class="thick-line" style="clear:both;">
<div id=''>
	<div style="padding:20px;"></div>
	<div class="detil" style="font-size:14px;margin-top:25px;width: 45%;margin: 0 auto;border-color: #FFFFFF;">
		<form id="frm_user" style="background:white;margin:0;" method="post" action="<?php echo base_url().'manage_user/validate_input';?>">
			<table id="tableDetilPerkara" style="font-size:14px;">
				<col width="35%">
				<col width="65%">
				<tbody>
					<tr>
						<td>Nama Lengkap <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input type="text" id='fullname' name='fullname' value="<?php echo $fullname;?>" class="standard-input" maxlength="255">
						</td>
					</tr>
					<tr>
						<td>Username <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input id='username' name='username' value="<?php echo $username;?>" class="standard-input" maxlength="30" <?php echo $readonly;?>>
						</td>
					</tr>
					<tr>
						<td>Password <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input type="password" id='password' name='password' value="<?php echo $password;?>" class="standard-input" maxlength="30">
						</td>
					</tr>
					<tr>
						<td>Ulangi Password <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input type="password" id='password_repeat' name='password_repeat' value="<?php echo $password_repeat;?>" class="standard-input" maxlength="30">
						</td>
					</tr>
					<tr>
						<td>Email <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input id='email' name='email' value="<?php echo $email;?>" class="standard-input" maxlength="100">
						</td>
					</tr>
					<tr>
						<td>Alternative Email</td>
						<td style="padding:0px;padding-left:5px;">
							<input id='alter_email' name='alter_email' value="<?php echo $alter_email;?>" class="standard-input" maxlength="100">
						</td>
					</tr>
					<tr>
						<td>Waktu Kadaluarsa</td>
						<td style="padding:0px;padding-left:5px;">
							<input id="expired_date" name="expired_date" value="<?php echo $expired_date;?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
						</td>
					</tr>
					<tr>
						<td>Block User</td>
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald" style="width:100px;">
								<select name="block" id="block" style="width:100px;" onchange="" class="custom-dropdown__select custom-dropdown__select--white">
									<?php
									echo '<option value="0" ';echo (0 === $block) ? 'selected' : ''; echo '>Tidak</option>';
									echo '<option value="1" ';echo (1 === $block) ? 'selected' : ''; echo '>Ya</option>';
									?>
								</select>
							</span>
						</td>
					</tr>
					<tr>
						<td valign="top" style="vertical-align: top;">Tupoksi <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald">
								<select name="tupoksi" id="tupoksi" style="width:288px;" onchange="" class="custom-dropdown__select custom-dropdown__select--white">
									<?php
										if($group_list!=''){
											if($group_list->num_rows>0){
												$rowspan = ($group_list->num_rows)+1;
												if(empty($tupoksi)){
													echo '<option value="">Pilih Tupoksi User</option>';
												}
								    			foreach ($group_list->result() as $row) {
								    				echo '<option value="'.$row->groupid.'" ';echo ($row->groupid == $tupoksi) ? 'selected' : ''; echo ' >'.$row->NAME.'</option>';
								    			}
								    		}
								    	}
									?>
								</select>
							</span>
						</td>
					</tr>
					<tr id="rw_hakim" class="sembunyi">
						<td>Nama Hakim</td>
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald">
								<select name="hakim" id="hakim" style="width:288px;" onchange="" class="custom-dropdown__select custom-dropdown__select--white">
									<?php
										if($hakim_list!=''){
											if($hakim_list->num_rows>0){
												$rowspan = ($hakim_list->num_rows)+1;
								    			foreach ($hakim_list->result() as $row) {
								    				echo '<option value="'.$row->id.'" ';echo ($row->id == $hakim_id) ? 'selected' : ''; echo ' >'.$row->nama_gelar.'</option>';
								    			}
								    		}
								    	}
									?>
								</select>
							</span>
						</td>
					</tr>
					<tr id="rw_panitera" class="sembunyi">
						<td>Nama Panitera</td>
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald">
								<select name="panitera" id="panitera" style="width:288px;" onchange="" class="custom-dropdown__select custom-dropdown__select--white">
									<?php
										if($panitera_list!=''){
											if($panitera_list->num_rows>0){
												$rowspan = ($panitera_list->num_rows)+1;
								    			foreach ($panitera_list->result() as $row) {
								    				echo '<option value="'.$row->id.'" ';echo ($row->id == $panitera_id) ? 'selected' : ''; echo ' >'.$row->nama_gelar.'</option>';
								    			}
								    		}
								    	}
									?>
								</select>
							</span>
						</td>
						<input type="hidden" id="userid" name="userid" value="<?php echo $userid;?>">
						<input type="hidden" id="act" name="act" value="<?php echo $action;?>">
					</tr>
					<tr id="rw_jurusita" class="sembunyi">
						<td >Nama Jurusita</td>
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald">
								<select name="jurusita" id="jurusita" style="width:288px;" onchange="" class="custom-dropdown__select custom-dropdown__select--white">
									<?php
										if($jurusita_list!=''){
											if($jurusita_list->num_rows>0){
												$rowspan = ($jurusita_list->num_rows)+1;
								    			foreach ($jurusita_list->result() as $row) {
								    				echo '<option value="'.$row->id.'" ';echo ($row->id == $jurusita_id) ? 'selected' : ''; echo ' >'.$row->nama_gelar.'</option>';
								    			}
								    		}
								    	}
									?>
								</select>
							</span>
						</td>
					</tr>
					<tr>
						
						<td colspan="3" style="background:white;" align="center">
							<input type="button" onClick='kembali();' id="back" value="Kembali" class="btn">
							<input type="submit" value="<?php echo $action_name;?>" class="btn">
						</td>
					</tr>
					
				</tbody>
			</table>
		</form>
	</div>
</div>
<style type="text/css">
.standard-input {
	font-family: Century Gothic, sans-serif;
	font-size: 13px;
	padding: 5px;
	padding-left: 10px;
	width: 350px;
	border: 1px solid rgb(166, 166, 166);
}
</style>
<script type="text/javascript">
function kembali(){
	window.open("<?php echo $previous;?>","_self");
}

var ori_name = $('#fullname').val();
var counter = 0;

$('.sembunyi').not('#<?php echo $show;?>').hide();

$(this).change(function(e){
	counter = counter+1;
	if(counter==1){
		ori_name = $('#fullname').val();
	}
    var val = $('#'+e.target.id).val()
    if(e.target.id=="tupoksi"){
    	if(val==10 || val==20){
    		$('.sembunyi').hide();
    		$('#rw_hakim').show();
    		$('#fullname').val($('#hakim :selected').text());
    		$("#fullname").prop('readonly', true);
	    }else if(val==30 || val==410 || val==420 || val==430 || val==440 || val==450 || val==460 || val==470 || val==480 || val==500 || val==1000 || val==1010 || val==1020 || val==1030){
	    	$('.sembunyi').hide();
	    	$('#rw_panitera').show();
	    	$('#fullname').val($('#panitera :selected').text());
	    	$('#fullname').prop('readonly', true);
	    }else if(val==600){
	    	$('.sembunyi').hide();
	    	$('#rw_jurusita').show();
	    	$('#fullname').val($('#jurusita :selected').text());
	    	$("#fullname").prop('readonly', true);
	    }else{
	    	$('.sembunyi').hide();
	    	if(ori_name!=''){
	    		$('#fullname').val(ori_name)
	    		$("#fullname").prop('readonly', false);
	    	}
	    }
    }else if(e.target.id=="hakim" || e.target.id=="panitera" || e.target.id=="jurusita"){
    	var nama = $('#'+e.target.id+' [value="'+val+'"]').text();
    	$('#fullname').val(nama);
    	
    }
});


$('#frm_user').SubmitHandling({
   	refresh:'1',
    setRefresh:1,
    divRef:'#frm_user',
    clicked:1,
    btnClicked:'#back',
    whenStatus:1,
});

$( function() {
        $('#expired_date').datepicker({
            inline: true,
            showOtherMonths: true,
            dateFormat: 'dd/mm/yy',
            dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
            });
    });
$('.datepicker').ValidateDateInput();
</script>
