<?php 
$submit_url = $file_name."?page=vac_scheduler_list_view"; 
$show_all_page = "page=vac_scheduler_list_view";

// Get selected machine IDs from request
$selected_machines = isset($_REQUEST['machine_id']) ? $_REQUEST['machine_id'] : array();
?>
<!-- search form -->
<form class="form-horizontal" action="<?php echo $submit_url;?>" method="post" name="search_form" id="search_form">
    <div class="card-body">
        <div class="row">
            <div class="col-lg-3 col-12">
                <label for="Search" class="control-label">Search (Work Order/Part Number)</label>
                <input type="text" class="form-control" id="search" name="search" value="<?php echo $search;?>" placeholder="Search Work Order or Part Number">
            </div>	
            
            <div class="col-lg-2 col-12">
                <label for="Part Number" class="control-label">Part Number</label>
                <?php 
                echo $gsi->getPartNumberListNew("part_id[]","","100%",false,"form-control select2 part_id","");
                ?>
            </div>
            
            <div class="col-lg-2 col-12">
                <label for="Machine" class="control-label">Machine</label>
                <?php 
                echo $gsi->getvacStationList("machine_id[]", $selected_machines, "100%", false, "form-control select2 machine_id", "");
                ?>
            </div>
            
            <div class="col-lg-2 col-12">
                <label for="End Date From" class="control-label">End Date From</label>
                <input type="text" class="form-control datepicker" id="from_start_date" name="from_start_date" value="<?php echo (isset($_REQUEST['from_start_date']) && $_REQUEST['from_start_date'] != "") ? $_REQUEST['from_start_date'] : "";?>" placeholder="DD-MM-YYYY" autocomplete="off">
            </div>
            
            <div class="col-lg-2 col-12">
                <label for="End Date To" class="control-label">End Date To</label>
                <input type="text" class="form-control datepicker" id="to_start_date" name="to_start_date" value="<?php echo (isset($_REQUEST['to_start_date']) && $_REQUEST['to_start_date'] != "") ? $_REQUEST['to_start_date'] : "";?>" placeholder="DD-MM-YYYY" autocomplete="off">
            </div>
            
            <div class="col-lg-1 col-12">
                <label for="Actions" class="control-label">&nbsp;</label><br>
                <button type="submit" class="btn btn-success">Search
                    <i class="fa fa-refresh fa-spin" style="display:none;" id="page_load_div"></i>
                </button>
            </div>
            <div class="col-lg-1 col-12">
                <label for="Actions" class="control-label">&nbsp;</label><br>
                <button type="button" value="Show All" onclick="javascript:window.location='?<?php echo $show_all_page ?>'" class="btn btn-info">Show All</button>
            </div>
        </div>
    </div>
</form>

<script type="text/javascript">
$(document).ready(function(){
    $('#search_form').submit(function(){
        $("#submit").attr("disabled", true);
        $('#page_load_div').show();
    });
    
    // Initialize select2 for all dropdowns
    $('.select2').select2();
    
    // Datepicker initialization
    $('.datepicker').datepicker({
        format: 'dd-mm-yyyy',
        autoclose: true
    });
});
</script>