<?php
session_start();
include "classes/html.class.php";
$db = new db();
$asset_type_res = $db->exec_query('assets', ["*"]);
$asset_type_list = '<option>ALL</option>';
while ($asset_type = $asset_type_res->fetch_assoc()) {
    $asset_type_list = $asset_type_list . "<option value='{$asset_type['record_id']}'>{$asset_type['asset_id']}</option>";
}

$user_type_res = $db->exec_query('users', ["*"], '', '', '', '', "user_type = 'MECHANIC'", "ORDER BY username ASC");
$users_list = '<option>ALL</option>';
while ($users = $user_type_res->fetch_assoc()) {
    $users_list = $users_list . "<option value='{$users['record_id']}'>{$users['username']}</option>";
}

$inspection_type_res = $db->exec_query('pre_inspection_content', ["*"]);
$inspection_list = '<option>ALL</option>';
while ($inspections = $inspection_type_res->fetch_assoc()) {
    $inspection_list = $inspection_list . "<option value='{$inspections['record_id']}'>{$inspections['name']}</option>";
}
$html = new html("pre inspections");
if ($_SESSION['farm_id'] == 0) {
    $farms_res = $db->exec_query('farms', ["*"]);
} else {
    $farms_res = $db->exec_query('farms', ["*"], '', '', '', '', "record_id = {$_SESSION['farm_id']}");
}

$farm_list = '<option value="0">ALL</option>';
while ($farms = $farms_res->fetch_assoc()) {
    $farm_list = $farm_list . "<option value='{$farms['record_id']}'>{$farms['farm_name']}</option>";
}

?>

<div class='form'  style="padding-bottom: 0%;">
    <form action='pre_inspecion_report.php' method='POST'>

        <h2 style="font-size: 2vw;">FILTER:</h2>
        <hr><br>
        <div class="center_screen">
            <div clas="">
            <label>DATE FROM</label><br>
            <input type='date' name='date_from' class='form_input' /><br><br>
            </div>
            <div class="">
            <label>DATE TO</label><br>
            <input type='date' name='date_to' class='form_input' /><br><br>
            </div>
            <div class="">
            <label>TYPE</label><br>
            <select name='type' class='form_input'>
                <?php echo $inspection_list; ?>
            </select><br><br>
            </div>
            <div class="">
            <label>USER</label><br>
            <select name='username' class='form_input'>
                <?php echo $users_list; ?>
            </select><br><br>
            </div>
            <div class="">
            <label>ASSET</label><br>
            <select name='asset_id' class='form_input'>
                <?php echo $asset_type_list; ?>
            </select><br><br>
            </div>
            <div class="">
                <label>FARM: </label><br>
                <select name='farm_id' class='form_input'>
                    <?php echo $farm_list; ?>
                </select><br><br>
            </div>
            <br>
        </div>
        <input type='submit' value='SEARCH' class='form_btn' />
    </form>
</div>
<br>
<br>
<br>




</body>

</html>