<?php 
$submit_url = $file_name."?page=view_masterdata&action=$action"; 
$status_submit_url = $file_name."?page=view_masterdata&name=$name"; 

$search_url = $file_name."?page=view_masterdata&name=$name"; 
$show_all = "page=view_masterdata&name=$name"; 
?>
<div class="hide_search_div">
<button data-toggle="collapse" data-target="#booke_note_area" type="button" name="" class="btn btn-primary hide_show <?=$add_btn_hide;?>" style="margin:0 0 5px 10px;" >Add</button>
<? if(!($name == "mileage_rate" && $button_value == "Add" && !$_SESSION['is_super_admin'])){ ?>
<div class="panel box box-primary <?=$collapse_area;?>" id="booke_note_area">
	<div class="box-header with-border" >
		<div class="col-12">
			<form action="<?php echo $submit_url;?>" method="post" id="form1">
				<div class="row">
					<div class="col-xs-2 text-nowrap " style="margin-right: 10px;">
						<label class="control-label"><?=ucwords(str_replace('_', ' ', $name));?><em class="text-danger"> *</em></label>						
					</div>
					
					<div class="col-xs-2">
						<div class="input-group" >
							<input type="text" class="form-control" id="code" name="code" value="<?php echo $code;?>" required>
						</div>
					</div>
					
					<input type="hidden" id="name" name="name" value="<?php echo $name;?>">
					<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
					
					<div class="col-xs-4" style="margin-left:10px;">
						<button type="submit" id="add_master_data"  name="add_master_data" class="btn btn-primary"><?=$button_value?>
							<i class="fas fa-sync-alt fa-spin" style="display:none;" id="page_load_div"></i>
						</button>
						<button data-toggle="collapse" data-target="#booke_note_area" type="button" name="" class="btn btn-primary cancel_btn <?=$cancel_btn_hide;?>">Cancel</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<? } ?>
<div class="box-header" id="search_list" style="display:<?=$search_list;?>;">
	<form action="<?php echo $search_url;?>" method="post" name="search_form" id="search_form">		
		<div class="card-body">
			<div class="row">
				<div class="col-sm-3">
					<label class="control-label"><?=ucwords(str_replace('_', ' ', $name));?></label>
					<input type="text" class="form-control" id="code_search" name="code_search" value="<?php echo $code_search;?>">
				</div>
				<div class="col-sm-3">
					<div style="clear:both;margin-top:23px;"></div>		
					<? if($_SESSION['is_super_admin']){ ?>
					View deleted items also &nbsp;&nbsp;<input class="flat-red" type="checkbox" id="status" name="status" value="2"  <? echo ($status ==2) ? 'checked':''; ?>>
					<? } ?>
				</div>
				<div class="col-sm-2">
					<div style="clear:both;margin-top:23px;"></div>			
					<button type="submit" name="search" class="btn btn-primary">Search</button>
					<button type="button" name="search" class="btn btn-primary" onclick="javascript:window.location='?<?php echo $show_all ?>'">Show All</button>
				</div>
			</div>
		</div>
	</form>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
	
	$("#search_form").submit(function() {
	 var is_error = false;
	 var input_string = $("#name").val();
	 if($("#code").val()==""){	 
		input_string = input_string.replace("_", " ");		
		if(view_all_clicked !=0){
			alert("Please enter "+input_string+".");
			$("#code").focus();
			is_error = true;
			return false;
		}
	   }
	});
	$('#form1').submit(function(){
		$("#add_master_data").attr("disabled", true);
			$('#page_load_div').show();
	});
	
	$('.hide_show').click(function(){
		$('.hide_show').hide();
		$('.cancel_btn').show();
		$('#search_list').hide();
		$('#listing').hide();
	});
	$('.cancel_btn').click(function(){
		$('.hide_show').show();
		$('#search_list').show();
		$('#listing').show();
	});
});
</script>